Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [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.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 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 | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 25 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 26 | #include "heap_poisoning.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 27 | #include "intrinsics.h" |
| 28 | #include "intrinsics_x86.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 29 | #include "linker/linker_patch.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 30 | #include "lock_word.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 31 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 32 | #include "mirror/class-inl.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 33 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 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 | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 36 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 37 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 38 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 39 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 40 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 41 | template<class MirrorType> |
| 42 | class GcRoot; |
| 43 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 44 | namespace x86 { |
| 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 = EAX; |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 48 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 49 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 50 | static constexpr int kC2ConditionMask = 0x400; |
| 51 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 52 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 53 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 54 | static constexpr int64_t kDoubleNaN = INT64_C(0x7FF8000000000000); |
| 55 | static constexpr int32_t kFloatNaN = INT32_C(0x7FC00000); |
| 56 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 57 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 58 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 59 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86PointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 60 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 61 | class NullCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 62 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 63 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 64 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 65 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 66 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 67 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 68 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 69 | // Live registers will be restored in the catch block if caught. |
| 70 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 71 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 72 | x86_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 73 | instruction_, |
| 74 | instruction_->GetDexPc(), |
| 75 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 76 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 77 | } |
| 78 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 79 | bool IsFatal() const OVERRIDE { return true; } |
| 80 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 81 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 82 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 83 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 84 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 85 | }; |
| 86 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 87 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 88 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 89 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 90 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 91 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 92 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 93 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 94 | x86_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 95 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 98 | bool IsFatal() const OVERRIDE { return true; } |
| 99 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 100 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 101 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 102 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 104 | }; |
| 105 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 106 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 107 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 108 | DivRemMinusOneSlowPathX86(HInstruction* instruction, Register reg, bool is_div) |
| 109 | : SlowPathCode(instruction), reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 110 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 111 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 112 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 113 | if (is_div_) { |
| 114 | __ negl(reg_); |
| 115 | } else { |
| 116 | __ movl(reg_, Immediate(0)); |
| 117 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 118 | __ jmp(GetExitLabel()); |
| 119 | } |
| 120 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 121 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 122 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 123 | private: |
| 124 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 125 | bool is_div_; |
| 126 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 129 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 130 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 131 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 132 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 133 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 134 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 135 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 136 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 137 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 138 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 139 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 140 | // Live registers will be restored in the catch block if caught. |
| 141 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 142 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 143 | |
| 144 | // Are we using an array length from memory? |
| 145 | HInstruction* array_length = instruction_->InputAt(1); |
| 146 | Location length_loc = locations->InAt(1); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 147 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 148 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 149 | // Load the array length into our temporary. |
Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 150 | HArrayLength* length = array_length->AsArrayLength(); |
| 151 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 152 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 153 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| 154 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 155 | // Check for conflicts with index. |
| 156 | if (length_loc.Equals(locations->InAt(0))) { |
| 157 | // We know we aren't using parameter 2. |
| 158 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 159 | } |
| 160 | __ movl(length_loc.AsRegister<Register>(), array_len); |
Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 161 | if (mirror::kUseStringCompression && length->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 162 | __ shrl(length_loc.AsRegister<Register>(), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 163 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 164 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 165 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 166 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 167 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 168 | DataType::Type::kInt32, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 169 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 170 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 171 | DataType::Type::kInt32); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 172 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 173 | ? kQuickThrowStringBounds |
| 174 | : kQuickThrowArrayBounds; |
| 175 | x86_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 176 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 177 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 178 | } |
| 179 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 180 | bool IsFatal() const OVERRIDE { return true; } |
| 181 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 182 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 183 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 184 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 185 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 186 | }; |
| 187 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 188 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 189 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 190 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 191 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 192 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 193 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 194 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 195 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 196 | __ Bind(GetEntryLabel()); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 197 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 198 | x86_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 199 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 200 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 201 | if (successor_ == nullptr) { |
| 202 | __ jmp(GetReturnLabel()); |
| 203 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 204 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 205 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 208 | Label* GetReturnLabel() { |
| 209 | DCHECK(successor_ == nullptr); |
| 210 | return &return_label_; |
| 211 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 212 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 213 | HBasicBlock* GetSuccessor() const { |
| 214 | return successor_; |
| 215 | } |
| 216 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 217 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 218 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 219 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 220 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 221 | Label return_label_; |
| 222 | |
| 223 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 224 | }; |
| 225 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 226 | class LoadStringSlowPathX86 : public SlowPathCode { |
| 227 | public: |
| 228 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} |
| 229 | |
| 230 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 231 | LocationSummary* locations = instruction_->GetLocations(); |
| 232 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 233 | |
| 234 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 235 | __ Bind(GetEntryLabel()); |
| 236 | SaveLiveRegisters(codegen, locations); |
| 237 | |
| 238 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 239 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 240 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index.index_)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 241 | x86_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 242 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 243 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 244 | RestoreLiveRegisters(codegen, locations); |
| 245 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 246 | __ jmp(GetExitLabel()); |
| 247 | } |
| 248 | |
| 249 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 250 | |
| 251 | private: |
| 252 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 253 | }; |
| 254 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 255 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 256 | public: |
| 257 | LoadClassSlowPathX86(HLoadClass* cls, |
| 258 | HInstruction* at, |
| 259 | uint32_t dex_pc, |
| 260 | bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 261 | : SlowPathCode(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 262 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 263 | } |
| 264 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 265 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 266 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 267 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 268 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 269 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 270 | |
| 271 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 272 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 273 | __ movl(calling_convention.GetRegisterAt(0), Immediate(type_index.index_)); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 274 | x86_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage |
| 275 | : kQuickInitializeType, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 276 | instruction_, |
| 277 | dex_pc_, |
| 278 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 279 | if (do_clinit_) { |
| 280 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 281 | } else { |
| 282 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 283 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 284 | |
| 285 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 286 | Location out = locations->Out(); |
| 287 | if (out.IsValid()) { |
| 288 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 289 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 290 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 291 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 292 | __ jmp(GetExitLabel()); |
| 293 | } |
| 294 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 295 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 296 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 297 | private: |
| 298 | // The class this slow path will load. |
| 299 | HLoadClass* const cls_; |
| 300 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 301 | // The dex PC of `at_`. |
| 302 | const uint32_t dex_pc_; |
| 303 | |
| 304 | // Whether to initialize the class. |
| 305 | const bool do_clinit_; |
| 306 | |
| 307 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 308 | }; |
| 309 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 310 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 311 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 312 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 313 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 314 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 315 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 316 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 317 | DCHECK(instruction_->IsCheckCast() |
| 318 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 319 | |
| 320 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 321 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 322 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 323 | if (kPoisonHeapReferences && |
| 324 | instruction_->IsCheckCast() && |
| 325 | instruction_->AsCheckCast()->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) { |
| 326 | // First, unpoison the `cls` reference that was poisoned for direct memory comparison. |
| 327 | __ UnpoisonHeapReference(locations->InAt(1).AsRegister<Register>()); |
| 328 | } |
| 329 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 330 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 331 | SaveLiveRegisters(codegen, locations); |
| 332 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 333 | |
| 334 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 335 | // move resolver. |
| 336 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 337 | x86_codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 338 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 339 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 340 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 341 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 342 | DataType::Type::kReference); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 343 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 344 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 345 | instruction_, |
| 346 | instruction_->GetDexPc(), |
| 347 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 348 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 349 | } else { |
| 350 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 351 | x86_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 352 | instruction_, |
| 353 | instruction_->GetDexPc(), |
| 354 | this); |
| 355 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 358 | if (!is_fatal_) { |
| 359 | if (instruction_->IsInstanceOf()) { |
| 360 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 361 | } |
| 362 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 363 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 364 | __ jmp(GetExitLabel()); |
| 365 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 368 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 369 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 370 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 371 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 372 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 373 | |
| 374 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 375 | }; |
| 376 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 377 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 378 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 379 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 380 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 381 | |
| 382 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 383 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 384 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 385 | LocationSummary* locations = instruction_->GetLocations(); |
| 386 | SaveLiveRegisters(codegen, locations); |
| 387 | InvokeRuntimeCallingConvention calling_convention; |
| 388 | x86_codegen->Load32BitValue( |
| 389 | calling_convention.GetRegisterAt(0), |
| 390 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 391 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 392 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 395 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 396 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 397 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 398 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 399 | }; |
| 400 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 401 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 402 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 403 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 404 | |
| 405 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 406 | LocationSummary* locations = instruction_->GetLocations(); |
| 407 | __ Bind(GetEntryLabel()); |
| 408 | SaveLiveRegisters(codegen, locations); |
| 409 | |
| 410 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 411 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 412 | parallel_move.AddMove( |
| 413 | locations->InAt(0), |
| 414 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 415 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 416 | nullptr); |
| 417 | parallel_move.AddMove( |
| 418 | locations->InAt(1), |
| 419 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 420 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 421 | nullptr); |
| 422 | parallel_move.AddMove( |
| 423 | locations->InAt(2), |
| 424 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 425 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 426 | nullptr); |
| 427 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 428 | |
| 429 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 430 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 431 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 432 | RestoreLiveRegisters(codegen, locations); |
| 433 | __ jmp(GetExitLabel()); |
| 434 | } |
| 435 | |
| 436 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 437 | |
| 438 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 439 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 440 | }; |
| 441 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 442 | // Slow path marking an object reference `ref` during a read |
| 443 | // barrier. The field `obj.field` in the object `obj` holding this |
| 444 | // reference does not get updated by this slow path after marking (see |
| 445 | // ReadBarrierMarkAndUpdateFieldSlowPathX86 below for that). |
| 446 | // |
| 447 | // This means that after the execution of this slow path, `ref` will |
| 448 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 449 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 450 | // probably still be a from-space reference (unless it gets updated by |
| 451 | // another thread, or if another thread installed another object |
| 452 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 453 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 454 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 455 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, |
| 456 | Location ref, |
| 457 | bool unpoison_ref_before_marking) |
| 458 | : SlowPathCode(instruction), |
| 459 | ref_(ref), |
| 460 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 461 | DCHECK(kEmitCompilerReadBarrier); |
| 462 | } |
| 463 | |
| 464 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 465 | |
| 466 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 467 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 468 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 469 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 470 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 471 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 472 | instruction_->IsStaticFieldGet() || |
| 473 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 474 | instruction_->IsArraySet() || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 475 | instruction_->IsLoadClass() || |
| 476 | instruction_->IsLoadString() || |
| 477 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 478 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 479 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 480 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 481 | << "Unexpected instruction in read barrier marking slow path: " |
| 482 | << instruction_->DebugName(); |
| 483 | |
| 484 | __ Bind(GetEntryLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 485 | if (unpoison_ref_before_marking_) { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 486 | // Object* ref = ref_addr->AsMirrorPtr() |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 487 | __ MaybeUnpoisonHeapReference(ref_reg); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 488 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 489 | // No need to save live registers; it's taken care of by the |
| 490 | // entrypoint. Also, there is no need to update the stack mask, |
| 491 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 492 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 493 | DCHECK_NE(ref_reg, ESP); |
| 494 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 495 | // "Compact" slow path, saving two moves. |
| 496 | // |
| 497 | // Instead of using the standard runtime calling convention (input |
| 498 | // and output in EAX): |
| 499 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 500 | // EAX <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 501 | // EAX <- ReadBarrierMark(EAX) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 502 | // ref <- EAX |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 503 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 504 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 505 | // of a dedicated entrypoint: |
| 506 | // |
| 507 | // rX <- ReadBarrierMarkRegX(rX) |
| 508 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 509 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 510 | // This runtime call does not require a stack map. |
| 511 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 512 | __ jmp(GetExitLabel()); |
| 513 | } |
| 514 | |
| 515 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 516 | // The location (register) of the marked object reference. |
| 517 | const Location ref_; |
| 518 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 519 | const bool unpoison_ref_before_marking_; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 520 | |
| 521 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 522 | }; |
| 523 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 524 | // Slow path marking an object reference `ref` during a read barrier, |
| 525 | // and if needed, atomically updating the field `obj.field` in the |
| 526 | // object `obj` holding this reference after marking (contrary to |
| 527 | // ReadBarrierMarkSlowPathX86 above, which never tries to update |
| 528 | // `obj.field`). |
| 529 | // |
| 530 | // This means that after the execution of this slow path, both `ref` |
| 531 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 532 | // hold the same to-space reference (unless another thread installed |
| 533 | // another object reference (different from `ref`) in `obj.field`). |
| 534 | class ReadBarrierMarkAndUpdateFieldSlowPathX86 : public SlowPathCode { |
| 535 | public: |
| 536 | ReadBarrierMarkAndUpdateFieldSlowPathX86(HInstruction* instruction, |
| 537 | Location ref, |
| 538 | Register obj, |
| 539 | const Address& field_addr, |
| 540 | bool unpoison_ref_before_marking, |
| 541 | Register temp) |
| 542 | : SlowPathCode(instruction), |
| 543 | ref_(ref), |
| 544 | obj_(obj), |
| 545 | field_addr_(field_addr), |
| 546 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 547 | temp_(temp) { |
| 548 | DCHECK(kEmitCompilerReadBarrier); |
| 549 | } |
| 550 | |
| 551 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkAndUpdateFieldSlowPathX86"; } |
| 552 | |
| 553 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 554 | LocationSummary* locations = instruction_->GetLocations(); |
| 555 | Register ref_reg = ref_.AsRegister<Register>(); |
| 556 | DCHECK(locations->CanCall()); |
| 557 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 558 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 559 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 560 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 561 | << instruction_->DebugName(); |
| 562 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 563 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 564 | |
| 565 | __ Bind(GetEntryLabel()); |
| 566 | if (unpoison_ref_before_marking_) { |
| 567 | // Object* ref = ref_addr->AsMirrorPtr() |
| 568 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 569 | } |
| 570 | |
| 571 | // Save the old (unpoisoned) reference. |
| 572 | __ movl(temp_, ref_reg); |
| 573 | |
| 574 | // No need to save live registers; it's taken care of by the |
| 575 | // entrypoint. Also, there is no need to update the stack mask, |
| 576 | // as this runtime call will not trigger a garbage collection. |
| 577 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 578 | DCHECK_NE(ref_reg, ESP); |
| 579 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 580 | // "Compact" slow path, saving two moves. |
| 581 | // |
| 582 | // Instead of using the standard runtime calling convention (input |
| 583 | // and output in EAX): |
| 584 | // |
| 585 | // EAX <- ref |
| 586 | // EAX <- ReadBarrierMark(EAX) |
| 587 | // ref <- EAX |
| 588 | // |
| 589 | // we just use rX (the register containing `ref`) as input and output |
| 590 | // of a dedicated entrypoint: |
| 591 | // |
| 592 | // rX <- ReadBarrierMarkRegX(rX) |
| 593 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 594 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 595 | // This runtime call does not require a stack map. |
| 596 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 597 | |
| 598 | // If the new reference is different from the old reference, |
| 599 | // update the field in the holder (`*field_addr`). |
| 600 | // |
| 601 | // Note that this field could also hold a different object, if |
| 602 | // another thread had concurrently changed it. In that case, the |
| 603 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 604 | // operation below would abort the CAS, leaving the field as-is. |
| 605 | NearLabel done; |
| 606 | __ cmpl(temp_, ref_reg); |
| 607 | __ j(kEqual, &done); |
| 608 | |
| 609 | // Update the the holder's field atomically. This may fail if |
| 610 | // mutator updates before us, but it's OK. This is achieved |
| 611 | // using a strong compare-and-set (CAS) operation with relaxed |
| 612 | // memory synchronization ordering, where the expected value is |
| 613 | // the old reference and the desired value is the new reference. |
| 614 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 615 | // instruction, which requires the expected value (the old |
| 616 | // reference) to be in EAX. Save EAX beforehand, and move the |
| 617 | // expected value (stored in `temp_`) into EAX. |
| 618 | __ pushl(EAX); |
| 619 | __ movl(EAX, temp_); |
| 620 | |
| 621 | // Convenience aliases. |
| 622 | Register base = obj_; |
| 623 | Register expected = EAX; |
| 624 | Register value = ref_reg; |
| 625 | |
| 626 | bool base_equals_value = (base == value); |
| 627 | if (kPoisonHeapReferences) { |
| 628 | if (base_equals_value) { |
| 629 | // If `base` and `value` are the same register location, move |
| 630 | // `value` to a temporary register. This way, poisoning |
| 631 | // `value` won't invalidate `base`. |
| 632 | value = temp_; |
| 633 | __ movl(value, base); |
| 634 | } |
| 635 | |
| 636 | // Check that the register allocator did not assign the location |
| 637 | // of `expected` (EAX) to `value` nor to `base`, so that heap |
| 638 | // poisoning (when enabled) works as intended below. |
| 639 | // - If `value` were equal to `expected`, both references would |
| 640 | // be poisoned twice, meaning they would not be poisoned at |
| 641 | // all, as heap poisoning uses address negation. |
| 642 | // - If `base` were equal to `expected`, poisoning `expected` |
| 643 | // would invalidate `base`. |
| 644 | DCHECK_NE(value, expected); |
| 645 | DCHECK_NE(base, expected); |
| 646 | |
| 647 | __ PoisonHeapReference(expected); |
| 648 | __ PoisonHeapReference(value); |
| 649 | } |
| 650 | |
| 651 | __ LockCmpxchgl(field_addr_, value); |
| 652 | |
| 653 | // If heap poisoning is enabled, we need to unpoison the values |
| 654 | // that were poisoned earlier. |
| 655 | if (kPoisonHeapReferences) { |
| 656 | if (base_equals_value) { |
| 657 | // `value` has been moved to a temporary register, no need |
| 658 | // to unpoison it. |
| 659 | } else { |
| 660 | __ UnpoisonHeapReference(value); |
| 661 | } |
| 662 | // No need to unpoison `expected` (EAX), as it is be overwritten below. |
| 663 | } |
| 664 | |
| 665 | // Restore EAX. |
| 666 | __ popl(EAX); |
| 667 | |
| 668 | __ Bind(&done); |
| 669 | __ jmp(GetExitLabel()); |
| 670 | } |
| 671 | |
| 672 | private: |
| 673 | // The location (register) of the marked object reference. |
| 674 | const Location ref_; |
| 675 | // The register containing the object holding the marked object reference field. |
| 676 | const Register obj_; |
| 677 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 678 | const Address field_addr_; |
| 679 | |
| 680 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 681 | const bool unpoison_ref_before_marking_; |
| 682 | |
| 683 | const Register temp_; |
| 684 | |
| 685 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86); |
| 686 | }; |
| 687 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 688 | // Slow path generating a read barrier for a heap reference. |
| 689 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 690 | public: |
| 691 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 692 | Location out, |
| 693 | Location ref, |
| 694 | Location obj, |
| 695 | uint32_t offset, |
| 696 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 697 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 698 | out_(out), |
| 699 | ref_(ref), |
| 700 | obj_(obj), |
| 701 | offset_(offset), |
| 702 | index_(index) { |
| 703 | DCHECK(kEmitCompilerReadBarrier); |
| 704 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 705 | // has been overwritten by (or after) the heap object reference load |
| 706 | // to be instrumented, e.g.: |
| 707 | // |
| 708 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 709 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 710 | // |
| 711 | // In that case, we have lost the information about the original |
| 712 | // object, and the emitted read barrier cannot work properly. |
| 713 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 714 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 715 | } |
| 716 | |
| 717 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 718 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 719 | LocationSummary* locations = instruction_->GetLocations(); |
| 720 | Register reg_out = out_.AsRegister<Register>(); |
| 721 | DCHECK(locations->CanCall()); |
| 722 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 723 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 724 | instruction_->IsStaticFieldGet() || |
| 725 | instruction_->IsArrayGet() || |
| 726 | instruction_->IsInstanceOf() || |
| 727 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 728 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 729 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 730 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 731 | |
| 732 | __ Bind(GetEntryLabel()); |
| 733 | SaveLiveRegisters(codegen, locations); |
| 734 | |
| 735 | // We may have to change the index's value, but as `index_` is a |
| 736 | // constant member (like other "inputs" of this slow path), |
| 737 | // introduce a copy of it, `index`. |
| 738 | Location index = index_; |
| 739 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 740 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 741 | if (instruction_->IsArrayGet()) { |
| 742 | // Compute the actual memory offset and store it in `index`. |
| 743 | Register index_reg = index_.AsRegister<Register>(); |
| 744 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 745 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 746 | // We are about to change the value of `index_reg` (see the |
| 747 | // calls to art::x86::X86Assembler::shll and |
| 748 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 749 | // not been saved by the previous call to |
| 750 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 751 | // callee-save register -- |
| 752 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 753 | // callee-save registers, as it has been designed with the |
| 754 | // assumption that callee-save registers are supposed to be |
| 755 | // handled by the called function. So, as a callee-save |
| 756 | // register, `index_reg` _would_ eventually be saved onto |
| 757 | // the stack, but it would be too late: we would have |
| 758 | // changed its value earlier. Therefore, we manually save |
| 759 | // it here into another freely available register, |
| 760 | // `free_reg`, chosen of course among the caller-save |
| 761 | // registers (as a callee-save `free_reg` register would |
| 762 | // exhibit the same problem). |
| 763 | // |
| 764 | // Note we could have requested a temporary register from |
| 765 | // the register allocator instead; but we prefer not to, as |
| 766 | // this is a slow path, and we know we can find a |
| 767 | // caller-save register that is available. |
| 768 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 769 | __ movl(free_reg, index_reg); |
| 770 | index_reg = free_reg; |
| 771 | index = Location::RegisterLocation(index_reg); |
| 772 | } else { |
| 773 | // The initial register stored in `index_` has already been |
| 774 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 775 | // (as it is not a callee-save register), so we can freely |
| 776 | // use it. |
| 777 | } |
| 778 | // Shifting the index value contained in `index_reg` by the scale |
| 779 | // factor (2) cannot overflow in practice, as the runtime is |
| 780 | // unable to allocate object arrays with a size larger than |
| 781 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 782 | __ shll(index_reg, Immediate(TIMES_4)); |
| 783 | static_assert( |
| 784 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 785 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 786 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 787 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 788 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 789 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 790 | // (as in the case of ArrayGet), as it is actually an offset |
| 791 | // to an object field within an object. |
| 792 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 793 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 794 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 795 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 796 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 797 | DCHECK_EQ(offset_, 0U); |
| 798 | DCHECK(index_.IsRegisterPair()); |
| 799 | // UnsafeGet's offset location is a register pair, the low |
| 800 | // part contains the correct offset. |
| 801 | index = index_.ToLow(); |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | // We're moving two or three locations to locations that could |
| 806 | // overlap, so we need a parallel move resolver. |
| 807 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 808 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 809 | parallel_move.AddMove(ref_, |
| 810 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 811 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 812 | nullptr); |
| 813 | parallel_move.AddMove(obj_, |
| 814 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 815 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 816 | nullptr); |
| 817 | if (index.IsValid()) { |
| 818 | parallel_move.AddMove(index, |
| 819 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 820 | DataType::Type::kInt32, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 821 | nullptr); |
| 822 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 823 | } else { |
| 824 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 825 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 826 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 827 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 828 | CheckEntrypointTypes< |
| 829 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 830 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 831 | |
| 832 | RestoreLiveRegisters(codegen, locations); |
| 833 | __ jmp(GetExitLabel()); |
| 834 | } |
| 835 | |
| 836 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 837 | |
| 838 | private: |
| 839 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 840 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 841 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 842 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 843 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 844 | return static_cast<Register>(i); |
| 845 | } |
| 846 | } |
| 847 | // We shall never fail to find a free caller-save register, as |
| 848 | // there are more than two core caller-save registers on x86 |
| 849 | // (meaning it is possible to find one which is different from |
| 850 | // `ref` and `obj`). |
| 851 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 852 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 853 | UNREACHABLE(); |
| 854 | } |
| 855 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 856 | const Location out_; |
| 857 | const Location ref_; |
| 858 | const Location obj_; |
| 859 | const uint32_t offset_; |
| 860 | // An additional location containing an index to an array. |
| 861 | // Only used for HArrayGet and the UnsafeGetObject & |
| 862 | // UnsafeGetObjectVolatile intrinsics. |
| 863 | const Location index_; |
| 864 | |
| 865 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 866 | }; |
| 867 | |
| 868 | // Slow path generating a read barrier for a GC root. |
| 869 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 870 | public: |
| 871 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 872 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 873 | DCHECK(kEmitCompilerReadBarrier); |
| 874 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 875 | |
| 876 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 877 | LocationSummary* locations = instruction_->GetLocations(); |
| 878 | Register reg_out = out_.AsRegister<Register>(); |
| 879 | DCHECK(locations->CanCall()); |
| 880 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 881 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 882 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 883 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 884 | |
| 885 | __ Bind(GetEntryLabel()); |
| 886 | SaveLiveRegisters(codegen, locations); |
| 887 | |
| 888 | InvokeRuntimeCallingConvention calling_convention; |
| 889 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 890 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 891 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 892 | instruction_, |
| 893 | instruction_->GetDexPc(), |
| 894 | this); |
| 895 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 896 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 897 | |
| 898 | RestoreLiveRegisters(codegen, locations); |
| 899 | __ jmp(GetExitLabel()); |
| 900 | } |
| 901 | |
| 902 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 903 | |
| 904 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 905 | const Location out_; |
| 906 | const Location root_; |
| 907 | |
| 908 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 909 | }; |
| 910 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 911 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 912 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 913 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 914 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 915 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 916 | switch (cond) { |
| 917 | case kCondEQ: return kEqual; |
| 918 | case kCondNE: return kNotEqual; |
| 919 | case kCondLT: return kLess; |
| 920 | case kCondLE: return kLessEqual; |
| 921 | case kCondGT: return kGreater; |
| 922 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 923 | case kCondB: return kBelow; |
| 924 | case kCondBE: return kBelowEqual; |
| 925 | case kCondA: return kAbove; |
| 926 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 927 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 928 | LOG(FATAL) << "Unreachable"; |
| 929 | UNREACHABLE(); |
| 930 | } |
| 931 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 932 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 933 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 934 | switch (cond) { |
| 935 | case kCondEQ: return kEqual; |
| 936 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 937 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 938 | case kCondLT: return kBelow; |
| 939 | case kCondLE: return kBelowEqual; |
| 940 | case kCondGT: return kAbove; |
| 941 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 942 | // Unsigned remain unchanged. |
| 943 | case kCondB: return kBelow; |
| 944 | case kCondBE: return kBelowEqual; |
| 945 | case kCondA: return kAbove; |
| 946 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 947 | } |
| 948 | LOG(FATAL) << "Unreachable"; |
| 949 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 950 | } |
| 951 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 952 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 953 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 957 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 958 | } |
| 959 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 960 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 961 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 962 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 963 | } |
| 964 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 965 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 966 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 967 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 968 | } |
| 969 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 970 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 971 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 972 | __ movups(Address(ESP, stack_index), XmmRegister(reg_id)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 973 | } else { |
| 974 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 975 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 976 | return GetFloatingPointSpillSlotSize(); |
| 977 | } |
| 978 | |
| 979 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 980 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 981 | __ movups(XmmRegister(reg_id), Address(ESP, stack_index)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 982 | } else { |
| 983 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 984 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 985 | return GetFloatingPointSpillSlotSize(); |
| 986 | } |
| 987 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 988 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 989 | HInstruction* instruction, |
| 990 | uint32_t dex_pc, |
| 991 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 992 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 993 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 994 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 995 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 996 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 997 | } |
| 998 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 999 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1000 | HInstruction* instruction, |
| 1001 | SlowPathCode* slow_path) { |
| 1002 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1003 | GenerateInvokeRuntime(entry_point_offset); |
| 1004 | } |
| 1005 | |
| 1006 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1007 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 1008 | } |
| 1009 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1010 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1011 | const X86InstructionSetFeatures& isa_features, |
| 1012 | const CompilerOptions& compiler_options, |
| 1013 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1014 | : CodeGenerator(graph, |
| 1015 | kNumberOfCpuRegisters, |
| 1016 | kNumberOfXmmRegisters, |
| 1017 | kNumberOfRegisterPairs, |
| 1018 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1019 | arraysize(kCoreCalleeSaves)) |
| 1020 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1021 | 0, |
| 1022 | compiler_options, |
| 1023 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1024 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1025 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1026 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1027 | move_resolver_(graph->GetAllocator(), this), |
| 1028 | assembler_(graph->GetAllocator()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1029 | isa_features_(isa_features), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1030 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1031 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1032 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1033 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1034 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1035 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1036 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1037 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1038 | constant_area_start_(-1), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1039 | fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1040 | method_address_offset_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1041 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1042 | // Use a fake return address register to mimic Quick. |
| 1043 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1044 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1045 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1046 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1047 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1048 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1049 | } |
| 1050 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1051 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1052 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1053 | assembler_(codegen->GetAssembler()), |
| 1054 | codegen_(codegen) {} |
| 1055 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1056 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1057 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1058 | } |
| 1059 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1060 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1061 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1062 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1063 | bool skip_overflow_check = |
| 1064 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1065 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1066 | |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1067 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1068 | __ addw(Address(kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value()), |
| 1069 | Immediate(1)); |
| 1070 | } |
| 1071 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1072 | if (!skip_overflow_check) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1073 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86); |
| 1074 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(reserved_bytes))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1075 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1076 | } |
| 1077 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1078 | if (HasEmptyFrame()) { |
| 1079 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1080 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1081 | |
| 1082 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1083 | Register reg = kCoreCalleeSaves[i]; |
| 1084 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1085 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1086 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1087 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1088 | } |
| 1089 | } |
| 1090 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1091 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1092 | __ subl(ESP, Immediate(adjust)); |
| 1093 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1094 | // Save the current method if we need it. Note that we do not |
| 1095 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1096 | // in the SSA graph. |
| 1097 | if (RequiresCurrentMethod()) { |
| 1098 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1099 | } |
Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 1100 | |
| 1101 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1102 | // Initialize should_deoptimize flag to 0. |
| 1103 | __ movl(Address(ESP, GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
| 1104 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1108 | __ cfi().RememberState(); |
| 1109 | if (!HasEmptyFrame()) { |
| 1110 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1111 | __ addl(ESP, Immediate(adjust)); |
| 1112 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1113 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1114 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1115 | Register reg = kCoreCalleeSaves[i]; |
| 1116 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1117 | __ popl(reg); |
| 1118 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1119 | __ cfi().Restore(DWARFReg(reg)); |
| 1120 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1121 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1122 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1123 | __ ret(); |
| 1124 | __ cfi().RestoreState(); |
| 1125 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1126 | } |
| 1127 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1128 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1129 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1132 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(DataType::Type type) const { |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1133 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1134 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1135 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1136 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1137 | case DataType::Type::kInt8: |
| 1138 | case DataType::Type::kUint16: |
| 1139 | case DataType::Type::kInt16: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1140 | case DataType::Type::kUint32: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1141 | case DataType::Type::kInt32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1142 | return Location::RegisterLocation(EAX); |
| 1143 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1144 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1145 | case DataType::Type::kInt64: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1146 | return Location::RegisterPairLocation(EAX, EDX); |
| 1147 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1148 | case DataType::Type::kVoid: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1149 | return Location::NoLocation(); |
| 1150 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1151 | case DataType::Type::kFloat64: |
| 1152 | case DataType::Type::kFloat32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1153 | return Location::FpuRegisterLocation(XMM0); |
| 1154 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1155 | |
| 1156 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1160 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1161 | } |
| 1162 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1163 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(DataType::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1164 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1165 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1166 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1167 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1168 | case DataType::Type::kInt8: |
| 1169 | case DataType::Type::kUint16: |
| 1170 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1171 | case DataType::Type::kInt32: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1172 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1173 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1174 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1175 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1176 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1177 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1178 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1179 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1180 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1181 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1182 | uint32_t index = gp_index_; |
| 1183 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1184 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1185 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1186 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1187 | calling_convention.GetRegisterPairAt(index)); |
| 1188 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1189 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1190 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1191 | } |
| 1192 | } |
| 1193 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1194 | case DataType::Type::kFloat32: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1195 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1196 | stack_index_++; |
| 1197 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1198 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1199 | } else { |
| 1200 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1201 | } |
| 1202 | } |
| 1203 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1204 | case DataType::Type::kFloat64: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1205 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1206 | stack_index_ += 2; |
| 1207 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1208 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1209 | } else { |
| 1210 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1211 | } |
| 1212 | } |
| 1213 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1214 | case DataType::Type::kUint32: |
| 1215 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1216 | case DataType::Type::kVoid: |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1217 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1218 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1219 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1220 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1221 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1222 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1223 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1224 | if (source.Equals(destination)) { |
| 1225 | return; |
| 1226 | } |
| 1227 | if (destination.IsRegister()) { |
| 1228 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1229 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1230 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1231 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1232 | } else { |
| 1233 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1234 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1235 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1236 | } else if (destination.IsFpuRegister()) { |
| 1237 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1238 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1239 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1240 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1241 | } else { |
| 1242 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1243 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1244 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1245 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1246 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1247 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1248 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1249 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1250 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1251 | } else if (source.IsConstant()) { |
| 1252 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1253 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1254 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1255 | } else { |
| 1256 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1257 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1258 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1259 | } |
| 1260 | } |
| 1261 | } |
| 1262 | |
| 1263 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1264 | if (source.Equals(destination)) { |
| 1265 | return; |
| 1266 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1267 | if (destination.IsRegisterPair()) { |
| 1268 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1269 | EmitParallelMoves( |
| 1270 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1271 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1272 | DataType::Type::kInt32, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1273 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1274 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1275 | DataType::Type::kInt32); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1276 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1277 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1278 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1279 | __ psrlq(src_reg, Immediate(32)); |
| 1280 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1281 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1282 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1283 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1284 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1285 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1286 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1287 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1288 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1289 | if (source.IsFpuRegister()) { |
| 1290 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1291 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1292 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1293 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1294 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1295 | // Create stack space for 2 elements. |
| 1296 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1297 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1298 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1299 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1300 | // And remove the temporary stack space we allocated. |
| 1301 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1302 | } else { |
| 1303 | LOG(FATAL) << "Unimplemented"; |
| 1304 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1305 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1306 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1307 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1308 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1309 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1310 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1311 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1312 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1313 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1314 | } else if (source.IsConstant()) { |
| 1315 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1316 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1317 | int64_t value = GetInt64ValueOf(constant); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1318 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1319 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1320 | Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1321 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1322 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1323 | EmitParallelMoves( |
| 1324 | Location::StackSlot(source.GetStackIndex()), |
| 1325 | Location::StackSlot(destination.GetStackIndex()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1326 | DataType::Type::kInt32, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1327 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1328 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1329 | DataType::Type::kInt32); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1330 | } |
| 1331 | } |
| 1332 | } |
| 1333 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1334 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1335 | DCHECK(location.IsRegister()); |
| 1336 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1337 | } |
| 1338 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1339 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1340 | HParallelMove move(GetGraph()->GetAllocator()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1341 | if (dst_type == DataType::Type::kInt64 && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1342 | move.AddMove(src.ToLow(), dst.ToLow(), DataType::Type::kInt32, nullptr); |
| 1343 | move.AddMove(src.ToHigh(), dst.ToHigh(), DataType::Type::kInt32, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1344 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1345 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1346 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1347 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1351 | if (location.IsRegister()) { |
| 1352 | locations->AddTemp(location); |
| 1353 | } else if (location.IsRegisterPair()) { |
| 1354 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1355 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1356 | } else { |
| 1357 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1358 | } |
| 1359 | } |
| 1360 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1361 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 1362 | if (successor->IsExitBlock()) { |
| 1363 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 1364 | return; // no code needed |
| 1365 | } |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1366 | |
| 1367 | HBasicBlock* block = got->GetBlock(); |
| 1368 | HInstruction* previous = got->GetPrevious(); |
| 1369 | |
| 1370 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1371 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1372 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1373 | __ pushl(EAX); |
| 1374 | __ movl(EAX, Address(ESP, kX86WordSize)); |
| 1375 | __ addw(Address(EAX, ArtMethod::HotnessCountOffset().Int32Value()), Immediate(1)); |
| 1376 | __ popl(EAX); |
| 1377 | } |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1378 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1379 | return; |
| 1380 | } |
| 1381 | |
| 1382 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1383 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1384 | } |
| 1385 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1386 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1387 | } |
| 1388 | } |
| 1389 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1390 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1391 | got->SetLocations(nullptr); |
| 1392 | } |
| 1393 | |
| 1394 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1395 | HandleGoto(got, got->GetSuccessor()); |
| 1396 | } |
| 1397 | |
| 1398 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1399 | try_boundary->SetLocations(nullptr); |
| 1400 | } |
| 1401 | |
| 1402 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1403 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1404 | if (!successor->IsExitBlock()) { |
| 1405 | HandleGoto(try_boundary, successor); |
| 1406 | } |
| 1407 | } |
| 1408 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1409 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1410 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1411 | } |
| 1412 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1413 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1414 | } |
| 1415 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1416 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1417 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1418 | LabelType* true_label, |
| 1419 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1420 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1421 | __ j(kUnordered, true_label); |
| 1422 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1423 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1424 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1425 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1426 | } |
| 1427 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1428 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1429 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1430 | LabelType* true_label, |
| 1431 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1432 | LocationSummary* locations = cond->GetLocations(); |
| 1433 | Location left = locations->InAt(0); |
| 1434 | Location right = locations->InAt(1); |
| 1435 | IfCondition if_cond = cond->GetCondition(); |
| 1436 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1437 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1438 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1439 | IfCondition true_high_cond = if_cond; |
| 1440 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1441 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1442 | |
| 1443 | // Set the conditions for the test, remembering that == needs to be |
| 1444 | // decided using the low words. |
| 1445 | switch (if_cond) { |
| 1446 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1447 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1448 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1449 | break; |
| 1450 | case kCondLT: |
| 1451 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1452 | break; |
| 1453 | case kCondLE: |
| 1454 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1455 | break; |
| 1456 | case kCondGT: |
| 1457 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1458 | break; |
| 1459 | case kCondGE: |
| 1460 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1461 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1462 | case kCondB: |
| 1463 | false_high_cond = kCondA; |
| 1464 | break; |
| 1465 | case kCondBE: |
| 1466 | true_high_cond = kCondB; |
| 1467 | break; |
| 1468 | case kCondA: |
| 1469 | false_high_cond = kCondB; |
| 1470 | break; |
| 1471 | case kCondAE: |
| 1472 | true_high_cond = kCondA; |
| 1473 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | if (right.IsConstant()) { |
| 1477 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1478 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1479 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1480 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1481 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1482 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1483 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1484 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1485 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1486 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1487 | __ j(X86Condition(true_high_cond), true_label); |
| 1488 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1489 | } |
| 1490 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1491 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1492 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1493 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1494 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1495 | |
| 1496 | __ cmpl(left_high, right_high); |
| 1497 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1498 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1499 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1500 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1501 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1502 | __ j(X86Condition(true_high_cond), true_label); |
| 1503 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1504 | } |
| 1505 | // Must be equal high, so compare the lows. |
| 1506 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1507 | } else { |
| 1508 | DCHECK(right.IsDoubleStackSlot()); |
| 1509 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1510 | if (if_cond == kCondNE) { |
| 1511 | __ j(X86Condition(true_high_cond), true_label); |
| 1512 | } else if (if_cond == kCondEQ) { |
| 1513 | __ j(X86Condition(false_high_cond), false_label); |
| 1514 | } else { |
| 1515 | __ j(X86Condition(true_high_cond), true_label); |
| 1516 | __ j(X86Condition(false_high_cond), false_label); |
| 1517 | } |
| 1518 | // Must be equal high, so compare the lows. |
| 1519 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1520 | } |
| 1521 | // The last comparison might be unsigned. |
| 1522 | __ j(final_condition, true_label); |
| 1523 | } |
| 1524 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1525 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1526 | Location rhs, |
| 1527 | HInstruction* insn, |
| 1528 | bool is_double) { |
| 1529 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1530 | if (is_double) { |
| 1531 | if (rhs.IsFpuRegister()) { |
| 1532 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1533 | } else if (const_area != nullptr) { |
| 1534 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1535 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1536 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1537 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1538 | const_area->GetBaseMethodAddress(), |
| 1539 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1540 | } else { |
| 1541 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1542 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1543 | } |
| 1544 | } else { |
| 1545 | if (rhs.IsFpuRegister()) { |
| 1546 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1547 | } else if (const_area != nullptr) { |
| 1548 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1549 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1550 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1551 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1552 | const_area->GetBaseMethodAddress(), |
| 1553 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1554 | } else { |
| 1555 | DCHECK(rhs.IsStackSlot()); |
| 1556 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1557 | } |
| 1558 | } |
| 1559 | } |
| 1560 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1561 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1562 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1563 | LabelType* true_target_in, |
| 1564 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1565 | // Generated branching requires both targets to be explicit. If either of the |
| 1566 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1567 | LabelType fallthrough_target; |
| 1568 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1569 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1570 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1571 | LocationSummary* locations = condition->GetLocations(); |
| 1572 | Location left = locations->InAt(0); |
| 1573 | Location right = locations->InAt(1); |
| 1574 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1575 | DataType::Type type = condition->InputAt(0)->GetType(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1576 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1577 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1578 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1579 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1580 | case DataType::Type::kFloat32: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1581 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1582 | GenerateFPJumps(condition, true_target, false_target); |
| 1583 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1584 | case DataType::Type::kFloat64: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1585 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1586 | GenerateFPJumps(condition, true_target, false_target); |
| 1587 | break; |
| 1588 | default: |
| 1589 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1590 | } |
| 1591 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1592 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1593 | __ jmp(false_target); |
| 1594 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1595 | |
| 1596 | if (fallthrough_target.IsLinked()) { |
| 1597 | __ Bind(&fallthrough_target); |
| 1598 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1599 | } |
| 1600 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1601 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1602 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1603 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1604 | // conditions if they are materialized due to the complex branching. |
| 1605 | return cond->IsCondition() && |
| 1606 | cond->GetNext() == branch && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1607 | cond->InputAt(0)->GetType() != DataType::Type::kInt64 && |
| 1608 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1609 | } |
| 1610 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1611 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1612 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1613 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1614 | LabelType* true_target, |
| 1615 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1616 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1617 | |
| 1618 | if (true_target == nullptr && false_target == nullptr) { |
| 1619 | // Nothing to do. The code always falls through. |
| 1620 | return; |
| 1621 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1622 | // Constant condition, statically compared against "true" (integer value 1). |
| 1623 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1624 | if (true_target != nullptr) { |
| 1625 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1626 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1627 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1628 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1629 | if (false_target != nullptr) { |
| 1630 | __ jmp(false_target); |
| 1631 | } |
| 1632 | } |
| 1633 | return; |
| 1634 | } |
| 1635 | |
| 1636 | // The following code generates these patterns: |
| 1637 | // (1) true_target == nullptr && false_target != nullptr |
| 1638 | // - opposite condition true => branch to false_target |
| 1639 | // (2) true_target != nullptr && false_target == nullptr |
| 1640 | // - condition true => branch to true_target |
| 1641 | // (3) true_target != nullptr && false_target != nullptr |
| 1642 | // - condition true => branch to true_target |
| 1643 | // - branch to false_target |
| 1644 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1645 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1646 | if (true_target == nullptr) { |
| 1647 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1648 | } else { |
| 1649 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1650 | } |
| 1651 | } else { |
| 1652 | // Materialized condition, compare against 0. |
| 1653 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1654 | if (lhs.IsRegister()) { |
| 1655 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1656 | } else { |
| 1657 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1658 | } |
| 1659 | if (true_target == nullptr) { |
| 1660 | __ j(kEqual, false_target); |
| 1661 | } else { |
| 1662 | __ j(kNotEqual, true_target); |
| 1663 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1664 | } |
| 1665 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1666 | // Condition has not been materialized, use its inputs as the comparison and |
| 1667 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1668 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1669 | |
| 1670 | // If this is a long or FP comparison that has been folded into |
| 1671 | // the HCondition, generate the comparison directly. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1672 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 1673 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1674 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1675 | return; |
| 1676 | } |
| 1677 | |
| 1678 | Location lhs = condition->GetLocations()->InAt(0); |
| 1679 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1680 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1681 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1682 | if (true_target == nullptr) { |
| 1683 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1684 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1685 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1686 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1687 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1688 | |
| 1689 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1690 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1691 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1692 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1693 | } |
| 1694 | } |
| 1695 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1696 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1697 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1698 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1699 | locations->SetInAt(0, Location::Any()); |
| 1700 | } |
| 1701 | } |
| 1702 | |
| 1703 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1704 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1705 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1706 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1707 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1708 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1709 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1710 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1714 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1715 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1716 | InvokeRuntimeCallingConvention calling_convention; |
| 1717 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1718 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1719 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1720 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1721 | locations->SetInAt(0, Location::Any()); |
| 1722 | } |
| 1723 | } |
| 1724 | |
| 1725 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1726 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1727 | GenerateTestAndBranch<Label>(deoptimize, |
| 1728 | /* condition_input_index */ 0, |
| 1729 | slow_path->GetEntryLabel(), |
| 1730 | /* false_target */ nullptr); |
| 1731 | } |
| 1732 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1733 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1734 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1735 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1736 | locations->SetOut(Location::RequiresRegister()); |
| 1737 | } |
| 1738 | |
| 1739 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1740 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), |
| 1741 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1742 | } |
| 1743 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1744 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1745 | // There are no conditional move instructions for XMMs. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1746 | if (DataType::IsFloatingPointType(select->GetType())) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1747 | return false; |
| 1748 | } |
| 1749 | |
| 1750 | // A FP condition doesn't generate the single CC that we need. |
| 1751 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1752 | HInstruction* condition = select->GetCondition(); |
| 1753 | if (condition->IsCondition()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1754 | DataType::Type compare_type = condition->InputAt(0)->GetType(); |
| 1755 | if (compare_type == DataType::Type::kInt64 || |
| 1756 | DataType::IsFloatingPointType(compare_type)) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1757 | return false; |
| 1758 | } |
| 1759 | } |
| 1760 | |
| 1761 | // We can generate a CMOV for this Select. |
| 1762 | return true; |
| 1763 | } |
| 1764 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1765 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1766 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1767 | if (DataType::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1768 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1769 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1770 | } else { |
| 1771 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1772 | if (SelectCanUseCMOV(select)) { |
| 1773 | if (select->InputAt(1)->IsConstant()) { |
| 1774 | // Cmov can't handle a constant value. |
| 1775 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1776 | } else { |
| 1777 | locations->SetInAt(1, Location::Any()); |
| 1778 | } |
| 1779 | } else { |
| 1780 | locations->SetInAt(1, Location::Any()); |
| 1781 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1782 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1783 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1784 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1785 | } |
| 1786 | locations->SetOut(Location::SameAsFirstInput()); |
| 1787 | } |
| 1788 | |
| 1789 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1790 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1791 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1792 | if (SelectCanUseCMOV(select)) { |
| 1793 | // If both the condition and the source types are integer, we can generate |
| 1794 | // a CMOV to implement Select. |
| 1795 | |
| 1796 | HInstruction* select_condition = select->GetCondition(); |
| 1797 | Condition cond = kNotEqual; |
| 1798 | |
| 1799 | // Figure out how to test the 'condition'. |
| 1800 | if (select_condition->IsCondition()) { |
| 1801 | HCondition* condition = select_condition->AsCondition(); |
| 1802 | if (!condition->IsEmittedAtUseSite()) { |
| 1803 | // This was a previously materialized condition. |
| 1804 | // Can we use the existing condition code? |
| 1805 | if (AreEflagsSetFrom(condition, select)) { |
| 1806 | // Materialization was the previous instruction. Condition codes are right. |
| 1807 | cond = X86Condition(condition->GetCondition()); |
| 1808 | } else { |
| 1809 | // No, we have to recreate the condition code. |
| 1810 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1811 | __ testl(cond_reg, cond_reg); |
| 1812 | } |
| 1813 | } else { |
| 1814 | // We can't handle FP or long here. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1815 | DCHECK_NE(condition->InputAt(0)->GetType(), DataType::Type::kInt64); |
| 1816 | DCHECK(!DataType::IsFloatingPointType(condition->InputAt(0)->GetType())); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1817 | LocationSummary* cond_locations = condition->GetLocations(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1818 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1819 | cond = X86Condition(condition->GetCondition()); |
| 1820 | } |
| 1821 | } else { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1822 | // Must be a Boolean condition, which needs to be compared to 0. |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1823 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1824 | __ testl(cond_reg, cond_reg); |
| 1825 | } |
| 1826 | |
| 1827 | // If the condition is true, overwrite the output, which already contains false. |
| 1828 | Location false_loc = locations->InAt(0); |
| 1829 | Location true_loc = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1830 | if (select->GetType() == DataType::Type::kInt64) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1831 | // 64 bit conditional move. |
| 1832 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1833 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1834 | if (true_loc.IsRegisterPair()) { |
| 1835 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1836 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1837 | } else { |
| 1838 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1839 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1840 | } |
| 1841 | } else { |
| 1842 | // 32 bit conditional move. |
| 1843 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1844 | if (true_loc.IsRegister()) { |
| 1845 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1846 | } else { |
| 1847 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1848 | } |
| 1849 | } |
| 1850 | } else { |
| 1851 | NearLabel false_target; |
| 1852 | GenerateTestAndBranch<NearLabel>( |
| 1853 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1854 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1855 | __ Bind(&false_target); |
| 1856 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1857 | } |
| 1858 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1859 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1860 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1861 | } |
| 1862 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1863 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1864 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1865 | } |
| 1866 | |
| 1867 | void CodeGeneratorX86::GenerateNop() { |
| 1868 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1869 | } |
| 1870 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1871 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1872 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1873 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1874 | // Handle the long/FP comparisons made in instruction simplification. |
| 1875 | switch (cond->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1876 | case DataType::Type::kInt64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1877 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1878 | locations->SetInAt(1, Location::Any()); |
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 | locations->SetOut(Location::RequiresRegister()); |
| 1881 | } |
| 1882 | break; |
| 1883 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1884 | case DataType::Type::kFloat32: |
| 1885 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1886 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1887 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1888 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1889 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1890 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1891 | } else { |
| 1892 | locations->SetInAt(1, Location::Any()); |
| 1893 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1894 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1895 | locations->SetOut(Location::RequiresRegister()); |
| 1896 | } |
| 1897 | break; |
| 1898 | } |
| 1899 | default: |
| 1900 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1901 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1902 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1903 | // We need a byte register. |
| 1904 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1905 | } |
| 1906 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1907 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1908 | } |
| 1909 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1910 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1911 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1912 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1913 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1914 | |
| 1915 | LocationSummary* locations = cond->GetLocations(); |
| 1916 | Location lhs = locations->InAt(0); |
| 1917 | Location rhs = locations->InAt(1); |
| 1918 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1919 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1920 | |
| 1921 | switch (cond->InputAt(0)->GetType()) { |
| 1922 | default: { |
| 1923 | // Integer case. |
| 1924 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1925 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1926 | __ xorl(reg, reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1927 | codegen_->GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1928 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1929 | return; |
| 1930 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1931 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1932 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1933 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1934 | case DataType::Type::kFloat32: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1935 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1936 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1937 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1938 | case DataType::Type::kFloat64: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1939 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1940 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1941 | break; |
| 1942 | } |
| 1943 | |
| 1944 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1945 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1946 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1947 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1948 | __ Bind(&false_label); |
| 1949 | __ xorl(reg, reg); |
| 1950 | __ jmp(&done_label); |
| 1951 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1952 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1953 | __ Bind(&true_label); |
| 1954 | __ movl(reg, Immediate(1)); |
| 1955 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1959 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1963 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1964 | } |
| 1965 | |
| 1966 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1967 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1971 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1975 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1976 | } |
| 1977 | |
| 1978 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1979 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1983 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1987 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1991 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1995 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1999 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2003 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2004 | } |
| 2005 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2006 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2007 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2011 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2012 | } |
| 2013 | |
| 2014 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2015 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2019 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2023 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2027 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2028 | } |
| 2029 | |
| 2030 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2031 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2032 | } |
| 2033 | |
| 2034 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2035 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2036 | } |
| 2037 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2038 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2039 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2040 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2041 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2042 | } |
| 2043 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2044 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2045 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2046 | } |
| 2047 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2048 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 2049 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2050 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2051 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2052 | } |
| 2053 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2054 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2055 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2056 | } |
| 2057 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2058 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2059 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2060 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2061 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2062 | } |
| 2063 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2064 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2065 | // Will be generated at use site. |
| 2066 | } |
| 2067 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2068 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2069 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2070 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2071 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2072 | } |
| 2073 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2074 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2075 | // Will be generated at use site. |
| 2076 | } |
| 2077 | |
| 2078 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2079 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2080 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2081 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2082 | } |
| 2083 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2084 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2085 | // Will be generated at use site. |
| 2086 | } |
| 2087 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2088 | void LocationsBuilderX86::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2089 | constructor_fence->SetLocations(nullptr); |
| 2090 | } |
| 2091 | |
| 2092 | void InstructionCodeGeneratorX86::VisitConstructorFence( |
| 2093 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2094 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2095 | } |
| 2096 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2097 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2098 | memory_barrier->SetLocations(nullptr); |
| 2099 | } |
| 2100 | |
| 2101 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2102 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2103 | } |
| 2104 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2105 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2106 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2107 | } |
| 2108 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2109 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2110 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2111 | } |
| 2112 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2113 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2114 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2115 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2116 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2117 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2118 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2119 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2120 | case DataType::Type::kInt8: |
| 2121 | case DataType::Type::kUint16: |
| 2122 | case DataType::Type::kInt16: |
| 2123 | case DataType::Type::kInt32: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2124 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2125 | break; |
| 2126 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2127 | case DataType::Type::kInt64: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2128 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2129 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2130 | break; |
| 2131 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2132 | case DataType::Type::kFloat32: |
| 2133 | case DataType::Type::kFloat64: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2134 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2135 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2136 | break; |
| 2137 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2138 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2139 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2140 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2141 | } |
| 2142 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2143 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2144 | if (kIsDebugBuild) { |
| 2145 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2146 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2147 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2148 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2149 | case DataType::Type::kInt8: |
| 2150 | case DataType::Type::kUint16: |
| 2151 | case DataType::Type::kInt16: |
| 2152 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2153 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2154 | break; |
| 2155 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2156 | case DataType::Type::kInt64: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2157 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2158 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2159 | break; |
| 2160 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2161 | case DataType::Type::kFloat32: |
| 2162 | case DataType::Type::kFloat64: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2163 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2164 | break; |
| 2165 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2166 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2167 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2168 | } |
| 2169 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2170 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2171 | } |
| 2172 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2173 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2174 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2175 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2176 | // the method_idx. |
| 2177 | HandleInvoke(invoke); |
| 2178 | } |
| 2179 | |
| 2180 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2181 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2182 | } |
| 2183 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2184 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2185 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2186 | // art::PrepareForRegisterAllocation. |
| 2187 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2188 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2189 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2190 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2191 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeMethodLoadKind()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2192 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2193 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2194 | return; |
| 2195 | } |
| 2196 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2197 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2198 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2199 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2200 | if (invoke->HasPcRelativeMethodLoadKind()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2201 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2202 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2203 | } |
| 2204 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2205 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2206 | if (invoke->GetLocations()->Intrinsified()) { |
| 2207 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2208 | intrinsic.Dispatch(invoke); |
| 2209 | return true; |
| 2210 | } |
| 2211 | return false; |
| 2212 | } |
| 2213 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2214 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2215 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2216 | // art::PrepareForRegisterAllocation. |
| 2217 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2218 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2219 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2220 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2221 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2222 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2223 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2224 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2225 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2226 | } |
| 2227 | |
| 2228 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2229 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2230 | if (intrinsic.TryDispatch(invoke)) { |
| 2231 | return; |
| 2232 | } |
| 2233 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2234 | HandleInvoke(invoke); |
| 2235 | } |
| 2236 | |
| 2237 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2238 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2239 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2240 | } |
| 2241 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2242 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2243 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2244 | return; |
| 2245 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2246 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2247 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2248 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2249 | } |
| 2250 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2251 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2252 | // This call to HandleInvoke allocates a temporary (core) register |
| 2253 | // which is also used to transfer the hidden argument from FP to |
| 2254 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2255 | HandleInvoke(invoke); |
| 2256 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2257 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2258 | } |
| 2259 | |
| 2260 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2261 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2262 | LocationSummary* locations = invoke->GetLocations(); |
| 2263 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2264 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2265 | Location receiver = locations->InAt(0); |
| 2266 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2267 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2268 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2269 | // won't be modified thereafter, before the `call` instruction. |
| 2270 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2271 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2272 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2273 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2274 | if (receiver.IsStackSlot()) { |
| 2275 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2276 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2277 | __ movl(temp, Address(temp, class_offset)); |
| 2278 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2279 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2280 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2281 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2282 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2283 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2284 | // emit a read barrier for the previous class reference load. |
| 2285 | // However this is not required in practice, as this is an |
| 2286 | // intermediate/temporary reference and because the current |
| 2287 | // concurrent copying collector keeps the from-space memory |
| 2288 | // intact/accessible until the end of the marking phase (the |
| 2289 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2290 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2291 | // temp = temp->GetAddressOfIMT() |
| 2292 | __ movl(temp, |
| 2293 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2294 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2295 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2296 | invoke->GetImtIndex(), kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2297 | __ movl(temp, Address(temp, method_offset)); |
| 2298 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2299 | __ call(Address(temp, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2300 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2301 | |
| 2302 | DCHECK(!codegen_->IsLeafMethod()); |
| 2303 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2304 | } |
| 2305 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2306 | void LocationsBuilderX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2307 | HandleInvoke(invoke); |
| 2308 | } |
| 2309 | |
| 2310 | void InstructionCodeGeneratorX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2311 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2312 | } |
| 2313 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2314 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2315 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2316 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2317 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2318 | case DataType::Type::kInt32: |
| 2319 | case DataType::Type::kInt64: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2320 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2321 | locations->SetOut(Location::SameAsFirstInput()); |
| 2322 | break; |
| 2323 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2324 | case DataType::Type::kFloat32: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2325 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2326 | locations->SetOut(Location::SameAsFirstInput()); |
| 2327 | locations->AddTemp(Location::RequiresRegister()); |
| 2328 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2329 | break; |
| 2330 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2331 | case DataType::Type::kFloat64: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2332 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2333 | locations->SetOut(Location::SameAsFirstInput()); |
| 2334 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2335 | break; |
| 2336 | |
| 2337 | default: |
| 2338 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2339 | } |
| 2340 | } |
| 2341 | |
| 2342 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2343 | LocationSummary* locations = neg->GetLocations(); |
| 2344 | Location out = locations->Out(); |
| 2345 | Location in = locations->InAt(0); |
| 2346 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2347 | case DataType::Type::kInt32: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2348 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2349 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2350 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2351 | break; |
| 2352 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2353 | case DataType::Type::kInt64: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2354 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2355 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2356 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2357 | // Negation is similar to subtraction from zero. The least |
| 2358 | // significant byte triggers a borrow when it is different from |
| 2359 | // zero; to take it into account, add 1 to the most significant |
| 2360 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2361 | // operation. |
| 2362 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2363 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2364 | break; |
| 2365 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2366 | case DataType::Type::kFloat32: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2367 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2368 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2369 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2370 | // Implement float negation with an exclusive or with value |
| 2371 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2372 | // single-precision floating-point number). |
| 2373 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2374 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2375 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2376 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2377 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2378 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2379 | case DataType::Type::kFloat64: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2380 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2381 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2382 | // Implement double negation with an exclusive or with value |
| 2383 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2384 | // a double-precision floating-point number). |
| 2385 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2386 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2387 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2388 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2389 | |
| 2390 | default: |
| 2391 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2392 | } |
| 2393 | } |
| 2394 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2395 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2396 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2397 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2398 | DCHECK(DataType::IsFloatingPointType(neg->GetType())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2399 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2400 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2401 | locations->SetOut(Location::SameAsFirstInput()); |
| 2402 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2403 | } |
| 2404 | |
| 2405 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2406 | LocationSummary* locations = neg->GetLocations(); |
| 2407 | Location out = locations->Out(); |
| 2408 | DCHECK(locations->InAt(0).Equals(out)); |
| 2409 | |
| 2410 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2411 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2412 | if (neg->GetType() == DataType::Type::kFloat32) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2413 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), |
| 2414 | neg->GetBaseMethodAddress(), |
| 2415 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2416 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2417 | } else { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2418 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), |
| 2419 | neg->GetBaseMethodAddress(), |
| 2420 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2421 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2422 | } |
| 2423 | } |
| 2424 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2425 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2426 | DataType::Type result_type = conversion->GetResultType(); |
| 2427 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2428 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2429 | << input_type << " -> " << result_type; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2430 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2431 | // The float-to-long and double-to-long type conversions rely on a |
| 2432 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2433 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2434 | ((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 2435 | && result_type == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2436 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2437 | : LocationSummary::kNoCall; |
| 2438 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2439 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2440 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2441 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2442 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2443 | case DataType::Type::kInt8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2444 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2445 | case DataType::Type::kUint8: |
| 2446 | case DataType::Type::kInt8: |
| 2447 | case DataType::Type::kUint16: |
| 2448 | case DataType::Type::kInt16: |
| 2449 | case DataType::Type::kInt32: |
| 2450 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2451 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2452 | // the validation of the linear scan implementation |
| 2453 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2454 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2455 | case DataType::Type::kInt64: { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2456 | HInstruction* input = conversion->InputAt(0); |
| 2457 | Location input_location = input->IsConstant() |
| 2458 | ? Location::ConstantLocation(input->AsConstant()) |
| 2459 | : Location::RegisterPairLocation(EAX, EDX); |
| 2460 | locations->SetInAt(0, input_location); |
| 2461 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2462 | // the validation of the linear scan implementation |
| 2463 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2464 | break; |
| 2465 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2466 | |
| 2467 | default: |
| 2468 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2469 | << " to " << result_type; |
| 2470 | } |
| 2471 | break; |
| 2472 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2473 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2474 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2475 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2476 | locations->SetInAt(0, Location::Any()); |
| 2477 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2478 | break; |
| 2479 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2480 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2481 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2482 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2483 | locations->SetInAt(0, Location::Any()); |
| 2484 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2485 | break; |
| 2486 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2487 | case DataType::Type::kFloat32: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2488 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2489 | locations->SetOut(Location::RequiresRegister()); |
| 2490 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2491 | break; |
| 2492 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2493 | case DataType::Type::kFloat64: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2494 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2495 | locations->SetOut(Location::RequiresRegister()); |
| 2496 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2497 | break; |
| 2498 | |
| 2499 | default: |
| 2500 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2501 | << " to " << result_type; |
| 2502 | } |
| 2503 | break; |
| 2504 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2505 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2506 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2507 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2508 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2509 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2510 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2511 | case DataType::Type::kInt16: |
| 2512 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2513 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2514 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2515 | break; |
| 2516 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2517 | case DataType::Type::kFloat32: |
| 2518 | case DataType::Type::kFloat64: { |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2519 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2520 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2521 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2522 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2523 | // The runtime helper puts the result in EAX, EDX. |
| 2524 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2525 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2526 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2527 | |
| 2528 | default: |
| 2529 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2530 | << " to " << result_type; |
| 2531 | } |
| 2532 | break; |
| 2533 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2534 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2535 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2536 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2537 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2538 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2539 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2540 | case DataType::Type::kInt16: |
| 2541 | case DataType::Type::kInt32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2542 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2543 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2544 | break; |
| 2545 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2546 | case DataType::Type::kInt64: |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2547 | locations->SetInAt(0, Location::Any()); |
| 2548 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2549 | break; |
| 2550 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2551 | case DataType::Type::kFloat64: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2552 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2553 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2554 | break; |
| 2555 | |
| 2556 | default: |
| 2557 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2558 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2559 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2560 | break; |
| 2561 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2562 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2563 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2564 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2565 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2566 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2567 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2568 | case DataType::Type::kInt16: |
| 2569 | case DataType::Type::kInt32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2570 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2571 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2572 | break; |
| 2573 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2574 | case DataType::Type::kInt64: |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2575 | locations->SetInAt(0, Location::Any()); |
| 2576 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2577 | break; |
| 2578 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2579 | case DataType::Type::kFloat32: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2580 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2581 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2582 | break; |
| 2583 | |
| 2584 | default: |
| 2585 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2586 | << " to " << result_type; |
| 2587 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2588 | break; |
| 2589 | |
| 2590 | default: |
| 2591 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2592 | << " to " << result_type; |
| 2593 | } |
| 2594 | } |
| 2595 | |
| 2596 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2597 | LocationSummary* locations = conversion->GetLocations(); |
| 2598 | Location out = locations->Out(); |
| 2599 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2600 | DataType::Type result_type = conversion->GetResultType(); |
| 2601 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2602 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2603 | << input_type << " -> " << result_type; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2604 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2605 | case DataType::Type::kUint8: |
| 2606 | switch (input_type) { |
| 2607 | case DataType::Type::kInt8: |
| 2608 | case DataType::Type::kUint16: |
| 2609 | case DataType::Type::kInt16: |
| 2610 | case DataType::Type::kInt32: |
| 2611 | if (in.IsRegister()) { |
| 2612 | __ movzxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2613 | } else { |
| 2614 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2615 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2616 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2617 | } |
| 2618 | break; |
| 2619 | case DataType::Type::kInt64: |
| 2620 | if (in.IsRegisterPair()) { |
| 2621 | __ movzxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2622 | } else { |
| 2623 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2624 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2625 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2626 | } |
| 2627 | break; |
| 2628 | |
| 2629 | default: |
| 2630 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2631 | << " to " << result_type; |
| 2632 | } |
| 2633 | break; |
| 2634 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2635 | case DataType::Type::kInt8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2636 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2637 | case DataType::Type::kUint8: |
| 2638 | case DataType::Type::kUint16: |
| 2639 | case DataType::Type::kInt16: |
| 2640 | case DataType::Type::kInt32: |
| 2641 | if (in.IsRegister()) { |
| 2642 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2643 | } else { |
| 2644 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2645 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2646 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2647 | } |
| 2648 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2649 | case DataType::Type::kInt64: |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2650 | if (in.IsRegisterPair()) { |
| 2651 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2652 | } else { |
| 2653 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2654 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2655 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2656 | } |
| 2657 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2658 | |
| 2659 | default: |
| 2660 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2661 | << " to " << result_type; |
| 2662 | } |
| 2663 | break; |
| 2664 | |
| 2665 | case DataType::Type::kUint16: |
| 2666 | switch (input_type) { |
| 2667 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2668 | case DataType::Type::kInt16: |
| 2669 | case DataType::Type::kInt32: |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2670 | if (in.IsRegister()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2671 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
| 2672 | } else if (in.IsStackSlot()) { |
| 2673 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2674 | } else { |
| 2675 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2676 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2677 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2678 | } |
| 2679 | break; |
| 2680 | case DataType::Type::kInt64: |
| 2681 | if (in.IsRegisterPair()) { |
| 2682 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2683 | } else if (in.IsDoubleStackSlot()) { |
| 2684 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2685 | } else { |
| 2686 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2687 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2688 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2689 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2690 | break; |
| 2691 | |
| 2692 | default: |
| 2693 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2694 | << " to " << result_type; |
| 2695 | } |
| 2696 | break; |
| 2697 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2698 | case DataType::Type::kInt16: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2699 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2700 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2701 | case DataType::Type::kInt32: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2702 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2703 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2704 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2705 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2706 | } else { |
| 2707 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2708 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2709 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2710 | } |
| 2711 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2712 | case DataType::Type::kInt64: |
| 2713 | if (in.IsRegisterPair()) { |
| 2714 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2715 | } else if (in.IsDoubleStackSlot()) { |
| 2716 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2717 | } else { |
| 2718 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2719 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2720 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2721 | } |
| 2722 | break; |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2723 | |
| 2724 | default: |
| 2725 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2726 | << " to " << result_type; |
| 2727 | } |
| 2728 | break; |
| 2729 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2730 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2731 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2732 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2733 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2734 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2735 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2736 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2737 | } else { |
| 2738 | DCHECK(in.IsConstant()); |
| 2739 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2740 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2741 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2742 | } |
| 2743 | break; |
| 2744 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2745 | case DataType::Type::kFloat32: { |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2746 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2747 | Register output = out.AsRegister<Register>(); |
| 2748 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2749 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2750 | |
| 2751 | __ movl(output, Immediate(kPrimIntMax)); |
| 2752 | // temp = int-to-float(output) |
| 2753 | __ cvtsi2ss(temp, output); |
| 2754 | // if input >= temp goto done |
| 2755 | __ comiss(input, temp); |
| 2756 | __ j(kAboveEqual, &done); |
| 2757 | // if input == NaN goto nan |
| 2758 | __ j(kUnordered, &nan); |
| 2759 | // output = float-to-int-truncate(input) |
| 2760 | __ cvttss2si(output, input); |
| 2761 | __ jmp(&done); |
| 2762 | __ Bind(&nan); |
| 2763 | // output = 0 |
| 2764 | __ xorl(output, output); |
| 2765 | __ Bind(&done); |
| 2766 | break; |
| 2767 | } |
| 2768 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2769 | case DataType::Type::kFloat64: { |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2770 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2771 | Register output = out.AsRegister<Register>(); |
| 2772 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2773 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2774 | |
| 2775 | __ movl(output, Immediate(kPrimIntMax)); |
| 2776 | // temp = int-to-double(output) |
| 2777 | __ cvtsi2sd(temp, output); |
| 2778 | // if input >= temp goto done |
| 2779 | __ comisd(input, temp); |
| 2780 | __ j(kAboveEqual, &done); |
| 2781 | // if input == NaN goto nan |
| 2782 | __ j(kUnordered, &nan); |
| 2783 | // output = double-to-int-truncate(input) |
| 2784 | __ cvttsd2si(output, input); |
| 2785 | __ jmp(&done); |
| 2786 | __ Bind(&nan); |
| 2787 | // output = 0 |
| 2788 | __ xorl(output, output); |
| 2789 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2790 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2791 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2792 | |
| 2793 | default: |
| 2794 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2795 | << " to " << result_type; |
| 2796 | } |
| 2797 | break; |
| 2798 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2799 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2800 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2801 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2802 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2803 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2804 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2805 | case DataType::Type::kInt16: |
| 2806 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2807 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2808 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2809 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2810 | __ cdq(); |
| 2811 | break; |
| 2812 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2813 | case DataType::Type::kFloat32: |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2814 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2815 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2816 | break; |
| 2817 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2818 | case DataType::Type::kFloat64: |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2819 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2820 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2821 | break; |
| 2822 | |
| 2823 | default: |
| 2824 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2825 | << " to " << result_type; |
| 2826 | } |
| 2827 | break; |
| 2828 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2829 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2830 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2831 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2832 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2833 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2834 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2835 | case DataType::Type::kInt16: |
| 2836 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2837 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2838 | break; |
| 2839 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2840 | case DataType::Type::kInt64: { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2841 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2842 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2843 | // Create stack space for the call to |
| 2844 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2845 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2846 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2847 | adjustment = DataType::Size(DataType::Type::kInt64); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2848 | __ subl(ESP, Immediate(adjustment)); |
| 2849 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2850 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2851 | // Load the value to the FP stack, using temporaries if needed. |
| 2852 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2853 | |
| 2854 | if (out.IsStackSlot()) { |
| 2855 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2856 | } else { |
| 2857 | __ fstps(Address(ESP, 0)); |
| 2858 | Location stack_temp = Location::StackSlot(0); |
| 2859 | codegen_->Move32(out, stack_temp); |
| 2860 | } |
| 2861 | |
| 2862 | // Remove the temporary stack space we allocated. |
| 2863 | if (adjustment != 0) { |
| 2864 | __ addl(ESP, Immediate(adjustment)); |
| 2865 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2866 | break; |
| 2867 | } |
| 2868 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2869 | case DataType::Type::kFloat64: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2870 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2871 | break; |
| 2872 | |
| 2873 | default: |
| 2874 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2875 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2876 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2877 | break; |
| 2878 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2879 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2880 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2881 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2882 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2883 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2884 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2885 | case DataType::Type::kInt16: |
| 2886 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2887 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2888 | break; |
| 2889 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2890 | case DataType::Type::kInt64: { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2891 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2892 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2893 | // Create stack space for the call to |
| 2894 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2895 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2896 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2897 | adjustment = DataType::Size(DataType::Type::kInt64); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2898 | __ subl(ESP, Immediate(adjustment)); |
| 2899 | } |
| 2900 | |
| 2901 | // Load the value to the FP stack, using temporaries if needed. |
| 2902 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2903 | |
| 2904 | if (out.IsDoubleStackSlot()) { |
| 2905 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2906 | } else { |
| 2907 | __ fstpl(Address(ESP, 0)); |
| 2908 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2909 | codegen_->Move64(out, stack_temp); |
| 2910 | } |
| 2911 | |
| 2912 | // Remove the temporary stack space we allocated. |
| 2913 | if (adjustment != 0) { |
| 2914 | __ addl(ESP, Immediate(adjustment)); |
| 2915 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2916 | break; |
| 2917 | } |
| 2918 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2919 | case DataType::Type::kFloat32: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2920 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2921 | break; |
| 2922 | |
| 2923 | default: |
| 2924 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2925 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2926 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2927 | break; |
| 2928 | |
| 2929 | default: |
| 2930 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2931 | << " to " << result_type; |
| 2932 | } |
| 2933 | } |
| 2934 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2935 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2936 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2937 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2938 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2939 | case DataType::Type::kInt32: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2940 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2941 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2942 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2943 | break; |
| 2944 | } |
| 2945 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2946 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2947 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2948 | locations->SetInAt(1, Location::Any()); |
| 2949 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2950 | break; |
| 2951 | } |
| 2952 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2953 | case DataType::Type::kFloat32: |
| 2954 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2955 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2956 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2957 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2958 | } else if (add->InputAt(1)->IsConstant()) { |
| 2959 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2960 | } else { |
| 2961 | locations->SetInAt(1, Location::Any()); |
| 2962 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2963 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2964 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2965 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2966 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2967 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2968 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2969 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2970 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2971 | } |
| 2972 | |
| 2973 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2974 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2975 | Location first = locations->InAt(0); |
| 2976 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2977 | Location out = locations->Out(); |
| 2978 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2979 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2980 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2981 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2982 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2983 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2984 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2985 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2986 | } else { |
| 2987 | __ leal(out.AsRegister<Register>(), Address( |
| 2988 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2989 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2990 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2991 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2992 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2993 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2994 | } else { |
| 2995 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2996 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2997 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2998 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2999 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3000 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3001 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3002 | } |
| 3003 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3004 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3005 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3006 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3007 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3008 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3009 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 3010 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3011 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3012 | } else { |
| 3013 | DCHECK(second.IsConstant()) << second; |
| 3014 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3015 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3016 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3017 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3018 | break; |
| 3019 | } |
| 3020 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3021 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3022 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3023 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3024 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3025 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3026 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3027 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3028 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3029 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3030 | const_area->GetBaseMethodAddress(), |
| 3031 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3032 | } else { |
| 3033 | DCHECK(second.IsStackSlot()); |
| 3034 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3035 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3036 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3037 | } |
| 3038 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3039 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3040 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3041 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3042 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3043 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3044 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3045 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3046 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3047 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3048 | const_area->GetBaseMethodAddress(), |
| 3049 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3050 | } else { |
| 3051 | DCHECK(second.IsDoubleStackSlot()); |
| 3052 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3053 | } |
| 3054 | break; |
| 3055 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3056 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3057 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3058 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3059 | } |
| 3060 | } |
| 3061 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3062 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3063 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3064 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3065 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3066 | case DataType::Type::kInt32: |
| 3067 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3068 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3069 | locations->SetInAt(1, Location::Any()); |
| 3070 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3071 | break; |
| 3072 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3073 | case DataType::Type::kFloat32: |
| 3074 | case DataType::Type::kFloat64: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3075 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3076 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3077 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3078 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3079 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3080 | } else { |
| 3081 | locations->SetInAt(1, Location::Any()); |
| 3082 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3083 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3084 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3085 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3086 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3087 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3088 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3089 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3090 | } |
| 3091 | |
| 3092 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3093 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3094 | Location first = locations->InAt(0); |
| 3095 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3096 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3097 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3098 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3099 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3100 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3101 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3102 | __ subl(first.AsRegister<Register>(), |
| 3103 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3104 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3105 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3106 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3107 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3108 | } |
| 3109 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3110 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3111 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3112 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3113 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3114 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3115 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3116 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3117 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3118 | } else { |
| 3119 | DCHECK(second.IsConstant()) << second; |
| 3120 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3121 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3122 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3123 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3124 | break; |
| 3125 | } |
| 3126 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3127 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3128 | if (second.IsFpuRegister()) { |
| 3129 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3130 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3131 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3132 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3133 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3134 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3135 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3136 | const_area->GetBaseMethodAddress(), |
| 3137 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3138 | } else { |
| 3139 | DCHECK(second.IsStackSlot()); |
| 3140 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3141 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3142 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3143 | } |
| 3144 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3145 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3146 | if (second.IsFpuRegister()) { |
| 3147 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3148 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3149 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3150 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3151 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3152 | codegen_->LiteralDoubleAddress( |
| 3153 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3154 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3155 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3156 | } else { |
| 3157 | DCHECK(second.IsDoubleStackSlot()); |
| 3158 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3159 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3160 | break; |
| 3161 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3162 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3163 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3164 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3165 | } |
| 3166 | } |
| 3167 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3168 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3169 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3170 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3171 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3172 | case DataType::Type::kInt32: |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3173 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3174 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3175 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3176 | // Can use 3 operand multiply. |
| 3177 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3178 | } else { |
| 3179 | locations->SetOut(Location::SameAsFirstInput()); |
| 3180 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3181 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3182 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3183 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3184 | locations->SetInAt(1, Location::Any()); |
| 3185 | locations->SetOut(Location::SameAsFirstInput()); |
| 3186 | // Needed for imul on 32bits with 64bits output. |
| 3187 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3188 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3189 | break; |
| 3190 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3191 | case DataType::Type::kFloat32: |
| 3192 | case DataType::Type::kFloat64: { |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3193 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3194 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3195 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3196 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3197 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3198 | } else { |
| 3199 | locations->SetInAt(1, Location::Any()); |
| 3200 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3201 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3202 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3203 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3204 | |
| 3205 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3206 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3207 | } |
| 3208 | } |
| 3209 | |
| 3210 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3211 | LocationSummary* locations = mul->GetLocations(); |
| 3212 | Location first = locations->InAt(0); |
| 3213 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3214 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3215 | |
| 3216 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3217 | case DataType::Type::kInt32: |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3218 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3219 | // problems where the output may not be the same as the first operand. |
| 3220 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3221 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3222 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3223 | } else if (second.IsRegister()) { |
| 3224 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3225 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3226 | } else { |
| 3227 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3228 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3229 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3230 | } |
| 3231 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3232 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3233 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3234 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3235 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3236 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3237 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3238 | |
| 3239 | DCHECK_EQ(EAX, eax); |
| 3240 | DCHECK_EQ(EDX, edx); |
| 3241 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3242 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3243 | // output: in1 |
| 3244 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3245 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3246 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3247 | if (second.IsConstant()) { |
| 3248 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3249 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3250 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3251 | int32_t low_value = Low32Bits(value); |
| 3252 | int32_t high_value = High32Bits(value); |
| 3253 | Immediate low(low_value); |
| 3254 | Immediate high(high_value); |
| 3255 | |
| 3256 | __ movl(eax, high); |
| 3257 | // eax <- in1.lo * in2.hi |
| 3258 | __ imull(eax, in1_lo); |
| 3259 | // in1.hi <- in1.hi * in2.lo |
| 3260 | __ imull(in1_hi, low); |
| 3261 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3262 | __ addl(in1_hi, eax); |
| 3263 | // move in2_lo to eax to prepare for double precision |
| 3264 | __ movl(eax, low); |
| 3265 | // edx:eax <- in1.lo * in2.lo |
| 3266 | __ mull(in1_lo); |
| 3267 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3268 | __ addl(in1_hi, edx); |
| 3269 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3270 | __ movl(in1_lo, eax); |
| 3271 | } else if (second.IsRegisterPair()) { |
| 3272 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3273 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3274 | |
| 3275 | __ movl(eax, in2_hi); |
| 3276 | // eax <- in1.lo * in2.hi |
| 3277 | __ imull(eax, in1_lo); |
| 3278 | // in1.hi <- in1.hi * in2.lo |
| 3279 | __ imull(in1_hi, in2_lo); |
| 3280 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3281 | __ addl(in1_hi, eax); |
| 3282 | // move in1_lo to eax to prepare for double precision |
| 3283 | __ movl(eax, in1_lo); |
| 3284 | // edx:eax <- in1.lo * in2.lo |
| 3285 | __ mull(in2_lo); |
| 3286 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3287 | __ addl(in1_hi, edx); |
| 3288 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3289 | __ movl(in1_lo, eax); |
| 3290 | } else { |
| 3291 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3292 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3293 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3294 | |
| 3295 | __ movl(eax, in2_hi); |
| 3296 | // eax <- in1.lo * in2.hi |
| 3297 | __ imull(eax, in1_lo); |
| 3298 | // in1.hi <- in1.hi * in2.lo |
| 3299 | __ imull(in1_hi, in2_lo); |
| 3300 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3301 | __ addl(in1_hi, eax); |
| 3302 | // move in1_lo to eax to prepare for double precision |
| 3303 | __ movl(eax, in1_lo); |
| 3304 | // edx:eax <- in1.lo * in2.lo |
| 3305 | __ mull(in2_lo); |
| 3306 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3307 | __ addl(in1_hi, edx); |
| 3308 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3309 | __ movl(in1_lo, eax); |
| 3310 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3311 | |
| 3312 | break; |
| 3313 | } |
| 3314 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3315 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3316 | DCHECK(first.Equals(locations->Out())); |
| 3317 | if (second.IsFpuRegister()) { |
| 3318 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3319 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3320 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3321 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3322 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3323 | codegen_->LiteralFloatAddress( |
| 3324 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3325 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3326 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3327 | } else { |
| 3328 | DCHECK(second.IsStackSlot()); |
| 3329 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3330 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3331 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3332 | } |
| 3333 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3334 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3335 | DCHECK(first.Equals(locations->Out())); |
| 3336 | if (second.IsFpuRegister()) { |
| 3337 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3338 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3339 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3340 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3341 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3342 | codegen_->LiteralDoubleAddress( |
| 3343 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3344 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3345 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3346 | } else { |
| 3347 | DCHECK(second.IsDoubleStackSlot()); |
| 3348 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3349 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3350 | break; |
| 3351 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3352 | |
| 3353 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3354 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3355 | } |
| 3356 | } |
| 3357 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3358 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3359 | uint32_t temp_offset, |
| 3360 | uint32_t stack_adjustment, |
| 3361 | bool is_fp, |
| 3362 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3363 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3364 | DCHECK(!is_wide); |
| 3365 | if (is_fp) { |
| 3366 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3367 | } else { |
| 3368 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3369 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3370 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3371 | DCHECK(is_wide); |
| 3372 | if (is_fp) { |
| 3373 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3374 | } else { |
| 3375 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3376 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3377 | } else { |
| 3378 | // Write the value to the temporary location on the stack and load to FP stack. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3379 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3380 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3381 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3382 | if (is_fp) { |
| 3383 | __ flds(Address(ESP, temp_offset)); |
| 3384 | } else { |
| 3385 | __ filds(Address(ESP, temp_offset)); |
| 3386 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3387 | } else { |
| 3388 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3389 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3390 | if (is_fp) { |
| 3391 | __ fldl(Address(ESP, temp_offset)); |
| 3392 | } else { |
| 3393 | __ fildl(Address(ESP, temp_offset)); |
| 3394 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3395 | } |
| 3396 | } |
| 3397 | } |
| 3398 | |
| 3399 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3400 | DataType::Type type = rem->GetResultType(); |
| 3401 | bool is_float = type == DataType::Type::kFloat32; |
| 3402 | size_t elem_size = DataType::Size(type); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3403 | LocationSummary* locations = rem->GetLocations(); |
| 3404 | Location first = locations->InAt(0); |
| 3405 | Location second = locations->InAt(1); |
| 3406 | Location out = locations->Out(); |
| 3407 | |
| 3408 | // Create stack space for 2 elements. |
| 3409 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3410 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3411 | |
| 3412 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3413 | const bool is_wide = !is_float; |
| 3414 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3415 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3416 | |
| 3417 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3418 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3419 | __ Bind(&retry); |
| 3420 | __ fprem(); |
| 3421 | |
| 3422 | // Move FP status to AX. |
| 3423 | __ fstsw(); |
| 3424 | |
| 3425 | // And see if the argument reduction is complete. This is signaled by the |
| 3426 | // C2 FPU flag bit set to 0. |
| 3427 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3428 | __ j(kNotEqual, &retry); |
| 3429 | |
| 3430 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3431 | // Store FP top of stack to real stack. |
| 3432 | if (is_float) { |
| 3433 | __ fsts(Address(ESP, 0)); |
| 3434 | } else { |
| 3435 | __ fstl(Address(ESP, 0)); |
| 3436 | } |
| 3437 | |
| 3438 | // Pop the 2 items from the FP stack. |
| 3439 | __ fucompp(); |
| 3440 | |
| 3441 | // Load the value from the stack into an XMM register. |
| 3442 | DCHECK(out.IsFpuRegister()) << out; |
| 3443 | if (is_float) { |
| 3444 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3445 | } else { |
| 3446 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3447 | } |
| 3448 | |
| 3449 | // And remove the temporary stack space we allocated. |
| 3450 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3451 | } |
| 3452 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3453 | |
| 3454 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3455 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3456 | |
| 3457 | LocationSummary* locations = instruction->GetLocations(); |
| 3458 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3459 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3460 | |
| 3461 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3462 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3463 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3464 | |
| 3465 | DCHECK(imm == 1 || imm == -1); |
| 3466 | |
| 3467 | if (instruction->IsRem()) { |
| 3468 | __ xorl(out_register, out_register); |
| 3469 | } else { |
| 3470 | __ movl(out_register, input_register); |
| 3471 | if (imm == -1) { |
| 3472 | __ negl(out_register); |
| 3473 | } |
| 3474 | } |
| 3475 | } |
| 3476 | |
| 3477 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3478 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3479 | LocationSummary* locations = instruction->GetLocations(); |
| 3480 | |
| 3481 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3482 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3483 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3484 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3485 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3486 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3487 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3488 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3489 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3490 | __ testl(input_register, input_register); |
| 3491 | __ cmovl(kGreaterEqual, num, input_register); |
| 3492 | int shift = CTZ(imm); |
| 3493 | __ sarl(num, Immediate(shift)); |
| 3494 | |
| 3495 | if (imm < 0) { |
| 3496 | __ negl(num); |
| 3497 | } |
| 3498 | |
| 3499 | __ movl(out_register, num); |
| 3500 | } |
| 3501 | |
| 3502 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3503 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3504 | |
| 3505 | LocationSummary* locations = instruction->GetLocations(); |
| 3506 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3507 | |
| 3508 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3509 | Register out = locations->Out().AsRegister<Register>(); |
| 3510 | Register num; |
| 3511 | Register edx; |
| 3512 | |
| 3513 | if (instruction->IsDiv()) { |
| 3514 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3515 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3516 | } else { |
| 3517 | edx = locations->Out().AsRegister<Register>(); |
| 3518 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3519 | } |
| 3520 | |
| 3521 | DCHECK_EQ(EAX, eax); |
| 3522 | DCHECK_EQ(EDX, edx); |
| 3523 | if (instruction->IsDiv()) { |
| 3524 | DCHECK_EQ(EAX, out); |
| 3525 | } else { |
| 3526 | DCHECK_EQ(EDX, out); |
| 3527 | } |
| 3528 | |
| 3529 | int64_t magic; |
| 3530 | int shift; |
| 3531 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3532 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3533 | // Save the numerator. |
| 3534 | __ movl(num, eax); |
| 3535 | |
| 3536 | // EAX = magic |
| 3537 | __ movl(eax, Immediate(magic)); |
| 3538 | |
| 3539 | // EDX:EAX = magic * numerator |
| 3540 | __ imull(num); |
| 3541 | |
| 3542 | if (imm > 0 && magic < 0) { |
| 3543 | // EDX += num |
| 3544 | __ addl(edx, num); |
| 3545 | } else if (imm < 0 && magic > 0) { |
| 3546 | __ subl(edx, num); |
| 3547 | } |
| 3548 | |
| 3549 | // Shift if needed. |
| 3550 | if (shift != 0) { |
| 3551 | __ sarl(edx, Immediate(shift)); |
| 3552 | } |
| 3553 | |
| 3554 | // EDX += 1 if EDX < 0 |
| 3555 | __ movl(eax, edx); |
| 3556 | __ shrl(edx, Immediate(31)); |
| 3557 | __ addl(edx, eax); |
| 3558 | |
| 3559 | if (instruction->IsRem()) { |
| 3560 | __ movl(eax, num); |
| 3561 | __ imull(edx, Immediate(imm)); |
| 3562 | __ subl(eax, edx); |
| 3563 | __ movl(edx, eax); |
| 3564 | } else { |
| 3565 | __ movl(eax, edx); |
| 3566 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3567 | } |
| 3568 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3569 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3570 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3571 | |
| 3572 | LocationSummary* locations = instruction->GetLocations(); |
| 3573 | Location out = locations->Out(); |
| 3574 | Location first = locations->InAt(0); |
| 3575 | Location second = locations->InAt(1); |
| 3576 | bool is_div = instruction->IsDiv(); |
| 3577 | |
| 3578 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3579 | case DataType::Type::kInt32: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3580 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3581 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3582 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3583 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3584 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3585 | |
| 3586 | if (imm == 0) { |
| 3587 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3588 | } else if (imm == 1 || imm == -1) { |
| 3589 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3590 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3591 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3592 | } else { |
| 3593 | DCHECK(imm <= -2 || imm >= 2); |
| 3594 | GenerateDivRemWithAnyConstant(instruction); |
| 3595 | } |
| 3596 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3597 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3598 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3599 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3600 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3601 | Register second_reg = second.AsRegister<Register>(); |
| 3602 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3603 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3604 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3605 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3606 | __ cmpl(second_reg, Immediate(-1)); |
| 3607 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3608 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3609 | // edx:eax <- sign-extended of eax |
| 3610 | __ cdq(); |
| 3611 | // eax = quotient, edx = remainder |
| 3612 | __ idivl(second_reg); |
| 3613 | __ Bind(slow_path->GetExitLabel()); |
| 3614 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3615 | break; |
| 3616 | } |
| 3617 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3618 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3619 | InvokeRuntimeCallingConvention calling_convention; |
| 3620 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3621 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3622 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3623 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3624 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3625 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3626 | |
| 3627 | if (is_div) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3628 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3629 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3630 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3631 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3632 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3633 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3634 | break; |
| 3635 | } |
| 3636 | |
| 3637 | default: |
| 3638 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3639 | } |
| 3640 | } |
| 3641 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3642 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3643 | LocationSummary::CallKind call_kind = (div->GetResultType() == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3644 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3645 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3646 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3647 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3648 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3649 | case DataType::Type::kInt32: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3650 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3651 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3652 | locations->SetOut(Location::SameAsFirstInput()); |
| 3653 | // Intel uses edx:eax as the dividend. |
| 3654 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3655 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3656 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3657 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3658 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3659 | locations->AddTemp(Location::RequiresRegister()); |
| 3660 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3661 | break; |
| 3662 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3663 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3664 | InvokeRuntimeCallingConvention calling_convention; |
| 3665 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3666 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3667 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3668 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3669 | // Runtime helper puts the result in EAX, EDX. |
| 3670 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3671 | break; |
| 3672 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3673 | case DataType::Type::kFloat32: |
| 3674 | case DataType::Type::kFloat64: { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3675 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3676 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3677 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3678 | } else if (div->InputAt(1)->IsConstant()) { |
| 3679 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3680 | } else { |
| 3681 | locations->SetInAt(1, Location::Any()); |
| 3682 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3683 | locations->SetOut(Location::SameAsFirstInput()); |
| 3684 | break; |
| 3685 | } |
| 3686 | |
| 3687 | default: |
| 3688 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3689 | } |
| 3690 | } |
| 3691 | |
| 3692 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3693 | LocationSummary* locations = div->GetLocations(); |
| 3694 | Location first = locations->InAt(0); |
| 3695 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3696 | |
| 3697 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3698 | case DataType::Type::kInt32: |
| 3699 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3700 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3701 | break; |
| 3702 | } |
| 3703 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3704 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3705 | if (second.IsFpuRegister()) { |
| 3706 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3707 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3708 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3709 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3710 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3711 | codegen_->LiteralFloatAddress( |
| 3712 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3713 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3714 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3715 | } else { |
| 3716 | DCHECK(second.IsStackSlot()); |
| 3717 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3718 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3719 | break; |
| 3720 | } |
| 3721 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3722 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3723 | if (second.IsFpuRegister()) { |
| 3724 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3725 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3726 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3727 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3728 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3729 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3730 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3731 | const_area->GetBaseMethodAddress(), |
| 3732 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3733 | } else { |
| 3734 | DCHECK(second.IsDoubleStackSlot()); |
| 3735 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3736 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3737 | break; |
| 3738 | } |
| 3739 | |
| 3740 | default: |
| 3741 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3742 | } |
| 3743 | } |
| 3744 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3745 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3746 | DataType::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3747 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3748 | LocationSummary::CallKind call_kind = (rem->GetResultType() == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3749 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3750 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3751 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3752 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3753 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3754 | case DataType::Type::kInt32: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3755 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3756 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3757 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3758 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3759 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3760 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3761 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3762 | locations->AddTemp(Location::RequiresRegister()); |
| 3763 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3764 | break; |
| 3765 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3766 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3767 | InvokeRuntimeCallingConvention calling_convention; |
| 3768 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3769 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3770 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3771 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3772 | // Runtime helper puts the result in EAX, EDX. |
| 3773 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3774 | break; |
| 3775 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3776 | case DataType::Type::kFloat64: |
| 3777 | case DataType::Type::kFloat32: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3778 | locations->SetInAt(0, Location::Any()); |
| 3779 | locations->SetInAt(1, Location::Any()); |
| 3780 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3781 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3782 | break; |
| 3783 | } |
| 3784 | |
| 3785 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3786 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3787 | } |
| 3788 | } |
| 3789 | |
| 3790 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3791 | DataType::Type type = rem->GetResultType(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3792 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3793 | case DataType::Type::kInt32: |
| 3794 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3795 | GenerateDivRemIntegral(rem); |
| 3796 | break; |
| 3797 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3798 | case DataType::Type::kFloat32: |
| 3799 | case DataType::Type::kFloat64: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3800 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3801 | break; |
| 3802 | } |
| 3803 | default: |
| 3804 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3805 | } |
| 3806 | } |
| 3807 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 3808 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 3809 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 3810 | switch (minmax->GetResultType()) { |
| 3811 | case DataType::Type::kInt32: |
| 3812 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3813 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3814 | locations->SetOut(Location::SameAsFirstInput()); |
| 3815 | break; |
| 3816 | case DataType::Type::kInt64: |
| 3817 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3818 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3819 | locations->SetOut(Location::SameAsFirstInput()); |
| 3820 | // Register to use to perform a long subtract to set cc. |
| 3821 | locations->AddTemp(Location::RequiresRegister()); |
| 3822 | break; |
| 3823 | case DataType::Type::kFloat32: |
| 3824 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3825 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3826 | locations->SetOut(Location::SameAsFirstInput()); |
| 3827 | locations->AddTemp(Location::RequiresRegister()); |
| 3828 | break; |
| 3829 | case DataType::Type::kFloat64: |
| 3830 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3831 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3832 | locations->SetOut(Location::SameAsFirstInput()); |
| 3833 | break; |
| 3834 | default: |
| 3835 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 3836 | } |
| 3837 | } |
| 3838 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 3839 | void InstructionCodeGeneratorX86::GenerateMinMaxInt(LocationSummary* locations, |
| 3840 | bool is_min, |
| 3841 | DataType::Type type) { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 3842 | Location op1_loc = locations->InAt(0); |
| 3843 | Location op2_loc = locations->InAt(1); |
| 3844 | |
| 3845 | // Shortcut for same input locations. |
| 3846 | if (op1_loc.Equals(op2_loc)) { |
| 3847 | // Can return immediately, as op1_loc == out_loc. |
| 3848 | // Note: if we ever support separate registers, e.g., output into memory, we need to check for |
| 3849 | // a copy here. |
| 3850 | DCHECK(locations->Out().Equals(op1_loc)); |
| 3851 | return; |
| 3852 | } |
| 3853 | |
| 3854 | if (type == DataType::Type::kInt64) { |
| 3855 | // Need to perform a subtract to get the sign right. |
| 3856 | // op1 is already in the same location as the output. |
| 3857 | Location output = locations->Out(); |
| 3858 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 3859 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 3860 | |
| 3861 | Register op2_lo = op2_loc.AsRegisterPairLow<Register>(); |
| 3862 | Register op2_hi = op2_loc.AsRegisterPairHigh<Register>(); |
| 3863 | |
| 3864 | // The comparison is performed by subtracting the second operand from |
| 3865 | // the first operand and then setting the status flags in the same |
| 3866 | // manner as the SUB instruction." |
| 3867 | __ cmpl(output_lo, op2_lo); |
| 3868 | |
| 3869 | // Now use a temp and the borrow to finish the subtraction of op2_hi. |
| 3870 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3871 | __ movl(temp, output_hi); |
| 3872 | __ sbbl(temp, op2_hi); |
| 3873 | |
| 3874 | // Now the condition code is correct. |
| 3875 | Condition cond = is_min ? Condition::kGreaterEqual : Condition::kLess; |
| 3876 | __ cmovl(cond, output_lo, op2_lo); |
| 3877 | __ cmovl(cond, output_hi, op2_hi); |
| 3878 | } else { |
| 3879 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 3880 | Register out = locations->Out().AsRegister<Register>(); |
| 3881 | Register op2 = op2_loc.AsRegister<Register>(); |
| 3882 | |
| 3883 | // (out := op1) |
| 3884 | // out <=? op2 |
| 3885 | // if out is min jmp done |
| 3886 | // out := op2 |
| 3887 | // done: |
| 3888 | |
| 3889 | __ cmpl(out, op2); |
| 3890 | Condition cond = is_min ? Condition::kGreater : Condition::kLess; |
| 3891 | __ cmovl(cond, out, op2); |
| 3892 | } |
| 3893 | } |
| 3894 | |
| 3895 | void InstructionCodeGeneratorX86::GenerateMinMaxFP(LocationSummary* locations, |
| 3896 | bool is_min, |
| 3897 | DataType::Type type) { |
| 3898 | Location op1_loc = locations->InAt(0); |
| 3899 | Location op2_loc = locations->InAt(1); |
| 3900 | Location out_loc = locations->Out(); |
| 3901 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| 3902 | |
| 3903 | // Shortcut for same input locations. |
| 3904 | if (op1_loc.Equals(op2_loc)) { |
| 3905 | DCHECK(out_loc.Equals(op1_loc)); |
| 3906 | return; |
| 3907 | } |
| 3908 | |
| 3909 | // (out := op1) |
| 3910 | // out <=? op2 |
| 3911 | // if Nan jmp Nan_label |
| 3912 | // if out is min jmp done |
| 3913 | // if op2 is min jmp op2_label |
| 3914 | // handle -0/+0 |
| 3915 | // jmp done |
| 3916 | // Nan_label: |
| 3917 | // out := NaN |
| 3918 | // op2_label: |
| 3919 | // out := op2 |
| 3920 | // done: |
| 3921 | // |
| 3922 | // This removes one jmp, but needs to copy one input (op1) to out. |
| 3923 | // |
| 3924 | // TODO: This is straight from Quick (except literal pool). Make NaN an out-of-line slowpath? |
| 3925 | |
| 3926 | XmmRegister op2 = op2_loc.AsFpuRegister<XmmRegister>(); |
| 3927 | |
| 3928 | NearLabel nan, done, op2_label; |
| 3929 | if (type == DataType::Type::kFloat64) { |
| 3930 | __ ucomisd(out, op2); |
| 3931 | } else { |
| 3932 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 3933 | __ ucomiss(out, op2); |
| 3934 | } |
| 3935 | |
| 3936 | __ j(Condition::kParityEven, &nan); |
| 3937 | |
| 3938 | __ j(is_min ? Condition::kAbove : Condition::kBelow, &op2_label); |
| 3939 | __ j(is_min ? Condition::kBelow : Condition::kAbove, &done); |
| 3940 | |
| 3941 | // Handle 0.0/-0.0. |
| 3942 | if (is_min) { |
| 3943 | if (type == DataType::Type::kFloat64) { |
| 3944 | __ orpd(out, op2); |
| 3945 | } else { |
| 3946 | __ orps(out, op2); |
| 3947 | } |
| 3948 | } else { |
| 3949 | if (type == DataType::Type::kFloat64) { |
| 3950 | __ andpd(out, op2); |
| 3951 | } else { |
| 3952 | __ andps(out, op2); |
| 3953 | } |
| 3954 | } |
| 3955 | __ jmp(&done); |
| 3956 | |
| 3957 | // NaN handling. |
| 3958 | __ Bind(&nan); |
| 3959 | if (type == DataType::Type::kFloat64) { |
| 3960 | // TODO: Use a constant from the constant table (requires extra input). |
| 3961 | __ LoadLongConstant(out, kDoubleNaN); |
| 3962 | } else { |
| 3963 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 3964 | __ movl(constant, Immediate(kFloatNaN)); |
| 3965 | __ movd(out, constant); |
| 3966 | } |
| 3967 | __ jmp(&done); |
| 3968 | |
| 3969 | // out := op2; |
| 3970 | __ Bind(&op2_label); |
| 3971 | if (type == DataType::Type::kFloat64) { |
| 3972 | __ movsd(out, op2); |
| 3973 | } else { |
| 3974 | __ movss(out, op2); |
| 3975 | } |
| 3976 | |
| 3977 | // Done. |
| 3978 | __ Bind(&done); |
| 3979 | } |
| 3980 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 3981 | void InstructionCodeGeneratorX86::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 3982 | DataType::Type type = minmax->GetResultType(); |
| 3983 | switch (type) { |
| 3984 | case DataType::Type::kInt32: |
| 3985 | case DataType::Type::kInt64: |
| 3986 | GenerateMinMaxInt(minmax->GetLocations(), is_min, type); |
| 3987 | break; |
| 3988 | case DataType::Type::kFloat32: |
| 3989 | case DataType::Type::kFloat64: |
| 3990 | GenerateMinMaxFP(minmax->GetLocations(), is_min, type); |
| 3991 | break; |
| 3992 | default: |
| 3993 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 3994 | } |
| 3995 | } |
| 3996 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 3997 | void LocationsBuilderX86::VisitMin(HMin* min) { |
| 3998 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 3999 | } |
| 4000 | |
| 4001 | void InstructionCodeGeneratorX86::VisitMin(HMin* min) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4002 | GenerateMinMax(min, /*is_min*/ true); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4003 | } |
| 4004 | |
| 4005 | void LocationsBuilderX86::VisitMax(HMax* max) { |
| 4006 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4007 | } |
| 4008 | |
| 4009 | void InstructionCodeGeneratorX86::VisitMax(HMax* max) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4010 | GenerateMinMax(max, /*is_min*/ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4011 | } |
| 4012 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4013 | void LocationsBuilderX86::VisitAbs(HAbs* abs) { |
| 4014 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 4015 | switch (abs->GetResultType()) { |
| 4016 | case DataType::Type::kInt32: |
| 4017 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 4018 | locations->SetOut(Location::SameAsFirstInput()); |
| 4019 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 4020 | break; |
| 4021 | case DataType::Type::kInt64: |
| 4022 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4023 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4024 | locations->AddTemp(Location::RequiresRegister()); |
| 4025 | break; |
| 4026 | case DataType::Type::kFloat32: |
| 4027 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4028 | locations->SetOut(Location::SameAsFirstInput()); |
| 4029 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4030 | locations->AddTemp(Location::RequiresRegister()); |
| 4031 | break; |
| 4032 | case DataType::Type::kFloat64: |
| 4033 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4034 | locations->SetOut(Location::SameAsFirstInput()); |
| 4035 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4036 | break; |
| 4037 | default: |
| 4038 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4039 | } |
| 4040 | } |
| 4041 | |
| 4042 | void InstructionCodeGeneratorX86::VisitAbs(HAbs* abs) { |
| 4043 | LocationSummary* locations = abs->GetLocations(); |
| 4044 | switch (abs->GetResultType()) { |
| 4045 | case DataType::Type::kInt32: { |
| 4046 | Register out = locations->Out().AsRegister<Register>(); |
| 4047 | DCHECK_EQ(out, EAX); |
| 4048 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4049 | DCHECK_EQ(temp, EDX); |
| 4050 | // Sign extend EAX into EDX. |
| 4051 | __ cdq(); |
| 4052 | // XOR EAX with sign. |
| 4053 | __ xorl(EAX, EDX); |
| 4054 | // Subtract out sign to correct. |
| 4055 | __ subl(EAX, EDX); |
| 4056 | // The result is in EAX. |
| 4057 | break; |
| 4058 | } |
| 4059 | case DataType::Type::kInt64: { |
| 4060 | Location input = locations->InAt(0); |
| 4061 | Register input_lo = input.AsRegisterPairLow<Register>(); |
| 4062 | Register input_hi = input.AsRegisterPairHigh<Register>(); |
| 4063 | Location output = locations->Out(); |
| 4064 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 4065 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 4066 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4067 | // Compute the sign into the temporary. |
| 4068 | __ movl(temp, input_hi); |
| 4069 | __ sarl(temp, Immediate(31)); |
| 4070 | // Store the sign into the output. |
| 4071 | __ movl(output_lo, temp); |
| 4072 | __ movl(output_hi, temp); |
| 4073 | // XOR the input to the output. |
| 4074 | __ xorl(output_lo, input_lo); |
| 4075 | __ xorl(output_hi, input_hi); |
| 4076 | // Subtract the sign. |
| 4077 | __ subl(output_lo, temp); |
| 4078 | __ sbbl(output_hi, temp); |
| 4079 | break; |
| 4080 | } |
| 4081 | case DataType::Type::kFloat32: { |
| 4082 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4083 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4084 | Register constant = locations->GetTemp(1).AsRegister<Register>(); |
| 4085 | __ movl(constant, Immediate(INT32_C(0x7FFFFFFF))); |
| 4086 | __ movd(temp, constant); |
| 4087 | __ andps(out, temp); |
| 4088 | break; |
| 4089 | } |
| 4090 | case DataType::Type::kFloat64: { |
| 4091 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4092 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4093 | // TODO: Use a constant from the constant table (requires extra input). |
| 4094 | __ LoadLongConstant(temp, INT64_C(0x7FFFFFFFFFFFFFFF)); |
| 4095 | __ andpd(out, temp); |
| 4096 | break; |
| 4097 | } |
| 4098 | default: |
| 4099 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4100 | } |
| 4101 | } |
| 4102 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4103 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4104 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4105 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4106 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4107 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4108 | case DataType::Type::kInt8: |
| 4109 | case DataType::Type::kUint16: |
| 4110 | case DataType::Type::kInt16: |
| 4111 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4112 | locations->SetInAt(0, Location::Any()); |
| 4113 | break; |
| 4114 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4115 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4116 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 4117 | if (!instruction->IsConstant()) { |
| 4118 | locations->AddTemp(Location::RequiresRegister()); |
| 4119 | } |
| 4120 | break; |
| 4121 | } |
| 4122 | default: |
| 4123 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4124 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4125 | } |
| 4126 | |
| 4127 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4128 | SlowPathCode* slow_path = |
| 4129 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4130 | codegen_->AddSlowPath(slow_path); |
| 4131 | |
| 4132 | LocationSummary* locations = instruction->GetLocations(); |
| 4133 | Location value = locations->InAt(0); |
| 4134 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4135 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4136 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4137 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4138 | case DataType::Type::kInt8: |
| 4139 | case DataType::Type::kUint16: |
| 4140 | case DataType::Type::kInt16: |
| 4141 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4142 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4143 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4144 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4145 | } else if (value.IsStackSlot()) { |
| 4146 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 4147 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4148 | } else { |
| 4149 | DCHECK(value.IsConstant()) << value; |
| 4150 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4151 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4152 | } |
| 4153 | } |
| 4154 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4155 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4156 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4157 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4158 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4159 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 4160 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 4161 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4162 | } else { |
| 4163 | DCHECK(value.IsConstant()) << value; |
| 4164 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4165 | __ jmp(slow_path->GetEntryLabel()); |
| 4166 | } |
| 4167 | } |
| 4168 | break; |
| 4169 | } |
| 4170 | default: |
| 4171 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4172 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4173 | } |
| 4174 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4175 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 4176 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4177 | |
| 4178 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4179 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4180 | |
| 4181 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4182 | case DataType::Type::kInt32: |
| 4183 | case DataType::Type::kInt64: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4184 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4185 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4186 | // The shift count needs to be in CL or a constant. |
| 4187 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4188 | locations->SetOut(Location::SameAsFirstInput()); |
| 4189 | break; |
| 4190 | } |
| 4191 | default: |
| 4192 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4193 | } |
| 4194 | } |
| 4195 | |
| 4196 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 4197 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4198 | |
| 4199 | LocationSummary* locations = op->GetLocations(); |
| 4200 | Location first = locations->InAt(0); |
| 4201 | Location second = locations->InAt(1); |
| 4202 | DCHECK(first.Equals(locations->Out())); |
| 4203 | |
| 4204 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4205 | case DataType::Type::kInt32: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4206 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4207 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4208 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4209 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4210 | DCHECK_EQ(ECX, second_reg); |
| 4211 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4212 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4213 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4214 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4215 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4216 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4217 | } |
| 4218 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4219 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4220 | if (shift == 0) { |
| 4221 | return; |
| 4222 | } |
| 4223 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4224 | if (op->IsShl()) { |
| 4225 | __ shll(first_reg, imm); |
| 4226 | } else if (op->IsShr()) { |
| 4227 | __ sarl(first_reg, imm); |
| 4228 | } else { |
| 4229 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4230 | } |
| 4231 | } |
| 4232 | break; |
| 4233 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4234 | case DataType::Type::kInt64: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4235 | if (second.IsRegister()) { |
| 4236 | Register second_reg = second.AsRegister<Register>(); |
| 4237 | DCHECK_EQ(ECX, second_reg); |
| 4238 | if (op->IsShl()) { |
| 4239 | GenerateShlLong(first, second_reg); |
| 4240 | } else if (op->IsShr()) { |
| 4241 | GenerateShrLong(first, second_reg); |
| 4242 | } else { |
| 4243 | GenerateUShrLong(first, second_reg); |
| 4244 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4245 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4246 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4247 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4248 | // Nothing to do if the shift is 0, as the input is already the output. |
| 4249 | if (shift != 0) { |
| 4250 | if (op->IsShl()) { |
| 4251 | GenerateShlLong(first, shift); |
| 4252 | } else if (op->IsShr()) { |
| 4253 | GenerateShrLong(first, shift); |
| 4254 | } else { |
| 4255 | GenerateUShrLong(first, shift); |
| 4256 | } |
| 4257 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4258 | } |
| 4259 | break; |
| 4260 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4261 | default: |
| 4262 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4263 | } |
| 4264 | } |
| 4265 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4266 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 4267 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4268 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 4269 | if (shift == 1) { |
| 4270 | // This is just an addition. |
| 4271 | __ addl(low, low); |
| 4272 | __ adcl(high, high); |
| 4273 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4274 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 4275 | codegen_->EmitParallelMoves( |
| 4276 | loc.ToLow(), |
| 4277 | loc.ToHigh(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4278 | DataType::Type::kInt32, |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4279 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4280 | loc.ToLow(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4281 | DataType::Type::kInt32); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4282 | } else if (shift > 32) { |
| 4283 | // Low part becomes 0. High part is low part << (shift-32). |
| 4284 | __ movl(high, low); |
| 4285 | __ shll(high, Immediate(shift - 32)); |
| 4286 | __ xorl(low, low); |
| 4287 | } else { |
| 4288 | // Between 1 and 31. |
| 4289 | __ shld(high, low, Immediate(shift)); |
| 4290 | __ shll(low, Immediate(shift)); |
| 4291 | } |
| 4292 | } |
| 4293 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4294 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4295 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4296 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 4297 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 4298 | __ testl(shifter, Immediate(32)); |
| 4299 | __ j(kEqual, &done); |
| 4300 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 4301 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 4302 | __ Bind(&done); |
| 4303 | } |
| 4304 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4305 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 4306 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4307 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4308 | if (shift == 32) { |
| 4309 | // Need to copy the sign. |
| 4310 | DCHECK_NE(low, high); |
| 4311 | __ movl(low, high); |
| 4312 | __ sarl(high, Immediate(31)); |
| 4313 | } else if (shift > 32) { |
| 4314 | DCHECK_NE(low, high); |
| 4315 | // High part becomes sign. Low part is shifted by shift - 32. |
| 4316 | __ movl(low, high); |
| 4317 | __ sarl(high, Immediate(31)); |
| 4318 | __ sarl(low, Immediate(shift - 32)); |
| 4319 | } else { |
| 4320 | // Between 1 and 31. |
| 4321 | __ shrd(low, high, Immediate(shift)); |
| 4322 | __ sarl(high, Immediate(shift)); |
| 4323 | } |
| 4324 | } |
| 4325 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4326 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4327 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4328 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4329 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4330 | __ testl(shifter, Immediate(32)); |
| 4331 | __ j(kEqual, &done); |
| 4332 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4333 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 4334 | __ Bind(&done); |
| 4335 | } |
| 4336 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4337 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 4338 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4339 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4340 | if (shift == 32) { |
| 4341 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 4342 | codegen_->EmitParallelMoves( |
| 4343 | loc.ToHigh(), |
| 4344 | loc.ToLow(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4345 | DataType::Type::kInt32, |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4346 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4347 | loc.ToHigh(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4348 | DataType::Type::kInt32); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4349 | } else if (shift > 32) { |
| 4350 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4351 | __ movl(low, high); |
| 4352 | __ shrl(low, Immediate(shift - 32)); |
| 4353 | __ xorl(high, high); |
| 4354 | } else { |
| 4355 | // Between 1 and 31. |
| 4356 | __ shrd(low, high, Immediate(shift)); |
| 4357 | __ shrl(high, Immediate(shift)); |
| 4358 | } |
| 4359 | } |
| 4360 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4361 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4362 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4363 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4364 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4365 | __ testl(shifter, Immediate(32)); |
| 4366 | __ j(kEqual, &done); |
| 4367 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4368 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4369 | __ Bind(&done); |
| 4370 | } |
| 4371 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4372 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4373 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4374 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4375 | |
| 4376 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4377 | case DataType::Type::kInt64: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4378 | // Add the temporary needed. |
| 4379 | locations->AddTemp(Location::RequiresRegister()); |
| 4380 | FALLTHROUGH_INTENDED; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4381 | case DataType::Type::kInt32: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4382 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4383 | // The shift count needs to be in CL (unless it is a constant). |
| 4384 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4385 | locations->SetOut(Location::SameAsFirstInput()); |
| 4386 | break; |
| 4387 | default: |
| 4388 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4389 | UNREACHABLE(); |
| 4390 | } |
| 4391 | } |
| 4392 | |
| 4393 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4394 | LocationSummary* locations = ror->GetLocations(); |
| 4395 | Location first = locations->InAt(0); |
| 4396 | Location second = locations->InAt(1); |
| 4397 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4398 | if (ror->GetResultType() == DataType::Type::kInt32) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4399 | Register first_reg = first.AsRegister<Register>(); |
| 4400 | if (second.IsRegister()) { |
| 4401 | Register second_reg = second.AsRegister<Register>(); |
| 4402 | __ rorl(first_reg, second_reg); |
| 4403 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4404 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4405 | __ rorl(first_reg, imm); |
| 4406 | } |
| 4407 | return; |
| 4408 | } |
| 4409 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4410 | DCHECK_EQ(ror->GetResultType(), DataType::Type::kInt64); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4411 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4412 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4413 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4414 | if (second.IsRegister()) { |
| 4415 | Register second_reg = second.AsRegister<Register>(); |
| 4416 | DCHECK_EQ(second_reg, ECX); |
| 4417 | __ movl(temp_reg, first_reg_hi); |
| 4418 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4419 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4420 | __ movl(temp_reg, first_reg_hi); |
| 4421 | __ testl(second_reg, Immediate(32)); |
| 4422 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4423 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4424 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4425 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4426 | if (shift_amt == 0) { |
| 4427 | // Already fine. |
| 4428 | return; |
| 4429 | } |
| 4430 | if (shift_amt == 32) { |
| 4431 | // Just swap. |
| 4432 | __ movl(temp_reg, first_reg_lo); |
| 4433 | __ movl(first_reg_lo, first_reg_hi); |
| 4434 | __ movl(first_reg_hi, temp_reg); |
| 4435 | return; |
| 4436 | } |
| 4437 | |
| 4438 | Immediate imm(shift_amt); |
| 4439 | // Save the constents of the low value. |
| 4440 | __ movl(temp_reg, first_reg_lo); |
| 4441 | |
| 4442 | // Shift right into low, feeding bits from high. |
| 4443 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4444 | |
| 4445 | // Shift right into high, feeding bits from the original low. |
| 4446 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4447 | |
| 4448 | // Swap if needed. |
| 4449 | if (shift_amt > 32) { |
| 4450 | __ movl(temp_reg, first_reg_lo); |
| 4451 | __ movl(first_reg_lo, first_reg_hi); |
| 4452 | __ movl(first_reg_hi, temp_reg); |
| 4453 | } |
| 4454 | } |
| 4455 | } |
| 4456 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4457 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4458 | HandleShift(shl); |
| 4459 | } |
| 4460 | |
| 4461 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4462 | HandleShift(shl); |
| 4463 | } |
| 4464 | |
| 4465 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4466 | HandleShift(shr); |
| 4467 | } |
| 4468 | |
| 4469 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4470 | HandleShift(shr); |
| 4471 | } |
| 4472 | |
| 4473 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4474 | HandleShift(ushr); |
| 4475 | } |
| 4476 | |
| 4477 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4478 | HandleShift(ushr); |
| 4479 | } |
| 4480 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4481 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4482 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4483 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4484 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4485 | if (instruction->IsStringAlloc()) { |
| 4486 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4487 | } else { |
| 4488 | InvokeRuntimeCallingConvention calling_convention; |
| 4489 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4490 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4491 | } |
| 4492 | |
| 4493 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4494 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4495 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4496 | if (instruction->IsStringAlloc()) { |
| 4497 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4498 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4499 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4500 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4501 | __ call(Address(temp, code_offset.Int32Value())); |
| 4502 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4503 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4504 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4505 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4506 | DCHECK(!codegen_->IsLeafMethod()); |
| 4507 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4508 | } |
| 4509 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4510 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4511 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4512 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4513 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4514 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4515 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4516 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4517 | } |
| 4518 | |
| 4519 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4520 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4521 | // of poisoning the reference. |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4522 | QuickEntrypointEnum entrypoint = |
| 4523 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4524 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4525 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4526 | DCHECK(!codegen_->IsLeafMethod()); |
| 4527 | } |
| 4528 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4529 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4530 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4531 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4532 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4533 | if (location.IsStackSlot()) { |
| 4534 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4535 | } else if (location.IsDoubleStackSlot()) { |
| 4536 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4537 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4538 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4539 | } |
| 4540 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4541 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4542 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4543 | } |
| 4544 | |
| 4545 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4546 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4547 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4548 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4549 | } |
| 4550 | |
| 4551 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4552 | } |
| 4553 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4554 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4555 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4556 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4557 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4558 | locations->SetOut(Location::RequiresRegister()); |
| 4559 | } |
| 4560 | |
| 4561 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4562 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4563 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4564 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4565 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4566 | __ movl(locations->Out().AsRegister<Register>(), |
| 4567 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4568 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4569 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4570 | instruction->GetIndex(), kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4571 | __ movl(locations->Out().AsRegister<Register>(), |
| 4572 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4573 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4574 | // temp = temp->GetImtEntryAt(method_offset); |
| 4575 | __ movl(locations->Out().AsRegister<Register>(), |
| 4576 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4577 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4578 | } |
| 4579 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4580 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4581 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4582 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4583 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4584 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4585 | } |
| 4586 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4587 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4588 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4589 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4590 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4591 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4592 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4593 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4594 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4595 | break; |
| 4596 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4597 | case DataType::Type::kInt64: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4598 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4599 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4600 | break; |
| 4601 | |
| 4602 | default: |
| 4603 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4604 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4605 | } |
| 4606 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4607 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4608 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4609 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4610 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4611 | locations->SetOut(Location::SameAsFirstInput()); |
| 4612 | } |
| 4613 | |
| 4614 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4615 | LocationSummary* locations = bool_not->GetLocations(); |
| 4616 | Location in = locations->InAt(0); |
| 4617 | Location out = locations->Out(); |
| 4618 | DCHECK(in.Equals(out)); |
| 4619 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4620 | } |
| 4621 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4622 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4623 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4624 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4625 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4626 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4627 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4628 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4629 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4630 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4631 | case DataType::Type::kInt32: |
| 4632 | case DataType::Type::kInt64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4633 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4634 | locations->SetInAt(1, Location::Any()); |
| 4635 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4636 | break; |
| 4637 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4638 | case DataType::Type::kFloat32: |
| 4639 | case DataType::Type::kFloat64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4640 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4641 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4642 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4643 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4644 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4645 | } else { |
| 4646 | locations->SetInAt(1, Location::Any()); |
| 4647 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4648 | locations->SetOut(Location::RequiresRegister()); |
| 4649 | break; |
| 4650 | } |
| 4651 | default: |
| 4652 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4653 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4654 | } |
| 4655 | |
| 4656 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4657 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4658 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4659 | Location left = locations->InAt(0); |
| 4660 | Location right = locations->InAt(1); |
| 4661 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4662 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4663 | Condition less_cond = kLess; |
| 4664 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4665 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4666 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4667 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4668 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4669 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4670 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4671 | case DataType::Type::kInt32: { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4672 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4673 | break; |
| 4674 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4675 | case DataType::Type::kInt64: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4676 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4677 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4678 | int32_t val_low = 0; |
| 4679 | int32_t val_high = 0; |
| 4680 | bool right_is_const = false; |
| 4681 | |
| 4682 | if (right.IsConstant()) { |
| 4683 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4684 | right_is_const = true; |
| 4685 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4686 | val_low = Low32Bits(val); |
| 4687 | val_high = High32Bits(val); |
| 4688 | } |
| 4689 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4690 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4691 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4692 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4693 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4694 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4695 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4696 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4697 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4698 | __ j(kLess, &less); // Signed compare. |
| 4699 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4700 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4701 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4702 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4703 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4704 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4705 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4706 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4707 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4708 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4709 | break; |
| 4710 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4711 | case DataType::Type::kFloat32: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4712 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4713 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4714 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4715 | break; |
| 4716 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4717 | case DataType::Type::kFloat64: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4718 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4719 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4720 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4721 | break; |
| 4722 | } |
| 4723 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4724 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4725 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4726 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4727 | __ movl(out, Immediate(0)); |
| 4728 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4729 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4730 | |
| 4731 | __ Bind(&greater); |
| 4732 | __ movl(out, Immediate(1)); |
| 4733 | __ jmp(&done); |
| 4734 | |
| 4735 | __ Bind(&less); |
| 4736 | __ movl(out, Immediate(-1)); |
| 4737 | |
| 4738 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4739 | } |
| 4740 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4741 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4742 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4743 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4744 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4745 | locations->SetInAt(i, Location::Any()); |
| 4746 | } |
| 4747 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4748 | } |
| 4749 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4750 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4751 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4752 | } |
| 4753 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4754 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4755 | /* |
| 4756 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4757 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4758 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4759 | */ |
| 4760 | switch (kind) { |
| 4761 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4762 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4763 | break; |
| 4764 | } |
| 4765 | case MemBarrierKind::kAnyStore: |
| 4766 | case MemBarrierKind::kLoadAny: |
| 4767 | case MemBarrierKind::kStoreStore: { |
| 4768 | // nop |
| 4769 | break; |
| 4770 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4771 | case MemBarrierKind::kNTStoreStore: |
| 4772 | // Non-Temporal Store/Store needs an explicit fence. |
| 4773 | MemoryFence(/* non-temporal */ true); |
| 4774 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4775 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4776 | } |
| 4777 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4778 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4779 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4780 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4781 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4782 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4783 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4784 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4785 | Register temp) { |
| 4786 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4787 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4788 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4789 | return location.AsRegister<Register>(); |
| 4790 | } |
| 4791 | // For intrinsics we allow any location, so it may be on the stack. |
| 4792 | if (!location.IsRegister()) { |
| 4793 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4794 | return temp; |
| 4795 | } |
| 4796 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4797 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4798 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4799 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4800 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 4801 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4802 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4803 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4804 | __ movl(temp, Address(ESP, stack_offset)); |
| 4805 | return temp; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4806 | } |
| 4807 | return location.AsRegister<Register>(); |
| 4808 | } |
| 4809 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4810 | void CodeGeneratorX86::GenerateStaticOrDirectCall( |
| 4811 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4812 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4813 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4814 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4815 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4816 | uint32_t offset = |
| 4817 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4818 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4819 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4820 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4821 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4822 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4823 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4824 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4825 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4826 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4827 | temp.AsRegister<Register>()); |
| 4828 | __ leal(temp.AsRegister<Register>(), Address(base_reg, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4829 | RecordBootImageMethodPatch(invoke); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4830 | break; |
| 4831 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4832 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4833 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4834 | break; |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4835 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
| 4836 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4837 | temp.AsRegister<Register>()); |
| 4838 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
| 4839 | RecordBootImageRelRoPatch( |
| 4840 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(), |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4841 | GetBootImageOffset(invoke)); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4842 | break; |
| 4843 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4844 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4845 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4846 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4847 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4848 | RecordMethodBssEntryPatch(invoke); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4849 | break; |
| 4850 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4851 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4852 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4853 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4854 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4855 | } |
| 4856 | |
| 4857 | switch (invoke->GetCodePtrLocation()) { |
| 4858 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4859 | __ call(GetFrameEntryLabel()); |
| 4860 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4861 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4862 | // (callee_method + offset_of_quick_compiled_code)() |
| 4863 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4864 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4865 | kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4866 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4867 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4868 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4869 | |
| 4870 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4871 | } |
| 4872 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4873 | void CodeGeneratorX86::GenerateVirtualCall( |
| 4874 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4875 | Register temp = temp_in.AsRegister<Register>(); |
| 4876 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4877 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4878 | |
| 4879 | // Use the calling convention instead of the location of the receiver, as |
| 4880 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4881 | // slow path, the arguments have been moved to the right place, so here we are |
| 4882 | // guaranteed that the receiver is the first register of the calling convention. |
| 4883 | InvokeDexCallingConvention calling_convention; |
| 4884 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4885 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4886 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4887 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4888 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4889 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4890 | // emit a read barrier for the previous class reference load. |
| 4891 | // However this is not required in practice, as this is an |
| 4892 | // intermediate/temporary reference and because the current |
| 4893 | // concurrent copying collector keeps the from-space memory |
| 4894 | // intact/accessible until the end of the marking phase (the |
| 4895 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4896 | __ MaybeUnpoisonHeapReference(temp); |
| 4897 | // temp = temp->GetMethodAt(method_offset); |
| 4898 | __ movl(temp, Address(temp, method_offset)); |
| 4899 | // call temp->GetEntryPoint(); |
| 4900 | __ call(Address( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4901 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4902 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4903 | } |
| 4904 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4905 | void CodeGeneratorX86::RecordBootImageRelRoPatch(HX86ComputeBaseMethodAddress* method_address, |
| 4906 | uint32_t boot_image_offset) { |
| 4907 | boot_image_method_patches_.emplace_back( |
| 4908 | method_address, /* target_dex_file */ nullptr, boot_image_offset); |
| 4909 | __ Bind(&boot_image_method_patches_.back().label); |
| 4910 | } |
| 4911 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4912 | void CodeGeneratorX86::RecordBootImageMethodPatch(HInvokeStaticOrDirect* invoke) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4913 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4914 | HX86ComputeBaseMethodAddress* method_address = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4915 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4916 | boot_image_method_patches_.emplace_back( |
| 4917 | method_address, invoke->GetTargetMethod().dex_file, invoke->GetTargetMethod().index); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4918 | __ Bind(&boot_image_method_patches_.back().label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4919 | } |
| 4920 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4921 | void CodeGeneratorX86::RecordMethodBssEntryPatch(HInvokeStaticOrDirect* invoke) { |
| 4922 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 4923 | HX86ComputeBaseMethodAddress* method_address = |
| 4924 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4925 | // Add the patch entry and bind its label at the end of the instruction. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4926 | method_bss_entry_patches_.emplace_back( |
| 4927 | method_address, &GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 4928 | __ Bind(&method_bss_entry_patches_.back().label); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4929 | } |
| 4930 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4931 | void CodeGeneratorX86::RecordBootImageTypePatch(HLoadClass* load_class) { |
| 4932 | HX86ComputeBaseMethodAddress* method_address = |
| 4933 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4934 | boot_image_type_patches_.emplace_back( |
| 4935 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4936 | __ Bind(&boot_image_type_patches_.back().label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4937 | } |
| 4938 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4939 | Label* CodeGeneratorX86::NewTypeBssEntryPatch(HLoadClass* load_class) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4940 | HX86ComputeBaseMethodAddress* method_address = |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4941 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4942 | type_bss_entry_patches_.emplace_back( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4943 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4944 | return &type_bss_entry_patches_.back().label; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4945 | } |
| 4946 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4947 | void CodeGeneratorX86::RecordBootImageStringPatch(HLoadString* load_string) { |
| 4948 | HX86ComputeBaseMethodAddress* method_address = |
| 4949 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4950 | boot_image_string_patches_.emplace_back( |
| 4951 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 4952 | __ Bind(&boot_image_string_patches_.back().label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4953 | } |
| 4954 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4955 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
| 4956 | DCHECK(!GetCompilerOptions().IsBootImage()); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4957 | HX86ComputeBaseMethodAddress* method_address = |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4958 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4959 | string_bss_entry_patches_.emplace_back( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4960 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4961 | return &string_bss_entry_patches_.back().label; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4962 | } |
| 4963 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4964 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 4965 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4966 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 4967 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4968 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4969 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4970 | const ArenaDeque<X86PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4971 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4972 | for (const X86PcRelativePatchInfo& info : infos) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4973 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4974 | linker_patches->push_back(Factory(literal_offset, |
| 4975 | info.target_dex_file, |
| 4976 | GetMethodAddressOffset(info.method_address), |
| 4977 | info.offset_or_index)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4978 | } |
| 4979 | } |
| 4980 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4981 | linker::LinkerPatch DataBimgRelRoPatchAdapter(size_t literal_offset, |
| 4982 | const DexFile* target_dex_file, |
| 4983 | uint32_t pc_insn_offset, |
| 4984 | uint32_t boot_image_offset) { |
| 4985 | DCHECK(target_dex_file == nullptr); // Unused for DataBimgRelRoPatch(), should be null. |
| 4986 | return linker::LinkerPatch::DataBimgRelRoPatch(literal_offset, pc_insn_offset, boot_image_offset); |
| 4987 | } |
| 4988 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4989 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4990 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4991 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4992 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4993 | method_bss_entry_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4994 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4995 | type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4996 | boot_image_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4997 | string_bss_entry_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4998 | linker_patches->reserve(size); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4999 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5000 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 5001 | boot_image_method_patches_, linker_patches); |
| 5002 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 5003 | boot_image_type_patches_, linker_patches); |
| 5004 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5005 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5006 | } else { |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5007 | EmitPcRelativeLinkerPatches<DataBimgRelRoPatchAdapter>( |
| 5008 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5009 | DCHECK(boot_image_type_patches_.empty()); |
| 5010 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5011 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5012 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 5013 | method_bss_entry_patches_, linker_patches); |
| 5014 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 5015 | type_bss_entry_patches_, linker_patches); |
| 5016 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 5017 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5018 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5019 | } |
| 5020 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5021 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 5022 | Register card, |
| 5023 | Register object, |
| 5024 | Register value, |
| 5025 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5026 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5027 | if (value_can_be_null) { |
| 5028 | __ testl(value, value); |
| 5029 | __ j(kEqual, &is_null); |
| 5030 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5031 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5032 | __ movl(temp, object); |
| 5033 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 5034 | __ movb(Address(temp, card, TIMES_1, 0), |
| 5035 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5036 | if (value_can_be_null) { |
| 5037 | __ Bind(&is_null); |
| 5038 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5039 | } |
| 5040 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5041 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5042 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5043 | |
| 5044 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5045 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5046 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5047 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5048 | kEmitCompilerReadBarrier |
| 5049 | ? LocationSummary::kCallOnSlowPath |
| 5050 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5051 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5052 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5053 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5054 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5055 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5056 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5057 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5058 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5059 | // The output overlaps in case of long: we don't want the low move |
| 5060 | // to overwrite the object's location. Likewise, in the case of |
| 5061 | // an object field get with read barriers enabled, we do not want |
| 5062 | // the move to overwrite the object's location, as we need it to emit |
| 5063 | // the read barrier. |
| 5064 | locations->SetOut( |
| 5065 | Location::RequiresRegister(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5066 | (object_field_get_with_read_barrier || instruction->GetType() == DataType::Type::kInt64) ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5067 | Location::kOutputOverlap : |
| 5068 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5069 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5070 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5071 | if (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5072 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5073 | // So we use an XMM register as a temp to achieve atomicity (first |
| 5074 | // load the temp into the XMM and then copy the XMM into the |
| 5075 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5076 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 5077 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5078 | } |
| 5079 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5080 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 5081 | const FieldInfo& field_info) { |
| 5082 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5083 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5084 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5085 | Location base_loc = locations->InAt(0); |
| 5086 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5087 | Location out = locations->Out(); |
| 5088 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5089 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 5090 | DataType::Type load_type = instruction->GetType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5091 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5092 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5093 | switch (load_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5094 | case DataType::Type::kBool: |
| 5095 | case DataType::Type::kUint8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5096 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5097 | break; |
| 5098 | } |
| 5099 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5100 | case DataType::Type::kInt8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5101 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5102 | break; |
| 5103 | } |
| 5104 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5105 | case DataType::Type::kUint16: { |
| 5106 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5107 | break; |
| 5108 | } |
| 5109 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5110 | case DataType::Type::kInt16: { |
| 5111 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5112 | break; |
| 5113 | } |
| 5114 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5115 | case DataType::Type::kInt32: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5116 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5117 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5118 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5119 | case DataType::Type::kReference: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5120 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5121 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5122 | // Note that a potential implicit null check is handled in this |
| 5123 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 5124 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5125 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5126 | if (is_volatile) { |
| 5127 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5128 | } |
| 5129 | } else { |
| 5130 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 5131 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5132 | if (is_volatile) { |
| 5133 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5134 | } |
| 5135 | // If read barriers are enabled, emit read barriers other than |
| 5136 | // Baker's using a slow path (and also unpoison the loaded |
| 5137 | // reference, if heap poisoning is enabled). |
| 5138 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 5139 | } |
| 5140 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5141 | } |
| 5142 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5143 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5144 | if (is_volatile) { |
| 5145 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 5146 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5147 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5148 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 5149 | __ psrlq(temp, Immediate(32)); |
| 5150 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 5151 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5152 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5153 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5154 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5155 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 5156 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5157 | break; |
| 5158 | } |
| 5159 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5160 | case DataType::Type::kFloat32: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5161 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5162 | break; |
| 5163 | } |
| 5164 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5165 | case DataType::Type::kFloat64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5166 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5167 | break; |
| 5168 | } |
| 5169 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5170 | case DataType::Type::kUint32: |
| 5171 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5172 | case DataType::Type::kVoid: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5173 | LOG(FATAL) << "Unreachable type " << load_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5174 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5175 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5176 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5177 | if (load_type == DataType::Type::kReference || load_type == DataType::Type::kInt64) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5178 | // Potential implicit null checks, in the case of reference or |
| 5179 | // long fields, are handled in the previous switch statement. |
| 5180 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5181 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5182 | } |
| 5183 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5184 | if (is_volatile) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5185 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5186 | // Memory barriers, in the case of references, are also handled |
| 5187 | // in the previous switch statement. |
| 5188 | } else { |
| 5189 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5190 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5191 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5192 | } |
| 5193 | |
| 5194 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5195 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5196 | |
| 5197 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5198 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5199 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5200 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5201 | DataType::Type field_type = field_info.GetFieldType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5202 | bool is_byte_type = DataType::Size(field_type) == 1u; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5203 | |
| 5204 | // The register allocator does not support multiple |
| 5205 | // inputs that die at entry with one in a specific register. |
| 5206 | if (is_byte_type) { |
| 5207 | // Ensure the value is in a byte register. |
| 5208 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5209 | } else if (DataType::IsFloatingPointType(field_type)) { |
| 5210 | if (is_volatile && field_type == DataType::Type::kFloat64) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5211 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 5212 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5213 | } else { |
| 5214 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 5215 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5216 | } else if (is_volatile && field_type == DataType::Type::kInt64) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5217 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5218 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5219 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5220 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 5221 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 5222 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 5223 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 5224 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 5225 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 5226 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5227 | } else { |
| 5228 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5229 | |
| 5230 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5231 | // Temporary registers for the write barrier. |
| 5232 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 5233 | // Ensure the card is in a byte register. |
| 5234 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 5235 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5236 | } |
| 5237 | } |
| 5238 | |
| 5239 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5240 | const FieldInfo& field_info, |
| 5241 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5242 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5243 | |
| 5244 | LocationSummary* locations = instruction->GetLocations(); |
| 5245 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 5246 | Location value = locations->InAt(1); |
| 5247 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5248 | DataType::Type field_type = field_info.GetFieldType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5249 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5250 | bool needs_write_barrier = |
| 5251 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5252 | |
| 5253 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5254 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5255 | } |
| 5256 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5257 | bool maybe_record_implicit_null_check_done = false; |
| 5258 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5259 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5260 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5261 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5262 | case DataType::Type::kInt8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5263 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 5264 | break; |
| 5265 | } |
| 5266 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5267 | case DataType::Type::kUint16: |
| 5268 | case DataType::Type::kInt16: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5269 | if (value.IsConstant()) { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5270 | __ movw(Address(base, offset), |
| 5271 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5272 | } else { |
| 5273 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 5274 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5275 | break; |
| 5276 | } |
| 5277 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5278 | case DataType::Type::kInt32: |
| 5279 | case DataType::Type::kReference: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5280 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5281 | // Note that in the case where `value` is a null reference, |
| 5282 | // we do not enter this block, as the reference does not |
| 5283 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5284 | DCHECK_EQ(field_type, DataType::Type::kReference); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5285 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5286 | __ movl(temp, value.AsRegister<Register>()); |
| 5287 | __ PoisonHeapReference(temp); |
| 5288 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5289 | } else if (value.IsConstant()) { |
| 5290 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5291 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5292 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 5293 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5294 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 5295 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5296 | break; |
| 5297 | } |
| 5298 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5299 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5300 | if (is_volatile) { |
| 5301 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 5302 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 5303 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 5304 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 5305 | __ punpckldq(temp1, temp2); |
| 5306 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5307 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5308 | } else if (value.IsConstant()) { |
| 5309 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5310 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5311 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5312 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5313 | } else { |
| 5314 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5315 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5316 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 5317 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5318 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5319 | break; |
| 5320 | } |
| 5321 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5322 | case DataType::Type::kFloat32: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5323 | if (value.IsConstant()) { |
| 5324 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5325 | __ movl(Address(base, offset), Immediate(v)); |
| 5326 | } else { |
| 5327 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5328 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5329 | break; |
| 5330 | } |
| 5331 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5332 | case DataType::Type::kFloat64: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5333 | if (value.IsConstant()) { |
| 5334 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5335 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5336 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5337 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 5338 | maybe_record_implicit_null_check_done = true; |
| 5339 | } else { |
| 5340 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5341 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5342 | break; |
| 5343 | } |
| 5344 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5345 | case DataType::Type::kUint32: |
| 5346 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5347 | case DataType::Type::kVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5348 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5349 | UNREACHABLE(); |
| 5350 | } |
| 5351 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5352 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5353 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5354 | } |
| 5355 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5356 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5357 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5358 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5359 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5360 | } |
| 5361 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5362 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5363 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5364 | } |
| 5365 | } |
| 5366 | |
| 5367 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5368 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5369 | } |
| 5370 | |
| 5371 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5372 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5373 | } |
| 5374 | |
| 5375 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5376 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5377 | } |
| 5378 | |
| 5379 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5380 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5381 | } |
| 5382 | |
| 5383 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5384 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5385 | } |
| 5386 | |
| 5387 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5388 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5389 | } |
| 5390 | |
| 5391 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5392 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5393 | } |
| 5394 | |
| 5395 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5396 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5397 | } |
| 5398 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5399 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 5400 | HUnresolvedInstanceFieldGet* instruction) { |
| 5401 | FieldAccessCallingConventionX86 calling_convention; |
| 5402 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5403 | instruction, instruction->GetFieldType(), calling_convention); |
| 5404 | } |
| 5405 | |
| 5406 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 5407 | HUnresolvedInstanceFieldGet* instruction) { |
| 5408 | FieldAccessCallingConventionX86 calling_convention; |
| 5409 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5410 | instruction->GetFieldType(), |
| 5411 | instruction->GetFieldIndex(), |
| 5412 | instruction->GetDexPc(), |
| 5413 | calling_convention); |
| 5414 | } |
| 5415 | |
| 5416 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 5417 | HUnresolvedInstanceFieldSet* instruction) { |
| 5418 | FieldAccessCallingConventionX86 calling_convention; |
| 5419 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5420 | instruction, instruction->GetFieldType(), calling_convention); |
| 5421 | } |
| 5422 | |
| 5423 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 5424 | HUnresolvedInstanceFieldSet* instruction) { |
| 5425 | FieldAccessCallingConventionX86 calling_convention; |
| 5426 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5427 | instruction->GetFieldType(), |
| 5428 | instruction->GetFieldIndex(), |
| 5429 | instruction->GetDexPc(), |
| 5430 | calling_convention); |
| 5431 | } |
| 5432 | |
| 5433 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 5434 | HUnresolvedStaticFieldGet* instruction) { |
| 5435 | FieldAccessCallingConventionX86 calling_convention; |
| 5436 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5437 | instruction, instruction->GetFieldType(), calling_convention); |
| 5438 | } |
| 5439 | |
| 5440 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 5441 | HUnresolvedStaticFieldGet* instruction) { |
| 5442 | FieldAccessCallingConventionX86 calling_convention; |
| 5443 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5444 | instruction->GetFieldType(), |
| 5445 | instruction->GetFieldIndex(), |
| 5446 | instruction->GetDexPc(), |
| 5447 | calling_convention); |
| 5448 | } |
| 5449 | |
| 5450 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 5451 | HUnresolvedStaticFieldSet* instruction) { |
| 5452 | FieldAccessCallingConventionX86 calling_convention; |
| 5453 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5454 | instruction, instruction->GetFieldType(), calling_convention); |
| 5455 | } |
| 5456 | |
| 5457 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 5458 | HUnresolvedStaticFieldSet* instruction) { |
| 5459 | FieldAccessCallingConventionX86 calling_convention; |
| 5460 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5461 | instruction->GetFieldType(), |
| 5462 | instruction->GetFieldIndex(), |
| 5463 | instruction->GetDexPc(), |
| 5464 | calling_convention); |
| 5465 | } |
| 5466 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5467 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5468 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5469 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5470 | ? Location::RequiresRegister() |
| 5471 | : Location::Any(); |
| 5472 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5473 | } |
| 5474 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5475 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5476 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5477 | return; |
| 5478 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5479 | LocationSummary* locations = instruction->GetLocations(); |
| 5480 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5481 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5482 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5483 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5484 | } |
| 5485 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5486 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5487 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5488 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5489 | |
| 5490 | LocationSummary* locations = instruction->GetLocations(); |
| 5491 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5492 | |
| 5493 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5494 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5495 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5496 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5497 | } else { |
| 5498 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5499 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5500 | __ jmp(slow_path->GetEntryLabel()); |
| 5501 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5502 | } |
| 5503 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5504 | } |
| 5505 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5506 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5507 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5508 | } |
| 5509 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5510 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5511 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5512 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5513 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5514 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5515 | object_array_get_with_read_barrier |
| 5516 | ? LocationSummary::kCallOnSlowPath |
| 5517 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5518 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5519 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5520 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5521 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5522 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5523 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5524 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5525 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5526 | // The output overlaps in case of long: we don't want the low move |
| 5527 | // to overwrite the array's location. Likewise, in the case of an |
| 5528 | // object array get with read barriers enabled, we do not want the |
| 5529 | // move to overwrite the array's location, as we need it to emit |
| 5530 | // the read barrier. |
| 5531 | locations->SetOut( |
| 5532 | Location::RequiresRegister(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5533 | (instruction->GetType() == DataType::Type::kInt64 || object_array_get_with_read_barrier) |
| 5534 | ? Location::kOutputOverlap |
| 5535 | : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5536 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5537 | } |
| 5538 | |
| 5539 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5540 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5541 | Location obj_loc = locations->InAt(0); |
| 5542 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5543 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5544 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5545 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5546 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5547 | DataType::Type type = instruction->GetType(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5548 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5549 | case DataType::Type::kBool: |
| 5550 | case DataType::Type::kUint8: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5551 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5552 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5553 | break; |
| 5554 | } |
| 5555 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5556 | case DataType::Type::kInt8: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5557 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5558 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5559 | break; |
| 5560 | } |
| 5561 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5562 | case DataType::Type::kUint16: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5563 | Register out = out_loc.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5564 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5565 | // Branch cases into compressed and uncompressed for each index's type. |
| 5566 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5567 | NearLabel done, not_compressed; |
Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 5568 | __ testb(Address(obj, count_offset), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5569 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5570 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5571 | "Expecting 0=compressed, 1=uncompressed"); |
| 5572 | __ j(kNotZero, ¬_compressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5573 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5574 | __ jmp(&done); |
| 5575 | __ Bind(¬_compressed); |
| 5576 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5577 | __ Bind(&done); |
| 5578 | } else { |
| 5579 | // Common case for charAt of array of char or when string compression's |
| 5580 | // feature is turned off. |
| 5581 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5582 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5583 | break; |
| 5584 | } |
| 5585 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5586 | case DataType::Type::kInt16: { |
| 5587 | Register out = out_loc.AsRegister<Register>(); |
| 5588 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5589 | break; |
| 5590 | } |
| 5591 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5592 | case DataType::Type::kInt32: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5593 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5594 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5595 | break; |
| 5596 | } |
| 5597 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5598 | case DataType::Type::kReference: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5599 | static_assert( |
| 5600 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5601 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5602 | // /* HeapReference<Object> */ out = |
| 5603 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5604 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5605 | // Note that a potential implicit null check is handled in this |
| 5606 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5607 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5608 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5609 | } else { |
| 5610 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5611 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5612 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5613 | // If read barriers are enabled, emit read barriers other than |
| 5614 | // Baker's using a slow path (and also unpoison the loaded |
| 5615 | // reference, if heap poisoning is enabled). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5616 | if (index.IsConstant()) { |
| 5617 | uint32_t offset = |
| 5618 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5619 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5620 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5621 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5622 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5623 | } |
| 5624 | } |
| 5625 | break; |
| 5626 | } |
| 5627 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5628 | case DataType::Type::kInt64: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5629 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5630 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 5631 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 5632 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5633 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 5634 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5635 | break; |
| 5636 | } |
| 5637 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5638 | case DataType::Type::kFloat32: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5639 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5640 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5641 | break; |
| 5642 | } |
| 5643 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5644 | case DataType::Type::kFloat64: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5645 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5646 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5647 | break; |
| 5648 | } |
| 5649 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5650 | case DataType::Type::kUint32: |
| 5651 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5652 | case DataType::Type::kVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5653 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5654 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5655 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5656 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5657 | if (type == DataType::Type::kReference || type == DataType::Type::kInt64) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5658 | // Potential implicit null checks, in the case of reference or |
| 5659 | // long arrays, are handled in the previous switch statement. |
| 5660 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5661 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5662 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5663 | } |
| 5664 | |
| 5665 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5666 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5667 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5668 | bool needs_write_barrier = |
| 5669 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5670 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5671 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5672 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5673 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5674 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5675 | LocationSummary::kCallOnSlowPath : |
| 5676 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5677 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5678 | bool is_byte_type = DataType::Size(value_type) == 1u; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5679 | // We need the inputs to be different than the output in case of long operation. |
| 5680 | // In case of a byte operation, the register allocator does not support multiple |
| 5681 | // inputs that die at entry with one in a specific register. |
| 5682 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5683 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5684 | if (is_byte_type) { |
| 5685 | // Ensure the value is in a byte register. |
| 5686 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5687 | } else if (DataType::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5688 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5689 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5690 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5691 | } |
| 5692 | if (needs_write_barrier) { |
| 5693 | // Temporary registers for the write barrier. |
| 5694 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5695 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5696 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5697 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5698 | } |
| 5699 | |
| 5700 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5701 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5702 | Location array_loc = locations->InAt(0); |
| 5703 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5704 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5705 | Location value = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5706 | DataType::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5707 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5708 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5709 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5710 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5711 | bool needs_write_barrier = |
| 5712 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5713 | |
| 5714 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5715 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5716 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5717 | case DataType::Type::kInt8: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5718 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5719 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5720 | if (value.IsRegister()) { |
| 5721 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5722 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5723 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5724 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5725 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5726 | break; |
| 5727 | } |
| 5728 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5729 | case DataType::Type::kUint16: |
| 5730 | case DataType::Type::kInt16: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5731 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5732 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5733 | if (value.IsRegister()) { |
| 5734 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5735 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5736 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5737 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5738 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5739 | break; |
| 5740 | } |
| 5741 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5742 | case DataType::Type::kReference: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5743 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5744 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5745 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5746 | if (!value.IsRegister()) { |
| 5747 | // Just setting null. |
| 5748 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5749 | DCHECK(value.IsConstant()) << value; |
| 5750 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5751 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5752 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5753 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5754 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5755 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5756 | |
| 5757 | DCHECK(needs_write_barrier); |
| 5758 | Register register_value = value.AsRegister<Register>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5759 | // We cannot use a NearLabel for `done`, as its range may be too |
| 5760 | // short when Baker read barriers are enabled. |
| 5761 | Label done; |
| 5762 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5763 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5764 | Location temp_loc = locations->GetTemp(0); |
| 5765 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5766 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5767 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5768 | codegen_->AddSlowPath(slow_path); |
| 5769 | if (instruction->GetValueCanBeNull()) { |
| 5770 | __ testl(register_value, register_value); |
| 5771 | __ j(kNotEqual, ¬_null); |
| 5772 | __ movl(address, Immediate(0)); |
| 5773 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5774 | __ jmp(&done); |
| 5775 | __ Bind(¬_null); |
| 5776 | } |
| 5777 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5778 | // Note that when Baker read barriers are enabled, the type |
| 5779 | // checks are performed without read barriers. This is fine, |
| 5780 | // even in the case where a class object is in the from-space |
| 5781 | // after the flip, as a comparison involving such a type would |
| 5782 | // not produce a false positive; it may of course produce a |
| 5783 | // false negative, in which case we would take the ArraySet |
| 5784 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5785 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5786 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5787 | __ movl(temp, Address(array, class_offset)); |
| 5788 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5789 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5790 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5791 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5792 | __ movl(temp, Address(temp, component_offset)); |
| 5793 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5794 | // nor the object reference in `register_value->klass`, as |
| 5795 | // we are comparing two poisoned references. |
| 5796 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5797 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5798 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5799 | __ j(kEqual, &do_put); |
| 5800 | // If heap poisoning is enabled, the `temp` reference has |
| 5801 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5802 | __ MaybeUnpoisonHeapReference(temp); |
| 5803 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5804 | // If heap poisoning is enabled, no need to unpoison the |
| 5805 | // heap reference loaded below, as it is only used for a |
| 5806 | // comparison with null. |
| 5807 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5808 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5809 | __ Bind(&do_put); |
| 5810 | } else { |
| 5811 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5812 | } |
| 5813 | } |
| 5814 | |
| 5815 | if (kPoisonHeapReferences) { |
| 5816 | __ movl(temp, register_value); |
| 5817 | __ PoisonHeapReference(temp); |
| 5818 | __ movl(address, temp); |
| 5819 | } else { |
| 5820 | __ movl(address, register_value); |
| 5821 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5822 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5823 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5824 | } |
| 5825 | |
| 5826 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5827 | codegen_->MarkGCCard( |
| 5828 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5829 | __ Bind(&done); |
| 5830 | |
| 5831 | if (slow_path != nullptr) { |
| 5832 | __ Bind(slow_path->GetExitLabel()); |
| 5833 | } |
| 5834 | |
| 5835 | break; |
| 5836 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5837 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5838 | case DataType::Type::kInt32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5839 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5840 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5841 | if (value.IsRegister()) { |
| 5842 | __ movl(address, value.AsRegister<Register>()); |
| 5843 | } else { |
| 5844 | DCHECK(value.IsConstant()) << value; |
| 5845 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5846 | __ movl(address, Immediate(v)); |
| 5847 | } |
| 5848 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5849 | break; |
| 5850 | } |
| 5851 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5852 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5853 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5854 | if (value.IsRegisterPair()) { |
| 5855 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5856 | value.AsRegisterPairLow<Register>()); |
| 5857 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5858 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5859 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5860 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5861 | DCHECK(value.IsConstant()); |
| 5862 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 5863 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5864 | Immediate(Low32Bits(val))); |
| 5865 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5866 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5867 | Immediate(High32Bits(val))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5868 | } |
| 5869 | break; |
| 5870 | } |
| 5871 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5872 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5873 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5874 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5875 | if (value.IsFpuRegister()) { |
| 5876 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5877 | } else { |
| 5878 | DCHECK(value.IsConstant()); |
| 5879 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5880 | __ movl(address, Immediate(v)); |
| 5881 | } |
| 5882 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5883 | break; |
| 5884 | } |
| 5885 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5886 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5887 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5888 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5889 | if (value.IsFpuRegister()) { |
| 5890 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5891 | } else { |
| 5892 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5893 | Address address_hi = |
| 5894 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5895 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5896 | __ movl(address, Immediate(Low32Bits(v))); |
| 5897 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5898 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5899 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5900 | break; |
| 5901 | } |
| 5902 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5903 | case DataType::Type::kUint32: |
| 5904 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5905 | case DataType::Type::kVoid: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5906 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5907 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5908 | } |
| 5909 | } |
| 5910 | |
| 5911 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5912 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5913 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5914 | if (!instruction->IsEmittedAtUseSite()) { |
| 5915 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5916 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5917 | } |
| 5918 | |
| 5919 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5920 | if (instruction->IsEmittedAtUseSite()) { |
| 5921 | return; |
| 5922 | } |
| 5923 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5924 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5925 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5926 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5927 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5928 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5929 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5930 | // Mask out most significant bit in case the array is String's array of char. |
| 5931 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5932 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5933 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5934 | } |
| 5935 | |
| 5936 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5937 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5938 | InvokeRuntimeCallingConvention calling_convention; |
| 5939 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5940 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5941 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5942 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5943 | HInstruction* length = instruction->InputAt(1); |
| 5944 | if (!length->IsEmittedAtUseSite()) { |
| 5945 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5946 | } |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5947 | // Need register to see array's length. |
| 5948 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5949 | locations->AddTemp(Location::RequiresRegister()); |
| 5950 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5951 | } |
| 5952 | |
| 5953 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5954 | const bool is_string_compressed_char_at = |
| 5955 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5956 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5957 | Location index_loc = locations->InAt(0); |
| 5958 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5959 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5960 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5961 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5962 | if (length_loc.IsConstant()) { |
| 5963 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5964 | if (index_loc.IsConstant()) { |
| 5965 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5966 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5967 | if (index < 0 || index >= length) { |
| 5968 | codegen_->AddSlowPath(slow_path); |
| 5969 | __ jmp(slow_path->GetEntryLabel()); |
| 5970 | } else { |
| 5971 | // Some optimization after BCE may have generated this, and we should not |
| 5972 | // generate a bounds check if it is a valid range. |
| 5973 | } |
| 5974 | return; |
| 5975 | } |
| 5976 | |
| 5977 | // We have to reverse the jump condition because the length is the constant. |
| 5978 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5979 | __ cmpl(index_reg, Immediate(length)); |
| 5980 | codegen_->AddSlowPath(slow_path); |
| 5981 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5982 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5983 | HInstruction* array_length = instruction->InputAt(1); |
| 5984 | if (array_length->IsEmittedAtUseSite()) { |
| 5985 | // Address the length field in the array. |
| 5986 | DCHECK(array_length->IsArrayLength()); |
| 5987 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5988 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5989 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5990 | if (is_string_compressed_char_at) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5991 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5992 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5993 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 5994 | __ movl(length_reg, array_len); |
| 5995 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5996 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5997 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5998 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5999 | // Checking bounds for general case: |
| 6000 | // Array of char or string's array with feature compression off. |
| 6001 | if (index_loc.IsConstant()) { |
| 6002 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 6003 | __ cmpl(array_len, Immediate(value)); |
| 6004 | } else { |
| 6005 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 6006 | } |
| 6007 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6008 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6009 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6010 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6011 | } |
| 6012 | codegen_->AddSlowPath(slow_path); |
| 6013 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6014 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6015 | } |
| 6016 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6017 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6018 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6019 | } |
| 6020 | |
| 6021 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6022 | if (instruction->GetNext()->IsSuspendCheck() && |
| 6023 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 6024 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 6025 | // The back edge will generate the suspend check. |
| 6026 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 6027 | } |
| 6028 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6029 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6030 | } |
| 6031 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6032 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6033 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6034 | instruction, LocationSummary::kCallOnSlowPath); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 6035 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 6036 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 6037 | // registers in full width (since the runtime only saves/restores lower part). |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6038 | locations->SetCustomSlowPathCallerSaves( |
| 6039 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6040 | } |
| 6041 | |
| 6042 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6043 | HBasicBlock* block = instruction->GetBlock(); |
| 6044 | if (block->GetLoopInformation() != nullptr) { |
| 6045 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6046 | // The back edge will generate the suspend check. |
| 6047 | return; |
| 6048 | } |
| 6049 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6050 | // The goto will generate the suspend check. |
| 6051 | return; |
| 6052 | } |
| 6053 | GenerateSuspendCheck(instruction, nullptr); |
| 6054 | } |
| 6055 | |
| 6056 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6057 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6058 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6059 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 6060 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6061 | slow_path = |
| 6062 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6063 | instruction->SetSlowPath(slow_path); |
| 6064 | codegen_->AddSlowPath(slow_path); |
| 6065 | if (successor != nullptr) { |
| 6066 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6067 | } |
| 6068 | } else { |
| 6069 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6070 | } |
| 6071 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6072 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6073 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6074 | if (successor == nullptr) { |
| 6075 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6076 | __ Bind(slow_path->GetReturnLabel()); |
| 6077 | } else { |
| 6078 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 6079 | __ jmp(slow_path->GetEntryLabel()); |
| 6080 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6081 | } |
| 6082 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6083 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 6084 | return codegen_->GetAssembler(); |
| 6085 | } |
| 6086 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6087 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src, int number_of_words) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6088 | ScratchRegisterScope ensure_scratch( |
| 6089 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6090 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6091 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6092 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6093 | // Now that temp register is available (possibly spilled), move blocks of memory. |
| 6094 | for (int i = 0; i < number_of_words; i++) { |
| 6095 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 6096 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 6097 | stack_offset += kX86WordSize; |
| 6098 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6099 | } |
| 6100 | |
| 6101 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6102 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6103 | Location source = move->GetSource(); |
| 6104 | Location destination = move->GetDestination(); |
| 6105 | |
| 6106 | if (source.IsRegister()) { |
| 6107 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6108 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6109 | } else if (destination.IsFpuRegister()) { |
| 6110 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6111 | } else { |
| 6112 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6113 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6114 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6115 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6116 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6117 | // Create stack space for 2 elements. |
| 6118 | __ subl(ESP, Immediate(2 * elem_size)); |
| 6119 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 6120 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 6121 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 6122 | // And remove the temporary stack space we allocated. |
| 6123 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6124 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6125 | if (destination.IsRegister()) { |
| 6126 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 6127 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6128 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6129 | } else if (destination.IsRegisterPair()) { |
| 6130 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 6131 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 6132 | __ psrlq(src_reg, Immediate(32)); |
| 6133 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6134 | } else if (destination.IsStackSlot()) { |
| 6135 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6136 | } else if (destination.IsDoubleStackSlot()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6137 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6138 | } else { |
| 6139 | DCHECK(destination.IsSIMDStackSlot()); |
| 6140 | __ movups(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6141 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6142 | } else if (source.IsStackSlot()) { |
| 6143 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6144 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6145 | } else if (destination.IsFpuRegister()) { |
| 6146 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6147 | } else { |
| 6148 | DCHECK(destination.IsStackSlot()); |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6149 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6150 | } |
| 6151 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6152 | if (destination.IsRegisterPair()) { |
| 6153 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 6154 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 6155 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 6156 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6157 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 6158 | } else { |
| 6159 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6160 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6161 | } |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6162 | } else if (source.IsSIMDStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6163 | if (destination.IsFpuRegister()) { |
| 6164 | __ movups(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 6165 | } else { |
| 6166 | DCHECK(destination.IsSIMDStackSlot()); |
| 6167 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 6168 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6169 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6170 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 6171 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6172 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6173 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6174 | if (value == 0) { |
| 6175 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6176 | } else { |
| 6177 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 6178 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6179 | } else { |
| 6180 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6181 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6182 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6183 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6184 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6185 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6186 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6187 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6188 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 6189 | if (value == 0) { |
| 6190 | // Easy handling of 0.0. |
| 6191 | __ xorps(dest, dest); |
| 6192 | } else { |
| 6193 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6194 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6195 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6196 | __ movl(temp, Immediate(value)); |
| 6197 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6198 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6199 | } else { |
| 6200 | DCHECK(destination.IsStackSlot()) << destination; |
| 6201 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 6202 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6203 | } else if (constant->IsLongConstant()) { |
| 6204 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 6205 | int32_t low_value = Low32Bits(value); |
| 6206 | int32_t high_value = High32Bits(value); |
| 6207 | Immediate low(low_value); |
| 6208 | Immediate high(high_value); |
| 6209 | if (destination.IsDoubleStackSlot()) { |
| 6210 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6211 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6212 | } else { |
| 6213 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 6214 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 6215 | } |
| 6216 | } else { |
| 6217 | DCHECK(constant->IsDoubleConstant()); |
| 6218 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6219 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6220 | int32_t low_value = Low32Bits(value); |
| 6221 | int32_t high_value = High32Bits(value); |
| 6222 | Immediate low(low_value); |
| 6223 | Immediate high(high_value); |
| 6224 | if (destination.IsFpuRegister()) { |
| 6225 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 6226 | if (value == 0) { |
| 6227 | // Easy handling of 0.0. |
| 6228 | __ xorpd(dest, dest); |
| 6229 | } else { |
| 6230 | __ pushl(high); |
| 6231 | __ pushl(low); |
| 6232 | __ movsd(dest, Address(ESP, 0)); |
| 6233 | __ addl(ESP, Immediate(8)); |
| 6234 | } |
| 6235 | } else { |
| 6236 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6237 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6238 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6239 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6240 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6241 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6242 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6243 | } |
| 6244 | } |
| 6245 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 6246 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6247 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 6248 | ScratchRegisterScope ensure_scratch( |
| 6249 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 6250 | |
| 6251 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6252 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 6253 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 6254 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6255 | } |
| 6256 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6257 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6258 | ScratchRegisterScope ensure_scratch( |
| 6259 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6260 | |
| 6261 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6262 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6263 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 6264 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 6265 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6266 | } |
| 6267 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6268 | void ParallelMoveResolverX86::Exchange128(XmmRegister reg, int mem) { |
| 6269 | size_t extra_slot = 4 * kX86WordSize; |
| 6270 | __ subl(ESP, Immediate(extra_slot)); |
| 6271 | __ movups(Address(ESP, 0), XmmRegister(reg)); |
| 6272 | ExchangeMemory(0, mem + extra_slot, 4); |
| 6273 | __ movups(XmmRegister(reg), Address(ESP, 0)); |
| 6274 | __ addl(ESP, Immediate(extra_slot)); |
| 6275 | } |
| 6276 | |
| 6277 | void ParallelMoveResolverX86::ExchangeMemory(int mem1, int mem2, int number_of_words) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6278 | ScratchRegisterScope ensure_scratch1( |
| 6279 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6280 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6281 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 6282 | ScratchRegisterScope ensure_scratch2( |
| 6283 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6284 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6285 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 6286 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6287 | |
| 6288 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 6289 | for (int i = 0; i < number_of_words; i++) { |
| 6290 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 6291 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 6292 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 6293 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 6294 | stack_offset += kX86WordSize; |
| 6295 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6296 | } |
| 6297 | |
| 6298 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6299 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6300 | Location source = move->GetSource(); |
| 6301 | Location destination = move->GetDestination(); |
| 6302 | |
| 6303 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 6304 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 6305 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 6306 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 6307 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6308 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6309 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6310 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6311 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6312 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6313 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6314 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6315 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 6316 | // Use XOR Swap algorithm to avoid a temporary. |
| 6317 | DCHECK_NE(source.reg(), destination.reg()); |
| 6318 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 6319 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 6320 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 6321 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 6322 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6323 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 6324 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6325 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 6326 | // Take advantage of the 16 bytes in the XMM register. |
| 6327 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 6328 | Address stack(ESP, destination.GetStackIndex()); |
| 6329 | // Load the double into the high doubleword. |
| 6330 | __ movhpd(reg, stack); |
| 6331 | |
| 6332 | // Store the low double into the destination. |
| 6333 | __ movsd(stack, reg); |
| 6334 | |
| 6335 | // Move the high double to the low double. |
| 6336 | __ psrldq(reg, Immediate(8)); |
| 6337 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 6338 | // Take advantage of the 16 bytes in the XMM register. |
| 6339 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 6340 | Address stack(ESP, source.GetStackIndex()); |
| 6341 | // Load the double into the high doubleword. |
| 6342 | __ movhpd(reg, stack); |
| 6343 | |
| 6344 | // Store the low double into the destination. |
| 6345 | __ movsd(stack, reg); |
| 6346 | |
| 6347 | // Move the high double to the low double. |
| 6348 | __ psrldq(reg, Immediate(8)); |
| 6349 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6350 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 6351 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 6352 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 6353 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 6354 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6355 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 6356 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6357 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6358 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6359 | } |
| 6360 | } |
| 6361 | |
| 6362 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 6363 | __ pushl(static_cast<Register>(reg)); |
| 6364 | } |
| 6365 | |
| 6366 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 6367 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6368 | } |
| 6369 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6370 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 6371 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6372 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6373 | case HLoadClass::LoadKind::kInvalid: |
| 6374 | LOG(FATAL) << "UNREACHABLE"; |
| 6375 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6376 | case HLoadClass::LoadKind::kReferrersClass: |
| 6377 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6378 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6379 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6380 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6381 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6382 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6383 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6384 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6385 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6386 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6387 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6388 | break; |
| 6389 | } |
| 6390 | return desired_class_load_kind; |
| 6391 | } |
| 6392 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6393 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6394 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6395 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6396 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6397 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6398 | cls, |
| 6399 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6400 | Location::RegisterLocation(EAX)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6401 | DCHECK_EQ(calling_convention.GetRegisterAt(0), EAX); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6402 | return; |
| 6403 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6404 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6405 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6406 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6407 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6408 | ? LocationSummary::kCallOnSlowPath |
| 6409 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6410 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6411 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6412 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6413 | } |
| 6414 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6415 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6416 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6417 | load_kind == HLoadClass::LoadKind::kBootImageRelRo || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6418 | load_kind == HLoadClass::LoadKind::kBssEntry) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6419 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6420 | } |
| 6421 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6422 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6423 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6424 | // Rely on the type resolution and/or initialization to save everything. |
| 6425 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6426 | InvokeRuntimeCallingConvention calling_convention; |
| 6427 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6428 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6429 | } else { |
| 6430 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6431 | } |
| 6432 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6433 | } |
| 6434 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6435 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6436 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6437 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6438 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6439 | // Add a patch entry and return the label. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6440 | jit_class_patches_.emplace_back(&dex_file, type_index.index_); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6441 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 6442 | return &info->label; |
| 6443 | } |
| 6444 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6445 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6446 | // move. |
| 6447 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6448 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6449 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6450 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6451 | return; |
| 6452 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6453 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6454 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6455 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6456 | Location out_loc = locations->Out(); |
| 6457 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6458 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6459 | bool generate_null_check = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6460 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6461 | ? kWithoutReadBarrier |
| 6462 | : kCompilerReadBarrierOption; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6463 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6464 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6465 | DCHECK(!cls->CanCallRuntime()); |
| 6466 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6467 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6468 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6469 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6470 | cls, |
| 6471 | out_loc, |
| 6472 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6473 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6474 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6475 | break; |
| 6476 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6477 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6478 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6479 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6480 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6481 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6482 | codegen_->RecordBootImageTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6483 | break; |
| 6484 | } |
| 6485 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6486 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6487 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6488 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6489 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6490 | __ movl(out, Immediate(address)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6491 | break; |
| 6492 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6493 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6494 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6495 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6496 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6497 | codegen_->RecordBootImageRelRoPatch(cls->InputAt(0)->AsX86ComputeBaseMethodAddress(), |
| 6498 | codegen_->GetBootImageOffset(cls)); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6499 | break; |
| 6500 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6501 | case HLoadClass::LoadKind::kBssEntry: { |
| 6502 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6503 | Address address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6504 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 6505 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| 6506 | generate_null_check = true; |
| 6507 | break; |
| 6508 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6509 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6510 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6511 | Label* fixup_label = codegen_->NewJitRootClassPatch( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6512 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6513 | // /* GcRoot<mirror::Class> */ out = *address |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6514 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6515 | break; |
| 6516 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6517 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6518 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6519 | LOG(FATAL) << "UNREACHABLE"; |
| 6520 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6521 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6522 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6523 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6524 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6525 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6526 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6527 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6528 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6529 | if (generate_null_check) { |
| 6530 | __ testl(out, out); |
| 6531 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6532 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6533 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6534 | if (cls->MustGenerateClinitCheck()) { |
| 6535 | GenerateClassInitializationCheck(slow_path, out); |
| 6536 | } else { |
| 6537 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6538 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6539 | } |
| 6540 | } |
| 6541 | |
| 6542 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6543 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6544 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6545 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6546 | if (check->HasUses()) { |
| 6547 | locations->SetOut(Location::SameAsFirstInput()); |
| 6548 | } |
| 6549 | } |
| 6550 | |
| 6551 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6552 | // We assume the class to not be null. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6553 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6554 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6555 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6556 | GenerateClassInitializationCheck(slow_path, |
| 6557 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6558 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6559 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6560 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6561 | SlowPathCode* slow_path, Register class_reg) { |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 6562 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 6563 | const size_t status_byte_offset = |
| 6564 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 6565 | constexpr uint32_t shifted_initialized_value = |
| 6566 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
| 6567 | |
| 6568 | __ cmpb(Address(class_reg, status_byte_offset), Immediate(shifted_initialized_value)); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 6569 | __ j(kBelow, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6570 | __ Bind(slow_path->GetExitLabel()); |
| 6571 | // No need for memory fence, thanks to the X86 memory model. |
| 6572 | } |
| 6573 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6574 | void InstructionCodeGeneratorX86::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 6575 | Register temp) { |
| 6576 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 6577 | uint32_t mask = check->GetBitstringMask(); |
| 6578 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 6579 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 6580 | |
| 6581 | if (mask_bits == 16u) { |
| 6582 | // Compare the bitstring in memory. |
| 6583 | __ cmpw(Address(temp, mirror::Class::StatusOffset()), Immediate(path_to_root)); |
| 6584 | } else { |
| 6585 | // /* uint32_t */ temp = temp->status_ |
| 6586 | __ movl(temp, Address(temp, mirror::Class::StatusOffset())); |
| 6587 | // Compare the bitstring bits using SUB. |
| 6588 | __ subl(temp, Immediate(path_to_root)); |
| 6589 | // Shift out bits that do not contribute to the comparison. |
| 6590 | __ shll(temp, Immediate(32u - mask_bits)); |
| 6591 | } |
| 6592 | } |
| 6593 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6594 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6595 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6596 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6597 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6598 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6599 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6600 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6601 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6602 | case HLoadString::LoadKind::kJitTableAddress: |
| 6603 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6604 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6605 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6606 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6607 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6608 | } |
| 6609 | return desired_string_load_kind; |
| 6610 | } |
| 6611 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6612 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6613 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6614 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6615 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6616 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6617 | load_kind == HLoadString::LoadKind::kBootImageRelRo || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6618 | load_kind == HLoadString::LoadKind::kBssEntry) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6619 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6620 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6621 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6622 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 6623 | } else { |
| 6624 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6625 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6626 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6627 | // Rely on the pResolveString to save everything. |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6628 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6629 | InvokeRuntimeCallingConvention calling_convention; |
| 6630 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6631 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6632 | } else { |
| 6633 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6634 | } |
| 6635 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6636 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6637 | } |
| 6638 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6639 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6640 | dex::StringIndex string_index, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6641 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6642 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6643 | // Add a patch entry and return the label. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6644 | jit_string_patches_.emplace_back(&dex_file, string_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6645 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6646 | return &info->label; |
| 6647 | } |
| 6648 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6649 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6650 | // move. |
| 6651 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6652 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6653 | Location out_loc = locations->Out(); |
| 6654 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6655 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6656 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6657 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6658 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6659 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6660 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6661 | codegen_->RecordBootImageStringPatch(load); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6662 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6663 | } |
| 6664 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6665 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6666 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6667 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6668 | __ movl(out, Immediate(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6669 | return; |
| 6670 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6671 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6672 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6673 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6674 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6675 | codegen_->RecordBootImageRelRoPatch(load->InputAt(0)->AsX86ComputeBaseMethodAddress(), |
| 6676 | codegen_->GetBootImageOffset(load)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6677 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6678 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6679 | case HLoadString::LoadKind::kBssEntry: { |
| 6680 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6681 | Address address = Address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6682 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6683 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6684 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6685 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6686 | codegen_->AddSlowPath(slow_path); |
| 6687 | __ testl(out, out); |
| 6688 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6689 | __ Bind(slow_path->GetExitLabel()); |
| 6690 | return; |
| 6691 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6692 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6693 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6694 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6695 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6696 | // /* GcRoot<mirror::String> */ out = *address |
| 6697 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6698 | return; |
| 6699 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6700 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6701 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6702 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6703 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6704 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6705 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6706 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6707 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6708 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6709 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6710 | } |
| 6711 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6712 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6713 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6714 | } |
| 6715 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6716 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6717 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6718 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6719 | locations->SetOut(Location::RequiresRegister()); |
| 6720 | } |
| 6721 | |
| 6722 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6723 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6724 | } |
| 6725 | |
| 6726 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6727 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6728 | } |
| 6729 | |
| 6730 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6731 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6732 | } |
| 6733 | |
| 6734 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6735 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6736 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6737 | InvokeRuntimeCallingConvention calling_convention; |
| 6738 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6739 | } |
| 6740 | |
| 6741 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6742 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6743 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6744 | } |
| 6745 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6746 | // Temp is used for read barrier. |
| 6747 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6748 | if (kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6749 | !kUseBakerReadBarrier && |
| 6750 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6751 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6752 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6753 | return 1; |
| 6754 | } |
| 6755 | return 0; |
| 6756 | } |
| 6757 | |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6758 | // Interface case has 2 temps, one for holding the number of interfaces, one for the current |
| 6759 | // interface pointer, the current interface is compared in memory. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6760 | // The other checks have one temp for loading the object's class. |
| 6761 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6762 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6763 | return 2; |
| 6764 | } |
| 6765 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6766 | } |
| 6767 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6768 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6769 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6770 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6771 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6772 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6773 | case TypeCheckKind::kExactCheck: |
| 6774 | case TypeCheckKind::kAbstractClassCheck: |
| 6775 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6776 | case TypeCheckKind::kArrayObjectCheck: { |
| 6777 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 6778 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 6779 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6780 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6781 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6782 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6783 | case TypeCheckKind::kUnresolvedCheck: |
| 6784 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6785 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6786 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6787 | case TypeCheckKind::kBitstringCheck: |
| 6788 | break; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6789 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6790 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6791 | LocationSummary* locations = |
| 6792 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6793 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6794 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6795 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6796 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6797 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 6798 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 6799 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 6800 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 6801 | } else { |
| 6802 | locations->SetInAt(1, Location::Any()); |
| 6803 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6804 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6805 | locations->SetOut(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6806 | // When read barriers are enabled, we need a temporary register for some cases. |
| 6807 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6808 | } |
| 6809 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6810 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6811 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6812 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6813 | Location obj_loc = locations->InAt(0); |
| 6814 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6815 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6816 | Location out_loc = locations->Out(); |
| 6817 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6818 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6819 | DCHECK_LE(num_temps, 1u); |
| 6820 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6821 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6822 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6823 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6824 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6825 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6826 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6827 | |
| 6828 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6829 | // Avoid null check if we know obj is not null. |
| 6830 | if (instruction->MustDoNullCheck()) { |
| 6831 | __ testl(obj, obj); |
| 6832 | __ j(kEqual, &zero); |
| 6833 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6834 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6835 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6836 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6837 | ReadBarrierOption read_barrier_option = |
| 6838 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6839 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6840 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6841 | out_loc, |
| 6842 | obj_loc, |
| 6843 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6844 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6845 | if (cls.IsRegister()) { |
| 6846 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6847 | } else { |
| 6848 | DCHECK(cls.IsStackSlot()) << cls; |
| 6849 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6850 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6851 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6852 | // Classes must be equal for the instanceof to succeed. |
| 6853 | __ j(kNotEqual, &zero); |
| 6854 | __ movl(out, Immediate(1)); |
| 6855 | __ jmp(&done); |
| 6856 | break; |
| 6857 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6858 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6859 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6860 | ReadBarrierOption read_barrier_option = |
| 6861 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6862 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6863 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6864 | out_loc, |
| 6865 | obj_loc, |
| 6866 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6867 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6868 | // If the class is abstract, we eagerly fetch the super class of the |
| 6869 | // object to avoid doing a comparison we know will fail. |
| 6870 | NearLabel loop; |
| 6871 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6872 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6873 | GenerateReferenceLoadOneRegister(instruction, |
| 6874 | out_loc, |
| 6875 | super_offset, |
| 6876 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6877 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6878 | __ testl(out, out); |
| 6879 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6880 | __ j(kEqual, &done); |
| 6881 | if (cls.IsRegister()) { |
| 6882 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6883 | } else { |
| 6884 | DCHECK(cls.IsStackSlot()) << cls; |
| 6885 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6886 | } |
| 6887 | __ j(kNotEqual, &loop); |
| 6888 | __ movl(out, Immediate(1)); |
| 6889 | if (zero.IsLinked()) { |
| 6890 | __ jmp(&done); |
| 6891 | } |
| 6892 | break; |
| 6893 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6894 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6895 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6896 | ReadBarrierOption read_barrier_option = |
| 6897 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6898 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6899 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6900 | out_loc, |
| 6901 | obj_loc, |
| 6902 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6903 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6904 | // Walk over the class hierarchy to find a match. |
| 6905 | NearLabel loop, success; |
| 6906 | __ Bind(&loop); |
| 6907 | if (cls.IsRegister()) { |
| 6908 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6909 | } else { |
| 6910 | DCHECK(cls.IsStackSlot()) << cls; |
| 6911 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6912 | } |
| 6913 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6914 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6915 | GenerateReferenceLoadOneRegister(instruction, |
| 6916 | out_loc, |
| 6917 | super_offset, |
| 6918 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6919 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6920 | __ testl(out, out); |
| 6921 | __ j(kNotEqual, &loop); |
| 6922 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6923 | __ jmp(&done); |
| 6924 | __ Bind(&success); |
| 6925 | __ movl(out, Immediate(1)); |
| 6926 | if (zero.IsLinked()) { |
| 6927 | __ jmp(&done); |
| 6928 | } |
| 6929 | break; |
| 6930 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6931 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6932 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6933 | ReadBarrierOption read_barrier_option = |
| 6934 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6935 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6936 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6937 | out_loc, |
| 6938 | obj_loc, |
| 6939 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6940 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6941 | // Do an exact check. |
| 6942 | NearLabel exact_check; |
| 6943 | if (cls.IsRegister()) { |
| 6944 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6945 | } else { |
| 6946 | DCHECK(cls.IsStackSlot()) << cls; |
| 6947 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6948 | } |
| 6949 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6950 | // 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] | 6951 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6952 | GenerateReferenceLoadOneRegister(instruction, |
| 6953 | out_loc, |
| 6954 | component_offset, |
| 6955 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6956 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6957 | __ testl(out, out); |
| 6958 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6959 | __ j(kEqual, &done); |
| 6960 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6961 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6962 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6963 | __ movl(out, Immediate(1)); |
| 6964 | __ jmp(&done); |
| 6965 | break; |
| 6966 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6967 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6968 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6969 | // No read barrier since the slow path will retry upon failure. |
| 6970 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6971 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6972 | out_loc, |
| 6973 | obj_loc, |
| 6974 | class_offset, |
| 6975 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6976 | if (cls.IsRegister()) { |
| 6977 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6978 | } else { |
| 6979 | DCHECK(cls.IsStackSlot()) << cls; |
| 6980 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6981 | } |
| 6982 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6983 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 6984 | instruction, /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6985 | codegen_->AddSlowPath(slow_path); |
| 6986 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6987 | __ movl(out, Immediate(1)); |
| 6988 | if (zero.IsLinked()) { |
| 6989 | __ jmp(&done); |
| 6990 | } |
| 6991 | break; |
| 6992 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6993 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6994 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6995 | case TypeCheckKind::kInterfaceCheck: { |
| 6996 | // 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] | 6997 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6998 | // cases. |
| 6999 | // |
| 7000 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7001 | // entry point without resorting to a type checking slow path |
| 7002 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7003 | // require to assign fixed registers for the inputs of this |
| 7004 | // HInstanceOf instruction (following the runtime calling |
| 7005 | // convention), which might be cluttered by the potential first |
| 7006 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7007 | // |
| 7008 | // TODO: Introduce a new runtime entry point taking the object |
| 7009 | // to test (instead of its class) as argument, and let it deal |
| 7010 | // with the read barrier issues. This will let us refactor this |
| 7011 | // case of the `switch` code as it was previously (with a direct |
| 7012 | // call to the runtime not using a type checking slow path). |
| 7013 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7014 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7015 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 7016 | instruction, /* is_fatal */ false); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7017 | codegen_->AddSlowPath(slow_path); |
| 7018 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7019 | if (zero.IsLinked()) { |
| 7020 | __ jmp(&done); |
| 7021 | } |
| 7022 | break; |
| 7023 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7024 | |
| 7025 | case TypeCheckKind::kBitstringCheck: { |
| 7026 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7027 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7028 | out_loc, |
| 7029 | obj_loc, |
| 7030 | class_offset, |
| 7031 | kWithoutReadBarrier); |
| 7032 | |
| 7033 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 7034 | __ j(kNotEqual, &zero); |
| 7035 | __ movl(out, Immediate(1)); |
| 7036 | __ jmp(&done); |
| 7037 | break; |
| 7038 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7039 | } |
| 7040 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7041 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7042 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7043 | __ xorl(out, out); |
| 7044 | } |
| 7045 | |
| 7046 | if (done.IsLinked()) { |
| 7047 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7048 | } |
| 7049 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7050 | if (slow_path != nullptr) { |
| 7051 | __ Bind(slow_path->GetExitLabel()); |
| 7052 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7053 | } |
| 7054 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7055 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7056 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7057 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7058 | LocationSummary* locations = |
| 7059 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7060 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7061 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7062 | // Require a register for the interface check since there is a loop that compares the class to |
| 7063 | // a memory address. |
| 7064 | locations->SetInAt(1, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7065 | } else if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7066 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7067 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7068 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7069 | } else { |
| 7070 | locations->SetInAt(1, Location::Any()); |
| 7071 | } |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 7072 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathX86. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7073 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 7074 | } |
| 7075 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7076 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7077 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7078 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7079 | Location obj_loc = locations->InAt(0); |
| 7080 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7081 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7082 | Location temp_loc = locations->GetTemp(0); |
| 7083 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7084 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7085 | DCHECK_GE(num_temps, 1u); |
| 7086 | DCHECK_LE(num_temps, 2u); |
| 7087 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7088 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7089 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7090 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7091 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7092 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7093 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7094 | const uint32_t object_array_data_offset = |
| 7095 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7096 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7097 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7098 | SlowPathCode* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7099 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 7100 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7101 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7102 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7103 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7104 | // Avoid null check if we know obj is not null. |
| 7105 | if (instruction->MustDoNullCheck()) { |
| 7106 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7107 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7108 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7109 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7110 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7111 | case TypeCheckKind::kExactCheck: |
| 7112 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7113 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7114 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7115 | temp_loc, |
| 7116 | obj_loc, |
| 7117 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7118 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7119 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7120 | if (cls.IsRegister()) { |
| 7121 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7122 | } else { |
| 7123 | DCHECK(cls.IsStackSlot()) << cls; |
| 7124 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7125 | } |
| 7126 | // Jump to slow path for throwing the exception or doing a |
| 7127 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7128 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7129 | break; |
| 7130 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7131 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7132 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7133 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7134 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7135 | temp_loc, |
| 7136 | obj_loc, |
| 7137 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7138 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7139 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7140 | // If the class is abstract, we eagerly fetch the super class of the |
| 7141 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7142 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7143 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7144 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7145 | GenerateReferenceLoadOneRegister(instruction, |
| 7146 | temp_loc, |
| 7147 | super_offset, |
| 7148 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7149 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7150 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7151 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7152 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7153 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7154 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7155 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7156 | // Otherwise, compare the classes |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7157 | if (cls.IsRegister()) { |
| 7158 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7159 | } else { |
| 7160 | DCHECK(cls.IsStackSlot()) << cls; |
| 7161 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7162 | } |
| 7163 | __ j(kNotEqual, &loop); |
| 7164 | break; |
| 7165 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7166 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7167 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7168 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7169 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7170 | temp_loc, |
| 7171 | obj_loc, |
| 7172 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7173 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7174 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7175 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7176 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7177 | __ Bind(&loop); |
| 7178 | if (cls.IsRegister()) { |
| 7179 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7180 | } else { |
| 7181 | DCHECK(cls.IsStackSlot()) << cls; |
| 7182 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7183 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7184 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7185 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7186 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7187 | GenerateReferenceLoadOneRegister(instruction, |
| 7188 | temp_loc, |
| 7189 | super_offset, |
| 7190 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7191 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7192 | |
| 7193 | // If the class reference currently in `temp` is not null, jump |
| 7194 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7195 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7196 | __ j(kNotZero, &loop); |
| 7197 | // Otherwise, jump to the slow path to throw the exception.; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7198 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7199 | break; |
| 7200 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7201 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7202 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7203 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7204 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7205 | temp_loc, |
| 7206 | obj_loc, |
| 7207 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7208 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7209 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7210 | // Do an exact check. |
| 7211 | if (cls.IsRegister()) { |
| 7212 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7213 | } else { |
| 7214 | DCHECK(cls.IsStackSlot()) << cls; |
| 7215 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7216 | } |
| 7217 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7218 | |
| 7219 | // 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] | 7220 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7221 | GenerateReferenceLoadOneRegister(instruction, |
| 7222 | temp_loc, |
| 7223 | component_offset, |
| 7224 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7225 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7226 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7227 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 7228 | // throw the exception. Otherwise proceed with the check. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7229 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7230 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7231 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7232 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7233 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7234 | break; |
| 7235 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7236 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7237 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7238 | // We always go into the type check slow path for the unresolved check case. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7239 | // We cannot directly call the CheckCast runtime entry point |
| 7240 | // without resorting to a type checking slow path here (i.e. by |
| 7241 | // calling InvokeRuntime directly), as it would require to |
| 7242 | // assign fixed registers for the inputs of this HInstanceOf |
| 7243 | // instruction (following the runtime calling convention), which |
| 7244 | // might be cluttered by the potential first read barrier |
| 7245 | // emission at the beginning of this method. |
| 7246 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7247 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7248 | |
| 7249 | case TypeCheckKind::kInterfaceCheck: { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7250 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. |
| 7251 | // We can not get false positives by doing this. |
| 7252 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7253 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7254 | temp_loc, |
| 7255 | obj_loc, |
| 7256 | class_offset, |
| 7257 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7258 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7259 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7260 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7261 | temp_loc, |
| 7262 | temp_loc, |
| 7263 | iftable_offset, |
| 7264 | kWithoutReadBarrier); |
| 7265 | // Iftable is never null. |
| 7266 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
| 7267 | // Maybe poison the `cls` for direct comparison with memory. |
| 7268 | __ MaybePoisonHeapReference(cls.AsRegister<Register>()); |
| 7269 | // Loop through the iftable and check if any class matches. |
| 7270 | NearLabel start_loop; |
| 7271 | __ Bind(&start_loop); |
| 7272 | // Need to subtract first to handle the empty array case. |
| 7273 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
| 7274 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 7275 | // Go to next interface if the classes do not match. |
| 7276 | __ cmpl(cls.AsRegister<Register>(), |
| 7277 | CodeGeneratorX86::ArrayAddress(temp, |
| 7278 | maybe_temp2_loc, |
| 7279 | TIMES_4, |
| 7280 | object_array_data_offset)); |
| 7281 | __ j(kNotEqual, &start_loop); |
| 7282 | // If `cls` was poisoned above, unpoison it. |
| 7283 | __ MaybeUnpoisonHeapReference(cls.AsRegister<Register>()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7284 | break; |
| 7285 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7286 | |
| 7287 | case TypeCheckKind::kBitstringCheck: { |
| 7288 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7289 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7290 | temp_loc, |
| 7291 | obj_loc, |
| 7292 | class_offset, |
| 7293 | kWithoutReadBarrier); |
| 7294 | |
| 7295 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 7296 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| 7297 | break; |
| 7298 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7299 | } |
| 7300 | __ Bind(&done); |
| 7301 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7302 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7303 | } |
| 7304 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7305 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7306 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7307 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7308 | InvokeRuntimeCallingConvention calling_convention; |
| 7309 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7310 | } |
| 7311 | |
| 7312 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7313 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 7314 | : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 7315 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7316 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7317 | if (instruction->IsEnter()) { |
| 7318 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7319 | } else { |
| 7320 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7321 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7322 | } |
| 7323 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7324 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 7325 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 7326 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 7327 | |
| 7328 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7329 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7330 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7331 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 7332 | || instruction->GetResultType() == DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7333 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7334 | locations->SetInAt(1, Location::Any()); |
| 7335 | locations->SetOut(Location::SameAsFirstInput()); |
| 7336 | } |
| 7337 | |
| 7338 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 7339 | HandleBitwiseOperation(instruction); |
| 7340 | } |
| 7341 | |
| 7342 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 7343 | HandleBitwiseOperation(instruction); |
| 7344 | } |
| 7345 | |
| 7346 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 7347 | HandleBitwiseOperation(instruction); |
| 7348 | } |
| 7349 | |
| 7350 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7351 | LocationSummary* locations = instruction->GetLocations(); |
| 7352 | Location first = locations->InAt(0); |
| 7353 | Location second = locations->InAt(1); |
| 7354 | DCHECK(first.Equals(locations->Out())); |
| 7355 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7356 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7357 | if (second.IsRegister()) { |
| 7358 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7359 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7360 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7361 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7362 | } else { |
| 7363 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7364 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7365 | } |
| 7366 | } else if (second.IsConstant()) { |
| 7367 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7368 | __ andl(first.AsRegister<Register>(), |
| 7369 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7370 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7371 | __ orl(first.AsRegister<Register>(), |
| 7372 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7373 | } else { |
| 7374 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7375 | __ xorl(first.AsRegister<Register>(), |
| 7376 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7377 | } |
| 7378 | } else { |
| 7379 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7380 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7381 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7382 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7383 | } else { |
| 7384 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7385 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7386 | } |
| 7387 | } |
| 7388 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7389 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7390 | if (second.IsRegisterPair()) { |
| 7391 | if (instruction->IsAnd()) { |
| 7392 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7393 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7394 | } else if (instruction->IsOr()) { |
| 7395 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7396 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7397 | } else { |
| 7398 | DCHECK(instruction->IsXor()); |
| 7399 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7400 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7401 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7402 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7403 | if (instruction->IsAnd()) { |
| 7404 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7405 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 7406 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7407 | } else if (instruction->IsOr()) { |
| 7408 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7409 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 7410 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7411 | } else { |
| 7412 | DCHECK(instruction->IsXor()); |
| 7413 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7414 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 7415 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7416 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7417 | } else { |
| 7418 | DCHECK(second.IsConstant()) << second; |
| 7419 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7420 | int32_t low_value = Low32Bits(value); |
| 7421 | int32_t high_value = High32Bits(value); |
| 7422 | Immediate low(low_value); |
| 7423 | Immediate high(high_value); |
| 7424 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7425 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7426 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7427 | if (low_value == 0) { |
| 7428 | __ xorl(first_low, first_low); |
| 7429 | } else if (low_value != -1) { |
| 7430 | __ andl(first_low, low); |
| 7431 | } |
| 7432 | if (high_value == 0) { |
| 7433 | __ xorl(first_high, first_high); |
| 7434 | } else if (high_value != -1) { |
| 7435 | __ andl(first_high, high); |
| 7436 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7437 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7438 | if (low_value != 0) { |
| 7439 | __ orl(first_low, low); |
| 7440 | } |
| 7441 | if (high_value != 0) { |
| 7442 | __ orl(first_high, high); |
| 7443 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7444 | } else { |
| 7445 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7446 | if (low_value != 0) { |
| 7447 | __ xorl(first_low, low); |
| 7448 | } |
| 7449 | if (high_value != 0) { |
| 7450 | __ xorl(first_high, high); |
| 7451 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7452 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7453 | } |
| 7454 | } |
| 7455 | } |
| 7456 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7457 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( |
| 7458 | HInstruction* instruction, |
| 7459 | Location out, |
| 7460 | uint32_t offset, |
| 7461 | Location maybe_temp, |
| 7462 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7463 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7464 | if (read_barrier_option == kWithReadBarrier) { |
| 7465 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7466 | if (kUseBakerReadBarrier) { |
| 7467 | // Load with fast path based Baker's read barrier. |
| 7468 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7469 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7470 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7471 | } else { |
| 7472 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7473 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7474 | // in the following move operation, as we will need it for the |
| 7475 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7476 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7477 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7478 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7479 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7480 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7481 | } |
| 7482 | } else { |
| 7483 | // Plain load with no read barrier. |
| 7484 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7485 | __ movl(out_reg, Address(out_reg, offset)); |
| 7486 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7487 | } |
| 7488 | } |
| 7489 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7490 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( |
| 7491 | HInstruction* instruction, |
| 7492 | Location out, |
| 7493 | Location obj, |
| 7494 | uint32_t offset, |
| 7495 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7496 | Register out_reg = out.AsRegister<Register>(); |
| 7497 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7498 | if (read_barrier_option == kWithReadBarrier) { |
| 7499 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7500 | if (kUseBakerReadBarrier) { |
| 7501 | // Load with fast path based Baker's read barrier. |
| 7502 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7503 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7504 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7505 | } else { |
| 7506 | // Load with slow path based read barrier. |
| 7507 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7508 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7509 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7510 | } |
| 7511 | } else { |
| 7512 | // Plain load with no read barrier. |
| 7513 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7514 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7515 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7516 | } |
| 7517 | } |
| 7518 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7519 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( |
| 7520 | HInstruction* instruction, |
| 7521 | Location root, |
| 7522 | const Address& address, |
| 7523 | Label* fixup_label, |
| 7524 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7525 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7526 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7527 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7528 | if (kUseBakerReadBarrier) { |
| 7529 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7530 | // Baker's read barrier are used: |
| 7531 | // |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7532 | // root = obj.field; |
| 7533 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7534 | // if (temp != null) { |
| 7535 | // root = temp(root) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7536 | // } |
| 7537 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7538 | // /* GcRoot<mirror::Object> */ root = *address |
| 7539 | __ movl(root_reg, address); |
| 7540 | if (fixup_label != nullptr) { |
| 7541 | __ Bind(fixup_label); |
| 7542 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7543 | static_assert( |
| 7544 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7545 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7546 | "have different sizes."); |
| 7547 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7548 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7549 | "have different sizes."); |
| 7550 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7551 | // Slow path marking the GC root `root`. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7552 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7553 | instruction, root, /* unpoison_ref_before_marking */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7554 | codegen_->AddSlowPath(slow_path); |
| 7555 | |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7556 | // Test the entrypoint (`Thread::Current()->pReadBarrierMarkReg ## root.reg()`). |
| 7557 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 7558 | Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(root.reg()); |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7559 | __ fs()->cmpl(Address::Absolute(entry_point_offset), Immediate(0)); |
| 7560 | // The entrypoint is null when the GC is not marking. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7561 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7562 | __ Bind(slow_path->GetExitLabel()); |
| 7563 | } else { |
| 7564 | // GC root loaded through a slow path for read barriers other |
| 7565 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7566 | // /* GcRoot<mirror::Object>* */ root = address |
| 7567 | __ leal(root_reg, address); |
| 7568 | if (fixup_label != nullptr) { |
| 7569 | __ Bind(fixup_label); |
| 7570 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7571 | // /* mirror::Object* */ root = root->Read() |
| 7572 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7573 | } |
| 7574 | } else { |
| 7575 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7576 | // /* GcRoot<mirror::Object> */ root = *address |
| 7577 | __ movl(root_reg, address); |
| 7578 | if (fixup_label != nullptr) { |
| 7579 | __ Bind(fixup_label); |
| 7580 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7581 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7582 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7583 | } |
| 7584 | } |
| 7585 | |
| 7586 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7587 | Location ref, |
| 7588 | Register obj, |
| 7589 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7590 | bool needs_null_check) { |
| 7591 | DCHECK(kEmitCompilerReadBarrier); |
| 7592 | DCHECK(kUseBakerReadBarrier); |
| 7593 | |
| 7594 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7595 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7596 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7597 | } |
| 7598 | |
| 7599 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7600 | Location ref, |
| 7601 | Register obj, |
| 7602 | uint32_t data_offset, |
| 7603 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7604 | bool needs_null_check) { |
| 7605 | DCHECK(kEmitCompilerReadBarrier); |
| 7606 | DCHECK(kUseBakerReadBarrier); |
| 7607 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7608 | static_assert( |
| 7609 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7610 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7611 | // /* HeapReference<Object> */ ref = |
| 7612 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7613 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7614 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7615 | } |
| 7616 | |
| 7617 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7618 | Location ref, |
| 7619 | Register obj, |
| 7620 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7621 | bool needs_null_check, |
| 7622 | bool always_update_field, |
| 7623 | Register* temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7624 | DCHECK(kEmitCompilerReadBarrier); |
| 7625 | DCHECK(kUseBakerReadBarrier); |
| 7626 | |
| 7627 | // In slow path based read barriers, the read barrier call is |
| 7628 | // inserted after the original load. However, in fast path based |
| 7629 | // Baker's read barriers, we need to perform the load of |
| 7630 | // mirror::Object::monitor_ *before* the original reference load. |
| 7631 | // This load-load ordering is required by the read barrier. |
| 7632 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7633 | // |
| 7634 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7635 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7636 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7637 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7638 | // if (is_gray) { |
| 7639 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7640 | // } |
| 7641 | // |
| 7642 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7643 | // slightly more complex as: |
| 7644 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7645 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7646 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7647 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7648 | // - it performs additional checks that we do not do here for |
| 7649 | // performance reasons. |
| 7650 | |
| 7651 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7652 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7653 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7654 | // 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] | 7655 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7656 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7657 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7658 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7659 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7660 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7661 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7662 | // ref = ReadBarrier::Mark(ref); |
| 7663 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7664 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7665 | if (needs_null_check) { |
| 7666 | MaybeRecordImplicitNullCheck(instruction); |
| 7667 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7668 | |
| 7669 | // Load fence to prevent load-load reordering. |
| 7670 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7671 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7672 | |
| 7673 | // The actual reference load. |
| 7674 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7675 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7676 | |
| 7677 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7678 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7679 | SlowPathCode* slow_path; |
| 7680 | if (always_update_field) { |
| 7681 | DCHECK(temp != nullptr); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7682 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7683 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp); |
| 7684 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7685 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7686 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 7687 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7688 | AddSlowPath(slow_path); |
| 7689 | |
| 7690 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7691 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7692 | |
| 7693 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7694 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7695 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7696 | __ Bind(slow_path->GetExitLabel()); |
| 7697 | } |
| 7698 | |
| 7699 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7700 | Location out, |
| 7701 | Location ref, |
| 7702 | Location obj, |
| 7703 | uint32_t offset, |
| 7704 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7705 | DCHECK(kEmitCompilerReadBarrier); |
| 7706 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7707 | // Insert a slow path based read barrier *after* the reference load. |
| 7708 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7709 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7710 | // reference will be carried out by the runtime within the slow |
| 7711 | // path. |
| 7712 | // |
| 7713 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7714 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7715 | // not used by the artReadBarrierSlow entry point. |
| 7716 | // |
| 7717 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7718 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7719 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 7720 | AddSlowPath(slow_path); |
| 7721 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7722 | __ jmp(slow_path->GetEntryLabel()); |
| 7723 | __ Bind(slow_path->GetExitLabel()); |
| 7724 | } |
| 7725 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7726 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7727 | Location out, |
| 7728 | Location ref, |
| 7729 | Location obj, |
| 7730 | uint32_t offset, |
| 7731 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7732 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7733 | // Baker's read barriers shall be handled by the fast path |
| 7734 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 7735 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7736 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7737 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7738 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7739 | } else if (kPoisonHeapReferences) { |
| 7740 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7741 | } |
| 7742 | } |
| 7743 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7744 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7745 | Location out, |
| 7746 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7747 | DCHECK(kEmitCompilerReadBarrier); |
| 7748 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7749 | // Insert a slow path based read barrier *after* the GC root load. |
| 7750 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7751 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7752 | // not need to do anything special for this here. |
| 7753 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7754 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7755 | AddSlowPath(slow_path); |
| 7756 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7757 | __ jmp(slow_path->GetEntryLabel()); |
| 7758 | __ Bind(slow_path->GetExitLabel()); |
| 7759 | } |
| 7760 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7761 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7762 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7763 | LOG(FATAL) << "Unreachable"; |
| 7764 | } |
| 7765 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7766 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7767 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7768 | LOG(FATAL) << "Unreachable"; |
| 7769 | } |
| 7770 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7771 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7772 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7773 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7774 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7775 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7776 | } |
| 7777 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7778 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7779 | int32_t lower_bound, |
| 7780 | uint32_t num_entries, |
| 7781 | HBasicBlock* switch_block, |
| 7782 | HBasicBlock* default_block) { |
| 7783 | // Figure out the correct compare values and jump conditions. |
| 7784 | // Handle the first compare/branch as a special case because it might |
| 7785 | // jump to the default case. |
| 7786 | DCHECK_GT(num_entries, 2u); |
| 7787 | Condition first_condition; |
| 7788 | uint32_t index; |
| 7789 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7790 | if (lower_bound != 0) { |
| 7791 | first_condition = kLess; |
| 7792 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7793 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7794 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7795 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7796 | index = 1; |
| 7797 | } else { |
| 7798 | // Handle all the compare/jumps below. |
| 7799 | first_condition = kBelow; |
| 7800 | index = 0; |
| 7801 | } |
| 7802 | |
| 7803 | // Handle the rest of the compare/jumps. |
| 7804 | for (; index + 1 < num_entries; index += 2) { |
| 7805 | int32_t compare_to_value = lower_bound + index + 1; |
| 7806 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7807 | // Jump to successors[index] if value < case_value[index]. |
| 7808 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7809 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7810 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7811 | } |
| 7812 | |
| 7813 | if (index != num_entries) { |
| 7814 | // There are an odd number of entries. Handle the last one. |
| 7815 | DCHECK_EQ(index + 1, num_entries); |
| 7816 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7817 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7818 | } |
| 7819 | |
| 7820 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7821 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7822 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7823 | } |
| 7824 | } |
| 7825 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7826 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7827 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7828 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7829 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7830 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7831 | |
| 7832 | GenPackedSwitchWithCompares(value_reg, |
| 7833 | lower_bound, |
| 7834 | num_entries, |
| 7835 | switch_instr->GetBlock(), |
| 7836 | switch_instr->GetDefaultBlock()); |
| 7837 | } |
| 7838 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7839 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7840 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7841 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7842 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7843 | |
| 7844 | // Constant area pointer. |
| 7845 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7846 | |
| 7847 | // And the temporary we need. |
| 7848 | locations->AddTemp(Location::RequiresRegister()); |
| 7849 | } |
| 7850 | |
| 7851 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7852 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7853 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7854 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7855 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7856 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7857 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7858 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7859 | GenPackedSwitchWithCompares(value_reg, |
| 7860 | lower_bound, |
| 7861 | num_entries, |
| 7862 | switch_instr->GetBlock(), |
| 7863 | default_block); |
| 7864 | return; |
| 7865 | } |
| 7866 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7867 | // Optimizing has a jump area. |
| 7868 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7869 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7870 | |
| 7871 | // Remove the bias, if needed. |
| 7872 | if (lower_bound != 0) { |
| 7873 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7874 | value_reg = temp_reg; |
| 7875 | } |
| 7876 | |
| 7877 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7878 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7879 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7880 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7881 | |
| 7882 | // We are in the range of the table. |
| 7883 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7884 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7885 | |
| 7886 | // Compute the actual target address by adding in constant_area. |
| 7887 | __ addl(temp_reg, constant_area); |
| 7888 | |
| 7889 | // And jump. |
| 7890 | __ jmp(temp_reg); |
| 7891 | } |
| 7892 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7893 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7894 | HX86ComputeBaseMethodAddress* insn) { |
| 7895 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7896 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7897 | locations->SetOut(Location::RequiresRegister()); |
| 7898 | } |
| 7899 | |
| 7900 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7901 | HX86ComputeBaseMethodAddress* insn) { |
| 7902 | LocationSummary* locations = insn->GetLocations(); |
| 7903 | Register reg = locations->Out().AsRegister<Register>(); |
| 7904 | |
| 7905 | // Generate call to next instruction. |
| 7906 | Label next_instruction; |
| 7907 | __ call(&next_instruction); |
| 7908 | __ Bind(&next_instruction); |
| 7909 | |
| 7910 | // Remember this offset for later use with constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7911 | codegen_->AddMethodAddressOffset(insn, GetAssembler()->CodeSize()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7912 | |
| 7913 | // Grab the return address off the stack. |
| 7914 | __ popl(reg); |
| 7915 | } |
| 7916 | |
| 7917 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7918 | HX86LoadFromConstantTable* insn) { |
| 7919 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7920 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7921 | |
| 7922 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7923 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7924 | |
| 7925 | // If we don't need to be materialized, we only need the inputs to be set. |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7926 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7927 | return; |
| 7928 | } |
| 7929 | |
| 7930 | switch (insn->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7931 | case DataType::Type::kFloat32: |
| 7932 | case DataType::Type::kFloat64: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7933 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7934 | break; |
| 7935 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7936 | case DataType::Type::kInt32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7937 | locations->SetOut(Location::RequiresRegister()); |
| 7938 | break; |
| 7939 | |
| 7940 | default: |
| 7941 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7942 | } |
| 7943 | } |
| 7944 | |
| 7945 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7946 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7947 | return; |
| 7948 | } |
| 7949 | |
| 7950 | LocationSummary* locations = insn->GetLocations(); |
| 7951 | Location out = locations->Out(); |
| 7952 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7953 | HConstant *value = insn->GetConstant(); |
| 7954 | |
| 7955 | switch (insn->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7956 | case DataType::Type::kFloat32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7957 | __ movss(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7958 | codegen_->LiteralFloatAddress( |
| 7959 | value->AsFloatConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7960 | break; |
| 7961 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7962 | case DataType::Type::kFloat64: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7963 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7964 | codegen_->LiteralDoubleAddress( |
| 7965 | value->AsDoubleConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7966 | break; |
| 7967 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7968 | case DataType::Type::kInt32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7969 | __ movl(out.AsRegister<Register>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7970 | codegen_->LiteralInt32Address( |
| 7971 | value->AsIntConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7972 | break; |
| 7973 | |
| 7974 | default: |
| 7975 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7976 | } |
| 7977 | } |
| 7978 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7979 | /** |
| 7980 | * Class to handle late fixup of offsets into constant area. |
| 7981 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7982 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7983 | public: |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7984 | RIPFixup(CodeGeneratorX86& codegen, |
| 7985 | HX86ComputeBaseMethodAddress* base_method_address, |
| 7986 | size_t offset) |
| 7987 | : codegen_(&codegen), |
| 7988 | base_method_address_(base_method_address), |
| 7989 | offset_into_constant_area_(offset) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7990 | |
| 7991 | protected: |
| 7992 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7993 | |
| 7994 | CodeGeneratorX86* codegen_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7995 | HX86ComputeBaseMethodAddress* base_method_address_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7996 | |
| 7997 | private: |
| 7998 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7999 | // Patch the correct offset for the instruction. The place to patch is the |
| 8000 | // last 4 bytes of the instruction. |
| 8001 | // The value to patch is the distance from the offset in the constant area |
| 8002 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8003 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8004 | int32_t relative_position = |
| 8005 | constant_offset - codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8006 | |
| 8007 | // Patch in the right value. |
| 8008 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 8009 | } |
| 8010 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8011 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8012 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8013 | }; |
| 8014 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8015 | /** |
| 8016 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 8017 | * constant area. |
| 8018 | */ |
| 8019 | class JumpTableRIPFixup : public RIPFixup { |
| 8020 | public: |
| 8021 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8022 | : RIPFixup(codegen, switch_instr->GetBaseMethodAddress(), static_cast<size_t>(-1)), |
| 8023 | switch_instr_(switch_instr) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8024 | |
| 8025 | void CreateJumpTable() { |
| 8026 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 8027 | |
| 8028 | // Ensure that the reference to the jump table has the correct offset. |
| 8029 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 8030 | SetOffset(offset_in_constant_table); |
| 8031 | |
| 8032 | // The label values in the jump table are computed relative to the |
| 8033 | // instruction addressing the constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8034 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8035 | |
| 8036 | // Populate the jump table with the correct values for the jump table. |
| 8037 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 8038 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 8039 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 8040 | // The value that we want is the target offset - the position of the table. |
| 8041 | for (int32_t i = 0; i < num_entries; i++) { |
| 8042 | HBasicBlock* b = successors[i]; |
| 8043 | Label* l = codegen_->GetLabelOf(b); |
| 8044 | DCHECK(l->IsBound()); |
| 8045 | int32_t offset_to_block = l->Position() - relative_offset; |
| 8046 | assembler->AppendInt32(offset_to_block); |
| 8047 | } |
| 8048 | } |
| 8049 | |
| 8050 | private: |
| 8051 | const HX86PackedSwitch* switch_instr_; |
| 8052 | }; |
| 8053 | |
| 8054 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 8055 | // Generate the constant area if needed. |
| 8056 | X86Assembler* assembler = GetAssembler(); |
| 8057 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 8058 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 8059 | // byte values. |
| 8060 | assembler->Align(4, 0); |
| 8061 | constant_area_start_ = assembler->CodeSize(); |
| 8062 | |
| 8063 | // Populate any jump tables. |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8064 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8065 | jump_table->CreateJumpTable(); |
| 8066 | } |
| 8067 | |
| 8068 | // And now add the constant area to the generated code. |
| 8069 | assembler->AddConstantArea(); |
| 8070 | } |
| 8071 | |
| 8072 | // And finish up. |
| 8073 | CodeGenerator::Finalize(allocator); |
| 8074 | } |
| 8075 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8076 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, |
| 8077 | HX86ComputeBaseMethodAddress* method_base, |
| 8078 | Register reg) { |
| 8079 | AssemblerFixup* fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8080 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddDouble(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8081 | return Address(reg, kDummy32BitOffset, fixup); |
| 8082 | } |
| 8083 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8084 | Address CodeGeneratorX86::LiteralFloatAddress(float v, |
| 8085 | HX86ComputeBaseMethodAddress* method_base, |
| 8086 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8087 | AssemblerFixup* fixup = |
| 8088 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddFloat(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8089 | return Address(reg, kDummy32BitOffset, fixup); |
| 8090 | } |
| 8091 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8092 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, |
| 8093 | HX86ComputeBaseMethodAddress* method_base, |
| 8094 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8095 | AssemblerFixup* fixup = |
| 8096 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt32(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8097 | return Address(reg, kDummy32BitOffset, fixup); |
| 8098 | } |
| 8099 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8100 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, |
| 8101 | HX86ComputeBaseMethodAddress* method_base, |
| 8102 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8103 | AssemblerFixup* fixup = |
| 8104 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt64(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8105 | return Address(reg, kDummy32BitOffset, fixup); |
| 8106 | } |
| 8107 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 8108 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 8109 | if (value == 0) { |
| 8110 | __ xorl(dest, dest); |
| 8111 | } else { |
| 8112 | __ movl(dest, Immediate(value)); |
| 8113 | } |
| 8114 | } |
| 8115 | |
| 8116 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 8117 | if (value == 0) { |
| 8118 | __ testl(dest, dest); |
| 8119 | } else { |
| 8120 | __ cmpl(dest, Immediate(value)); |
| 8121 | } |
| 8122 | } |
| 8123 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8124 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 8125 | Register lhs_reg = lhs.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8126 | GenerateIntCompare(lhs_reg, rhs); |
| 8127 | } |
| 8128 | |
| 8129 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8130 | if (rhs.IsConstant()) { |
| 8131 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8132 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8133 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8134 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8135 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8136 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8137 | } |
| 8138 | } |
| 8139 | |
| 8140 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 8141 | Location index, |
| 8142 | ScaleFactor scale, |
| 8143 | uint32_t data_offset) { |
| 8144 | return index.IsConstant() ? |
| 8145 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 8146 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 8147 | } |
| 8148 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8149 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 8150 | Register reg, |
| 8151 | Register value) { |
| 8152 | // Create a fixup to be used to create and address the jump table. |
| 8153 | JumpTableRIPFixup* table_fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8154 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8155 | |
| 8156 | // We have to populate the jump tables. |
| 8157 | fixups_to_jump_tables_.push_back(table_fixup); |
| 8158 | |
| 8159 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 8160 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 8161 | } |
| 8162 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8163 | // TODO: target as memory. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8164 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, DataType::Type type) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8165 | if (!target.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8166 | DCHECK_EQ(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8167 | return; |
| 8168 | } |
| 8169 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8170 | DCHECK_NE(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8171 | |
| 8172 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 8173 | if (target.Equals(return_loc)) { |
| 8174 | return; |
| 8175 | } |
| 8176 | |
| 8177 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 8178 | // with the else branch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8179 | if (type == DataType::Type::kInt64) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8180 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8181 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), DataType::Type::kInt32, nullptr); |
| 8182 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), DataType::Type::kInt32, nullptr); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8183 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8184 | } else { |
| 8185 | // Let the parallel move resolver take care of all of this. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8186 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8187 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 8188 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8189 | } |
| 8190 | } |
| 8191 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8192 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, |
| 8193 | const uint8_t* roots_data, |
| 8194 | const PatchInfo<Label>& info, |
| 8195 | uint64_t index_in_table) const { |
| 8196 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 8197 | uintptr_t address = |
| 8198 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 8199 | typedef __attribute__((__aligned__(1))) uint32_t unaligned_uint32_t; |
| 8200 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 8201 | dchecked_integral_cast<uint32_t>(address); |
| 8202 | } |
| 8203 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8204 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 8205 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8206 | StringReference string_reference(info.target_dex_file, dex::StringIndex(info.offset_or_index)); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8207 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8208 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8209 | } |
| 8210 | |
| 8211 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8212 | TypeReference type_reference(info.target_dex_file, dex::TypeIndex(info.offset_or_index)); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8213 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8214 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8215 | } |
| 8216 | } |
| 8217 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8218 | void LocationsBuilderX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 8219 | ATTRIBUTE_UNUSED) { |
| 8220 | LOG(FATAL) << "Unreachable"; |
| 8221 | } |
| 8222 | |
| 8223 | void InstructionCodeGeneratorX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 8224 | ATTRIBUTE_UNUSED) { |
| 8225 | LOG(FATAL) << "Unreachable"; |
| 8226 | } |
| 8227 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 8228 | #undef __ |
| 8229 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 8230 | } // namespace x86 |
| 8231 | } // namespace art |