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" |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 26 | #include "gc/space/image_space.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 27 | #include "heap_poisoning.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 28 | #include "intrinsics.h" |
| 29 | #include "intrinsics_x86.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 30 | #include "linker/linker_patch.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 31 | #include "lock_word.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 32 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 33 | #include "mirror/class-inl.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 34 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 36 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 37 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 38 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 39 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 40 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 41 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 42 | template<class MirrorType> |
| 43 | class GcRoot; |
| 44 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 45 | namespace x86 { |
| 46 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 47 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 48 | static constexpr Register kMethodRegisterArgument = EAX; |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 49 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 50 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 51 | static constexpr int kC2ConditionMask = 0x400; |
| 52 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 53 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 54 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 55 | static constexpr int64_t kDoubleNaN = INT64_C(0x7FF8000000000000); |
| 56 | static constexpr int32_t kFloatNaN = INT32_C(0x7FC00000); |
| 57 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 58 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 59 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 60 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86PointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 61 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 62 | class NullCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 63 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 64 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 65 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 66 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 67 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 68 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 69 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 70 | // Live registers will be restored in the catch block if caught. |
| 71 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 72 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 73 | x86_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 74 | instruction_, |
| 75 | instruction_->GetDexPc(), |
| 76 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 77 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 78 | } |
| 79 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 80 | bool IsFatal() const OVERRIDE { return true; } |
| 81 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 82 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 83 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 84 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 85 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 86 | }; |
| 87 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 88 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 89 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 90 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 91 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 92 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 93 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 94 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 95 | x86_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 96 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 99 | bool IsFatal() const OVERRIDE { return true; } |
| 100 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 101 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 102 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 104 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 105 | }; |
| 106 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 107 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 108 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 109 | DivRemMinusOneSlowPathX86(HInstruction* instruction, Register reg, bool is_div) |
| 110 | : SlowPathCode(instruction), reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 112 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 113 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 114 | if (is_div_) { |
| 115 | __ negl(reg_); |
| 116 | } else { |
| 117 | __ movl(reg_, Immediate(0)); |
| 118 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 119 | __ jmp(GetExitLabel()); |
| 120 | } |
| 121 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 122 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 123 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 124 | private: |
| 125 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 126 | bool is_div_; |
| 127 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 128 | }; |
| 129 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 130 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 131 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 132 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 133 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 134 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 135 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 136 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 137 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 138 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 139 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 140 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 141 | // Live registers will be restored in the catch block if caught. |
| 142 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 143 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 144 | |
| 145 | // Are we using an array length from memory? |
| 146 | HInstruction* array_length = instruction_->InputAt(1); |
| 147 | Location length_loc = locations->InAt(1); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 148 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 149 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 150 | // Load the array length into our temporary. |
Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 151 | HArrayLength* length = array_length->AsArrayLength(); |
| 152 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 153 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 154 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| 155 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 156 | // Check for conflicts with index. |
| 157 | if (length_loc.Equals(locations->InAt(0))) { |
| 158 | // We know we aren't using parameter 2. |
| 159 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 160 | } |
| 161 | __ movl(length_loc.AsRegister<Register>(), array_len); |
Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 162 | if (mirror::kUseStringCompression && length->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 163 | __ shrl(length_loc.AsRegister<Register>(), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 164 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 165 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 166 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 167 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 168 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 169 | DataType::Type::kInt32, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 170 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 171 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 172 | DataType::Type::kInt32); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 173 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 174 | ? kQuickThrowStringBounds |
| 175 | : kQuickThrowArrayBounds; |
| 176 | x86_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 177 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 178 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 179 | } |
| 180 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 181 | bool IsFatal() const OVERRIDE { return true; } |
| 182 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 183 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 184 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 185 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 186 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 187 | }; |
| 188 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 189 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 190 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 191 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 192 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 193 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 194 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 195 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 196 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 197 | __ Bind(GetEntryLabel()); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 198 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 199 | x86_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 200 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 201 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 202 | if (successor_ == nullptr) { |
| 203 | __ jmp(GetReturnLabel()); |
| 204 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 205 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 206 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 209 | Label* GetReturnLabel() { |
| 210 | DCHECK(successor_ == nullptr); |
| 211 | return &return_label_; |
| 212 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 213 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 214 | HBasicBlock* GetSuccessor() const { |
| 215 | return successor_; |
| 216 | } |
| 217 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 218 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 219 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 220 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 221 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 222 | Label return_label_; |
| 223 | |
| 224 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 225 | }; |
| 226 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 227 | class LoadStringSlowPathX86 : public SlowPathCode { |
| 228 | public: |
| 229 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} |
| 230 | |
| 231 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 232 | LocationSummary* locations = instruction_->GetLocations(); |
| 233 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 234 | |
| 235 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 236 | __ Bind(GetEntryLabel()); |
| 237 | SaveLiveRegisters(codegen, locations); |
| 238 | |
| 239 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 240 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 241 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index.index_)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 242 | x86_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 243 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 244 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 245 | RestoreLiveRegisters(codegen, locations); |
| 246 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 247 | __ jmp(GetExitLabel()); |
| 248 | } |
| 249 | |
| 250 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 251 | |
| 252 | private: |
| 253 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 254 | }; |
| 255 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 256 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 257 | public: |
| 258 | LoadClassSlowPathX86(HLoadClass* cls, |
| 259 | HInstruction* at, |
| 260 | uint32_t dex_pc, |
| 261 | bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 262 | : SlowPathCode(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 263 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 264 | } |
| 265 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 266 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 267 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 268 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 269 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 270 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 271 | |
| 272 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 273 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 274 | __ movl(calling_convention.GetRegisterAt(0), Immediate(type_index.index_)); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 275 | x86_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage |
| 276 | : kQuickInitializeType, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 277 | instruction_, |
| 278 | dex_pc_, |
| 279 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 280 | if (do_clinit_) { |
| 281 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 282 | } else { |
| 283 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 284 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 285 | |
| 286 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 287 | Location out = locations->Out(); |
| 288 | if (out.IsValid()) { |
| 289 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 290 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 291 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 292 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 293 | __ jmp(GetExitLabel()); |
| 294 | } |
| 295 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 296 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 297 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 298 | private: |
| 299 | // The class this slow path will load. |
| 300 | HLoadClass* const cls_; |
| 301 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 302 | // The dex PC of `at_`. |
| 303 | const uint32_t dex_pc_; |
| 304 | |
| 305 | // Whether to initialize the class. |
| 306 | const bool do_clinit_; |
| 307 | |
| 308 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 309 | }; |
| 310 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 311 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 312 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 313 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 314 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 315 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 316 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 317 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 318 | DCHECK(instruction_->IsCheckCast() |
| 319 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 320 | |
| 321 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 322 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 323 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 324 | if (kPoisonHeapReferences && |
| 325 | instruction_->IsCheckCast() && |
| 326 | instruction_->AsCheckCast()->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) { |
| 327 | // First, unpoison the `cls` reference that was poisoned for direct memory comparison. |
| 328 | __ UnpoisonHeapReference(locations->InAt(1).AsRegister<Register>()); |
| 329 | } |
| 330 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 331 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 332 | SaveLiveRegisters(codegen, locations); |
| 333 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 334 | |
| 335 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 336 | // move resolver. |
| 337 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 338 | x86_codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 339 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 340 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 341 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 342 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 343 | DataType::Type::kReference); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 344 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 345 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 346 | instruction_, |
| 347 | instruction_->GetDexPc(), |
| 348 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 349 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 350 | } else { |
| 351 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 352 | x86_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 353 | instruction_, |
| 354 | instruction_->GetDexPc(), |
| 355 | this); |
| 356 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 359 | if (!is_fatal_) { |
| 360 | if (instruction_->IsInstanceOf()) { |
| 361 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 362 | } |
| 363 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 364 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 365 | __ jmp(GetExitLabel()); |
| 366 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 369 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 370 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 371 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 372 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 373 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 374 | |
| 375 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 376 | }; |
| 377 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 378 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 379 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 380 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 381 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 382 | |
| 383 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 384 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 385 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 386 | LocationSummary* locations = instruction_->GetLocations(); |
| 387 | SaveLiveRegisters(codegen, locations); |
| 388 | InvokeRuntimeCallingConvention calling_convention; |
| 389 | x86_codegen->Load32BitValue( |
| 390 | calling_convention.GetRegisterAt(0), |
| 391 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 392 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 393 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 396 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 397 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 398 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 399 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 400 | }; |
| 401 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 402 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 403 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 404 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 405 | |
| 406 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 407 | LocationSummary* locations = instruction_->GetLocations(); |
| 408 | __ Bind(GetEntryLabel()); |
| 409 | SaveLiveRegisters(codegen, locations); |
| 410 | |
| 411 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 412 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 413 | parallel_move.AddMove( |
| 414 | locations->InAt(0), |
| 415 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 416 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 417 | nullptr); |
| 418 | parallel_move.AddMove( |
| 419 | locations->InAt(1), |
| 420 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 421 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 422 | nullptr); |
| 423 | parallel_move.AddMove( |
| 424 | locations->InAt(2), |
| 425 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 426 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 427 | nullptr); |
| 428 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 429 | |
| 430 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 431 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 432 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 433 | RestoreLiveRegisters(codegen, locations); |
| 434 | __ jmp(GetExitLabel()); |
| 435 | } |
| 436 | |
| 437 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 438 | |
| 439 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 440 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 441 | }; |
| 442 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 443 | // Slow path marking an object reference `ref` during a read |
| 444 | // barrier. The field `obj.field` in the object `obj` holding this |
| 445 | // reference does not get updated by this slow path after marking (see |
| 446 | // ReadBarrierMarkAndUpdateFieldSlowPathX86 below for that). |
| 447 | // |
| 448 | // This means that after the execution of this slow path, `ref` will |
| 449 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 450 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 451 | // probably still be a from-space reference (unless it gets updated by |
| 452 | // another thread, or if another thread installed another object |
| 453 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 454 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 455 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 456 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, |
| 457 | Location ref, |
| 458 | bool unpoison_ref_before_marking) |
| 459 | : SlowPathCode(instruction), |
| 460 | ref_(ref), |
| 461 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 462 | DCHECK(kEmitCompilerReadBarrier); |
| 463 | } |
| 464 | |
| 465 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 466 | |
| 467 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 468 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 469 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 470 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 471 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 472 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 473 | instruction_->IsStaticFieldGet() || |
| 474 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 475 | instruction_->IsArraySet() || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 476 | instruction_->IsLoadClass() || |
| 477 | instruction_->IsLoadString() || |
| 478 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 479 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 480 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 481 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 482 | << "Unexpected instruction in read barrier marking slow path: " |
| 483 | << instruction_->DebugName(); |
| 484 | |
| 485 | __ Bind(GetEntryLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 486 | if (unpoison_ref_before_marking_) { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 487 | // Object* ref = ref_addr->AsMirrorPtr() |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 488 | __ MaybeUnpoisonHeapReference(ref_reg); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 489 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 490 | // No need to save live registers; it's taken care of by the |
| 491 | // entrypoint. Also, there is no need to update the stack mask, |
| 492 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 493 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 494 | DCHECK_NE(ref_reg, ESP); |
| 495 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 496 | // "Compact" slow path, saving two moves. |
| 497 | // |
| 498 | // Instead of using the standard runtime calling convention (input |
| 499 | // and output in EAX): |
| 500 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 501 | // EAX <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 502 | // EAX <- ReadBarrierMark(EAX) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 503 | // ref <- EAX |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 504 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 505 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 506 | // of a dedicated entrypoint: |
| 507 | // |
| 508 | // rX <- ReadBarrierMarkRegX(rX) |
| 509 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 510 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 511 | // This runtime call does not require a stack map. |
| 512 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 513 | __ jmp(GetExitLabel()); |
| 514 | } |
| 515 | |
| 516 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 517 | // The location (register) of the marked object reference. |
| 518 | const Location ref_; |
| 519 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 520 | const bool unpoison_ref_before_marking_; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 521 | |
| 522 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 523 | }; |
| 524 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 525 | // Slow path marking an object reference `ref` during a read barrier, |
| 526 | // and if needed, atomically updating the field `obj.field` in the |
| 527 | // object `obj` holding this reference after marking (contrary to |
| 528 | // ReadBarrierMarkSlowPathX86 above, which never tries to update |
| 529 | // `obj.field`). |
| 530 | // |
| 531 | // This means that after the execution of this slow path, both `ref` |
| 532 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 533 | // hold the same to-space reference (unless another thread installed |
| 534 | // another object reference (different from `ref`) in `obj.field`). |
| 535 | class ReadBarrierMarkAndUpdateFieldSlowPathX86 : public SlowPathCode { |
| 536 | public: |
| 537 | ReadBarrierMarkAndUpdateFieldSlowPathX86(HInstruction* instruction, |
| 538 | Location ref, |
| 539 | Register obj, |
| 540 | const Address& field_addr, |
| 541 | bool unpoison_ref_before_marking, |
| 542 | Register temp) |
| 543 | : SlowPathCode(instruction), |
| 544 | ref_(ref), |
| 545 | obj_(obj), |
| 546 | field_addr_(field_addr), |
| 547 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 548 | temp_(temp) { |
| 549 | DCHECK(kEmitCompilerReadBarrier); |
| 550 | } |
| 551 | |
| 552 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkAndUpdateFieldSlowPathX86"; } |
| 553 | |
| 554 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 555 | LocationSummary* locations = instruction_->GetLocations(); |
| 556 | Register ref_reg = ref_.AsRegister<Register>(); |
| 557 | DCHECK(locations->CanCall()); |
| 558 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 559 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 560 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 561 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 562 | << instruction_->DebugName(); |
| 563 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 564 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 565 | |
| 566 | __ Bind(GetEntryLabel()); |
| 567 | if (unpoison_ref_before_marking_) { |
| 568 | // Object* ref = ref_addr->AsMirrorPtr() |
| 569 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 570 | } |
| 571 | |
| 572 | // Save the old (unpoisoned) reference. |
| 573 | __ movl(temp_, ref_reg); |
| 574 | |
| 575 | // No need to save live registers; it's taken care of by the |
| 576 | // entrypoint. Also, there is no need to update the stack mask, |
| 577 | // as this runtime call will not trigger a garbage collection. |
| 578 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 579 | DCHECK_NE(ref_reg, ESP); |
| 580 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 581 | // "Compact" slow path, saving two moves. |
| 582 | // |
| 583 | // Instead of using the standard runtime calling convention (input |
| 584 | // and output in EAX): |
| 585 | // |
| 586 | // EAX <- ref |
| 587 | // EAX <- ReadBarrierMark(EAX) |
| 588 | // ref <- EAX |
| 589 | // |
| 590 | // we just use rX (the register containing `ref`) as input and output |
| 591 | // of a dedicated entrypoint: |
| 592 | // |
| 593 | // rX <- ReadBarrierMarkRegX(rX) |
| 594 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 595 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 596 | // This runtime call does not require a stack map. |
| 597 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 598 | |
| 599 | // If the new reference is different from the old reference, |
| 600 | // update the field in the holder (`*field_addr`). |
| 601 | // |
| 602 | // Note that this field could also hold a different object, if |
| 603 | // another thread had concurrently changed it. In that case, the |
| 604 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 605 | // operation below would abort the CAS, leaving the field as-is. |
| 606 | NearLabel done; |
| 607 | __ cmpl(temp_, ref_reg); |
| 608 | __ j(kEqual, &done); |
| 609 | |
| 610 | // Update the the holder's field atomically. This may fail if |
| 611 | // mutator updates before us, but it's OK. This is achieved |
| 612 | // using a strong compare-and-set (CAS) operation with relaxed |
| 613 | // memory synchronization ordering, where the expected value is |
| 614 | // the old reference and the desired value is the new reference. |
| 615 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 616 | // instruction, which requires the expected value (the old |
| 617 | // reference) to be in EAX. Save EAX beforehand, and move the |
| 618 | // expected value (stored in `temp_`) into EAX. |
| 619 | __ pushl(EAX); |
| 620 | __ movl(EAX, temp_); |
| 621 | |
| 622 | // Convenience aliases. |
| 623 | Register base = obj_; |
| 624 | Register expected = EAX; |
| 625 | Register value = ref_reg; |
| 626 | |
| 627 | bool base_equals_value = (base == value); |
| 628 | if (kPoisonHeapReferences) { |
| 629 | if (base_equals_value) { |
| 630 | // If `base` and `value` are the same register location, move |
| 631 | // `value` to a temporary register. This way, poisoning |
| 632 | // `value` won't invalidate `base`. |
| 633 | value = temp_; |
| 634 | __ movl(value, base); |
| 635 | } |
| 636 | |
| 637 | // Check that the register allocator did not assign the location |
| 638 | // of `expected` (EAX) to `value` nor to `base`, so that heap |
| 639 | // poisoning (when enabled) works as intended below. |
| 640 | // - If `value` were equal to `expected`, both references would |
| 641 | // be poisoned twice, meaning they would not be poisoned at |
| 642 | // all, as heap poisoning uses address negation. |
| 643 | // - If `base` were equal to `expected`, poisoning `expected` |
| 644 | // would invalidate `base`. |
| 645 | DCHECK_NE(value, expected); |
| 646 | DCHECK_NE(base, expected); |
| 647 | |
| 648 | __ PoisonHeapReference(expected); |
| 649 | __ PoisonHeapReference(value); |
| 650 | } |
| 651 | |
| 652 | __ LockCmpxchgl(field_addr_, value); |
| 653 | |
| 654 | // If heap poisoning is enabled, we need to unpoison the values |
| 655 | // that were poisoned earlier. |
| 656 | if (kPoisonHeapReferences) { |
| 657 | if (base_equals_value) { |
| 658 | // `value` has been moved to a temporary register, no need |
| 659 | // to unpoison it. |
| 660 | } else { |
| 661 | __ UnpoisonHeapReference(value); |
| 662 | } |
| 663 | // No need to unpoison `expected` (EAX), as it is be overwritten below. |
| 664 | } |
| 665 | |
| 666 | // Restore EAX. |
| 667 | __ popl(EAX); |
| 668 | |
| 669 | __ Bind(&done); |
| 670 | __ jmp(GetExitLabel()); |
| 671 | } |
| 672 | |
| 673 | private: |
| 674 | // The location (register) of the marked object reference. |
| 675 | const Location ref_; |
| 676 | // The register containing the object holding the marked object reference field. |
| 677 | const Register obj_; |
| 678 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 679 | const Address field_addr_; |
| 680 | |
| 681 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 682 | const bool unpoison_ref_before_marking_; |
| 683 | |
| 684 | const Register temp_; |
| 685 | |
| 686 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86); |
| 687 | }; |
| 688 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 689 | // Slow path generating a read barrier for a heap reference. |
| 690 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 691 | public: |
| 692 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 693 | Location out, |
| 694 | Location ref, |
| 695 | Location obj, |
| 696 | uint32_t offset, |
| 697 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 698 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 699 | out_(out), |
| 700 | ref_(ref), |
| 701 | obj_(obj), |
| 702 | offset_(offset), |
| 703 | index_(index) { |
| 704 | DCHECK(kEmitCompilerReadBarrier); |
| 705 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 706 | // has been overwritten by (or after) the heap object reference load |
| 707 | // to be instrumented, e.g.: |
| 708 | // |
| 709 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 710 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 711 | // |
| 712 | // In that case, we have lost the information about the original |
| 713 | // object, and the emitted read barrier cannot work properly. |
| 714 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 715 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 716 | } |
| 717 | |
| 718 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 719 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 720 | LocationSummary* locations = instruction_->GetLocations(); |
| 721 | Register reg_out = out_.AsRegister<Register>(); |
| 722 | DCHECK(locations->CanCall()); |
| 723 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 724 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 725 | instruction_->IsStaticFieldGet() || |
| 726 | instruction_->IsArrayGet() || |
| 727 | instruction_->IsInstanceOf() || |
| 728 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 729 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 730 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 731 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 732 | |
| 733 | __ Bind(GetEntryLabel()); |
| 734 | SaveLiveRegisters(codegen, locations); |
| 735 | |
| 736 | // We may have to change the index's value, but as `index_` is a |
| 737 | // constant member (like other "inputs" of this slow path), |
| 738 | // introduce a copy of it, `index`. |
| 739 | Location index = index_; |
| 740 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 741 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 742 | if (instruction_->IsArrayGet()) { |
| 743 | // Compute the actual memory offset and store it in `index`. |
| 744 | Register index_reg = index_.AsRegister<Register>(); |
| 745 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 746 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 747 | // We are about to change the value of `index_reg` (see the |
| 748 | // calls to art::x86::X86Assembler::shll and |
| 749 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 750 | // not been saved by the previous call to |
| 751 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 752 | // callee-save register -- |
| 753 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 754 | // callee-save registers, as it has been designed with the |
| 755 | // assumption that callee-save registers are supposed to be |
| 756 | // handled by the called function. So, as a callee-save |
| 757 | // register, `index_reg` _would_ eventually be saved onto |
| 758 | // the stack, but it would be too late: we would have |
| 759 | // changed its value earlier. Therefore, we manually save |
| 760 | // it here into another freely available register, |
| 761 | // `free_reg`, chosen of course among the caller-save |
| 762 | // registers (as a callee-save `free_reg` register would |
| 763 | // exhibit the same problem). |
| 764 | // |
| 765 | // Note we could have requested a temporary register from |
| 766 | // the register allocator instead; but we prefer not to, as |
| 767 | // this is a slow path, and we know we can find a |
| 768 | // caller-save register that is available. |
| 769 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 770 | __ movl(free_reg, index_reg); |
| 771 | index_reg = free_reg; |
| 772 | index = Location::RegisterLocation(index_reg); |
| 773 | } else { |
| 774 | // The initial register stored in `index_` has already been |
| 775 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 776 | // (as it is not a callee-save register), so we can freely |
| 777 | // use it. |
| 778 | } |
| 779 | // Shifting the index value contained in `index_reg` by the scale |
| 780 | // factor (2) cannot overflow in practice, as the runtime is |
| 781 | // unable to allocate object arrays with a size larger than |
| 782 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 783 | __ shll(index_reg, Immediate(TIMES_4)); |
| 784 | static_assert( |
| 785 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 786 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 787 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 788 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 789 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 790 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 791 | // (as in the case of ArrayGet), as it is actually an offset |
| 792 | // to an object field within an object. |
| 793 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 794 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 795 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 796 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 797 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 798 | DCHECK_EQ(offset_, 0U); |
| 799 | DCHECK(index_.IsRegisterPair()); |
| 800 | // UnsafeGet's offset location is a register pair, the low |
| 801 | // part contains the correct offset. |
| 802 | index = index_.ToLow(); |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | // We're moving two or three locations to locations that could |
| 807 | // overlap, so we need a parallel move resolver. |
| 808 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 809 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 810 | parallel_move.AddMove(ref_, |
| 811 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 812 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 813 | nullptr); |
| 814 | parallel_move.AddMove(obj_, |
| 815 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 816 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 817 | nullptr); |
| 818 | if (index.IsValid()) { |
| 819 | parallel_move.AddMove(index, |
| 820 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 821 | DataType::Type::kInt32, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 822 | nullptr); |
| 823 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 824 | } else { |
| 825 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 826 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 827 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 828 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 829 | CheckEntrypointTypes< |
| 830 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 831 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 832 | |
| 833 | RestoreLiveRegisters(codegen, locations); |
| 834 | __ jmp(GetExitLabel()); |
| 835 | } |
| 836 | |
| 837 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 838 | |
| 839 | private: |
| 840 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 841 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 842 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 843 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 844 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 845 | return static_cast<Register>(i); |
| 846 | } |
| 847 | } |
| 848 | // We shall never fail to find a free caller-save register, as |
| 849 | // there are more than two core caller-save registers on x86 |
| 850 | // (meaning it is possible to find one which is different from |
| 851 | // `ref` and `obj`). |
| 852 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 853 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 854 | UNREACHABLE(); |
| 855 | } |
| 856 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 857 | const Location out_; |
| 858 | const Location ref_; |
| 859 | const Location obj_; |
| 860 | const uint32_t offset_; |
| 861 | // An additional location containing an index to an array. |
| 862 | // Only used for HArrayGet and the UnsafeGetObject & |
| 863 | // UnsafeGetObjectVolatile intrinsics. |
| 864 | const Location index_; |
| 865 | |
| 866 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 867 | }; |
| 868 | |
| 869 | // Slow path generating a read barrier for a GC root. |
| 870 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 871 | public: |
| 872 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 873 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 874 | DCHECK(kEmitCompilerReadBarrier); |
| 875 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 876 | |
| 877 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 878 | LocationSummary* locations = instruction_->GetLocations(); |
| 879 | Register reg_out = out_.AsRegister<Register>(); |
| 880 | DCHECK(locations->CanCall()); |
| 881 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 882 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 883 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 884 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 885 | |
| 886 | __ Bind(GetEntryLabel()); |
| 887 | SaveLiveRegisters(codegen, locations); |
| 888 | |
| 889 | InvokeRuntimeCallingConvention calling_convention; |
| 890 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 891 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 892 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 893 | instruction_, |
| 894 | instruction_->GetDexPc(), |
| 895 | this); |
| 896 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 897 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 898 | |
| 899 | RestoreLiveRegisters(codegen, locations); |
| 900 | __ jmp(GetExitLabel()); |
| 901 | } |
| 902 | |
| 903 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 904 | |
| 905 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 906 | const Location out_; |
| 907 | const Location root_; |
| 908 | |
| 909 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 910 | }; |
| 911 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 912 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 913 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 914 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 915 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 916 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 917 | switch (cond) { |
| 918 | case kCondEQ: return kEqual; |
| 919 | case kCondNE: return kNotEqual; |
| 920 | case kCondLT: return kLess; |
| 921 | case kCondLE: return kLessEqual; |
| 922 | case kCondGT: return kGreater; |
| 923 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 924 | case kCondB: return kBelow; |
| 925 | case kCondBE: return kBelowEqual; |
| 926 | case kCondA: return kAbove; |
| 927 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 928 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 929 | LOG(FATAL) << "Unreachable"; |
| 930 | UNREACHABLE(); |
| 931 | } |
| 932 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 933 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 934 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 935 | switch (cond) { |
| 936 | case kCondEQ: return kEqual; |
| 937 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 938 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 939 | case kCondLT: return kBelow; |
| 940 | case kCondLE: return kBelowEqual; |
| 941 | case kCondGT: return kAbove; |
| 942 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 943 | // Unsigned remain unchanged. |
| 944 | case kCondB: return kBelow; |
| 945 | case kCondBE: return kBelowEqual; |
| 946 | case kCondA: return kAbove; |
| 947 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 948 | } |
| 949 | LOG(FATAL) << "Unreachable"; |
| 950 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 951 | } |
| 952 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 953 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 954 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 958 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 959 | } |
| 960 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame^] | 961 | const X86InstructionSetFeatures& CodeGeneratorX86::GetInstructionSetFeatures() const { |
| 962 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsX86InstructionSetFeatures(); |
| 963 | } |
| 964 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 965 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 966 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 967 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 968 | } |
| 969 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 970 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 971 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 972 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 973 | } |
| 974 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 975 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 976 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 977 | __ movups(Address(ESP, stack_index), XmmRegister(reg_id)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 978 | } else { |
| 979 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 980 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 981 | return GetFloatingPointSpillSlotSize(); |
| 982 | } |
| 983 | |
| 984 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 985 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 986 | __ movups(XmmRegister(reg_id), Address(ESP, stack_index)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 987 | } else { |
| 988 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 989 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 990 | return GetFloatingPointSpillSlotSize(); |
| 991 | } |
| 992 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 993 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 994 | HInstruction* instruction, |
| 995 | uint32_t dex_pc, |
| 996 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 997 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 998 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 999 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1000 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1001 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1002 | } |
| 1003 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1004 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1005 | HInstruction* instruction, |
| 1006 | SlowPathCode* slow_path) { |
| 1007 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1008 | GenerateInvokeRuntime(entry_point_offset); |
| 1009 | } |
| 1010 | |
| 1011 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1012 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 1013 | } |
| 1014 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1015 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1016 | const CompilerOptions& compiler_options, |
| 1017 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1018 | : CodeGenerator(graph, |
| 1019 | kNumberOfCpuRegisters, |
| 1020 | kNumberOfXmmRegisters, |
| 1021 | kNumberOfRegisterPairs, |
| 1022 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1023 | arraysize(kCoreCalleeSaves)) |
| 1024 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1025 | 0, |
| 1026 | compiler_options, |
| 1027 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1028 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1029 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1030 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1031 | move_resolver_(graph->GetAllocator(), this), |
| 1032 | assembler_(graph->GetAllocator()), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1033 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1034 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1035 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1036 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1037 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1038 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1039 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1040 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1041 | constant_area_start_(-1), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1042 | fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1043 | method_address_offset_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1044 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1045 | // Use a fake return address register to mimic Quick. |
| 1046 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1047 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1048 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1049 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1050 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1051 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1052 | } |
| 1053 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1054 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1055 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1056 | assembler_(codegen->GetAssembler()), |
| 1057 | codegen_(codegen) {} |
| 1058 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1059 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1060 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1061 | } |
| 1062 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1063 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1064 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1065 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1066 | bool skip_overflow_check = |
| 1067 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1068 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1069 | |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1070 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1071 | __ addw(Address(kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value()), |
| 1072 | Immediate(1)); |
| 1073 | } |
| 1074 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1075 | if (!skip_overflow_check) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1076 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86); |
| 1077 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(reserved_bytes))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1078 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1079 | } |
| 1080 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1081 | if (HasEmptyFrame()) { |
| 1082 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1083 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1084 | |
| 1085 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1086 | Register reg = kCoreCalleeSaves[i]; |
| 1087 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1088 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1089 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1090 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1091 | } |
| 1092 | } |
| 1093 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1094 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1095 | __ subl(ESP, Immediate(adjust)); |
| 1096 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1097 | // Save the current method if we need it. Note that we do not |
| 1098 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1099 | // in the SSA graph. |
| 1100 | if (RequiresCurrentMethod()) { |
| 1101 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1102 | } |
Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 1103 | |
| 1104 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1105 | // Initialize should_deoptimize flag to 0. |
| 1106 | __ movl(Address(ESP, GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
| 1107 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1111 | __ cfi().RememberState(); |
| 1112 | if (!HasEmptyFrame()) { |
| 1113 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1114 | __ addl(ESP, Immediate(adjust)); |
| 1115 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1116 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1117 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1118 | Register reg = kCoreCalleeSaves[i]; |
| 1119 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1120 | __ popl(reg); |
| 1121 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1122 | __ cfi().Restore(DWARFReg(reg)); |
| 1123 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1124 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1125 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1126 | __ ret(); |
| 1127 | __ cfi().RestoreState(); |
| 1128 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1129 | } |
| 1130 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1131 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1132 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1135 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(DataType::Type type) const { |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1136 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1137 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1138 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1139 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1140 | case DataType::Type::kInt8: |
| 1141 | case DataType::Type::kUint16: |
| 1142 | case DataType::Type::kInt16: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1143 | case DataType::Type::kUint32: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1144 | case DataType::Type::kInt32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1145 | return Location::RegisterLocation(EAX); |
| 1146 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1147 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1148 | case DataType::Type::kInt64: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1149 | return Location::RegisterPairLocation(EAX, EDX); |
| 1150 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1151 | case DataType::Type::kVoid: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1152 | return Location::NoLocation(); |
| 1153 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1154 | case DataType::Type::kFloat64: |
| 1155 | case DataType::Type::kFloat32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1156 | return Location::FpuRegisterLocation(XMM0); |
| 1157 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1158 | |
| 1159 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1163 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1164 | } |
| 1165 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1166 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(DataType::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1167 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1168 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1169 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1170 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1171 | case DataType::Type::kInt8: |
| 1172 | case DataType::Type::kUint16: |
| 1173 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1174 | case DataType::Type::kInt32: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1175 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1176 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1177 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1178 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1179 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1180 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1181 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1182 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1183 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1184 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1185 | uint32_t index = gp_index_; |
| 1186 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1187 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1188 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1189 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1190 | calling_convention.GetRegisterPairAt(index)); |
| 1191 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1192 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1193 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1194 | } |
| 1195 | } |
| 1196 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1197 | case DataType::Type::kFloat32: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1198 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1199 | stack_index_++; |
| 1200 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1201 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1202 | } else { |
| 1203 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1204 | } |
| 1205 | } |
| 1206 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1207 | case DataType::Type::kFloat64: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1208 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1209 | stack_index_ += 2; |
| 1210 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1211 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1212 | } else { |
| 1213 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1214 | } |
| 1215 | } |
| 1216 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1217 | case DataType::Type::kUint32: |
| 1218 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1219 | case DataType::Type::kVoid: |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1220 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1221 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1222 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1223 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1224 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1225 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1226 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1227 | if (source.Equals(destination)) { |
| 1228 | return; |
| 1229 | } |
| 1230 | if (destination.IsRegister()) { |
| 1231 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1232 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1233 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1234 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1235 | } else { |
| 1236 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1237 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1238 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1239 | } else if (destination.IsFpuRegister()) { |
| 1240 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1241 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1242 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1243 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1244 | } else { |
| 1245 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1246 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1247 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1248 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1249 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1250 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1251 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1252 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1253 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1254 | } else if (source.IsConstant()) { |
| 1255 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1256 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1257 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1258 | } else { |
| 1259 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1260 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1261 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1262 | } |
| 1263 | } |
| 1264 | } |
| 1265 | |
| 1266 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1267 | if (source.Equals(destination)) { |
| 1268 | return; |
| 1269 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1270 | if (destination.IsRegisterPair()) { |
| 1271 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1272 | EmitParallelMoves( |
| 1273 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1274 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1275 | DataType::Type::kInt32, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1276 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1277 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1278 | DataType::Type::kInt32); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1279 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1280 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1281 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1282 | __ psrlq(src_reg, Immediate(32)); |
| 1283 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1284 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1285 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1286 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1287 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1288 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1289 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1290 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1291 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1292 | if (source.IsFpuRegister()) { |
| 1293 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1294 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1295 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1296 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1297 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1298 | // Create stack space for 2 elements. |
| 1299 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1300 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1301 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1302 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1303 | // And remove the temporary stack space we allocated. |
| 1304 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1305 | } else { |
| 1306 | LOG(FATAL) << "Unimplemented"; |
| 1307 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1308 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1309 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1310 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1311 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1312 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1313 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1314 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1315 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1316 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1317 | } else if (source.IsConstant()) { |
| 1318 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1319 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1320 | int64_t value = GetInt64ValueOf(constant); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1321 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1322 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1323 | Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1324 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1325 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1326 | EmitParallelMoves( |
| 1327 | Location::StackSlot(source.GetStackIndex()), |
| 1328 | Location::StackSlot(destination.GetStackIndex()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1329 | DataType::Type::kInt32, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1330 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1331 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1332 | DataType::Type::kInt32); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1333 | } |
| 1334 | } |
| 1335 | } |
| 1336 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1337 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1338 | DCHECK(location.IsRegister()); |
| 1339 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1340 | } |
| 1341 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1342 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1343 | HParallelMove move(GetGraph()->GetAllocator()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1344 | if (dst_type == DataType::Type::kInt64 && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1345 | move.AddMove(src.ToLow(), dst.ToLow(), DataType::Type::kInt32, nullptr); |
| 1346 | move.AddMove(src.ToHigh(), dst.ToHigh(), DataType::Type::kInt32, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1347 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1348 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1349 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1350 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1354 | if (location.IsRegister()) { |
| 1355 | locations->AddTemp(location); |
| 1356 | } else if (location.IsRegisterPair()) { |
| 1357 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1358 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1359 | } else { |
| 1360 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1361 | } |
| 1362 | } |
| 1363 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1364 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 1365 | if (successor->IsExitBlock()) { |
| 1366 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 1367 | return; // no code needed |
| 1368 | } |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1369 | |
| 1370 | HBasicBlock* block = got->GetBlock(); |
| 1371 | HInstruction* previous = got->GetPrevious(); |
| 1372 | |
| 1373 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1374 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1375 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1376 | __ pushl(EAX); |
| 1377 | __ movl(EAX, Address(ESP, kX86WordSize)); |
| 1378 | __ addw(Address(EAX, ArtMethod::HotnessCountOffset().Int32Value()), Immediate(1)); |
| 1379 | __ popl(EAX); |
| 1380 | } |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1381 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1382 | return; |
| 1383 | } |
| 1384 | |
| 1385 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1386 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1387 | } |
| 1388 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1389 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1390 | } |
| 1391 | } |
| 1392 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1393 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1394 | got->SetLocations(nullptr); |
| 1395 | } |
| 1396 | |
| 1397 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1398 | HandleGoto(got, got->GetSuccessor()); |
| 1399 | } |
| 1400 | |
| 1401 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1402 | try_boundary->SetLocations(nullptr); |
| 1403 | } |
| 1404 | |
| 1405 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1406 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1407 | if (!successor->IsExitBlock()) { |
| 1408 | HandleGoto(try_boundary, successor); |
| 1409 | } |
| 1410 | } |
| 1411 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1412 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1413 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1414 | } |
| 1415 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1416 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1417 | } |
| 1418 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1419 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1420 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1421 | LabelType* true_label, |
| 1422 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1423 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1424 | __ j(kUnordered, true_label); |
| 1425 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1426 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1427 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1428 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1429 | } |
| 1430 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1431 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1432 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1433 | LabelType* true_label, |
| 1434 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1435 | LocationSummary* locations = cond->GetLocations(); |
| 1436 | Location left = locations->InAt(0); |
| 1437 | Location right = locations->InAt(1); |
| 1438 | IfCondition if_cond = cond->GetCondition(); |
| 1439 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1440 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1441 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1442 | IfCondition true_high_cond = if_cond; |
| 1443 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1444 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1445 | |
| 1446 | // Set the conditions for the test, remembering that == needs to be |
| 1447 | // decided using the low words. |
| 1448 | switch (if_cond) { |
| 1449 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1450 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1451 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1452 | break; |
| 1453 | case kCondLT: |
| 1454 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1455 | break; |
| 1456 | case kCondLE: |
| 1457 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1458 | break; |
| 1459 | case kCondGT: |
| 1460 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1461 | break; |
| 1462 | case kCondGE: |
| 1463 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1464 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1465 | case kCondB: |
| 1466 | false_high_cond = kCondA; |
| 1467 | break; |
| 1468 | case kCondBE: |
| 1469 | true_high_cond = kCondB; |
| 1470 | break; |
| 1471 | case kCondA: |
| 1472 | false_high_cond = kCondB; |
| 1473 | break; |
| 1474 | case kCondAE: |
| 1475 | true_high_cond = kCondA; |
| 1476 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | if (right.IsConstant()) { |
| 1480 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1481 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1482 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1483 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1484 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1485 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1486 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1487 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1488 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1489 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1490 | __ j(X86Condition(true_high_cond), true_label); |
| 1491 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1492 | } |
| 1493 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1494 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1495 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1496 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1497 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1498 | |
| 1499 | __ cmpl(left_high, right_high); |
| 1500 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1501 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1502 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1503 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1504 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1505 | __ j(X86Condition(true_high_cond), true_label); |
| 1506 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1507 | } |
| 1508 | // Must be equal high, so compare the lows. |
| 1509 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1510 | } else { |
| 1511 | DCHECK(right.IsDoubleStackSlot()); |
| 1512 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1513 | if (if_cond == kCondNE) { |
| 1514 | __ j(X86Condition(true_high_cond), true_label); |
| 1515 | } else if (if_cond == kCondEQ) { |
| 1516 | __ j(X86Condition(false_high_cond), false_label); |
| 1517 | } else { |
| 1518 | __ j(X86Condition(true_high_cond), true_label); |
| 1519 | __ j(X86Condition(false_high_cond), false_label); |
| 1520 | } |
| 1521 | // Must be equal high, so compare the lows. |
| 1522 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1523 | } |
| 1524 | // The last comparison might be unsigned. |
| 1525 | __ j(final_condition, true_label); |
| 1526 | } |
| 1527 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1528 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1529 | Location rhs, |
| 1530 | HInstruction* insn, |
| 1531 | bool is_double) { |
| 1532 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1533 | if (is_double) { |
| 1534 | if (rhs.IsFpuRegister()) { |
| 1535 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1536 | } else if (const_area != nullptr) { |
| 1537 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1538 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1539 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1540 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1541 | const_area->GetBaseMethodAddress(), |
| 1542 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1543 | } else { |
| 1544 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1545 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1546 | } |
| 1547 | } else { |
| 1548 | if (rhs.IsFpuRegister()) { |
| 1549 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1550 | } else if (const_area != nullptr) { |
| 1551 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1552 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1553 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1554 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1555 | const_area->GetBaseMethodAddress(), |
| 1556 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1557 | } else { |
| 1558 | DCHECK(rhs.IsStackSlot()); |
| 1559 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1560 | } |
| 1561 | } |
| 1562 | } |
| 1563 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1564 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1565 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1566 | LabelType* true_target_in, |
| 1567 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1568 | // Generated branching requires both targets to be explicit. If either of the |
| 1569 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1570 | LabelType fallthrough_target; |
| 1571 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1572 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1573 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1574 | LocationSummary* locations = condition->GetLocations(); |
| 1575 | Location left = locations->InAt(0); |
| 1576 | Location right = locations->InAt(1); |
| 1577 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1578 | DataType::Type type = condition->InputAt(0)->GetType(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1579 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1580 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1581 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1582 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1583 | case DataType::Type::kFloat32: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1584 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1585 | GenerateFPJumps(condition, true_target, false_target); |
| 1586 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1587 | case DataType::Type::kFloat64: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1588 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1589 | GenerateFPJumps(condition, true_target, false_target); |
| 1590 | break; |
| 1591 | default: |
| 1592 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1593 | } |
| 1594 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1595 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1596 | __ jmp(false_target); |
| 1597 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1598 | |
| 1599 | if (fallthrough_target.IsLinked()) { |
| 1600 | __ Bind(&fallthrough_target); |
| 1601 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1602 | } |
| 1603 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1604 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1605 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1606 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1607 | // conditions if they are materialized due to the complex branching. |
| 1608 | return cond->IsCondition() && |
| 1609 | cond->GetNext() == branch && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1610 | cond->InputAt(0)->GetType() != DataType::Type::kInt64 && |
| 1611 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1612 | } |
| 1613 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1614 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1615 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1616 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1617 | LabelType* true_target, |
| 1618 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1619 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1620 | |
| 1621 | if (true_target == nullptr && false_target == nullptr) { |
| 1622 | // Nothing to do. The code always falls through. |
| 1623 | return; |
| 1624 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1625 | // Constant condition, statically compared against "true" (integer value 1). |
| 1626 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1627 | if (true_target != nullptr) { |
| 1628 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1629 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1630 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1631 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1632 | if (false_target != nullptr) { |
| 1633 | __ jmp(false_target); |
| 1634 | } |
| 1635 | } |
| 1636 | return; |
| 1637 | } |
| 1638 | |
| 1639 | // The following code generates these patterns: |
| 1640 | // (1) true_target == nullptr && false_target != nullptr |
| 1641 | // - opposite condition true => branch to false_target |
| 1642 | // (2) true_target != nullptr && false_target == nullptr |
| 1643 | // - condition true => branch to true_target |
| 1644 | // (3) true_target != nullptr && false_target != nullptr |
| 1645 | // - condition true => branch to true_target |
| 1646 | // - branch to false_target |
| 1647 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1648 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1649 | if (true_target == nullptr) { |
| 1650 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1651 | } else { |
| 1652 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1653 | } |
| 1654 | } else { |
| 1655 | // Materialized condition, compare against 0. |
| 1656 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1657 | if (lhs.IsRegister()) { |
| 1658 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1659 | } else { |
| 1660 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1661 | } |
| 1662 | if (true_target == nullptr) { |
| 1663 | __ j(kEqual, false_target); |
| 1664 | } else { |
| 1665 | __ j(kNotEqual, true_target); |
| 1666 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1667 | } |
| 1668 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1669 | // Condition has not been materialized, use its inputs as the comparison and |
| 1670 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1671 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1672 | |
| 1673 | // If this is a long or FP comparison that has been folded into |
| 1674 | // the HCondition, generate the comparison directly. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1675 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 1676 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1677 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1678 | return; |
| 1679 | } |
| 1680 | |
| 1681 | Location lhs = condition->GetLocations()->InAt(0); |
| 1682 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1683 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1684 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1685 | if (true_target == nullptr) { |
| 1686 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1687 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1688 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1689 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1690 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1691 | |
| 1692 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1693 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1694 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1695 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1696 | } |
| 1697 | } |
| 1698 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1699 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1700 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1701 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1702 | locations->SetInAt(0, Location::Any()); |
| 1703 | } |
| 1704 | } |
| 1705 | |
| 1706 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1707 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1708 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1709 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1710 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1711 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1712 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1713 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1717 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1718 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1719 | InvokeRuntimeCallingConvention calling_convention; |
| 1720 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1721 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1722 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1723 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1724 | locations->SetInAt(0, Location::Any()); |
| 1725 | } |
| 1726 | } |
| 1727 | |
| 1728 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1729 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1730 | GenerateTestAndBranch<Label>(deoptimize, |
| 1731 | /* condition_input_index */ 0, |
| 1732 | slow_path->GetEntryLabel(), |
| 1733 | /* false_target */ nullptr); |
| 1734 | } |
| 1735 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1736 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1737 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1738 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1739 | locations->SetOut(Location::RequiresRegister()); |
| 1740 | } |
| 1741 | |
| 1742 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1743 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), |
| 1744 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1745 | } |
| 1746 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1747 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1748 | // There are no conditional move instructions for XMMs. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1749 | if (DataType::IsFloatingPointType(select->GetType())) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1750 | return false; |
| 1751 | } |
| 1752 | |
| 1753 | // A FP condition doesn't generate the single CC that we need. |
| 1754 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1755 | HInstruction* condition = select->GetCondition(); |
| 1756 | if (condition->IsCondition()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1757 | DataType::Type compare_type = condition->InputAt(0)->GetType(); |
| 1758 | if (compare_type == DataType::Type::kInt64 || |
| 1759 | DataType::IsFloatingPointType(compare_type)) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1760 | return false; |
| 1761 | } |
| 1762 | } |
| 1763 | |
| 1764 | // We can generate a CMOV for this Select. |
| 1765 | return true; |
| 1766 | } |
| 1767 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1768 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1769 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1770 | if (DataType::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1771 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1772 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1773 | } else { |
| 1774 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1775 | if (SelectCanUseCMOV(select)) { |
| 1776 | if (select->InputAt(1)->IsConstant()) { |
| 1777 | // Cmov can't handle a constant value. |
| 1778 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1779 | } else { |
| 1780 | locations->SetInAt(1, Location::Any()); |
| 1781 | } |
| 1782 | } else { |
| 1783 | locations->SetInAt(1, Location::Any()); |
| 1784 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1785 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1786 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1787 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1788 | } |
| 1789 | locations->SetOut(Location::SameAsFirstInput()); |
| 1790 | } |
| 1791 | |
| 1792 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1793 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1794 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1795 | if (SelectCanUseCMOV(select)) { |
| 1796 | // If both the condition and the source types are integer, we can generate |
| 1797 | // a CMOV to implement Select. |
| 1798 | |
| 1799 | HInstruction* select_condition = select->GetCondition(); |
| 1800 | Condition cond = kNotEqual; |
| 1801 | |
| 1802 | // Figure out how to test the 'condition'. |
| 1803 | if (select_condition->IsCondition()) { |
| 1804 | HCondition* condition = select_condition->AsCondition(); |
| 1805 | if (!condition->IsEmittedAtUseSite()) { |
| 1806 | // This was a previously materialized condition. |
| 1807 | // Can we use the existing condition code? |
| 1808 | if (AreEflagsSetFrom(condition, select)) { |
| 1809 | // Materialization was the previous instruction. Condition codes are right. |
| 1810 | cond = X86Condition(condition->GetCondition()); |
| 1811 | } else { |
| 1812 | // No, we have to recreate the condition code. |
| 1813 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1814 | __ testl(cond_reg, cond_reg); |
| 1815 | } |
| 1816 | } else { |
| 1817 | // We can't handle FP or long here. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1818 | DCHECK_NE(condition->InputAt(0)->GetType(), DataType::Type::kInt64); |
| 1819 | DCHECK(!DataType::IsFloatingPointType(condition->InputAt(0)->GetType())); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1820 | LocationSummary* cond_locations = condition->GetLocations(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1821 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1822 | cond = X86Condition(condition->GetCondition()); |
| 1823 | } |
| 1824 | } else { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1825 | // Must be a Boolean condition, which needs to be compared to 0. |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1826 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1827 | __ testl(cond_reg, cond_reg); |
| 1828 | } |
| 1829 | |
| 1830 | // If the condition is true, overwrite the output, which already contains false. |
| 1831 | Location false_loc = locations->InAt(0); |
| 1832 | Location true_loc = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1833 | if (select->GetType() == DataType::Type::kInt64) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1834 | // 64 bit conditional move. |
| 1835 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1836 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1837 | if (true_loc.IsRegisterPair()) { |
| 1838 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1839 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1840 | } else { |
| 1841 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1842 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1843 | } |
| 1844 | } else { |
| 1845 | // 32 bit conditional move. |
| 1846 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1847 | if (true_loc.IsRegister()) { |
| 1848 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1849 | } else { |
| 1850 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1851 | } |
| 1852 | } |
| 1853 | } else { |
| 1854 | NearLabel false_target; |
| 1855 | GenerateTestAndBranch<NearLabel>( |
| 1856 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1857 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1858 | __ Bind(&false_target); |
| 1859 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1860 | } |
| 1861 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1862 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1863 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1864 | } |
| 1865 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1866 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1867 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1868 | } |
| 1869 | |
| 1870 | void CodeGeneratorX86::GenerateNop() { |
| 1871 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1872 | } |
| 1873 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1874 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1875 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1876 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1877 | // Handle the long/FP comparisons made in instruction simplification. |
| 1878 | switch (cond->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1879 | case DataType::Type::kInt64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1880 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1881 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1882 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1883 | locations->SetOut(Location::RequiresRegister()); |
| 1884 | } |
| 1885 | break; |
| 1886 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1887 | case DataType::Type::kFloat32: |
| 1888 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1889 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1890 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1891 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1892 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1893 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1894 | } else { |
| 1895 | locations->SetInAt(1, Location::Any()); |
| 1896 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1897 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1898 | locations->SetOut(Location::RequiresRegister()); |
| 1899 | } |
| 1900 | break; |
| 1901 | } |
| 1902 | default: |
| 1903 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1904 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1905 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1906 | // We need a byte register. |
| 1907 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1908 | } |
| 1909 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1910 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1911 | } |
| 1912 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1913 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1914 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1915 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1916 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1917 | |
| 1918 | LocationSummary* locations = cond->GetLocations(); |
| 1919 | Location lhs = locations->InAt(0); |
| 1920 | Location rhs = locations->InAt(1); |
| 1921 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1922 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1923 | |
| 1924 | switch (cond->InputAt(0)->GetType()) { |
| 1925 | default: { |
| 1926 | // Integer case. |
| 1927 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1928 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1929 | __ xorl(reg, reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1930 | codegen_->GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1931 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1932 | return; |
| 1933 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1934 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1935 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1936 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1937 | case DataType::Type::kFloat32: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1938 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1939 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1940 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1941 | case DataType::Type::kFloat64: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1942 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1943 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1944 | break; |
| 1945 | } |
| 1946 | |
| 1947 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1948 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1949 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1950 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1951 | __ Bind(&false_label); |
| 1952 | __ xorl(reg, reg); |
| 1953 | __ jmp(&done_label); |
| 1954 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1955 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1956 | __ Bind(&true_label); |
| 1957 | __ movl(reg, Immediate(1)); |
| 1958 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1962 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1966 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1970 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1974 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1978 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1979 | } |
| 1980 | |
| 1981 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1982 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1986 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1990 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1991 | } |
| 1992 | |
| 1993 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1994 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1995 | } |
| 1996 | |
| 1997 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1998 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2002 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2006 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2007 | } |
| 2008 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2009 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2010 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2014 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2015 | } |
| 2016 | |
| 2017 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2018 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2019 | } |
| 2020 | |
| 2021 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2022 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2023 | } |
| 2024 | |
| 2025 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2026 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2027 | } |
| 2028 | |
| 2029 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2030 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2031 | } |
| 2032 | |
| 2033 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2034 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2035 | } |
| 2036 | |
| 2037 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2038 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2039 | } |
| 2040 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2041 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2042 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2043 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2044 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2045 | } |
| 2046 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2047 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2048 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2049 | } |
| 2050 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2051 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 2052 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2053 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2054 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2055 | } |
| 2056 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2057 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2058 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2059 | } |
| 2060 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2061 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2062 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2063 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2064 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2065 | } |
| 2066 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2067 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2068 | // Will be generated at use site. |
| 2069 | } |
| 2070 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2071 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2072 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2073 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2074 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2075 | } |
| 2076 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2077 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2078 | // Will be generated at use site. |
| 2079 | } |
| 2080 | |
| 2081 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2082 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2083 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2084 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2085 | } |
| 2086 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2087 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2088 | // Will be generated at use site. |
| 2089 | } |
| 2090 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2091 | void LocationsBuilderX86::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2092 | constructor_fence->SetLocations(nullptr); |
| 2093 | } |
| 2094 | |
| 2095 | void InstructionCodeGeneratorX86::VisitConstructorFence( |
| 2096 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2097 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2098 | } |
| 2099 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2100 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2101 | memory_barrier->SetLocations(nullptr); |
| 2102 | } |
| 2103 | |
| 2104 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2105 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2106 | } |
| 2107 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2108 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2109 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2110 | } |
| 2111 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2112 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2113 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2114 | } |
| 2115 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2116 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2117 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2118 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2119 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2120 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2121 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2122 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2123 | case DataType::Type::kInt8: |
| 2124 | case DataType::Type::kUint16: |
| 2125 | case DataType::Type::kInt16: |
| 2126 | case DataType::Type::kInt32: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2127 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2128 | break; |
| 2129 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2130 | case DataType::Type::kInt64: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2131 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2132 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2133 | break; |
| 2134 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2135 | case DataType::Type::kFloat32: |
| 2136 | case DataType::Type::kFloat64: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2137 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2138 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2139 | break; |
| 2140 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2141 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2142 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2143 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2144 | } |
| 2145 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2146 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2147 | if (kIsDebugBuild) { |
| 2148 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2149 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2150 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2151 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2152 | case DataType::Type::kInt8: |
| 2153 | case DataType::Type::kUint16: |
| 2154 | case DataType::Type::kInt16: |
| 2155 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2156 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2157 | break; |
| 2158 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2159 | case DataType::Type::kInt64: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2160 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2161 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2162 | break; |
| 2163 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2164 | case DataType::Type::kFloat32: |
| 2165 | case DataType::Type::kFloat64: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2166 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2167 | break; |
| 2168 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2169 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2170 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2171 | } |
| 2172 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2173 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2174 | } |
| 2175 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2176 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2177 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2178 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2179 | // the method_idx. |
| 2180 | HandleInvoke(invoke); |
| 2181 | } |
| 2182 | |
| 2183 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2184 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2185 | } |
| 2186 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2187 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2188 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2189 | // art::PrepareForRegisterAllocation. |
| 2190 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2191 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2192 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2193 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 2194 | if (invoke->GetLocations()->CanCall() && |
| 2195 | invoke->HasPcRelativeMethodLoadKind() && |
| 2196 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).IsInvalid()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2197 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2198 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2199 | return; |
| 2200 | } |
| 2201 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2202 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2203 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2204 | // 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] | 2205 | if (invoke->HasPcRelativeMethodLoadKind()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2206 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2207 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2208 | } |
| 2209 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2210 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2211 | if (invoke->GetLocations()->Intrinsified()) { |
| 2212 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2213 | intrinsic.Dispatch(invoke); |
| 2214 | return true; |
| 2215 | } |
| 2216 | return false; |
| 2217 | } |
| 2218 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2219 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2220 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2221 | // art::PrepareForRegisterAllocation. |
| 2222 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2223 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2224 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2225 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2226 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2227 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2228 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2229 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2230 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2231 | } |
| 2232 | |
| 2233 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2234 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2235 | if (intrinsic.TryDispatch(invoke)) { |
| 2236 | return; |
| 2237 | } |
| 2238 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2239 | HandleInvoke(invoke); |
| 2240 | } |
| 2241 | |
| 2242 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2243 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2244 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2245 | } |
| 2246 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2247 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2248 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2249 | return; |
| 2250 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2251 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2252 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2253 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2254 | } |
| 2255 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2256 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2257 | // This call to HandleInvoke allocates a temporary (core) register |
| 2258 | // which is also used to transfer the hidden argument from FP to |
| 2259 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2260 | HandleInvoke(invoke); |
| 2261 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2262 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2263 | } |
| 2264 | |
| 2265 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2266 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2267 | LocationSummary* locations = invoke->GetLocations(); |
| 2268 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2269 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2270 | Location receiver = locations->InAt(0); |
| 2271 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2272 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2273 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2274 | // won't be modified thereafter, before the `call` instruction. |
| 2275 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2276 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2277 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2278 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2279 | if (receiver.IsStackSlot()) { |
| 2280 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2281 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2282 | __ movl(temp, Address(temp, class_offset)); |
| 2283 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2284 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2285 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2286 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2287 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2288 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2289 | // emit a read barrier for the previous class reference load. |
| 2290 | // However this is not required in practice, as this is an |
| 2291 | // intermediate/temporary reference and because the current |
| 2292 | // concurrent copying collector keeps the from-space memory |
| 2293 | // intact/accessible until the end of the marking phase (the |
| 2294 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2295 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2296 | // temp = temp->GetAddressOfIMT() |
| 2297 | __ movl(temp, |
| 2298 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2299 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2300 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2301 | invoke->GetImtIndex(), kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2302 | __ movl(temp, Address(temp, method_offset)); |
| 2303 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2304 | __ call(Address(temp, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2305 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2306 | |
| 2307 | DCHECK(!codegen_->IsLeafMethod()); |
| 2308 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2309 | } |
| 2310 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2311 | void LocationsBuilderX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2312 | HandleInvoke(invoke); |
| 2313 | } |
| 2314 | |
| 2315 | void InstructionCodeGeneratorX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2316 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2317 | } |
| 2318 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 2319 | void LocationsBuilderX86::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2320 | HandleInvoke(invoke); |
| 2321 | } |
| 2322 | |
| 2323 | void InstructionCodeGeneratorX86::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2324 | codegen_->GenerateInvokeCustomCall(invoke); |
| 2325 | } |
| 2326 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2327 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2328 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2329 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2330 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2331 | case DataType::Type::kInt32: |
| 2332 | case DataType::Type::kInt64: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2333 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2334 | locations->SetOut(Location::SameAsFirstInput()); |
| 2335 | break; |
| 2336 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2337 | case DataType::Type::kFloat32: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2338 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2339 | locations->SetOut(Location::SameAsFirstInput()); |
| 2340 | locations->AddTemp(Location::RequiresRegister()); |
| 2341 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2342 | break; |
| 2343 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2344 | case DataType::Type::kFloat64: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2345 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2346 | locations->SetOut(Location::SameAsFirstInput()); |
| 2347 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2348 | break; |
| 2349 | |
| 2350 | default: |
| 2351 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2352 | } |
| 2353 | } |
| 2354 | |
| 2355 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2356 | LocationSummary* locations = neg->GetLocations(); |
| 2357 | Location out = locations->Out(); |
| 2358 | Location in = locations->InAt(0); |
| 2359 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2360 | case DataType::Type::kInt32: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2361 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2362 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2363 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2364 | break; |
| 2365 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2366 | case DataType::Type::kInt64: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2367 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2368 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2369 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2370 | // Negation is similar to subtraction from zero. The least |
| 2371 | // significant byte triggers a borrow when it is different from |
| 2372 | // zero; to take it into account, add 1 to the most significant |
| 2373 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2374 | // operation. |
| 2375 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2376 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2377 | break; |
| 2378 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2379 | case DataType::Type::kFloat32: { |
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 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2382 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2383 | // Implement float negation with an exclusive or with value |
| 2384 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2385 | // single-precision floating-point number). |
| 2386 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2387 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2388 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2389 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2390 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2391 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2392 | case DataType::Type::kFloat64: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2393 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2394 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2395 | // Implement double negation with an exclusive or with value |
| 2396 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2397 | // a double-precision floating-point number). |
| 2398 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2399 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2400 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2401 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2402 | |
| 2403 | default: |
| 2404 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2405 | } |
| 2406 | } |
| 2407 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2408 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2409 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2410 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2411 | DCHECK(DataType::IsFloatingPointType(neg->GetType())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2412 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2413 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2414 | locations->SetOut(Location::SameAsFirstInput()); |
| 2415 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2416 | } |
| 2417 | |
| 2418 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2419 | LocationSummary* locations = neg->GetLocations(); |
| 2420 | Location out = locations->Out(); |
| 2421 | DCHECK(locations->InAt(0).Equals(out)); |
| 2422 | |
| 2423 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2424 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2425 | if (neg->GetType() == DataType::Type::kFloat32) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2426 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), |
| 2427 | neg->GetBaseMethodAddress(), |
| 2428 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2429 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2430 | } else { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2431 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), |
| 2432 | neg->GetBaseMethodAddress(), |
| 2433 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2434 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2435 | } |
| 2436 | } |
| 2437 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2438 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2439 | DataType::Type result_type = conversion->GetResultType(); |
| 2440 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2441 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2442 | << input_type << " -> " << result_type; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2443 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2444 | // The float-to-long and double-to-long type conversions rely on a |
| 2445 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2446 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2447 | ((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 2448 | && result_type == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2449 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2450 | : LocationSummary::kNoCall; |
| 2451 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2452 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2453 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2454 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2455 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2456 | case DataType::Type::kInt8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2457 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2458 | case DataType::Type::kUint8: |
| 2459 | case DataType::Type::kInt8: |
| 2460 | case DataType::Type::kUint16: |
| 2461 | case DataType::Type::kInt16: |
| 2462 | case DataType::Type::kInt32: |
| 2463 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2464 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2465 | // the validation of the linear scan implementation |
| 2466 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2467 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2468 | case DataType::Type::kInt64: { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2469 | HInstruction* input = conversion->InputAt(0); |
| 2470 | Location input_location = input->IsConstant() |
| 2471 | ? Location::ConstantLocation(input->AsConstant()) |
| 2472 | : Location::RegisterPairLocation(EAX, EDX); |
| 2473 | locations->SetInAt(0, input_location); |
| 2474 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2475 | // the validation of the linear scan implementation |
| 2476 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2477 | break; |
| 2478 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2479 | |
| 2480 | default: |
| 2481 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2482 | << " to " << result_type; |
| 2483 | } |
| 2484 | break; |
| 2485 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2486 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2487 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2488 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2489 | locations->SetInAt(0, Location::Any()); |
| 2490 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2491 | break; |
| 2492 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2493 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2494 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2495 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2496 | locations->SetInAt(0, Location::Any()); |
| 2497 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2498 | break; |
| 2499 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2500 | case DataType::Type::kFloat32: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2501 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2502 | locations->SetOut(Location::RequiresRegister()); |
| 2503 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2504 | break; |
| 2505 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2506 | case DataType::Type::kFloat64: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2507 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2508 | locations->SetOut(Location::RequiresRegister()); |
| 2509 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2510 | break; |
| 2511 | |
| 2512 | default: |
| 2513 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2514 | << " to " << result_type; |
| 2515 | } |
| 2516 | break; |
| 2517 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2518 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2519 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2520 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2521 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2522 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2523 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2524 | case DataType::Type::kInt16: |
| 2525 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2526 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2527 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2528 | break; |
| 2529 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2530 | case DataType::Type::kFloat32: |
| 2531 | case DataType::Type::kFloat64: { |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2532 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2533 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2534 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2535 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2536 | // The runtime helper puts the result in EAX, EDX. |
| 2537 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2538 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2539 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2540 | |
| 2541 | default: |
| 2542 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2543 | << " to " << result_type; |
| 2544 | } |
| 2545 | break; |
| 2546 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2547 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2548 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2549 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2550 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2551 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2552 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2553 | case DataType::Type::kInt16: |
| 2554 | case DataType::Type::kInt32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2555 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2556 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2557 | break; |
| 2558 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2559 | case DataType::Type::kInt64: |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2560 | locations->SetInAt(0, Location::Any()); |
| 2561 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2562 | break; |
| 2563 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2564 | case DataType::Type::kFloat64: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2565 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2566 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2567 | break; |
| 2568 | |
| 2569 | default: |
| 2570 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2571 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2572 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2573 | break; |
| 2574 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2575 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2576 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2577 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2578 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2579 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2580 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2581 | case DataType::Type::kInt16: |
| 2582 | case DataType::Type::kInt32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2583 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2584 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2585 | break; |
| 2586 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2587 | case DataType::Type::kInt64: |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2588 | locations->SetInAt(0, Location::Any()); |
| 2589 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2590 | break; |
| 2591 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2592 | case DataType::Type::kFloat32: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2593 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2594 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2595 | break; |
| 2596 | |
| 2597 | default: |
| 2598 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2599 | << " to " << result_type; |
| 2600 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2601 | break; |
| 2602 | |
| 2603 | default: |
| 2604 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2605 | << " to " << result_type; |
| 2606 | } |
| 2607 | } |
| 2608 | |
| 2609 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2610 | LocationSummary* locations = conversion->GetLocations(); |
| 2611 | Location out = locations->Out(); |
| 2612 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2613 | DataType::Type result_type = conversion->GetResultType(); |
| 2614 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2615 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2616 | << input_type << " -> " << result_type; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2617 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2618 | case DataType::Type::kUint8: |
| 2619 | switch (input_type) { |
| 2620 | case DataType::Type::kInt8: |
| 2621 | case DataType::Type::kUint16: |
| 2622 | case DataType::Type::kInt16: |
| 2623 | case DataType::Type::kInt32: |
| 2624 | if (in.IsRegister()) { |
| 2625 | __ movzxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2626 | } else { |
| 2627 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2628 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2629 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2630 | } |
| 2631 | break; |
| 2632 | case DataType::Type::kInt64: |
| 2633 | if (in.IsRegisterPair()) { |
| 2634 | __ movzxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2635 | } else { |
| 2636 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2637 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2638 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2639 | } |
| 2640 | break; |
| 2641 | |
| 2642 | default: |
| 2643 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2644 | << " to " << result_type; |
| 2645 | } |
| 2646 | break; |
| 2647 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2648 | case DataType::Type::kInt8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2649 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2650 | case DataType::Type::kUint8: |
| 2651 | case DataType::Type::kUint16: |
| 2652 | case DataType::Type::kInt16: |
| 2653 | case DataType::Type::kInt32: |
| 2654 | if (in.IsRegister()) { |
| 2655 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2656 | } else { |
| 2657 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2658 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2659 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2660 | } |
| 2661 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2662 | case DataType::Type::kInt64: |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2663 | if (in.IsRegisterPair()) { |
| 2664 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2665 | } else { |
| 2666 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2667 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2668 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2669 | } |
| 2670 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2671 | |
| 2672 | default: |
| 2673 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2674 | << " to " << result_type; |
| 2675 | } |
| 2676 | break; |
| 2677 | |
| 2678 | case DataType::Type::kUint16: |
| 2679 | switch (input_type) { |
| 2680 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2681 | case DataType::Type::kInt16: |
| 2682 | case DataType::Type::kInt32: |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2683 | if (in.IsRegister()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2684 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
| 2685 | } else if (in.IsStackSlot()) { |
| 2686 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2687 | } else { |
| 2688 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2689 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2690 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2691 | } |
| 2692 | break; |
| 2693 | case DataType::Type::kInt64: |
| 2694 | if (in.IsRegisterPair()) { |
| 2695 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2696 | } else if (in.IsDoubleStackSlot()) { |
| 2697 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2698 | } else { |
| 2699 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2700 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2701 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2702 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2703 | break; |
| 2704 | |
| 2705 | default: |
| 2706 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2707 | << " to " << result_type; |
| 2708 | } |
| 2709 | break; |
| 2710 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2711 | case DataType::Type::kInt16: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2712 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2713 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2714 | case DataType::Type::kInt32: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2715 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2716 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2717 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2718 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2719 | } else { |
| 2720 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2721 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2722 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2723 | } |
| 2724 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2725 | case DataType::Type::kInt64: |
| 2726 | if (in.IsRegisterPair()) { |
| 2727 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2728 | } else if (in.IsDoubleStackSlot()) { |
| 2729 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2730 | } else { |
| 2731 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2732 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2733 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2734 | } |
| 2735 | break; |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2736 | |
| 2737 | default: |
| 2738 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2739 | << " to " << result_type; |
| 2740 | } |
| 2741 | break; |
| 2742 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2743 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2744 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2745 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2746 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2747 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2748 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2749 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2750 | } else { |
| 2751 | DCHECK(in.IsConstant()); |
| 2752 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2753 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2754 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2755 | } |
| 2756 | break; |
| 2757 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2758 | case DataType::Type::kFloat32: { |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2759 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2760 | Register output = out.AsRegister<Register>(); |
| 2761 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2762 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2763 | |
| 2764 | __ movl(output, Immediate(kPrimIntMax)); |
| 2765 | // temp = int-to-float(output) |
| 2766 | __ cvtsi2ss(temp, output); |
| 2767 | // if input >= temp goto done |
| 2768 | __ comiss(input, temp); |
| 2769 | __ j(kAboveEqual, &done); |
| 2770 | // if input == NaN goto nan |
| 2771 | __ j(kUnordered, &nan); |
| 2772 | // output = float-to-int-truncate(input) |
| 2773 | __ cvttss2si(output, input); |
| 2774 | __ jmp(&done); |
| 2775 | __ Bind(&nan); |
| 2776 | // output = 0 |
| 2777 | __ xorl(output, output); |
| 2778 | __ Bind(&done); |
| 2779 | break; |
| 2780 | } |
| 2781 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2782 | case DataType::Type::kFloat64: { |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2783 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2784 | Register output = out.AsRegister<Register>(); |
| 2785 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2786 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2787 | |
| 2788 | __ movl(output, Immediate(kPrimIntMax)); |
| 2789 | // temp = int-to-double(output) |
| 2790 | __ cvtsi2sd(temp, output); |
| 2791 | // if input >= temp goto done |
| 2792 | __ comisd(input, temp); |
| 2793 | __ j(kAboveEqual, &done); |
| 2794 | // if input == NaN goto nan |
| 2795 | __ j(kUnordered, &nan); |
| 2796 | // output = double-to-int-truncate(input) |
| 2797 | __ cvttsd2si(output, input); |
| 2798 | __ jmp(&done); |
| 2799 | __ Bind(&nan); |
| 2800 | // output = 0 |
| 2801 | __ xorl(output, output); |
| 2802 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2803 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2804 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2805 | |
| 2806 | default: |
| 2807 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2808 | << " to " << result_type; |
| 2809 | } |
| 2810 | break; |
| 2811 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2812 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2813 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2814 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2815 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2816 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2817 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2818 | case DataType::Type::kInt16: |
| 2819 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2820 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2821 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2822 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2823 | __ cdq(); |
| 2824 | break; |
| 2825 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2826 | case DataType::Type::kFloat32: |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2827 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2828 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2829 | break; |
| 2830 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2831 | case DataType::Type::kFloat64: |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2832 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2833 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2834 | break; |
| 2835 | |
| 2836 | default: |
| 2837 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2838 | << " to " << result_type; |
| 2839 | } |
| 2840 | break; |
| 2841 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2842 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2843 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2844 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2845 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2846 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2847 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2848 | case DataType::Type::kInt16: |
| 2849 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2850 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2851 | break; |
| 2852 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2853 | case DataType::Type::kInt64: { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2854 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2855 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2856 | // Create stack space for the call to |
| 2857 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2858 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2859 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2860 | adjustment = DataType::Size(DataType::Type::kInt64); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2861 | __ subl(ESP, Immediate(adjustment)); |
| 2862 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2863 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2864 | // Load the value to the FP stack, using temporaries if needed. |
| 2865 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2866 | |
| 2867 | if (out.IsStackSlot()) { |
| 2868 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2869 | } else { |
| 2870 | __ fstps(Address(ESP, 0)); |
| 2871 | Location stack_temp = Location::StackSlot(0); |
| 2872 | codegen_->Move32(out, stack_temp); |
| 2873 | } |
| 2874 | |
| 2875 | // Remove the temporary stack space we allocated. |
| 2876 | if (adjustment != 0) { |
| 2877 | __ addl(ESP, Immediate(adjustment)); |
| 2878 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2879 | break; |
| 2880 | } |
| 2881 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2882 | case DataType::Type::kFloat64: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2883 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2884 | break; |
| 2885 | |
| 2886 | default: |
| 2887 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2888 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2889 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2890 | break; |
| 2891 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2892 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2893 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2894 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2895 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2896 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2897 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2898 | case DataType::Type::kInt16: |
| 2899 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2900 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2901 | break; |
| 2902 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2903 | case DataType::Type::kInt64: { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2904 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2905 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2906 | // Create stack space for the call to |
| 2907 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2908 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2909 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2910 | adjustment = DataType::Size(DataType::Type::kInt64); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2911 | __ subl(ESP, Immediate(adjustment)); |
| 2912 | } |
| 2913 | |
| 2914 | // Load the value to the FP stack, using temporaries if needed. |
| 2915 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2916 | |
| 2917 | if (out.IsDoubleStackSlot()) { |
| 2918 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2919 | } else { |
| 2920 | __ fstpl(Address(ESP, 0)); |
| 2921 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2922 | codegen_->Move64(out, stack_temp); |
| 2923 | } |
| 2924 | |
| 2925 | // Remove the temporary stack space we allocated. |
| 2926 | if (adjustment != 0) { |
| 2927 | __ addl(ESP, Immediate(adjustment)); |
| 2928 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2929 | break; |
| 2930 | } |
| 2931 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2932 | case DataType::Type::kFloat32: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2933 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2934 | break; |
| 2935 | |
| 2936 | default: |
| 2937 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2938 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2939 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2940 | break; |
| 2941 | |
| 2942 | default: |
| 2943 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2944 | << " to " << result_type; |
| 2945 | } |
| 2946 | } |
| 2947 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2948 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2949 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2950 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2951 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2952 | case DataType::Type::kInt32: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2953 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2954 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2955 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2956 | break; |
| 2957 | } |
| 2958 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2959 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2960 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2961 | locations->SetInAt(1, Location::Any()); |
| 2962 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2963 | break; |
| 2964 | } |
| 2965 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2966 | case DataType::Type::kFloat32: |
| 2967 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2968 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2969 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2970 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2971 | } else if (add->InputAt(1)->IsConstant()) { |
| 2972 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2973 | } else { |
| 2974 | locations->SetInAt(1, Location::Any()); |
| 2975 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2976 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2977 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2978 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2979 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2980 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2981 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2982 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2983 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2987 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2988 | Location first = locations->InAt(0); |
| 2989 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2990 | Location out = locations->Out(); |
| 2991 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2992 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2993 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2994 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2995 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2996 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2997 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2998 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2999 | } else { |
| 3000 | __ leal(out.AsRegister<Register>(), Address( |
| 3001 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 3002 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3003 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3004 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3005 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3006 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 3007 | } else { |
| 3008 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 3009 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3010 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3011 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3012 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3013 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3014 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3015 | } |
| 3016 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3017 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3018 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3019 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3020 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3021 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3022 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 3023 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3024 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3025 | } else { |
| 3026 | DCHECK(second.IsConstant()) << second; |
| 3027 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3028 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3029 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3030 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3031 | break; |
| 3032 | } |
| 3033 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3034 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3035 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3036 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3037 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3038 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3039 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3040 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3041 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3042 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3043 | const_area->GetBaseMethodAddress(), |
| 3044 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3045 | } else { |
| 3046 | DCHECK(second.IsStackSlot()); |
| 3047 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3048 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3049 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3050 | } |
| 3051 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3052 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3053 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3054 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3055 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3056 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3057 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3058 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3059 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3060 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3061 | const_area->GetBaseMethodAddress(), |
| 3062 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3063 | } else { |
| 3064 | DCHECK(second.IsDoubleStackSlot()); |
| 3065 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3066 | } |
| 3067 | break; |
| 3068 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3069 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3070 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3071 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3072 | } |
| 3073 | } |
| 3074 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3075 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3076 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3077 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3078 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3079 | case DataType::Type::kInt32: |
| 3080 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3081 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3082 | locations->SetInAt(1, Location::Any()); |
| 3083 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3084 | break; |
| 3085 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3086 | case DataType::Type::kFloat32: |
| 3087 | case DataType::Type::kFloat64: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3088 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3089 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3090 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3091 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3092 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3093 | } else { |
| 3094 | locations->SetInAt(1, Location::Any()); |
| 3095 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3096 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3097 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3098 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3099 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3100 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3101 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3102 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3103 | } |
| 3104 | |
| 3105 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3106 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3107 | Location first = locations->InAt(0); |
| 3108 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3109 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3110 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3111 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3112 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3113 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3114 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3115 | __ subl(first.AsRegister<Register>(), |
| 3116 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3117 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3118 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3119 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3120 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3121 | } |
| 3122 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3123 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3124 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3125 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3126 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3127 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3128 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3129 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3130 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3131 | } else { |
| 3132 | DCHECK(second.IsConstant()) << second; |
| 3133 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3134 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3135 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3136 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3137 | break; |
| 3138 | } |
| 3139 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3140 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3141 | if (second.IsFpuRegister()) { |
| 3142 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3143 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3144 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3145 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3146 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3147 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3148 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3149 | const_area->GetBaseMethodAddress(), |
| 3150 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3151 | } else { |
| 3152 | DCHECK(second.IsStackSlot()); |
| 3153 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3154 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3155 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3156 | } |
| 3157 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3158 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3159 | if (second.IsFpuRegister()) { |
| 3160 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3161 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3162 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3163 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3164 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3165 | codegen_->LiteralDoubleAddress( |
| 3166 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3167 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3168 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3169 | } else { |
| 3170 | DCHECK(second.IsDoubleStackSlot()); |
| 3171 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3172 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3173 | break; |
| 3174 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3175 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3176 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3177 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3178 | } |
| 3179 | } |
| 3180 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3181 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3182 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3183 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3184 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3185 | case DataType::Type::kInt32: |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3186 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3187 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3188 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3189 | // Can use 3 operand multiply. |
| 3190 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3191 | } else { |
| 3192 | locations->SetOut(Location::SameAsFirstInput()); |
| 3193 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3194 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3195 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3196 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3197 | locations->SetInAt(1, Location::Any()); |
| 3198 | locations->SetOut(Location::SameAsFirstInput()); |
| 3199 | // Needed for imul on 32bits with 64bits output. |
| 3200 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3201 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3202 | break; |
| 3203 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3204 | case DataType::Type::kFloat32: |
| 3205 | case DataType::Type::kFloat64: { |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3206 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3207 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3208 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3209 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3210 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3211 | } else { |
| 3212 | locations->SetInAt(1, Location::Any()); |
| 3213 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3214 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3215 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3216 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3217 | |
| 3218 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3219 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3220 | } |
| 3221 | } |
| 3222 | |
| 3223 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3224 | LocationSummary* locations = mul->GetLocations(); |
| 3225 | Location first = locations->InAt(0); |
| 3226 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3227 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3228 | |
| 3229 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3230 | case DataType::Type::kInt32: |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3231 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3232 | // problems where the output may not be the same as the first operand. |
| 3233 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3234 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3235 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3236 | } else if (second.IsRegister()) { |
| 3237 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3238 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3239 | } else { |
| 3240 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3241 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3242 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3243 | } |
| 3244 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3245 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3246 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3247 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3248 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3249 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3250 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3251 | |
| 3252 | DCHECK_EQ(EAX, eax); |
| 3253 | DCHECK_EQ(EDX, edx); |
| 3254 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3255 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3256 | // output: in1 |
| 3257 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3258 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3259 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3260 | if (second.IsConstant()) { |
| 3261 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3262 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3263 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3264 | int32_t low_value = Low32Bits(value); |
| 3265 | int32_t high_value = High32Bits(value); |
| 3266 | Immediate low(low_value); |
| 3267 | Immediate high(high_value); |
| 3268 | |
| 3269 | __ movl(eax, high); |
| 3270 | // eax <- in1.lo * in2.hi |
| 3271 | __ imull(eax, in1_lo); |
| 3272 | // in1.hi <- in1.hi * in2.lo |
| 3273 | __ imull(in1_hi, low); |
| 3274 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3275 | __ addl(in1_hi, eax); |
| 3276 | // move in2_lo to eax to prepare for double precision |
| 3277 | __ movl(eax, low); |
| 3278 | // edx:eax <- in1.lo * in2.lo |
| 3279 | __ mull(in1_lo); |
| 3280 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3281 | __ addl(in1_hi, edx); |
| 3282 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3283 | __ movl(in1_lo, eax); |
| 3284 | } else if (second.IsRegisterPair()) { |
| 3285 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3286 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3287 | |
| 3288 | __ movl(eax, in2_hi); |
| 3289 | // eax <- in1.lo * in2.hi |
| 3290 | __ imull(eax, in1_lo); |
| 3291 | // in1.hi <- in1.hi * in2.lo |
| 3292 | __ imull(in1_hi, in2_lo); |
| 3293 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3294 | __ addl(in1_hi, eax); |
| 3295 | // move in1_lo to eax to prepare for double precision |
| 3296 | __ movl(eax, in1_lo); |
| 3297 | // edx:eax <- in1.lo * in2.lo |
| 3298 | __ mull(in2_lo); |
| 3299 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3300 | __ addl(in1_hi, edx); |
| 3301 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3302 | __ movl(in1_lo, eax); |
| 3303 | } else { |
| 3304 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3305 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3306 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3307 | |
| 3308 | __ movl(eax, in2_hi); |
| 3309 | // eax <- in1.lo * in2.hi |
| 3310 | __ imull(eax, in1_lo); |
| 3311 | // in1.hi <- in1.hi * in2.lo |
| 3312 | __ imull(in1_hi, in2_lo); |
| 3313 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3314 | __ addl(in1_hi, eax); |
| 3315 | // move in1_lo to eax to prepare for double precision |
| 3316 | __ movl(eax, in1_lo); |
| 3317 | // edx:eax <- in1.lo * in2.lo |
| 3318 | __ mull(in2_lo); |
| 3319 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3320 | __ addl(in1_hi, edx); |
| 3321 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3322 | __ movl(in1_lo, eax); |
| 3323 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3324 | |
| 3325 | break; |
| 3326 | } |
| 3327 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3328 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3329 | DCHECK(first.Equals(locations->Out())); |
| 3330 | if (second.IsFpuRegister()) { |
| 3331 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3332 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3333 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3334 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3335 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3336 | codegen_->LiteralFloatAddress( |
| 3337 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3338 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3339 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3340 | } else { |
| 3341 | DCHECK(second.IsStackSlot()); |
| 3342 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3343 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3344 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3345 | } |
| 3346 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3347 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3348 | DCHECK(first.Equals(locations->Out())); |
| 3349 | if (second.IsFpuRegister()) { |
| 3350 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3351 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3352 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3353 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3354 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3355 | codegen_->LiteralDoubleAddress( |
| 3356 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3357 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3358 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3359 | } else { |
| 3360 | DCHECK(second.IsDoubleStackSlot()); |
| 3361 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3362 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3363 | break; |
| 3364 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3365 | |
| 3366 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3367 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3368 | } |
| 3369 | } |
| 3370 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3371 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3372 | uint32_t temp_offset, |
| 3373 | uint32_t stack_adjustment, |
| 3374 | bool is_fp, |
| 3375 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3376 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3377 | DCHECK(!is_wide); |
| 3378 | if (is_fp) { |
| 3379 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3380 | } else { |
| 3381 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3382 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3383 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3384 | DCHECK(is_wide); |
| 3385 | if (is_fp) { |
| 3386 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3387 | } else { |
| 3388 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3389 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3390 | } else { |
| 3391 | // 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] | 3392 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3393 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3394 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3395 | if (is_fp) { |
| 3396 | __ flds(Address(ESP, temp_offset)); |
| 3397 | } else { |
| 3398 | __ filds(Address(ESP, temp_offset)); |
| 3399 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3400 | } else { |
| 3401 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3402 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3403 | if (is_fp) { |
| 3404 | __ fldl(Address(ESP, temp_offset)); |
| 3405 | } else { |
| 3406 | __ fildl(Address(ESP, temp_offset)); |
| 3407 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3408 | } |
| 3409 | } |
| 3410 | } |
| 3411 | |
| 3412 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3413 | DataType::Type type = rem->GetResultType(); |
| 3414 | bool is_float = type == DataType::Type::kFloat32; |
| 3415 | size_t elem_size = DataType::Size(type); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3416 | LocationSummary* locations = rem->GetLocations(); |
| 3417 | Location first = locations->InAt(0); |
| 3418 | Location second = locations->InAt(1); |
| 3419 | Location out = locations->Out(); |
| 3420 | |
| 3421 | // Create stack space for 2 elements. |
| 3422 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3423 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3424 | |
| 3425 | // 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] | 3426 | const bool is_wide = !is_float; |
| 3427 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3428 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3429 | |
| 3430 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3431 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3432 | __ Bind(&retry); |
| 3433 | __ fprem(); |
| 3434 | |
| 3435 | // Move FP status to AX. |
| 3436 | __ fstsw(); |
| 3437 | |
| 3438 | // And see if the argument reduction is complete. This is signaled by the |
| 3439 | // C2 FPU flag bit set to 0. |
| 3440 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3441 | __ j(kNotEqual, &retry); |
| 3442 | |
| 3443 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3444 | // Store FP top of stack to real stack. |
| 3445 | if (is_float) { |
| 3446 | __ fsts(Address(ESP, 0)); |
| 3447 | } else { |
| 3448 | __ fstl(Address(ESP, 0)); |
| 3449 | } |
| 3450 | |
| 3451 | // Pop the 2 items from the FP stack. |
| 3452 | __ fucompp(); |
| 3453 | |
| 3454 | // Load the value from the stack into an XMM register. |
| 3455 | DCHECK(out.IsFpuRegister()) << out; |
| 3456 | if (is_float) { |
| 3457 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3458 | } else { |
| 3459 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3460 | } |
| 3461 | |
| 3462 | // And remove the temporary stack space we allocated. |
| 3463 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3464 | } |
| 3465 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3466 | |
| 3467 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3468 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3469 | |
| 3470 | LocationSummary* locations = instruction->GetLocations(); |
| 3471 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3472 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3473 | |
| 3474 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3475 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3476 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3477 | |
| 3478 | DCHECK(imm == 1 || imm == -1); |
| 3479 | |
| 3480 | if (instruction->IsRem()) { |
| 3481 | __ xorl(out_register, out_register); |
| 3482 | } else { |
| 3483 | __ movl(out_register, input_register); |
| 3484 | if (imm == -1) { |
| 3485 | __ negl(out_register); |
| 3486 | } |
| 3487 | } |
| 3488 | } |
| 3489 | |
| 3490 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3491 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3492 | LocationSummary* locations = instruction->GetLocations(); |
| 3493 | |
| 3494 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3495 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3496 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3497 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3498 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3499 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3500 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3501 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3502 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3503 | __ testl(input_register, input_register); |
| 3504 | __ cmovl(kGreaterEqual, num, input_register); |
| 3505 | int shift = CTZ(imm); |
| 3506 | __ sarl(num, Immediate(shift)); |
| 3507 | |
| 3508 | if (imm < 0) { |
| 3509 | __ negl(num); |
| 3510 | } |
| 3511 | |
| 3512 | __ movl(out_register, num); |
| 3513 | } |
| 3514 | |
| 3515 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3516 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3517 | |
| 3518 | LocationSummary* locations = instruction->GetLocations(); |
| 3519 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3520 | |
| 3521 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3522 | Register out = locations->Out().AsRegister<Register>(); |
| 3523 | Register num; |
| 3524 | Register edx; |
| 3525 | |
| 3526 | if (instruction->IsDiv()) { |
| 3527 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3528 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3529 | } else { |
| 3530 | edx = locations->Out().AsRegister<Register>(); |
| 3531 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3532 | } |
| 3533 | |
| 3534 | DCHECK_EQ(EAX, eax); |
| 3535 | DCHECK_EQ(EDX, edx); |
| 3536 | if (instruction->IsDiv()) { |
| 3537 | DCHECK_EQ(EAX, out); |
| 3538 | } else { |
| 3539 | DCHECK_EQ(EDX, out); |
| 3540 | } |
| 3541 | |
| 3542 | int64_t magic; |
| 3543 | int shift; |
| 3544 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3545 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3546 | // Save the numerator. |
| 3547 | __ movl(num, eax); |
| 3548 | |
| 3549 | // EAX = magic |
| 3550 | __ movl(eax, Immediate(magic)); |
| 3551 | |
| 3552 | // EDX:EAX = magic * numerator |
| 3553 | __ imull(num); |
| 3554 | |
| 3555 | if (imm > 0 && magic < 0) { |
| 3556 | // EDX += num |
| 3557 | __ addl(edx, num); |
| 3558 | } else if (imm < 0 && magic > 0) { |
| 3559 | __ subl(edx, num); |
| 3560 | } |
| 3561 | |
| 3562 | // Shift if needed. |
| 3563 | if (shift != 0) { |
| 3564 | __ sarl(edx, Immediate(shift)); |
| 3565 | } |
| 3566 | |
| 3567 | // EDX += 1 if EDX < 0 |
| 3568 | __ movl(eax, edx); |
| 3569 | __ shrl(edx, Immediate(31)); |
| 3570 | __ addl(edx, eax); |
| 3571 | |
| 3572 | if (instruction->IsRem()) { |
| 3573 | __ movl(eax, num); |
| 3574 | __ imull(edx, Immediate(imm)); |
| 3575 | __ subl(eax, edx); |
| 3576 | __ movl(edx, eax); |
| 3577 | } else { |
| 3578 | __ movl(eax, edx); |
| 3579 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3580 | } |
| 3581 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3582 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3583 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3584 | |
| 3585 | LocationSummary* locations = instruction->GetLocations(); |
| 3586 | Location out = locations->Out(); |
| 3587 | Location first = locations->InAt(0); |
| 3588 | Location second = locations->InAt(1); |
| 3589 | bool is_div = instruction->IsDiv(); |
| 3590 | |
| 3591 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3592 | case DataType::Type::kInt32: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3593 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3594 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3595 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3596 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3597 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3598 | |
| 3599 | if (imm == 0) { |
| 3600 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3601 | } else if (imm == 1 || imm == -1) { |
| 3602 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3603 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3604 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3605 | } else { |
| 3606 | DCHECK(imm <= -2 || imm >= 2); |
| 3607 | GenerateDivRemWithAnyConstant(instruction); |
| 3608 | } |
| 3609 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3610 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3611 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3612 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3613 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3614 | Register second_reg = second.AsRegister<Register>(); |
| 3615 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3616 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3617 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3618 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3619 | __ cmpl(second_reg, Immediate(-1)); |
| 3620 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3621 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3622 | // edx:eax <- sign-extended of eax |
| 3623 | __ cdq(); |
| 3624 | // eax = quotient, edx = remainder |
| 3625 | __ idivl(second_reg); |
| 3626 | __ Bind(slow_path->GetExitLabel()); |
| 3627 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3628 | break; |
| 3629 | } |
| 3630 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3631 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3632 | InvokeRuntimeCallingConvention calling_convention; |
| 3633 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3634 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3635 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3636 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3637 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3638 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3639 | |
| 3640 | if (is_div) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3641 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3642 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3643 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3644 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3645 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3646 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3647 | break; |
| 3648 | } |
| 3649 | |
| 3650 | default: |
| 3651 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3652 | } |
| 3653 | } |
| 3654 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3655 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3656 | LocationSummary::CallKind call_kind = (div->GetResultType() == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3657 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3658 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3659 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3660 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3661 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3662 | case DataType::Type::kInt32: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3663 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3664 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3665 | locations->SetOut(Location::SameAsFirstInput()); |
| 3666 | // Intel uses edx:eax as the dividend. |
| 3667 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3668 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3669 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3670 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3671 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3672 | locations->AddTemp(Location::RequiresRegister()); |
| 3673 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3674 | break; |
| 3675 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3676 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3677 | InvokeRuntimeCallingConvention calling_convention; |
| 3678 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3679 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3680 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3681 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3682 | // Runtime helper puts the result in EAX, EDX. |
| 3683 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3684 | break; |
| 3685 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3686 | case DataType::Type::kFloat32: |
| 3687 | case DataType::Type::kFloat64: { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3688 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3689 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3690 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3691 | } else if (div->InputAt(1)->IsConstant()) { |
| 3692 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3693 | } else { |
| 3694 | locations->SetInAt(1, Location::Any()); |
| 3695 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3696 | locations->SetOut(Location::SameAsFirstInput()); |
| 3697 | break; |
| 3698 | } |
| 3699 | |
| 3700 | default: |
| 3701 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3702 | } |
| 3703 | } |
| 3704 | |
| 3705 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3706 | LocationSummary* locations = div->GetLocations(); |
| 3707 | Location first = locations->InAt(0); |
| 3708 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3709 | |
| 3710 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3711 | case DataType::Type::kInt32: |
| 3712 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3713 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3714 | break; |
| 3715 | } |
| 3716 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3717 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3718 | if (second.IsFpuRegister()) { |
| 3719 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3720 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3721 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3722 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3723 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3724 | codegen_->LiteralFloatAddress( |
| 3725 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3726 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3727 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3728 | } else { |
| 3729 | DCHECK(second.IsStackSlot()); |
| 3730 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3731 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3732 | break; |
| 3733 | } |
| 3734 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3735 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3736 | if (second.IsFpuRegister()) { |
| 3737 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3738 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3739 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3740 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3741 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3742 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3743 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3744 | const_area->GetBaseMethodAddress(), |
| 3745 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3746 | } else { |
| 3747 | DCHECK(second.IsDoubleStackSlot()); |
| 3748 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3749 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3750 | break; |
| 3751 | } |
| 3752 | |
| 3753 | default: |
| 3754 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3755 | } |
| 3756 | } |
| 3757 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3758 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3759 | DataType::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3760 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3761 | LocationSummary::CallKind call_kind = (rem->GetResultType() == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3762 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3763 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3764 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3765 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3766 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3767 | case DataType::Type::kInt32: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3768 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3769 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3770 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3771 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3772 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3773 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3774 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3775 | locations->AddTemp(Location::RequiresRegister()); |
| 3776 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3777 | break; |
| 3778 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3779 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3780 | InvokeRuntimeCallingConvention calling_convention; |
| 3781 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3782 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3783 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3784 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3785 | // Runtime helper puts the result in EAX, EDX. |
| 3786 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3787 | break; |
| 3788 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3789 | case DataType::Type::kFloat64: |
| 3790 | case DataType::Type::kFloat32: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3791 | locations->SetInAt(0, Location::Any()); |
| 3792 | locations->SetInAt(1, Location::Any()); |
| 3793 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3794 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3795 | break; |
| 3796 | } |
| 3797 | |
| 3798 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3799 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3800 | } |
| 3801 | } |
| 3802 | |
| 3803 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3804 | DataType::Type type = rem->GetResultType(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3805 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3806 | case DataType::Type::kInt32: |
| 3807 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3808 | GenerateDivRemIntegral(rem); |
| 3809 | break; |
| 3810 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3811 | case DataType::Type::kFloat32: |
| 3812 | case DataType::Type::kFloat64: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3813 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3814 | break; |
| 3815 | } |
| 3816 | default: |
| 3817 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3818 | } |
| 3819 | } |
| 3820 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 3821 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 3822 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 3823 | switch (minmax->GetResultType()) { |
| 3824 | case DataType::Type::kInt32: |
| 3825 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3826 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3827 | locations->SetOut(Location::SameAsFirstInput()); |
| 3828 | break; |
| 3829 | case DataType::Type::kInt64: |
| 3830 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3831 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3832 | locations->SetOut(Location::SameAsFirstInput()); |
| 3833 | // Register to use to perform a long subtract to set cc. |
| 3834 | locations->AddTemp(Location::RequiresRegister()); |
| 3835 | break; |
| 3836 | case DataType::Type::kFloat32: |
| 3837 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3838 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3839 | locations->SetOut(Location::SameAsFirstInput()); |
| 3840 | locations->AddTemp(Location::RequiresRegister()); |
| 3841 | break; |
| 3842 | case DataType::Type::kFloat64: |
| 3843 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3844 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3845 | locations->SetOut(Location::SameAsFirstInput()); |
| 3846 | break; |
| 3847 | default: |
| 3848 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 3849 | } |
| 3850 | } |
| 3851 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 3852 | void InstructionCodeGeneratorX86::GenerateMinMaxInt(LocationSummary* locations, |
| 3853 | bool is_min, |
| 3854 | DataType::Type type) { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 3855 | Location op1_loc = locations->InAt(0); |
| 3856 | Location op2_loc = locations->InAt(1); |
| 3857 | |
| 3858 | // Shortcut for same input locations. |
| 3859 | if (op1_loc.Equals(op2_loc)) { |
| 3860 | // Can return immediately, as op1_loc == out_loc. |
| 3861 | // Note: if we ever support separate registers, e.g., output into memory, we need to check for |
| 3862 | // a copy here. |
| 3863 | DCHECK(locations->Out().Equals(op1_loc)); |
| 3864 | return; |
| 3865 | } |
| 3866 | |
| 3867 | if (type == DataType::Type::kInt64) { |
| 3868 | // Need to perform a subtract to get the sign right. |
| 3869 | // op1 is already in the same location as the output. |
| 3870 | Location output = locations->Out(); |
| 3871 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 3872 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 3873 | |
| 3874 | Register op2_lo = op2_loc.AsRegisterPairLow<Register>(); |
| 3875 | Register op2_hi = op2_loc.AsRegisterPairHigh<Register>(); |
| 3876 | |
| 3877 | // The comparison is performed by subtracting the second operand from |
| 3878 | // the first operand and then setting the status flags in the same |
| 3879 | // manner as the SUB instruction." |
| 3880 | __ cmpl(output_lo, op2_lo); |
| 3881 | |
| 3882 | // Now use a temp and the borrow to finish the subtraction of op2_hi. |
| 3883 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3884 | __ movl(temp, output_hi); |
| 3885 | __ sbbl(temp, op2_hi); |
| 3886 | |
| 3887 | // Now the condition code is correct. |
| 3888 | Condition cond = is_min ? Condition::kGreaterEqual : Condition::kLess; |
| 3889 | __ cmovl(cond, output_lo, op2_lo); |
| 3890 | __ cmovl(cond, output_hi, op2_hi); |
| 3891 | } else { |
| 3892 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 3893 | Register out = locations->Out().AsRegister<Register>(); |
| 3894 | Register op2 = op2_loc.AsRegister<Register>(); |
| 3895 | |
| 3896 | // (out := op1) |
| 3897 | // out <=? op2 |
| 3898 | // if out is min jmp done |
| 3899 | // out := op2 |
| 3900 | // done: |
| 3901 | |
| 3902 | __ cmpl(out, op2); |
| 3903 | Condition cond = is_min ? Condition::kGreater : Condition::kLess; |
| 3904 | __ cmovl(cond, out, op2); |
| 3905 | } |
| 3906 | } |
| 3907 | |
| 3908 | void InstructionCodeGeneratorX86::GenerateMinMaxFP(LocationSummary* locations, |
| 3909 | bool is_min, |
| 3910 | DataType::Type type) { |
| 3911 | Location op1_loc = locations->InAt(0); |
| 3912 | Location op2_loc = locations->InAt(1); |
| 3913 | Location out_loc = locations->Out(); |
| 3914 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| 3915 | |
| 3916 | // Shortcut for same input locations. |
| 3917 | if (op1_loc.Equals(op2_loc)) { |
| 3918 | DCHECK(out_loc.Equals(op1_loc)); |
| 3919 | return; |
| 3920 | } |
| 3921 | |
| 3922 | // (out := op1) |
| 3923 | // out <=? op2 |
| 3924 | // if Nan jmp Nan_label |
| 3925 | // if out is min jmp done |
| 3926 | // if op2 is min jmp op2_label |
| 3927 | // handle -0/+0 |
| 3928 | // jmp done |
| 3929 | // Nan_label: |
| 3930 | // out := NaN |
| 3931 | // op2_label: |
| 3932 | // out := op2 |
| 3933 | // done: |
| 3934 | // |
| 3935 | // This removes one jmp, but needs to copy one input (op1) to out. |
| 3936 | // |
| 3937 | // TODO: This is straight from Quick (except literal pool). Make NaN an out-of-line slowpath? |
| 3938 | |
| 3939 | XmmRegister op2 = op2_loc.AsFpuRegister<XmmRegister>(); |
| 3940 | |
| 3941 | NearLabel nan, done, op2_label; |
| 3942 | if (type == DataType::Type::kFloat64) { |
| 3943 | __ ucomisd(out, op2); |
| 3944 | } else { |
| 3945 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 3946 | __ ucomiss(out, op2); |
| 3947 | } |
| 3948 | |
| 3949 | __ j(Condition::kParityEven, &nan); |
| 3950 | |
| 3951 | __ j(is_min ? Condition::kAbove : Condition::kBelow, &op2_label); |
| 3952 | __ j(is_min ? Condition::kBelow : Condition::kAbove, &done); |
| 3953 | |
| 3954 | // Handle 0.0/-0.0. |
| 3955 | if (is_min) { |
| 3956 | if (type == DataType::Type::kFloat64) { |
| 3957 | __ orpd(out, op2); |
| 3958 | } else { |
| 3959 | __ orps(out, op2); |
| 3960 | } |
| 3961 | } else { |
| 3962 | if (type == DataType::Type::kFloat64) { |
| 3963 | __ andpd(out, op2); |
| 3964 | } else { |
| 3965 | __ andps(out, op2); |
| 3966 | } |
| 3967 | } |
| 3968 | __ jmp(&done); |
| 3969 | |
| 3970 | // NaN handling. |
| 3971 | __ Bind(&nan); |
| 3972 | if (type == DataType::Type::kFloat64) { |
| 3973 | // TODO: Use a constant from the constant table (requires extra input). |
| 3974 | __ LoadLongConstant(out, kDoubleNaN); |
| 3975 | } else { |
| 3976 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 3977 | __ movl(constant, Immediate(kFloatNaN)); |
| 3978 | __ movd(out, constant); |
| 3979 | } |
| 3980 | __ jmp(&done); |
| 3981 | |
| 3982 | // out := op2; |
| 3983 | __ Bind(&op2_label); |
| 3984 | if (type == DataType::Type::kFloat64) { |
| 3985 | __ movsd(out, op2); |
| 3986 | } else { |
| 3987 | __ movss(out, op2); |
| 3988 | } |
| 3989 | |
| 3990 | // Done. |
| 3991 | __ Bind(&done); |
| 3992 | } |
| 3993 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 3994 | void InstructionCodeGeneratorX86::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 3995 | DataType::Type type = minmax->GetResultType(); |
| 3996 | switch (type) { |
| 3997 | case DataType::Type::kInt32: |
| 3998 | case DataType::Type::kInt64: |
| 3999 | GenerateMinMaxInt(minmax->GetLocations(), is_min, type); |
| 4000 | break; |
| 4001 | case DataType::Type::kFloat32: |
| 4002 | case DataType::Type::kFloat64: |
| 4003 | GenerateMinMaxFP(minmax->GetLocations(), is_min, type); |
| 4004 | break; |
| 4005 | default: |
| 4006 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4007 | } |
| 4008 | } |
| 4009 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4010 | void LocationsBuilderX86::VisitMin(HMin* min) { |
| 4011 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4012 | } |
| 4013 | |
| 4014 | void InstructionCodeGeneratorX86::VisitMin(HMin* min) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4015 | GenerateMinMax(min, /*is_min*/ true); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4016 | } |
| 4017 | |
| 4018 | void LocationsBuilderX86::VisitMax(HMax* max) { |
| 4019 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4020 | } |
| 4021 | |
| 4022 | void InstructionCodeGeneratorX86::VisitMax(HMax* max) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4023 | GenerateMinMax(max, /*is_min*/ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4024 | } |
| 4025 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4026 | void LocationsBuilderX86::VisitAbs(HAbs* abs) { |
| 4027 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 4028 | switch (abs->GetResultType()) { |
| 4029 | case DataType::Type::kInt32: |
| 4030 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 4031 | locations->SetOut(Location::SameAsFirstInput()); |
| 4032 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 4033 | break; |
| 4034 | case DataType::Type::kInt64: |
| 4035 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4036 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4037 | locations->AddTemp(Location::RequiresRegister()); |
| 4038 | break; |
| 4039 | case DataType::Type::kFloat32: |
| 4040 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4041 | locations->SetOut(Location::SameAsFirstInput()); |
| 4042 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4043 | locations->AddTemp(Location::RequiresRegister()); |
| 4044 | break; |
| 4045 | case DataType::Type::kFloat64: |
| 4046 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4047 | locations->SetOut(Location::SameAsFirstInput()); |
| 4048 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4049 | break; |
| 4050 | default: |
| 4051 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4052 | } |
| 4053 | } |
| 4054 | |
| 4055 | void InstructionCodeGeneratorX86::VisitAbs(HAbs* abs) { |
| 4056 | LocationSummary* locations = abs->GetLocations(); |
| 4057 | switch (abs->GetResultType()) { |
| 4058 | case DataType::Type::kInt32: { |
| 4059 | Register out = locations->Out().AsRegister<Register>(); |
| 4060 | DCHECK_EQ(out, EAX); |
| 4061 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4062 | DCHECK_EQ(temp, EDX); |
| 4063 | // Sign extend EAX into EDX. |
| 4064 | __ cdq(); |
| 4065 | // XOR EAX with sign. |
| 4066 | __ xorl(EAX, EDX); |
| 4067 | // Subtract out sign to correct. |
| 4068 | __ subl(EAX, EDX); |
| 4069 | // The result is in EAX. |
| 4070 | break; |
| 4071 | } |
| 4072 | case DataType::Type::kInt64: { |
| 4073 | Location input = locations->InAt(0); |
| 4074 | Register input_lo = input.AsRegisterPairLow<Register>(); |
| 4075 | Register input_hi = input.AsRegisterPairHigh<Register>(); |
| 4076 | Location output = locations->Out(); |
| 4077 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 4078 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 4079 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4080 | // Compute the sign into the temporary. |
| 4081 | __ movl(temp, input_hi); |
| 4082 | __ sarl(temp, Immediate(31)); |
| 4083 | // Store the sign into the output. |
| 4084 | __ movl(output_lo, temp); |
| 4085 | __ movl(output_hi, temp); |
| 4086 | // XOR the input to the output. |
| 4087 | __ xorl(output_lo, input_lo); |
| 4088 | __ xorl(output_hi, input_hi); |
| 4089 | // Subtract the sign. |
| 4090 | __ subl(output_lo, temp); |
| 4091 | __ sbbl(output_hi, temp); |
| 4092 | break; |
| 4093 | } |
| 4094 | case DataType::Type::kFloat32: { |
| 4095 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4096 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4097 | Register constant = locations->GetTemp(1).AsRegister<Register>(); |
| 4098 | __ movl(constant, Immediate(INT32_C(0x7FFFFFFF))); |
| 4099 | __ movd(temp, constant); |
| 4100 | __ andps(out, temp); |
| 4101 | break; |
| 4102 | } |
| 4103 | case DataType::Type::kFloat64: { |
| 4104 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4105 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4106 | // TODO: Use a constant from the constant table (requires extra input). |
| 4107 | __ LoadLongConstant(temp, INT64_C(0x7FFFFFFFFFFFFFFF)); |
| 4108 | __ andpd(out, temp); |
| 4109 | break; |
| 4110 | } |
| 4111 | default: |
| 4112 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4113 | } |
| 4114 | } |
| 4115 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4116 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4117 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4118 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4119 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4120 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4121 | case DataType::Type::kInt8: |
| 4122 | case DataType::Type::kUint16: |
| 4123 | case DataType::Type::kInt16: |
| 4124 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4125 | locations->SetInAt(0, Location::Any()); |
| 4126 | break; |
| 4127 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4128 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4129 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 4130 | if (!instruction->IsConstant()) { |
| 4131 | locations->AddTemp(Location::RequiresRegister()); |
| 4132 | } |
| 4133 | break; |
| 4134 | } |
| 4135 | default: |
| 4136 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4137 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4138 | } |
| 4139 | |
| 4140 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4141 | SlowPathCode* slow_path = |
| 4142 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4143 | codegen_->AddSlowPath(slow_path); |
| 4144 | |
| 4145 | LocationSummary* locations = instruction->GetLocations(); |
| 4146 | Location value = locations->InAt(0); |
| 4147 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4148 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4149 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4150 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4151 | case DataType::Type::kInt8: |
| 4152 | case DataType::Type::kUint16: |
| 4153 | case DataType::Type::kInt16: |
| 4154 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4155 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4156 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4157 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4158 | } else if (value.IsStackSlot()) { |
| 4159 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 4160 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4161 | } else { |
| 4162 | DCHECK(value.IsConstant()) << value; |
| 4163 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4164 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4165 | } |
| 4166 | } |
| 4167 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4168 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4169 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4170 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4171 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4172 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 4173 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 4174 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4175 | } else { |
| 4176 | DCHECK(value.IsConstant()) << value; |
| 4177 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4178 | __ jmp(slow_path->GetEntryLabel()); |
| 4179 | } |
| 4180 | } |
| 4181 | break; |
| 4182 | } |
| 4183 | default: |
| 4184 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4185 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4186 | } |
| 4187 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4188 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 4189 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4190 | |
| 4191 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4192 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4193 | |
| 4194 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4195 | case DataType::Type::kInt32: |
| 4196 | case DataType::Type::kInt64: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4197 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4198 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4199 | // The shift count needs to be in CL or a constant. |
| 4200 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4201 | locations->SetOut(Location::SameAsFirstInput()); |
| 4202 | break; |
| 4203 | } |
| 4204 | default: |
| 4205 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4206 | } |
| 4207 | } |
| 4208 | |
| 4209 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 4210 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4211 | |
| 4212 | LocationSummary* locations = op->GetLocations(); |
| 4213 | Location first = locations->InAt(0); |
| 4214 | Location second = locations->InAt(1); |
| 4215 | DCHECK(first.Equals(locations->Out())); |
| 4216 | |
| 4217 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4218 | case DataType::Type::kInt32: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4219 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4220 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4221 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4222 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4223 | DCHECK_EQ(ECX, second_reg); |
| 4224 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4225 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4226 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4227 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4228 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4229 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4230 | } |
| 4231 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4232 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4233 | if (shift == 0) { |
| 4234 | return; |
| 4235 | } |
| 4236 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4237 | if (op->IsShl()) { |
| 4238 | __ shll(first_reg, imm); |
| 4239 | } else if (op->IsShr()) { |
| 4240 | __ sarl(first_reg, imm); |
| 4241 | } else { |
| 4242 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4243 | } |
| 4244 | } |
| 4245 | break; |
| 4246 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4247 | case DataType::Type::kInt64: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4248 | if (second.IsRegister()) { |
| 4249 | Register second_reg = second.AsRegister<Register>(); |
| 4250 | DCHECK_EQ(ECX, second_reg); |
| 4251 | if (op->IsShl()) { |
| 4252 | GenerateShlLong(first, second_reg); |
| 4253 | } else if (op->IsShr()) { |
| 4254 | GenerateShrLong(first, second_reg); |
| 4255 | } else { |
| 4256 | GenerateUShrLong(first, second_reg); |
| 4257 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4258 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4259 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4260 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4261 | // Nothing to do if the shift is 0, as the input is already the output. |
| 4262 | if (shift != 0) { |
| 4263 | if (op->IsShl()) { |
| 4264 | GenerateShlLong(first, shift); |
| 4265 | } else if (op->IsShr()) { |
| 4266 | GenerateShrLong(first, shift); |
| 4267 | } else { |
| 4268 | GenerateUShrLong(first, shift); |
| 4269 | } |
| 4270 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4271 | } |
| 4272 | break; |
| 4273 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4274 | default: |
| 4275 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4276 | } |
| 4277 | } |
| 4278 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4279 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 4280 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4281 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 4282 | if (shift == 1) { |
| 4283 | // This is just an addition. |
| 4284 | __ addl(low, low); |
| 4285 | __ adcl(high, high); |
| 4286 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4287 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 4288 | codegen_->EmitParallelMoves( |
| 4289 | loc.ToLow(), |
| 4290 | loc.ToHigh(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4291 | DataType::Type::kInt32, |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4292 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4293 | loc.ToLow(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4294 | DataType::Type::kInt32); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4295 | } else if (shift > 32) { |
| 4296 | // Low part becomes 0. High part is low part << (shift-32). |
| 4297 | __ movl(high, low); |
| 4298 | __ shll(high, Immediate(shift - 32)); |
| 4299 | __ xorl(low, low); |
| 4300 | } else { |
| 4301 | // Between 1 and 31. |
| 4302 | __ shld(high, low, Immediate(shift)); |
| 4303 | __ shll(low, Immediate(shift)); |
| 4304 | } |
| 4305 | } |
| 4306 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4307 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4308 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4309 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 4310 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 4311 | __ testl(shifter, Immediate(32)); |
| 4312 | __ j(kEqual, &done); |
| 4313 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 4314 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 4315 | __ Bind(&done); |
| 4316 | } |
| 4317 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4318 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 4319 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4320 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4321 | if (shift == 32) { |
| 4322 | // Need to copy the sign. |
| 4323 | DCHECK_NE(low, high); |
| 4324 | __ movl(low, high); |
| 4325 | __ sarl(high, Immediate(31)); |
| 4326 | } else if (shift > 32) { |
| 4327 | DCHECK_NE(low, high); |
| 4328 | // High part becomes sign. Low part is shifted by shift - 32. |
| 4329 | __ movl(low, high); |
| 4330 | __ sarl(high, Immediate(31)); |
| 4331 | __ sarl(low, Immediate(shift - 32)); |
| 4332 | } else { |
| 4333 | // Between 1 and 31. |
| 4334 | __ shrd(low, high, Immediate(shift)); |
| 4335 | __ sarl(high, Immediate(shift)); |
| 4336 | } |
| 4337 | } |
| 4338 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4339 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4340 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4341 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4342 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4343 | __ testl(shifter, Immediate(32)); |
| 4344 | __ j(kEqual, &done); |
| 4345 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4346 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 4347 | __ Bind(&done); |
| 4348 | } |
| 4349 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4350 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 4351 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4352 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4353 | if (shift == 32) { |
| 4354 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 4355 | codegen_->EmitParallelMoves( |
| 4356 | loc.ToHigh(), |
| 4357 | loc.ToLow(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4358 | DataType::Type::kInt32, |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4359 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4360 | loc.ToHigh(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4361 | DataType::Type::kInt32); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4362 | } else if (shift > 32) { |
| 4363 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4364 | __ movl(low, high); |
| 4365 | __ shrl(low, Immediate(shift - 32)); |
| 4366 | __ xorl(high, high); |
| 4367 | } else { |
| 4368 | // Between 1 and 31. |
| 4369 | __ shrd(low, high, Immediate(shift)); |
| 4370 | __ shrl(high, Immediate(shift)); |
| 4371 | } |
| 4372 | } |
| 4373 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4374 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4375 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4376 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4377 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4378 | __ testl(shifter, Immediate(32)); |
| 4379 | __ j(kEqual, &done); |
| 4380 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4381 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4382 | __ Bind(&done); |
| 4383 | } |
| 4384 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4385 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4386 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4387 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4388 | |
| 4389 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4390 | case DataType::Type::kInt64: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4391 | // Add the temporary needed. |
| 4392 | locations->AddTemp(Location::RequiresRegister()); |
| 4393 | FALLTHROUGH_INTENDED; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4394 | case DataType::Type::kInt32: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4395 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4396 | // The shift count needs to be in CL (unless it is a constant). |
| 4397 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4398 | locations->SetOut(Location::SameAsFirstInput()); |
| 4399 | break; |
| 4400 | default: |
| 4401 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4402 | UNREACHABLE(); |
| 4403 | } |
| 4404 | } |
| 4405 | |
| 4406 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4407 | LocationSummary* locations = ror->GetLocations(); |
| 4408 | Location first = locations->InAt(0); |
| 4409 | Location second = locations->InAt(1); |
| 4410 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4411 | if (ror->GetResultType() == DataType::Type::kInt32) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4412 | Register first_reg = first.AsRegister<Register>(); |
| 4413 | if (second.IsRegister()) { |
| 4414 | Register second_reg = second.AsRegister<Register>(); |
| 4415 | __ rorl(first_reg, second_reg); |
| 4416 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4417 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4418 | __ rorl(first_reg, imm); |
| 4419 | } |
| 4420 | return; |
| 4421 | } |
| 4422 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4423 | DCHECK_EQ(ror->GetResultType(), DataType::Type::kInt64); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4424 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4425 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4426 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4427 | if (second.IsRegister()) { |
| 4428 | Register second_reg = second.AsRegister<Register>(); |
| 4429 | DCHECK_EQ(second_reg, ECX); |
| 4430 | __ movl(temp_reg, first_reg_hi); |
| 4431 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4432 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4433 | __ movl(temp_reg, first_reg_hi); |
| 4434 | __ testl(second_reg, Immediate(32)); |
| 4435 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4436 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4437 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4438 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4439 | if (shift_amt == 0) { |
| 4440 | // Already fine. |
| 4441 | return; |
| 4442 | } |
| 4443 | if (shift_amt == 32) { |
| 4444 | // Just swap. |
| 4445 | __ movl(temp_reg, first_reg_lo); |
| 4446 | __ movl(first_reg_lo, first_reg_hi); |
| 4447 | __ movl(first_reg_hi, temp_reg); |
| 4448 | return; |
| 4449 | } |
| 4450 | |
| 4451 | Immediate imm(shift_amt); |
| 4452 | // Save the constents of the low value. |
| 4453 | __ movl(temp_reg, first_reg_lo); |
| 4454 | |
| 4455 | // Shift right into low, feeding bits from high. |
| 4456 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4457 | |
| 4458 | // Shift right into high, feeding bits from the original low. |
| 4459 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4460 | |
| 4461 | // Swap if needed. |
| 4462 | if (shift_amt > 32) { |
| 4463 | __ movl(temp_reg, first_reg_lo); |
| 4464 | __ movl(first_reg_lo, first_reg_hi); |
| 4465 | __ movl(first_reg_hi, temp_reg); |
| 4466 | } |
| 4467 | } |
| 4468 | } |
| 4469 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4470 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4471 | HandleShift(shl); |
| 4472 | } |
| 4473 | |
| 4474 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4475 | HandleShift(shl); |
| 4476 | } |
| 4477 | |
| 4478 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4479 | HandleShift(shr); |
| 4480 | } |
| 4481 | |
| 4482 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4483 | HandleShift(shr); |
| 4484 | } |
| 4485 | |
| 4486 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4487 | HandleShift(ushr); |
| 4488 | } |
| 4489 | |
| 4490 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4491 | HandleShift(ushr); |
| 4492 | } |
| 4493 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4494 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4495 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4496 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4497 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4498 | if (instruction->IsStringAlloc()) { |
| 4499 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4500 | } else { |
| 4501 | InvokeRuntimeCallingConvention calling_convention; |
| 4502 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4503 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4504 | } |
| 4505 | |
| 4506 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4507 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4508 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4509 | if (instruction->IsStringAlloc()) { |
| 4510 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4511 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4512 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4513 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4514 | __ call(Address(temp, code_offset.Int32Value())); |
| 4515 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4516 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4517 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4518 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4519 | DCHECK(!codegen_->IsLeafMethod()); |
| 4520 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4521 | } |
| 4522 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4523 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4524 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4525 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4526 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4527 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4528 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4529 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4530 | } |
| 4531 | |
| 4532 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4533 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4534 | // of poisoning the reference. |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4535 | QuickEntrypointEnum entrypoint = |
| 4536 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4537 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4538 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4539 | DCHECK(!codegen_->IsLeafMethod()); |
| 4540 | } |
| 4541 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4542 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4543 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4544 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4545 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4546 | if (location.IsStackSlot()) { |
| 4547 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4548 | } else if (location.IsDoubleStackSlot()) { |
| 4549 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4550 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4551 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4552 | } |
| 4553 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4554 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4555 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4556 | } |
| 4557 | |
| 4558 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4559 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4560 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4561 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4562 | } |
| 4563 | |
| 4564 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4565 | } |
| 4566 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4567 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4568 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4569 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4570 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4571 | locations->SetOut(Location::RequiresRegister()); |
| 4572 | } |
| 4573 | |
| 4574 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4575 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4576 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4577 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4578 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4579 | __ movl(locations->Out().AsRegister<Register>(), |
| 4580 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4581 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4582 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4583 | instruction->GetIndex(), kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4584 | __ movl(locations->Out().AsRegister<Register>(), |
| 4585 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4586 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4587 | // temp = temp->GetImtEntryAt(method_offset); |
| 4588 | __ movl(locations->Out().AsRegister<Register>(), |
| 4589 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4590 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4591 | } |
| 4592 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4593 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4594 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4595 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4596 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4597 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4598 | } |
| 4599 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4600 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4601 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4602 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4603 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4604 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4605 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4606 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4607 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4608 | break; |
| 4609 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4610 | case DataType::Type::kInt64: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4611 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4612 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4613 | break; |
| 4614 | |
| 4615 | default: |
| 4616 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4617 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4618 | } |
| 4619 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4620 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4621 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4622 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4623 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4624 | locations->SetOut(Location::SameAsFirstInput()); |
| 4625 | } |
| 4626 | |
| 4627 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4628 | LocationSummary* locations = bool_not->GetLocations(); |
| 4629 | Location in = locations->InAt(0); |
| 4630 | Location out = locations->Out(); |
| 4631 | DCHECK(in.Equals(out)); |
| 4632 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4633 | } |
| 4634 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4635 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4636 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4637 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4638 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4639 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4640 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4641 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4642 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4643 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4644 | case DataType::Type::kInt32: |
| 4645 | case DataType::Type::kInt64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4646 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4647 | locations->SetInAt(1, Location::Any()); |
| 4648 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4649 | break; |
| 4650 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4651 | case DataType::Type::kFloat32: |
| 4652 | case DataType::Type::kFloat64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4653 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4654 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4655 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4656 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4657 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4658 | } else { |
| 4659 | locations->SetInAt(1, Location::Any()); |
| 4660 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4661 | locations->SetOut(Location::RequiresRegister()); |
| 4662 | break; |
| 4663 | } |
| 4664 | default: |
| 4665 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4666 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4667 | } |
| 4668 | |
| 4669 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4670 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4671 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4672 | Location left = locations->InAt(0); |
| 4673 | Location right = locations->InAt(1); |
| 4674 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4675 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4676 | Condition less_cond = kLess; |
| 4677 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4678 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4679 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4680 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4681 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4682 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4683 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4684 | case DataType::Type::kInt32: { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4685 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4686 | break; |
| 4687 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4688 | case DataType::Type::kInt64: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4689 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4690 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4691 | int32_t val_low = 0; |
| 4692 | int32_t val_high = 0; |
| 4693 | bool right_is_const = false; |
| 4694 | |
| 4695 | if (right.IsConstant()) { |
| 4696 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4697 | right_is_const = true; |
| 4698 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4699 | val_low = Low32Bits(val); |
| 4700 | val_high = High32Bits(val); |
| 4701 | } |
| 4702 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4703 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4704 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4705 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4706 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4707 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4708 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4709 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4710 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4711 | __ j(kLess, &less); // Signed compare. |
| 4712 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4713 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4714 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4715 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4716 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4717 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4718 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4719 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4720 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4721 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4722 | break; |
| 4723 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4724 | case DataType::Type::kFloat32: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4725 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4726 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4727 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4728 | break; |
| 4729 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4730 | case DataType::Type::kFloat64: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4731 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4732 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4733 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4734 | break; |
| 4735 | } |
| 4736 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4737 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4738 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4739 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4740 | __ movl(out, Immediate(0)); |
| 4741 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4742 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4743 | |
| 4744 | __ Bind(&greater); |
| 4745 | __ movl(out, Immediate(1)); |
| 4746 | __ jmp(&done); |
| 4747 | |
| 4748 | __ Bind(&less); |
| 4749 | __ movl(out, Immediate(-1)); |
| 4750 | |
| 4751 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4752 | } |
| 4753 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4754 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4755 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4756 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4757 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4758 | locations->SetInAt(i, Location::Any()); |
| 4759 | } |
| 4760 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4761 | } |
| 4762 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4763 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4764 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4765 | } |
| 4766 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4767 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4768 | /* |
| 4769 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4770 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4771 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4772 | */ |
| 4773 | switch (kind) { |
| 4774 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4775 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4776 | break; |
| 4777 | } |
| 4778 | case MemBarrierKind::kAnyStore: |
| 4779 | case MemBarrierKind::kLoadAny: |
| 4780 | case MemBarrierKind::kStoreStore: { |
| 4781 | // nop |
| 4782 | break; |
| 4783 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4784 | case MemBarrierKind::kNTStoreStore: |
| 4785 | // Non-Temporal Store/Store needs an explicit fence. |
| 4786 | MemoryFence(/* non-temporal */ true); |
| 4787 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4788 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4789 | } |
| 4790 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4791 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4792 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4793 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4794 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4795 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4796 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4797 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4798 | Register temp) { |
| 4799 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4800 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4801 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4802 | return location.AsRegister<Register>(); |
| 4803 | } |
| 4804 | // For intrinsics we allow any location, so it may be on the stack. |
| 4805 | if (!location.IsRegister()) { |
| 4806 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4807 | return temp; |
| 4808 | } |
| 4809 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4810 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4811 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4812 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4813 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 4814 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4815 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4816 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4817 | __ movl(temp, Address(ESP, stack_offset)); |
| 4818 | return temp; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4819 | } |
| 4820 | return location.AsRegister<Register>(); |
| 4821 | } |
| 4822 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4823 | void CodeGeneratorX86::GenerateStaticOrDirectCall( |
| 4824 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4825 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4826 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4827 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4828 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4829 | uint32_t offset = |
| 4830 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4831 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4832 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4833 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4834 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4835 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4836 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4837 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4838 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4839 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4840 | temp.AsRegister<Register>()); |
| 4841 | __ leal(temp.AsRegister<Register>(), Address(base_reg, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4842 | RecordBootImageMethodPatch(invoke); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4843 | break; |
| 4844 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4845 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4846 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4847 | break; |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4848 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
| 4849 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4850 | temp.AsRegister<Register>()); |
| 4851 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
| 4852 | RecordBootImageRelRoPatch( |
| 4853 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(), |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4854 | GetBootImageOffset(invoke)); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4855 | break; |
| 4856 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4857 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4858 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4859 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4860 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4861 | RecordMethodBssEntryPatch(invoke); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4862 | break; |
| 4863 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4864 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4865 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4866 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4867 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4868 | } |
| 4869 | |
| 4870 | switch (invoke->GetCodePtrLocation()) { |
| 4871 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4872 | __ call(GetFrameEntryLabel()); |
| 4873 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4874 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4875 | // (callee_method + offset_of_quick_compiled_code)() |
| 4876 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4877 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4878 | kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4879 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4880 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4881 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4882 | |
| 4883 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4884 | } |
| 4885 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4886 | void CodeGeneratorX86::GenerateVirtualCall( |
| 4887 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4888 | Register temp = temp_in.AsRegister<Register>(); |
| 4889 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4890 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4891 | |
| 4892 | // Use the calling convention instead of the location of the receiver, as |
| 4893 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4894 | // slow path, the arguments have been moved to the right place, so here we are |
| 4895 | // guaranteed that the receiver is the first register of the calling convention. |
| 4896 | InvokeDexCallingConvention calling_convention; |
| 4897 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4898 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4899 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4900 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4901 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4902 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4903 | // emit a read barrier for the previous class reference load. |
| 4904 | // However this is not required in practice, as this is an |
| 4905 | // intermediate/temporary reference and because the current |
| 4906 | // concurrent copying collector keeps the from-space memory |
| 4907 | // intact/accessible until the end of the marking phase (the |
| 4908 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4909 | __ MaybeUnpoisonHeapReference(temp); |
| 4910 | // temp = temp->GetMethodAt(method_offset); |
| 4911 | __ movl(temp, Address(temp, method_offset)); |
| 4912 | // call temp->GetEntryPoint(); |
| 4913 | __ call(Address( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4914 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4915 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4916 | } |
| 4917 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4918 | void CodeGeneratorX86::RecordBootImageRelRoPatch(HX86ComputeBaseMethodAddress* method_address, |
| 4919 | uint32_t boot_image_offset) { |
| 4920 | boot_image_method_patches_.emplace_back( |
| 4921 | method_address, /* target_dex_file */ nullptr, boot_image_offset); |
| 4922 | __ Bind(&boot_image_method_patches_.back().label); |
| 4923 | } |
| 4924 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4925 | void CodeGeneratorX86::RecordBootImageMethodPatch(HInvokeStaticOrDirect* invoke) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4926 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4927 | HX86ComputeBaseMethodAddress* method_address = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4928 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4929 | boot_image_method_patches_.emplace_back( |
| 4930 | method_address, invoke->GetTargetMethod().dex_file, invoke->GetTargetMethod().index); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4931 | __ Bind(&boot_image_method_patches_.back().label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4932 | } |
| 4933 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4934 | void CodeGeneratorX86::RecordMethodBssEntryPatch(HInvokeStaticOrDirect* invoke) { |
| 4935 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 4936 | HX86ComputeBaseMethodAddress* method_address = |
| 4937 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4938 | // 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] | 4939 | method_bss_entry_patches_.emplace_back( |
| 4940 | method_address, &GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 4941 | __ Bind(&method_bss_entry_patches_.back().label); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4942 | } |
| 4943 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4944 | void CodeGeneratorX86::RecordBootImageTypePatch(HLoadClass* load_class) { |
| 4945 | HX86ComputeBaseMethodAddress* method_address = |
| 4946 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4947 | boot_image_type_patches_.emplace_back( |
| 4948 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4949 | __ Bind(&boot_image_type_patches_.back().label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4950 | } |
| 4951 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4952 | Label* CodeGeneratorX86::NewTypeBssEntryPatch(HLoadClass* load_class) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4953 | HX86ComputeBaseMethodAddress* method_address = |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4954 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4955 | type_bss_entry_patches_.emplace_back( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4956 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4957 | return &type_bss_entry_patches_.back().label; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4958 | } |
| 4959 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4960 | void CodeGeneratorX86::RecordBootImageStringPatch(HLoadString* load_string) { |
| 4961 | HX86ComputeBaseMethodAddress* method_address = |
| 4962 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4963 | boot_image_string_patches_.emplace_back( |
| 4964 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 4965 | __ Bind(&boot_image_string_patches_.back().label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4966 | } |
| 4967 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4968 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
| 4969 | DCHECK(!GetCompilerOptions().IsBootImage()); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4970 | HX86ComputeBaseMethodAddress* method_address = |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4971 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4972 | string_bss_entry_patches_.emplace_back( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4973 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4974 | return &string_bss_entry_patches_.back().label; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4975 | } |
| 4976 | |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4977 | void CodeGeneratorX86::LoadBootImageAddress(Register reg, |
| 4978 | uint32_t boot_image_offset, |
| 4979 | HInvokeStaticOrDirect* invoke) { |
| 4980 | DCHECK(!GetCompilerOptions().IsBootImage()); |
| 4981 | if (GetCompilerOptions().GetCompilePic()) { |
| 4982 | DCHECK(Runtime::Current()->IsAotCompiler()); |
| 4983 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 4984 | HX86ComputeBaseMethodAddress* method_address = |
| 4985 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 4986 | DCHECK(method_address != nullptr); |
| 4987 | Register method_address_reg = |
| 4988 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
| 4989 | __ movl(reg, Address(method_address_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| 4990 | RecordBootImageRelRoPatch(method_address, boot_image_offset); |
| 4991 | } else { |
| 4992 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 4993 | DCHECK(!heap->GetBootImageSpaces().empty()); |
| 4994 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_offset; |
| 4995 | __ movl(reg, Immediate(dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(address)))); |
| 4996 | } |
| 4997 | } |
| 4998 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4999 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 5000 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 5001 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 5002 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5003 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5004 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5005 | const ArenaDeque<X86PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5006 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5007 | for (const X86PcRelativePatchInfo& info : infos) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5008 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5009 | linker_patches->push_back(Factory(literal_offset, |
| 5010 | info.target_dex_file, |
| 5011 | GetMethodAddressOffset(info.method_address), |
| 5012 | info.offset_or_index)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5013 | } |
| 5014 | } |
| 5015 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5016 | linker::LinkerPatch DataBimgRelRoPatchAdapter(size_t literal_offset, |
| 5017 | const DexFile* target_dex_file, |
| 5018 | uint32_t pc_insn_offset, |
| 5019 | uint32_t boot_image_offset) { |
| 5020 | DCHECK(target_dex_file == nullptr); // Unused for DataBimgRelRoPatch(), should be null. |
| 5021 | return linker::LinkerPatch::DataBimgRelRoPatch(literal_offset, pc_insn_offset, boot_image_offset); |
| 5022 | } |
| 5023 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5024 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5025 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5026 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5027 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5028 | method_bss_entry_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5029 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5030 | type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5031 | boot_image_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5032 | string_bss_entry_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5033 | linker_patches->reserve(size); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5034 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5035 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 5036 | boot_image_method_patches_, linker_patches); |
| 5037 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 5038 | boot_image_type_patches_, linker_patches); |
| 5039 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5040 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5041 | } else { |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5042 | EmitPcRelativeLinkerPatches<DataBimgRelRoPatchAdapter>( |
| 5043 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5044 | DCHECK(boot_image_type_patches_.empty()); |
| 5045 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5046 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5047 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 5048 | method_bss_entry_patches_, linker_patches); |
| 5049 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 5050 | type_bss_entry_patches_, linker_patches); |
| 5051 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 5052 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5053 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5054 | } |
| 5055 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5056 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 5057 | Register card, |
| 5058 | Register object, |
| 5059 | Register value, |
| 5060 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5061 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5062 | if (value_can_be_null) { |
| 5063 | __ testl(value, value); |
| 5064 | __ j(kEqual, &is_null); |
| 5065 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5066 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5067 | __ movl(temp, object); |
| 5068 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 5069 | __ movb(Address(temp, card, TIMES_1, 0), |
| 5070 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5071 | if (value_can_be_null) { |
| 5072 | __ Bind(&is_null); |
| 5073 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5074 | } |
| 5075 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5076 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5077 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5078 | |
| 5079 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5080 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5081 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5082 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5083 | kEmitCompilerReadBarrier |
| 5084 | ? LocationSummary::kCallOnSlowPath |
| 5085 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5086 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5087 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5088 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5089 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5090 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5091 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5092 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5093 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5094 | // The output overlaps in case of long: we don't want the low move |
| 5095 | // to overwrite the object's location. Likewise, in the case of |
| 5096 | // an object field get with read barriers enabled, we do not want |
| 5097 | // the move to overwrite the object's location, as we need it to emit |
| 5098 | // the read barrier. |
| 5099 | locations->SetOut( |
| 5100 | Location::RequiresRegister(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5101 | (object_field_get_with_read_barrier || instruction->GetType() == DataType::Type::kInt64) ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5102 | Location::kOutputOverlap : |
| 5103 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5104 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5105 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5106 | if (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5107 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5108 | // So we use an XMM register as a temp to achieve atomicity (first |
| 5109 | // load the temp into the XMM and then copy the XMM into the |
| 5110 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5111 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 5112 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5113 | } |
| 5114 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5115 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 5116 | const FieldInfo& field_info) { |
| 5117 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5118 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5119 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5120 | Location base_loc = locations->InAt(0); |
| 5121 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5122 | Location out = locations->Out(); |
| 5123 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5124 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 5125 | DataType::Type load_type = instruction->GetType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5126 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5127 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5128 | switch (load_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5129 | case DataType::Type::kBool: |
| 5130 | case DataType::Type::kUint8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5131 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5132 | break; |
| 5133 | } |
| 5134 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5135 | case DataType::Type::kInt8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5136 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5137 | break; |
| 5138 | } |
| 5139 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5140 | case DataType::Type::kUint16: { |
| 5141 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5142 | break; |
| 5143 | } |
| 5144 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5145 | case DataType::Type::kInt16: { |
| 5146 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5147 | break; |
| 5148 | } |
| 5149 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5150 | case DataType::Type::kInt32: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5151 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5152 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5153 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5154 | case DataType::Type::kReference: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5155 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5156 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5157 | // Note that a potential implicit null check is handled in this |
| 5158 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 5159 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5160 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5161 | if (is_volatile) { |
| 5162 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5163 | } |
| 5164 | } else { |
| 5165 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 5166 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5167 | if (is_volatile) { |
| 5168 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5169 | } |
| 5170 | // If read barriers are enabled, emit read barriers other than |
| 5171 | // Baker's using a slow path (and also unpoison the loaded |
| 5172 | // reference, if heap poisoning is enabled). |
| 5173 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 5174 | } |
| 5175 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5176 | } |
| 5177 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5178 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5179 | if (is_volatile) { |
| 5180 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 5181 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5182 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5183 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 5184 | __ psrlq(temp, Immediate(32)); |
| 5185 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 5186 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5187 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5188 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5189 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5190 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 5191 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5192 | break; |
| 5193 | } |
| 5194 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5195 | case DataType::Type::kFloat32: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5196 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5197 | break; |
| 5198 | } |
| 5199 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5200 | case DataType::Type::kFloat64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5201 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5202 | break; |
| 5203 | } |
| 5204 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5205 | case DataType::Type::kUint32: |
| 5206 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5207 | case DataType::Type::kVoid: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5208 | LOG(FATAL) << "Unreachable type " << load_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5209 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5210 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5211 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5212 | if (load_type == DataType::Type::kReference || load_type == DataType::Type::kInt64) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5213 | // Potential implicit null checks, in the case of reference or |
| 5214 | // long fields, are handled in the previous switch statement. |
| 5215 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5216 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5217 | } |
| 5218 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5219 | if (is_volatile) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5220 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5221 | // Memory barriers, in the case of references, are also handled |
| 5222 | // in the previous switch statement. |
| 5223 | } else { |
| 5224 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5225 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5226 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5227 | } |
| 5228 | |
| 5229 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5230 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5231 | |
| 5232 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5233 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5234 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5235 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5236 | DataType::Type field_type = field_info.GetFieldType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5237 | bool is_byte_type = DataType::Size(field_type) == 1u; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5238 | |
| 5239 | // The register allocator does not support multiple |
| 5240 | // inputs that die at entry with one in a specific register. |
| 5241 | if (is_byte_type) { |
| 5242 | // Ensure the value is in a byte register. |
| 5243 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5244 | } else if (DataType::IsFloatingPointType(field_type)) { |
| 5245 | if (is_volatile && field_type == DataType::Type::kFloat64) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5246 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 5247 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5248 | } else { |
| 5249 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 5250 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5251 | } else if (is_volatile && field_type == DataType::Type::kInt64) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5252 | // 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] | 5253 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5254 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5255 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 5256 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 5257 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 5258 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 5259 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 5260 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 5261 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5262 | } else { |
| 5263 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5264 | |
| 5265 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5266 | // Temporary registers for the write barrier. |
| 5267 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 5268 | // Ensure the card is in a byte register. |
| 5269 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 5270 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5271 | } |
| 5272 | } |
| 5273 | |
| 5274 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5275 | const FieldInfo& field_info, |
| 5276 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5277 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5278 | |
| 5279 | LocationSummary* locations = instruction->GetLocations(); |
| 5280 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 5281 | Location value = locations->InAt(1); |
| 5282 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5283 | DataType::Type field_type = field_info.GetFieldType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5284 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5285 | bool needs_write_barrier = |
| 5286 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5287 | |
| 5288 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5289 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5290 | } |
| 5291 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5292 | bool maybe_record_implicit_null_check_done = false; |
| 5293 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5294 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5295 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5296 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5297 | case DataType::Type::kInt8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5298 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 5299 | break; |
| 5300 | } |
| 5301 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5302 | case DataType::Type::kUint16: |
| 5303 | case DataType::Type::kInt16: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5304 | if (value.IsConstant()) { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5305 | __ movw(Address(base, offset), |
| 5306 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5307 | } else { |
| 5308 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 5309 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5310 | break; |
| 5311 | } |
| 5312 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5313 | case DataType::Type::kInt32: |
| 5314 | case DataType::Type::kReference: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5315 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5316 | // Note that in the case where `value` is a null reference, |
| 5317 | // we do not enter this block, as the reference does not |
| 5318 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5319 | DCHECK_EQ(field_type, DataType::Type::kReference); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5320 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5321 | __ movl(temp, value.AsRegister<Register>()); |
| 5322 | __ PoisonHeapReference(temp); |
| 5323 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5324 | } else if (value.IsConstant()) { |
| 5325 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5326 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5327 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 5328 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5329 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 5330 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5331 | break; |
| 5332 | } |
| 5333 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5334 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5335 | if (is_volatile) { |
| 5336 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 5337 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 5338 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 5339 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 5340 | __ punpckldq(temp1, temp2); |
| 5341 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5342 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5343 | } else if (value.IsConstant()) { |
| 5344 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5345 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5346 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5347 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5348 | } else { |
| 5349 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5350 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5351 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 5352 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5353 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5354 | break; |
| 5355 | } |
| 5356 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5357 | case DataType::Type::kFloat32: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5358 | if (value.IsConstant()) { |
| 5359 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5360 | __ movl(Address(base, offset), Immediate(v)); |
| 5361 | } else { |
| 5362 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5363 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5364 | break; |
| 5365 | } |
| 5366 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5367 | case DataType::Type::kFloat64: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5368 | if (value.IsConstant()) { |
| 5369 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5370 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5371 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5372 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 5373 | maybe_record_implicit_null_check_done = true; |
| 5374 | } else { |
| 5375 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5376 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5377 | break; |
| 5378 | } |
| 5379 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5380 | case DataType::Type::kUint32: |
| 5381 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5382 | case DataType::Type::kVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5383 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5384 | UNREACHABLE(); |
| 5385 | } |
| 5386 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5387 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5388 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5389 | } |
| 5390 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5391 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5392 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5393 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5394 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5395 | } |
| 5396 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5397 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5398 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5399 | } |
| 5400 | } |
| 5401 | |
| 5402 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5403 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5404 | } |
| 5405 | |
| 5406 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5407 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5408 | } |
| 5409 | |
| 5410 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5411 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5412 | } |
| 5413 | |
| 5414 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5415 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5416 | } |
| 5417 | |
| 5418 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5419 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5420 | } |
| 5421 | |
| 5422 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5423 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5424 | } |
| 5425 | |
| 5426 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5427 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5428 | } |
| 5429 | |
| 5430 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5431 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5432 | } |
| 5433 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5434 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 5435 | HUnresolvedInstanceFieldGet* instruction) { |
| 5436 | FieldAccessCallingConventionX86 calling_convention; |
| 5437 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5438 | instruction, instruction->GetFieldType(), calling_convention); |
| 5439 | } |
| 5440 | |
| 5441 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 5442 | HUnresolvedInstanceFieldGet* instruction) { |
| 5443 | FieldAccessCallingConventionX86 calling_convention; |
| 5444 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5445 | instruction->GetFieldType(), |
| 5446 | instruction->GetFieldIndex(), |
| 5447 | instruction->GetDexPc(), |
| 5448 | calling_convention); |
| 5449 | } |
| 5450 | |
| 5451 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 5452 | HUnresolvedInstanceFieldSet* instruction) { |
| 5453 | FieldAccessCallingConventionX86 calling_convention; |
| 5454 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5455 | instruction, instruction->GetFieldType(), calling_convention); |
| 5456 | } |
| 5457 | |
| 5458 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 5459 | HUnresolvedInstanceFieldSet* instruction) { |
| 5460 | FieldAccessCallingConventionX86 calling_convention; |
| 5461 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5462 | instruction->GetFieldType(), |
| 5463 | instruction->GetFieldIndex(), |
| 5464 | instruction->GetDexPc(), |
| 5465 | calling_convention); |
| 5466 | } |
| 5467 | |
| 5468 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 5469 | HUnresolvedStaticFieldGet* instruction) { |
| 5470 | FieldAccessCallingConventionX86 calling_convention; |
| 5471 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5472 | instruction, instruction->GetFieldType(), calling_convention); |
| 5473 | } |
| 5474 | |
| 5475 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 5476 | HUnresolvedStaticFieldGet* instruction) { |
| 5477 | FieldAccessCallingConventionX86 calling_convention; |
| 5478 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5479 | instruction->GetFieldType(), |
| 5480 | instruction->GetFieldIndex(), |
| 5481 | instruction->GetDexPc(), |
| 5482 | calling_convention); |
| 5483 | } |
| 5484 | |
| 5485 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 5486 | HUnresolvedStaticFieldSet* instruction) { |
| 5487 | FieldAccessCallingConventionX86 calling_convention; |
| 5488 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5489 | instruction, instruction->GetFieldType(), calling_convention); |
| 5490 | } |
| 5491 | |
| 5492 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 5493 | HUnresolvedStaticFieldSet* instruction) { |
| 5494 | FieldAccessCallingConventionX86 calling_convention; |
| 5495 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5496 | instruction->GetFieldType(), |
| 5497 | instruction->GetFieldIndex(), |
| 5498 | instruction->GetDexPc(), |
| 5499 | calling_convention); |
| 5500 | } |
| 5501 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5502 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5503 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5504 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5505 | ? Location::RequiresRegister() |
| 5506 | : Location::Any(); |
| 5507 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5508 | } |
| 5509 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5510 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5511 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5512 | return; |
| 5513 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5514 | LocationSummary* locations = instruction->GetLocations(); |
| 5515 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5516 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5517 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5518 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5519 | } |
| 5520 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5521 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5522 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5523 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5524 | |
| 5525 | LocationSummary* locations = instruction->GetLocations(); |
| 5526 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5527 | |
| 5528 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5529 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5530 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5531 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5532 | } else { |
| 5533 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5534 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5535 | __ jmp(slow_path->GetEntryLabel()); |
| 5536 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5537 | } |
| 5538 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5539 | } |
| 5540 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5541 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5542 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5543 | } |
| 5544 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5545 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5546 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5547 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5548 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5549 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5550 | object_array_get_with_read_barrier |
| 5551 | ? LocationSummary::kCallOnSlowPath |
| 5552 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5553 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5554 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5555 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5556 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5557 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5558 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5559 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5560 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5561 | // The output overlaps in case of long: we don't want the low move |
| 5562 | // to overwrite the array's location. Likewise, in the case of an |
| 5563 | // object array get with read barriers enabled, we do not want the |
| 5564 | // move to overwrite the array's location, as we need it to emit |
| 5565 | // the read barrier. |
| 5566 | locations->SetOut( |
| 5567 | Location::RequiresRegister(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5568 | (instruction->GetType() == DataType::Type::kInt64 || object_array_get_with_read_barrier) |
| 5569 | ? Location::kOutputOverlap |
| 5570 | : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5571 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5572 | } |
| 5573 | |
| 5574 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5575 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5576 | Location obj_loc = locations->InAt(0); |
| 5577 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5578 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5579 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5580 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5581 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5582 | DataType::Type type = instruction->GetType(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5583 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5584 | case DataType::Type::kBool: |
| 5585 | case DataType::Type::kUint8: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5586 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5587 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5588 | break; |
| 5589 | } |
| 5590 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5591 | case DataType::Type::kInt8: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5592 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5593 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5594 | break; |
| 5595 | } |
| 5596 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5597 | case DataType::Type::kUint16: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5598 | Register out = out_loc.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5599 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5600 | // Branch cases into compressed and uncompressed for each index's type. |
| 5601 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5602 | NearLabel done, not_compressed; |
Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 5603 | __ testb(Address(obj, count_offset), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5604 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5605 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5606 | "Expecting 0=compressed, 1=uncompressed"); |
| 5607 | __ j(kNotZero, ¬_compressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5608 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5609 | __ jmp(&done); |
| 5610 | __ Bind(¬_compressed); |
| 5611 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5612 | __ Bind(&done); |
| 5613 | } else { |
| 5614 | // Common case for charAt of array of char or when string compression's |
| 5615 | // feature is turned off. |
| 5616 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5617 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5618 | break; |
| 5619 | } |
| 5620 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5621 | case DataType::Type::kInt16: { |
| 5622 | Register out = out_loc.AsRegister<Register>(); |
| 5623 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5624 | break; |
| 5625 | } |
| 5626 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5627 | case DataType::Type::kInt32: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5628 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5629 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5630 | break; |
| 5631 | } |
| 5632 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5633 | case DataType::Type::kReference: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5634 | static_assert( |
| 5635 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5636 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5637 | // /* HeapReference<Object> */ out = |
| 5638 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5639 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5640 | // Note that a potential implicit null check is handled in this |
| 5641 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5642 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5643 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5644 | } else { |
| 5645 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5646 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5647 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5648 | // If read barriers are enabled, emit read barriers other than |
| 5649 | // Baker's using a slow path (and also unpoison the loaded |
| 5650 | // reference, if heap poisoning is enabled). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5651 | if (index.IsConstant()) { |
| 5652 | uint32_t offset = |
| 5653 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5654 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5655 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5656 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5657 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5658 | } |
| 5659 | } |
| 5660 | break; |
| 5661 | } |
| 5662 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5663 | case DataType::Type::kInt64: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5664 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5665 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 5666 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 5667 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5668 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 5669 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5670 | break; |
| 5671 | } |
| 5672 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5673 | case DataType::Type::kFloat32: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5674 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5675 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5676 | break; |
| 5677 | } |
| 5678 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5679 | case DataType::Type::kFloat64: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5680 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5681 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5682 | break; |
| 5683 | } |
| 5684 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5685 | case DataType::Type::kUint32: |
| 5686 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5687 | case DataType::Type::kVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5688 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5689 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5690 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5691 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5692 | if (type == DataType::Type::kReference || type == DataType::Type::kInt64) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5693 | // Potential implicit null checks, in the case of reference or |
| 5694 | // long arrays, are handled in the previous switch statement. |
| 5695 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5696 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5697 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5698 | } |
| 5699 | |
| 5700 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5701 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5702 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5703 | bool needs_write_barrier = |
| 5704 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5705 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5706 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5707 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5708 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5709 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5710 | LocationSummary::kCallOnSlowPath : |
| 5711 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5712 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5713 | bool is_byte_type = DataType::Size(value_type) == 1u; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5714 | // We need the inputs to be different than the output in case of long operation. |
| 5715 | // In case of a byte operation, the register allocator does not support multiple |
| 5716 | // inputs that die at entry with one in a specific register. |
| 5717 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5718 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5719 | if (is_byte_type) { |
| 5720 | // Ensure the value is in a byte register. |
| 5721 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5722 | } else if (DataType::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5723 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5724 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5725 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5726 | } |
| 5727 | if (needs_write_barrier) { |
| 5728 | // Temporary registers for the write barrier. |
| 5729 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5730 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5731 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5732 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5733 | } |
| 5734 | |
| 5735 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5736 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5737 | Location array_loc = locations->InAt(0); |
| 5738 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5739 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5740 | Location value = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5741 | DataType::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5742 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5743 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5744 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5745 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5746 | bool needs_write_barrier = |
| 5747 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5748 | |
| 5749 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5750 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5751 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5752 | case DataType::Type::kInt8: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5753 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5754 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5755 | if (value.IsRegister()) { |
| 5756 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5757 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5758 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5759 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5760 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5761 | break; |
| 5762 | } |
| 5763 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5764 | case DataType::Type::kUint16: |
| 5765 | case DataType::Type::kInt16: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5766 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5767 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5768 | if (value.IsRegister()) { |
| 5769 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5770 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5771 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5772 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5773 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5774 | break; |
| 5775 | } |
| 5776 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5777 | case DataType::Type::kReference: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5778 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5779 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5780 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5781 | if (!value.IsRegister()) { |
| 5782 | // Just setting null. |
| 5783 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5784 | DCHECK(value.IsConstant()) << value; |
| 5785 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5786 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5787 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5788 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5789 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5790 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5791 | |
| 5792 | DCHECK(needs_write_barrier); |
| 5793 | Register register_value = value.AsRegister<Register>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5794 | // We cannot use a NearLabel for `done`, as its range may be too |
| 5795 | // short when Baker read barriers are enabled. |
| 5796 | Label done; |
| 5797 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5798 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5799 | Location temp_loc = locations->GetTemp(0); |
| 5800 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5801 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5802 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5803 | codegen_->AddSlowPath(slow_path); |
| 5804 | if (instruction->GetValueCanBeNull()) { |
| 5805 | __ testl(register_value, register_value); |
| 5806 | __ j(kNotEqual, ¬_null); |
| 5807 | __ movl(address, Immediate(0)); |
| 5808 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5809 | __ jmp(&done); |
| 5810 | __ Bind(¬_null); |
| 5811 | } |
| 5812 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5813 | // Note that when Baker read barriers are enabled, the type |
| 5814 | // checks are performed without read barriers. This is fine, |
| 5815 | // even in the case where a class object is in the from-space |
| 5816 | // after the flip, as a comparison involving such a type would |
| 5817 | // not produce a false positive; it may of course produce a |
| 5818 | // false negative, in which case we would take the ArraySet |
| 5819 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5820 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5821 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5822 | __ movl(temp, Address(array, class_offset)); |
| 5823 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5824 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5825 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5826 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5827 | __ movl(temp, Address(temp, component_offset)); |
| 5828 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5829 | // nor the object reference in `register_value->klass`, as |
| 5830 | // we are comparing two poisoned references. |
| 5831 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5832 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5833 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5834 | __ j(kEqual, &do_put); |
| 5835 | // If heap poisoning is enabled, the `temp` reference has |
| 5836 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5837 | __ MaybeUnpoisonHeapReference(temp); |
| 5838 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5839 | // If heap poisoning is enabled, no need to unpoison the |
| 5840 | // heap reference loaded below, as it is only used for a |
| 5841 | // comparison with null. |
| 5842 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5843 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5844 | __ Bind(&do_put); |
| 5845 | } else { |
| 5846 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5847 | } |
| 5848 | } |
| 5849 | |
| 5850 | if (kPoisonHeapReferences) { |
| 5851 | __ movl(temp, register_value); |
| 5852 | __ PoisonHeapReference(temp); |
| 5853 | __ movl(address, temp); |
| 5854 | } else { |
| 5855 | __ movl(address, register_value); |
| 5856 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5857 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5858 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5859 | } |
| 5860 | |
| 5861 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5862 | codegen_->MarkGCCard( |
| 5863 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5864 | __ Bind(&done); |
| 5865 | |
| 5866 | if (slow_path != nullptr) { |
| 5867 | __ Bind(slow_path->GetExitLabel()); |
| 5868 | } |
| 5869 | |
| 5870 | break; |
| 5871 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5872 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5873 | case DataType::Type::kInt32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5874 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5875 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5876 | if (value.IsRegister()) { |
| 5877 | __ movl(address, value.AsRegister<Register>()); |
| 5878 | } else { |
| 5879 | DCHECK(value.IsConstant()) << value; |
| 5880 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5881 | __ movl(address, Immediate(v)); |
| 5882 | } |
| 5883 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5884 | break; |
| 5885 | } |
| 5886 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5887 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5888 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5889 | if (value.IsRegisterPair()) { |
| 5890 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5891 | value.AsRegisterPairLow<Register>()); |
| 5892 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5893 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5894 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5895 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5896 | DCHECK(value.IsConstant()); |
| 5897 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 5898 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5899 | Immediate(Low32Bits(val))); |
| 5900 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5901 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5902 | Immediate(High32Bits(val))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5903 | } |
| 5904 | break; |
| 5905 | } |
| 5906 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5907 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5908 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5909 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5910 | if (value.IsFpuRegister()) { |
| 5911 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5912 | } else { |
| 5913 | DCHECK(value.IsConstant()); |
| 5914 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5915 | __ movl(address, Immediate(v)); |
| 5916 | } |
| 5917 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5918 | break; |
| 5919 | } |
| 5920 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5921 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5922 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5923 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5924 | if (value.IsFpuRegister()) { |
| 5925 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5926 | } else { |
| 5927 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5928 | Address address_hi = |
| 5929 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5930 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5931 | __ movl(address, Immediate(Low32Bits(v))); |
| 5932 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5933 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5934 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5935 | break; |
| 5936 | } |
| 5937 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5938 | case DataType::Type::kUint32: |
| 5939 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5940 | case DataType::Type::kVoid: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5941 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5942 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5943 | } |
| 5944 | } |
| 5945 | |
| 5946 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5947 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5948 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5949 | if (!instruction->IsEmittedAtUseSite()) { |
| 5950 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5951 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5952 | } |
| 5953 | |
| 5954 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5955 | if (instruction->IsEmittedAtUseSite()) { |
| 5956 | return; |
| 5957 | } |
| 5958 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5959 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5960 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5961 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5962 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5963 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5964 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5965 | // Mask out most significant bit in case the array is String's array of char. |
| 5966 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5967 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5968 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5969 | } |
| 5970 | |
| 5971 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5972 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5973 | InvokeRuntimeCallingConvention calling_convention; |
| 5974 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5975 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5976 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5977 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5978 | HInstruction* length = instruction->InputAt(1); |
| 5979 | if (!length->IsEmittedAtUseSite()) { |
| 5980 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5981 | } |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5982 | // Need register to see array's length. |
| 5983 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5984 | locations->AddTemp(Location::RequiresRegister()); |
| 5985 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5986 | } |
| 5987 | |
| 5988 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5989 | const bool is_string_compressed_char_at = |
| 5990 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5991 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5992 | Location index_loc = locations->InAt(0); |
| 5993 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5994 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5995 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5996 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5997 | if (length_loc.IsConstant()) { |
| 5998 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5999 | if (index_loc.IsConstant()) { |
| 6000 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 6001 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 6002 | if (index < 0 || index >= length) { |
| 6003 | codegen_->AddSlowPath(slow_path); |
| 6004 | __ jmp(slow_path->GetEntryLabel()); |
| 6005 | } else { |
| 6006 | // Some optimization after BCE may have generated this, and we should not |
| 6007 | // generate a bounds check if it is a valid range. |
| 6008 | } |
| 6009 | return; |
| 6010 | } |
| 6011 | |
| 6012 | // We have to reverse the jump condition because the length is the constant. |
| 6013 | Register index_reg = index_loc.AsRegister<Register>(); |
| 6014 | __ cmpl(index_reg, Immediate(length)); |
| 6015 | codegen_->AddSlowPath(slow_path); |
| 6016 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6017 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6018 | HInstruction* array_length = instruction->InputAt(1); |
| 6019 | if (array_length->IsEmittedAtUseSite()) { |
| 6020 | // Address the length field in the array. |
| 6021 | DCHECK(array_length->IsArrayLength()); |
| 6022 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 6023 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 6024 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6025 | if (is_string_compressed_char_at) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6026 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 6027 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6028 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6029 | __ movl(length_reg, array_len); |
| 6030 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6031 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6032 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6033 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6034 | // Checking bounds for general case: |
| 6035 | // Array of char or string's array with feature compression off. |
| 6036 | if (index_loc.IsConstant()) { |
| 6037 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 6038 | __ cmpl(array_len, Immediate(value)); |
| 6039 | } else { |
| 6040 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 6041 | } |
| 6042 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6043 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6044 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6045 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6046 | } |
| 6047 | codegen_->AddSlowPath(slow_path); |
| 6048 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6049 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6050 | } |
| 6051 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6052 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6053 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6054 | } |
| 6055 | |
| 6056 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6057 | if (instruction->GetNext()->IsSuspendCheck() && |
| 6058 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 6059 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 6060 | // The back edge will generate the suspend check. |
| 6061 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 6062 | } |
| 6063 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6064 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6065 | } |
| 6066 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6067 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6068 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6069 | instruction, LocationSummary::kCallOnSlowPath); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 6070 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 6071 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 6072 | // registers in full width (since the runtime only saves/restores lower part). |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6073 | locations->SetCustomSlowPathCallerSaves( |
| 6074 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6075 | } |
| 6076 | |
| 6077 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6078 | HBasicBlock* block = instruction->GetBlock(); |
| 6079 | if (block->GetLoopInformation() != nullptr) { |
| 6080 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6081 | // The back edge will generate the suspend check. |
| 6082 | return; |
| 6083 | } |
| 6084 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6085 | // The goto will generate the suspend check. |
| 6086 | return; |
| 6087 | } |
| 6088 | GenerateSuspendCheck(instruction, nullptr); |
| 6089 | } |
| 6090 | |
| 6091 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6092 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6093 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6094 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 6095 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6096 | slow_path = |
| 6097 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6098 | instruction->SetSlowPath(slow_path); |
| 6099 | codegen_->AddSlowPath(slow_path); |
| 6100 | if (successor != nullptr) { |
| 6101 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6102 | } |
| 6103 | } else { |
| 6104 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6105 | } |
| 6106 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6107 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6108 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6109 | if (successor == nullptr) { |
| 6110 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6111 | __ Bind(slow_path->GetReturnLabel()); |
| 6112 | } else { |
| 6113 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 6114 | __ jmp(slow_path->GetEntryLabel()); |
| 6115 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6116 | } |
| 6117 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6118 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 6119 | return codegen_->GetAssembler(); |
| 6120 | } |
| 6121 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6122 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src, int number_of_words) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6123 | ScratchRegisterScope ensure_scratch( |
| 6124 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6125 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6126 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6127 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6128 | // Now that temp register is available (possibly spilled), move blocks of memory. |
| 6129 | for (int i = 0; i < number_of_words; i++) { |
| 6130 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 6131 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 6132 | stack_offset += kX86WordSize; |
| 6133 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6134 | } |
| 6135 | |
| 6136 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6137 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6138 | Location source = move->GetSource(); |
| 6139 | Location destination = move->GetDestination(); |
| 6140 | |
| 6141 | if (source.IsRegister()) { |
| 6142 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6143 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6144 | } else if (destination.IsFpuRegister()) { |
| 6145 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6146 | } else { |
| 6147 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6148 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6149 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6150 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6151 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6152 | // Create stack space for 2 elements. |
| 6153 | __ subl(ESP, Immediate(2 * elem_size)); |
| 6154 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 6155 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 6156 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 6157 | // And remove the temporary stack space we allocated. |
| 6158 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6159 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6160 | if (destination.IsRegister()) { |
| 6161 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 6162 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6163 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6164 | } else if (destination.IsRegisterPair()) { |
| 6165 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 6166 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 6167 | __ psrlq(src_reg, Immediate(32)); |
| 6168 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6169 | } else if (destination.IsStackSlot()) { |
| 6170 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6171 | } else if (destination.IsDoubleStackSlot()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6172 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6173 | } else { |
| 6174 | DCHECK(destination.IsSIMDStackSlot()); |
| 6175 | __ movups(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6176 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6177 | } else if (source.IsStackSlot()) { |
| 6178 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6179 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6180 | } else if (destination.IsFpuRegister()) { |
| 6181 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6182 | } else { |
| 6183 | DCHECK(destination.IsStackSlot()); |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6184 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6185 | } |
| 6186 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6187 | if (destination.IsRegisterPair()) { |
| 6188 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 6189 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 6190 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 6191 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6192 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 6193 | } else { |
| 6194 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6195 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6196 | } |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6197 | } else if (source.IsSIMDStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6198 | if (destination.IsFpuRegister()) { |
| 6199 | __ movups(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 6200 | } else { |
| 6201 | DCHECK(destination.IsSIMDStackSlot()); |
| 6202 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 6203 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6204 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6205 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 6206 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6207 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6208 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6209 | if (value == 0) { |
| 6210 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6211 | } else { |
| 6212 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 6213 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6214 | } else { |
| 6215 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6216 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6217 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6218 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6219 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6220 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6221 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6222 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6223 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 6224 | if (value == 0) { |
| 6225 | // Easy handling of 0.0. |
| 6226 | __ xorps(dest, dest); |
| 6227 | } else { |
| 6228 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6229 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6230 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6231 | __ movl(temp, Immediate(value)); |
| 6232 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6233 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6234 | } else { |
| 6235 | DCHECK(destination.IsStackSlot()) << destination; |
| 6236 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 6237 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6238 | } else if (constant->IsLongConstant()) { |
| 6239 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 6240 | int32_t low_value = Low32Bits(value); |
| 6241 | int32_t high_value = High32Bits(value); |
| 6242 | Immediate low(low_value); |
| 6243 | Immediate high(high_value); |
| 6244 | if (destination.IsDoubleStackSlot()) { |
| 6245 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6246 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6247 | } else { |
| 6248 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 6249 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 6250 | } |
| 6251 | } else { |
| 6252 | DCHECK(constant->IsDoubleConstant()); |
| 6253 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6254 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6255 | int32_t low_value = Low32Bits(value); |
| 6256 | int32_t high_value = High32Bits(value); |
| 6257 | Immediate low(low_value); |
| 6258 | Immediate high(high_value); |
| 6259 | if (destination.IsFpuRegister()) { |
| 6260 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 6261 | if (value == 0) { |
| 6262 | // Easy handling of 0.0. |
| 6263 | __ xorpd(dest, dest); |
| 6264 | } else { |
| 6265 | __ pushl(high); |
| 6266 | __ pushl(low); |
| 6267 | __ movsd(dest, Address(ESP, 0)); |
| 6268 | __ addl(ESP, Immediate(8)); |
| 6269 | } |
| 6270 | } else { |
| 6271 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6272 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6273 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6274 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6275 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6276 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6277 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6278 | } |
| 6279 | } |
| 6280 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 6281 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6282 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 6283 | ScratchRegisterScope ensure_scratch( |
| 6284 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 6285 | |
| 6286 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6287 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 6288 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 6289 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6290 | } |
| 6291 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6292 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6293 | ScratchRegisterScope ensure_scratch( |
| 6294 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6295 | |
| 6296 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6297 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6298 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 6299 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 6300 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6301 | } |
| 6302 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6303 | void ParallelMoveResolverX86::Exchange128(XmmRegister reg, int mem) { |
| 6304 | size_t extra_slot = 4 * kX86WordSize; |
| 6305 | __ subl(ESP, Immediate(extra_slot)); |
| 6306 | __ movups(Address(ESP, 0), XmmRegister(reg)); |
| 6307 | ExchangeMemory(0, mem + extra_slot, 4); |
| 6308 | __ movups(XmmRegister(reg), Address(ESP, 0)); |
| 6309 | __ addl(ESP, Immediate(extra_slot)); |
| 6310 | } |
| 6311 | |
| 6312 | void ParallelMoveResolverX86::ExchangeMemory(int mem1, int mem2, int number_of_words) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6313 | ScratchRegisterScope ensure_scratch1( |
| 6314 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6315 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6316 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 6317 | ScratchRegisterScope ensure_scratch2( |
| 6318 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6319 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6320 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 6321 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6322 | |
| 6323 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 6324 | for (int i = 0; i < number_of_words; i++) { |
| 6325 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 6326 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 6327 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 6328 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 6329 | stack_offset += kX86WordSize; |
| 6330 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6331 | } |
| 6332 | |
| 6333 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6334 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6335 | Location source = move->GetSource(); |
| 6336 | Location destination = move->GetDestination(); |
| 6337 | |
| 6338 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 6339 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 6340 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 6341 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 6342 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6343 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6344 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6345 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6346 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6347 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6348 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6349 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6350 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 6351 | // Use XOR Swap algorithm to avoid a temporary. |
| 6352 | DCHECK_NE(source.reg(), destination.reg()); |
| 6353 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 6354 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 6355 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 6356 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 6357 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6358 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 6359 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6360 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 6361 | // Take advantage of the 16 bytes in the XMM register. |
| 6362 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 6363 | Address stack(ESP, destination.GetStackIndex()); |
| 6364 | // Load the double into the high doubleword. |
| 6365 | __ movhpd(reg, stack); |
| 6366 | |
| 6367 | // Store the low double into the destination. |
| 6368 | __ movsd(stack, reg); |
| 6369 | |
| 6370 | // Move the high double to the low double. |
| 6371 | __ psrldq(reg, Immediate(8)); |
| 6372 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 6373 | // Take advantage of the 16 bytes in the XMM register. |
| 6374 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 6375 | Address stack(ESP, source.GetStackIndex()); |
| 6376 | // Load the double into the high doubleword. |
| 6377 | __ movhpd(reg, stack); |
| 6378 | |
| 6379 | // Store the low double into the destination. |
| 6380 | __ movsd(stack, reg); |
| 6381 | |
| 6382 | // Move the high double to the low double. |
| 6383 | __ psrldq(reg, Immediate(8)); |
| 6384 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6385 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 6386 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 6387 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 6388 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 6389 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6390 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 6391 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6392 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6393 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6394 | } |
| 6395 | } |
| 6396 | |
| 6397 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 6398 | __ pushl(static_cast<Register>(reg)); |
| 6399 | } |
| 6400 | |
| 6401 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 6402 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6403 | } |
| 6404 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6405 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 6406 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6407 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6408 | case HLoadClass::LoadKind::kInvalid: |
| 6409 | LOG(FATAL) << "UNREACHABLE"; |
| 6410 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6411 | case HLoadClass::LoadKind::kReferrersClass: |
| 6412 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6413 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6414 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6415 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6416 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6417 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6418 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6419 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6420 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6421 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6422 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6423 | break; |
| 6424 | } |
| 6425 | return desired_class_load_kind; |
| 6426 | } |
| 6427 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6428 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6429 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6430 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6431 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6432 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6433 | cls, |
| 6434 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6435 | Location::RegisterLocation(EAX)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6436 | DCHECK_EQ(calling_convention.GetRegisterAt(0), EAX); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6437 | return; |
| 6438 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6439 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6440 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6441 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6442 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6443 | ? LocationSummary::kCallOnSlowPath |
| 6444 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6445 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6446 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6447 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6448 | } |
| 6449 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6450 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6451 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6452 | load_kind == HLoadClass::LoadKind::kBootImageRelRo || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6453 | load_kind == HLoadClass::LoadKind::kBssEntry) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6454 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6455 | } |
| 6456 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6457 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6458 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6459 | // Rely on the type resolution and/or initialization to save everything. |
| 6460 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6461 | InvokeRuntimeCallingConvention calling_convention; |
| 6462 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6463 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6464 | } else { |
| 6465 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6466 | } |
| 6467 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6468 | } |
| 6469 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6470 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6471 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6472 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6473 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6474 | // Add a patch entry and return the label. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6475 | jit_class_patches_.emplace_back(&dex_file, type_index.index_); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6476 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 6477 | return &info->label; |
| 6478 | } |
| 6479 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6480 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6481 | // move. |
| 6482 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6483 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6484 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6485 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6486 | return; |
| 6487 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6488 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6489 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6490 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6491 | Location out_loc = locations->Out(); |
| 6492 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6493 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6494 | bool generate_null_check = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6495 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6496 | ? kWithoutReadBarrier |
| 6497 | : kCompilerReadBarrierOption; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6498 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6499 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6500 | DCHECK(!cls->CanCallRuntime()); |
| 6501 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6502 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6503 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6504 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6505 | cls, |
| 6506 | out_loc, |
| 6507 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6508 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6509 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6510 | break; |
| 6511 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6512 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6513 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6514 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6515 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6516 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6517 | codegen_->RecordBootImageTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6518 | break; |
| 6519 | } |
| 6520 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6521 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6522 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6523 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6524 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6525 | __ movl(out, Immediate(address)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6526 | break; |
| 6527 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6528 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6529 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6530 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6531 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6532 | codegen_->RecordBootImageRelRoPatch(cls->InputAt(0)->AsX86ComputeBaseMethodAddress(), |
| 6533 | codegen_->GetBootImageOffset(cls)); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6534 | break; |
| 6535 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6536 | case HLoadClass::LoadKind::kBssEntry: { |
| 6537 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6538 | Address address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6539 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 6540 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| 6541 | generate_null_check = true; |
| 6542 | break; |
| 6543 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6544 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6545 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6546 | Label* fixup_label = codegen_->NewJitRootClassPatch( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6547 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6548 | // /* GcRoot<mirror::Class> */ out = *address |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6549 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6550 | break; |
| 6551 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6552 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6553 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6554 | LOG(FATAL) << "UNREACHABLE"; |
| 6555 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6556 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6557 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6558 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6559 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6560 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6561 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6562 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6563 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6564 | if (generate_null_check) { |
| 6565 | __ testl(out, out); |
| 6566 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6567 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6568 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6569 | if (cls->MustGenerateClinitCheck()) { |
| 6570 | GenerateClassInitializationCheck(slow_path, out); |
| 6571 | } else { |
| 6572 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6573 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6574 | } |
| 6575 | } |
| 6576 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6577 | void LocationsBuilderX86::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6578 | InvokeRuntimeCallingConvention calling_convention; |
| 6579 | Location location = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 6580 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 6581 | } |
| 6582 | |
| 6583 | void InstructionCodeGeneratorX86::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6584 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 6585 | } |
| 6586 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6587 | void LocationsBuilderX86::VisitLoadMethodType(HLoadMethodType* load) { |
| 6588 | InvokeRuntimeCallingConvention calling_convention; |
| 6589 | Location location = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 6590 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 6591 | } |
| 6592 | |
| 6593 | void InstructionCodeGeneratorX86::VisitLoadMethodType(HLoadMethodType* load) { |
| 6594 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 6595 | } |
| 6596 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6597 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6598 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6599 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6600 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6601 | if (check->HasUses()) { |
| 6602 | locations->SetOut(Location::SameAsFirstInput()); |
| 6603 | } |
| 6604 | } |
| 6605 | |
| 6606 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6607 | // We assume the class to not be null. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6608 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6609 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6610 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6611 | GenerateClassInitializationCheck(slow_path, |
| 6612 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6613 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6614 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6615 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6616 | SlowPathCode* slow_path, Register class_reg) { |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 6617 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 6618 | const size_t status_byte_offset = |
| 6619 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 6620 | constexpr uint32_t shifted_initialized_value = |
| 6621 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
| 6622 | |
| 6623 | __ cmpb(Address(class_reg, status_byte_offset), Immediate(shifted_initialized_value)); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 6624 | __ j(kBelow, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6625 | __ Bind(slow_path->GetExitLabel()); |
| 6626 | // No need for memory fence, thanks to the X86 memory model. |
| 6627 | } |
| 6628 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6629 | void InstructionCodeGeneratorX86::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 6630 | Register temp) { |
| 6631 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 6632 | uint32_t mask = check->GetBitstringMask(); |
| 6633 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 6634 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 6635 | |
| 6636 | if (mask_bits == 16u) { |
| 6637 | // Compare the bitstring in memory. |
| 6638 | __ cmpw(Address(temp, mirror::Class::StatusOffset()), Immediate(path_to_root)); |
| 6639 | } else { |
| 6640 | // /* uint32_t */ temp = temp->status_ |
| 6641 | __ movl(temp, Address(temp, mirror::Class::StatusOffset())); |
| 6642 | // Compare the bitstring bits using SUB. |
| 6643 | __ subl(temp, Immediate(path_to_root)); |
| 6644 | // Shift out bits that do not contribute to the comparison. |
| 6645 | __ shll(temp, Immediate(32u - mask_bits)); |
| 6646 | } |
| 6647 | } |
| 6648 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6649 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6650 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6651 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6652 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6653 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6654 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6655 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6656 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6657 | case HLoadString::LoadKind::kJitTableAddress: |
| 6658 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6659 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6660 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6661 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6662 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6663 | } |
| 6664 | return desired_string_load_kind; |
| 6665 | } |
| 6666 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6667 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6668 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6669 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6670 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6671 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6672 | load_kind == HLoadString::LoadKind::kBootImageRelRo || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6673 | load_kind == HLoadString::LoadKind::kBssEntry) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6674 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6675 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6676 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6677 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 6678 | } else { |
| 6679 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6680 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6681 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6682 | // Rely on the pResolveString to save everything. |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6683 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6684 | InvokeRuntimeCallingConvention calling_convention; |
| 6685 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6686 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6687 | } else { |
| 6688 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6689 | } |
| 6690 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6691 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6692 | } |
| 6693 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6694 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6695 | dex::StringIndex string_index, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6696 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6697 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6698 | // Add a patch entry and return the label. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6699 | jit_string_patches_.emplace_back(&dex_file, string_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6700 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6701 | return &info->label; |
| 6702 | } |
| 6703 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6704 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6705 | // move. |
| 6706 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6707 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6708 | Location out_loc = locations->Out(); |
| 6709 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6710 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6711 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6712 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6713 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6714 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6715 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6716 | codegen_->RecordBootImageStringPatch(load); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6717 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6718 | } |
| 6719 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6720 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6721 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6722 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6723 | __ movl(out, Immediate(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6724 | return; |
| 6725 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6726 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6727 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6728 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6729 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6730 | codegen_->RecordBootImageRelRoPatch(load->InputAt(0)->AsX86ComputeBaseMethodAddress(), |
| 6731 | codegen_->GetBootImageOffset(load)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6732 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6733 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6734 | case HLoadString::LoadKind::kBssEntry: { |
| 6735 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6736 | Address address = Address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6737 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6738 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6739 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6740 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6741 | codegen_->AddSlowPath(slow_path); |
| 6742 | __ testl(out, out); |
| 6743 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6744 | __ Bind(slow_path->GetExitLabel()); |
| 6745 | return; |
| 6746 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6747 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6748 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6749 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6750 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6751 | // /* GcRoot<mirror::String> */ out = *address |
| 6752 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6753 | return; |
| 6754 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6755 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6756 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6757 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6758 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6759 | // 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] | 6760 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6761 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6762 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6763 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6764 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6765 | } |
| 6766 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6767 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6768 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6769 | } |
| 6770 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6771 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6772 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6773 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6774 | locations->SetOut(Location::RequiresRegister()); |
| 6775 | } |
| 6776 | |
| 6777 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6778 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6779 | } |
| 6780 | |
| 6781 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6782 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6783 | } |
| 6784 | |
| 6785 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6786 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6787 | } |
| 6788 | |
| 6789 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6790 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6791 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6792 | InvokeRuntimeCallingConvention calling_convention; |
| 6793 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6794 | } |
| 6795 | |
| 6796 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6797 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6798 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6799 | } |
| 6800 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6801 | // Temp is used for read barrier. |
| 6802 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6803 | if (kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6804 | !kUseBakerReadBarrier && |
| 6805 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6806 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6807 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6808 | return 1; |
| 6809 | } |
| 6810 | return 0; |
| 6811 | } |
| 6812 | |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6813 | // Interface case has 2 temps, one for holding the number of interfaces, one for the current |
| 6814 | // interface pointer, the current interface is compared in memory. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6815 | // The other checks have one temp for loading the object's class. |
| 6816 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6817 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6818 | return 2; |
| 6819 | } |
| 6820 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6821 | } |
| 6822 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6823 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6824 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6825 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6826 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6827 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6828 | case TypeCheckKind::kExactCheck: |
| 6829 | case TypeCheckKind::kAbstractClassCheck: |
| 6830 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6831 | case TypeCheckKind::kArrayObjectCheck: { |
| 6832 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 6833 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 6834 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6835 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6836 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6837 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6838 | case TypeCheckKind::kUnresolvedCheck: |
| 6839 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6840 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6841 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6842 | case TypeCheckKind::kBitstringCheck: |
| 6843 | break; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6844 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6845 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6846 | LocationSummary* locations = |
| 6847 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6848 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6849 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6850 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6851 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6852 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 6853 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 6854 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 6855 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 6856 | } else { |
| 6857 | locations->SetInAt(1, Location::Any()); |
| 6858 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6859 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6860 | locations->SetOut(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6861 | // When read barriers are enabled, we need a temporary register for some cases. |
| 6862 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6863 | } |
| 6864 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6865 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6866 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6867 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6868 | Location obj_loc = locations->InAt(0); |
| 6869 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6870 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6871 | Location out_loc = locations->Out(); |
| 6872 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6873 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6874 | DCHECK_LE(num_temps, 1u); |
| 6875 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6876 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6877 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6878 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6879 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6880 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6881 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6882 | |
| 6883 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6884 | // Avoid null check if we know obj is not null. |
| 6885 | if (instruction->MustDoNullCheck()) { |
| 6886 | __ testl(obj, obj); |
| 6887 | __ j(kEqual, &zero); |
| 6888 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6889 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6890 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6891 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6892 | ReadBarrierOption read_barrier_option = |
| 6893 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6894 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6895 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6896 | out_loc, |
| 6897 | obj_loc, |
| 6898 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6899 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6900 | if (cls.IsRegister()) { |
| 6901 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6902 | } else { |
| 6903 | DCHECK(cls.IsStackSlot()) << cls; |
| 6904 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6905 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6906 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6907 | // Classes must be equal for the instanceof to succeed. |
| 6908 | __ j(kNotEqual, &zero); |
| 6909 | __ movl(out, Immediate(1)); |
| 6910 | __ jmp(&done); |
| 6911 | break; |
| 6912 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6913 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6914 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6915 | ReadBarrierOption read_barrier_option = |
| 6916 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6917 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6918 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6919 | out_loc, |
| 6920 | obj_loc, |
| 6921 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6922 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6923 | // If the class is abstract, we eagerly fetch the super class of the |
| 6924 | // object to avoid doing a comparison we know will fail. |
| 6925 | NearLabel loop; |
| 6926 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6927 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6928 | GenerateReferenceLoadOneRegister(instruction, |
| 6929 | out_loc, |
| 6930 | super_offset, |
| 6931 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6932 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6933 | __ testl(out, out); |
| 6934 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6935 | __ j(kEqual, &done); |
| 6936 | if (cls.IsRegister()) { |
| 6937 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6938 | } else { |
| 6939 | DCHECK(cls.IsStackSlot()) << cls; |
| 6940 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6941 | } |
| 6942 | __ j(kNotEqual, &loop); |
| 6943 | __ movl(out, Immediate(1)); |
| 6944 | if (zero.IsLinked()) { |
| 6945 | __ jmp(&done); |
| 6946 | } |
| 6947 | break; |
| 6948 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6949 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6950 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6951 | ReadBarrierOption read_barrier_option = |
| 6952 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6953 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6954 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6955 | out_loc, |
| 6956 | obj_loc, |
| 6957 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6958 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6959 | // Walk over the class hierarchy to find a match. |
| 6960 | NearLabel loop, success; |
| 6961 | __ Bind(&loop); |
| 6962 | if (cls.IsRegister()) { |
| 6963 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6964 | } else { |
| 6965 | DCHECK(cls.IsStackSlot()) << cls; |
| 6966 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6967 | } |
| 6968 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6969 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6970 | GenerateReferenceLoadOneRegister(instruction, |
| 6971 | out_loc, |
| 6972 | super_offset, |
| 6973 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6974 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6975 | __ testl(out, out); |
| 6976 | __ j(kNotEqual, &loop); |
| 6977 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6978 | __ jmp(&done); |
| 6979 | __ Bind(&success); |
| 6980 | __ movl(out, Immediate(1)); |
| 6981 | if (zero.IsLinked()) { |
| 6982 | __ jmp(&done); |
| 6983 | } |
| 6984 | break; |
| 6985 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6986 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6987 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6988 | ReadBarrierOption read_barrier_option = |
| 6989 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6990 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6991 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6992 | out_loc, |
| 6993 | obj_loc, |
| 6994 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6995 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6996 | // Do an exact check. |
| 6997 | NearLabel exact_check; |
| 6998 | if (cls.IsRegister()) { |
| 6999 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7000 | } else { |
| 7001 | DCHECK(cls.IsStackSlot()) << cls; |
| 7002 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7003 | } |
| 7004 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7005 | // 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] | 7006 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7007 | GenerateReferenceLoadOneRegister(instruction, |
| 7008 | out_loc, |
| 7009 | component_offset, |
| 7010 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7011 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7012 | __ testl(out, out); |
| 7013 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7014 | __ j(kEqual, &done); |
| 7015 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 7016 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7017 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7018 | __ movl(out, Immediate(1)); |
| 7019 | __ jmp(&done); |
| 7020 | break; |
| 7021 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7022 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7023 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7024 | // No read barrier since the slow path will retry upon failure. |
| 7025 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7026 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7027 | out_loc, |
| 7028 | obj_loc, |
| 7029 | class_offset, |
| 7030 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7031 | if (cls.IsRegister()) { |
| 7032 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7033 | } else { |
| 7034 | DCHECK(cls.IsStackSlot()) << cls; |
| 7035 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7036 | } |
| 7037 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7038 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 7039 | instruction, /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7040 | codegen_->AddSlowPath(slow_path); |
| 7041 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7042 | __ movl(out, Immediate(1)); |
| 7043 | if (zero.IsLinked()) { |
| 7044 | __ jmp(&done); |
| 7045 | } |
| 7046 | break; |
| 7047 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7048 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7049 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7050 | case TypeCheckKind::kInterfaceCheck: { |
| 7051 | // 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] | 7052 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7053 | // cases. |
| 7054 | // |
| 7055 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7056 | // entry point without resorting to a type checking slow path |
| 7057 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7058 | // require to assign fixed registers for the inputs of this |
| 7059 | // HInstanceOf instruction (following the runtime calling |
| 7060 | // convention), which might be cluttered by the potential first |
| 7061 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7062 | // |
| 7063 | // TODO: Introduce a new runtime entry point taking the object |
| 7064 | // to test (instead of its class) as argument, and let it deal |
| 7065 | // with the read barrier issues. This will let us refactor this |
| 7066 | // case of the `switch` code as it was previously (with a direct |
| 7067 | // call to the runtime not using a type checking slow path). |
| 7068 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7069 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7070 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 7071 | instruction, /* is_fatal */ false); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7072 | codegen_->AddSlowPath(slow_path); |
| 7073 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7074 | if (zero.IsLinked()) { |
| 7075 | __ jmp(&done); |
| 7076 | } |
| 7077 | break; |
| 7078 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7079 | |
| 7080 | case TypeCheckKind::kBitstringCheck: { |
| 7081 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7082 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7083 | out_loc, |
| 7084 | obj_loc, |
| 7085 | class_offset, |
| 7086 | kWithoutReadBarrier); |
| 7087 | |
| 7088 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 7089 | __ j(kNotEqual, &zero); |
| 7090 | __ movl(out, Immediate(1)); |
| 7091 | __ jmp(&done); |
| 7092 | break; |
| 7093 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7094 | } |
| 7095 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7096 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7097 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7098 | __ xorl(out, out); |
| 7099 | } |
| 7100 | |
| 7101 | if (done.IsLinked()) { |
| 7102 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7103 | } |
| 7104 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7105 | if (slow_path != nullptr) { |
| 7106 | __ Bind(slow_path->GetExitLabel()); |
| 7107 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7108 | } |
| 7109 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7110 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7111 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7112 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7113 | LocationSummary* locations = |
| 7114 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7115 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7116 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7117 | // Require a register for the interface check since there is a loop that compares the class to |
| 7118 | // a memory address. |
| 7119 | locations->SetInAt(1, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7120 | } else if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7121 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7122 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7123 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7124 | } else { |
| 7125 | locations->SetInAt(1, Location::Any()); |
| 7126 | } |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 7127 | // 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] | 7128 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 7129 | } |
| 7130 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7131 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7132 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7133 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7134 | Location obj_loc = locations->InAt(0); |
| 7135 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7136 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7137 | Location temp_loc = locations->GetTemp(0); |
| 7138 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7139 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7140 | DCHECK_GE(num_temps, 1u); |
| 7141 | DCHECK_LE(num_temps, 2u); |
| 7142 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7143 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7144 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7145 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7146 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7147 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7148 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7149 | const uint32_t object_array_data_offset = |
| 7150 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7151 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7152 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7153 | SlowPathCode* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7154 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 7155 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7156 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7157 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7158 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7159 | // Avoid null check if we know obj is not null. |
| 7160 | if (instruction->MustDoNullCheck()) { |
| 7161 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7162 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7163 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7164 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7165 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7166 | case TypeCheckKind::kExactCheck: |
| 7167 | case TypeCheckKind::kArrayCheck: { |
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 | if (cls.IsRegister()) { |
| 7176 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7177 | } else { |
| 7178 | DCHECK(cls.IsStackSlot()) << cls; |
| 7179 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7180 | } |
| 7181 | // Jump to slow path for throwing the exception or doing a |
| 7182 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7183 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7184 | break; |
| 7185 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7186 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7187 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7188 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7189 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7190 | temp_loc, |
| 7191 | obj_loc, |
| 7192 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7193 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7194 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7195 | // If the class is abstract, we eagerly fetch the super class of the |
| 7196 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7197 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7198 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7199 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7200 | GenerateReferenceLoadOneRegister(instruction, |
| 7201 | temp_loc, |
| 7202 | super_offset, |
| 7203 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7204 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7205 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7206 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7207 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7208 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7209 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7210 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7211 | // Otherwise, compare the classes |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7212 | if (cls.IsRegister()) { |
| 7213 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7214 | } else { |
| 7215 | DCHECK(cls.IsStackSlot()) << cls; |
| 7216 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7217 | } |
| 7218 | __ j(kNotEqual, &loop); |
| 7219 | break; |
| 7220 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7221 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7222 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7223 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7224 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7225 | temp_loc, |
| 7226 | obj_loc, |
| 7227 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7228 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7229 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7230 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7231 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7232 | __ Bind(&loop); |
| 7233 | if (cls.IsRegister()) { |
| 7234 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7235 | } else { |
| 7236 | DCHECK(cls.IsStackSlot()) << cls; |
| 7237 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7238 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7239 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7240 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7241 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7242 | GenerateReferenceLoadOneRegister(instruction, |
| 7243 | temp_loc, |
| 7244 | super_offset, |
| 7245 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7246 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7247 | |
| 7248 | // If the class reference currently in `temp` is not null, jump |
| 7249 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7250 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7251 | __ j(kNotZero, &loop); |
| 7252 | // Otherwise, jump to the slow path to throw the exception.; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7253 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7254 | break; |
| 7255 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7256 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7257 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7258 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7259 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7260 | temp_loc, |
| 7261 | obj_loc, |
| 7262 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7263 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7264 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7265 | // Do an exact check. |
| 7266 | if (cls.IsRegister()) { |
| 7267 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7268 | } else { |
| 7269 | DCHECK(cls.IsStackSlot()) << cls; |
| 7270 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7271 | } |
| 7272 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7273 | |
| 7274 | // 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] | 7275 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7276 | GenerateReferenceLoadOneRegister(instruction, |
| 7277 | temp_loc, |
| 7278 | component_offset, |
| 7279 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7280 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7281 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7282 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 7283 | // throw the exception. Otherwise proceed with the check. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7284 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7285 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7286 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7287 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7288 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7289 | break; |
| 7290 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7291 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7292 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7293 | // 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] | 7294 | // We cannot directly call the CheckCast runtime entry point |
| 7295 | // without resorting to a type checking slow path here (i.e. by |
| 7296 | // calling InvokeRuntime directly), as it would require to |
| 7297 | // assign fixed registers for the inputs of this HInstanceOf |
| 7298 | // instruction (following the runtime calling convention), which |
| 7299 | // might be cluttered by the potential first read barrier |
| 7300 | // emission at the beginning of this method. |
| 7301 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7302 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7303 | |
| 7304 | case TypeCheckKind::kInterfaceCheck: { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7305 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. |
| 7306 | // We can not get false positives by doing this. |
| 7307 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7308 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7309 | temp_loc, |
| 7310 | obj_loc, |
| 7311 | class_offset, |
| 7312 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7313 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7314 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7315 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7316 | temp_loc, |
| 7317 | temp_loc, |
| 7318 | iftable_offset, |
| 7319 | kWithoutReadBarrier); |
| 7320 | // Iftable is never null. |
| 7321 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
| 7322 | // Maybe poison the `cls` for direct comparison with memory. |
| 7323 | __ MaybePoisonHeapReference(cls.AsRegister<Register>()); |
| 7324 | // Loop through the iftable and check if any class matches. |
| 7325 | NearLabel start_loop; |
| 7326 | __ Bind(&start_loop); |
| 7327 | // Need to subtract first to handle the empty array case. |
| 7328 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
| 7329 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 7330 | // Go to next interface if the classes do not match. |
| 7331 | __ cmpl(cls.AsRegister<Register>(), |
| 7332 | CodeGeneratorX86::ArrayAddress(temp, |
| 7333 | maybe_temp2_loc, |
| 7334 | TIMES_4, |
| 7335 | object_array_data_offset)); |
| 7336 | __ j(kNotEqual, &start_loop); |
| 7337 | // If `cls` was poisoned above, unpoison it. |
| 7338 | __ MaybeUnpoisonHeapReference(cls.AsRegister<Register>()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7339 | break; |
| 7340 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7341 | |
| 7342 | case TypeCheckKind::kBitstringCheck: { |
| 7343 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7344 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7345 | temp_loc, |
| 7346 | obj_loc, |
| 7347 | class_offset, |
| 7348 | kWithoutReadBarrier); |
| 7349 | |
| 7350 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 7351 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| 7352 | break; |
| 7353 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7354 | } |
| 7355 | __ Bind(&done); |
| 7356 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7357 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7358 | } |
| 7359 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7360 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7361 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7362 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7363 | InvokeRuntimeCallingConvention calling_convention; |
| 7364 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7365 | } |
| 7366 | |
| 7367 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7368 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 7369 | : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 7370 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7371 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7372 | if (instruction->IsEnter()) { |
| 7373 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7374 | } else { |
| 7375 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7376 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7377 | } |
| 7378 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7379 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 7380 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 7381 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 7382 | |
| 7383 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7384 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7385 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7386 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 7387 | || instruction->GetResultType() == DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7388 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7389 | locations->SetInAt(1, Location::Any()); |
| 7390 | locations->SetOut(Location::SameAsFirstInput()); |
| 7391 | } |
| 7392 | |
| 7393 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 7394 | HandleBitwiseOperation(instruction); |
| 7395 | } |
| 7396 | |
| 7397 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 7398 | HandleBitwiseOperation(instruction); |
| 7399 | } |
| 7400 | |
| 7401 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 7402 | HandleBitwiseOperation(instruction); |
| 7403 | } |
| 7404 | |
| 7405 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7406 | LocationSummary* locations = instruction->GetLocations(); |
| 7407 | Location first = locations->InAt(0); |
| 7408 | Location second = locations->InAt(1); |
| 7409 | DCHECK(first.Equals(locations->Out())); |
| 7410 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7411 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7412 | if (second.IsRegister()) { |
| 7413 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7414 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7415 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7416 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7417 | } else { |
| 7418 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7419 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7420 | } |
| 7421 | } else if (second.IsConstant()) { |
| 7422 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7423 | __ andl(first.AsRegister<Register>(), |
| 7424 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7425 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7426 | __ orl(first.AsRegister<Register>(), |
| 7427 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7428 | } else { |
| 7429 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7430 | __ xorl(first.AsRegister<Register>(), |
| 7431 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7432 | } |
| 7433 | } else { |
| 7434 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7435 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7436 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7437 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7438 | } else { |
| 7439 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7440 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7441 | } |
| 7442 | } |
| 7443 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7444 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7445 | if (second.IsRegisterPair()) { |
| 7446 | if (instruction->IsAnd()) { |
| 7447 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7448 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7449 | } else if (instruction->IsOr()) { |
| 7450 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7451 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7452 | } else { |
| 7453 | DCHECK(instruction->IsXor()); |
| 7454 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7455 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7456 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7457 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7458 | if (instruction->IsAnd()) { |
| 7459 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7460 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 7461 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7462 | } else if (instruction->IsOr()) { |
| 7463 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7464 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 7465 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7466 | } else { |
| 7467 | DCHECK(instruction->IsXor()); |
| 7468 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7469 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 7470 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7471 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7472 | } else { |
| 7473 | DCHECK(second.IsConstant()) << second; |
| 7474 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7475 | int32_t low_value = Low32Bits(value); |
| 7476 | int32_t high_value = High32Bits(value); |
| 7477 | Immediate low(low_value); |
| 7478 | Immediate high(high_value); |
| 7479 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7480 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7481 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7482 | if (low_value == 0) { |
| 7483 | __ xorl(first_low, first_low); |
| 7484 | } else if (low_value != -1) { |
| 7485 | __ andl(first_low, low); |
| 7486 | } |
| 7487 | if (high_value == 0) { |
| 7488 | __ xorl(first_high, first_high); |
| 7489 | } else if (high_value != -1) { |
| 7490 | __ andl(first_high, high); |
| 7491 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7492 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7493 | if (low_value != 0) { |
| 7494 | __ orl(first_low, low); |
| 7495 | } |
| 7496 | if (high_value != 0) { |
| 7497 | __ orl(first_high, high); |
| 7498 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7499 | } else { |
| 7500 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7501 | if (low_value != 0) { |
| 7502 | __ xorl(first_low, low); |
| 7503 | } |
| 7504 | if (high_value != 0) { |
| 7505 | __ xorl(first_high, high); |
| 7506 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7507 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7508 | } |
| 7509 | } |
| 7510 | } |
| 7511 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7512 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( |
| 7513 | HInstruction* instruction, |
| 7514 | Location out, |
| 7515 | uint32_t offset, |
| 7516 | Location maybe_temp, |
| 7517 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7518 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7519 | if (read_barrier_option == kWithReadBarrier) { |
| 7520 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7521 | if (kUseBakerReadBarrier) { |
| 7522 | // Load with fast path based Baker's read barrier. |
| 7523 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7524 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7525 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7526 | } else { |
| 7527 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7528 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7529 | // in the following move operation, as we will need it for the |
| 7530 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7531 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7532 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7533 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7534 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7535 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7536 | } |
| 7537 | } else { |
| 7538 | // Plain load with no read barrier. |
| 7539 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7540 | __ movl(out_reg, Address(out_reg, offset)); |
| 7541 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7542 | } |
| 7543 | } |
| 7544 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7545 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( |
| 7546 | HInstruction* instruction, |
| 7547 | Location out, |
| 7548 | Location obj, |
| 7549 | uint32_t offset, |
| 7550 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7551 | Register out_reg = out.AsRegister<Register>(); |
| 7552 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7553 | if (read_barrier_option == kWithReadBarrier) { |
| 7554 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7555 | if (kUseBakerReadBarrier) { |
| 7556 | // Load with fast path based Baker's read barrier. |
| 7557 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7558 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7559 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7560 | } else { |
| 7561 | // Load with slow path based read barrier. |
| 7562 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7563 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7564 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7565 | } |
| 7566 | } else { |
| 7567 | // Plain load with no read barrier. |
| 7568 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7569 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7570 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7571 | } |
| 7572 | } |
| 7573 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7574 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( |
| 7575 | HInstruction* instruction, |
| 7576 | Location root, |
| 7577 | const Address& address, |
| 7578 | Label* fixup_label, |
| 7579 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7580 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7581 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7582 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7583 | if (kUseBakerReadBarrier) { |
| 7584 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7585 | // Baker's read barrier are used: |
| 7586 | // |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7587 | // root = obj.field; |
| 7588 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7589 | // if (temp != null) { |
| 7590 | // root = temp(root) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7591 | // } |
| 7592 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7593 | // /* GcRoot<mirror::Object> */ root = *address |
| 7594 | __ movl(root_reg, address); |
| 7595 | if (fixup_label != nullptr) { |
| 7596 | __ Bind(fixup_label); |
| 7597 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7598 | static_assert( |
| 7599 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7600 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7601 | "have different sizes."); |
| 7602 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7603 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7604 | "have different sizes."); |
| 7605 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7606 | // Slow path marking the GC root `root`. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7607 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7608 | instruction, root, /* unpoison_ref_before_marking */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7609 | codegen_->AddSlowPath(slow_path); |
| 7610 | |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7611 | // Test the entrypoint (`Thread::Current()->pReadBarrierMarkReg ## root.reg()`). |
| 7612 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 7613 | Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(root.reg()); |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7614 | __ fs()->cmpl(Address::Absolute(entry_point_offset), Immediate(0)); |
| 7615 | // The entrypoint is null when the GC is not marking. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7616 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7617 | __ Bind(slow_path->GetExitLabel()); |
| 7618 | } else { |
| 7619 | // GC root loaded through a slow path for read barriers other |
| 7620 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7621 | // /* GcRoot<mirror::Object>* */ root = address |
| 7622 | __ leal(root_reg, address); |
| 7623 | if (fixup_label != nullptr) { |
| 7624 | __ Bind(fixup_label); |
| 7625 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7626 | // /* mirror::Object* */ root = root->Read() |
| 7627 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7628 | } |
| 7629 | } else { |
| 7630 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7631 | // /* GcRoot<mirror::Object> */ root = *address |
| 7632 | __ movl(root_reg, address); |
| 7633 | if (fixup_label != nullptr) { |
| 7634 | __ Bind(fixup_label); |
| 7635 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7636 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7637 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7638 | } |
| 7639 | } |
| 7640 | |
| 7641 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7642 | Location ref, |
| 7643 | Register obj, |
| 7644 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7645 | bool needs_null_check) { |
| 7646 | DCHECK(kEmitCompilerReadBarrier); |
| 7647 | DCHECK(kUseBakerReadBarrier); |
| 7648 | |
| 7649 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7650 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7651 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7652 | } |
| 7653 | |
| 7654 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7655 | Location ref, |
| 7656 | Register obj, |
| 7657 | uint32_t data_offset, |
| 7658 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7659 | bool needs_null_check) { |
| 7660 | DCHECK(kEmitCompilerReadBarrier); |
| 7661 | DCHECK(kUseBakerReadBarrier); |
| 7662 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7663 | static_assert( |
| 7664 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7665 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7666 | // /* HeapReference<Object> */ ref = |
| 7667 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7668 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7669 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7670 | } |
| 7671 | |
| 7672 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7673 | Location ref, |
| 7674 | Register obj, |
| 7675 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7676 | bool needs_null_check, |
| 7677 | bool always_update_field, |
| 7678 | Register* temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7679 | DCHECK(kEmitCompilerReadBarrier); |
| 7680 | DCHECK(kUseBakerReadBarrier); |
| 7681 | |
| 7682 | // In slow path based read barriers, the read barrier call is |
| 7683 | // inserted after the original load. However, in fast path based |
| 7684 | // Baker's read barriers, we need to perform the load of |
| 7685 | // mirror::Object::monitor_ *before* the original reference load. |
| 7686 | // This load-load ordering is required by the read barrier. |
| 7687 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7688 | // |
| 7689 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7690 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7691 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7692 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7693 | // if (is_gray) { |
| 7694 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7695 | // } |
| 7696 | // |
| 7697 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7698 | // slightly more complex as: |
| 7699 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7700 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7701 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7702 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7703 | // - it performs additional checks that we do not do here for |
| 7704 | // performance reasons. |
| 7705 | |
| 7706 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7707 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7708 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7709 | // 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] | 7710 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7711 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7712 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7713 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7714 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7715 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7716 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7717 | // ref = ReadBarrier::Mark(ref); |
| 7718 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7719 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7720 | if (needs_null_check) { |
| 7721 | MaybeRecordImplicitNullCheck(instruction); |
| 7722 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7723 | |
| 7724 | // Load fence to prevent load-load reordering. |
| 7725 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7726 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7727 | |
| 7728 | // The actual reference load. |
| 7729 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7730 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7731 | |
| 7732 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7733 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7734 | SlowPathCode* slow_path; |
| 7735 | if (always_update_field) { |
| 7736 | DCHECK(temp != nullptr); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7737 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7738 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp); |
| 7739 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7740 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7741 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 7742 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7743 | AddSlowPath(slow_path); |
| 7744 | |
| 7745 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7746 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7747 | |
| 7748 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7749 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7750 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7751 | __ Bind(slow_path->GetExitLabel()); |
| 7752 | } |
| 7753 | |
| 7754 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7755 | Location out, |
| 7756 | Location ref, |
| 7757 | Location obj, |
| 7758 | uint32_t offset, |
| 7759 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7760 | DCHECK(kEmitCompilerReadBarrier); |
| 7761 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7762 | // Insert a slow path based read barrier *after* the reference load. |
| 7763 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7764 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7765 | // reference will be carried out by the runtime within the slow |
| 7766 | // path. |
| 7767 | // |
| 7768 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7769 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7770 | // not used by the artReadBarrierSlow entry point. |
| 7771 | // |
| 7772 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7773 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7774 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 7775 | AddSlowPath(slow_path); |
| 7776 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7777 | __ jmp(slow_path->GetEntryLabel()); |
| 7778 | __ Bind(slow_path->GetExitLabel()); |
| 7779 | } |
| 7780 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7781 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7782 | Location out, |
| 7783 | Location ref, |
| 7784 | Location obj, |
| 7785 | uint32_t offset, |
| 7786 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7787 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7788 | // Baker's read barriers shall be handled by the fast path |
| 7789 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 7790 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7791 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7792 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7793 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7794 | } else if (kPoisonHeapReferences) { |
| 7795 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7796 | } |
| 7797 | } |
| 7798 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7799 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7800 | Location out, |
| 7801 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7802 | DCHECK(kEmitCompilerReadBarrier); |
| 7803 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7804 | // Insert a slow path based read barrier *after* the GC root load. |
| 7805 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7806 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7807 | // not need to do anything special for this here. |
| 7808 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7809 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7810 | AddSlowPath(slow_path); |
| 7811 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7812 | __ jmp(slow_path->GetEntryLabel()); |
| 7813 | __ Bind(slow_path->GetExitLabel()); |
| 7814 | } |
| 7815 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7816 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7817 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7818 | LOG(FATAL) << "Unreachable"; |
| 7819 | } |
| 7820 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7821 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7822 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7823 | LOG(FATAL) << "Unreachable"; |
| 7824 | } |
| 7825 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7826 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7827 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7828 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7829 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7830 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7831 | } |
| 7832 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7833 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7834 | int32_t lower_bound, |
| 7835 | uint32_t num_entries, |
| 7836 | HBasicBlock* switch_block, |
| 7837 | HBasicBlock* default_block) { |
| 7838 | // Figure out the correct compare values and jump conditions. |
| 7839 | // Handle the first compare/branch as a special case because it might |
| 7840 | // jump to the default case. |
| 7841 | DCHECK_GT(num_entries, 2u); |
| 7842 | Condition first_condition; |
| 7843 | uint32_t index; |
| 7844 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7845 | if (lower_bound != 0) { |
| 7846 | first_condition = kLess; |
| 7847 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7848 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7849 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7850 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7851 | index = 1; |
| 7852 | } else { |
| 7853 | // Handle all the compare/jumps below. |
| 7854 | first_condition = kBelow; |
| 7855 | index = 0; |
| 7856 | } |
| 7857 | |
| 7858 | // Handle the rest of the compare/jumps. |
| 7859 | for (; index + 1 < num_entries; index += 2) { |
| 7860 | int32_t compare_to_value = lower_bound + index + 1; |
| 7861 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7862 | // Jump to successors[index] if value < case_value[index]. |
| 7863 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7864 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7865 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7866 | } |
| 7867 | |
| 7868 | if (index != num_entries) { |
| 7869 | // There are an odd number of entries. Handle the last one. |
| 7870 | DCHECK_EQ(index + 1, num_entries); |
| 7871 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7872 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7873 | } |
| 7874 | |
| 7875 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7876 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7877 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7878 | } |
| 7879 | } |
| 7880 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7881 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7882 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7883 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7884 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7885 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7886 | |
| 7887 | GenPackedSwitchWithCompares(value_reg, |
| 7888 | lower_bound, |
| 7889 | num_entries, |
| 7890 | switch_instr->GetBlock(), |
| 7891 | switch_instr->GetDefaultBlock()); |
| 7892 | } |
| 7893 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7894 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7895 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7896 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7897 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7898 | |
| 7899 | // Constant area pointer. |
| 7900 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7901 | |
| 7902 | // And the temporary we need. |
| 7903 | locations->AddTemp(Location::RequiresRegister()); |
| 7904 | } |
| 7905 | |
| 7906 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7907 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7908 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7909 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7910 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7911 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7912 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7913 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7914 | GenPackedSwitchWithCompares(value_reg, |
| 7915 | lower_bound, |
| 7916 | num_entries, |
| 7917 | switch_instr->GetBlock(), |
| 7918 | default_block); |
| 7919 | return; |
| 7920 | } |
| 7921 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7922 | // Optimizing has a jump area. |
| 7923 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7924 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7925 | |
| 7926 | // Remove the bias, if needed. |
| 7927 | if (lower_bound != 0) { |
| 7928 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7929 | value_reg = temp_reg; |
| 7930 | } |
| 7931 | |
| 7932 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7933 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7934 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7935 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7936 | |
| 7937 | // We are in the range of the table. |
| 7938 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7939 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7940 | |
| 7941 | // Compute the actual target address by adding in constant_area. |
| 7942 | __ addl(temp_reg, constant_area); |
| 7943 | |
| 7944 | // And jump. |
| 7945 | __ jmp(temp_reg); |
| 7946 | } |
| 7947 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7948 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7949 | HX86ComputeBaseMethodAddress* insn) { |
| 7950 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7951 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7952 | locations->SetOut(Location::RequiresRegister()); |
| 7953 | } |
| 7954 | |
| 7955 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7956 | HX86ComputeBaseMethodAddress* insn) { |
| 7957 | LocationSummary* locations = insn->GetLocations(); |
| 7958 | Register reg = locations->Out().AsRegister<Register>(); |
| 7959 | |
| 7960 | // Generate call to next instruction. |
| 7961 | Label next_instruction; |
| 7962 | __ call(&next_instruction); |
| 7963 | __ Bind(&next_instruction); |
| 7964 | |
| 7965 | // Remember this offset for later use with constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7966 | codegen_->AddMethodAddressOffset(insn, GetAssembler()->CodeSize()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7967 | |
| 7968 | // Grab the return address off the stack. |
| 7969 | __ popl(reg); |
| 7970 | } |
| 7971 | |
| 7972 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7973 | HX86LoadFromConstantTable* insn) { |
| 7974 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7975 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7976 | |
| 7977 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7978 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7979 | |
| 7980 | // 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] | 7981 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7982 | return; |
| 7983 | } |
| 7984 | |
| 7985 | switch (insn->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7986 | case DataType::Type::kFloat32: |
| 7987 | case DataType::Type::kFloat64: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7988 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7989 | break; |
| 7990 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7991 | case DataType::Type::kInt32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7992 | locations->SetOut(Location::RequiresRegister()); |
| 7993 | break; |
| 7994 | |
| 7995 | default: |
| 7996 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7997 | } |
| 7998 | } |
| 7999 | |
| 8000 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 8001 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8002 | return; |
| 8003 | } |
| 8004 | |
| 8005 | LocationSummary* locations = insn->GetLocations(); |
| 8006 | Location out = locations->Out(); |
| 8007 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 8008 | HConstant *value = insn->GetConstant(); |
| 8009 | |
| 8010 | switch (insn->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8011 | case DataType::Type::kFloat32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8012 | __ movss(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8013 | codegen_->LiteralFloatAddress( |
| 8014 | value->AsFloatConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8015 | break; |
| 8016 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8017 | case DataType::Type::kFloat64: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8018 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8019 | codegen_->LiteralDoubleAddress( |
| 8020 | value->AsDoubleConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8021 | break; |
| 8022 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8023 | case DataType::Type::kInt32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8024 | __ movl(out.AsRegister<Register>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8025 | codegen_->LiteralInt32Address( |
| 8026 | value->AsIntConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8027 | break; |
| 8028 | |
| 8029 | default: |
| 8030 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 8031 | } |
| 8032 | } |
| 8033 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8034 | /** |
| 8035 | * Class to handle late fixup of offsets into constant area. |
| 8036 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 8037 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8038 | public: |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8039 | RIPFixup(CodeGeneratorX86& codegen, |
| 8040 | HX86ComputeBaseMethodAddress* base_method_address, |
| 8041 | size_t offset) |
| 8042 | : codegen_(&codegen), |
| 8043 | base_method_address_(base_method_address), |
| 8044 | offset_into_constant_area_(offset) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8045 | |
| 8046 | protected: |
| 8047 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 8048 | |
| 8049 | CodeGeneratorX86* codegen_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8050 | HX86ComputeBaseMethodAddress* base_method_address_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8051 | |
| 8052 | private: |
| 8053 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 8054 | // Patch the correct offset for the instruction. The place to patch is the |
| 8055 | // last 4 bytes of the instruction. |
| 8056 | // The value to patch is the distance from the offset in the constant area |
| 8057 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8058 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8059 | int32_t relative_position = |
| 8060 | constant_offset - codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8061 | |
| 8062 | // Patch in the right value. |
| 8063 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 8064 | } |
| 8065 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8066 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8067 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8068 | }; |
| 8069 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8070 | /** |
| 8071 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 8072 | * constant area. |
| 8073 | */ |
| 8074 | class JumpTableRIPFixup : public RIPFixup { |
| 8075 | public: |
| 8076 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8077 | : RIPFixup(codegen, switch_instr->GetBaseMethodAddress(), static_cast<size_t>(-1)), |
| 8078 | switch_instr_(switch_instr) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8079 | |
| 8080 | void CreateJumpTable() { |
| 8081 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 8082 | |
| 8083 | // Ensure that the reference to the jump table has the correct offset. |
| 8084 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 8085 | SetOffset(offset_in_constant_table); |
| 8086 | |
| 8087 | // The label values in the jump table are computed relative to the |
| 8088 | // instruction addressing the constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8089 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8090 | |
| 8091 | // Populate the jump table with the correct values for the jump table. |
| 8092 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 8093 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 8094 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 8095 | // The value that we want is the target offset - the position of the table. |
| 8096 | for (int32_t i = 0; i < num_entries; i++) { |
| 8097 | HBasicBlock* b = successors[i]; |
| 8098 | Label* l = codegen_->GetLabelOf(b); |
| 8099 | DCHECK(l->IsBound()); |
| 8100 | int32_t offset_to_block = l->Position() - relative_offset; |
| 8101 | assembler->AppendInt32(offset_to_block); |
| 8102 | } |
| 8103 | } |
| 8104 | |
| 8105 | private: |
| 8106 | const HX86PackedSwitch* switch_instr_; |
| 8107 | }; |
| 8108 | |
| 8109 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 8110 | // Generate the constant area if needed. |
| 8111 | X86Assembler* assembler = GetAssembler(); |
| 8112 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 8113 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 8114 | // byte values. |
| 8115 | assembler->Align(4, 0); |
| 8116 | constant_area_start_ = assembler->CodeSize(); |
| 8117 | |
| 8118 | // Populate any jump tables. |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8119 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8120 | jump_table->CreateJumpTable(); |
| 8121 | } |
| 8122 | |
| 8123 | // And now add the constant area to the generated code. |
| 8124 | assembler->AddConstantArea(); |
| 8125 | } |
| 8126 | |
| 8127 | // And finish up. |
| 8128 | CodeGenerator::Finalize(allocator); |
| 8129 | } |
| 8130 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8131 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, |
| 8132 | HX86ComputeBaseMethodAddress* method_base, |
| 8133 | Register reg) { |
| 8134 | AssemblerFixup* fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8135 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddDouble(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8136 | return Address(reg, kDummy32BitOffset, fixup); |
| 8137 | } |
| 8138 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8139 | Address CodeGeneratorX86::LiteralFloatAddress(float v, |
| 8140 | HX86ComputeBaseMethodAddress* method_base, |
| 8141 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8142 | AssemblerFixup* fixup = |
| 8143 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddFloat(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8144 | return Address(reg, kDummy32BitOffset, fixup); |
| 8145 | } |
| 8146 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8147 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, |
| 8148 | HX86ComputeBaseMethodAddress* method_base, |
| 8149 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8150 | AssemblerFixup* fixup = |
| 8151 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt32(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8152 | return Address(reg, kDummy32BitOffset, fixup); |
| 8153 | } |
| 8154 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8155 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, |
| 8156 | HX86ComputeBaseMethodAddress* method_base, |
| 8157 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8158 | AssemblerFixup* fixup = |
| 8159 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt64(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8160 | return Address(reg, kDummy32BitOffset, fixup); |
| 8161 | } |
| 8162 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 8163 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 8164 | if (value == 0) { |
| 8165 | __ xorl(dest, dest); |
| 8166 | } else { |
| 8167 | __ movl(dest, Immediate(value)); |
| 8168 | } |
| 8169 | } |
| 8170 | |
| 8171 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 8172 | if (value == 0) { |
| 8173 | __ testl(dest, dest); |
| 8174 | } else { |
| 8175 | __ cmpl(dest, Immediate(value)); |
| 8176 | } |
| 8177 | } |
| 8178 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8179 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 8180 | Register lhs_reg = lhs.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8181 | GenerateIntCompare(lhs_reg, rhs); |
| 8182 | } |
| 8183 | |
| 8184 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8185 | if (rhs.IsConstant()) { |
| 8186 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8187 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8188 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8189 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8190 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8191 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8192 | } |
| 8193 | } |
| 8194 | |
| 8195 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 8196 | Location index, |
| 8197 | ScaleFactor scale, |
| 8198 | uint32_t data_offset) { |
| 8199 | return index.IsConstant() ? |
| 8200 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 8201 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 8202 | } |
| 8203 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8204 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 8205 | Register reg, |
| 8206 | Register value) { |
| 8207 | // Create a fixup to be used to create and address the jump table. |
| 8208 | JumpTableRIPFixup* table_fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8209 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8210 | |
| 8211 | // We have to populate the jump tables. |
| 8212 | fixups_to_jump_tables_.push_back(table_fixup); |
| 8213 | |
| 8214 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 8215 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 8216 | } |
| 8217 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8218 | // TODO: target as memory. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8219 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, DataType::Type type) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8220 | if (!target.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8221 | DCHECK_EQ(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8222 | return; |
| 8223 | } |
| 8224 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8225 | DCHECK_NE(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8226 | |
| 8227 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 8228 | if (target.Equals(return_loc)) { |
| 8229 | return; |
| 8230 | } |
| 8231 | |
| 8232 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 8233 | // with the else branch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8234 | if (type == DataType::Type::kInt64) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8235 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8236 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), DataType::Type::kInt32, nullptr); |
| 8237 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), DataType::Type::kInt32, nullptr); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8238 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8239 | } else { |
| 8240 | // Let the parallel move resolver take care of all of this. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8241 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8242 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 8243 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8244 | } |
| 8245 | } |
| 8246 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8247 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, |
| 8248 | const uint8_t* roots_data, |
| 8249 | const PatchInfo<Label>& info, |
| 8250 | uint64_t index_in_table) const { |
| 8251 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 8252 | uintptr_t address = |
| 8253 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 8254 | typedef __attribute__((__aligned__(1))) uint32_t unaligned_uint32_t; |
| 8255 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 8256 | dchecked_integral_cast<uint32_t>(address); |
| 8257 | } |
| 8258 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8259 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 8260 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8261 | 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] | 8262 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8263 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8264 | } |
| 8265 | |
| 8266 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8267 | 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] | 8268 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8269 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8270 | } |
| 8271 | } |
| 8272 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8273 | void LocationsBuilderX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 8274 | ATTRIBUTE_UNUSED) { |
| 8275 | LOG(FATAL) << "Unreachable"; |
| 8276 | } |
| 8277 | |
| 8278 | void InstructionCodeGeneratorX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 8279 | ATTRIBUTE_UNUSED) { |
| 8280 | LOG(FATAL) << "Unreachable"; |
| 8281 | } |
| 8282 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 8283 | #undef __ |
| 8284 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 8285 | } // namespace x86 |
| 8286 | } // namespace art |