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" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 25 | #include "heap_poisoning.h" |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 26 | #include "intrinsics.h" |
| 27 | #include "intrinsics_x86_64.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 28 | #include "linker/linker_patch.h" |
Andreas Gampe | d490129 | 2017-05-30 18:41:34 -0700 | [diff] [blame] | 29 | #include "lock_word.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 30 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 31 | #include "mirror/class-inl.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 32 | #include "mirror/object_reference.h" |
| 33 | #include "thread.h" |
| 34 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 35 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 36 | #include "utils/x86_64/assembler_x86_64.h" |
| 37 | #include "utils/x86_64/managed_register_x86_64.h" |
| 38 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 39 | namespace art { |
| 40 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 41 | template<class MirrorType> |
| 42 | class GcRoot; |
| 43 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 44 | namespace x86_64 { |
| 45 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 46 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 47 | static constexpr Register kMethodRegisterArgument = RDI; |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 48 | // The compare/jump sequence will generate about (1.5 * num_entries) instructions. A jump |
| 49 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 50 | // generates less code/data with a small num_entries. |
| 51 | static constexpr uint32_t kPackedSwitchJumpTableThreshold = 5; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 52 | |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 53 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 54 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 55 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 56 | static constexpr int kC2ConditionMask = 0x400; |
| 57 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 58 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 59 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 60 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86_64PointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 61 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 62 | class NullCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 63 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 64 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 65 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 66 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 67 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 68 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 69 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 70 | // Live registers will be restored in the catch block if caught. |
| 71 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 72 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 73 | x86_64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 74 | instruction_, |
| 75 | instruction_->GetDexPc(), |
| 76 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 77 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 78 | } |
| 79 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 80 | bool IsFatal() const OVERRIDE { return true; } |
| 81 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 82 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86_64"; } |
| 83 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 84 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 85 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 86 | }; |
| 87 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 88 | class DivZeroCheckSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 89 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 90 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 91 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 92 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 93 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 94 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 95 | x86_64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 96 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 99 | bool IsFatal() const OVERRIDE { return true; } |
| 100 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 101 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86_64"; } |
| 102 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 104 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 105 | }; |
| 106 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 107 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 108 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 109 | DivRemMinusOneSlowPathX86_64(HInstruction* at, Register reg, DataType::Type type, bool is_div) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 110 | : SlowPathCode(at), cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 112 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 113 | __ Bind(GetEntryLabel()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 114 | if (type_ == DataType::Type::kInt32) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 115 | if (is_div_) { |
| 116 | __ negl(cpu_reg_); |
| 117 | } else { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 118 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 121 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 122 | DCHECK_EQ(DataType::Type::kInt64, type_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 123 | if (is_div_) { |
| 124 | __ negq(cpu_reg_); |
| 125 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 126 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 127 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 128 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 129 | __ jmp(GetExitLabel()); |
| 130 | } |
| 131 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 132 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86_64"; } |
| 133 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 134 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 135 | const CpuRegister cpu_reg_; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 136 | const DataType::Type type_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 137 | const bool is_div_; |
| 138 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 141 | class SuspendCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 142 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 143 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 144 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 145 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 146 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 147 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 148 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 149 | __ Bind(GetEntryLabel()); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 150 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 151 | x86_64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 152 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 153 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 154 | if (successor_ == nullptr) { |
| 155 | __ jmp(GetReturnLabel()); |
| 156 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 157 | __ jmp(x86_64_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 158 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 161 | Label* GetReturnLabel() { |
| 162 | DCHECK(successor_ == nullptr); |
| 163 | return &return_label_; |
| 164 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 165 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 166 | HBasicBlock* GetSuccessor() const { |
| 167 | return successor_; |
| 168 | } |
| 169 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 170 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 171 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 172 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 173 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 174 | Label return_label_; |
| 175 | |
| 176 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 177 | }; |
| 178 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 179 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 180 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 181 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 182 | : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 183 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 184 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 185 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 186 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 187 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 188 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 189 | // Live registers will be restored in the catch block if caught. |
| 190 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 191 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 192 | // Are we using an array length from memory? |
| 193 | HInstruction* array_length = instruction_->InputAt(1); |
| 194 | Location length_loc = locations->InAt(1); |
| 195 | InvokeRuntimeCallingConvention calling_convention; |
| 196 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 197 | // Load the array length into our temporary. |
Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 198 | HArrayLength* length = array_length->AsArrayLength(); |
Nicolas Geoffray | 003444a | 2017-10-17 10:58:42 +0100 | [diff] [blame] | 199 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 200 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 201 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
| 202 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 203 | // Check for conflicts with index. |
| 204 | if (length_loc.Equals(locations->InAt(0))) { |
| 205 | // We know we aren't using parameter 2. |
| 206 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 207 | } |
| 208 | __ movl(length_loc.AsRegister<CpuRegister>(), array_len); |
Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 209 | if (mirror::kUseStringCompression && length->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 210 | __ shrl(length_loc.AsRegister<CpuRegister>(), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 211 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 212 | } |
| 213 | |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 214 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 215 | // move resolver. |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 216 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 217 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 218 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 219 | DataType::Type::kInt32, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 220 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 221 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 222 | DataType::Type::kInt32); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 223 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 224 | ? kQuickThrowStringBounds |
| 225 | : kQuickThrowArrayBounds; |
| 226 | x86_64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 227 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 228 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 229 | } |
| 230 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 231 | bool IsFatal() const OVERRIDE { return true; } |
| 232 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 233 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 234 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 235 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 236 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 237 | }; |
| 238 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 239 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 240 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 241 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 242 | HInstruction* at, |
| 243 | uint32_t dex_pc, |
| 244 | bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 245 | : SlowPathCode(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 246 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 247 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 248 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 249 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 250 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 251 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 252 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 253 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 254 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 255 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 256 | // Custom calling convention: RAX serves as both input and output. |
| 257 | __ movl(CpuRegister(RAX), Immediate(cls_->GetTypeIndex().index_)); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 258 | x86_64_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage : kQuickInitializeType, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 259 | instruction_, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 260 | dex_pc_, |
| 261 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 262 | if (do_clinit_) { |
| 263 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 264 | } else { |
| 265 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 266 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 267 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 268 | Location out = locations->Out(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 269 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 270 | if (out.IsValid()) { |
| 271 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 272 | x86_64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 275 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 276 | __ jmp(GetExitLabel()); |
| 277 | } |
| 278 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 279 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 280 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 281 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 282 | // The class this slow path will load. |
| 283 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 284 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 285 | // The dex PC of `at_`. |
| 286 | const uint32_t dex_pc_; |
| 287 | |
| 288 | // Whether to initialize the class. |
| 289 | const bool do_clinit_; |
| 290 | |
| 291 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 292 | }; |
| 293 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 294 | class LoadStringSlowPathX86_64 : public SlowPathCode { |
| 295 | public: |
| 296 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : SlowPathCode(instruction) {} |
| 297 | |
| 298 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 299 | LocationSummary* locations = instruction_->GetLocations(); |
| 300 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 301 | |
| 302 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 303 | __ Bind(GetEntryLabel()); |
| 304 | SaveLiveRegisters(codegen, locations); |
| 305 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 306 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 307 | // Custom calling convention: RAX serves as both input and output. |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 308 | __ movl(CpuRegister(RAX), Immediate(string_index.index_)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 309 | x86_64_codegen->InvokeRuntime(kQuickResolveString, |
| 310 | instruction_, |
| 311 | instruction_->GetDexPc(), |
| 312 | this); |
| 313 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 314 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| 315 | RestoreLiveRegisters(codegen, locations); |
| 316 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 317 | __ jmp(GetExitLabel()); |
| 318 | } |
| 319 | |
| 320 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86_64"; } |
| 321 | |
| 322 | private: |
| 323 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 324 | }; |
| 325 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 326 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 327 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 328 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 329 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 330 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 331 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 332 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 333 | uint32_t dex_pc = instruction_->GetDexPc(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 334 | DCHECK(instruction_->IsCheckCast() |
| 335 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 336 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 337 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 338 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 339 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 340 | if (kPoisonHeapReferences && |
| 341 | instruction_->IsCheckCast() && |
| 342 | instruction_->AsCheckCast()->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) { |
| 343 | // First, unpoison the `cls` reference that was poisoned for direct memory comparison. |
| 344 | __ UnpoisonHeapReference(locations->InAt(1).AsRegister<CpuRegister>()); |
| 345 | } |
| 346 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 347 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 348 | SaveLiveRegisters(codegen, locations); |
| 349 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 350 | |
| 351 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 352 | // move resolver. |
| 353 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 354 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 355 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 356 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 357 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 358 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 359 | DataType::Type::kReference); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 360 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 361 | x86_64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 362 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 363 | } else { |
| 364 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 365 | x86_64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 366 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 367 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 368 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 369 | if (!is_fatal_) { |
| 370 | if (instruction_->IsInstanceOf()) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 371 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 372 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 373 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 374 | RestoreLiveRegisters(codegen, locations); |
| 375 | __ jmp(GetExitLabel()); |
| 376 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 379 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 380 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 381 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 382 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 383 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 384 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 385 | |
| 386 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 387 | }; |
| 388 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 389 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 390 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 391 | explicit DeoptimizationSlowPathX86_64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 392 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 393 | |
| 394 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 395 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 396 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 397 | LocationSummary* locations = instruction_->GetLocations(); |
| 398 | SaveLiveRegisters(codegen, locations); |
| 399 | InvokeRuntimeCallingConvention calling_convention; |
| 400 | x86_64_codegen->Load32BitValue( |
| 401 | CpuRegister(calling_convention.GetRegisterAt(0)), |
| 402 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 403 | x86_64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 404 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 407 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 408 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 409 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 410 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 411 | }; |
| 412 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 413 | class ArraySetSlowPathX86_64 : public SlowPathCode { |
| 414 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 415 | explicit ArraySetSlowPathX86_64(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 416 | |
| 417 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 418 | LocationSummary* locations = instruction_->GetLocations(); |
| 419 | __ Bind(GetEntryLabel()); |
| 420 | SaveLiveRegisters(codegen, locations); |
| 421 | |
| 422 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 423 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 424 | parallel_move.AddMove( |
| 425 | locations->InAt(0), |
| 426 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 427 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 428 | nullptr); |
| 429 | parallel_move.AddMove( |
| 430 | locations->InAt(1), |
| 431 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 432 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 433 | nullptr); |
| 434 | parallel_move.AddMove( |
| 435 | locations->InAt(2), |
| 436 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 437 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 438 | nullptr); |
| 439 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 440 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 441 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 442 | x86_64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 443 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 444 | RestoreLiveRegisters(codegen, locations); |
| 445 | __ jmp(GetExitLabel()); |
| 446 | } |
| 447 | |
| 448 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86_64"; } |
| 449 | |
| 450 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 451 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 452 | }; |
| 453 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 454 | // Slow path marking an object reference `ref` during a read |
| 455 | // barrier. The field `obj.field` in the object `obj` holding this |
| 456 | // reference does not get updated by this slow path after marking (see |
| 457 | // ReadBarrierMarkAndUpdateFieldSlowPathX86_64 below for that). |
| 458 | // |
| 459 | // This means that after the execution of this slow path, `ref` will |
| 460 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 461 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 462 | // probably still be a from-space reference (unless it gets updated by |
| 463 | // another thread, or if another thread installed another object |
| 464 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 465 | class ReadBarrierMarkSlowPathX86_64 : public SlowPathCode { |
| 466 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 467 | ReadBarrierMarkSlowPathX86_64(HInstruction* instruction, |
| 468 | Location ref, |
| 469 | bool unpoison_ref_before_marking) |
| 470 | : SlowPathCode(instruction), |
| 471 | ref_(ref), |
| 472 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 473 | DCHECK(kEmitCompilerReadBarrier); |
| 474 | } |
| 475 | |
| 476 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86_64"; } |
| 477 | |
| 478 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 479 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 480 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 481 | Register ref_reg = ref_cpu_reg.AsRegister(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 482 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 483 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 484 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 485 | instruction_->IsStaticFieldGet() || |
| 486 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 487 | instruction_->IsArraySet() || |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 488 | instruction_->IsLoadClass() || |
| 489 | instruction_->IsLoadString() || |
| 490 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 491 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 492 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 493 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 494 | << "Unexpected instruction in read barrier marking slow path: " |
| 495 | << instruction_->DebugName(); |
| 496 | |
| 497 | __ Bind(GetEntryLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 498 | if (unpoison_ref_before_marking_) { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 499 | // Object* ref = ref_addr->AsMirrorPtr() |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 500 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 501 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 502 | // No need to save live registers; it's taken care of by the |
| 503 | // entrypoint. Also, there is no need to update the stack mask, |
| 504 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 505 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 506 | DCHECK_NE(ref_reg, RSP); |
| 507 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 508 | // "Compact" slow path, saving two moves. |
| 509 | // |
| 510 | // Instead of using the standard runtime calling convention (input |
| 511 | // and output in R0): |
| 512 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 513 | // RDI <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 514 | // RAX <- ReadBarrierMark(RDI) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 515 | // ref <- RAX |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 516 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 517 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 518 | // of a dedicated entrypoint: |
| 519 | // |
| 520 | // rX <- ReadBarrierMarkRegX(rX) |
| 521 | // |
| 522 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 523 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 524 | // This runtime call does not require a stack map. |
| 525 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 526 | __ jmp(GetExitLabel()); |
| 527 | } |
| 528 | |
| 529 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 530 | // The location (register) of the marked object reference. |
| 531 | const Location ref_; |
| 532 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 533 | const bool unpoison_ref_before_marking_; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 534 | |
| 535 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86_64); |
| 536 | }; |
| 537 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 538 | // Slow path marking an object reference `ref` during a read barrier, |
| 539 | // and if needed, atomically updating the field `obj.field` in the |
| 540 | // object `obj` holding this reference after marking (contrary to |
| 541 | // ReadBarrierMarkSlowPathX86_64 above, which never tries to update |
| 542 | // `obj.field`). |
| 543 | // |
| 544 | // This means that after the execution of this slow path, both `ref` |
| 545 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 546 | // hold the same to-space reference (unless another thread installed |
| 547 | // another object reference (different from `ref`) in `obj.field`). |
| 548 | class ReadBarrierMarkAndUpdateFieldSlowPathX86_64 : public SlowPathCode { |
| 549 | public: |
| 550 | ReadBarrierMarkAndUpdateFieldSlowPathX86_64(HInstruction* instruction, |
| 551 | Location ref, |
| 552 | CpuRegister obj, |
| 553 | const Address& field_addr, |
| 554 | bool unpoison_ref_before_marking, |
| 555 | CpuRegister temp1, |
| 556 | CpuRegister temp2) |
| 557 | : SlowPathCode(instruction), |
| 558 | ref_(ref), |
| 559 | obj_(obj), |
| 560 | field_addr_(field_addr), |
| 561 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 562 | temp1_(temp1), |
| 563 | temp2_(temp2) { |
| 564 | DCHECK(kEmitCompilerReadBarrier); |
| 565 | } |
| 566 | |
| 567 | const char* GetDescription() const OVERRIDE { |
| 568 | return "ReadBarrierMarkAndUpdateFieldSlowPathX86_64"; |
| 569 | } |
| 570 | |
| 571 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 572 | LocationSummary* locations = instruction_->GetLocations(); |
| 573 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 574 | Register ref_reg = ref_cpu_reg.AsRegister(); |
| 575 | DCHECK(locations->CanCall()); |
| 576 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 577 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 578 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 579 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 580 | << instruction_->DebugName(); |
| 581 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 582 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 583 | |
| 584 | __ Bind(GetEntryLabel()); |
| 585 | if (unpoison_ref_before_marking_) { |
| 586 | // Object* ref = ref_addr->AsMirrorPtr() |
| 587 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
| 588 | } |
| 589 | |
| 590 | // Save the old (unpoisoned) reference. |
| 591 | __ movl(temp1_, ref_cpu_reg); |
| 592 | |
| 593 | // No need to save live registers; it's taken care of by the |
| 594 | // entrypoint. Also, there is no need to update the stack mask, |
| 595 | // as this runtime call will not trigger a garbage collection. |
| 596 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 597 | DCHECK_NE(ref_reg, RSP); |
| 598 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 599 | // "Compact" slow path, saving two moves. |
| 600 | // |
| 601 | // Instead of using the standard runtime calling convention (input |
| 602 | // and output in R0): |
| 603 | // |
| 604 | // RDI <- ref |
| 605 | // RAX <- ReadBarrierMark(RDI) |
| 606 | // ref <- RAX |
| 607 | // |
| 608 | // we just use rX (the register containing `ref`) as input and output |
| 609 | // of a dedicated entrypoint: |
| 610 | // |
| 611 | // rX <- ReadBarrierMarkRegX(rX) |
| 612 | // |
| 613 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 614 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 615 | // This runtime call does not require a stack map. |
| 616 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 617 | |
| 618 | // If the new reference is different from the old reference, |
| 619 | // update the field in the holder (`*field_addr`). |
| 620 | // |
| 621 | // Note that this field could also hold a different object, if |
| 622 | // another thread had concurrently changed it. In that case, the |
| 623 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 624 | // operation below would abort the CAS, leaving the field as-is. |
| 625 | NearLabel done; |
| 626 | __ cmpl(temp1_, ref_cpu_reg); |
| 627 | __ j(kEqual, &done); |
| 628 | |
| 629 | // Update the the holder's field atomically. This may fail if |
| 630 | // mutator updates before us, but it's OK. This is achived |
| 631 | // using a strong compare-and-set (CAS) operation with relaxed |
| 632 | // memory synchronization ordering, where the expected value is |
| 633 | // the old reference and the desired value is the new reference. |
| 634 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 635 | // instruction, which requires the expected value (the old |
| 636 | // reference) to be in EAX. Save RAX beforehand, and move the |
| 637 | // expected value (stored in `temp1_`) into EAX. |
| 638 | __ movq(temp2_, CpuRegister(RAX)); |
| 639 | __ movl(CpuRegister(RAX), temp1_); |
| 640 | |
| 641 | // Convenience aliases. |
| 642 | CpuRegister base = obj_; |
| 643 | CpuRegister expected = CpuRegister(RAX); |
| 644 | CpuRegister value = ref_cpu_reg; |
| 645 | |
| 646 | bool base_equals_value = (base.AsRegister() == value.AsRegister()); |
| 647 | Register value_reg = ref_reg; |
| 648 | if (kPoisonHeapReferences) { |
| 649 | if (base_equals_value) { |
| 650 | // If `base` and `value` are the same register location, move |
| 651 | // `value_reg` to a temporary register. This way, poisoning |
| 652 | // `value_reg` won't invalidate `base`. |
| 653 | value_reg = temp1_.AsRegister(); |
| 654 | __ movl(CpuRegister(value_reg), base); |
| 655 | } |
| 656 | |
| 657 | // Check that the register allocator did not assign the location |
| 658 | // of `expected` (RAX) to `value` nor to `base`, so that heap |
| 659 | // poisoning (when enabled) works as intended below. |
| 660 | // - If `value` were equal to `expected`, both references would |
| 661 | // be poisoned twice, meaning they would not be poisoned at |
| 662 | // all, as heap poisoning uses address negation. |
| 663 | // - If `base` were equal to `expected`, poisoning `expected` |
| 664 | // would invalidate `base`. |
| 665 | DCHECK_NE(value_reg, expected.AsRegister()); |
| 666 | DCHECK_NE(base.AsRegister(), expected.AsRegister()); |
| 667 | |
| 668 | __ PoisonHeapReference(expected); |
| 669 | __ PoisonHeapReference(CpuRegister(value_reg)); |
| 670 | } |
| 671 | |
| 672 | __ LockCmpxchgl(field_addr_, CpuRegister(value_reg)); |
| 673 | |
| 674 | // If heap poisoning is enabled, we need to unpoison the values |
| 675 | // that were poisoned earlier. |
| 676 | if (kPoisonHeapReferences) { |
| 677 | if (base_equals_value) { |
| 678 | // `value_reg` has been moved to a temporary register, no need |
| 679 | // to unpoison it. |
| 680 | } else { |
| 681 | __ UnpoisonHeapReference(CpuRegister(value_reg)); |
| 682 | } |
| 683 | // No need to unpoison `expected` (RAX), as it is be overwritten below. |
| 684 | } |
| 685 | |
| 686 | // Restore RAX. |
| 687 | __ movq(CpuRegister(RAX), temp2_); |
| 688 | |
| 689 | __ Bind(&done); |
| 690 | __ jmp(GetExitLabel()); |
| 691 | } |
| 692 | |
| 693 | private: |
| 694 | // The location (register) of the marked object reference. |
| 695 | const Location ref_; |
| 696 | // The register containing the object holding the marked object reference field. |
| 697 | const CpuRegister obj_; |
| 698 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 699 | const Address field_addr_; |
| 700 | |
| 701 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 702 | const bool unpoison_ref_before_marking_; |
| 703 | |
| 704 | const CpuRegister temp1_; |
| 705 | const CpuRegister temp2_; |
| 706 | |
| 707 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86_64); |
| 708 | }; |
| 709 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 710 | // Slow path generating a read barrier for a heap reference. |
| 711 | class ReadBarrierForHeapReferenceSlowPathX86_64 : public SlowPathCode { |
| 712 | public: |
| 713 | ReadBarrierForHeapReferenceSlowPathX86_64(HInstruction* instruction, |
| 714 | Location out, |
| 715 | Location ref, |
| 716 | Location obj, |
| 717 | uint32_t offset, |
| 718 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 719 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 720 | out_(out), |
| 721 | ref_(ref), |
| 722 | obj_(obj), |
| 723 | offset_(offset), |
| 724 | index_(index) { |
| 725 | DCHECK(kEmitCompilerReadBarrier); |
| 726 | // If `obj` is equal to `out` or `ref`, it means the initial |
| 727 | // object has been overwritten by (or after) the heap object |
| 728 | // reference load to be instrumented, e.g.: |
| 729 | // |
| 730 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 731 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 732 | // |
| 733 | // In that case, we have lost the information about the original |
| 734 | // object, and the emitted read barrier cannot work properly. |
| 735 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 736 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 737 | } |
| 738 | |
| 739 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 740 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 741 | LocationSummary* locations = instruction_->GetLocations(); |
| 742 | CpuRegister reg_out = out_.AsRegister<CpuRegister>(); |
| 743 | DCHECK(locations->CanCall()); |
| 744 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.AsRegister())) << out_; |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 745 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 746 | instruction_->IsStaticFieldGet() || |
| 747 | instruction_->IsArrayGet() || |
| 748 | instruction_->IsInstanceOf() || |
| 749 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 750 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 751 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 752 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 753 | |
| 754 | __ Bind(GetEntryLabel()); |
| 755 | SaveLiveRegisters(codegen, locations); |
| 756 | |
| 757 | // We may have to change the index's value, but as `index_` is a |
| 758 | // constant member (like other "inputs" of this slow path), |
| 759 | // introduce a copy of it, `index`. |
| 760 | Location index = index_; |
| 761 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 762 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 763 | if (instruction_->IsArrayGet()) { |
| 764 | // Compute real offset and store it in index_. |
| 765 | Register index_reg = index_.AsRegister<CpuRegister>().AsRegister(); |
| 766 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 767 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 768 | // We are about to change the value of `index_reg` (see the |
| 769 | // calls to art::x86_64::X86_64Assembler::shll and |
| 770 | // art::x86_64::X86_64Assembler::AddImmediate below), but it |
| 771 | // has not been saved by the previous call to |
| 772 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 773 | // callee-save register -- |
| 774 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 775 | // callee-save registers, as it has been designed with the |
| 776 | // assumption that callee-save registers are supposed to be |
| 777 | // handled by the called function. So, as a callee-save |
| 778 | // register, `index_reg` _would_ eventually be saved onto |
| 779 | // the stack, but it would be too late: we would have |
| 780 | // changed its value earlier. Therefore, we manually save |
| 781 | // it here into another freely available register, |
| 782 | // `free_reg`, chosen of course among the caller-save |
| 783 | // registers (as a callee-save `free_reg` register would |
| 784 | // exhibit the same problem). |
| 785 | // |
| 786 | // Note we could have requested a temporary register from |
| 787 | // the register allocator instead; but we prefer not to, as |
| 788 | // this is a slow path, and we know we can find a |
| 789 | // caller-save register that is available. |
| 790 | Register free_reg = FindAvailableCallerSaveRegister(codegen).AsRegister(); |
| 791 | __ movl(CpuRegister(free_reg), CpuRegister(index_reg)); |
| 792 | index_reg = free_reg; |
| 793 | index = Location::RegisterLocation(index_reg); |
| 794 | } else { |
| 795 | // The initial register stored in `index_` has already been |
| 796 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 797 | // (as it is not a callee-save register), so we can freely |
| 798 | // use it. |
| 799 | } |
| 800 | // Shifting the index value contained in `index_reg` by the |
| 801 | // scale factor (2) cannot overflow in practice, as the |
| 802 | // runtime is unable to allocate object arrays with a size |
| 803 | // larger than 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 804 | __ shll(CpuRegister(index_reg), Immediate(TIMES_4)); |
| 805 | static_assert( |
| 806 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 807 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 808 | __ AddImmediate(CpuRegister(index_reg), Immediate(offset_)); |
| 809 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 810 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 811 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 812 | // (as in the case of ArrayGet), as it is actually an offset |
| 813 | // to an object field within an object. |
| 814 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 815 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 816 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 817 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 818 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 819 | DCHECK_EQ(offset_, 0U); |
| 820 | DCHECK(index_.IsRegister()); |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | // We're moving two or three locations to locations that could |
| 825 | // overlap, so we need a parallel move resolver. |
| 826 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 827 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 828 | parallel_move.AddMove(ref_, |
| 829 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 830 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 831 | nullptr); |
| 832 | parallel_move.AddMove(obj_, |
| 833 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 834 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 835 | nullptr); |
| 836 | if (index.IsValid()) { |
| 837 | parallel_move.AddMove(index, |
| 838 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 839 | DataType::Type::kInt32, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 840 | nullptr); |
| 841 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 842 | } else { |
| 843 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 844 | __ movl(CpuRegister(calling_convention.GetRegisterAt(2)), Immediate(offset_)); |
| 845 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 846 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 847 | instruction_, |
| 848 | instruction_->GetDexPc(), |
| 849 | this); |
| 850 | CheckEntrypointTypes< |
| 851 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 852 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 853 | |
| 854 | RestoreLiveRegisters(codegen, locations); |
| 855 | __ jmp(GetExitLabel()); |
| 856 | } |
| 857 | |
| 858 | const char* GetDescription() const OVERRIDE { |
| 859 | return "ReadBarrierForHeapReferenceSlowPathX86_64"; |
| 860 | } |
| 861 | |
| 862 | private: |
| 863 | CpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 864 | size_t ref = static_cast<int>(ref_.AsRegister<CpuRegister>().AsRegister()); |
| 865 | size_t obj = static_cast<int>(obj_.AsRegister<CpuRegister>().AsRegister()); |
| 866 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 867 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 868 | return static_cast<CpuRegister>(i); |
| 869 | } |
| 870 | } |
| 871 | // We shall never fail to find a free caller-save register, as |
| 872 | // there are more than two core caller-save registers on x86-64 |
| 873 | // (meaning it is possible to find one which is different from |
| 874 | // `ref` and `obj`). |
| 875 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 876 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 877 | UNREACHABLE(); |
| 878 | } |
| 879 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 880 | const Location out_; |
| 881 | const Location ref_; |
| 882 | const Location obj_; |
| 883 | const uint32_t offset_; |
| 884 | // An additional location containing an index to an array. |
| 885 | // Only used for HArrayGet and the UnsafeGetObject & |
| 886 | // UnsafeGetObjectVolatile intrinsics. |
| 887 | const Location index_; |
| 888 | |
| 889 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86_64); |
| 890 | }; |
| 891 | |
| 892 | // Slow path generating a read barrier for a GC root. |
| 893 | class ReadBarrierForRootSlowPathX86_64 : public SlowPathCode { |
| 894 | public: |
| 895 | ReadBarrierForRootSlowPathX86_64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 896 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 897 | DCHECK(kEmitCompilerReadBarrier); |
| 898 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 899 | |
| 900 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 901 | LocationSummary* locations = instruction_->GetLocations(); |
| 902 | DCHECK(locations->CanCall()); |
| 903 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 904 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 905 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 906 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 907 | |
| 908 | __ Bind(GetEntryLabel()); |
| 909 | SaveLiveRegisters(codegen, locations); |
| 910 | |
| 911 | InvokeRuntimeCallingConvention calling_convention; |
| 912 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 913 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 914 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 915 | instruction_, |
| 916 | instruction_->GetDexPc(), |
| 917 | this); |
| 918 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 919 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 920 | |
| 921 | RestoreLiveRegisters(codegen, locations); |
| 922 | __ jmp(GetExitLabel()); |
| 923 | } |
| 924 | |
| 925 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86_64"; } |
| 926 | |
| 927 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 928 | const Location out_; |
| 929 | const Location root_; |
| 930 | |
| 931 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86_64); |
| 932 | }; |
| 933 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 934 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 935 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 936 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 937 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 938 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 939 | switch (cond) { |
| 940 | case kCondEQ: return kEqual; |
| 941 | case kCondNE: return kNotEqual; |
| 942 | case kCondLT: return kLess; |
| 943 | case kCondLE: return kLessEqual; |
| 944 | case kCondGT: return kGreater; |
| 945 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 946 | case kCondB: return kBelow; |
| 947 | case kCondBE: return kBelowEqual; |
| 948 | case kCondA: return kAbove; |
| 949 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 950 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 951 | LOG(FATAL) << "Unreachable"; |
| 952 | UNREACHABLE(); |
| 953 | } |
| 954 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 955 | // Maps FP condition to x86_64 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 956 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 957 | switch (cond) { |
| 958 | case kCondEQ: return kEqual; |
| 959 | case kCondNE: return kNotEqual; |
| 960 | case kCondLT: return kBelow; |
| 961 | case kCondLE: return kBelowEqual; |
| 962 | case kCondGT: return kAbove; |
| 963 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 964 | default: break; // should not happen |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 965 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 966 | LOG(FATAL) << "Unreachable"; |
| 967 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 968 | } |
| 969 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 970 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86_64::GetSupportedInvokeStaticOrDirectDispatch( |
| 971 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 972 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 973 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 974 | } |
| 975 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 976 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall( |
| 977 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 978 | // All registers are assumed to be correctly set up. |
Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 979 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 980 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 981 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 982 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 983 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 984 | uint32_t offset = |
| 985 | GetThreadOffset<kX86_64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 986 | __ gs()->movq(temp.AsRegister<CpuRegister>(), Address::Absolute(offset, /* no_rip */ true)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 987 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 988 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 989 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 990 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 991 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 992 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: |
| 993 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 994 | __ leal(temp.AsRegister<CpuRegister>(), |
| 995 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
| 996 | RecordBootMethodPatch(invoke); |
| 997 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 998 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
Vladimir Marko | 2d73f33 | 2017-03-16 15:55:49 +0000 | [diff] [blame] | 999 | Load64BitValue(temp.AsRegister<CpuRegister>(), invoke->GetMethodAddress()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1000 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1001 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1002 | __ movq(temp.AsRegister<CpuRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 1003 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1004 | // Bind a new fixup label at the end of the "movl" insn. |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1005 | __ Bind(NewMethodBssEntryPatch( |
| 1006 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()))); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1007 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1008 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1009 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 1010 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 1011 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 1012 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | switch (invoke->GetCodePtrLocation()) { |
| 1016 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 1017 | __ call(&frame_entry_label_); |
| 1018 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1019 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 1020 | // (callee_method + offset_of_quick_compiled_code)() |
| 1021 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 1022 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1023 | kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1024 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1025 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1026 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1027 | |
| 1028 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1029 | } |
| 1030 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1031 | void CodeGeneratorX86_64::GenerateVirtualCall( |
| 1032 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1033 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 1034 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 1035 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1036 | |
| 1037 | // Use the calling convention instead of the location of the receiver, as |
| 1038 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 1039 | // slow path, the arguments have been moved to the right place, so here we are |
| 1040 | // guaranteed that the receiver is the first register of the calling convention. |
| 1041 | InvokeDexCallingConvention calling_convention; |
| 1042 | Register receiver = calling_convention.GetRegisterAt(0); |
| 1043 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1044 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1045 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1046 | __ movl(temp, Address(CpuRegister(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1047 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1048 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 1049 | // emit a read barrier for the previous class reference load. |
| 1050 | // However this is not required in practice, as this is an |
| 1051 | // intermediate/temporary reference and because the current |
| 1052 | // concurrent copying collector keeps the from-space memory |
| 1053 | // intact/accessible until the end of the marking phase (the |
| 1054 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1055 | __ MaybeUnpoisonHeapReference(temp); |
| 1056 | // temp = temp->GetMethodAt(method_offset); |
| 1057 | __ movq(temp, Address(temp, method_offset)); |
| 1058 | // call temp->GetEntryPoint(); |
| 1059 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1060 | kX86_64PointerSize).SizeValue())); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1061 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1064 | void CodeGeneratorX86_64::RecordBootMethodPatch(HInvokeStaticOrDirect* invoke) { |
| 1065 | boot_image_method_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 1066 | invoke->GetTargetMethod().index); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1067 | __ Bind(&boot_image_method_patches_.back().label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1068 | } |
| 1069 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1070 | Label* CodeGeneratorX86_64::NewMethodBssEntryPatch(MethodReference target_method) { |
| 1071 | // Add a patch entry and return the label. |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 1072 | method_bss_entry_patches_.emplace_back(*target_method.dex_file, target_method.index); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1073 | return &method_bss_entry_patches_.back().label; |
| 1074 | } |
| 1075 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1076 | void CodeGeneratorX86_64::RecordBootTypePatch(HLoadClass* load_class) { |
| 1077 | boot_image_type_patches_.emplace_back(load_class->GetDexFile(), |
| 1078 | load_class->GetTypeIndex().index_); |
| 1079 | __ Bind(&boot_image_type_patches_.back().label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1080 | } |
| 1081 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1082 | Label* CodeGeneratorX86_64::NewTypeBssEntryPatch(HLoadClass* load_class) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1083 | type_bss_entry_patches_.emplace_back(load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| 1084 | return &type_bss_entry_patches_.back().label; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1087 | void CodeGeneratorX86_64::RecordBootStringPatch(HLoadString* load_string) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1088 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 1089 | __ Bind(&string_patches_.back().label); |
| 1090 | } |
| 1091 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1092 | Label* CodeGeneratorX86_64::NewStringBssEntryPatch(HLoadString* load_string) { |
| 1093 | DCHECK(!GetCompilerOptions().IsBootImage()); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1094 | string_bss_entry_patches_.emplace_back( |
| 1095 | load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 1096 | return &string_bss_entry_patches_.back().label; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1099 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 1100 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 1101 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 1102 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1103 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1104 | inline void CodeGeneratorX86_64::EmitPcRelativeLinkerPatches( |
| 1105 | const ArenaDeque<PatchInfo<Label>>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1106 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1107 | for (const PatchInfo<Label>& info : infos) { |
| 1108 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 1109 | linker_patches->push_back( |
| 1110 | Factory(literal_offset, &info.dex_file, info.label.Position(), info.index)); |
| 1111 | } |
| 1112 | } |
| 1113 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1114 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1115 | DCHECK(linker_patches->empty()); |
| 1116 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1117 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1118 | method_bss_entry_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1119 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1120 | type_bss_entry_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1121 | string_patches_.size() + |
| 1122 | string_bss_entry_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1123 | linker_patches->reserve(size); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 1124 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1125 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 1126 | boot_image_method_patches_, linker_patches); |
| 1127 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 1128 | boot_image_type_patches_, linker_patches); |
| 1129 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| 1130 | string_patches_, linker_patches); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 1131 | } else { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1132 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1133 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>( |
| 1134 | boot_image_type_patches_, linker_patches); |
| 1135 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>( |
| 1136 | string_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1137 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1138 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 1139 | method_bss_entry_patches_, linker_patches); |
| 1140 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 1141 | type_bss_entry_patches_, linker_patches); |
| 1142 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 1143 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1144 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1147 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1148 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1152 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1153 | } |
| 1154 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1155 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1156 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 1157 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1158 | } |
| 1159 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1160 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1161 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1162 | return kX86_64WordSize; |
| 1163 | } |
| 1164 | |
| 1165 | 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] | 1166 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1167 | __ movups(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1168 | } else { |
| 1169 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 1170 | } |
| 1171 | return GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | 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] | 1175 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1176 | __ movups(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1177 | } else { |
| 1178 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1179 | } |
| 1180 | return GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1181 | } |
| 1182 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1183 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1184 | HInstruction* instruction, |
| 1185 | uint32_t dex_pc, |
| 1186 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1187 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1188 | GenerateInvokeRuntime(GetThreadOffset<kX86_64PointerSize>(entrypoint).Int32Value()); |
| 1189 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1190 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1191 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1192 | } |
| 1193 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1194 | void CodeGeneratorX86_64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1195 | HInstruction* instruction, |
| 1196 | SlowPathCode* slow_path) { |
| 1197 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1198 | GenerateInvokeRuntime(entry_point_offset); |
| 1199 | } |
| 1200 | |
| 1201 | void CodeGeneratorX86_64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1202 | __ gs()->call(Address::Absolute(entry_point_offset, /* no_rip */ true)); |
| 1203 | } |
| 1204 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1205 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1206 | // Use a fake return address register to mimic Quick. |
| 1207 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1208 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1209 | const X86_64InstructionSetFeatures& isa_features, |
| 1210 | const CompilerOptions& compiler_options, |
| 1211 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1212 | : CodeGenerator(graph, |
| 1213 | kNumberOfCpuRegisters, |
| 1214 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1215 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1216 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1217 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1218 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1219 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1220 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1221 | compiler_options, |
| 1222 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1223 | block_labels_(nullptr), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1224 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1225 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1226 | move_resolver_(graph->GetAllocator(), this), |
| 1227 | assembler_(graph->GetAllocator()), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 1228 | isa_features_(isa_features), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1229 | constant_area_start_(0), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1230 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1231 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1232 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1233 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1234 | string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1235 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1236 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1237 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1238 | fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1239 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 1240 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1241 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1242 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 1243 | CodeGeneratorX86_64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1244 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1245 | assembler_(codegen->GetAssembler()), |
| 1246 | codegen_(codegen) {} |
| 1247 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1248 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1249 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1250 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1251 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1252 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1253 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1254 | } |
| 1255 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1256 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1257 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1258 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1259 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1260 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1261 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1262 | } |
| 1263 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1264 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1265 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1266 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1267 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1268 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1269 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1270 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1271 | if (!skip_overflow_check) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1272 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86_64); |
| 1273 | __ testq(CpuRegister(RAX), Address(CpuRegister(RSP), -static_cast<int32_t>(reserved_bytes))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1274 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1275 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1276 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1277 | if (HasEmptyFrame()) { |
| 1278 | return; |
| 1279 | } |
| 1280 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1281 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1282 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1283 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1284 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1285 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1286 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1287 | } |
| 1288 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1289 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1290 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1291 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 1292 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1293 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1294 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1295 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1296 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1297 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1298 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1299 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1300 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1301 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1302 | } |
| 1303 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1304 | // Save the current method if we need it. Note that we do not |
| 1305 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1306 | // in the SSA graph. |
| 1307 | if (RequiresCurrentMethod()) { |
| 1308 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
| 1309 | CpuRegister(kMethodRegisterArgument)); |
| 1310 | } |
Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 1311 | |
| 1312 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1313 | // Initialize should_deoptimize flag to 0. |
| 1314 | __ movl(Address(CpuRegister(RSP), GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
| 1315 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1319 | __ cfi().RememberState(); |
| 1320 | if (!HasEmptyFrame()) { |
| 1321 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1322 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 1323 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1324 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1325 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1326 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1327 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1332 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 1333 | __ cfi().AdjustCFAOffset(-adjust); |
| 1334 | |
| 1335 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1336 | Register reg = kCoreCalleeSaves[i]; |
| 1337 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1338 | __ popq(CpuRegister(reg)); |
| 1339 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1340 | __ cfi().Restore(DWARFReg(reg)); |
| 1341 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1342 | } |
| 1343 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1344 | __ ret(); |
| 1345 | __ cfi().RestoreState(); |
| 1346 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1347 | } |
| 1348 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1349 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1350 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1351 | } |
| 1352 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1353 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1354 | if (source.Equals(destination)) { |
| 1355 | return; |
| 1356 | } |
| 1357 | if (destination.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1358 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1359 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1360 | __ movq(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1361 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1362 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1363 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1364 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1365 | } else if (source.IsConstant()) { |
| 1366 | HConstant* constant = source.GetConstant(); |
| 1367 | if (constant->IsLongConstant()) { |
| 1368 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
| 1369 | } else { |
| 1370 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1371 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1372 | } else { |
| 1373 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1374 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1375 | } |
| 1376 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1377 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1378 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1379 | __ movd(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1380 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1381 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1382 | } else if (source.IsConstant()) { |
| 1383 | HConstant* constant = source.GetConstant(); |
| 1384 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1385 | if (constant->IsFloatConstant()) { |
| 1386 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1387 | } else { |
| 1388 | Load64BitValue(dest, value); |
| 1389 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1390 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1391 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1392 | } else { |
| 1393 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1394 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1395 | } |
| 1396 | } else if (destination.IsStackSlot()) { |
| 1397 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1398 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1399 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1400 | } else if (source.IsFpuRegister()) { |
| 1401 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1402 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1403 | } else if (source.IsConstant()) { |
| 1404 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1405 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1406 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1407 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1408 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1409 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1410 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1411 | } |
| 1412 | } else { |
| 1413 | DCHECK(destination.IsDoubleStackSlot()); |
| 1414 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1415 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1416 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1417 | } else if (source.IsFpuRegister()) { |
| 1418 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1419 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1420 | } else if (source.IsConstant()) { |
| 1421 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1422 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1423 | int64_t value = GetInt64ValueOf(constant); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1424 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1425 | } else { |
| 1426 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1427 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1428 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1429 | } |
| 1430 | } |
| 1431 | } |
| 1432 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1433 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1434 | DCHECK(location.IsRegister()); |
| 1435 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1436 | } |
| 1437 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1438 | void CodeGeneratorX86_64::MoveLocation( |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1439 | Location dst, Location src, DataType::Type dst_type ATTRIBUTE_UNUSED) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1440 | Move(dst, src); |
| 1441 | } |
| 1442 | |
| 1443 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1444 | if (location.IsRegister()) { |
| 1445 | locations->AddTemp(location); |
| 1446 | } else { |
| 1447 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1448 | } |
| 1449 | } |
| 1450 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1451 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1452 | DCHECK(!successor->IsExitBlock()); |
| 1453 | |
| 1454 | HBasicBlock* block = got->GetBlock(); |
| 1455 | HInstruction* previous = got->GetPrevious(); |
| 1456 | |
| 1457 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1458 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1459 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1460 | return; |
| 1461 | } |
| 1462 | |
| 1463 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1464 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1465 | } |
| 1466 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1467 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1468 | } |
| 1469 | } |
| 1470 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1471 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1472 | got->SetLocations(nullptr); |
| 1473 | } |
| 1474 | |
| 1475 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1476 | HandleGoto(got, got->GetSuccessor()); |
| 1477 | } |
| 1478 | |
| 1479 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1480 | try_boundary->SetLocations(nullptr); |
| 1481 | } |
| 1482 | |
| 1483 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1484 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1485 | if (!successor->IsExitBlock()) { |
| 1486 | HandleGoto(try_boundary, successor); |
| 1487 | } |
| 1488 | } |
| 1489 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1490 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1491 | exit->SetLocations(nullptr); |
| 1492 | } |
| 1493 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1494 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1495 | } |
| 1496 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1497 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1498 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1499 | LabelType* true_label, |
| 1500 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1501 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1502 | __ j(kUnordered, true_label); |
| 1503 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1504 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1505 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1506 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1507 | } |
| 1508 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1509 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1510 | LocationSummary* locations = condition->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1511 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1512 | Location left = locations->InAt(0); |
| 1513 | Location right = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1514 | DataType::Type type = condition->InputAt(0)->GetType(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1515 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1516 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1517 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1518 | case DataType::Type::kInt8: |
| 1519 | case DataType::Type::kUint16: |
| 1520 | case DataType::Type::kInt16: |
| 1521 | case DataType::Type::kInt32: |
| 1522 | case DataType::Type::kReference: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1523 | codegen_->GenerateIntCompare(left, right); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1524 | break; |
| 1525 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1526 | case DataType::Type::kInt64: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1527 | codegen_->GenerateLongCompare(left, right); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1528 | break; |
| 1529 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1530 | case DataType::Type::kFloat32: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1531 | if (right.IsFpuRegister()) { |
| 1532 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1533 | } else if (right.IsConstant()) { |
| 1534 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1535 | codegen_->LiteralFloatAddress( |
| 1536 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1537 | } else { |
| 1538 | DCHECK(right.IsStackSlot()); |
| 1539 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1540 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1541 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1542 | break; |
| 1543 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1544 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1545 | if (right.IsFpuRegister()) { |
| 1546 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1547 | } else if (right.IsConstant()) { |
| 1548 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1549 | codegen_->LiteralDoubleAddress( |
| 1550 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1551 | } else { |
| 1552 | DCHECK(right.IsDoubleStackSlot()); |
| 1553 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1554 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1555 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1556 | break; |
| 1557 | } |
| 1558 | default: |
| 1559 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1560 | } |
| 1561 | } |
| 1562 | |
| 1563 | template<class LabelType> |
| 1564 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1565 | LabelType* true_target_in, |
| 1566 | LabelType* false_target_in) { |
| 1567 | // Generated branching requires both targets to be explicit. If either of the |
| 1568 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1569 | LabelType fallthrough_target; |
| 1570 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1571 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1572 | |
| 1573 | // Generate the comparison to set the CC. |
| 1574 | GenerateCompareTest(condition); |
| 1575 | |
| 1576 | // Now generate the correct jump(s). |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1577 | DataType::Type type = condition->InputAt(0)->GetType(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1578 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1579 | case DataType::Type::kInt64: { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1580 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1581 | break; |
| 1582 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1583 | case DataType::Type::kFloat32: { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1584 | GenerateFPJumps(condition, true_target, false_target); |
| 1585 | break; |
| 1586 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1587 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1588 | GenerateFPJumps(condition, true_target, false_target); |
| 1589 | break; |
| 1590 | } |
| 1591 | default: |
| 1592 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1593 | } |
| 1594 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1595 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1596 | __ jmp(false_target); |
| 1597 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1598 | |
| 1599 | if (fallthrough_target.IsLinked()) { |
| 1600 | __ Bind(&fallthrough_target); |
| 1601 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1602 | } |
| 1603 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1604 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1605 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1606 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1607 | // conditions if they are materialized due to the complex branching. |
| 1608 | return cond->IsCondition() && |
| 1609 | cond->GetNext() == branch && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1610 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1611 | } |
| 1612 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1613 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1614 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1615 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1616 | LabelType* true_target, |
| 1617 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1618 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1619 | |
| 1620 | if (true_target == nullptr && false_target == nullptr) { |
| 1621 | // Nothing to do. The code always falls through. |
| 1622 | return; |
| 1623 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1624 | // Constant condition, statically compared against "true" (integer value 1). |
| 1625 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1626 | if (true_target != nullptr) { |
| 1627 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1628 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1629 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1630 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1631 | if (false_target != nullptr) { |
| 1632 | __ jmp(false_target); |
| 1633 | } |
| 1634 | } |
| 1635 | return; |
| 1636 | } |
| 1637 | |
| 1638 | // The following code generates these patterns: |
| 1639 | // (1) true_target == nullptr && false_target != nullptr |
| 1640 | // - opposite condition true => branch to false_target |
| 1641 | // (2) true_target != nullptr && false_target == nullptr |
| 1642 | // - condition true => branch to true_target |
| 1643 | // (3) true_target != nullptr && false_target != nullptr |
| 1644 | // - condition true => branch to true_target |
| 1645 | // - branch to false_target |
| 1646 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1647 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1648 | if (true_target == nullptr) { |
| 1649 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1650 | } else { |
| 1651 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1652 | } |
| 1653 | } else { |
| 1654 | // Materialized condition, compare against 0. |
| 1655 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1656 | if (lhs.IsRegister()) { |
| 1657 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1658 | } else { |
| 1659 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1660 | } |
| 1661 | if (true_target == nullptr) { |
| 1662 | __ j(kEqual, false_target); |
| 1663 | } else { |
| 1664 | __ j(kNotEqual, true_target); |
| 1665 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1666 | } |
| 1667 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1668 | // Condition has not been materialized, use its inputs as the |
| 1669 | // comparison and its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1670 | HCondition* condition = cond->AsCondition(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1671 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1672 | // If this is a long or FP comparison that has been folded into |
| 1673 | // the HCondition, generate the comparison directly. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1674 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 1675 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1676 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1677 | return; |
| 1678 | } |
| 1679 | |
| 1680 | Location lhs = condition->GetLocations()->InAt(0); |
| 1681 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1682 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1683 | if (true_target == nullptr) { |
| 1684 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1685 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1686 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1687 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1688 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1689 | |
| 1690 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1691 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1692 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1693 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1694 | } |
| 1695 | } |
| 1696 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1697 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1698 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1699 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1700 | locations->SetInAt(0, Location::Any()); |
| 1701 | } |
| 1702 | } |
| 1703 | |
| 1704 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1705 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1706 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1707 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1708 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1709 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1710 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1711 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1715 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1716 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1717 | InvokeRuntimeCallingConvention calling_convention; |
| 1718 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1719 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1720 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1721 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1722 | locations->SetInAt(0, Location::Any()); |
| 1723 | } |
| 1724 | } |
| 1725 | |
| 1726 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1727 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1728 | GenerateTestAndBranch<Label>(deoptimize, |
| 1729 | /* condition_input_index */ 0, |
| 1730 | slow_path->GetEntryLabel(), |
| 1731 | /* false_target */ nullptr); |
| 1732 | } |
| 1733 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1734 | void LocationsBuilderX86_64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1735 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1736 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1737 | locations->SetOut(Location::RequiresRegister()); |
| 1738 | } |
| 1739 | |
| 1740 | void InstructionCodeGeneratorX86_64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1741 | __ movl(flag->GetLocations()->Out().AsRegister<CpuRegister>(), |
| 1742 | Address(CpuRegister(RSP), codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1743 | } |
| 1744 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1745 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1746 | // There are no conditional move instructions for XMMs. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1747 | if (DataType::IsFloatingPointType(select->GetType())) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1748 | return false; |
| 1749 | } |
| 1750 | |
| 1751 | // A FP condition doesn't generate the single CC that we need. |
| 1752 | HInstruction* condition = select->GetCondition(); |
| 1753 | if (condition->IsCondition() && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1754 | DataType::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1755 | return false; |
| 1756 | } |
| 1757 | |
| 1758 | // We can generate a CMOV for this Select. |
| 1759 | return true; |
| 1760 | } |
| 1761 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1762 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1763 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1764 | if (DataType::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1765 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1766 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1767 | } else { |
| 1768 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1769 | if (SelectCanUseCMOV(select)) { |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1770 | if (select->InputAt(1)->IsConstant()) { |
| 1771 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1772 | } else { |
| 1773 | locations->SetInAt(1, Location::Any()); |
| 1774 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1775 | } else { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1776 | locations->SetInAt(1, Location::Any()); |
| 1777 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1778 | } |
| 1779 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1780 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1781 | } |
| 1782 | locations->SetOut(Location::SameAsFirstInput()); |
| 1783 | } |
| 1784 | |
| 1785 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 1786 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1787 | if (SelectCanUseCMOV(select)) { |
| 1788 | // If both the condition and the source types are integer, we can generate |
| 1789 | // a CMOV to implement Select. |
| 1790 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1791 | Location value_true_loc = locations->InAt(1); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1792 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1793 | |
| 1794 | HInstruction* select_condition = select->GetCondition(); |
| 1795 | Condition cond = kNotEqual; |
| 1796 | |
| 1797 | // Figure out how to test the 'condition'. |
| 1798 | if (select_condition->IsCondition()) { |
| 1799 | HCondition* condition = select_condition->AsCondition(); |
| 1800 | if (!condition->IsEmittedAtUseSite()) { |
| 1801 | // This was a previously materialized condition. |
| 1802 | // Can we use the existing condition code? |
| 1803 | if (AreEflagsSetFrom(condition, select)) { |
| 1804 | // Materialization was the previous instruction. Condition codes are right. |
| 1805 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1806 | } else { |
| 1807 | // No, we have to recreate the condition code. |
| 1808 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1809 | __ testl(cond_reg, cond_reg); |
| 1810 | } |
| 1811 | } else { |
| 1812 | GenerateCompareTest(condition); |
| 1813 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1814 | } |
| 1815 | } else { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1816 | // Must be a Boolean condition, which needs to be compared to 0. |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1817 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1818 | __ testl(cond_reg, cond_reg); |
| 1819 | } |
| 1820 | |
| 1821 | // If the condition is true, overwrite the output, which already contains false. |
| 1822 | // Generate the correct sized CMOV. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1823 | bool is_64_bit = DataType::Is64BitType(select->GetType()); |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1824 | if (value_true_loc.IsRegister()) { |
| 1825 | __ cmov(cond, value_false, value_true_loc.AsRegister<CpuRegister>(), is_64_bit); |
| 1826 | } else { |
| 1827 | __ cmov(cond, |
| 1828 | value_false, |
| 1829 | Address(CpuRegister(RSP), value_true_loc.GetStackIndex()), is_64_bit); |
| 1830 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1831 | } else { |
| 1832 | NearLabel false_target; |
| 1833 | GenerateTestAndBranch<NearLabel>(select, |
| 1834 | /* condition_input_index */ 2, |
| 1835 | /* true_target */ nullptr, |
| 1836 | &false_target); |
| 1837 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1838 | __ Bind(&false_target); |
| 1839 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1840 | } |
| 1841 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1842 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1843 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1844 | } |
| 1845 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1846 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1847 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1848 | } |
| 1849 | |
| 1850 | void CodeGeneratorX86_64::GenerateNop() { |
| 1851 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1852 | } |
| 1853 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1854 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1855 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1856 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1857 | // Handle the long/FP comparisons made in instruction simplification. |
| 1858 | switch (cond->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1859 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1860 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1861 | locations->SetInAt(1, Location::Any()); |
| 1862 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1863 | case DataType::Type::kFloat32: |
| 1864 | case DataType::Type::kFloat64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1865 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1866 | locations->SetInAt(1, Location::Any()); |
| 1867 | break; |
| 1868 | default: |
| 1869 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1870 | locations->SetInAt(1, Location::Any()); |
| 1871 | break; |
| 1872 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1873 | if (!cond->IsEmittedAtUseSite()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1874 | locations->SetOut(Location::RequiresRegister()); |
| 1875 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1876 | } |
| 1877 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1878 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1879 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1880 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1881 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1882 | |
| 1883 | LocationSummary* locations = cond->GetLocations(); |
| 1884 | Location lhs = locations->InAt(0); |
| 1885 | Location rhs = locations->InAt(1); |
| 1886 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1887 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1888 | |
| 1889 | switch (cond->InputAt(0)->GetType()) { |
| 1890 | default: |
| 1891 | // Integer case. |
| 1892 | |
| 1893 | // Clear output register: setcc only sets the low byte. |
| 1894 | __ xorl(reg, reg); |
| 1895 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1896 | codegen_->GenerateIntCompare(lhs, rhs); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1897 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1898 | return; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1899 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1900 | // Clear output register: setcc only sets the low byte. |
| 1901 | __ xorl(reg, reg); |
| 1902 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1903 | codegen_->GenerateLongCompare(lhs, rhs); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1904 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1905 | return; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1906 | case DataType::Type::kFloat32: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1907 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1908 | if (rhs.IsConstant()) { |
| 1909 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1910 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1911 | } else if (rhs.IsStackSlot()) { |
| 1912 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1913 | } else { |
| 1914 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1915 | } |
| 1916 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1917 | break; |
| 1918 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1919 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1920 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1921 | if (rhs.IsConstant()) { |
| 1922 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1923 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1924 | } else if (rhs.IsDoubleStackSlot()) { |
| 1925 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1926 | } else { |
| 1927 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1928 | } |
| 1929 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1930 | break; |
| 1931 | } |
| 1932 | } |
| 1933 | |
| 1934 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1935 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1936 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1937 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1938 | __ Bind(&false_label); |
| 1939 | __ xorl(reg, reg); |
| 1940 | __ jmp(&done_label); |
| 1941 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1942 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1943 | __ Bind(&true_label); |
| 1944 | __ movl(reg, Immediate(1)); |
| 1945 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1949 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1950 | } |
| 1951 | |
| 1952 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1953 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1957 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1961 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1965 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1969 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1973 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1977 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1978 | } |
| 1979 | |
| 1980 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1981 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1982 | } |
| 1983 | |
| 1984 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1985 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1986 | } |
| 1987 | |
| 1988 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1989 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1993 | HandleCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1994 | } |
| 1995 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1996 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1997 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2001 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2005 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2009 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2013 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2017 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2018 | } |
| 2019 | |
| 2020 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2021 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2025 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2026 | } |
| 2027 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2028 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2029 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2030 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2031 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2032 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2033 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2034 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2035 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2036 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2037 | case DataType::Type::kInt32: |
| 2038 | case DataType::Type::kInt64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2039 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2040 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2041 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2042 | break; |
| 2043 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2044 | case DataType::Type::kFloat32: |
| 2045 | case DataType::Type::kFloat64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2046 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2047 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2048 | locations->SetOut(Location::RequiresRegister()); |
| 2049 | break; |
| 2050 | } |
| 2051 | default: |
| 2052 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 2053 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2054 | } |
| 2055 | |
| 2056 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2057 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2058 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2059 | Location left = locations->InAt(0); |
| 2060 | Location right = locations->InAt(1); |
| 2061 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2062 | NearLabel less, greater, done; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2063 | DataType::Type type = compare->InputAt(0)->GetType(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2064 | Condition less_cond = kLess; |
| 2065 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2066 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2067 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2068 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2069 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2070 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2071 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2072 | case DataType::Type::kInt32: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2073 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2074 | break; |
| 2075 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2076 | case DataType::Type::kInt64: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2077 | codegen_->GenerateLongCompare(left, right); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2078 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2079 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2080 | case DataType::Type::kFloat32: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2081 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2082 | if (right.IsConstant()) { |
| 2083 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 2084 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 2085 | } else if (right.IsStackSlot()) { |
| 2086 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2087 | } else { |
| 2088 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2089 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2090 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2091 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2092 | break; |
| 2093 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2094 | case DataType::Type::kFloat64: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2095 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2096 | if (right.IsConstant()) { |
| 2097 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2098 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 2099 | } else if (right.IsDoubleStackSlot()) { |
| 2100 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2101 | } else { |
| 2102 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2103 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2104 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2105 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2106 | break; |
| 2107 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2108 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2109 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2110 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2111 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2112 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2113 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2114 | __ j(less_cond, &less); |
Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2115 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2116 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2117 | __ movl(out, Immediate(1)); |
| 2118 | __ jmp(&done); |
| 2119 | |
| 2120 | __ Bind(&less); |
| 2121 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2122 | |
| 2123 | __ Bind(&done); |
| 2124 | } |
| 2125 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2126 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2127 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2128 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2129 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2130 | } |
| 2131 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2132 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2133 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2134 | } |
| 2135 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2136 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 2137 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2138 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2139 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2140 | } |
| 2141 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2142 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2143 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2144 | } |
| 2145 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2146 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2147 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2148 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2149 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2150 | } |
| 2151 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2152 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2153 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2154 | } |
| 2155 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2156 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 2157 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2158 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2159 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2160 | } |
| 2161 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2162 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2163 | // Will be generated at use site. |
| 2164 | } |
| 2165 | |
| 2166 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2167 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2168 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2169 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2170 | } |
| 2171 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2172 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 2173 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2174 | // Will be generated at use site. |
| 2175 | } |
| 2176 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2177 | void LocationsBuilderX86_64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2178 | constructor_fence->SetLocations(nullptr); |
| 2179 | } |
| 2180 | |
| 2181 | void InstructionCodeGeneratorX86_64::VisitConstructorFence( |
| 2182 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2183 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2184 | } |
| 2185 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2186 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2187 | memory_barrier->SetLocations(nullptr); |
| 2188 | } |
| 2189 | |
| 2190 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2191 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2192 | } |
| 2193 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2194 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 2195 | ret->SetLocations(nullptr); |
| 2196 | } |
| 2197 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2198 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2199 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2203 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2204 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2205 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2206 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2207 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2208 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2209 | case DataType::Type::kInt8: |
| 2210 | case DataType::Type::kUint16: |
| 2211 | case DataType::Type::kInt16: |
| 2212 | case DataType::Type::kInt32: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2213 | case DataType::Type::kInt64: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2214 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2215 | break; |
| 2216 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2217 | case DataType::Type::kFloat32: |
| 2218 | case DataType::Type::kFloat64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2219 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2220 | break; |
| 2221 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2222 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2223 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2224 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2225 | } |
| 2226 | |
| 2227 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 2228 | if (kIsDebugBuild) { |
| 2229 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2230 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2231 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2232 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2233 | case DataType::Type::kInt8: |
| 2234 | case DataType::Type::kUint16: |
| 2235 | case DataType::Type::kInt16: |
| 2236 | case DataType::Type::kInt32: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2237 | case DataType::Type::kInt64: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2238 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2239 | break; |
| 2240 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2241 | case DataType::Type::kFloat32: |
| 2242 | case DataType::Type::kFloat64: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2243 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2244 | XMM0); |
| 2245 | break; |
| 2246 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2247 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2248 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2249 | } |
| 2250 | } |
| 2251 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2252 | } |
| 2253 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2254 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(DataType::Type type) const { |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2255 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2256 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2257 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2258 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2259 | case DataType::Type::kInt8: |
| 2260 | case DataType::Type::kUint16: |
| 2261 | case DataType::Type::kInt16: |
| 2262 | case DataType::Type::kInt32: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2263 | case DataType::Type::kInt64: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2264 | return Location::RegisterLocation(RAX); |
| 2265 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2266 | case DataType::Type::kVoid: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2267 | return Location::NoLocation(); |
| 2268 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2269 | case DataType::Type::kFloat64: |
| 2270 | case DataType::Type::kFloat32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2271 | return Location::FpuRegisterLocation(XMM0); |
| 2272 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2273 | |
| 2274 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2278 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2279 | } |
| 2280 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2281 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(DataType::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2282 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2283 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2284 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2285 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2286 | case DataType::Type::kInt8: |
| 2287 | case DataType::Type::kUint16: |
| 2288 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2289 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2290 | uint32_t index = gp_index_++; |
| 2291 | stack_index_++; |
| 2292 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2293 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2294 | } else { |
| 2295 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2296 | } |
| 2297 | } |
| 2298 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2299 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2300 | uint32_t index = gp_index_; |
| 2301 | stack_index_ += 2; |
| 2302 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2303 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2304 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2305 | } else { |
| 2306 | gp_index_ += 2; |
| 2307 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2308 | } |
| 2309 | } |
| 2310 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2311 | case DataType::Type::kFloat32: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2312 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2313 | stack_index_++; |
| 2314 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2315 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2316 | } else { |
| 2317 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2318 | } |
| 2319 | } |
| 2320 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2321 | case DataType::Type::kFloat64: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2322 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2323 | stack_index_ += 2; |
| 2324 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2325 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2326 | } else { |
| 2327 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2328 | } |
| 2329 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2330 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2331 | case DataType::Type::kVoid: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2332 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2333 | break; |
| 2334 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2335 | return Location::NoLocation(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2336 | } |
| 2337 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2338 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2339 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2340 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2341 | // the method_idx. |
| 2342 | HandleInvoke(invoke); |
| 2343 | } |
| 2344 | |
| 2345 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2346 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2347 | } |
| 2348 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2349 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2350 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2351 | // art::PrepareForRegisterAllocation. |
| 2352 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2353 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2354 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2355 | if (intrinsic.TryDispatch(invoke)) { |
| 2356 | return; |
| 2357 | } |
| 2358 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2359 | HandleInvoke(invoke); |
| 2360 | } |
| 2361 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2362 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2363 | if (invoke->GetLocations()->Intrinsified()) { |
| 2364 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2365 | intrinsic.Dispatch(invoke); |
| 2366 | return true; |
| 2367 | } |
| 2368 | return false; |
| 2369 | } |
| 2370 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2371 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2372 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2373 | // art::PrepareForRegisterAllocation. |
| 2374 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2375 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2376 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2377 | return; |
| 2378 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2379 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2380 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2381 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2382 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2383 | } |
| 2384 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2385 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2386 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2387 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2388 | } |
| 2389 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2390 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2391 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2392 | if (intrinsic.TryDispatch(invoke)) { |
| 2393 | return; |
| 2394 | } |
| 2395 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2396 | HandleInvoke(invoke); |
| 2397 | } |
| 2398 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2399 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2400 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2401 | return; |
| 2402 | } |
| 2403 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2404 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2405 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2406 | } |
| 2407 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2408 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2409 | HandleInvoke(invoke); |
| 2410 | // Add the hidden argument. |
| 2411 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2412 | } |
| 2413 | |
| 2414 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2415 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2416 | LocationSummary* locations = invoke->GetLocations(); |
| 2417 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2418 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2419 | Location receiver = locations->InAt(0); |
| 2420 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2421 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2422 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2423 | // won't be modified thereafter, before the `call` instruction. |
| 2424 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2425 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2426 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2427 | if (receiver.IsStackSlot()) { |
| 2428 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2429 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2430 | __ movl(temp, Address(temp, class_offset)); |
| 2431 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2432 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2433 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2434 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2435 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2436 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2437 | // emit a read barrier for the previous class reference load. |
| 2438 | // However this is not required in practice, as this is an |
| 2439 | // intermediate/temporary reference and because the current |
| 2440 | // concurrent copying collector keeps the from-space memory |
| 2441 | // intact/accessible until the end of the marking phase (the |
| 2442 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2443 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2444 | // temp = temp->GetAddressOfIMT() |
| 2445 | __ movq(temp, |
| 2446 | Address(temp, mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| 2447 | // temp = temp->GetImtEntryAt(method_offset); |
| 2448 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2449 | invoke->GetImtIndex(), kX86_64PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2450 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2451 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2452 | // call temp->GetEntryPoint(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2453 | __ call(Address( |
| 2454 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2455 | |
| 2456 | DCHECK(!codegen_->IsLeafMethod()); |
| 2457 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2458 | } |
| 2459 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2460 | void LocationsBuilderX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2461 | HandleInvoke(invoke); |
| 2462 | } |
| 2463 | |
| 2464 | void InstructionCodeGeneratorX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2465 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2466 | } |
| 2467 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2468 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2469 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2470 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2471 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2472 | case DataType::Type::kInt32: |
| 2473 | case DataType::Type::kInt64: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2474 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2475 | locations->SetOut(Location::SameAsFirstInput()); |
| 2476 | break; |
| 2477 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2478 | case DataType::Type::kFloat32: |
| 2479 | case DataType::Type::kFloat64: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2480 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2481 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2482 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2483 | break; |
| 2484 | |
| 2485 | default: |
| 2486 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2487 | } |
| 2488 | } |
| 2489 | |
| 2490 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2491 | LocationSummary* locations = neg->GetLocations(); |
| 2492 | Location out = locations->Out(); |
| 2493 | Location in = locations->InAt(0); |
| 2494 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2495 | case DataType::Type::kInt32: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2496 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2497 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2498 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2499 | break; |
| 2500 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2501 | case DataType::Type::kInt64: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2502 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2503 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2504 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2505 | break; |
| 2506 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2507 | case DataType::Type::kFloat32: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2508 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2509 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2510 | // Implement float negation with an exclusive or with value |
| 2511 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2512 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2513 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2514 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2515 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2516 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2517 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2518 | case DataType::Type::kFloat64: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2519 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2520 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2521 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2522 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2523 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2524 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2525 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2526 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2527 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2528 | |
| 2529 | default: |
| 2530 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2531 | } |
| 2532 | } |
| 2533 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2534 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2535 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2536 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2537 | DataType::Type result_type = conversion->GetResultType(); |
| 2538 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2539 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2540 | << input_type << " -> " << result_type; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2541 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2542 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2543 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2544 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2545 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2546 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2547 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2548 | locations->SetInAt(0, Location::Any()); |
| 2549 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2550 | break; |
| 2551 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2552 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2553 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2554 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2555 | locations->SetInAt(0, Location::Any()); |
| 2556 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2557 | break; |
| 2558 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2559 | case DataType::Type::kFloat32: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2560 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2561 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2562 | break; |
| 2563 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2564 | case DataType::Type::kFloat64: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2565 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2566 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2567 | break; |
| 2568 | |
| 2569 | default: |
| 2570 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2571 | << " to " << result_type; |
| 2572 | } |
| 2573 | break; |
| 2574 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2575 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2576 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2577 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2578 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2579 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2580 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2581 | case DataType::Type::kInt16: |
| 2582 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2583 | // TODO: We would benefit from a (to-be-implemented) |
| 2584 | // Location::RegisterOrStackSlot requirement for this input. |
| 2585 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2586 | locations->SetOut(Location::RequiresRegister()); |
| 2587 | break; |
| 2588 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2589 | case DataType::Type::kFloat32: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2590 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2591 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2592 | break; |
| 2593 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2594 | case DataType::Type::kFloat64: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2595 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2596 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2597 | break; |
| 2598 | |
| 2599 | default: |
| 2600 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2601 | << " to " << result_type; |
| 2602 | } |
| 2603 | break; |
| 2604 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2605 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2606 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2607 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2608 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2609 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2610 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2611 | case DataType::Type::kInt16: |
| 2612 | case DataType::Type::kInt32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2613 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2614 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2615 | break; |
| 2616 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2617 | case DataType::Type::kInt64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2618 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2619 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2620 | break; |
| 2621 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2622 | case DataType::Type::kFloat64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2623 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2624 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2625 | break; |
| 2626 | |
| 2627 | default: |
| 2628 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2629 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2630 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2631 | break; |
| 2632 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2633 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2634 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2635 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2636 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2637 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2638 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2639 | case DataType::Type::kInt16: |
| 2640 | case DataType::Type::kInt32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2641 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2642 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2643 | break; |
| 2644 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2645 | case DataType::Type::kInt64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2646 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2647 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2648 | break; |
| 2649 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2650 | case DataType::Type::kFloat32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2651 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2652 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2653 | break; |
| 2654 | |
| 2655 | default: |
| 2656 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2657 | << " to " << result_type; |
| 2658 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2659 | break; |
| 2660 | |
| 2661 | default: |
| 2662 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2663 | << " to " << result_type; |
| 2664 | } |
| 2665 | } |
| 2666 | |
| 2667 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2668 | LocationSummary* locations = conversion->GetLocations(); |
| 2669 | Location out = locations->Out(); |
| 2670 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2671 | DataType::Type result_type = conversion->GetResultType(); |
| 2672 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2673 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2674 | << input_type << " -> " << result_type; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2675 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2676 | case DataType::Type::kUint8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2677 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2678 | case DataType::Type::kInt8: |
| 2679 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2680 | case DataType::Type::kInt16: |
| 2681 | case DataType::Type::kInt32: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2682 | case DataType::Type::kInt64: |
| 2683 | if (in.IsRegister()) { |
| 2684 | __ movzxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| 2685 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| 2686 | __ movzxb(out.AsRegister<CpuRegister>(), |
| 2687 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2688 | } else { |
| 2689 | __ movl(out.AsRegister<CpuRegister>(), |
| 2690 | Immediate(static_cast<uint8_t>(Int64FromConstant(in.GetConstant())))); |
| 2691 | } |
| 2692 | break; |
| 2693 | |
| 2694 | default: |
| 2695 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2696 | << " to " << result_type; |
| 2697 | } |
| 2698 | break; |
| 2699 | |
| 2700 | case DataType::Type::kInt8: |
| 2701 | switch (input_type) { |
| 2702 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2703 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2704 | case DataType::Type::kInt16: |
| 2705 | case DataType::Type::kInt32: |
| 2706 | case DataType::Type::kInt64: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2707 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2708 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2709 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2710 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2711 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2712 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2713 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2714 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2715 | } |
| 2716 | break; |
| 2717 | |
| 2718 | default: |
| 2719 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2720 | << " to " << result_type; |
| 2721 | } |
| 2722 | break; |
| 2723 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2724 | case DataType::Type::kUint16: |
| 2725 | switch (input_type) { |
| 2726 | case DataType::Type::kInt8: |
| 2727 | case DataType::Type::kInt16: |
| 2728 | case DataType::Type::kInt32: |
| 2729 | case DataType::Type::kInt64: |
| 2730 | if (in.IsRegister()) { |
| 2731 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| 2732 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| 2733 | __ movzxw(out.AsRegister<CpuRegister>(), |
| 2734 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2735 | } else { |
| 2736 | __ movl(out.AsRegister<CpuRegister>(), |
| 2737 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
| 2738 | } |
| 2739 | break; |
| 2740 | |
| 2741 | default: |
| 2742 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2743 | << " to " << result_type; |
| 2744 | } |
| 2745 | break; |
| 2746 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2747 | case DataType::Type::kInt16: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2748 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2749 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2750 | case DataType::Type::kInt32: |
| 2751 | case DataType::Type::kInt64: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2752 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2753 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2754 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2755 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2756 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2757 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2758 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2759 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2760 | } |
| 2761 | break; |
| 2762 | |
| 2763 | default: |
| 2764 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2765 | << " to " << result_type; |
| 2766 | } |
| 2767 | break; |
| 2768 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2769 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2770 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2771 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2772 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2773 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2774 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2775 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2776 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2777 | } else { |
| 2778 | DCHECK(in.IsConstant()); |
| 2779 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2780 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2781 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2782 | } |
| 2783 | break; |
| 2784 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2785 | case DataType::Type::kFloat32: { |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2786 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2787 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2788 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2789 | |
| 2790 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2791 | // if input >= (float)INT_MAX goto done |
| 2792 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2793 | __ j(kAboveEqual, &done); |
| 2794 | // if input == NaN goto nan |
| 2795 | __ j(kUnordered, &nan); |
| 2796 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2797 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2798 | __ jmp(&done); |
| 2799 | __ Bind(&nan); |
| 2800 | // output = 0 |
| 2801 | __ xorl(output, output); |
| 2802 | __ Bind(&done); |
| 2803 | break; |
| 2804 | } |
| 2805 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2806 | case DataType::Type::kFloat64: { |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2807 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2808 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2809 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2810 | |
| 2811 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2812 | // if input >= (double)INT_MAX goto done |
| 2813 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2814 | __ j(kAboveEqual, &done); |
| 2815 | // if input == NaN goto nan |
| 2816 | __ j(kUnordered, &nan); |
| 2817 | // output = double-to-int-truncate(input) |
| 2818 | __ cvttsd2si(output, input); |
| 2819 | __ jmp(&done); |
| 2820 | __ Bind(&nan); |
| 2821 | // output = 0 |
| 2822 | __ xorl(output, output); |
| 2823 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2824 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2825 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2826 | |
| 2827 | default: |
| 2828 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2829 | << " to " << result_type; |
| 2830 | } |
| 2831 | break; |
| 2832 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2833 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2834 | switch (input_type) { |
| 2835 | DCHECK(out.IsRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2836 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2837 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2838 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2839 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2840 | case DataType::Type::kInt16: |
| 2841 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2842 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2843 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2844 | break; |
| 2845 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2846 | case DataType::Type::kFloat32: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2847 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2848 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2849 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2850 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2851 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2852 | // if input >= (float)LONG_MAX goto done |
| 2853 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2854 | __ j(kAboveEqual, &done); |
| 2855 | // if input == NaN goto nan |
| 2856 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2857 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2858 | __ cvttss2si(output, input, true); |
| 2859 | __ jmp(&done); |
| 2860 | __ Bind(&nan); |
| 2861 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2862 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2863 | __ Bind(&done); |
| 2864 | break; |
| 2865 | } |
| 2866 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2867 | case DataType::Type::kFloat64: { |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2868 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2869 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2870 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2871 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2872 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2873 | // if input >= (double)LONG_MAX goto done |
| 2874 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2875 | __ j(kAboveEqual, &done); |
| 2876 | // if input == NaN goto nan |
| 2877 | __ j(kUnordered, &nan); |
| 2878 | // output = double-to-long-truncate(input) |
| 2879 | __ cvttsd2si(output, input, true); |
| 2880 | __ jmp(&done); |
| 2881 | __ Bind(&nan); |
| 2882 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2883 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2884 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2885 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2886 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2887 | |
| 2888 | default: |
| 2889 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2890 | << " to " << result_type; |
| 2891 | } |
| 2892 | break; |
| 2893 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2894 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2895 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2896 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2897 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2898 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2899 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2900 | case DataType::Type::kInt16: |
| 2901 | case DataType::Type::kInt32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2902 | if (in.IsRegister()) { |
| 2903 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2904 | } else if (in.IsConstant()) { |
| 2905 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2906 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2907 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2908 | } else { |
| 2909 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2910 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2911 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2912 | break; |
| 2913 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2914 | case DataType::Type::kInt64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2915 | if (in.IsRegister()) { |
| 2916 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2917 | } else if (in.IsConstant()) { |
| 2918 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2919 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 2920 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2921 | } else { |
| 2922 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2923 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2924 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2925 | break; |
| 2926 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2927 | case DataType::Type::kFloat64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2928 | if (in.IsFpuRegister()) { |
| 2929 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2930 | } else if (in.IsConstant()) { |
| 2931 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2932 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2933 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2934 | } else { |
| 2935 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2936 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2937 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2938 | break; |
| 2939 | |
| 2940 | default: |
| 2941 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2942 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2943 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2944 | break; |
| 2945 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2946 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2947 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2948 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2949 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2950 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2951 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2952 | case DataType::Type::kInt16: |
| 2953 | case DataType::Type::kInt32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2954 | if (in.IsRegister()) { |
| 2955 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2956 | } else if (in.IsConstant()) { |
| 2957 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2958 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2959 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2960 | } else { |
| 2961 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2962 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2963 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2964 | break; |
| 2965 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2966 | case DataType::Type::kInt64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2967 | if (in.IsRegister()) { |
| 2968 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2969 | } else if (in.IsConstant()) { |
| 2970 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2971 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2972 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2973 | } else { |
| 2974 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2975 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2976 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2977 | break; |
| 2978 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2979 | case DataType::Type::kFloat32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2980 | if (in.IsFpuRegister()) { |
| 2981 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2982 | } else if (in.IsConstant()) { |
| 2983 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 2984 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2985 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2986 | } else { |
| 2987 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 2988 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2989 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2990 | break; |
| 2991 | |
| 2992 | default: |
| 2993 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2994 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2995 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2996 | break; |
| 2997 | |
| 2998 | default: |
| 2999 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3000 | << " to " << result_type; |
| 3001 | } |
| 3002 | } |
| 3003 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3004 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3005 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3006 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3007 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3008 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3009 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3010 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3011 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3012 | break; |
| 3013 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3014 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3015 | case DataType::Type::kInt64: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3016 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3017 | // 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] | 3018 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3019 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3020 | break; |
| 3021 | } |
| 3022 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3023 | case DataType::Type::kFloat64: |
| 3024 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3025 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3026 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3027 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3028 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3029 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3030 | |
| 3031 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3032 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3033 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3034 | } |
| 3035 | |
| 3036 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 3037 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3038 | Location first = locations->InAt(0); |
| 3039 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3040 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3041 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3042 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3043 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3044 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3045 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3046 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3047 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3048 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3049 | } else { |
| 3050 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3051 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3052 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3053 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3054 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3055 | __ addl(out.AsRegister<CpuRegister>(), |
| 3056 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 3057 | } else { |
| 3058 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3059 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 3060 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3061 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3062 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3063 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3064 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3065 | break; |
| 3066 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3067 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3068 | case DataType::Type::kInt64: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3069 | if (second.IsRegister()) { |
| 3070 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3071 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3072 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3073 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3074 | } else { |
| 3075 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3076 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3077 | } |
| 3078 | } else { |
| 3079 | DCHECK(second.IsConstant()); |
| 3080 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3081 | int32_t int32_value = Low32Bits(value); |
| 3082 | DCHECK_EQ(int32_value, value); |
| 3083 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3084 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 3085 | } else { |
| 3086 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3087 | first.AsRegister<CpuRegister>(), int32_value)); |
| 3088 | } |
| 3089 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3090 | break; |
| 3091 | } |
| 3092 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3093 | case DataType::Type::kFloat32: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3094 | if (second.IsFpuRegister()) { |
| 3095 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3096 | } else if (second.IsConstant()) { |
| 3097 | __ addss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3098 | codegen_->LiteralFloatAddress( |
| 3099 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3100 | } else { |
| 3101 | DCHECK(second.IsStackSlot()); |
| 3102 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3103 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3104 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3105 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3106 | } |
| 3107 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3108 | case DataType::Type::kFloat64: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3109 | if (second.IsFpuRegister()) { |
| 3110 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3111 | } else if (second.IsConstant()) { |
| 3112 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3113 | codegen_->LiteralDoubleAddress( |
| 3114 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3115 | } else { |
| 3116 | DCHECK(second.IsDoubleStackSlot()); |
| 3117 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3118 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3119 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3120 | break; |
| 3121 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3122 | |
| 3123 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3124 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3125 | } |
| 3126 | } |
| 3127 | |
| 3128 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3129 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3130 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3131 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3132 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3133 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3134 | locations->SetInAt(1, Location::Any()); |
| 3135 | locations->SetOut(Location::SameAsFirstInput()); |
| 3136 | break; |
| 3137 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3138 | case DataType::Type::kInt64: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3139 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 3140 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3141 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3142 | break; |
| 3143 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3144 | case DataType::Type::kFloat32: |
| 3145 | case DataType::Type::kFloat64: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3146 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3147 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3148 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3149 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3150 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3151 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3152 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3153 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3154 | } |
| 3155 | |
| 3156 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3157 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3158 | Location first = locations->InAt(0); |
| 3159 | Location second = locations->InAt(1); |
| 3160 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3161 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3162 | case DataType::Type::kInt32: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3163 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3164 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3165 | } else if (second.IsConstant()) { |
| 3166 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3167 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3168 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3169 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3170 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3171 | break; |
| 3172 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3173 | case DataType::Type::kInt64: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3174 | if (second.IsConstant()) { |
| 3175 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3176 | DCHECK(IsInt<32>(value)); |
| 3177 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3178 | } else { |
| 3179 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3180 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3181 | break; |
| 3182 | } |
| 3183 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3184 | case DataType::Type::kFloat32: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3185 | if (second.IsFpuRegister()) { |
| 3186 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3187 | } else if (second.IsConstant()) { |
| 3188 | __ subss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3189 | codegen_->LiteralFloatAddress( |
| 3190 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3191 | } else { |
| 3192 | DCHECK(second.IsStackSlot()); |
| 3193 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3194 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3195 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3196 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3197 | } |
| 3198 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3199 | case DataType::Type::kFloat64: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3200 | if (second.IsFpuRegister()) { |
| 3201 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3202 | } else if (second.IsConstant()) { |
| 3203 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3204 | codegen_->LiteralDoubleAddress( |
| 3205 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3206 | } else { |
| 3207 | DCHECK(second.IsDoubleStackSlot()); |
| 3208 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3209 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3210 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3211 | break; |
| 3212 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3213 | |
| 3214 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3215 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3216 | } |
| 3217 | } |
| 3218 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3219 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3220 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3221 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3222 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3223 | case DataType::Type::kInt32: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3224 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3225 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3226 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3227 | // Can use 3 operand multiply. |
| 3228 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3229 | } else { |
| 3230 | locations->SetOut(Location::SameAsFirstInput()); |
| 3231 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3232 | break; |
| 3233 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3234 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3235 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3236 | locations->SetInAt(1, Location::Any()); |
| 3237 | if (mul->InputAt(1)->IsLongConstant() && |
| 3238 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3239 | // Can use 3 operand multiply. |
| 3240 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3241 | } else { |
| 3242 | locations->SetOut(Location::SameAsFirstInput()); |
| 3243 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3244 | break; |
| 3245 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3246 | case DataType::Type::kFloat32: |
| 3247 | case DataType::Type::kFloat64: { |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3248 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3249 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3250 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3251 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3252 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3253 | |
| 3254 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3255 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3256 | } |
| 3257 | } |
| 3258 | |
| 3259 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3260 | LocationSummary* locations = mul->GetLocations(); |
| 3261 | Location first = locations->InAt(0); |
| 3262 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3263 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3264 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3265 | case DataType::Type::kInt32: |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3266 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3267 | // problems where the output may not be the same as the first operand. |
| 3268 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3269 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3270 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3271 | } else if (second.IsRegister()) { |
| 3272 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3273 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3274 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3275 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3276 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3277 | __ imull(first.AsRegister<CpuRegister>(), |
| 3278 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3279 | } |
| 3280 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3281 | case DataType::Type::kInt64: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3282 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3283 | // problems where the output may not be the same as the first operand. |
| 3284 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3285 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3286 | if (IsInt<32>(value)) { |
| 3287 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3288 | Immediate(static_cast<int32_t>(value))); |
| 3289 | } else { |
| 3290 | // Have to use the constant area. |
| 3291 | DCHECK(first.Equals(out)); |
| 3292 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3293 | } |
| 3294 | } else if (second.IsRegister()) { |
| 3295 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3296 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3297 | } else { |
| 3298 | DCHECK(second.IsDoubleStackSlot()); |
| 3299 | DCHECK(first.Equals(out)); |
| 3300 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3301 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3302 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3303 | break; |
| 3304 | } |
| 3305 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3306 | case DataType::Type::kFloat32: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3307 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3308 | if (second.IsFpuRegister()) { |
| 3309 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3310 | } else if (second.IsConstant()) { |
| 3311 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3312 | codegen_->LiteralFloatAddress( |
| 3313 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3314 | } else { |
| 3315 | DCHECK(second.IsStackSlot()); |
| 3316 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3317 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3318 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3319 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3320 | } |
| 3321 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3322 | case DataType::Type::kFloat64: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3323 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3324 | if (second.IsFpuRegister()) { |
| 3325 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3326 | } else if (second.IsConstant()) { |
| 3327 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3328 | codegen_->LiteralDoubleAddress( |
| 3329 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3330 | } else { |
| 3331 | DCHECK(second.IsDoubleStackSlot()); |
| 3332 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3333 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3334 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3335 | break; |
| 3336 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3337 | |
| 3338 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3339 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3340 | } |
| 3341 | } |
| 3342 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3343 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3344 | uint32_t stack_adjustment, bool is_float) { |
| 3345 | if (source.IsStackSlot()) { |
| 3346 | DCHECK(is_float); |
| 3347 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3348 | } else if (source.IsDoubleStackSlot()) { |
| 3349 | DCHECK(!is_float); |
| 3350 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3351 | } else { |
| 3352 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3353 | if (is_float) { |
| 3354 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3355 | codegen_->Move(stack_temp, source); |
| 3356 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3357 | } else { |
| 3358 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3359 | codegen_->Move(stack_temp, source); |
| 3360 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3361 | } |
| 3362 | } |
| 3363 | } |
| 3364 | |
| 3365 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3366 | DataType::Type type = rem->GetResultType(); |
| 3367 | bool is_float = type == DataType::Type::kFloat32; |
| 3368 | size_t elem_size = DataType::Size(type); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3369 | LocationSummary* locations = rem->GetLocations(); |
| 3370 | Location first = locations->InAt(0); |
| 3371 | Location second = locations->InAt(1); |
| 3372 | Location out = locations->Out(); |
| 3373 | |
| 3374 | // Create stack space for 2 elements. |
| 3375 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3376 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3377 | |
| 3378 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3379 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3380 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3381 | |
| 3382 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3383 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3384 | __ Bind(&retry); |
| 3385 | __ fprem(); |
| 3386 | |
| 3387 | // Move FP status to AX. |
| 3388 | __ fstsw(); |
| 3389 | |
| 3390 | // And see if the argument reduction is complete. This is signaled by the |
| 3391 | // C2 FPU flag bit set to 0. |
| 3392 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3393 | __ j(kNotEqual, &retry); |
| 3394 | |
| 3395 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3396 | // Store FP top of stack to real stack. |
| 3397 | if (is_float) { |
| 3398 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3399 | } else { |
| 3400 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3401 | } |
| 3402 | |
| 3403 | // Pop the 2 items from the FP stack. |
| 3404 | __ fucompp(); |
| 3405 | |
| 3406 | // Load the value from the stack into an XMM register. |
| 3407 | DCHECK(out.IsFpuRegister()) << out; |
| 3408 | if (is_float) { |
| 3409 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3410 | } else { |
| 3411 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3412 | } |
| 3413 | |
| 3414 | // And remove the temporary stack space we allocated. |
| 3415 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3416 | } |
| 3417 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3418 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3419 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3420 | |
| 3421 | LocationSummary* locations = instruction->GetLocations(); |
| 3422 | Location second = locations->InAt(1); |
| 3423 | DCHECK(second.IsConstant()); |
| 3424 | |
| 3425 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3426 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3427 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3428 | |
| 3429 | DCHECK(imm == 1 || imm == -1); |
| 3430 | |
| 3431 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3432 | case DataType::Type::kInt32: { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3433 | if (instruction->IsRem()) { |
| 3434 | __ xorl(output_register, output_register); |
| 3435 | } else { |
| 3436 | __ movl(output_register, input_register); |
| 3437 | if (imm == -1) { |
| 3438 | __ negl(output_register); |
| 3439 | } |
| 3440 | } |
| 3441 | break; |
| 3442 | } |
| 3443 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3444 | case DataType::Type::kInt64: { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3445 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3446 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3447 | } else { |
| 3448 | __ movq(output_register, input_register); |
| 3449 | if (imm == -1) { |
| 3450 | __ negq(output_register); |
| 3451 | } |
| 3452 | } |
| 3453 | break; |
| 3454 | } |
| 3455 | |
| 3456 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3457 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3458 | } |
| 3459 | } |
| 3460 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3461 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3462 | LocationSummary* locations = instruction->GetLocations(); |
| 3463 | Location second = locations->InAt(1); |
| 3464 | |
| 3465 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3466 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3467 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3468 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3469 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3470 | uint64_t abs_imm = AbsOrMin(imm); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3471 | |
| 3472 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3473 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3474 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3475 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3476 | __ testl(numerator, numerator); |
| 3477 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3478 | int shift = CTZ(imm); |
| 3479 | __ sarl(tmp, Immediate(shift)); |
| 3480 | |
| 3481 | if (imm < 0) { |
| 3482 | __ negl(tmp); |
| 3483 | } |
| 3484 | |
| 3485 | __ movl(output_register, tmp); |
| 3486 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3487 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3488 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3489 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3490 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3491 | __ addq(rdx, numerator); |
| 3492 | __ testq(numerator, numerator); |
| 3493 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3494 | int shift = CTZ(imm); |
| 3495 | __ sarq(rdx, Immediate(shift)); |
| 3496 | |
| 3497 | if (imm < 0) { |
| 3498 | __ negq(rdx); |
| 3499 | } |
| 3500 | |
| 3501 | __ movq(output_register, rdx); |
| 3502 | } |
| 3503 | } |
| 3504 | |
| 3505 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3506 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3507 | |
| 3508 | LocationSummary* locations = instruction->GetLocations(); |
| 3509 | Location second = locations->InAt(1); |
| 3510 | |
| 3511 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3512 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3513 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3514 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3515 | : locations->Out().AsRegister<CpuRegister>(); |
| 3516 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3517 | |
| 3518 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3519 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3520 | if (instruction->IsDiv()) { |
| 3521 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3522 | } else { |
| 3523 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3524 | } |
| 3525 | |
| 3526 | int64_t magic; |
| 3527 | int shift; |
| 3528 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3529 | // TODO: can these branches be written as one? |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3530 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3531 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3532 | |
| 3533 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3534 | |
| 3535 | __ movl(numerator, eax); |
| 3536 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3537 | __ movl(eax, Immediate(magic)); |
| 3538 | __ imull(numerator); |
| 3539 | |
| 3540 | if (imm > 0 && magic < 0) { |
| 3541 | __ addl(edx, numerator); |
| 3542 | } else if (imm < 0 && magic > 0) { |
| 3543 | __ subl(edx, numerator); |
| 3544 | } |
| 3545 | |
| 3546 | if (shift != 0) { |
| 3547 | __ sarl(edx, Immediate(shift)); |
| 3548 | } |
| 3549 | |
| 3550 | __ movl(eax, edx); |
| 3551 | __ shrl(edx, Immediate(31)); |
| 3552 | __ addl(edx, eax); |
| 3553 | |
| 3554 | if (instruction->IsRem()) { |
| 3555 | __ movl(eax, numerator); |
| 3556 | __ imull(edx, Immediate(imm)); |
| 3557 | __ subl(eax, edx); |
| 3558 | __ movl(edx, eax); |
| 3559 | } else { |
| 3560 | __ movl(eax, edx); |
| 3561 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3562 | } else { |
| 3563 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3564 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3565 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3566 | |
| 3567 | CpuRegister rax = eax; |
| 3568 | CpuRegister rdx = edx; |
| 3569 | |
| 3570 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3571 | |
| 3572 | // Save the numerator. |
| 3573 | __ movq(numerator, rax); |
| 3574 | |
| 3575 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3576 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3577 | |
| 3578 | // RDX:RAX = magic * numerator |
| 3579 | __ imulq(numerator); |
| 3580 | |
| 3581 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3582 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3583 | __ addq(rdx, numerator); |
| 3584 | } else if (imm < 0 && magic > 0) { |
| 3585 | // RDX -= numerator |
| 3586 | __ subq(rdx, numerator); |
| 3587 | } |
| 3588 | |
| 3589 | // Shift if needed. |
| 3590 | if (shift != 0) { |
| 3591 | __ sarq(rdx, Immediate(shift)); |
| 3592 | } |
| 3593 | |
| 3594 | // RDX += 1 if RDX < 0 |
| 3595 | __ movq(rax, rdx); |
| 3596 | __ shrq(rdx, Immediate(63)); |
| 3597 | __ addq(rdx, rax); |
| 3598 | |
| 3599 | if (instruction->IsRem()) { |
| 3600 | __ movq(rax, numerator); |
| 3601 | |
| 3602 | if (IsInt<32>(imm)) { |
| 3603 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3604 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3605 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3606 | } |
| 3607 | |
| 3608 | __ subq(rax, rdx); |
| 3609 | __ movq(rdx, rax); |
| 3610 | } else { |
| 3611 | __ movq(rax, rdx); |
| 3612 | } |
| 3613 | } |
| 3614 | } |
| 3615 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3616 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3617 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3618 | DataType::Type type = instruction->GetResultType(); |
| 3619 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3620 | |
| 3621 | bool is_div = instruction->IsDiv(); |
| 3622 | LocationSummary* locations = instruction->GetLocations(); |
| 3623 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3624 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3625 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3626 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3627 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3628 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3629 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3630 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3631 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3632 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3633 | if (imm == 0) { |
| 3634 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3635 | } else if (imm == 1 || imm == -1) { |
| 3636 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3637 | } else if (instruction->IsDiv() && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3638 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3639 | } else { |
| 3640 | DCHECK(imm <= -2 || imm >= 2); |
| 3641 | GenerateDivRemWithAnyConstant(instruction); |
| 3642 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3643 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3644 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3645 | new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86_64( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3646 | instruction, out.AsRegister(), type, is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3647 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3648 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3649 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3650 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3651 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3652 | // 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] | 3653 | if (type == DataType::Type::kInt32) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3654 | __ cmpl(second_reg, Immediate(-1)); |
| 3655 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3656 | // edx:eax <- sign-extended of eax |
| 3657 | __ cdq(); |
| 3658 | // eax = quotient, edx = remainder |
| 3659 | __ idivl(second_reg); |
| 3660 | } else { |
| 3661 | __ cmpq(second_reg, Immediate(-1)); |
| 3662 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3663 | // rdx:rax <- sign-extended of rax |
| 3664 | __ cqo(); |
| 3665 | // rax = quotient, rdx = remainder |
| 3666 | __ idivq(second_reg); |
| 3667 | } |
| 3668 | __ Bind(slow_path->GetExitLabel()); |
| 3669 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3670 | } |
| 3671 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3672 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3673 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3674 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3675 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3676 | case DataType::Type::kInt32: |
| 3677 | case DataType::Type::kInt64: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3678 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3679 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3680 | locations->SetOut(Location::SameAsFirstInput()); |
| 3681 | // Intel uses edx:eax as the dividend. |
| 3682 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3683 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3684 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3685 | // output and request another temp. |
| 3686 | if (div->InputAt(1)->IsConstant()) { |
| 3687 | locations->AddTemp(Location::RequiresRegister()); |
| 3688 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3689 | break; |
| 3690 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3691 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3692 | case DataType::Type::kFloat32: |
| 3693 | case DataType::Type::kFloat64: { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3694 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3695 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3696 | locations->SetOut(Location::SameAsFirstInput()); |
| 3697 | break; |
| 3698 | } |
| 3699 | |
| 3700 | default: |
| 3701 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3702 | } |
| 3703 | } |
| 3704 | |
| 3705 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3706 | LocationSummary* locations = div->GetLocations(); |
| 3707 | Location first = locations->InAt(0); |
| 3708 | Location second = locations->InAt(1); |
| 3709 | DCHECK(first.Equals(locations->Out())); |
| 3710 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3711 | DataType::Type type = div->GetResultType(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3712 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3713 | case DataType::Type::kInt32: |
| 3714 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3715 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3716 | break; |
| 3717 | } |
| 3718 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3719 | case DataType::Type::kFloat32: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3720 | if (second.IsFpuRegister()) { |
| 3721 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3722 | } else if (second.IsConstant()) { |
| 3723 | __ divss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3724 | codegen_->LiteralFloatAddress( |
| 3725 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3726 | } else { |
| 3727 | DCHECK(second.IsStackSlot()); |
| 3728 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3729 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3730 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3731 | break; |
| 3732 | } |
| 3733 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3734 | case DataType::Type::kFloat64: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3735 | if (second.IsFpuRegister()) { |
| 3736 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3737 | } else if (second.IsConstant()) { |
| 3738 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3739 | codegen_->LiteralDoubleAddress( |
| 3740 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3741 | } else { |
| 3742 | DCHECK(second.IsDoubleStackSlot()); |
| 3743 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3744 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3745 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3746 | break; |
| 3747 | } |
| 3748 | |
| 3749 | default: |
| 3750 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3751 | } |
| 3752 | } |
| 3753 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3754 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3755 | DataType::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3756 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3757 | new (GetGraph()->GetAllocator()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3758 | |
| 3759 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3760 | case DataType::Type::kInt32: |
| 3761 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3762 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3763 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3764 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3765 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3766 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3767 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3768 | // output and request another temp. |
| 3769 | if (rem->InputAt(1)->IsConstant()) { |
| 3770 | locations->AddTemp(Location::RequiresRegister()); |
| 3771 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3772 | break; |
| 3773 | } |
| 3774 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3775 | case DataType::Type::kFloat32: |
| 3776 | case DataType::Type::kFloat64: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3777 | locations->SetInAt(0, Location::Any()); |
| 3778 | locations->SetInAt(1, Location::Any()); |
| 3779 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3780 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3781 | break; |
| 3782 | } |
| 3783 | |
| 3784 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3785 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3786 | } |
| 3787 | } |
| 3788 | |
| 3789 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3790 | DataType::Type type = rem->GetResultType(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3791 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3792 | case DataType::Type::kInt32: |
| 3793 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3794 | GenerateDivRemIntegral(rem); |
| 3795 | break; |
| 3796 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3797 | case DataType::Type::kFloat32: |
| 3798 | case DataType::Type::kFloat64: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3799 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3800 | break; |
| 3801 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3802 | default: |
| 3803 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3804 | } |
| 3805 | } |
| 3806 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3807 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3808 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3809 | locations->SetInAt(0, Location::Any()); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3810 | } |
| 3811 | |
| 3812 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3813 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3814 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86_64(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3815 | codegen_->AddSlowPath(slow_path); |
| 3816 | |
| 3817 | LocationSummary* locations = instruction->GetLocations(); |
| 3818 | Location value = locations->InAt(0); |
| 3819 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3820 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3821 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3822 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3823 | case DataType::Type::kInt8: |
| 3824 | case DataType::Type::kUint16: |
| 3825 | case DataType::Type::kInt16: |
| 3826 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3827 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3828 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3829 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3830 | } else if (value.IsStackSlot()) { |
| 3831 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3832 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3833 | } else { |
| 3834 | DCHECK(value.IsConstant()) << value; |
| 3835 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3836 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3837 | } |
| 3838 | } |
| 3839 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3840 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3841 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3842 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3843 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3844 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3845 | } else if (value.IsDoubleStackSlot()) { |
| 3846 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3847 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3848 | } else { |
| 3849 | DCHECK(value.IsConstant()) << value; |
| 3850 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3851 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3852 | } |
| 3853 | } |
| 3854 | break; |
| 3855 | } |
| 3856 | default: |
| 3857 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3858 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3859 | } |
| 3860 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3861 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3862 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3863 | |
| 3864 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3865 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3866 | |
| 3867 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3868 | case DataType::Type::kInt32: |
| 3869 | case DataType::Type::kInt64: { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3870 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3871 | // The shift count needs to be in CL. |
| 3872 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3873 | locations->SetOut(Location::SameAsFirstInput()); |
| 3874 | break; |
| 3875 | } |
| 3876 | default: |
| 3877 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3878 | } |
| 3879 | } |
| 3880 | |
| 3881 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3882 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3883 | |
| 3884 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3885 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3886 | Location second = locations->InAt(1); |
| 3887 | |
| 3888 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3889 | case DataType::Type::kInt32: { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3890 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3891 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3892 | if (op->IsShl()) { |
| 3893 | __ shll(first_reg, second_reg); |
| 3894 | } else if (op->IsShr()) { |
| 3895 | __ sarl(first_reg, second_reg); |
| 3896 | } else { |
| 3897 | __ shrl(first_reg, second_reg); |
| 3898 | } |
| 3899 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3900 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3901 | if (op->IsShl()) { |
| 3902 | __ shll(first_reg, imm); |
| 3903 | } else if (op->IsShr()) { |
| 3904 | __ sarl(first_reg, imm); |
| 3905 | } else { |
| 3906 | __ shrl(first_reg, imm); |
| 3907 | } |
| 3908 | } |
| 3909 | break; |
| 3910 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3911 | case DataType::Type::kInt64: { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3912 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3913 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3914 | if (op->IsShl()) { |
| 3915 | __ shlq(first_reg, second_reg); |
| 3916 | } else if (op->IsShr()) { |
| 3917 | __ sarq(first_reg, second_reg); |
| 3918 | } else { |
| 3919 | __ shrq(first_reg, second_reg); |
| 3920 | } |
| 3921 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3922 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3923 | if (op->IsShl()) { |
| 3924 | __ shlq(first_reg, imm); |
| 3925 | } else if (op->IsShr()) { |
| 3926 | __ sarq(first_reg, imm); |
| 3927 | } else { |
| 3928 | __ shrq(first_reg, imm); |
| 3929 | } |
| 3930 | } |
| 3931 | break; |
| 3932 | } |
| 3933 | default: |
| 3934 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3935 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3936 | } |
| 3937 | } |
| 3938 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3939 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 3940 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3941 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3942 | |
| 3943 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3944 | case DataType::Type::kInt32: |
| 3945 | case DataType::Type::kInt64: { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3946 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3947 | // The shift count needs to be in CL (unless it is a constant). |
| 3948 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 3949 | locations->SetOut(Location::SameAsFirstInput()); |
| 3950 | break; |
| 3951 | } |
| 3952 | default: |
| 3953 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3954 | UNREACHABLE(); |
| 3955 | } |
| 3956 | } |
| 3957 | |
| 3958 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 3959 | LocationSummary* locations = ror->GetLocations(); |
| 3960 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3961 | Location second = locations->InAt(1); |
| 3962 | |
| 3963 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3964 | case DataType::Type::kInt32: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3965 | if (second.IsRegister()) { |
| 3966 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3967 | __ rorl(first_reg, second_reg); |
| 3968 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3969 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3970 | __ rorl(first_reg, imm); |
| 3971 | } |
| 3972 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3973 | case DataType::Type::kInt64: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3974 | if (second.IsRegister()) { |
| 3975 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3976 | __ rorq(first_reg, second_reg); |
| 3977 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3978 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3979 | __ rorq(first_reg, imm); |
| 3980 | } |
| 3981 | break; |
| 3982 | default: |
| 3983 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3984 | UNREACHABLE(); |
| 3985 | } |
| 3986 | } |
| 3987 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3988 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 3989 | HandleShift(shl); |
| 3990 | } |
| 3991 | |
| 3992 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 3993 | HandleShift(shl); |
| 3994 | } |
| 3995 | |
| 3996 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 3997 | HandleShift(shr); |
| 3998 | } |
| 3999 | |
| 4000 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 4001 | HandleShift(shr); |
| 4002 | } |
| 4003 | |
| 4004 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 4005 | HandleShift(ushr); |
| 4006 | } |
| 4007 | |
| 4008 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 4009 | HandleShift(ushr); |
| 4010 | } |
| 4011 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4012 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4013 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4014 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4015 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4016 | if (instruction->IsStringAlloc()) { |
| 4017 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4018 | } else { |
| 4019 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4020 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4021 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4022 | } |
| 4023 | |
| 4024 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4025 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4026 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4027 | if (instruction->IsStringAlloc()) { |
| 4028 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4029 | CpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4030 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4031 | __ gs()->movq(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString), /* no_rip */ true)); |
| 4032 | __ call(Address(temp, code_offset.SizeValue())); |
| 4033 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4034 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4035 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4036 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4037 | DCHECK(!codegen_->IsLeafMethod()); |
| 4038 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4039 | } |
| 4040 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4041 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4042 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4043 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4044 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4045 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4046 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4047 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4048 | } |
| 4049 | |
| 4050 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4051 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4052 | // of poisoning the reference. |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 4053 | QuickEntrypointEnum entrypoint = |
| 4054 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4055 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4056 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4057 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4058 | } |
| 4059 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4060 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4061 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4062 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4063 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4064 | if (location.IsStackSlot()) { |
| 4065 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4066 | } else if (location.IsDoubleStackSlot()) { |
| 4067 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4068 | } |
| 4069 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4070 | } |
| 4071 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4072 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 4073 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4074 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4075 | } |
| 4076 | |
| 4077 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4078 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4079 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4080 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4081 | } |
| 4082 | |
| 4083 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 4084 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4085 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4086 | } |
| 4087 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4088 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4089 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4090 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4091 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4092 | locations->SetOut(Location::RequiresRegister()); |
| 4093 | } |
| 4094 | |
| 4095 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4096 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4097 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4098 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4099 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4100 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4101 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4102 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4103 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4104 | instruction->GetIndex(), kX86_64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4105 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4106 | Address(locations->InAt(0).AsRegister<CpuRegister>(), |
| 4107 | mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4108 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4109 | Address(locations->Out().AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4110 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4111 | } |
| 4112 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4113 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4114 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4115 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4116 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4117 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4118 | } |
| 4119 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4120 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 4121 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4122 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4123 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4124 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4125 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4126 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4127 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4128 | break; |
| 4129 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4130 | case DataType::Type::kInt64: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4131 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4132 | break; |
| 4133 | |
| 4134 | default: |
| 4135 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4136 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4137 | } |
| 4138 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4139 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4140 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4141 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4142 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4143 | locations->SetOut(Location::SameAsFirstInput()); |
| 4144 | } |
| 4145 | |
| 4146 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4147 | LocationSummary* locations = bool_not->GetLocations(); |
| 4148 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4149 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 4150 | Location out = locations->Out(); |
| 4151 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4152 | } |
| 4153 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4154 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4155 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4156 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4157 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4158 | locations->SetInAt(i, Location::Any()); |
| 4159 | } |
| 4160 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4161 | } |
| 4162 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4163 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4164 | LOG(FATAL) << "Unimplemented"; |
| 4165 | } |
| 4166 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4167 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4168 | /* |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4169 | * 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] | 4170 | * 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] | 4171 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4172 | */ |
| 4173 | switch (kind) { |
| 4174 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4175 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4176 | break; |
| 4177 | } |
| 4178 | case MemBarrierKind::kAnyStore: |
| 4179 | case MemBarrierKind::kLoadAny: |
| 4180 | case MemBarrierKind::kStoreStore: { |
| 4181 | // nop |
| 4182 | break; |
| 4183 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4184 | case MemBarrierKind::kNTStoreStore: |
| 4185 | // Non-Temporal Store/Store needs an explicit fence. |
| 4186 | MemoryFence(/* non-temporal */ true); |
| 4187 | break; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4188 | } |
| 4189 | } |
| 4190 | |
| 4191 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4192 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4193 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4194 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4195 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4196 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4197 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 4198 | object_field_get_with_read_barrier |
| 4199 | ? LocationSummary::kCallOnSlowPath |
| 4200 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4201 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4202 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4203 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4204 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4205 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4206 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4207 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4208 | // The output overlaps for an object field get when read barriers |
| 4209 | // are enabled: we do not want the move to overwrite the object's |
| 4210 | // location, as we need it to emit the read barrier. |
| 4211 | locations->SetOut( |
| 4212 | Location::RequiresRegister(), |
| 4213 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4214 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4215 | } |
| 4216 | |
| 4217 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4218 | const FieldInfo& field_info) { |
| 4219 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4220 | |
| 4221 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4222 | Location base_loc = locations->InAt(0); |
| 4223 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4224 | Location out = locations->Out(); |
| 4225 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4226 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 4227 | DataType::Type load_type = instruction->GetType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4228 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4229 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4230 | switch (load_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4231 | case DataType::Type::kBool: |
| 4232 | case DataType::Type::kUint8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4233 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4234 | break; |
| 4235 | } |
| 4236 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4237 | case DataType::Type::kInt8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4238 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4239 | break; |
| 4240 | } |
| 4241 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4242 | case DataType::Type::kUint16: { |
| 4243 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4244 | break; |
| 4245 | } |
| 4246 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4247 | case DataType::Type::kInt16: { |
| 4248 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4249 | break; |
| 4250 | } |
| 4251 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4252 | case DataType::Type::kInt32: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4253 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4254 | break; |
| 4255 | } |
| 4256 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4257 | case DataType::Type::kReference: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4258 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4259 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4260 | // Note that a potential implicit null check is handled in this |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 4261 | // CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier call. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4262 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4263 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4264 | if (is_volatile) { |
| 4265 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4266 | } |
| 4267 | } else { |
| 4268 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4269 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4270 | if (is_volatile) { |
| 4271 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4272 | } |
| 4273 | // If read barriers are enabled, emit read barriers other than |
| 4274 | // Baker's using a slow path (and also unpoison the loaded |
| 4275 | // reference, if heap poisoning is enabled). |
| 4276 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4277 | } |
| 4278 | break; |
| 4279 | } |
| 4280 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4281 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4282 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4283 | break; |
| 4284 | } |
| 4285 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4286 | case DataType::Type::kFloat32: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4287 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4288 | break; |
| 4289 | } |
| 4290 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4291 | case DataType::Type::kFloat64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4292 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4293 | break; |
| 4294 | } |
| 4295 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4296 | case DataType::Type::kVoid: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4297 | LOG(FATAL) << "Unreachable type " << load_type; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4298 | UNREACHABLE(); |
| 4299 | } |
| 4300 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4301 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4302 | // Potential implicit null checks, in the case of reference |
| 4303 | // fields, are handled in the previous switch statement. |
| 4304 | } else { |
| 4305 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4306 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4307 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4308 | if (is_volatile) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4309 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4310 | // Memory barriers, in the case of references, are also handled |
| 4311 | // in the previous switch statement. |
| 4312 | } else { |
| 4313 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4314 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4315 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4316 | } |
| 4317 | |
| 4318 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4319 | const FieldInfo& field_info) { |
| 4320 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4321 | |
| 4322 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4323 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4324 | DataType::Type field_type = field_info.GetFieldType(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4325 | bool is_volatile = field_info.IsVolatile(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4326 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4327 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4328 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4329 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4330 | if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4331 | if (is_volatile) { |
| 4332 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4333 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4334 | } else { |
| 4335 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4336 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4337 | } else { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4338 | if (is_volatile) { |
| 4339 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4340 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4341 | } else { |
| 4342 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4343 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4344 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4345 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4346 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4347 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4348 | locations->AddTemp(Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4349 | } else if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4350 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4351 | locations->AddTemp(Location::RequiresRegister()); |
| 4352 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4353 | } |
| 4354 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4355 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4356 | const FieldInfo& field_info, |
| 4357 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4358 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4359 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4360 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4361 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4362 | Location value = locations->InAt(1); |
| 4363 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4364 | DataType::Type field_type = field_info.GetFieldType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4365 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4366 | |
| 4367 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4368 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4369 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4370 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4371 | bool maybe_record_implicit_null_check_done = false; |
| 4372 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4373 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4374 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4375 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4376 | case DataType::Type::kInt8: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4377 | if (value.IsConstant()) { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4378 | __ movb(Address(base, offset), |
| 4379 | Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4380 | } else { |
| 4381 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4382 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4383 | break; |
| 4384 | } |
| 4385 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4386 | case DataType::Type::kUint16: |
| 4387 | case DataType::Type::kInt16: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4388 | if (value.IsConstant()) { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4389 | __ movw(Address(base, offset), |
| 4390 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4391 | } else { |
| 4392 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4393 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4394 | break; |
| 4395 | } |
| 4396 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4397 | case DataType::Type::kInt32: |
| 4398 | case DataType::Type::kReference: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4399 | if (value.IsConstant()) { |
| 4400 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4401 | // `field_type == DataType::Type::kReference` implies `v == 0`. |
| 4402 | DCHECK((field_type != DataType::Type::kReference) || (v == 0)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4403 | // Note: if heap poisoning is enabled, no need to poison |
| 4404 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4405 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4406 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4407 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4408 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4409 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4410 | __ PoisonHeapReference(temp); |
| 4411 | __ movl(Address(base, offset), temp); |
| 4412 | } else { |
| 4413 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4414 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4415 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4416 | break; |
| 4417 | } |
| 4418 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4419 | case DataType::Type::kInt64: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4420 | if (value.IsConstant()) { |
| 4421 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4422 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4423 | Address(base, offset + sizeof(int32_t)), |
| 4424 | v, |
| 4425 | instruction); |
| 4426 | maybe_record_implicit_null_check_done = true; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4427 | } else { |
| 4428 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4429 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4430 | break; |
| 4431 | } |
| 4432 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4433 | case DataType::Type::kFloat32: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4434 | if (value.IsConstant()) { |
| 4435 | int32_t v = |
| 4436 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4437 | __ movl(Address(base, offset), Immediate(v)); |
| 4438 | } else { |
| 4439 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4440 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4441 | break; |
| 4442 | } |
| 4443 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4444 | case DataType::Type::kFloat64: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4445 | if (value.IsConstant()) { |
| 4446 | int64_t v = |
| 4447 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4448 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4449 | Address(base, offset + sizeof(int32_t)), |
| 4450 | v, |
| 4451 | instruction); |
| 4452 | maybe_record_implicit_null_check_done = true; |
| 4453 | } else { |
| 4454 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4455 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4456 | break; |
| 4457 | } |
| 4458 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4459 | case DataType::Type::kVoid: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4460 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4461 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4462 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4463 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4464 | if (!maybe_record_implicit_null_check_done) { |
| 4465 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4466 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4467 | |
| 4468 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4469 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4470 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4471 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4472 | } |
| 4473 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4474 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4475 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4476 | } |
| 4477 | } |
| 4478 | |
| 4479 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4480 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4481 | } |
| 4482 | |
| 4483 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4484 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4485 | } |
| 4486 | |
| 4487 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4488 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4489 | } |
| 4490 | |
| 4491 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4492 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4493 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4494 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4495 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4496 | HandleFieldGet(instruction); |
| 4497 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4498 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4499 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4500 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4501 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4502 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4503 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4504 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4505 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4506 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4507 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4508 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4509 | } |
| 4510 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4511 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4512 | HUnresolvedInstanceFieldGet* instruction) { |
| 4513 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4514 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4515 | instruction, instruction->GetFieldType(), calling_convention); |
| 4516 | } |
| 4517 | |
| 4518 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4519 | HUnresolvedInstanceFieldGet* instruction) { |
| 4520 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4521 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4522 | instruction->GetFieldType(), |
| 4523 | instruction->GetFieldIndex(), |
| 4524 | instruction->GetDexPc(), |
| 4525 | calling_convention); |
| 4526 | } |
| 4527 | |
| 4528 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4529 | HUnresolvedInstanceFieldSet* instruction) { |
| 4530 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4531 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4532 | instruction, instruction->GetFieldType(), calling_convention); |
| 4533 | } |
| 4534 | |
| 4535 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4536 | HUnresolvedInstanceFieldSet* instruction) { |
| 4537 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4538 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4539 | instruction->GetFieldType(), |
| 4540 | instruction->GetFieldIndex(), |
| 4541 | instruction->GetDexPc(), |
| 4542 | calling_convention); |
| 4543 | } |
| 4544 | |
| 4545 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4546 | HUnresolvedStaticFieldGet* instruction) { |
| 4547 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4548 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4549 | instruction, instruction->GetFieldType(), calling_convention); |
| 4550 | } |
| 4551 | |
| 4552 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4553 | HUnresolvedStaticFieldGet* instruction) { |
| 4554 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4555 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4556 | instruction->GetFieldType(), |
| 4557 | instruction->GetFieldIndex(), |
| 4558 | instruction->GetDexPc(), |
| 4559 | calling_convention); |
| 4560 | } |
| 4561 | |
| 4562 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4563 | HUnresolvedStaticFieldSet* instruction) { |
| 4564 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4565 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4566 | instruction, instruction->GetFieldType(), calling_convention); |
| 4567 | } |
| 4568 | |
| 4569 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4570 | HUnresolvedStaticFieldSet* instruction) { |
| 4571 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4572 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4573 | instruction->GetFieldType(), |
| 4574 | instruction->GetFieldIndex(), |
| 4575 | instruction->GetDexPc(), |
| 4576 | calling_convention); |
| 4577 | } |
| 4578 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4579 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4580 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4581 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 4582 | ? Location::RequiresRegister() |
| 4583 | : Location::Any(); |
| 4584 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4585 | } |
| 4586 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4587 | void CodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4588 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4589 | return; |
| 4590 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4591 | LocationSummary* locations = instruction->GetLocations(); |
| 4592 | Location obj = locations->InAt(0); |
| 4593 | |
| 4594 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4595 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4596 | } |
| 4597 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4598 | void CodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4599 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86_64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4600 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4601 | |
| 4602 | LocationSummary* locations = instruction->GetLocations(); |
| 4603 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4604 | |
| 4605 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4606 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4607 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4608 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4609 | } else { |
| 4610 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4611 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4612 | __ jmp(slow_path->GetEntryLabel()); |
| 4613 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4614 | } |
| 4615 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4616 | } |
| 4617 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4618 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4619 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4620 | } |
| 4621 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4622 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4623 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4624 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4625 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4626 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 4627 | object_array_get_with_read_barrier |
| 4628 | ? LocationSummary::kCallOnSlowPath |
| 4629 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4630 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4631 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4632 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4633 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4634 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4635 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4636 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4637 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4638 | // The output overlaps for an object array get when read barriers |
| 4639 | // are enabled: we do not want the move to overwrite the array's |
| 4640 | // location, as we need it to emit the read barrier. |
| 4641 | locations->SetOut( |
| 4642 | Location::RequiresRegister(), |
| 4643 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4644 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4645 | } |
| 4646 | |
| 4647 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4648 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4649 | Location obj_loc = locations->InAt(0); |
| 4650 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4651 | Location index = locations->InAt(1); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4652 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4653 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4654 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4655 | DataType::Type type = instruction->GetType(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4656 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4657 | case DataType::Type::kBool: |
| 4658 | case DataType::Type::kUint8: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4659 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4660 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4661 | break; |
| 4662 | } |
| 4663 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4664 | case DataType::Type::kInt8: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4665 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4666 | __ movsxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4667 | break; |
| 4668 | } |
| 4669 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4670 | case DataType::Type::kUint16: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4671 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 4672 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 4673 | // Branch cases into compressed and uncompressed for each index's type. |
| 4674 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 4675 | NearLabel done, not_compressed; |
Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 4676 | __ testb(Address(obj, count_offset), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 4677 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 4678 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 4679 | "Expecting 0=compressed, 1=uncompressed"); |
| 4680 | __ j(kNotZero, ¬_compressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 4681 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 4682 | __ jmp(&done); |
| 4683 | __ Bind(¬_compressed); |
| 4684 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 4685 | __ Bind(&done); |
| 4686 | } else { |
| 4687 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 4688 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4689 | break; |
| 4690 | } |
| 4691 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4692 | case DataType::Type::kInt16: { |
| 4693 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| 4694 | __ movsxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 4695 | break; |
| 4696 | } |
| 4697 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4698 | case DataType::Type::kInt32: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4699 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4700 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4701 | break; |
| 4702 | } |
| 4703 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4704 | case DataType::Type::kReference: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4705 | static_assert( |
| 4706 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4707 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4708 | // /* HeapReference<Object> */ out = |
| 4709 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4710 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4711 | // Note that a potential implicit null check is handled in this |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 4712 | // CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier call. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4713 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4714 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4715 | } else { |
| 4716 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4717 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 4718 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4719 | // If read barriers are enabled, emit read barriers other than |
| 4720 | // Baker's using a slow path (and also unpoison the loaded |
| 4721 | // reference, if heap poisoning is enabled). |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4722 | if (index.IsConstant()) { |
| 4723 | uint32_t offset = |
| 4724 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4725 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4726 | } else { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4727 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4728 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4729 | } |
| 4730 | } |
| 4731 | break; |
| 4732 | } |
| 4733 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4734 | case DataType::Type::kInt64: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4735 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4736 | __ movq(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4737 | break; |
| 4738 | } |
| 4739 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4740 | case DataType::Type::kFloat32: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4741 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4742 | __ movss(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4743 | break; |
| 4744 | } |
| 4745 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4746 | case DataType::Type::kFloat64: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4747 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4748 | __ movsd(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4749 | break; |
| 4750 | } |
| 4751 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4752 | case DataType::Type::kVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4753 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4754 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4755 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4756 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4757 | if (type == DataType::Type::kReference) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4758 | // Potential implicit null checks, in the case of reference |
| 4759 | // arrays, are handled in the previous switch statement. |
| 4760 | } else { |
| 4761 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4762 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4763 | } |
| 4764 | |
| 4765 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4766 | DataType::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4767 | |
| 4768 | bool needs_write_barrier = |
| 4769 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4770 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4771 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4772 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4773 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 4774 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4775 | LocationSummary::kCallOnSlowPath : |
| 4776 | LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4777 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4778 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4779 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4780 | if (DataType::IsFloatingPointType(value_type)) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4781 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4782 | } else { |
| 4783 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4784 | } |
| 4785 | |
| 4786 | if (needs_write_barrier) { |
| 4787 | // Temporary registers for the write barrier. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4788 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4789 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4790 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4791 | } |
| 4792 | |
| 4793 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4794 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4795 | Location array_loc = locations->InAt(0); |
| 4796 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4797 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4798 | Location value = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4799 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4800 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4801 | bool needs_write_barrier = |
| 4802 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4803 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4804 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4805 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4806 | |
| 4807 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4808 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4809 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4810 | case DataType::Type::kInt8: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4811 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4812 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4813 | if (value.IsRegister()) { |
| 4814 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4815 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4816 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4817 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4818 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4819 | break; |
| 4820 | } |
| 4821 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4822 | case DataType::Type::kUint16: |
| 4823 | case DataType::Type::kInt16: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4824 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4825 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4826 | if (value.IsRegister()) { |
| 4827 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4828 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4829 | DCHECK(value.IsConstant()) << value; |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4830 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4831 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4832 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4833 | break; |
| 4834 | } |
| 4835 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4836 | case DataType::Type::kReference: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4837 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4838 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4839 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4840 | if (!value.IsRegister()) { |
| 4841 | // Just setting null. |
| 4842 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4843 | DCHECK(value.IsConstant()) << value; |
| 4844 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4845 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4846 | DCHECK(!needs_write_barrier); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4847 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4848 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4849 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4850 | |
| 4851 | DCHECK(needs_write_barrier); |
| 4852 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4853 | // We cannot use a NearLabel for `done`, as its range may be too |
| 4854 | // short when Baker read barriers are enabled. |
| 4855 | Label done; |
| 4856 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4857 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4858 | Location temp_loc = locations->GetTemp(0); |
| 4859 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4860 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4861 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86_64(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4862 | codegen_->AddSlowPath(slow_path); |
| 4863 | if (instruction->GetValueCanBeNull()) { |
| 4864 | __ testl(register_value, register_value); |
| 4865 | __ j(kNotEqual, ¬_null); |
| 4866 | __ movl(address, Immediate(0)); |
| 4867 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4868 | __ jmp(&done); |
| 4869 | __ Bind(¬_null); |
| 4870 | } |
| 4871 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4872 | // Note that when Baker read barriers are enabled, the type |
| 4873 | // checks are performed without read barriers. This is fine, |
| 4874 | // even in the case where a class object is in the from-space |
| 4875 | // after the flip, as a comparison involving such a type would |
| 4876 | // not produce a false positive; it may of course produce a |
| 4877 | // false negative, in which case we would take the ArraySet |
| 4878 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4879 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4880 | // /* HeapReference<Class> */ temp = array->klass_ |
| 4881 | __ movl(temp, Address(array, class_offset)); |
| 4882 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4883 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4884 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4885 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4886 | __ movl(temp, Address(temp, component_offset)); |
| 4887 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 4888 | // nor the object reference in `register_value->klass`, as |
| 4889 | // we are comparing two poisoned references. |
| 4890 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4891 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4892 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4893 | __ j(kEqual, &do_put); |
| 4894 | // If heap poisoning is enabled, the `temp` reference has |
| 4895 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4896 | __ MaybeUnpoisonHeapReference(temp); |
| 4897 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4898 | // If heap poisoning is enabled, no need to unpoison the |
| 4899 | // heap reference loaded below, as it is only used for a |
| 4900 | // comparison with null. |
| 4901 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 4902 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4903 | __ Bind(&do_put); |
| 4904 | } else { |
| 4905 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4906 | } |
| 4907 | } |
| 4908 | |
| 4909 | if (kPoisonHeapReferences) { |
| 4910 | __ movl(temp, register_value); |
| 4911 | __ PoisonHeapReference(temp); |
| 4912 | __ movl(address, temp); |
| 4913 | } else { |
| 4914 | __ movl(address, register_value); |
| 4915 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4916 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4917 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4918 | } |
| 4919 | |
| 4920 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4921 | codegen_->MarkGCCard( |
| 4922 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4923 | __ Bind(&done); |
| 4924 | |
| 4925 | if (slow_path != nullptr) { |
| 4926 | __ Bind(slow_path->GetExitLabel()); |
| 4927 | } |
| 4928 | |
| 4929 | break; |
| 4930 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4931 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4932 | case DataType::Type::kInt32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4933 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4934 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4935 | if (value.IsRegister()) { |
| 4936 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 4937 | } else { |
| 4938 | DCHECK(value.IsConstant()) << value; |
| 4939 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4940 | __ movl(address, Immediate(v)); |
| 4941 | } |
| 4942 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4943 | break; |
| 4944 | } |
| 4945 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4946 | case DataType::Type::kInt64: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4947 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4948 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4949 | if (value.IsRegister()) { |
| 4950 | __ movq(address, value.AsRegister<CpuRegister>()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4951 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4952 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4953 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4954 | Address address_high = |
| 4955 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4956 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4957 | } |
| 4958 | break; |
| 4959 | } |
| 4960 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4961 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4962 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4963 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4964 | if (value.IsFpuRegister()) { |
| 4965 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 4966 | } else { |
| 4967 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4968 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4969 | __ movl(address, Immediate(v)); |
| 4970 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4971 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4972 | break; |
| 4973 | } |
| 4974 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4975 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4976 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4977 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4978 | if (value.IsFpuRegister()) { |
| 4979 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 4980 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4981 | } else { |
| 4982 | int64_t v = |
| 4983 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4984 | Address address_high = |
| 4985 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4986 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 4987 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4988 | break; |
| 4989 | } |
| 4990 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4991 | case DataType::Type::kVoid: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4992 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4993 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4994 | } |
| 4995 | } |
| 4996 | |
| 4997 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4998 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4999 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5000 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5001 | if (!instruction->IsEmittedAtUseSite()) { |
| 5002 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5003 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5004 | } |
| 5005 | |
| 5006 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5007 | if (instruction->IsEmittedAtUseSite()) { |
| 5008 | return; |
| 5009 | } |
| 5010 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5011 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5012 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5013 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5014 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5015 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5016 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5017 | // Mask out most significant bit in case the array is String's array of char. |
| 5018 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5019 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5020 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5021 | } |
| 5022 | |
| 5023 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5024 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5025 | InvokeRuntimeCallingConvention calling_convention; |
| 5026 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5027 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5028 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5029 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5030 | HInstruction* length = instruction->InputAt(1); |
| 5031 | if (!length->IsEmittedAtUseSite()) { |
| 5032 | locations->SetInAt(1, Location::RegisterOrConstant(length)); |
| 5033 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5034 | } |
| 5035 | |
| 5036 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5037 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5038 | Location index_loc = locations->InAt(0); |
| 5039 | Location length_loc = locations->InAt(1); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5040 | SlowPathCode* slow_path = |
| 5041 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5042 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5043 | if (length_loc.IsConstant()) { |
| 5044 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5045 | if (index_loc.IsConstant()) { |
| 5046 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5047 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5048 | if (index < 0 || index >= length) { |
| 5049 | codegen_->AddSlowPath(slow_path); |
| 5050 | __ jmp(slow_path->GetEntryLabel()); |
| 5051 | } else { |
| 5052 | // Some optimization after BCE may have generated this, and we should not |
| 5053 | // generate a bounds check if it is a valid range. |
| 5054 | } |
| 5055 | return; |
| 5056 | } |
| 5057 | |
| 5058 | // We have to reverse the jump condition because the length is the constant. |
| 5059 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 5060 | __ cmpl(index_reg, Immediate(length)); |
| 5061 | codegen_->AddSlowPath(slow_path); |
| 5062 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5063 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5064 | HInstruction* array_length = instruction->InputAt(1); |
| 5065 | if (array_length->IsEmittedAtUseSite()) { |
| 5066 | // Address the length field in the array. |
| 5067 | DCHECK(array_length->IsArrayLength()); |
| 5068 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5069 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5070 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5071 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5072 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5073 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5074 | CpuRegister length_reg = CpuRegister(TMP); |
| 5075 | __ movl(length_reg, array_len); |
| 5076 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5077 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5078 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5079 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5080 | // Checking the bound for general case: |
| 5081 | // Array of char or String's array when the compression feature off. |
| 5082 | if (index_loc.IsConstant()) { |
| 5083 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5084 | __ cmpl(array_len, Immediate(value)); |
| 5085 | } else { |
| 5086 | __ cmpl(array_len, index_loc.AsRegister<CpuRegister>()); |
| 5087 | } |
| 5088 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5089 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5090 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5091 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5092 | } |
| 5093 | codegen_->AddSlowPath(slow_path); |
| 5094 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5095 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5096 | } |
| 5097 | |
| 5098 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5099 | CpuRegister card, |
| 5100 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5101 | CpuRegister value, |
| 5102 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5103 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5104 | if (value_can_be_null) { |
| 5105 | __ testl(value, value); |
| 5106 | __ j(kEqual, &is_null); |
| 5107 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5108 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5109 | /* no_rip */ true)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5110 | __ movq(temp, object); |
| 5111 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5112 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5113 | if (value_can_be_null) { |
| 5114 | __ Bind(&is_null); |
| 5115 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5116 | } |
| 5117 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5118 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5119 | LOG(FATAL) << "Unimplemented"; |
| 5120 | } |
| 5121 | |
| 5122 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5123 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5124 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5125 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5126 | // The back edge will generate the suspend check. |
| 5127 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5128 | } |
| 5129 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5130 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5131 | } |
| 5132 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5133 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5134 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5135 | instruction, LocationSummary::kCallOnSlowPath); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 5136 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5137 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5138 | // registers in full width (since the runtime only saves/restores lower part). |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5139 | locations->SetCustomSlowPathCallerSaves( |
| 5140 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5141 | } |
| 5142 | |
| 5143 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5144 | HBasicBlock* block = instruction->GetBlock(); |
| 5145 | if (block->GetLoopInformation() != nullptr) { |
| 5146 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5147 | // The back edge will generate the suspend check. |
| 5148 | return; |
| 5149 | } |
| 5150 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5151 | // The goto will generate the suspend check. |
| 5152 | return; |
| 5153 | } |
| 5154 | GenerateSuspendCheck(instruction, nullptr); |
| 5155 | } |
| 5156 | |
| 5157 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5158 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5159 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5160 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5161 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5162 | slow_path = |
| 5163 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86_64(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5164 | instruction->SetSlowPath(slow_path); |
| 5165 | codegen_->AddSlowPath(slow_path); |
| 5166 | if (successor != nullptr) { |
| 5167 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5168 | } |
| 5169 | } else { |
| 5170 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5171 | } |
| 5172 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5173 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5174 | /* no_rip */ true), |
| 5175 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5176 | if (successor == nullptr) { |
| 5177 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5178 | __ Bind(slow_path->GetReturnLabel()); |
| 5179 | } else { |
| 5180 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5181 | __ jmp(slow_path->GetEntryLabel()); |
| 5182 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5183 | } |
| 5184 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5185 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5186 | return codegen_->GetAssembler(); |
| 5187 | } |
| 5188 | |
| 5189 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5190 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5191 | Location source = move->GetSource(); |
| 5192 | Location destination = move->GetDestination(); |
| 5193 | |
| 5194 | if (source.IsRegister()) { |
| 5195 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5196 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5197 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5198 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5199 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5200 | } else { |
| 5201 | DCHECK(destination.IsDoubleStackSlot()); |
| 5202 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5203 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5204 | } |
| 5205 | } else if (source.IsStackSlot()) { |
| 5206 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5207 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5208 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5209 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5210 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5211 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5212 | } else { |
| 5213 | DCHECK(destination.IsStackSlot()); |
| 5214 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5215 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5216 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5217 | } else if (source.IsDoubleStackSlot()) { |
| 5218 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5219 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5220 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5221 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5222 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5223 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5224 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5225 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5226 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5227 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5228 | } |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5229 | } else if (source.IsSIMDStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5230 | if (destination.IsFpuRegister()) { |
| 5231 | __ movups(destination.AsFpuRegister<XmmRegister>(), |
| 5232 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5233 | } else { |
| 5234 | DCHECK(destination.IsSIMDStackSlot()); |
| 5235 | size_t high = kX86_64WordSize; |
| 5236 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5237 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5238 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex() + high)); |
| 5239 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex() + high), CpuRegister(TMP)); |
| 5240 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5241 | } else if (source.IsConstant()) { |
| 5242 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5243 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5244 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5245 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5246 | if (value == 0) { |
| 5247 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5248 | } else { |
| 5249 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5250 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5251 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5252 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5253 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5254 | } |
| 5255 | } else if (constant->IsLongConstant()) { |
| 5256 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5257 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5258 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5259 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5260 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5261 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5262 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5263 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5264 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5265 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5266 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5267 | codegen_->Load32BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5268 | } else { |
| 5269 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5270 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5271 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5272 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5273 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5274 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5275 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5276 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5277 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5278 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5279 | codegen_->Load64BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5280 | } else { |
| 5281 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5282 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5283 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5284 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5285 | } else if (source.IsFpuRegister()) { |
| 5286 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5287 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5288 | } else if (destination.IsStackSlot()) { |
| 5289 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5290 | source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5291 | } else if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5292 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5293 | source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5294 | } else { |
| 5295 | DCHECK(destination.IsSIMDStackSlot()); |
| 5296 | __ movups(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 5297 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5298 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5299 | } |
| 5300 | } |
| 5301 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5302 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5303 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5304 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5305 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5306 | } |
| 5307 | |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5308 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg1, CpuRegister reg2) { |
| 5309 | __ movq(CpuRegister(TMP), reg1); |
| 5310 | __ movq(reg1, reg2); |
| 5311 | __ movq(reg2, CpuRegister(TMP)); |
| 5312 | } |
| 5313 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5314 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5315 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5316 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5317 | __ movq(reg, CpuRegister(TMP)); |
| 5318 | } |
| 5319 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5320 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5321 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5322 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5323 | __ movd(reg, CpuRegister(TMP)); |
| 5324 | } |
| 5325 | |
| 5326 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5327 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5328 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5329 | __ movd(reg, CpuRegister(TMP)); |
| 5330 | } |
| 5331 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5332 | void ParallelMoveResolverX86_64::Exchange128(XmmRegister reg, int mem) { |
| 5333 | size_t extra_slot = 2 * kX86_64WordSize; |
| 5334 | __ subq(CpuRegister(RSP), Immediate(extra_slot)); |
| 5335 | __ movups(Address(CpuRegister(RSP), 0), XmmRegister(reg)); |
| 5336 | ExchangeMemory64(0, mem + extra_slot, 2); |
| 5337 | __ movups(XmmRegister(reg), Address(CpuRegister(RSP), 0)); |
| 5338 | __ addq(CpuRegister(RSP), Immediate(extra_slot)); |
| 5339 | } |
| 5340 | |
| 5341 | void ParallelMoveResolverX86_64::ExchangeMemory32(int mem1, int mem2) { |
| 5342 | ScratchRegisterScope ensure_scratch( |
| 5343 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5344 | |
| 5345 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5346 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5347 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5348 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5349 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5350 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5351 | CpuRegister(ensure_scratch.GetRegister())); |
| 5352 | } |
| 5353 | |
| 5354 | void ParallelMoveResolverX86_64::ExchangeMemory64(int mem1, int mem2, int num_of_qwords) { |
| 5355 | ScratchRegisterScope ensure_scratch( |
| 5356 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5357 | |
| 5358 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5359 | |
| 5360 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 5361 | for (int i = 0; i < num_of_qwords; i++) { |
| 5362 | __ movq(CpuRegister(TMP), |
| 5363 | Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5364 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5365 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5366 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), |
| 5367 | CpuRegister(TMP)); |
| 5368 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5369 | CpuRegister(ensure_scratch.GetRegister())); |
| 5370 | stack_offset += kX86_64WordSize; |
| 5371 | } |
| 5372 | } |
| 5373 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5374 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5375 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5376 | Location source = move->GetSource(); |
| 5377 | Location destination = move->GetDestination(); |
| 5378 | |
| 5379 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5380 | Exchange64(source.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5381 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5382 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5383 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5384 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5385 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5386 | ExchangeMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5387 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5388 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5389 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5390 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5391 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5392 | ExchangeMemory64(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5393 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5394 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5395 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5396 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5397 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5398 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5399 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5400 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5401 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5402 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5403 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5404 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5405 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 5406 | ExchangeMemory64(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 5407 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 5408 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5409 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 5410 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5411 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5412 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5413 | } |
| 5414 | } |
| 5415 | |
| 5416 | |
| 5417 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5418 | __ pushq(CpuRegister(reg)); |
| 5419 | } |
| 5420 | |
| 5421 | |
| 5422 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5423 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5424 | } |
| 5425 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5426 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5427 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 5428 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 5429 | const size_t status_byte_offset = |
| 5430 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 5431 | constexpr uint32_t shifted_initialized_value = |
| 5432 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
| 5433 | |
| 5434 | __ cmpb(Address(class_reg, status_byte_offset), Immediate(shifted_initialized_value)); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 5435 | __ j(kBelow, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5436 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5437 | // No need for memory fence, thanks to the x86-64 memory model. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5438 | } |
| 5439 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5440 | HLoadClass::LoadKind CodeGeneratorX86_64::GetSupportedLoadClassKind( |
| 5441 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5442 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5443 | case HLoadClass::LoadKind::kInvalid: |
| 5444 | LOG(FATAL) << "UNREACHABLE"; |
| 5445 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5446 | case HLoadClass::LoadKind::kReferrersClass: |
| 5447 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5448 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5449 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5450 | case HLoadClass::LoadKind::kBssEntry: |
| 5451 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5452 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5453 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5454 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5455 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5456 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5457 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5458 | break; |
| 5459 | } |
| 5460 | return desired_class_load_kind; |
| 5461 | } |
| 5462 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5463 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5464 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5465 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5466 | // Custom calling convention: RAX serves as both input and output. |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5467 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5468 | cls, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5469 | Location::RegisterLocation(RAX), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5470 | Location::RegisterLocation(RAX)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5471 | return; |
| 5472 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5473 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5474 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5475 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5476 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5477 | ? LocationSummary::kCallOnSlowPath |
| 5478 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5479 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5480 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5481 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5482 | } |
| 5483 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5484 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5485 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5486 | } |
| 5487 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5488 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 5489 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5490 | // Rely on the type resolution and/or initialization to save everything. |
| 5491 | // Custom calling convention: RAX serves as both input and output. |
| 5492 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5493 | caller_saves.Add(Location::RegisterLocation(RAX)); |
| 5494 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5495 | } else { |
| 5496 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5497 | } |
| 5498 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5499 | } |
| 5500 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5501 | Label* CodeGeneratorX86_64::NewJitRootClassPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5502 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5503 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5504 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5505 | // Add a patch entry and return the label. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5506 | jit_class_patches_.emplace_back(dex_file, type_index.index_); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5507 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 5508 | return &info->label; |
| 5509 | } |
| 5510 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5511 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5512 | // move. |
| 5513 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5514 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5515 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5516 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5517 | return; |
| 5518 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5519 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5520 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5521 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5522 | Location out_loc = locations->Out(); |
| 5523 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5524 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5525 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5526 | ? kWithoutReadBarrier |
| 5527 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5528 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5529 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5530 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5531 | DCHECK(!cls->CanCallRuntime()); |
| 5532 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5533 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5534 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5535 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5536 | cls, |
| 5537 | out_loc, |
| 5538 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5539 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5540 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5541 | break; |
| 5542 | } |
| 5543 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5544 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5545 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5546 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5547 | codegen_->RecordBootTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5548 | break; |
| 5549 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5550 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5551 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5552 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 5553 | DCHECK_NE(address, 0u); |
Colin Cross | 0bd9717 | 2017-03-15 16:33:27 -0700 | [diff] [blame] | 5554 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5555 | break; |
| 5556 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5557 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 5558 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 5559 | __ movl(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| 5560 | codegen_->RecordBootTypePatch(cls); |
| 5561 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 5562 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 5563 | ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex()))); |
| 5564 | if (masked_hash != 0) { |
| 5565 | __ subl(out, Immediate(masked_hash)); |
| 5566 | } |
| 5567 | break; |
| 5568 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5569 | case HLoadClass::LoadKind::kBssEntry: { |
| 5570 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5571 | /* no_rip */ false); |
| 5572 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 5573 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
| 5574 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| 5575 | generate_null_check = true; |
| 5576 | break; |
| 5577 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5578 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5579 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5580 | /* no_rip */ true); |
| 5581 | Label* fixup_label = |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5582 | codegen_->NewJitRootClassPatch(cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5583 | // /* GcRoot<mirror::Class> */ out = *address |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5584 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5585 | break; |
| 5586 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5587 | default: |
| 5588 | LOG(FATAL) << "Unexpected load kind: " << cls->GetLoadKind(); |
| 5589 | UNREACHABLE(); |
| 5590 | } |
| 5591 | |
| 5592 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5593 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5594 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86_64( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5595 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5596 | codegen_->AddSlowPath(slow_path); |
| 5597 | if (generate_null_check) { |
| 5598 | __ testl(out, out); |
| 5599 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5600 | } |
| 5601 | if (cls->MustGenerateClinitCheck()) { |
| 5602 | GenerateClassInitializationCheck(slow_path, out); |
| 5603 | } else { |
| 5604 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5605 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5606 | } |
| 5607 | } |
| 5608 | |
| 5609 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 5610 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5611 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5612 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5613 | if (check->HasUses()) { |
| 5614 | locations->SetOut(Location::SameAsFirstInput()); |
| 5615 | } |
| 5616 | } |
| 5617 | |
| 5618 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5619 | // We assume the class to not be null. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5620 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5621 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5622 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5623 | GenerateClassInitializationCheck(slow_path, |
| 5624 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5625 | } |
| 5626 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5627 | HLoadString::LoadKind CodeGeneratorX86_64::GetSupportedLoadStringKind( |
| 5628 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5629 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5630 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5631 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5632 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5633 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5634 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5635 | case HLoadString::LoadKind::kJitTableAddress: |
| 5636 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5637 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5638 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5639 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5640 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5641 | } |
| 5642 | return desired_string_load_kind; |
| 5643 | } |
| 5644 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5645 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5646 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5647 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5648 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5649 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 5650 | } else { |
| 5651 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5652 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5653 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5654 | // Rely on the pResolveString to save everything. |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5655 | // Custom calling convention: RAX serves as both input and output. |
| 5656 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5657 | caller_saves.Add(Location::RegisterLocation(RAX)); |
| 5658 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5659 | } else { |
| 5660 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5661 | } |
| 5662 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5663 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5664 | } |
| 5665 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5666 | Label* CodeGeneratorX86_64::NewJitRootStringPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5667 | dex::StringIndex string_index, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5668 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5669 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5670 | // Add a patch entry and return the label. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5671 | jit_string_patches_.emplace_back(dex_file, string_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5672 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 5673 | return &info->label; |
| 5674 | } |
| 5675 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5676 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5677 | // move. |
| 5678 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5679 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5680 | Location out_loc = locations->Out(); |
| 5681 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5682 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5683 | switch (load->GetLoadKind()) { |
| 5684 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5685 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5686 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5687 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5688 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5689 | } |
| 5690 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5691 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5692 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5693 | DCHECK_NE(address, 0u); |
Colin Cross | 0bd9717 | 2017-03-15 16:33:27 -0700 | [diff] [blame] | 5694 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5695 | return; |
| 5696 | } |
| 5697 | case HLoadString::LoadKind::kBootImageInternTable: { |
| 5698 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 5699 | __ movl(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| 5700 | codegen_->RecordBootStringPatch(load); |
| 5701 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5702 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5703 | case HLoadString::LoadKind::kBssEntry: { |
| 5704 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5705 | /* no_rip */ false); |
| 5706 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
| 5707 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5708 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5709 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86_64(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5710 | codegen_->AddSlowPath(slow_path); |
| 5711 | __ testl(out, out); |
| 5712 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5713 | __ Bind(slow_path->GetExitLabel()); |
| 5714 | return; |
| 5715 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5716 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5717 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5718 | /* no_rip */ true); |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5719 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
| 5720 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5721 | // /* GcRoot<mirror::String> */ out = *address |
| 5722 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 5723 | return; |
| 5724 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5725 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5726 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5727 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5728 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5729 | // 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] | 5730 | // Custom calling convention: RAX serves as both input and output. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5731 | __ movl(CpuRegister(RAX), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5732 | codegen_->InvokeRuntime(kQuickResolveString, |
| 5733 | load, |
| 5734 | load->GetDexPc()); |
| 5735 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5736 | } |
| 5737 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5738 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5739 | return Address::Absolute(Thread::ExceptionOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5740 | /* no_rip */ true); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5741 | } |
| 5742 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5743 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 5744 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5745 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5746 | locations->SetOut(Location::RequiresRegister()); |
| 5747 | } |
| 5748 | |
| 5749 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5750 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 5751 | } |
| 5752 | |
| 5753 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5754 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5755 | } |
| 5756 | |
| 5757 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5758 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5759 | } |
| 5760 | |
| 5761 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5762 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5763 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5764 | InvokeRuntimeCallingConvention calling_convention; |
| 5765 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5766 | } |
| 5767 | |
| 5768 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 5769 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5770 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5771 | } |
| 5772 | |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5773 | static bool CheckCastTypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 5774 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 5775 | // We need a temporary for holding the iftable length. |
| 5776 | return true; |
| 5777 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5778 | return kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5779 | !kUseBakerReadBarrier && |
| 5780 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5781 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5782 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5783 | } |
| 5784 | |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5785 | static bool InstanceOfTypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5786 | return kEmitCompilerReadBarrier && |
| 5787 | !kUseBakerReadBarrier && |
| 5788 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5789 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5790 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5791 | } |
| 5792 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5793 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5794 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5795 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5796 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5797 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5798 | case TypeCheckKind::kExactCheck: |
| 5799 | case TypeCheckKind::kAbstractClassCheck: |
| 5800 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 5801 | case TypeCheckKind::kArrayObjectCheck: { |
| 5802 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 5803 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 5804 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5805 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 5806 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5807 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5808 | case TypeCheckKind::kUnresolvedCheck: |
| 5809 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5810 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5811 | break; |
| 5812 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5813 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5814 | LocationSummary* locations = |
| 5815 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5816 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5817 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5818 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5819 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5820 | locations->SetInAt(1, Location::Any()); |
| 5821 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 5822 | locations->SetOut(Location::RequiresRegister()); |
| 5823 | // When read barriers are enabled, we need a temporary register for |
| 5824 | // some cases. |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5825 | if (InstanceOfTypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5826 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5827 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5828 | } |
| 5829 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5830 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5831 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5832 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5833 | Location obj_loc = locations->InAt(0); |
| 5834 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5835 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5836 | Location out_loc = locations->Out(); |
| 5837 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5838 | Location maybe_temp_loc = InstanceOfTypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5839 | locations->GetTemp(0) : |
| 5840 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5841 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5842 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5843 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5844 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5845 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5846 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5847 | |
| 5848 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5849 | // Avoid null check if we know obj is not null. |
| 5850 | if (instruction->MustDoNullCheck()) { |
| 5851 | __ testl(obj, obj); |
| 5852 | __ j(kEqual, &zero); |
| 5853 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5854 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5855 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5856 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 5857 | ReadBarrierOption read_barrier_option = |
| 5858 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5859 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5860 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5861 | out_loc, |
| 5862 | obj_loc, |
| 5863 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 5864 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5865 | if (cls.IsRegister()) { |
| 5866 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5867 | } else { |
| 5868 | DCHECK(cls.IsStackSlot()) << cls; |
| 5869 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5870 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5871 | if (zero.IsLinked()) { |
| 5872 | // Classes must be equal for the instanceof to succeed. |
| 5873 | __ j(kNotEqual, &zero); |
| 5874 | __ movl(out, Immediate(1)); |
| 5875 | __ jmp(&done); |
| 5876 | } else { |
| 5877 | __ setcc(kEqual, out); |
| 5878 | // setcc only sets the low byte. |
| 5879 | __ andl(out, Immediate(1)); |
| 5880 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5881 | break; |
| 5882 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5883 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5884 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 5885 | ReadBarrierOption read_barrier_option = |
| 5886 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5887 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5888 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5889 | out_loc, |
| 5890 | obj_loc, |
| 5891 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 5892 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5893 | // If the class is abstract, we eagerly fetch the super class of the |
| 5894 | // object to avoid doing a comparison we know will fail. |
| 5895 | NearLabel loop, success; |
| 5896 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5897 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5898 | GenerateReferenceLoadOneRegister(instruction, |
| 5899 | out_loc, |
| 5900 | super_offset, |
| 5901 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 5902 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5903 | __ testl(out, out); |
| 5904 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5905 | __ j(kEqual, &done); |
| 5906 | if (cls.IsRegister()) { |
| 5907 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5908 | } else { |
| 5909 | DCHECK(cls.IsStackSlot()) << cls; |
| 5910 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5911 | } |
| 5912 | __ j(kNotEqual, &loop); |
| 5913 | __ movl(out, Immediate(1)); |
| 5914 | if (zero.IsLinked()) { |
| 5915 | __ jmp(&done); |
| 5916 | } |
| 5917 | break; |
| 5918 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5919 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5920 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 5921 | ReadBarrierOption read_barrier_option = |
| 5922 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5923 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5924 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5925 | out_loc, |
| 5926 | obj_loc, |
| 5927 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 5928 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5929 | // Walk over the class hierarchy to find a match. |
| 5930 | NearLabel loop, success; |
| 5931 | __ Bind(&loop); |
| 5932 | if (cls.IsRegister()) { |
| 5933 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5934 | } else { |
| 5935 | DCHECK(cls.IsStackSlot()) << cls; |
| 5936 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5937 | } |
| 5938 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5939 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5940 | GenerateReferenceLoadOneRegister(instruction, |
| 5941 | out_loc, |
| 5942 | super_offset, |
| 5943 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 5944 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5945 | __ testl(out, out); |
| 5946 | __ j(kNotEqual, &loop); |
| 5947 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5948 | __ jmp(&done); |
| 5949 | __ Bind(&success); |
| 5950 | __ movl(out, Immediate(1)); |
| 5951 | if (zero.IsLinked()) { |
| 5952 | __ jmp(&done); |
| 5953 | } |
| 5954 | break; |
| 5955 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5956 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5957 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 5958 | ReadBarrierOption read_barrier_option = |
| 5959 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5960 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5961 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5962 | out_loc, |
| 5963 | obj_loc, |
| 5964 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 5965 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5966 | // Do an exact check. |
| 5967 | NearLabel exact_check; |
| 5968 | if (cls.IsRegister()) { |
| 5969 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5970 | } else { |
| 5971 | DCHECK(cls.IsStackSlot()) << cls; |
| 5972 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5973 | } |
| 5974 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5975 | // 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] | 5976 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5977 | GenerateReferenceLoadOneRegister(instruction, |
| 5978 | out_loc, |
| 5979 | component_offset, |
| 5980 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 5981 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5982 | __ testl(out, out); |
| 5983 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5984 | __ j(kEqual, &done); |
| 5985 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5986 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5987 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5988 | __ movl(out, Immediate(1)); |
| 5989 | __ jmp(&done); |
| 5990 | break; |
| 5991 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5992 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5993 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5994 | // No read barrier since the slow path will retry upon failure. |
| 5995 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5996 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5997 | out_loc, |
| 5998 | obj_loc, |
| 5999 | class_offset, |
| 6000 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6001 | if (cls.IsRegister()) { |
| 6002 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6003 | } else { |
| 6004 | DCHECK(cls.IsStackSlot()) << cls; |
| 6005 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6006 | } |
| 6007 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6008 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
| 6009 | instruction, /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6010 | codegen_->AddSlowPath(slow_path); |
| 6011 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6012 | __ movl(out, Immediate(1)); |
| 6013 | if (zero.IsLinked()) { |
| 6014 | __ jmp(&done); |
| 6015 | } |
| 6016 | break; |
| 6017 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6018 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6019 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6020 | case TypeCheckKind::kInterfaceCheck: { |
| 6021 | // 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] | 6022 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6023 | // cases. |
| 6024 | // |
| 6025 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6026 | // entry point without resorting to a type checking slow path |
| 6027 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6028 | // require to assign fixed registers for the inputs of this |
| 6029 | // HInstanceOf instruction (following the runtime calling |
| 6030 | // convention), which might be cluttered by the potential first |
| 6031 | // read barrier emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6032 | // |
| 6033 | // TODO: Introduce a new runtime entry point taking the object |
| 6034 | // to test (instead of its class) as argument, and let it deal |
| 6035 | // with the read barrier issues. This will let us refactor this |
| 6036 | // case of the `switch` code as it was previously (with a direct |
| 6037 | // call to the runtime not using a type checking slow path). |
| 6038 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6039 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6040 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
| 6041 | instruction, /* is_fatal */ false); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6042 | codegen_->AddSlowPath(slow_path); |
| 6043 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6044 | if (zero.IsLinked()) { |
| 6045 | __ jmp(&done); |
| 6046 | } |
| 6047 | break; |
| 6048 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6049 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6050 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6051 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6052 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6053 | __ xorl(out, out); |
| 6054 | } |
| 6055 | |
| 6056 | if (done.IsLinked()) { |
| 6057 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6058 | } |
| 6059 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6060 | if (slow_path != nullptr) { |
| 6061 | __ Bind(slow_path->GetExitLabel()); |
| 6062 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6063 | } |
| 6064 | |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6065 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6066 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6067 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6068 | LocationSummary* locations = |
| 6069 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6070 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6071 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6072 | // Require a register for the interface check since there is a loop that compares the class to |
| 6073 | // a memory address. |
| 6074 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6075 | } else { |
| 6076 | locations->SetInAt(1, Location::Any()); |
| 6077 | } |
| 6078 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6079 | // Note that TypeCheckSlowPathX86_64 uses this "temp" register too. |
| 6080 | locations->AddTemp(Location::RequiresRegister()); |
| 6081 | // When read barriers are enabled, we need an additional temporary |
| 6082 | // register for some cases. |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6083 | if (CheckCastTypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6084 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6085 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6086 | } |
| 6087 | |
| 6088 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6089 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6090 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6091 | Location obj_loc = locations->InAt(0); |
| 6092 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6093 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6094 | Location temp_loc = locations->GetTemp(0); |
| 6095 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6096 | Location maybe_temp2_loc = CheckCastTypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6097 | locations->GetTemp(1) : |
| 6098 | Location::NoLocation(); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6099 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6100 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6101 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6102 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6103 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6104 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6105 | const uint32_t object_array_data_offset = |
| 6106 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6107 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6108 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6109 | SlowPathCode* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6110 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
| 6111 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6112 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6113 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6114 | |
| 6115 | NearLabel done; |
| 6116 | // Avoid null check if we know obj is not null. |
| 6117 | if (instruction->MustDoNullCheck()) { |
| 6118 | __ testl(obj, obj); |
| 6119 | __ j(kEqual, &done); |
| 6120 | } |
| 6121 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6122 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6123 | case TypeCheckKind::kExactCheck: |
| 6124 | case TypeCheckKind::kArrayCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6125 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6126 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6127 | temp_loc, |
| 6128 | obj_loc, |
| 6129 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6130 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6131 | if (cls.IsRegister()) { |
| 6132 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6133 | } else { |
| 6134 | DCHECK(cls.IsStackSlot()) << cls; |
| 6135 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6136 | } |
| 6137 | // Jump to slow path for throwing the exception or doing a |
| 6138 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6139 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6140 | break; |
| 6141 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6142 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6143 | case TypeCheckKind::kAbstractClassCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6144 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6145 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6146 | temp_loc, |
| 6147 | obj_loc, |
| 6148 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6149 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6150 | // If the class is abstract, we eagerly fetch the super class of the |
| 6151 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6152 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6153 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6154 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6155 | GenerateReferenceLoadOneRegister(instruction, |
| 6156 | temp_loc, |
| 6157 | super_offset, |
| 6158 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6159 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6160 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6161 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6162 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6163 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6164 | // Otherwise, compare the classes. |
| 6165 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6166 | if (cls.IsRegister()) { |
| 6167 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6168 | } else { |
| 6169 | DCHECK(cls.IsStackSlot()) << cls; |
| 6170 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6171 | } |
| 6172 | __ j(kNotEqual, &loop); |
| 6173 | break; |
| 6174 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6175 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6176 | case TypeCheckKind::kClassHierarchyCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6177 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6178 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6179 | temp_loc, |
| 6180 | obj_loc, |
| 6181 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6182 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6183 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6184 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6185 | __ Bind(&loop); |
| 6186 | if (cls.IsRegister()) { |
| 6187 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6188 | } else { |
| 6189 | DCHECK(cls.IsStackSlot()) << cls; |
| 6190 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6191 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6192 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6193 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6194 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6195 | GenerateReferenceLoadOneRegister(instruction, |
| 6196 | temp_loc, |
| 6197 | super_offset, |
| 6198 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6199 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6200 | |
| 6201 | // If the class reference currently in `temp` is not null, jump |
| 6202 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6203 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6204 | __ j(kNotZero, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6205 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6206 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6207 | break; |
| 6208 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6209 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6210 | case TypeCheckKind::kArrayObjectCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6211 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6212 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6213 | temp_loc, |
| 6214 | obj_loc, |
| 6215 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6216 | kWithoutReadBarrier); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6217 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6218 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6219 | if (cls.IsRegister()) { |
| 6220 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6221 | } else { |
| 6222 | DCHECK(cls.IsStackSlot()) << cls; |
| 6223 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6224 | } |
| 6225 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6226 | |
| 6227 | // 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] | 6228 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6229 | GenerateReferenceLoadOneRegister(instruction, |
| 6230 | temp_loc, |
| 6231 | component_offset, |
| 6232 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6233 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6234 | |
| 6235 | // If the component type is not null (i.e. the object is indeed |
| 6236 | // an array), jump to label `check_non_primitive_component_type` |
| 6237 | // to further check that this component type is not a primitive |
| 6238 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6239 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6240 | // Otherwise, jump to the slow path to throw the exception. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6241 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6242 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6243 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6244 | break; |
| 6245 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6246 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6247 | case TypeCheckKind::kUnresolvedCheck: { |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6248 | // 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] | 6249 | // |
| 6250 | // We cannot directly call the CheckCast runtime entry point |
| 6251 | // without resorting to a type checking slow path here (i.e. by |
| 6252 | // calling InvokeRuntime directly), as it would require to |
| 6253 | // assign fixed registers for the inputs of this HInstanceOf |
| 6254 | // instruction (following the runtime calling convention), which |
| 6255 | // might be cluttered by the potential first read barrier |
| 6256 | // emission at the beginning of this method. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6257 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6258 | break; |
| 6259 | } |
| 6260 | |
| 6261 | case TypeCheckKind::kInterfaceCheck: |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6262 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. |
| 6263 | // We can not get false positives by doing this. |
| 6264 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6265 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6266 | temp_loc, |
| 6267 | obj_loc, |
| 6268 | class_offset, |
| 6269 | kWithoutReadBarrier); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6270 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6271 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6272 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6273 | temp_loc, |
| 6274 | temp_loc, |
| 6275 | iftable_offset, |
| 6276 | kWithoutReadBarrier); |
| 6277 | // Iftable is never null. |
| 6278 | __ movl(maybe_temp2_loc.AsRegister<CpuRegister>(), Address(temp, array_length_offset)); |
| 6279 | // Maybe poison the `cls` for direct comparison with memory. |
| 6280 | __ MaybePoisonHeapReference(cls.AsRegister<CpuRegister>()); |
| 6281 | // Loop through the iftable and check if any class matches. |
| 6282 | NearLabel start_loop; |
| 6283 | __ Bind(&start_loop); |
| 6284 | // Need to subtract first to handle the empty array case. |
| 6285 | __ subl(maybe_temp2_loc.AsRegister<CpuRegister>(), Immediate(2)); |
| 6286 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 6287 | // Go to next interface if the classes do not match. |
| 6288 | __ cmpl(cls.AsRegister<CpuRegister>(), |
| 6289 | CodeGeneratorX86_64::ArrayAddress(temp, |
| 6290 | maybe_temp2_loc, |
| 6291 | TIMES_4, |
| 6292 | object_array_data_offset)); |
| 6293 | __ j(kNotEqual, &start_loop); // Return if same class. |
| 6294 | // If `cls` was poisoned above, unpoison it. |
| 6295 | __ MaybeUnpoisonHeapReference(cls.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6296 | break; |
| 6297 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6298 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6299 | if (done.IsLinked()) { |
| 6300 | __ Bind(&done); |
| 6301 | } |
| 6302 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6303 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6304 | } |
| 6305 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6306 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6307 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6308 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6309 | InvokeRuntimeCallingConvention calling_convention; |
| 6310 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6311 | } |
| 6312 | |
| 6313 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6314 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6315 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6316 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6317 | if (instruction->IsEnter()) { |
| 6318 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6319 | } else { |
| 6320 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6321 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6322 | } |
| 6323 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6324 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6325 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6326 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6327 | |
| 6328 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6329 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6330 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6331 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 6332 | || instruction->GetResultType() == DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6333 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6334 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6335 | locations->SetOut(Location::SameAsFirstInput()); |
| 6336 | } |
| 6337 | |
| 6338 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 6339 | HandleBitwiseOperation(instruction); |
| 6340 | } |
| 6341 | |
| 6342 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 6343 | HandleBitwiseOperation(instruction); |
| 6344 | } |
| 6345 | |
| 6346 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 6347 | HandleBitwiseOperation(instruction); |
| 6348 | } |
| 6349 | |
| 6350 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6351 | LocationSummary* locations = instruction->GetLocations(); |
| 6352 | Location first = locations->InAt(0); |
| 6353 | Location second = locations->InAt(1); |
| 6354 | DCHECK(first.Equals(locations->Out())); |
| 6355 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6356 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6357 | if (second.IsRegister()) { |
| 6358 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6359 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6360 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6361 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6362 | } else { |
| 6363 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6364 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6365 | } |
| 6366 | } else if (second.IsConstant()) { |
| 6367 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 6368 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6369 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6370 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6371 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6372 | } else { |
| 6373 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6374 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6375 | } |
| 6376 | } else { |
| 6377 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 6378 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6379 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6380 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6381 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6382 | } else { |
| 6383 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6384 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6385 | } |
| 6386 | } |
| 6387 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6388 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6389 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 6390 | bool second_is_constant = false; |
| 6391 | int64_t value = 0; |
| 6392 | if (second.IsConstant()) { |
| 6393 | second_is_constant = true; |
| 6394 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6395 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6396 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6397 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6398 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6399 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6400 | if (is_int32_value) { |
| 6401 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6402 | } else { |
| 6403 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6404 | } |
| 6405 | } else if (second.IsDoubleStackSlot()) { |
| 6406 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6407 | } else { |
| 6408 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 6409 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6410 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6411 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6412 | if (is_int32_value) { |
| 6413 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6414 | } else { |
| 6415 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6416 | } |
| 6417 | } else if (second.IsDoubleStackSlot()) { |
| 6418 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6419 | } else { |
| 6420 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6421 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6422 | } else { |
| 6423 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6424 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6425 | if (is_int32_value) { |
| 6426 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6427 | } else { |
| 6428 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6429 | } |
| 6430 | } else if (second.IsDoubleStackSlot()) { |
| 6431 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6432 | } else { |
| 6433 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 6434 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6435 | } |
| 6436 | } |
| 6437 | } |
| 6438 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6439 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister( |
| 6440 | HInstruction* instruction, |
| 6441 | Location out, |
| 6442 | uint32_t offset, |
| 6443 | Location maybe_temp, |
| 6444 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6445 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6446 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6447 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6448 | if (kUseBakerReadBarrier) { |
| 6449 | // Load with fast path based Baker's read barrier. |
| 6450 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6451 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6452 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6453 | } else { |
| 6454 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6455 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6456 | // in the following move operation, as we will need it for the |
| 6457 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6458 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6459 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6460 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6461 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6462 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6463 | } |
| 6464 | } else { |
| 6465 | // Plain load with no read barrier. |
| 6466 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6467 | __ movl(out_reg, Address(out_reg, offset)); |
| 6468 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6469 | } |
| 6470 | } |
| 6471 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6472 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters( |
| 6473 | HInstruction* instruction, |
| 6474 | Location out, |
| 6475 | Location obj, |
| 6476 | uint32_t offset, |
| 6477 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6478 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6479 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6480 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6481 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6482 | if (kUseBakerReadBarrier) { |
| 6483 | // Load with fast path based Baker's read barrier. |
| 6484 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6485 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6486 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6487 | } else { |
| 6488 | // Load with slow path based read barrier. |
| 6489 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6490 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6491 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6492 | } |
| 6493 | } else { |
| 6494 | // Plain load with no read barrier. |
| 6495 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6496 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6497 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6498 | } |
| 6499 | } |
| 6500 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6501 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad( |
| 6502 | HInstruction* instruction, |
| 6503 | Location root, |
| 6504 | const Address& address, |
| 6505 | Label* fixup_label, |
| 6506 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6507 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6508 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6509 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6510 | if (kUseBakerReadBarrier) { |
| 6511 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6512 | // Baker's read barrier are used: |
| 6513 | // |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 6514 | // root = obj.field; |
| 6515 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6516 | // if (temp != null) { |
| 6517 | // root = temp(root) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6518 | // } |
| 6519 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6520 | // /* GcRoot<mirror::Object> */ root = *address |
| 6521 | __ movl(root_reg, address); |
| 6522 | if (fixup_label != nullptr) { |
| 6523 | __ Bind(fixup_label); |
| 6524 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6525 | static_assert( |
| 6526 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6527 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6528 | "have different sizes."); |
| 6529 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6530 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6531 | "have different sizes."); |
| 6532 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6533 | // Slow path marking the GC root `root`. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6534 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86_64( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6535 | instruction, root, /* unpoison_ref_before_marking */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6536 | codegen_->AddSlowPath(slow_path); |
| 6537 | |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 6538 | // Test the `Thread::Current()->pReadBarrierMarkReg ## root.reg()` entrypoint. |
| 6539 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6540 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(root.reg()); |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 6541 | __ gs()->cmpl(Address::Absolute(entry_point_offset, /* no_rip */ true), Immediate(0)); |
| 6542 | // The entrypoint is null when the GC is not marking. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6543 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6544 | __ Bind(slow_path->GetExitLabel()); |
| 6545 | } else { |
| 6546 | // GC root loaded through a slow path for read barriers other |
| 6547 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6548 | // /* GcRoot<mirror::Object>* */ root = address |
| 6549 | __ leaq(root_reg, address); |
| 6550 | if (fixup_label != nullptr) { |
| 6551 | __ Bind(fixup_label); |
| 6552 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6553 | // /* mirror::Object* */ root = root->Read() |
| 6554 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6555 | } |
| 6556 | } else { |
| 6557 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6558 | // /* GcRoot<mirror::Object> */ root = *address |
| 6559 | __ movl(root_reg, address); |
| 6560 | if (fixup_label != nullptr) { |
| 6561 | __ Bind(fixup_label); |
| 6562 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6563 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6564 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6565 | } |
| 6566 | } |
| 6567 | |
| 6568 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6569 | Location ref, |
| 6570 | CpuRegister obj, |
| 6571 | uint32_t offset, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6572 | bool needs_null_check) { |
| 6573 | DCHECK(kEmitCompilerReadBarrier); |
| 6574 | DCHECK(kUseBakerReadBarrier); |
| 6575 | |
| 6576 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6577 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6578 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6579 | } |
| 6580 | |
| 6581 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6582 | Location ref, |
| 6583 | CpuRegister obj, |
| 6584 | uint32_t data_offset, |
| 6585 | Location index, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6586 | bool needs_null_check) { |
| 6587 | DCHECK(kEmitCompilerReadBarrier); |
| 6588 | DCHECK(kUseBakerReadBarrier); |
| 6589 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 6590 | static_assert( |
| 6591 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6592 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6593 | // /* HeapReference<Object> */ ref = |
| 6594 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6595 | Address src = CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6596 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6597 | } |
| 6598 | |
| 6599 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6600 | Location ref, |
| 6601 | CpuRegister obj, |
| 6602 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6603 | bool needs_null_check, |
| 6604 | bool always_update_field, |
| 6605 | CpuRegister* temp1, |
| 6606 | CpuRegister* temp2) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6607 | DCHECK(kEmitCompilerReadBarrier); |
| 6608 | DCHECK(kUseBakerReadBarrier); |
| 6609 | |
| 6610 | // In slow path based read barriers, the read barrier call is |
| 6611 | // inserted after the original load. However, in fast path based |
| 6612 | // Baker's read barriers, we need to perform the load of |
| 6613 | // mirror::Object::monitor_ *before* the original reference load. |
| 6614 | // This load-load ordering is required by the read barrier. |
| 6615 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6616 | // |
| 6617 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6618 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6619 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 6620 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6621 | // if (is_gray) { |
| 6622 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6623 | // } |
| 6624 | // |
| 6625 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6626 | // slightly more complex as: |
| 6627 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6628 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6629 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 6630 | // 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] | 6631 | // - it performs additional checks that we do not do here for |
| 6632 | // performance reasons. |
| 6633 | |
| 6634 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6635 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6636 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6637 | // 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] | 6638 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 6639 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6640 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 6641 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 6642 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 6643 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 6644 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6645 | // ref = ReadBarrier::Mark(ref); |
| 6646 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 6647 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6648 | if (needs_null_check) { |
| 6649 | MaybeRecordImplicitNullCheck(instruction); |
| 6650 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6651 | |
| 6652 | // Load fence to prevent load-load reordering. |
| 6653 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 6654 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6655 | |
| 6656 | // The actual reference load. |
| 6657 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6658 | __ movl(ref_reg, src); // Flags are unaffected. |
| 6659 | |
| 6660 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 6661 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6662 | SlowPathCode* slow_path; |
| 6663 | if (always_update_field) { |
| 6664 | DCHECK(temp1 != nullptr); |
| 6665 | DCHECK(temp2 != nullptr); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6666 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86_64( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6667 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp1, *temp2); |
| 6668 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6669 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86_64( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6670 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 6671 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6672 | AddSlowPath(slow_path); |
| 6673 | |
| 6674 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 6675 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6676 | |
| 6677 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6678 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6679 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6680 | __ Bind(slow_path->GetExitLabel()); |
| 6681 | } |
| 6682 | |
| 6683 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6684 | Location out, |
| 6685 | Location ref, |
| 6686 | Location obj, |
| 6687 | uint32_t offset, |
| 6688 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6689 | DCHECK(kEmitCompilerReadBarrier); |
| 6690 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6691 | // Insert a slow path based read barrier *after* the reference load. |
| 6692 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6693 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6694 | // reference will be carried out by the runtime within the slow |
| 6695 | // path. |
| 6696 | // |
| 6697 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6698 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6699 | // not used by the artReadBarrierSlow entry point. |
| 6700 | // |
| 6701 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6702 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6703 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 6704 | AddSlowPath(slow_path); |
| 6705 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6706 | __ jmp(slow_path->GetEntryLabel()); |
| 6707 | __ Bind(slow_path->GetExitLabel()); |
| 6708 | } |
| 6709 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6710 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6711 | Location out, |
| 6712 | Location ref, |
| 6713 | Location obj, |
| 6714 | uint32_t offset, |
| 6715 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6716 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6717 | // Baker's read barriers shall be handled by the fast path |
| 6718 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6719 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6720 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6721 | // by the runtime within the slow path. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6722 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6723 | } else if (kPoisonHeapReferences) { |
| 6724 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 6725 | } |
| 6726 | } |
| 6727 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6728 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6729 | Location out, |
| 6730 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6731 | DCHECK(kEmitCompilerReadBarrier); |
| 6732 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6733 | // Insert a slow path based read barrier *after* the GC root load. |
| 6734 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6735 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6736 | // not need to do anything special for this here. |
| 6737 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6738 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6739 | AddSlowPath(slow_path); |
| 6740 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6741 | __ jmp(slow_path->GetEntryLabel()); |
| 6742 | __ Bind(slow_path->GetExitLabel()); |
| 6743 | } |
| 6744 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6745 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6746 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6747 | LOG(FATAL) << "Unreachable"; |
| 6748 | } |
| 6749 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6750 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6751 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6752 | LOG(FATAL) << "Unreachable"; |
| 6753 | } |
| 6754 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6755 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6756 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6757 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6758 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6759 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6760 | locations->AddTemp(Location::RequiresRegister()); |
| 6761 | locations->AddTemp(Location::RequiresRegister()); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6762 | } |
| 6763 | |
| 6764 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6765 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6766 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6767 | LocationSummary* locations = switch_instr->GetLocations(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6768 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 6769 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 6770 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6771 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6772 | |
| 6773 | // Should we generate smaller inline compare/jumps? |
| 6774 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6775 | // Figure out the correct compare values and jump conditions. |
| 6776 | // Handle the first compare/branch as a special case because it might |
| 6777 | // jump to the default case. |
| 6778 | DCHECK_GT(num_entries, 2u); |
| 6779 | Condition first_condition; |
| 6780 | uint32_t index; |
| 6781 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6782 | if (lower_bound != 0) { |
| 6783 | first_condition = kLess; |
| 6784 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 6785 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6786 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 6787 | |
| 6788 | index = 1; |
| 6789 | } else { |
| 6790 | // Handle all the compare/jumps below. |
| 6791 | first_condition = kBelow; |
| 6792 | index = 0; |
| 6793 | } |
| 6794 | |
| 6795 | // Handle the rest of the compare/jumps. |
| 6796 | for (; index + 1 < num_entries; index += 2) { |
| 6797 | int32_t compare_to_value = lower_bound + index + 1; |
| 6798 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 6799 | // Jump to successors[index] if value < case_value[index]. |
| 6800 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6801 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6802 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6803 | } |
| 6804 | |
| 6805 | if (index != num_entries) { |
| 6806 | // There are an odd number of entries. Handle the last one. |
| 6807 | DCHECK_EQ(index + 1, num_entries); |
Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 6808 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6809 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 6810 | } |
| 6811 | |
| 6812 | // And the default for any other value. |
| 6813 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6814 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 6815 | } |
| 6816 | return; |
| 6817 | } |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6818 | |
| 6819 | // Remove the bias, if needed. |
| 6820 | Register value_reg_out = value_reg_in.AsRegister(); |
| 6821 | if (lower_bound != 0) { |
| 6822 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 6823 | value_reg_out = temp_reg.AsRegister(); |
| 6824 | } |
| 6825 | CpuRegister value_reg(value_reg_out); |
| 6826 | |
| 6827 | // Is the value in range? |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6828 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6829 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6830 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6831 | // We are in the range of the table. |
| 6832 | // Load the address of the jump table in the constant area. |
| 6833 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6834 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6835 | // Load the (signed) offset from the jump table. |
| 6836 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 6837 | |
| 6838 | // Add the offset to the address of the table base. |
| 6839 | __ addq(temp_reg, base_reg); |
| 6840 | |
| 6841 | // And jump. |
| 6842 | __ jmp(temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6843 | } |
| 6844 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 6845 | void LocationsBuilderX86_64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 6846 | ATTRIBUTE_UNUSED) { |
| 6847 | LOG(FATAL) << "Unreachable"; |
| 6848 | } |
| 6849 | |
| 6850 | void InstructionCodeGeneratorX86_64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 6851 | ATTRIBUTE_UNUSED) { |
| 6852 | LOG(FATAL) << "Unreachable"; |
| 6853 | } |
| 6854 | |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6855 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 6856 | if (value == 0) { |
| 6857 | __ xorl(dest, dest); |
| 6858 | } else { |
| 6859 | __ movl(dest, Immediate(value)); |
| 6860 | } |
| 6861 | } |
| 6862 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6863 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 6864 | if (value == 0) { |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6865 | // Clears upper bits too. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6866 | __ xorl(dest, dest); |
Vladimir Marko | ed00978 | 2016-02-22 16:54:39 +0000 | [diff] [blame] | 6867 | } else if (IsUint<32>(value)) { |
| 6868 | // 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] | 6869 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 6870 | } else { |
| 6871 | __ movq(dest, Immediate(value)); |
| 6872 | } |
| 6873 | } |
| 6874 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 6875 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 6876 | if (value == 0) { |
| 6877 | __ xorps(dest, dest); |
| 6878 | } else { |
| 6879 | __ movss(dest, LiteralInt32Address(value)); |
| 6880 | } |
| 6881 | } |
| 6882 | |
| 6883 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 6884 | if (value == 0) { |
| 6885 | __ xorpd(dest, dest); |
| 6886 | } else { |
| 6887 | __ movsd(dest, LiteralInt64Address(value)); |
| 6888 | } |
| 6889 | } |
| 6890 | |
| 6891 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 6892 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 6893 | } |
| 6894 | |
| 6895 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 6896 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 6897 | } |
| 6898 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 6899 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 6900 | if (value == 0) { |
| 6901 | __ testl(dest, dest); |
| 6902 | } else { |
| 6903 | __ cmpl(dest, Immediate(value)); |
| 6904 | } |
| 6905 | } |
| 6906 | |
| 6907 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 6908 | if (IsInt<32>(value)) { |
| 6909 | if (value == 0) { |
| 6910 | __ testq(dest, dest); |
| 6911 | } else { |
| 6912 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 6913 | } |
| 6914 | } else { |
| 6915 | // Value won't fit in an int. |
| 6916 | __ cmpq(dest, LiteralInt64Address(value)); |
| 6917 | } |
| 6918 | } |
| 6919 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6920 | void CodeGeneratorX86_64::GenerateIntCompare(Location lhs, Location rhs) { |
| 6921 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6922 | GenerateIntCompare(lhs_reg, rhs); |
| 6923 | } |
| 6924 | |
| 6925 | void CodeGeneratorX86_64::GenerateIntCompare(CpuRegister lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6926 | if (rhs.IsConstant()) { |
| 6927 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6928 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6929 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6930 | __ cmpl(lhs, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6931 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6932 | __ cmpl(lhs, rhs.AsRegister<CpuRegister>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6933 | } |
| 6934 | } |
| 6935 | |
| 6936 | void CodeGeneratorX86_64::GenerateLongCompare(Location lhs, Location rhs) { |
| 6937 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| 6938 | if (rhs.IsConstant()) { |
| 6939 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 6940 | Compare64BitValue(lhs_reg, value); |
| 6941 | } else if (rhs.IsDoubleStackSlot()) { |
| 6942 | __ cmpq(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 6943 | } else { |
| 6944 | __ cmpq(lhs_reg, rhs.AsRegister<CpuRegister>()); |
| 6945 | } |
| 6946 | } |
| 6947 | |
| 6948 | Address CodeGeneratorX86_64::ArrayAddress(CpuRegister obj, |
| 6949 | Location index, |
| 6950 | ScaleFactor scale, |
| 6951 | uint32_t data_offset) { |
| 6952 | return index.IsConstant() ? |
| 6953 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 6954 | Address(obj, index.AsRegister<CpuRegister>(), scale, data_offset); |
| 6955 | } |
| 6956 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 6957 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 6958 | DCHECK(dest.IsDoubleStackSlot()); |
| 6959 | if (IsInt<32>(value)) { |
| 6960 | // Can move directly as an int32 constant. |
| 6961 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 6962 | Immediate(static_cast<int32_t>(value))); |
| 6963 | } else { |
| 6964 | Load64BitValue(CpuRegister(TMP), value); |
| 6965 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 6966 | } |
| 6967 | } |
| 6968 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6969 | /** |
| 6970 | * Class to handle late fixup of offsets into constant area. |
| 6971 | */ |
| 6972 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 6973 | public: |
| 6974 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 6975 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6976 | |
| 6977 | protected: |
| 6978 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6979 | |
| 6980 | CodeGeneratorX86_64* codegen_; |
| 6981 | |
| 6982 | private: |
| 6983 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6984 | // Patch the correct offset for the instruction. We use the address of the |
| 6985 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 6986 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 6987 | int32_t relative_position = constant_offset - pos; |
| 6988 | |
| 6989 | // Patch in the right value. |
| 6990 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 6991 | } |
| 6992 | |
| 6993 | // Location in constant area that the fixup refers to. |
| 6994 | size_t offset_into_constant_area_; |
| 6995 | }; |
| 6996 | |
| 6997 | /** |
| 6998 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 6999 | * constant area. |
| 7000 | */ |
| 7001 | class JumpTableRIPFixup : public RIPFixup { |
| 7002 | public: |
| 7003 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 7004 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 7005 | |
| 7006 | void CreateJumpTable() { |
| 7007 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 7008 | |
| 7009 | // Ensure that the reference to the jump table has the correct offset. |
| 7010 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7011 | SetOffset(offset_in_constant_table); |
| 7012 | |
| 7013 | // Compute the offset from the start of the function to this jump table. |
| 7014 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 7015 | |
| 7016 | // Populate the jump table with the correct values for the jump table. |
| 7017 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7018 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7019 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7020 | // The value that we want is the target offset - the position of the table. |
| 7021 | for (int32_t i = 0; i < num_entries; i++) { |
| 7022 | HBasicBlock* b = successors[i]; |
| 7023 | Label* l = codegen_->GetLabelOf(b); |
| 7024 | DCHECK(l->IsBound()); |
| 7025 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 7026 | assembler->AppendInt32(offset_to_block); |
| 7027 | } |
| 7028 | } |
| 7029 | |
| 7030 | private: |
| 7031 | const HPackedSwitch* switch_instr_; |
| 7032 | }; |
| 7033 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7034 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 7035 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7036 | X86_64Assembler* assembler = GetAssembler(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7037 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7038 | // 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] | 7039 | assembler->Align(4, 0); |
| 7040 | constant_area_start_ = assembler->CodeSize(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7041 | |
| 7042 | // Populate any jump tables. |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7043 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7044 | jump_table->CreateJumpTable(); |
| 7045 | } |
| 7046 | |
| 7047 | // And now add the constant area to the generated code. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7048 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7049 | } |
| 7050 | |
| 7051 | // And finish up. |
| 7052 | CodeGenerator::Finalize(allocator); |
| 7053 | } |
| 7054 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7055 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7056 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddDouble(v)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7057 | return Address::RIP(fixup); |
| 7058 | } |
| 7059 | |
| 7060 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7061 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddFloat(v)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7062 | return Address::RIP(fixup); |
| 7063 | } |
| 7064 | |
| 7065 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7066 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddInt32(v)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7067 | return Address::RIP(fixup); |
| 7068 | } |
| 7069 | |
| 7070 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7071 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddInt64(v)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7072 | return Address::RIP(fixup); |
| 7073 | } |
| 7074 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7075 | // TODO: trg as memory. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7076 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, DataType::Type type) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7077 | if (!trg.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7078 | DCHECK_EQ(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7079 | return; |
| 7080 | } |
| 7081 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7082 | DCHECK_NE(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7083 | |
| 7084 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 7085 | if (trg.Equals(return_loc)) { |
| 7086 | return; |
| 7087 | } |
| 7088 | |
| 7089 | // Let the parallel move resolver take care of all of this. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7090 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7091 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7092 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7093 | } |
| 7094 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7095 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 7096 | // Create a fixup to be used to create and address the jump table. |
| 7097 | JumpTableRIPFixup* table_fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7098 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7099 | |
| 7100 | // We have to populate the jump tables. |
| 7101 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7102 | return Address::RIP(table_fixup); |
| 7103 | } |
| 7104 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 7105 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 7106 | const Address& addr_high, |
| 7107 | int64_t v, |
| 7108 | HInstruction* instruction) { |
| 7109 | if (IsInt<32>(v)) { |
| 7110 | int32_t v_32 = v; |
| 7111 | __ movq(addr_low, Immediate(v_32)); |
| 7112 | MaybeRecordImplicitNullCheck(instruction); |
| 7113 | } else { |
| 7114 | // Didn't fit in a register. Do it in pieces. |
| 7115 | int32_t low_v = Low32Bits(v); |
| 7116 | int32_t high_v = High32Bits(v); |
| 7117 | __ movl(addr_low, Immediate(low_v)); |
| 7118 | MaybeRecordImplicitNullCheck(instruction); |
| 7119 | __ movl(addr_high, Immediate(high_v)); |
| 7120 | } |
| 7121 | } |
| 7122 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7123 | void CodeGeneratorX86_64::PatchJitRootUse(uint8_t* code, |
| 7124 | const uint8_t* roots_data, |
| 7125 | const PatchInfo<Label>& info, |
| 7126 | uint64_t index_in_table) const { |
| 7127 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7128 | uintptr_t address = |
| 7129 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7130 | typedef __attribute__((__aligned__(1))) uint32_t unaligned_uint32_t; |
| 7131 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7132 | dchecked_integral_cast<uint32_t>(address); |
| 7133 | } |
| 7134 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7135 | void CodeGeneratorX86_64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7136 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7137 | StringReference string_reference(&info.dex_file, dex::StringIndex(info.index)); |
| 7138 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7139 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7140 | } |
| 7141 | |
| 7142 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7143 | TypeReference type_reference(&info.dex_file, dex::TypeIndex(info.index)); |
| 7144 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7145 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7146 | } |
| 7147 | } |
| 7148 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7149 | #undef __ |
| 7150 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 7151 | } // namespace x86_64 |
| 7152 | } // namespace art |