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" |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 20 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 21 | #include "compiled_method.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 25 | #include "intrinsics.h" |
| 26 | #include "intrinsics_x86.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 27 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 28 | #include "mirror/class-inl.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 29 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 30 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 31 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 32 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 33 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 34 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 36 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 37 | template<class MirrorType> |
| 38 | class GcRoot; |
| 39 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 40 | namespace x86 { |
| 41 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 42 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 43 | static constexpr Register kMethodRegisterArgument = EAX; |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 44 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 45 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 46 | static constexpr int kC2ConditionMask = 0x400; |
| 47 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 48 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 49 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 50 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 51 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 52 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86PointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 53 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 54 | class NullCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 55 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 56 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 57 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 58 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 59 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 60 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 61 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 62 | // Live registers will be restored in the catch block if caught. |
| 63 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 64 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 65 | x86_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 66 | instruction_, |
| 67 | instruction_->GetDexPc(), |
| 68 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 69 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 72 | bool IsFatal() const OVERRIDE { return true; } |
| 73 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 74 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 75 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 76 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 77 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 78 | }; |
| 79 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 80 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 81 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 82 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 83 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 84 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 85 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 86 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 87 | x86_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 88 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 91 | bool IsFatal() const OVERRIDE { return true; } |
| 92 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 93 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 94 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 95 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 96 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 97 | }; |
| 98 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 99 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 100 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 101 | DivRemMinusOneSlowPathX86(HInstruction* instruction, Register reg, bool is_div) |
| 102 | : SlowPathCode(instruction), reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 104 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 105 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 106 | if (is_div_) { |
| 107 | __ negl(reg_); |
| 108 | } else { |
| 109 | __ movl(reg_, Immediate(0)); |
| 110 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 | __ jmp(GetExitLabel()); |
| 112 | } |
| 113 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 114 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 115 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 116 | private: |
| 117 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 118 | bool is_div_; |
| 119 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 120 | }; |
| 121 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 122 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 123 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 124 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 125 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 126 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 127 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 128 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 129 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 130 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 131 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 132 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 133 | // Live registers will be restored in the catch block if caught. |
| 134 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 135 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 136 | |
| 137 | // Are we using an array length from memory? |
| 138 | HInstruction* array_length = instruction_->InputAt(1); |
| 139 | Location length_loc = locations->InAt(1); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 140 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 141 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 142 | // Load the array length into our temporary. |
| 143 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 144 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 145 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| 146 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 147 | // Check for conflicts with index. |
| 148 | if (length_loc.Equals(locations->InAt(0))) { |
| 149 | // We know we aren't using parameter 2. |
| 150 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 151 | } |
| 152 | __ movl(length_loc.AsRegister<Register>(), array_len); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 153 | if (mirror::kUseStringCompression) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 154 | __ shrl(length_loc.AsRegister<Register>(), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 155 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 156 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 157 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 158 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 159 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 160 | Primitive::kPrimInt, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 161 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 162 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 163 | Primitive::kPrimInt); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 164 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 165 | ? kQuickThrowStringBounds |
| 166 | : kQuickThrowArrayBounds; |
| 167 | x86_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 168 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 169 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 170 | } |
| 171 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 172 | bool IsFatal() const OVERRIDE { return true; } |
| 173 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 174 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 175 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 176 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 177 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 178 | }; |
| 179 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 180 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 181 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 182 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 183 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 184 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 185 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 186 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 187 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 188 | x86_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 189 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 190 | if (successor_ == nullptr) { |
| 191 | __ jmp(GetReturnLabel()); |
| 192 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 193 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 194 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 197 | Label* GetReturnLabel() { |
| 198 | DCHECK(successor_ == nullptr); |
| 199 | return &return_label_; |
| 200 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 201 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 202 | HBasicBlock* GetSuccessor() const { |
| 203 | return successor_; |
| 204 | } |
| 205 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 206 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 207 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 208 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 209 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 210 | Label return_label_; |
| 211 | |
| 212 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 213 | }; |
| 214 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 215 | class LoadStringSlowPathX86 : public SlowPathCode { |
| 216 | public: |
| 217 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} |
| 218 | |
| 219 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 220 | LocationSummary* locations = instruction_->GetLocations(); |
| 221 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 222 | |
| 223 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 224 | __ Bind(GetEntryLabel()); |
| 225 | SaveLiveRegisters(codegen, locations); |
| 226 | |
| 227 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 228 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex().index_; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 229 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index)); |
| 230 | x86_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 231 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 232 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 233 | RestoreLiveRegisters(codegen, locations); |
| 234 | |
| 235 | // Store the resolved String to the BSS entry. |
| 236 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 237 | __ movl(Address(method_address, CodeGeneratorX86::kDummy32BitOffset), |
| 238 | locations->Out().AsRegister<Register>()); |
| 239 | Label* fixup_label = x86_codegen->NewStringBssEntryPatch(instruction_->AsLoadString()); |
| 240 | __ Bind(fixup_label); |
| 241 | |
| 242 | __ jmp(GetExitLabel()); |
| 243 | } |
| 244 | |
| 245 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 246 | |
| 247 | private: |
| 248 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 249 | }; |
| 250 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 251 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 252 | public: |
| 253 | LoadClassSlowPathX86(HLoadClass* cls, |
| 254 | HInstruction* at, |
| 255 | uint32_t dex_pc, |
| 256 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 257 | : SlowPathCode(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 258 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 259 | } |
| 260 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 261 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 262 | LocationSummary* locations = at_->GetLocations(); |
| 263 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 264 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 265 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 266 | |
| 267 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 268 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex().index_)); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 269 | x86_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage |
| 270 | : kQuickInitializeType, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 271 | at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 272 | if (do_clinit_) { |
| 273 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 274 | } else { |
| 275 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 276 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 277 | |
| 278 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 279 | Location out = locations->Out(); |
| 280 | if (out.IsValid()) { |
| 281 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 282 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 283 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 284 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 285 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 286 | __ jmp(GetExitLabel()); |
| 287 | } |
| 288 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 289 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 290 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 291 | private: |
| 292 | // The class this slow path will load. |
| 293 | HLoadClass* const cls_; |
| 294 | |
| 295 | // The instruction where this slow path is happening. |
| 296 | // (Might be the load class or an initialization check). |
| 297 | HInstruction* const at_; |
| 298 | |
| 299 | // The dex PC of `at_`. |
| 300 | const uint32_t dex_pc_; |
| 301 | |
| 302 | // Whether to initialize the class. |
| 303 | const bool do_clinit_; |
| 304 | |
| 305 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 306 | }; |
| 307 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 308 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 309 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 310 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 311 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 312 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 313 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 314 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 315 | DCHECK(instruction_->IsCheckCast() |
| 316 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 317 | |
| 318 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 319 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 320 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 321 | if (!is_fatal_) { |
| 322 | SaveLiveRegisters(codegen, locations); |
| 323 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 324 | |
| 325 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 326 | // move resolver. |
| 327 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 328 | x86_codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 329 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 330 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 331 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 332 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 333 | Primitive::kPrimNot); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 334 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 335 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 336 | instruction_, |
| 337 | instruction_->GetDexPc(), |
| 338 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 339 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 340 | } else { |
| 341 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 342 | x86_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 343 | instruction_, |
| 344 | instruction_->GetDexPc(), |
| 345 | this); |
| 346 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 349 | if (!is_fatal_) { |
| 350 | if (instruction_->IsInstanceOf()) { |
| 351 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 352 | } |
| 353 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 354 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 355 | __ jmp(GetExitLabel()); |
| 356 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 359 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 360 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 361 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 362 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 363 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 364 | |
| 365 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 366 | }; |
| 367 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 368 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 369 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 370 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 371 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 372 | |
| 373 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 374 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 375 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 376 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 377 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 380 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 381 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 382 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 383 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 384 | }; |
| 385 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 386 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 387 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 388 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 389 | |
| 390 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 391 | LocationSummary* locations = instruction_->GetLocations(); |
| 392 | __ Bind(GetEntryLabel()); |
| 393 | SaveLiveRegisters(codegen, locations); |
| 394 | |
| 395 | InvokeRuntimeCallingConvention calling_convention; |
| 396 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 397 | parallel_move.AddMove( |
| 398 | locations->InAt(0), |
| 399 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 400 | Primitive::kPrimNot, |
| 401 | nullptr); |
| 402 | parallel_move.AddMove( |
| 403 | locations->InAt(1), |
| 404 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 405 | Primitive::kPrimInt, |
| 406 | nullptr); |
| 407 | parallel_move.AddMove( |
| 408 | locations->InAt(2), |
| 409 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 410 | Primitive::kPrimNot, |
| 411 | nullptr); |
| 412 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 413 | |
| 414 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 415 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 416 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 417 | RestoreLiveRegisters(codegen, locations); |
| 418 | __ jmp(GetExitLabel()); |
| 419 | } |
| 420 | |
| 421 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 422 | |
| 423 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 424 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 425 | }; |
| 426 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 427 | // Slow path marking an object reference `ref` during a read |
| 428 | // barrier. The field `obj.field` in the object `obj` holding this |
| 429 | // reference does not get updated by this slow path after marking (see |
| 430 | // ReadBarrierMarkAndUpdateFieldSlowPathX86 below for that). |
| 431 | // |
| 432 | // This means that after the execution of this slow path, `ref` will |
| 433 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 434 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 435 | // probably still be a from-space reference (unless it gets updated by |
| 436 | // another thread, or if another thread installed another object |
| 437 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 438 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 439 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 440 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, |
| 441 | Location ref, |
| 442 | bool unpoison_ref_before_marking) |
| 443 | : SlowPathCode(instruction), |
| 444 | ref_(ref), |
| 445 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 446 | DCHECK(kEmitCompilerReadBarrier); |
| 447 | } |
| 448 | |
| 449 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 450 | |
| 451 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 452 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 453 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 454 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 455 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 456 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 457 | instruction_->IsStaticFieldGet() || |
| 458 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 459 | instruction_->IsArraySet() || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 460 | instruction_->IsLoadClass() || |
| 461 | instruction_->IsLoadString() || |
| 462 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 463 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 464 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 465 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 466 | << "Unexpected instruction in read barrier marking slow path: " |
| 467 | << instruction_->DebugName(); |
| 468 | |
| 469 | __ Bind(GetEntryLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 470 | if (unpoison_ref_before_marking_) { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 471 | // Object* ref = ref_addr->AsMirrorPtr() |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 472 | __ MaybeUnpoisonHeapReference(ref_reg); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 473 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 474 | // No need to save live registers; it's taken care of by the |
| 475 | // entrypoint. Also, there is no need to update the stack mask, |
| 476 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 477 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 478 | DCHECK_NE(ref_reg, ESP); |
| 479 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 480 | // "Compact" slow path, saving two moves. |
| 481 | // |
| 482 | // Instead of using the standard runtime calling convention (input |
| 483 | // and output in EAX): |
| 484 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 485 | // EAX <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 486 | // EAX <- ReadBarrierMark(EAX) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 487 | // ref <- EAX |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 488 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 489 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 490 | // of a dedicated entrypoint: |
| 491 | // |
| 492 | // rX <- ReadBarrierMarkRegX(rX) |
| 493 | // |
| 494 | int32_t entry_point_offset = |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 495 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 496 | // This runtime call does not require a stack map. |
| 497 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 498 | __ jmp(GetExitLabel()); |
| 499 | } |
| 500 | |
| 501 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 502 | // The location (register) of the marked object reference. |
| 503 | const Location ref_; |
| 504 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 505 | const bool unpoison_ref_before_marking_; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 506 | |
| 507 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 508 | }; |
| 509 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 510 | // Slow path marking an object reference `ref` during a read barrier, |
| 511 | // and if needed, atomically updating the field `obj.field` in the |
| 512 | // object `obj` holding this reference after marking (contrary to |
| 513 | // ReadBarrierMarkSlowPathX86 above, which never tries to update |
| 514 | // `obj.field`). |
| 515 | // |
| 516 | // This means that after the execution of this slow path, both `ref` |
| 517 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 518 | // hold the same to-space reference (unless another thread installed |
| 519 | // another object reference (different from `ref`) in `obj.field`). |
| 520 | class ReadBarrierMarkAndUpdateFieldSlowPathX86 : public SlowPathCode { |
| 521 | public: |
| 522 | ReadBarrierMarkAndUpdateFieldSlowPathX86(HInstruction* instruction, |
| 523 | Location ref, |
| 524 | Register obj, |
| 525 | const Address& field_addr, |
| 526 | bool unpoison_ref_before_marking, |
| 527 | Register temp) |
| 528 | : SlowPathCode(instruction), |
| 529 | ref_(ref), |
| 530 | obj_(obj), |
| 531 | field_addr_(field_addr), |
| 532 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 533 | temp_(temp) { |
| 534 | DCHECK(kEmitCompilerReadBarrier); |
| 535 | } |
| 536 | |
| 537 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkAndUpdateFieldSlowPathX86"; } |
| 538 | |
| 539 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 540 | LocationSummary* locations = instruction_->GetLocations(); |
| 541 | Register ref_reg = ref_.AsRegister<Register>(); |
| 542 | DCHECK(locations->CanCall()); |
| 543 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 544 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 545 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 546 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 547 | << instruction_->DebugName(); |
| 548 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 549 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 550 | |
| 551 | __ Bind(GetEntryLabel()); |
| 552 | if (unpoison_ref_before_marking_) { |
| 553 | // Object* ref = ref_addr->AsMirrorPtr() |
| 554 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 555 | } |
| 556 | |
| 557 | // Save the old (unpoisoned) reference. |
| 558 | __ movl(temp_, ref_reg); |
| 559 | |
| 560 | // No need to save live registers; it's taken care of by the |
| 561 | // entrypoint. Also, there is no need to update the stack mask, |
| 562 | // as this runtime call will not trigger a garbage collection. |
| 563 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 564 | DCHECK_NE(ref_reg, ESP); |
| 565 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 566 | // "Compact" slow path, saving two moves. |
| 567 | // |
| 568 | // Instead of using the standard runtime calling convention (input |
| 569 | // and output in EAX): |
| 570 | // |
| 571 | // EAX <- ref |
| 572 | // EAX <- ReadBarrierMark(EAX) |
| 573 | // ref <- EAX |
| 574 | // |
| 575 | // we just use rX (the register containing `ref`) as input and output |
| 576 | // of a dedicated entrypoint: |
| 577 | // |
| 578 | // rX <- ReadBarrierMarkRegX(rX) |
| 579 | // |
| 580 | int32_t entry_point_offset = |
| 581 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
| 582 | // This runtime call does not require a stack map. |
| 583 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 584 | |
| 585 | // If the new reference is different from the old reference, |
| 586 | // update the field in the holder (`*field_addr`). |
| 587 | // |
| 588 | // Note that this field could also hold a different object, if |
| 589 | // another thread had concurrently changed it. In that case, the |
| 590 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 591 | // operation below would abort the CAS, leaving the field as-is. |
| 592 | NearLabel done; |
| 593 | __ cmpl(temp_, ref_reg); |
| 594 | __ j(kEqual, &done); |
| 595 | |
| 596 | // Update the the holder's field atomically. This may fail if |
| 597 | // mutator updates before us, but it's OK. This is achieved |
| 598 | // using a strong compare-and-set (CAS) operation with relaxed |
| 599 | // memory synchronization ordering, where the expected value is |
| 600 | // the old reference and the desired value is the new reference. |
| 601 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 602 | // instruction, which requires the expected value (the old |
| 603 | // reference) to be in EAX. Save EAX beforehand, and move the |
| 604 | // expected value (stored in `temp_`) into EAX. |
| 605 | __ pushl(EAX); |
| 606 | __ movl(EAX, temp_); |
| 607 | |
| 608 | // Convenience aliases. |
| 609 | Register base = obj_; |
| 610 | Register expected = EAX; |
| 611 | Register value = ref_reg; |
| 612 | |
| 613 | bool base_equals_value = (base == value); |
| 614 | if (kPoisonHeapReferences) { |
| 615 | if (base_equals_value) { |
| 616 | // If `base` and `value` are the same register location, move |
| 617 | // `value` to a temporary register. This way, poisoning |
| 618 | // `value` won't invalidate `base`. |
| 619 | value = temp_; |
| 620 | __ movl(value, base); |
| 621 | } |
| 622 | |
| 623 | // Check that the register allocator did not assign the location |
| 624 | // of `expected` (EAX) to `value` nor to `base`, so that heap |
| 625 | // poisoning (when enabled) works as intended below. |
| 626 | // - If `value` were equal to `expected`, both references would |
| 627 | // be poisoned twice, meaning they would not be poisoned at |
| 628 | // all, as heap poisoning uses address negation. |
| 629 | // - If `base` were equal to `expected`, poisoning `expected` |
| 630 | // would invalidate `base`. |
| 631 | DCHECK_NE(value, expected); |
| 632 | DCHECK_NE(base, expected); |
| 633 | |
| 634 | __ PoisonHeapReference(expected); |
| 635 | __ PoisonHeapReference(value); |
| 636 | } |
| 637 | |
| 638 | __ LockCmpxchgl(field_addr_, value); |
| 639 | |
| 640 | // If heap poisoning is enabled, we need to unpoison the values |
| 641 | // that were poisoned earlier. |
| 642 | if (kPoisonHeapReferences) { |
| 643 | if (base_equals_value) { |
| 644 | // `value` has been moved to a temporary register, no need |
| 645 | // to unpoison it. |
| 646 | } else { |
| 647 | __ UnpoisonHeapReference(value); |
| 648 | } |
| 649 | // No need to unpoison `expected` (EAX), as it is be overwritten below. |
| 650 | } |
| 651 | |
| 652 | // Restore EAX. |
| 653 | __ popl(EAX); |
| 654 | |
| 655 | __ Bind(&done); |
| 656 | __ jmp(GetExitLabel()); |
| 657 | } |
| 658 | |
| 659 | private: |
| 660 | // The location (register) of the marked object reference. |
| 661 | const Location ref_; |
| 662 | // The register containing the object holding the marked object reference field. |
| 663 | const Register obj_; |
| 664 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 665 | const Address field_addr_; |
| 666 | |
| 667 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 668 | const bool unpoison_ref_before_marking_; |
| 669 | |
| 670 | const Register temp_; |
| 671 | |
| 672 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86); |
| 673 | }; |
| 674 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 675 | // Slow path generating a read barrier for a heap reference. |
| 676 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 677 | public: |
| 678 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 679 | Location out, |
| 680 | Location ref, |
| 681 | Location obj, |
| 682 | uint32_t offset, |
| 683 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 684 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 685 | out_(out), |
| 686 | ref_(ref), |
| 687 | obj_(obj), |
| 688 | offset_(offset), |
| 689 | index_(index) { |
| 690 | DCHECK(kEmitCompilerReadBarrier); |
| 691 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 692 | // has been overwritten by (or after) the heap object reference load |
| 693 | // to be instrumented, e.g.: |
| 694 | // |
| 695 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 696 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 697 | // |
| 698 | // In that case, we have lost the information about the original |
| 699 | // object, and the emitted read barrier cannot work properly. |
| 700 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 701 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 702 | } |
| 703 | |
| 704 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 705 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 706 | LocationSummary* locations = instruction_->GetLocations(); |
| 707 | Register reg_out = out_.AsRegister<Register>(); |
| 708 | DCHECK(locations->CanCall()); |
| 709 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 710 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 711 | instruction_->IsStaticFieldGet() || |
| 712 | instruction_->IsArrayGet() || |
| 713 | instruction_->IsInstanceOf() || |
| 714 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 715 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 716 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 717 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 718 | |
| 719 | __ Bind(GetEntryLabel()); |
| 720 | SaveLiveRegisters(codegen, locations); |
| 721 | |
| 722 | // We may have to change the index's value, but as `index_` is a |
| 723 | // constant member (like other "inputs" of this slow path), |
| 724 | // introduce a copy of it, `index`. |
| 725 | Location index = index_; |
| 726 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 727 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 728 | if (instruction_->IsArrayGet()) { |
| 729 | // Compute the actual memory offset and store it in `index`. |
| 730 | Register index_reg = index_.AsRegister<Register>(); |
| 731 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 732 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 733 | // We are about to change the value of `index_reg` (see the |
| 734 | // calls to art::x86::X86Assembler::shll and |
| 735 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 736 | // not been saved by the previous call to |
| 737 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 738 | // callee-save register -- |
| 739 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 740 | // callee-save registers, as it has been designed with the |
| 741 | // assumption that callee-save registers are supposed to be |
| 742 | // handled by the called function. So, as a callee-save |
| 743 | // register, `index_reg` _would_ eventually be saved onto |
| 744 | // the stack, but it would be too late: we would have |
| 745 | // changed its value earlier. Therefore, we manually save |
| 746 | // it here into another freely available register, |
| 747 | // `free_reg`, chosen of course among the caller-save |
| 748 | // registers (as a callee-save `free_reg` register would |
| 749 | // exhibit the same problem). |
| 750 | // |
| 751 | // Note we could have requested a temporary register from |
| 752 | // the register allocator instead; but we prefer not to, as |
| 753 | // this is a slow path, and we know we can find a |
| 754 | // caller-save register that is available. |
| 755 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 756 | __ movl(free_reg, index_reg); |
| 757 | index_reg = free_reg; |
| 758 | index = Location::RegisterLocation(index_reg); |
| 759 | } else { |
| 760 | // The initial register stored in `index_` has already been |
| 761 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 762 | // (as it is not a callee-save register), so we can freely |
| 763 | // use it. |
| 764 | } |
| 765 | // Shifting the index value contained in `index_reg` by the scale |
| 766 | // factor (2) cannot overflow in practice, as the runtime is |
| 767 | // unable to allocate object arrays with a size larger than |
| 768 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 769 | __ shll(index_reg, Immediate(TIMES_4)); |
| 770 | static_assert( |
| 771 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 772 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 773 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 774 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 775 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 776 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 777 | // (as in the case of ArrayGet), as it is actually an offset |
| 778 | // to an object field within an object. |
| 779 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 780 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 781 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 782 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 783 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 784 | DCHECK_EQ(offset_, 0U); |
| 785 | DCHECK(index_.IsRegisterPair()); |
| 786 | // UnsafeGet's offset location is a register pair, the low |
| 787 | // part contains the correct offset. |
| 788 | index = index_.ToLow(); |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | // We're moving two or three locations to locations that could |
| 793 | // overlap, so we need a parallel move resolver. |
| 794 | InvokeRuntimeCallingConvention calling_convention; |
| 795 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 796 | parallel_move.AddMove(ref_, |
| 797 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 798 | Primitive::kPrimNot, |
| 799 | nullptr); |
| 800 | parallel_move.AddMove(obj_, |
| 801 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 802 | Primitive::kPrimNot, |
| 803 | nullptr); |
| 804 | if (index.IsValid()) { |
| 805 | parallel_move.AddMove(index, |
| 806 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 807 | Primitive::kPrimInt, |
| 808 | nullptr); |
| 809 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 810 | } else { |
| 811 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 812 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 813 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 814 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 815 | CheckEntrypointTypes< |
| 816 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 817 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 818 | |
| 819 | RestoreLiveRegisters(codegen, locations); |
| 820 | __ jmp(GetExitLabel()); |
| 821 | } |
| 822 | |
| 823 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 824 | |
| 825 | private: |
| 826 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 827 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 828 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 829 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 830 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 831 | return static_cast<Register>(i); |
| 832 | } |
| 833 | } |
| 834 | // We shall never fail to find a free caller-save register, as |
| 835 | // there are more than two core caller-save registers on x86 |
| 836 | // (meaning it is possible to find one which is different from |
| 837 | // `ref` and `obj`). |
| 838 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 839 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 840 | UNREACHABLE(); |
| 841 | } |
| 842 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 843 | const Location out_; |
| 844 | const Location ref_; |
| 845 | const Location obj_; |
| 846 | const uint32_t offset_; |
| 847 | // An additional location containing an index to an array. |
| 848 | // Only used for HArrayGet and the UnsafeGetObject & |
| 849 | // UnsafeGetObjectVolatile intrinsics. |
| 850 | const Location index_; |
| 851 | |
| 852 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 853 | }; |
| 854 | |
| 855 | // Slow path generating a read barrier for a GC root. |
| 856 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 857 | public: |
| 858 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 859 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 860 | DCHECK(kEmitCompilerReadBarrier); |
| 861 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 862 | |
| 863 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 864 | LocationSummary* locations = instruction_->GetLocations(); |
| 865 | Register reg_out = out_.AsRegister<Register>(); |
| 866 | DCHECK(locations->CanCall()); |
| 867 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 868 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 869 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 870 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 871 | |
| 872 | __ Bind(GetEntryLabel()); |
| 873 | SaveLiveRegisters(codegen, locations); |
| 874 | |
| 875 | InvokeRuntimeCallingConvention calling_convention; |
| 876 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 877 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 878 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 879 | instruction_, |
| 880 | instruction_->GetDexPc(), |
| 881 | this); |
| 882 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 883 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 884 | |
| 885 | RestoreLiveRegisters(codegen, locations); |
| 886 | __ jmp(GetExitLabel()); |
| 887 | } |
| 888 | |
| 889 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 890 | |
| 891 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 892 | const Location out_; |
| 893 | const Location root_; |
| 894 | |
| 895 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 896 | }; |
| 897 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 898 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 899 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 900 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 901 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 902 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 903 | switch (cond) { |
| 904 | case kCondEQ: return kEqual; |
| 905 | case kCondNE: return kNotEqual; |
| 906 | case kCondLT: return kLess; |
| 907 | case kCondLE: return kLessEqual; |
| 908 | case kCondGT: return kGreater; |
| 909 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 910 | case kCondB: return kBelow; |
| 911 | case kCondBE: return kBelowEqual; |
| 912 | case kCondA: return kAbove; |
| 913 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 914 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 915 | LOG(FATAL) << "Unreachable"; |
| 916 | UNREACHABLE(); |
| 917 | } |
| 918 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 919 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 920 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 921 | switch (cond) { |
| 922 | case kCondEQ: return kEqual; |
| 923 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 924 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 925 | case kCondLT: return kBelow; |
| 926 | case kCondLE: return kBelowEqual; |
| 927 | case kCondGT: return kAbove; |
| 928 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 929 | // Unsigned remain unchanged. |
| 930 | case kCondB: return kBelow; |
| 931 | case kCondBE: return kBelowEqual; |
| 932 | case kCondA: return kAbove; |
| 933 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 934 | } |
| 935 | LOG(FATAL) << "Unreachable"; |
| 936 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 937 | } |
| 938 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 939 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 940 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 944 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 945 | } |
| 946 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 947 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 948 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 949 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 950 | } |
| 951 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 952 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 953 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 954 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 955 | } |
| 956 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 957 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 958 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 959 | return GetFloatingPointSpillSlotSize(); |
| 960 | } |
| 961 | |
| 962 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 963 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 964 | return GetFloatingPointSpillSlotSize(); |
| 965 | } |
| 966 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 967 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 968 | HInstruction* instruction, |
| 969 | uint32_t dex_pc, |
| 970 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 971 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 972 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 973 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 974 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 975 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 976 | } |
| 977 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 978 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 979 | HInstruction* instruction, |
| 980 | SlowPathCode* slow_path) { |
| 981 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 982 | GenerateInvokeRuntime(entry_point_offset); |
| 983 | } |
| 984 | |
| 985 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 986 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 987 | } |
| 988 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 989 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 990 | const X86InstructionSetFeatures& isa_features, |
| 991 | const CompilerOptions& compiler_options, |
| 992 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 993 | : CodeGenerator(graph, |
| 994 | kNumberOfCpuRegisters, |
| 995 | kNumberOfXmmRegisters, |
| 996 | kNumberOfRegisterPairs, |
| 997 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 998 | arraysize(kCoreCalleeSaves)) |
| 999 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1000 | 0, |
| 1001 | compiler_options, |
| 1002 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1003 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1004 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1005 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1006 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1007 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1008 | isa_features_(isa_features), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1009 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1010 | simple_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1011 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1012 | type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1013 | jit_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1014 | jit_class_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1015 | constant_area_start_(-1), |
| 1016 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1017 | method_address_offset_(-1) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1018 | // Use a fake return address register to mimic Quick. |
| 1019 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1020 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1021 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1022 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1023 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1024 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1025 | } |
| 1026 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1027 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1028 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1029 | assembler_(codegen->GetAssembler()), |
| 1030 | codegen_(codegen) {} |
| 1031 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1032 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1033 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1034 | } |
| 1035 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1036 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1037 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1038 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1039 | bool skip_overflow_check = |
| 1040 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1041 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1042 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1043 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1044 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1045 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1046 | } |
| 1047 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1048 | if (HasEmptyFrame()) { |
| 1049 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1050 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1051 | |
| 1052 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1053 | Register reg = kCoreCalleeSaves[i]; |
| 1054 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1055 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1056 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1057 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1058 | } |
| 1059 | } |
| 1060 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1061 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1062 | // Initialize should_deoptimize flag to 0. |
| 1063 | __ movl(Address(ESP, -kShouldDeoptimizeFlagSize), Immediate(0)); |
| 1064 | } |
| 1065 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1066 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1067 | __ subl(ESP, Immediate(adjust)); |
| 1068 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1069 | // Save the current method if we need it. Note that we do not |
| 1070 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1071 | // in the SSA graph. |
| 1072 | if (RequiresCurrentMethod()) { |
| 1073 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1074 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1078 | __ cfi().RememberState(); |
| 1079 | if (!HasEmptyFrame()) { |
| 1080 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1081 | __ addl(ESP, Immediate(adjust)); |
| 1082 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1083 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1084 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1085 | Register reg = kCoreCalleeSaves[i]; |
| 1086 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1087 | __ popl(reg); |
| 1088 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1089 | __ cfi().Restore(DWARFReg(reg)); |
| 1090 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1091 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1092 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1093 | __ ret(); |
| 1094 | __ cfi().RestoreState(); |
| 1095 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1096 | } |
| 1097 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1098 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1099 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1102 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 1103 | switch (type) { |
| 1104 | case Primitive::kPrimBoolean: |
| 1105 | case Primitive::kPrimByte: |
| 1106 | case Primitive::kPrimChar: |
| 1107 | case Primitive::kPrimShort: |
| 1108 | case Primitive::kPrimInt: |
| 1109 | case Primitive::kPrimNot: |
| 1110 | return Location::RegisterLocation(EAX); |
| 1111 | |
| 1112 | case Primitive::kPrimLong: |
| 1113 | return Location::RegisterPairLocation(EAX, EDX); |
| 1114 | |
| 1115 | case Primitive::kPrimVoid: |
| 1116 | return Location::NoLocation(); |
| 1117 | |
| 1118 | case Primitive::kPrimDouble: |
| 1119 | case Primitive::kPrimFloat: |
| 1120 | return Location::FpuRegisterLocation(XMM0); |
| 1121 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1122 | |
| 1123 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1127 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1128 | } |
| 1129 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1130 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1131 | switch (type) { |
| 1132 | case Primitive::kPrimBoolean: |
| 1133 | case Primitive::kPrimByte: |
| 1134 | case Primitive::kPrimChar: |
| 1135 | case Primitive::kPrimShort: |
| 1136 | case Primitive::kPrimInt: |
| 1137 | case Primitive::kPrimNot: { |
| 1138 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1139 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1140 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1141 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1142 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1143 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1144 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1145 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1146 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1147 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1148 | uint32_t index = gp_index_; |
| 1149 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1150 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1151 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1152 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1153 | calling_convention.GetRegisterPairAt(index)); |
| 1154 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1155 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1156 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1161 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1162 | stack_index_++; |
| 1163 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1164 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1165 | } else { |
| 1166 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1171 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1172 | stack_index_ += 2; |
| 1173 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1174 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1175 | } else { |
| 1176 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1177 | } |
| 1178 | } |
| 1179 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1180 | case Primitive::kPrimVoid: |
| 1181 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1182 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1183 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1184 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1185 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1186 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1187 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1188 | if (source.Equals(destination)) { |
| 1189 | return; |
| 1190 | } |
| 1191 | if (destination.IsRegister()) { |
| 1192 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1193 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1194 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1195 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1196 | } else { |
| 1197 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1198 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1199 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1200 | } else if (destination.IsFpuRegister()) { |
| 1201 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1202 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1203 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1204 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1205 | } else { |
| 1206 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1207 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1208 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1209 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1210 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1211 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1212 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1213 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1214 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1215 | } else if (source.IsConstant()) { |
| 1216 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1217 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1218 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1219 | } else { |
| 1220 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1221 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1222 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1223 | } |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1228 | if (source.Equals(destination)) { |
| 1229 | return; |
| 1230 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1231 | if (destination.IsRegisterPair()) { |
| 1232 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1233 | EmitParallelMoves( |
| 1234 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1235 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1236 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1237 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1238 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1239 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1240 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1241 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1242 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1243 | __ psrlq(src_reg, Immediate(32)); |
| 1244 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1245 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1246 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1247 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1248 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1249 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1250 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1251 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1252 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1253 | if (source.IsFpuRegister()) { |
| 1254 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1255 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1256 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1257 | } else if (source.IsRegisterPair()) { |
| 1258 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1259 | // Create stack space for 2 elements. |
| 1260 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1261 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1262 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1263 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1264 | // And remove the temporary stack space we allocated. |
| 1265 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1266 | } else { |
| 1267 | LOG(FATAL) << "Unimplemented"; |
| 1268 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1269 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1270 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1271 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1272 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1273 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1274 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1275 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1276 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1277 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1278 | } else if (source.IsConstant()) { |
| 1279 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1280 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1281 | int64_t value = GetInt64ValueOf(constant); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1282 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1283 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1284 | Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1285 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1286 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1287 | EmitParallelMoves( |
| 1288 | Location::StackSlot(source.GetStackIndex()), |
| 1289 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1290 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1291 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1292 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1293 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1294 | } |
| 1295 | } |
| 1296 | } |
| 1297 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1298 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1299 | DCHECK(location.IsRegister()); |
| 1300 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1301 | } |
| 1302 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1303 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1304 | HParallelMove move(GetGraph()->GetArena()); |
| 1305 | if (dst_type == Primitive::kPrimLong && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1306 | move.AddMove(src.ToLow(), dst.ToLow(), Primitive::kPrimInt, nullptr); |
| 1307 | move.AddMove(src.ToHigh(), dst.ToHigh(), Primitive::kPrimInt, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1308 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1309 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1310 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1311 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1315 | if (location.IsRegister()) { |
| 1316 | locations->AddTemp(location); |
| 1317 | } else if (location.IsRegisterPair()) { |
| 1318 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1319 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1320 | } else { |
| 1321 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1322 | } |
| 1323 | } |
| 1324 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1325 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1326 | DCHECK(!successor->IsExitBlock()); |
| 1327 | |
| 1328 | HBasicBlock* block = got->GetBlock(); |
| 1329 | HInstruction* previous = got->GetPrevious(); |
| 1330 | |
| 1331 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1332 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1333 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1334 | return; |
| 1335 | } |
| 1336 | |
| 1337 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1338 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1339 | } |
| 1340 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1341 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1342 | } |
| 1343 | } |
| 1344 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1345 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1346 | got->SetLocations(nullptr); |
| 1347 | } |
| 1348 | |
| 1349 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1350 | HandleGoto(got, got->GetSuccessor()); |
| 1351 | } |
| 1352 | |
| 1353 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1354 | try_boundary->SetLocations(nullptr); |
| 1355 | } |
| 1356 | |
| 1357 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1358 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1359 | if (!successor->IsExitBlock()) { |
| 1360 | HandleGoto(try_boundary, successor); |
| 1361 | } |
| 1362 | } |
| 1363 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1364 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1365 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1366 | } |
| 1367 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1368 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1369 | } |
| 1370 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1371 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1372 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1373 | LabelType* true_label, |
| 1374 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1375 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1376 | __ j(kUnordered, true_label); |
| 1377 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1378 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1379 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1380 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1381 | } |
| 1382 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1383 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1384 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1385 | LabelType* true_label, |
| 1386 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1387 | LocationSummary* locations = cond->GetLocations(); |
| 1388 | Location left = locations->InAt(0); |
| 1389 | Location right = locations->InAt(1); |
| 1390 | IfCondition if_cond = cond->GetCondition(); |
| 1391 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1392 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1393 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1394 | IfCondition true_high_cond = if_cond; |
| 1395 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1396 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1397 | |
| 1398 | // Set the conditions for the test, remembering that == needs to be |
| 1399 | // decided using the low words. |
| 1400 | switch (if_cond) { |
| 1401 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1402 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1403 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1404 | break; |
| 1405 | case kCondLT: |
| 1406 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1407 | break; |
| 1408 | case kCondLE: |
| 1409 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1410 | break; |
| 1411 | case kCondGT: |
| 1412 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1413 | break; |
| 1414 | case kCondGE: |
| 1415 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1416 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1417 | case kCondB: |
| 1418 | false_high_cond = kCondA; |
| 1419 | break; |
| 1420 | case kCondBE: |
| 1421 | true_high_cond = kCondB; |
| 1422 | break; |
| 1423 | case kCondA: |
| 1424 | false_high_cond = kCondB; |
| 1425 | break; |
| 1426 | case kCondAE: |
| 1427 | true_high_cond = kCondA; |
| 1428 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | if (right.IsConstant()) { |
| 1432 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1433 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1434 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1435 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1436 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1437 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1438 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1439 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1440 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1441 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1442 | __ j(X86Condition(true_high_cond), true_label); |
| 1443 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1444 | } |
| 1445 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1446 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1447 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1448 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1449 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1450 | |
| 1451 | __ cmpl(left_high, right_high); |
| 1452 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1453 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1454 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1455 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1456 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1457 | __ j(X86Condition(true_high_cond), true_label); |
| 1458 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1459 | } |
| 1460 | // Must be equal high, so compare the lows. |
| 1461 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1462 | } else { |
| 1463 | DCHECK(right.IsDoubleStackSlot()); |
| 1464 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1465 | if (if_cond == kCondNE) { |
| 1466 | __ j(X86Condition(true_high_cond), true_label); |
| 1467 | } else if (if_cond == kCondEQ) { |
| 1468 | __ j(X86Condition(false_high_cond), false_label); |
| 1469 | } else { |
| 1470 | __ j(X86Condition(true_high_cond), true_label); |
| 1471 | __ j(X86Condition(false_high_cond), false_label); |
| 1472 | } |
| 1473 | // Must be equal high, so compare the lows. |
| 1474 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1475 | } |
| 1476 | // The last comparison might be unsigned. |
| 1477 | __ j(final_condition, true_label); |
| 1478 | } |
| 1479 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1480 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1481 | Location rhs, |
| 1482 | HInstruction* insn, |
| 1483 | bool is_double) { |
| 1484 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1485 | if (is_double) { |
| 1486 | if (rhs.IsFpuRegister()) { |
| 1487 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1488 | } else if (const_area != nullptr) { |
| 1489 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1490 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1491 | codegen_->LiteralDoubleAddress( |
| 1492 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1493 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1494 | } else { |
| 1495 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1496 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1497 | } |
| 1498 | } else { |
| 1499 | if (rhs.IsFpuRegister()) { |
| 1500 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1501 | } else if (const_area != nullptr) { |
| 1502 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1503 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1504 | codegen_->LiteralFloatAddress( |
| 1505 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1506 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1507 | } else { |
| 1508 | DCHECK(rhs.IsStackSlot()); |
| 1509 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1510 | } |
| 1511 | } |
| 1512 | } |
| 1513 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1514 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1515 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1516 | LabelType* true_target_in, |
| 1517 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1518 | // Generated branching requires both targets to be explicit. If either of the |
| 1519 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1520 | LabelType fallthrough_target; |
| 1521 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1522 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1523 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1524 | LocationSummary* locations = condition->GetLocations(); |
| 1525 | Location left = locations->InAt(0); |
| 1526 | Location right = locations->InAt(1); |
| 1527 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1528 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1529 | switch (type) { |
| 1530 | case Primitive::kPrimLong: |
| 1531 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1532 | break; |
| 1533 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1534 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1535 | GenerateFPJumps(condition, true_target, false_target); |
| 1536 | break; |
| 1537 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1538 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1539 | GenerateFPJumps(condition, true_target, false_target); |
| 1540 | break; |
| 1541 | default: |
| 1542 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1543 | } |
| 1544 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1545 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1546 | __ jmp(false_target); |
| 1547 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1548 | |
| 1549 | if (fallthrough_target.IsLinked()) { |
| 1550 | __ Bind(&fallthrough_target); |
| 1551 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1552 | } |
| 1553 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1554 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1555 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1556 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1557 | // conditions if they are materialized due to the complex branching. |
| 1558 | return cond->IsCondition() && |
| 1559 | cond->GetNext() == branch && |
| 1560 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1561 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1562 | } |
| 1563 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1564 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1565 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1566 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1567 | LabelType* true_target, |
| 1568 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1569 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1570 | |
| 1571 | if (true_target == nullptr && false_target == nullptr) { |
| 1572 | // Nothing to do. The code always falls through. |
| 1573 | return; |
| 1574 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1575 | // Constant condition, statically compared against "true" (integer value 1). |
| 1576 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1577 | if (true_target != nullptr) { |
| 1578 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1579 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1580 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1581 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1582 | if (false_target != nullptr) { |
| 1583 | __ jmp(false_target); |
| 1584 | } |
| 1585 | } |
| 1586 | return; |
| 1587 | } |
| 1588 | |
| 1589 | // The following code generates these patterns: |
| 1590 | // (1) true_target == nullptr && false_target != nullptr |
| 1591 | // - opposite condition true => branch to false_target |
| 1592 | // (2) true_target != nullptr && false_target == nullptr |
| 1593 | // - condition true => branch to true_target |
| 1594 | // (3) true_target != nullptr && false_target != nullptr |
| 1595 | // - condition true => branch to true_target |
| 1596 | // - branch to false_target |
| 1597 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1598 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1599 | if (true_target == nullptr) { |
| 1600 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1601 | } else { |
| 1602 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1603 | } |
| 1604 | } else { |
| 1605 | // Materialized condition, compare against 0. |
| 1606 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1607 | if (lhs.IsRegister()) { |
| 1608 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1609 | } else { |
| 1610 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1611 | } |
| 1612 | if (true_target == nullptr) { |
| 1613 | __ j(kEqual, false_target); |
| 1614 | } else { |
| 1615 | __ j(kNotEqual, true_target); |
| 1616 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1617 | } |
| 1618 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1619 | // Condition has not been materialized, use its inputs as the comparison and |
| 1620 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1621 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1622 | |
| 1623 | // If this is a long or FP comparison that has been folded into |
| 1624 | // the HCondition, generate the comparison directly. |
| 1625 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1626 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1627 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1628 | return; |
| 1629 | } |
| 1630 | |
| 1631 | Location lhs = condition->GetLocations()->InAt(0); |
| 1632 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1633 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1634 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1635 | if (true_target == nullptr) { |
| 1636 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1637 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1638 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1639 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1640 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1641 | |
| 1642 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1643 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1644 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1645 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1646 | } |
| 1647 | } |
| 1648 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1649 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1650 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1651 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1652 | locations->SetInAt(0, Location::Any()); |
| 1653 | } |
| 1654 | } |
| 1655 | |
| 1656 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1657 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1658 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1659 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1660 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1661 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1662 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1663 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1667 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1668 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1669 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1670 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1671 | locations->SetInAt(0, Location::Any()); |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1676 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1677 | GenerateTestAndBranch<Label>(deoptimize, |
| 1678 | /* condition_input_index */ 0, |
| 1679 | slow_path->GetEntryLabel(), |
| 1680 | /* false_target */ nullptr); |
| 1681 | } |
| 1682 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1683 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1684 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1685 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1686 | locations->SetOut(Location::RequiresRegister()); |
| 1687 | } |
| 1688 | |
| 1689 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1690 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), |
| 1691 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1692 | } |
| 1693 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1694 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1695 | // There are no conditional move instructions for XMMs. |
| 1696 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1697 | return false; |
| 1698 | } |
| 1699 | |
| 1700 | // A FP condition doesn't generate the single CC that we need. |
| 1701 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1702 | HInstruction* condition = select->GetCondition(); |
| 1703 | if (condition->IsCondition()) { |
| 1704 | Primitive::Type compare_type = condition->InputAt(0)->GetType(); |
| 1705 | if (compare_type == Primitive::kPrimLong || |
| 1706 | Primitive::IsFloatingPointType(compare_type)) { |
| 1707 | return false; |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | // We can generate a CMOV for this Select. |
| 1712 | return true; |
| 1713 | } |
| 1714 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1715 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| 1716 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1717 | if (Primitive::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1718 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1719 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1720 | } else { |
| 1721 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1722 | if (SelectCanUseCMOV(select)) { |
| 1723 | if (select->InputAt(1)->IsConstant()) { |
| 1724 | // Cmov can't handle a constant value. |
| 1725 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1726 | } else { |
| 1727 | locations->SetInAt(1, Location::Any()); |
| 1728 | } |
| 1729 | } else { |
| 1730 | locations->SetInAt(1, Location::Any()); |
| 1731 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1732 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1733 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1734 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1735 | } |
| 1736 | locations->SetOut(Location::SameAsFirstInput()); |
| 1737 | } |
| 1738 | |
| 1739 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1740 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1741 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1742 | if (SelectCanUseCMOV(select)) { |
| 1743 | // If both the condition and the source types are integer, we can generate |
| 1744 | // a CMOV to implement Select. |
| 1745 | |
| 1746 | HInstruction* select_condition = select->GetCondition(); |
| 1747 | Condition cond = kNotEqual; |
| 1748 | |
| 1749 | // Figure out how to test the 'condition'. |
| 1750 | if (select_condition->IsCondition()) { |
| 1751 | HCondition* condition = select_condition->AsCondition(); |
| 1752 | if (!condition->IsEmittedAtUseSite()) { |
| 1753 | // This was a previously materialized condition. |
| 1754 | // Can we use the existing condition code? |
| 1755 | if (AreEflagsSetFrom(condition, select)) { |
| 1756 | // Materialization was the previous instruction. Condition codes are right. |
| 1757 | cond = X86Condition(condition->GetCondition()); |
| 1758 | } else { |
| 1759 | // No, we have to recreate the condition code. |
| 1760 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1761 | __ testl(cond_reg, cond_reg); |
| 1762 | } |
| 1763 | } else { |
| 1764 | // We can't handle FP or long here. |
| 1765 | DCHECK_NE(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 1766 | DCHECK(!Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| 1767 | LocationSummary* cond_locations = condition->GetLocations(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1768 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1769 | cond = X86Condition(condition->GetCondition()); |
| 1770 | } |
| 1771 | } else { |
| 1772 | // Must be a boolean condition, which needs to be compared to 0. |
| 1773 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1774 | __ testl(cond_reg, cond_reg); |
| 1775 | } |
| 1776 | |
| 1777 | // If the condition is true, overwrite the output, which already contains false. |
| 1778 | Location false_loc = locations->InAt(0); |
| 1779 | Location true_loc = locations->InAt(1); |
| 1780 | if (select->GetType() == Primitive::kPrimLong) { |
| 1781 | // 64 bit conditional move. |
| 1782 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1783 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1784 | if (true_loc.IsRegisterPair()) { |
| 1785 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1786 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1787 | } else { |
| 1788 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1789 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1790 | } |
| 1791 | } else { |
| 1792 | // 32 bit conditional move. |
| 1793 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1794 | if (true_loc.IsRegister()) { |
| 1795 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1796 | } else { |
| 1797 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1798 | } |
| 1799 | } |
| 1800 | } else { |
| 1801 | NearLabel false_target; |
| 1802 | GenerateTestAndBranch<NearLabel>( |
| 1803 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1804 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1805 | __ Bind(&false_target); |
| 1806 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1809 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1810 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1811 | } |
| 1812 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1813 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1814 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | void CodeGeneratorX86::GenerateNop() { |
| 1818 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1819 | } |
| 1820 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1821 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1822 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1823 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1824 | // Handle the long/FP comparisons made in instruction simplification. |
| 1825 | switch (cond->InputAt(0)->GetType()) { |
| 1826 | case Primitive::kPrimLong: { |
| 1827 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1828 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1829 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1830 | locations->SetOut(Location::RequiresRegister()); |
| 1831 | } |
| 1832 | break; |
| 1833 | } |
| 1834 | case Primitive::kPrimFloat: |
| 1835 | case Primitive::kPrimDouble: { |
| 1836 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1837 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1838 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1839 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1840 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1841 | } else { |
| 1842 | locations->SetInAt(1, Location::Any()); |
| 1843 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1844 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1845 | locations->SetOut(Location::RequiresRegister()); |
| 1846 | } |
| 1847 | break; |
| 1848 | } |
| 1849 | default: |
| 1850 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1851 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1852 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1853 | // We need a byte register. |
| 1854 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1855 | } |
| 1856 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1857 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1858 | } |
| 1859 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1860 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1861 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1862 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1863 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1864 | |
| 1865 | LocationSummary* locations = cond->GetLocations(); |
| 1866 | Location lhs = locations->InAt(0); |
| 1867 | Location rhs = locations->InAt(1); |
| 1868 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1869 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1870 | |
| 1871 | switch (cond->InputAt(0)->GetType()) { |
| 1872 | default: { |
| 1873 | // Integer case. |
| 1874 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1875 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1876 | __ xorl(reg, reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1877 | codegen_->GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1878 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1879 | return; |
| 1880 | } |
| 1881 | case Primitive::kPrimLong: |
| 1882 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1883 | break; |
| 1884 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1885 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1886 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1887 | break; |
| 1888 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1889 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1890 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1891 | break; |
| 1892 | } |
| 1893 | |
| 1894 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1895 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1896 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1897 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1898 | __ Bind(&false_label); |
| 1899 | __ xorl(reg, reg); |
| 1900 | __ jmp(&done_label); |
| 1901 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1902 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1903 | __ Bind(&true_label); |
| 1904 | __ movl(reg, Immediate(1)); |
| 1905 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1906 | } |
| 1907 | |
| 1908 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1909 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1910 | } |
| 1911 | |
| 1912 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1913 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1917 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1918 | } |
| 1919 | |
| 1920 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1921 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1922 | } |
| 1923 | |
| 1924 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1925 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1926 | } |
| 1927 | |
| 1928 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1929 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1933 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1934 | } |
| 1935 | |
| 1936 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1937 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1938 | } |
| 1939 | |
| 1940 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1941 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1942 | } |
| 1943 | |
| 1944 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1945 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1949 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1950 | } |
| 1951 | |
| 1952 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1953 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1954 | } |
| 1955 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1956 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1957 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1961 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1965 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1969 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1973 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1977 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1978 | } |
| 1979 | |
| 1980 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1981 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1982 | } |
| 1983 | |
| 1984 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1985 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1986 | } |
| 1987 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1988 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1989 | LocationSummary* locations = |
| 1990 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1991 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1992 | } |
| 1993 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1994 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1995 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1996 | } |
| 1997 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1998 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1999 | LocationSummary* locations = |
| 2000 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2001 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2002 | } |
| 2003 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2004 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2005 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2006 | } |
| 2007 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2008 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2009 | LocationSummary* locations = |
| 2010 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2011 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2012 | } |
| 2013 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2014 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2015 | // Will be generated at use site. |
| 2016 | } |
| 2017 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2018 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2019 | LocationSummary* locations = |
| 2020 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2021 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2022 | } |
| 2023 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2024 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2025 | // Will be generated at use site. |
| 2026 | } |
| 2027 | |
| 2028 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2029 | LocationSummary* locations = |
| 2030 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2031 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2032 | } |
| 2033 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2034 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2035 | // Will be generated at use site. |
| 2036 | } |
| 2037 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2038 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2039 | memory_barrier->SetLocations(nullptr); |
| 2040 | } |
| 2041 | |
| 2042 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2043 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2044 | } |
| 2045 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2046 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2047 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2048 | } |
| 2049 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2050 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2051 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2052 | } |
| 2053 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2054 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2055 | LocationSummary* locations = |
| 2056 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2057 | switch (ret->InputAt(0)->GetType()) { |
| 2058 | case Primitive::kPrimBoolean: |
| 2059 | case Primitive::kPrimByte: |
| 2060 | case Primitive::kPrimChar: |
| 2061 | case Primitive::kPrimShort: |
| 2062 | case Primitive::kPrimInt: |
| 2063 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2064 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2065 | break; |
| 2066 | |
| 2067 | case Primitive::kPrimLong: |
| 2068 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2069 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2070 | break; |
| 2071 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2072 | case Primitive::kPrimFloat: |
| 2073 | case Primitive::kPrimDouble: |
| 2074 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2075 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2076 | break; |
| 2077 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2078 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2079 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2080 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2081 | } |
| 2082 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2083 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2084 | if (kIsDebugBuild) { |
| 2085 | switch (ret->InputAt(0)->GetType()) { |
| 2086 | case Primitive::kPrimBoolean: |
| 2087 | case Primitive::kPrimByte: |
| 2088 | case Primitive::kPrimChar: |
| 2089 | case Primitive::kPrimShort: |
| 2090 | case Primitive::kPrimInt: |
| 2091 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2092 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2093 | break; |
| 2094 | |
| 2095 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2096 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2097 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2098 | break; |
| 2099 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2100 | case Primitive::kPrimFloat: |
| 2101 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2102 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2103 | break; |
| 2104 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2105 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2106 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2107 | } |
| 2108 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2109 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2110 | } |
| 2111 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2112 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2113 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2114 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2115 | // the method_idx. |
| 2116 | HandleInvoke(invoke); |
| 2117 | } |
| 2118 | |
| 2119 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2120 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2121 | } |
| 2122 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2123 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2124 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2125 | // art::PrepareForRegisterAllocation. |
| 2126 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2127 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2128 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2129 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2130 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2131 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2132 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2133 | return; |
| 2134 | } |
| 2135 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2136 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2137 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2138 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2139 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2140 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2141 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2142 | } |
| 2143 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2144 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2145 | if (invoke->GetLocations()->Intrinsified()) { |
| 2146 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2147 | intrinsic.Dispatch(invoke); |
| 2148 | return true; |
| 2149 | } |
| 2150 | return false; |
| 2151 | } |
| 2152 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2153 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2154 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2155 | // art::PrepareForRegisterAllocation. |
| 2156 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2157 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2158 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2159 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2160 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2161 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2162 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2163 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2164 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 2165 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2166 | } |
| 2167 | |
| 2168 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2169 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2170 | if (intrinsic.TryDispatch(invoke)) { |
| 2171 | return; |
| 2172 | } |
| 2173 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2174 | HandleInvoke(invoke); |
| 2175 | } |
| 2176 | |
| 2177 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2178 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2179 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2180 | } |
| 2181 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2182 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2183 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2184 | return; |
| 2185 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2186 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2187 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2188 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2189 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2190 | } |
| 2191 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2192 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2193 | // This call to HandleInvoke allocates a temporary (core) register |
| 2194 | // which is also used to transfer the hidden argument from FP to |
| 2195 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2196 | HandleInvoke(invoke); |
| 2197 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2198 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2202 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2203 | LocationSummary* locations = invoke->GetLocations(); |
| 2204 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2205 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2206 | Location receiver = locations->InAt(0); |
| 2207 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2208 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2209 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2210 | // won't be modified thereafter, before the `call` instruction. |
| 2211 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2212 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2213 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2214 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2215 | if (receiver.IsStackSlot()) { |
| 2216 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2217 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2218 | __ movl(temp, Address(temp, class_offset)); |
| 2219 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2220 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2221 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2222 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2223 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2224 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2225 | // emit a read barrier for the previous class reference load. |
| 2226 | // However this is not required in practice, as this is an |
| 2227 | // intermediate/temporary reference and because the current |
| 2228 | // concurrent copying collector keeps the from-space memory |
| 2229 | // intact/accessible until the end of the marking phase (the |
| 2230 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2231 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2232 | // temp = temp->GetAddressOfIMT() |
| 2233 | __ movl(temp, |
| 2234 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2235 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2236 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2237 | invoke->GetImtIndex(), kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2238 | __ movl(temp, Address(temp, method_offset)); |
| 2239 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2240 | __ call(Address(temp, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2241 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2242 | |
| 2243 | DCHECK(!codegen_->IsLeafMethod()); |
| 2244 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2245 | } |
| 2246 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2247 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2248 | LocationSummary* locations = |
| 2249 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2250 | switch (neg->GetResultType()) { |
| 2251 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2252 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2253 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2254 | locations->SetOut(Location::SameAsFirstInput()); |
| 2255 | break; |
| 2256 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2257 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2258 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2259 | locations->SetOut(Location::SameAsFirstInput()); |
| 2260 | locations->AddTemp(Location::RequiresRegister()); |
| 2261 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2262 | break; |
| 2263 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2264 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2265 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2266 | locations->SetOut(Location::SameAsFirstInput()); |
| 2267 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2268 | break; |
| 2269 | |
| 2270 | default: |
| 2271 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2272 | } |
| 2273 | } |
| 2274 | |
| 2275 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2276 | LocationSummary* locations = neg->GetLocations(); |
| 2277 | Location out = locations->Out(); |
| 2278 | Location in = locations->InAt(0); |
| 2279 | switch (neg->GetResultType()) { |
| 2280 | case Primitive::kPrimInt: |
| 2281 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2282 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2283 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2284 | break; |
| 2285 | |
| 2286 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2287 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2288 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2289 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2290 | // Negation is similar to subtraction from zero. The least |
| 2291 | // significant byte triggers a borrow when it is different from |
| 2292 | // zero; to take it into account, add 1 to the most significant |
| 2293 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2294 | // operation. |
| 2295 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2296 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2297 | break; |
| 2298 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2299 | case Primitive::kPrimFloat: { |
| 2300 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2301 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2302 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2303 | // Implement float negation with an exclusive or with value |
| 2304 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2305 | // single-precision floating-point number). |
| 2306 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2307 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2308 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2309 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2310 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2311 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2312 | case Primitive::kPrimDouble: { |
| 2313 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2314 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2315 | // Implement double negation with an exclusive or with value |
| 2316 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2317 | // a double-precision floating-point number). |
| 2318 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2319 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2320 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2321 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2322 | |
| 2323 | default: |
| 2324 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2325 | } |
| 2326 | } |
| 2327 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2328 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2329 | LocationSummary* locations = |
| 2330 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2331 | DCHECK(Primitive::IsFloatingPointType(neg->GetType())); |
| 2332 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2333 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2334 | locations->SetOut(Location::SameAsFirstInput()); |
| 2335 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2336 | } |
| 2337 | |
| 2338 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2339 | LocationSummary* locations = neg->GetLocations(); |
| 2340 | Location out = locations->Out(); |
| 2341 | DCHECK(locations->InAt(0).Equals(out)); |
| 2342 | |
| 2343 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2344 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2345 | if (neg->GetType() == Primitive::kPrimFloat) { |
| 2346 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), constant_area)); |
| 2347 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2348 | } else { |
| 2349 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), constant_area)); |
| 2350 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2351 | } |
| 2352 | } |
| 2353 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2354 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2355 | Primitive::Type result_type = conversion->GetResultType(); |
| 2356 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2357 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2358 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2359 | // The float-to-long and double-to-long type conversions rely on a |
| 2360 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2361 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2362 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2363 | && result_type == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2364 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2365 | : LocationSummary::kNoCall; |
| 2366 | LocationSummary* locations = |
| 2367 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2368 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2369 | // The Java language does not allow treating boolean as an integral type but |
| 2370 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2371 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2372 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2373 | case Primitive::kPrimByte: |
| 2374 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2375 | case Primitive::kPrimLong: { |
| 2376 | // Type conversion from long to byte is a result of code transformations. |
| 2377 | HInstruction* input = conversion->InputAt(0); |
| 2378 | Location input_location = input->IsConstant() |
| 2379 | ? Location::ConstantLocation(input->AsConstant()) |
| 2380 | : Location::RegisterPairLocation(EAX, EDX); |
| 2381 | locations->SetInAt(0, input_location); |
| 2382 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2383 | // the validation of the linear scan implementation |
| 2384 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2385 | break; |
| 2386 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2387 | case Primitive::kPrimBoolean: |
| 2388 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2389 | case Primitive::kPrimShort: |
| 2390 | case Primitive::kPrimInt: |
| 2391 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2392 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2393 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2394 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2395 | // the validation of the linear scan implementation |
| 2396 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2397 | break; |
| 2398 | |
| 2399 | default: |
| 2400 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2401 | << " to " << result_type; |
| 2402 | } |
| 2403 | break; |
| 2404 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2405 | case Primitive::kPrimShort: |
| 2406 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2407 | case Primitive::kPrimLong: |
| 2408 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2409 | case Primitive::kPrimBoolean: |
| 2410 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2411 | case Primitive::kPrimByte: |
| 2412 | case Primitive::kPrimInt: |
| 2413 | case Primitive::kPrimChar: |
| 2414 | // Processing a Dex `int-to-short' instruction. |
| 2415 | locations->SetInAt(0, Location::Any()); |
| 2416 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2417 | break; |
| 2418 | |
| 2419 | default: |
| 2420 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2421 | << " to " << result_type; |
| 2422 | } |
| 2423 | break; |
| 2424 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2425 | case Primitive::kPrimInt: |
| 2426 | switch (input_type) { |
| 2427 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2428 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2429 | locations->SetInAt(0, Location::Any()); |
| 2430 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2431 | break; |
| 2432 | |
| 2433 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2434 | // Processing a Dex `float-to-int' instruction. |
| 2435 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2436 | locations->SetOut(Location::RequiresRegister()); |
| 2437 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2438 | break; |
| 2439 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2440 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2441 | // Processing a Dex `double-to-int' instruction. |
| 2442 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2443 | locations->SetOut(Location::RequiresRegister()); |
| 2444 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2445 | break; |
| 2446 | |
| 2447 | default: |
| 2448 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2449 | << " to " << result_type; |
| 2450 | } |
| 2451 | break; |
| 2452 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2453 | case Primitive::kPrimLong: |
| 2454 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2455 | case Primitive::kPrimBoolean: |
| 2456 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2457 | case Primitive::kPrimByte: |
| 2458 | case Primitive::kPrimShort: |
| 2459 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2460 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2461 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2462 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2463 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2464 | break; |
| 2465 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2466 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2467 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2468 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2469 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2470 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2471 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2472 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2473 | // The runtime helper puts the result in EAX, EDX. |
| 2474 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2475 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2476 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2477 | |
| 2478 | default: |
| 2479 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2480 | << " to " << result_type; |
| 2481 | } |
| 2482 | break; |
| 2483 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2484 | case Primitive::kPrimChar: |
| 2485 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2486 | case Primitive::kPrimLong: |
| 2487 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2488 | case Primitive::kPrimBoolean: |
| 2489 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2490 | case Primitive::kPrimByte: |
| 2491 | case Primitive::kPrimShort: |
| 2492 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2493 | // Processing a Dex `int-to-char' instruction. |
| 2494 | locations->SetInAt(0, Location::Any()); |
| 2495 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2496 | break; |
| 2497 | |
| 2498 | default: |
| 2499 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2500 | << " to " << result_type; |
| 2501 | } |
| 2502 | break; |
| 2503 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2504 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2505 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2506 | case Primitive::kPrimBoolean: |
| 2507 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2508 | case Primitive::kPrimByte: |
| 2509 | case Primitive::kPrimShort: |
| 2510 | case Primitive::kPrimInt: |
| 2511 | case Primitive::kPrimChar: |
| 2512 | // Processing a Dex `int-to-float' instruction. |
| 2513 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2514 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2515 | break; |
| 2516 | |
| 2517 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2518 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2519 | locations->SetInAt(0, Location::Any()); |
| 2520 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2521 | break; |
| 2522 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2523 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2524 | // Processing a Dex `double-to-float' instruction. |
| 2525 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2526 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2527 | break; |
| 2528 | |
| 2529 | default: |
| 2530 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2531 | << " to " << result_type; |
| 2532 | }; |
| 2533 | break; |
| 2534 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2535 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2536 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2537 | case Primitive::kPrimBoolean: |
| 2538 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2539 | case Primitive::kPrimByte: |
| 2540 | case Primitive::kPrimShort: |
| 2541 | case Primitive::kPrimInt: |
| 2542 | case Primitive::kPrimChar: |
| 2543 | // Processing a Dex `int-to-double' instruction. |
| 2544 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2545 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2546 | break; |
| 2547 | |
| 2548 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2549 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2550 | locations->SetInAt(0, Location::Any()); |
| 2551 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2552 | break; |
| 2553 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2554 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2555 | // Processing a Dex `float-to-double' instruction. |
| 2556 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2557 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2558 | break; |
| 2559 | |
| 2560 | default: |
| 2561 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2562 | << " to " << result_type; |
| 2563 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2564 | break; |
| 2565 | |
| 2566 | default: |
| 2567 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2568 | << " to " << result_type; |
| 2569 | } |
| 2570 | } |
| 2571 | |
| 2572 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2573 | LocationSummary* locations = conversion->GetLocations(); |
| 2574 | Location out = locations->Out(); |
| 2575 | Location in = locations->InAt(0); |
| 2576 | Primitive::Type result_type = conversion->GetResultType(); |
| 2577 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2578 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2579 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2580 | case Primitive::kPrimByte: |
| 2581 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2582 | case Primitive::kPrimLong: |
| 2583 | // Type conversion from long to byte is a result of code transformations. |
| 2584 | if (in.IsRegisterPair()) { |
| 2585 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2586 | } else { |
| 2587 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2588 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2589 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2590 | } |
| 2591 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2592 | case Primitive::kPrimBoolean: |
| 2593 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2594 | case Primitive::kPrimShort: |
| 2595 | case Primitive::kPrimInt: |
| 2596 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2597 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2598 | if (in.IsRegister()) { |
| 2599 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2600 | } else { |
| 2601 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2602 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2603 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2604 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2605 | break; |
| 2606 | |
| 2607 | default: |
| 2608 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2609 | << " to " << result_type; |
| 2610 | } |
| 2611 | break; |
| 2612 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2613 | case Primitive::kPrimShort: |
| 2614 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2615 | case Primitive::kPrimLong: |
| 2616 | // Type conversion from long to short is a result of code transformations. |
| 2617 | if (in.IsRegisterPair()) { |
| 2618 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2619 | } else if (in.IsDoubleStackSlot()) { |
| 2620 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2621 | } else { |
| 2622 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2623 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2624 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2625 | } |
| 2626 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2627 | case Primitive::kPrimBoolean: |
| 2628 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2629 | case Primitive::kPrimByte: |
| 2630 | case Primitive::kPrimInt: |
| 2631 | case Primitive::kPrimChar: |
| 2632 | // Processing a Dex `int-to-short' instruction. |
| 2633 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2634 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2635 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2636 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2637 | } else { |
| 2638 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2639 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2640 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2641 | } |
| 2642 | break; |
| 2643 | |
| 2644 | default: |
| 2645 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2646 | << " to " << result_type; |
| 2647 | } |
| 2648 | break; |
| 2649 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2650 | case Primitive::kPrimInt: |
| 2651 | switch (input_type) { |
| 2652 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2653 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2654 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2655 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2656 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2657 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2658 | } else { |
| 2659 | DCHECK(in.IsConstant()); |
| 2660 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2661 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2662 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2663 | } |
| 2664 | break; |
| 2665 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2666 | case Primitive::kPrimFloat: { |
| 2667 | // Processing a Dex `float-to-int' instruction. |
| 2668 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2669 | Register output = out.AsRegister<Register>(); |
| 2670 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2671 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2672 | |
| 2673 | __ movl(output, Immediate(kPrimIntMax)); |
| 2674 | // temp = int-to-float(output) |
| 2675 | __ cvtsi2ss(temp, output); |
| 2676 | // if input >= temp goto done |
| 2677 | __ comiss(input, temp); |
| 2678 | __ j(kAboveEqual, &done); |
| 2679 | // if input == NaN goto nan |
| 2680 | __ j(kUnordered, &nan); |
| 2681 | // output = float-to-int-truncate(input) |
| 2682 | __ cvttss2si(output, input); |
| 2683 | __ jmp(&done); |
| 2684 | __ Bind(&nan); |
| 2685 | // output = 0 |
| 2686 | __ xorl(output, output); |
| 2687 | __ Bind(&done); |
| 2688 | break; |
| 2689 | } |
| 2690 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2691 | case Primitive::kPrimDouble: { |
| 2692 | // Processing a Dex `double-to-int' instruction. |
| 2693 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2694 | Register output = out.AsRegister<Register>(); |
| 2695 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2696 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2697 | |
| 2698 | __ movl(output, Immediate(kPrimIntMax)); |
| 2699 | // temp = int-to-double(output) |
| 2700 | __ cvtsi2sd(temp, output); |
| 2701 | // if input >= temp goto done |
| 2702 | __ comisd(input, temp); |
| 2703 | __ j(kAboveEqual, &done); |
| 2704 | // if input == NaN goto nan |
| 2705 | __ j(kUnordered, &nan); |
| 2706 | // output = double-to-int-truncate(input) |
| 2707 | __ cvttsd2si(output, input); |
| 2708 | __ jmp(&done); |
| 2709 | __ Bind(&nan); |
| 2710 | // output = 0 |
| 2711 | __ xorl(output, output); |
| 2712 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2713 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2714 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2715 | |
| 2716 | default: |
| 2717 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2718 | << " to " << result_type; |
| 2719 | } |
| 2720 | break; |
| 2721 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2722 | case Primitive::kPrimLong: |
| 2723 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2724 | case Primitive::kPrimBoolean: |
| 2725 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2726 | case Primitive::kPrimByte: |
| 2727 | case Primitive::kPrimShort: |
| 2728 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2729 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2730 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2731 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2732 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2733 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2734 | __ cdq(); |
| 2735 | break; |
| 2736 | |
| 2737 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2738 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2739 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2740 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2741 | break; |
| 2742 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2743 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2744 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2745 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2746 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2747 | break; |
| 2748 | |
| 2749 | default: |
| 2750 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2751 | << " to " << result_type; |
| 2752 | } |
| 2753 | break; |
| 2754 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2755 | case Primitive::kPrimChar: |
| 2756 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2757 | case Primitive::kPrimLong: |
| 2758 | // Type conversion from long to short is a result of code transformations. |
| 2759 | if (in.IsRegisterPair()) { |
| 2760 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2761 | } else if (in.IsDoubleStackSlot()) { |
| 2762 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2763 | } else { |
| 2764 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2765 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2766 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2767 | } |
| 2768 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2769 | case Primitive::kPrimBoolean: |
| 2770 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2771 | case Primitive::kPrimByte: |
| 2772 | case Primitive::kPrimShort: |
| 2773 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2774 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2775 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2776 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2777 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2778 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2779 | } else { |
| 2780 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2781 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2782 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2783 | } |
| 2784 | break; |
| 2785 | |
| 2786 | default: |
| 2787 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2788 | << " to " << result_type; |
| 2789 | } |
| 2790 | break; |
| 2791 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2792 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2793 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2794 | case Primitive::kPrimBoolean: |
| 2795 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2796 | case Primitive::kPrimByte: |
| 2797 | case Primitive::kPrimShort: |
| 2798 | case Primitive::kPrimInt: |
| 2799 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2800 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2801 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2802 | break; |
| 2803 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2804 | case Primitive::kPrimLong: { |
| 2805 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2806 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2807 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2808 | // Create stack space for the call to |
| 2809 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2810 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2811 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2812 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2813 | __ subl(ESP, Immediate(adjustment)); |
| 2814 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2815 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2816 | // Load the value to the FP stack, using temporaries if needed. |
| 2817 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2818 | |
| 2819 | if (out.IsStackSlot()) { |
| 2820 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2821 | } else { |
| 2822 | __ fstps(Address(ESP, 0)); |
| 2823 | Location stack_temp = Location::StackSlot(0); |
| 2824 | codegen_->Move32(out, stack_temp); |
| 2825 | } |
| 2826 | |
| 2827 | // Remove the temporary stack space we allocated. |
| 2828 | if (adjustment != 0) { |
| 2829 | __ addl(ESP, Immediate(adjustment)); |
| 2830 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2831 | break; |
| 2832 | } |
| 2833 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2834 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2835 | // Processing a Dex `double-to-float' instruction. |
| 2836 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2837 | break; |
| 2838 | |
| 2839 | default: |
| 2840 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2841 | << " to " << result_type; |
| 2842 | }; |
| 2843 | break; |
| 2844 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2845 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2846 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2847 | case Primitive::kPrimBoolean: |
| 2848 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2849 | case Primitive::kPrimByte: |
| 2850 | case Primitive::kPrimShort: |
| 2851 | case Primitive::kPrimInt: |
| 2852 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2853 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2854 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2855 | break; |
| 2856 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2857 | case Primitive::kPrimLong: { |
| 2858 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2859 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2860 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2861 | // Create stack space for the call to |
| 2862 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2863 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2864 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2865 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2866 | __ subl(ESP, Immediate(adjustment)); |
| 2867 | } |
| 2868 | |
| 2869 | // Load the value to the FP stack, using temporaries if needed. |
| 2870 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2871 | |
| 2872 | if (out.IsDoubleStackSlot()) { |
| 2873 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2874 | } else { |
| 2875 | __ fstpl(Address(ESP, 0)); |
| 2876 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2877 | codegen_->Move64(out, stack_temp); |
| 2878 | } |
| 2879 | |
| 2880 | // Remove the temporary stack space we allocated. |
| 2881 | if (adjustment != 0) { |
| 2882 | __ addl(ESP, Immediate(adjustment)); |
| 2883 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2884 | break; |
| 2885 | } |
| 2886 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2887 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2888 | // Processing a Dex `float-to-double' instruction. |
| 2889 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2890 | break; |
| 2891 | |
| 2892 | default: |
| 2893 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2894 | << " to " << result_type; |
| 2895 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2896 | break; |
| 2897 | |
| 2898 | default: |
| 2899 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2900 | << " to " << result_type; |
| 2901 | } |
| 2902 | } |
| 2903 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2904 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2905 | LocationSummary* locations = |
| 2906 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2907 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2908 | case Primitive::kPrimInt: { |
| 2909 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2910 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2911 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2912 | break; |
| 2913 | } |
| 2914 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2915 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2916 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2917 | locations->SetInAt(1, Location::Any()); |
| 2918 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2919 | break; |
| 2920 | } |
| 2921 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2922 | case Primitive::kPrimFloat: |
| 2923 | case Primitive::kPrimDouble: { |
| 2924 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2925 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2926 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2927 | } else if (add->InputAt(1)->IsConstant()) { |
| 2928 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2929 | } else { |
| 2930 | locations->SetInAt(1, Location::Any()); |
| 2931 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2932 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2933 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2934 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2935 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2936 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2937 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2938 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2939 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2940 | } |
| 2941 | |
| 2942 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2943 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2944 | Location first = locations->InAt(0); |
| 2945 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2946 | Location out = locations->Out(); |
| 2947 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2948 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2949 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2950 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2951 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2952 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2953 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2954 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2955 | } else { |
| 2956 | __ leal(out.AsRegister<Register>(), Address( |
| 2957 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2958 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2959 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2960 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2961 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2962 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2963 | } else { |
| 2964 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2965 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2966 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2967 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2968 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2969 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2970 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2971 | } |
| 2972 | |
| 2973 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2974 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2975 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2976 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2977 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2978 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2979 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2980 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2981 | } else { |
| 2982 | DCHECK(second.IsConstant()) << second; |
| 2983 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2984 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2985 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2986 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2987 | break; |
| 2988 | } |
| 2989 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2990 | case Primitive::kPrimFloat: { |
| 2991 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2992 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2993 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2994 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2995 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2996 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2997 | codegen_->LiteralFloatAddress( |
| 2998 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2999 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3000 | } else { |
| 3001 | DCHECK(second.IsStackSlot()); |
| 3002 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3003 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3004 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3005 | } |
| 3006 | |
| 3007 | case Primitive::kPrimDouble: { |
| 3008 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3009 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3010 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3011 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3012 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3013 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3014 | codegen_->LiteralDoubleAddress( |
| 3015 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3016 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3017 | } else { |
| 3018 | DCHECK(second.IsDoubleStackSlot()); |
| 3019 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3020 | } |
| 3021 | break; |
| 3022 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3023 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3024 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3025 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3026 | } |
| 3027 | } |
| 3028 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3029 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3030 | LocationSummary* locations = |
| 3031 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3032 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3033 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3034 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3035 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3036 | locations->SetInAt(1, Location::Any()); |
| 3037 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3038 | break; |
| 3039 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3040 | case Primitive::kPrimFloat: |
| 3041 | case Primitive::kPrimDouble: { |
| 3042 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3043 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3044 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3045 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3046 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3047 | } else { |
| 3048 | locations->SetInAt(1, Location::Any()); |
| 3049 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3050 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3051 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3052 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3053 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3054 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3055 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3056 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3057 | } |
| 3058 | |
| 3059 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3060 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3061 | Location first = locations->InAt(0); |
| 3062 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3063 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3064 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3065 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3066 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3067 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3068 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3069 | __ subl(first.AsRegister<Register>(), |
| 3070 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3071 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3072 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3073 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3074 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3075 | } |
| 3076 | |
| 3077 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3078 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3079 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3080 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3081 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3082 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3083 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3084 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3085 | } else { |
| 3086 | DCHECK(second.IsConstant()) << second; |
| 3087 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3088 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3089 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3090 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3091 | break; |
| 3092 | } |
| 3093 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3094 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3095 | if (second.IsFpuRegister()) { |
| 3096 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3097 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3098 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3099 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3100 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3101 | codegen_->LiteralFloatAddress( |
| 3102 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3103 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3104 | } else { |
| 3105 | DCHECK(second.IsStackSlot()); |
| 3106 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3107 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3108 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3109 | } |
| 3110 | |
| 3111 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3112 | if (second.IsFpuRegister()) { |
| 3113 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3114 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3115 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3116 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3117 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3118 | codegen_->LiteralDoubleAddress( |
| 3119 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3120 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3121 | } else { |
| 3122 | DCHECK(second.IsDoubleStackSlot()); |
| 3123 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3124 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3125 | break; |
| 3126 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3127 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3128 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3129 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3130 | } |
| 3131 | } |
| 3132 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3133 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3134 | LocationSummary* locations = |
| 3135 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3136 | switch (mul->GetResultType()) { |
| 3137 | case Primitive::kPrimInt: |
| 3138 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3139 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3140 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3141 | // Can use 3 operand multiply. |
| 3142 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3143 | } else { |
| 3144 | locations->SetOut(Location::SameAsFirstInput()); |
| 3145 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3146 | break; |
| 3147 | case Primitive::kPrimLong: { |
| 3148 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3149 | locations->SetInAt(1, Location::Any()); |
| 3150 | locations->SetOut(Location::SameAsFirstInput()); |
| 3151 | // Needed for imul on 32bits with 64bits output. |
| 3152 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3153 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3154 | break; |
| 3155 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3156 | case Primitive::kPrimFloat: |
| 3157 | case Primitive::kPrimDouble: { |
| 3158 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3159 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3160 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3161 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3162 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3163 | } else { |
| 3164 | locations->SetInAt(1, Location::Any()); |
| 3165 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3166 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3167 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3168 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3169 | |
| 3170 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3171 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3172 | } |
| 3173 | } |
| 3174 | |
| 3175 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3176 | LocationSummary* locations = mul->GetLocations(); |
| 3177 | Location first = locations->InAt(0); |
| 3178 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3179 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3180 | |
| 3181 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3182 | case Primitive::kPrimInt: |
| 3183 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3184 | // problems where the output may not be the same as the first operand. |
| 3185 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3186 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3187 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3188 | } else if (second.IsRegister()) { |
| 3189 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3190 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3191 | } else { |
| 3192 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3193 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3194 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3195 | } |
| 3196 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3197 | |
| 3198 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3199 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3200 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3201 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3202 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3203 | |
| 3204 | DCHECK_EQ(EAX, eax); |
| 3205 | DCHECK_EQ(EDX, edx); |
| 3206 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3207 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3208 | // output: in1 |
| 3209 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3210 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3211 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3212 | if (second.IsConstant()) { |
| 3213 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3214 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3215 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3216 | int32_t low_value = Low32Bits(value); |
| 3217 | int32_t high_value = High32Bits(value); |
| 3218 | Immediate low(low_value); |
| 3219 | Immediate high(high_value); |
| 3220 | |
| 3221 | __ movl(eax, high); |
| 3222 | // eax <- in1.lo * in2.hi |
| 3223 | __ imull(eax, in1_lo); |
| 3224 | // in1.hi <- in1.hi * in2.lo |
| 3225 | __ imull(in1_hi, low); |
| 3226 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3227 | __ addl(in1_hi, eax); |
| 3228 | // move in2_lo to eax to prepare for double precision |
| 3229 | __ movl(eax, low); |
| 3230 | // edx:eax <- in1.lo * in2.lo |
| 3231 | __ mull(in1_lo); |
| 3232 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3233 | __ addl(in1_hi, edx); |
| 3234 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3235 | __ movl(in1_lo, eax); |
| 3236 | } else if (second.IsRegisterPair()) { |
| 3237 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3238 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3239 | |
| 3240 | __ movl(eax, in2_hi); |
| 3241 | // eax <- in1.lo * in2.hi |
| 3242 | __ imull(eax, in1_lo); |
| 3243 | // in1.hi <- in1.hi * in2.lo |
| 3244 | __ imull(in1_hi, in2_lo); |
| 3245 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3246 | __ addl(in1_hi, eax); |
| 3247 | // move in1_lo to eax to prepare for double precision |
| 3248 | __ movl(eax, in1_lo); |
| 3249 | // edx:eax <- in1.lo * in2.lo |
| 3250 | __ mull(in2_lo); |
| 3251 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3252 | __ addl(in1_hi, edx); |
| 3253 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3254 | __ movl(in1_lo, eax); |
| 3255 | } else { |
| 3256 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3257 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3258 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3259 | |
| 3260 | __ movl(eax, in2_hi); |
| 3261 | // eax <- in1.lo * in2.hi |
| 3262 | __ imull(eax, in1_lo); |
| 3263 | // in1.hi <- in1.hi * in2.lo |
| 3264 | __ imull(in1_hi, in2_lo); |
| 3265 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3266 | __ addl(in1_hi, eax); |
| 3267 | // move in1_lo to eax to prepare for double precision |
| 3268 | __ movl(eax, in1_lo); |
| 3269 | // edx:eax <- in1.lo * in2.lo |
| 3270 | __ mull(in2_lo); |
| 3271 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3272 | __ addl(in1_hi, edx); |
| 3273 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3274 | __ movl(in1_lo, eax); |
| 3275 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3276 | |
| 3277 | break; |
| 3278 | } |
| 3279 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3280 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3281 | DCHECK(first.Equals(locations->Out())); |
| 3282 | if (second.IsFpuRegister()) { |
| 3283 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3284 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3285 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3286 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3287 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3288 | codegen_->LiteralFloatAddress( |
| 3289 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3290 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3291 | } else { |
| 3292 | DCHECK(second.IsStackSlot()); |
| 3293 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3294 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3295 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3296 | } |
| 3297 | |
| 3298 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3299 | DCHECK(first.Equals(locations->Out())); |
| 3300 | if (second.IsFpuRegister()) { |
| 3301 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3302 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3303 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3304 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3305 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3306 | codegen_->LiteralDoubleAddress( |
| 3307 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3308 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3309 | } else { |
| 3310 | DCHECK(second.IsDoubleStackSlot()); |
| 3311 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3312 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3313 | break; |
| 3314 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3315 | |
| 3316 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3317 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3318 | } |
| 3319 | } |
| 3320 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3321 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3322 | uint32_t temp_offset, |
| 3323 | uint32_t stack_adjustment, |
| 3324 | bool is_fp, |
| 3325 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3326 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3327 | DCHECK(!is_wide); |
| 3328 | if (is_fp) { |
| 3329 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3330 | } else { |
| 3331 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3332 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3333 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3334 | DCHECK(is_wide); |
| 3335 | if (is_fp) { |
| 3336 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3337 | } else { |
| 3338 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3339 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3340 | } else { |
| 3341 | // 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] | 3342 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3343 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3344 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3345 | if (is_fp) { |
| 3346 | __ flds(Address(ESP, temp_offset)); |
| 3347 | } else { |
| 3348 | __ filds(Address(ESP, temp_offset)); |
| 3349 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3350 | } else { |
| 3351 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3352 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3353 | if (is_fp) { |
| 3354 | __ fldl(Address(ESP, temp_offset)); |
| 3355 | } else { |
| 3356 | __ fildl(Address(ESP, temp_offset)); |
| 3357 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3358 | } |
| 3359 | } |
| 3360 | } |
| 3361 | |
| 3362 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3363 | Primitive::Type type = rem->GetResultType(); |
| 3364 | bool is_float = type == Primitive::kPrimFloat; |
| 3365 | size_t elem_size = Primitive::ComponentSize(type); |
| 3366 | LocationSummary* locations = rem->GetLocations(); |
| 3367 | Location first = locations->InAt(0); |
| 3368 | Location second = locations->InAt(1); |
| 3369 | Location out = locations->Out(); |
| 3370 | |
| 3371 | // Create stack space for 2 elements. |
| 3372 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3373 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3374 | |
| 3375 | // 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] | 3376 | const bool is_wide = !is_float; |
| 3377 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3378 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3379 | |
| 3380 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3381 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3382 | __ Bind(&retry); |
| 3383 | __ fprem(); |
| 3384 | |
| 3385 | // Move FP status to AX. |
| 3386 | __ fstsw(); |
| 3387 | |
| 3388 | // And see if the argument reduction is complete. This is signaled by the |
| 3389 | // C2 FPU flag bit set to 0. |
| 3390 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3391 | __ j(kNotEqual, &retry); |
| 3392 | |
| 3393 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3394 | // Store FP top of stack to real stack. |
| 3395 | if (is_float) { |
| 3396 | __ fsts(Address(ESP, 0)); |
| 3397 | } else { |
| 3398 | __ fstl(Address(ESP, 0)); |
| 3399 | } |
| 3400 | |
| 3401 | // Pop the 2 items from the FP stack. |
| 3402 | __ fucompp(); |
| 3403 | |
| 3404 | // Load the value from the stack into an XMM register. |
| 3405 | DCHECK(out.IsFpuRegister()) << out; |
| 3406 | if (is_float) { |
| 3407 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3408 | } else { |
| 3409 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3410 | } |
| 3411 | |
| 3412 | // And remove the temporary stack space we allocated. |
| 3413 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3414 | } |
| 3415 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3416 | |
| 3417 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3418 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3419 | |
| 3420 | LocationSummary* locations = instruction->GetLocations(); |
| 3421 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3422 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3423 | |
| 3424 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3425 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3426 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3427 | |
| 3428 | DCHECK(imm == 1 || imm == -1); |
| 3429 | |
| 3430 | if (instruction->IsRem()) { |
| 3431 | __ xorl(out_register, out_register); |
| 3432 | } else { |
| 3433 | __ movl(out_register, input_register); |
| 3434 | if (imm == -1) { |
| 3435 | __ negl(out_register); |
| 3436 | } |
| 3437 | } |
| 3438 | } |
| 3439 | |
| 3440 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3441 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3442 | LocationSummary* locations = instruction->GetLocations(); |
| 3443 | |
| 3444 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3445 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3446 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3447 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3448 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3449 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3450 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3451 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3452 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3453 | __ testl(input_register, input_register); |
| 3454 | __ cmovl(kGreaterEqual, num, input_register); |
| 3455 | int shift = CTZ(imm); |
| 3456 | __ sarl(num, Immediate(shift)); |
| 3457 | |
| 3458 | if (imm < 0) { |
| 3459 | __ negl(num); |
| 3460 | } |
| 3461 | |
| 3462 | __ movl(out_register, num); |
| 3463 | } |
| 3464 | |
| 3465 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3466 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3467 | |
| 3468 | LocationSummary* locations = instruction->GetLocations(); |
| 3469 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3470 | |
| 3471 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3472 | Register out = locations->Out().AsRegister<Register>(); |
| 3473 | Register num; |
| 3474 | Register edx; |
| 3475 | |
| 3476 | if (instruction->IsDiv()) { |
| 3477 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3478 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3479 | } else { |
| 3480 | edx = locations->Out().AsRegister<Register>(); |
| 3481 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3482 | } |
| 3483 | |
| 3484 | DCHECK_EQ(EAX, eax); |
| 3485 | DCHECK_EQ(EDX, edx); |
| 3486 | if (instruction->IsDiv()) { |
| 3487 | DCHECK_EQ(EAX, out); |
| 3488 | } else { |
| 3489 | DCHECK_EQ(EDX, out); |
| 3490 | } |
| 3491 | |
| 3492 | int64_t magic; |
| 3493 | int shift; |
| 3494 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3495 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3496 | // Save the numerator. |
| 3497 | __ movl(num, eax); |
| 3498 | |
| 3499 | // EAX = magic |
| 3500 | __ movl(eax, Immediate(magic)); |
| 3501 | |
| 3502 | // EDX:EAX = magic * numerator |
| 3503 | __ imull(num); |
| 3504 | |
| 3505 | if (imm > 0 && magic < 0) { |
| 3506 | // EDX += num |
| 3507 | __ addl(edx, num); |
| 3508 | } else if (imm < 0 && magic > 0) { |
| 3509 | __ subl(edx, num); |
| 3510 | } |
| 3511 | |
| 3512 | // Shift if needed. |
| 3513 | if (shift != 0) { |
| 3514 | __ sarl(edx, Immediate(shift)); |
| 3515 | } |
| 3516 | |
| 3517 | // EDX += 1 if EDX < 0 |
| 3518 | __ movl(eax, edx); |
| 3519 | __ shrl(edx, Immediate(31)); |
| 3520 | __ addl(edx, eax); |
| 3521 | |
| 3522 | if (instruction->IsRem()) { |
| 3523 | __ movl(eax, num); |
| 3524 | __ imull(edx, Immediate(imm)); |
| 3525 | __ subl(eax, edx); |
| 3526 | __ movl(edx, eax); |
| 3527 | } else { |
| 3528 | __ movl(eax, edx); |
| 3529 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3530 | } |
| 3531 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3532 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3533 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3534 | |
| 3535 | LocationSummary* locations = instruction->GetLocations(); |
| 3536 | Location out = locations->Out(); |
| 3537 | Location first = locations->InAt(0); |
| 3538 | Location second = locations->InAt(1); |
| 3539 | bool is_div = instruction->IsDiv(); |
| 3540 | |
| 3541 | switch (instruction->GetResultType()) { |
| 3542 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3543 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3544 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3545 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3546 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3547 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3548 | |
| 3549 | if (imm == 0) { |
| 3550 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3551 | } else if (imm == 1 || imm == -1) { |
| 3552 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3553 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3554 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3555 | } else { |
| 3556 | DCHECK(imm <= -2 || imm >= 2); |
| 3557 | GenerateDivRemWithAnyConstant(instruction); |
| 3558 | } |
| 3559 | } else { |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3560 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86( |
| 3561 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3562 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3563 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3564 | Register second_reg = second.AsRegister<Register>(); |
| 3565 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3566 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3567 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3568 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3569 | __ cmpl(second_reg, Immediate(-1)); |
| 3570 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3571 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3572 | // edx:eax <- sign-extended of eax |
| 3573 | __ cdq(); |
| 3574 | // eax = quotient, edx = remainder |
| 3575 | __ idivl(second_reg); |
| 3576 | __ Bind(slow_path->GetExitLabel()); |
| 3577 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3578 | break; |
| 3579 | } |
| 3580 | |
| 3581 | case Primitive::kPrimLong: { |
| 3582 | InvokeRuntimeCallingConvention calling_convention; |
| 3583 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3584 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3585 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3586 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3587 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3588 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3589 | |
| 3590 | if (is_div) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3591 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3592 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3593 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3594 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3595 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3596 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3597 | break; |
| 3598 | } |
| 3599 | |
| 3600 | default: |
| 3601 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3602 | } |
| 3603 | } |
| 3604 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3605 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3606 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3607 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3608 | : LocationSummary::kNoCall; |
| 3609 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3610 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3611 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3612 | case Primitive::kPrimInt: { |
| 3613 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3614 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3615 | locations->SetOut(Location::SameAsFirstInput()); |
| 3616 | // Intel uses edx:eax as the dividend. |
| 3617 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3618 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3619 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3620 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3621 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3622 | locations->AddTemp(Location::RequiresRegister()); |
| 3623 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3624 | break; |
| 3625 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3626 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3627 | InvokeRuntimeCallingConvention calling_convention; |
| 3628 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3629 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3630 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3631 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3632 | // Runtime helper puts the result in EAX, EDX. |
| 3633 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3634 | break; |
| 3635 | } |
| 3636 | case Primitive::kPrimFloat: |
| 3637 | case Primitive::kPrimDouble: { |
| 3638 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3639 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3640 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3641 | } else if (div->InputAt(1)->IsConstant()) { |
| 3642 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3643 | } else { |
| 3644 | locations->SetInAt(1, Location::Any()); |
| 3645 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3646 | locations->SetOut(Location::SameAsFirstInput()); |
| 3647 | break; |
| 3648 | } |
| 3649 | |
| 3650 | default: |
| 3651 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3652 | } |
| 3653 | } |
| 3654 | |
| 3655 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3656 | LocationSummary* locations = div->GetLocations(); |
| 3657 | Location first = locations->InAt(0); |
| 3658 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3659 | |
| 3660 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3661 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3662 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3663 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3664 | break; |
| 3665 | } |
| 3666 | |
| 3667 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3668 | if (second.IsFpuRegister()) { |
| 3669 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3670 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3671 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3672 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3673 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3674 | codegen_->LiteralFloatAddress( |
| 3675 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3676 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3677 | } else { |
| 3678 | DCHECK(second.IsStackSlot()); |
| 3679 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3680 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3681 | break; |
| 3682 | } |
| 3683 | |
| 3684 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3685 | if (second.IsFpuRegister()) { |
| 3686 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3687 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3688 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3689 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3690 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3691 | codegen_->LiteralDoubleAddress( |
| 3692 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3693 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3694 | } else { |
| 3695 | DCHECK(second.IsDoubleStackSlot()); |
| 3696 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3697 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3698 | break; |
| 3699 | } |
| 3700 | |
| 3701 | default: |
| 3702 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3703 | } |
| 3704 | } |
| 3705 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3706 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3707 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3708 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3709 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3710 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3711 | : LocationSummary::kNoCall; |
| 3712 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3713 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3714 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3715 | case Primitive::kPrimInt: { |
| 3716 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3717 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3718 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3719 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3720 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3721 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3722 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3723 | locations->AddTemp(Location::RequiresRegister()); |
| 3724 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3725 | break; |
| 3726 | } |
| 3727 | case Primitive::kPrimLong: { |
| 3728 | InvokeRuntimeCallingConvention calling_convention; |
| 3729 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3730 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3731 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3732 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3733 | // Runtime helper puts the result in EAX, EDX. |
| 3734 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3735 | break; |
| 3736 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3737 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3738 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3739 | locations->SetInAt(0, Location::Any()); |
| 3740 | locations->SetInAt(1, Location::Any()); |
| 3741 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3742 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3743 | break; |
| 3744 | } |
| 3745 | |
| 3746 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3747 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3748 | } |
| 3749 | } |
| 3750 | |
| 3751 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3752 | Primitive::Type type = rem->GetResultType(); |
| 3753 | switch (type) { |
| 3754 | case Primitive::kPrimInt: |
| 3755 | case Primitive::kPrimLong: { |
| 3756 | GenerateDivRemIntegral(rem); |
| 3757 | break; |
| 3758 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3759 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3760 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3761 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3762 | break; |
| 3763 | } |
| 3764 | default: |
| 3765 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3766 | } |
| 3767 | } |
| 3768 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3769 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3770 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3771 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3772 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3773 | case Primitive::kPrimByte: |
| 3774 | case Primitive::kPrimChar: |
| 3775 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3776 | case Primitive::kPrimInt: { |
| 3777 | locations->SetInAt(0, Location::Any()); |
| 3778 | break; |
| 3779 | } |
| 3780 | case Primitive::kPrimLong: { |
| 3781 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3782 | if (!instruction->IsConstant()) { |
| 3783 | locations->AddTemp(Location::RequiresRegister()); |
| 3784 | } |
| 3785 | break; |
| 3786 | } |
| 3787 | default: |
| 3788 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3789 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3790 | } |
| 3791 | |
| 3792 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3793 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3794 | codegen_->AddSlowPath(slow_path); |
| 3795 | |
| 3796 | LocationSummary* locations = instruction->GetLocations(); |
| 3797 | Location value = locations->InAt(0); |
| 3798 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3799 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3800 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3801 | case Primitive::kPrimByte: |
| 3802 | case Primitive::kPrimChar: |
| 3803 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3804 | case Primitive::kPrimInt: { |
| 3805 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3806 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3807 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3808 | } else if (value.IsStackSlot()) { |
| 3809 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3810 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3811 | } else { |
| 3812 | DCHECK(value.IsConstant()) << value; |
| 3813 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3814 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3815 | } |
| 3816 | } |
| 3817 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3818 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3819 | case Primitive::kPrimLong: { |
| 3820 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3821 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3822 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3823 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3824 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3825 | } else { |
| 3826 | DCHECK(value.IsConstant()) << value; |
| 3827 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3828 | __ jmp(slow_path->GetEntryLabel()); |
| 3829 | } |
| 3830 | } |
| 3831 | break; |
| 3832 | } |
| 3833 | default: |
| 3834 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3835 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3836 | } |
| 3837 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3838 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3839 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3840 | |
| 3841 | LocationSummary* locations = |
| 3842 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3843 | |
| 3844 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3845 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3846 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3847 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3848 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3849 | // The shift count needs to be in CL or a constant. |
| 3850 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3851 | locations->SetOut(Location::SameAsFirstInput()); |
| 3852 | break; |
| 3853 | } |
| 3854 | default: |
| 3855 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3856 | } |
| 3857 | } |
| 3858 | |
| 3859 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3860 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3861 | |
| 3862 | LocationSummary* locations = op->GetLocations(); |
| 3863 | Location first = locations->InAt(0); |
| 3864 | Location second = locations->InAt(1); |
| 3865 | DCHECK(first.Equals(locations->Out())); |
| 3866 | |
| 3867 | switch (op->GetResultType()) { |
| 3868 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3869 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3870 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3871 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3872 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3873 | DCHECK_EQ(ECX, second_reg); |
| 3874 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3875 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3876 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3877 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3878 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3879 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3880 | } |
| 3881 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3882 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3883 | if (shift == 0) { |
| 3884 | return; |
| 3885 | } |
| 3886 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3887 | if (op->IsShl()) { |
| 3888 | __ shll(first_reg, imm); |
| 3889 | } else if (op->IsShr()) { |
| 3890 | __ sarl(first_reg, imm); |
| 3891 | } else { |
| 3892 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3893 | } |
| 3894 | } |
| 3895 | break; |
| 3896 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3897 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3898 | if (second.IsRegister()) { |
| 3899 | Register second_reg = second.AsRegister<Register>(); |
| 3900 | DCHECK_EQ(ECX, second_reg); |
| 3901 | if (op->IsShl()) { |
| 3902 | GenerateShlLong(first, second_reg); |
| 3903 | } else if (op->IsShr()) { |
| 3904 | GenerateShrLong(first, second_reg); |
| 3905 | } else { |
| 3906 | GenerateUShrLong(first, second_reg); |
| 3907 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3908 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3909 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3910 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3911 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3912 | if (shift != 0) { |
| 3913 | if (op->IsShl()) { |
| 3914 | GenerateShlLong(first, shift); |
| 3915 | } else if (op->IsShr()) { |
| 3916 | GenerateShrLong(first, shift); |
| 3917 | } else { |
| 3918 | GenerateUShrLong(first, shift); |
| 3919 | } |
| 3920 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3921 | } |
| 3922 | break; |
| 3923 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3924 | default: |
| 3925 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3926 | } |
| 3927 | } |
| 3928 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3929 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3930 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3931 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3932 | if (shift == 1) { |
| 3933 | // This is just an addition. |
| 3934 | __ addl(low, low); |
| 3935 | __ adcl(high, high); |
| 3936 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3937 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3938 | codegen_->EmitParallelMoves( |
| 3939 | loc.ToLow(), |
| 3940 | loc.ToHigh(), |
| 3941 | Primitive::kPrimInt, |
| 3942 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3943 | loc.ToLow(), |
| 3944 | Primitive::kPrimInt); |
| 3945 | } else if (shift > 32) { |
| 3946 | // Low part becomes 0. High part is low part << (shift-32). |
| 3947 | __ movl(high, low); |
| 3948 | __ shll(high, Immediate(shift - 32)); |
| 3949 | __ xorl(low, low); |
| 3950 | } else { |
| 3951 | // Between 1 and 31. |
| 3952 | __ shld(high, low, Immediate(shift)); |
| 3953 | __ shll(low, Immediate(shift)); |
| 3954 | } |
| 3955 | } |
| 3956 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3957 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3958 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3959 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3960 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3961 | __ testl(shifter, Immediate(32)); |
| 3962 | __ j(kEqual, &done); |
| 3963 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3964 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3965 | __ Bind(&done); |
| 3966 | } |
| 3967 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3968 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3969 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3970 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3971 | if (shift == 32) { |
| 3972 | // Need to copy the sign. |
| 3973 | DCHECK_NE(low, high); |
| 3974 | __ movl(low, high); |
| 3975 | __ sarl(high, Immediate(31)); |
| 3976 | } else if (shift > 32) { |
| 3977 | DCHECK_NE(low, high); |
| 3978 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3979 | __ movl(low, high); |
| 3980 | __ sarl(high, Immediate(31)); |
| 3981 | __ sarl(low, Immediate(shift - 32)); |
| 3982 | } else { |
| 3983 | // Between 1 and 31. |
| 3984 | __ shrd(low, high, Immediate(shift)); |
| 3985 | __ sarl(high, Immediate(shift)); |
| 3986 | } |
| 3987 | } |
| 3988 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3989 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3990 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3991 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3992 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3993 | __ testl(shifter, Immediate(32)); |
| 3994 | __ j(kEqual, &done); |
| 3995 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3996 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3997 | __ Bind(&done); |
| 3998 | } |
| 3999 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4000 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 4001 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4002 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4003 | if (shift == 32) { |
| 4004 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 4005 | codegen_->EmitParallelMoves( |
| 4006 | loc.ToHigh(), |
| 4007 | loc.ToLow(), |
| 4008 | Primitive::kPrimInt, |
| 4009 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4010 | loc.ToHigh(), |
| 4011 | Primitive::kPrimInt); |
| 4012 | } else if (shift > 32) { |
| 4013 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4014 | __ movl(low, high); |
| 4015 | __ shrl(low, Immediate(shift - 32)); |
| 4016 | __ xorl(high, high); |
| 4017 | } else { |
| 4018 | // Between 1 and 31. |
| 4019 | __ shrd(low, high, Immediate(shift)); |
| 4020 | __ shrl(high, Immediate(shift)); |
| 4021 | } |
| 4022 | } |
| 4023 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4024 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4025 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4026 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4027 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4028 | __ testl(shifter, Immediate(32)); |
| 4029 | __ j(kEqual, &done); |
| 4030 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4031 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4032 | __ Bind(&done); |
| 4033 | } |
| 4034 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4035 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4036 | LocationSummary* locations = |
| 4037 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 4038 | |
| 4039 | switch (ror->GetResultType()) { |
| 4040 | case Primitive::kPrimLong: |
| 4041 | // Add the temporary needed. |
| 4042 | locations->AddTemp(Location::RequiresRegister()); |
| 4043 | FALLTHROUGH_INTENDED; |
| 4044 | case Primitive::kPrimInt: |
| 4045 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4046 | // The shift count needs to be in CL (unless it is a constant). |
| 4047 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4048 | locations->SetOut(Location::SameAsFirstInput()); |
| 4049 | break; |
| 4050 | default: |
| 4051 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4052 | UNREACHABLE(); |
| 4053 | } |
| 4054 | } |
| 4055 | |
| 4056 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4057 | LocationSummary* locations = ror->GetLocations(); |
| 4058 | Location first = locations->InAt(0); |
| 4059 | Location second = locations->InAt(1); |
| 4060 | |
| 4061 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 4062 | Register first_reg = first.AsRegister<Register>(); |
| 4063 | if (second.IsRegister()) { |
| 4064 | Register second_reg = second.AsRegister<Register>(); |
| 4065 | __ rorl(first_reg, second_reg); |
| 4066 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4067 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4068 | __ rorl(first_reg, imm); |
| 4069 | } |
| 4070 | return; |
| 4071 | } |
| 4072 | |
| 4073 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 4074 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4075 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4076 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4077 | if (second.IsRegister()) { |
| 4078 | Register second_reg = second.AsRegister<Register>(); |
| 4079 | DCHECK_EQ(second_reg, ECX); |
| 4080 | __ movl(temp_reg, first_reg_hi); |
| 4081 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4082 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4083 | __ movl(temp_reg, first_reg_hi); |
| 4084 | __ testl(second_reg, Immediate(32)); |
| 4085 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4086 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4087 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4088 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4089 | if (shift_amt == 0) { |
| 4090 | // Already fine. |
| 4091 | return; |
| 4092 | } |
| 4093 | if (shift_amt == 32) { |
| 4094 | // Just swap. |
| 4095 | __ movl(temp_reg, first_reg_lo); |
| 4096 | __ movl(first_reg_lo, first_reg_hi); |
| 4097 | __ movl(first_reg_hi, temp_reg); |
| 4098 | return; |
| 4099 | } |
| 4100 | |
| 4101 | Immediate imm(shift_amt); |
| 4102 | // Save the constents of the low value. |
| 4103 | __ movl(temp_reg, first_reg_lo); |
| 4104 | |
| 4105 | // Shift right into low, feeding bits from high. |
| 4106 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4107 | |
| 4108 | // Shift right into high, feeding bits from the original low. |
| 4109 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4110 | |
| 4111 | // Swap if needed. |
| 4112 | if (shift_amt > 32) { |
| 4113 | __ movl(temp_reg, first_reg_lo); |
| 4114 | __ movl(first_reg_lo, first_reg_hi); |
| 4115 | __ movl(first_reg_hi, temp_reg); |
| 4116 | } |
| 4117 | } |
| 4118 | } |
| 4119 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4120 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4121 | HandleShift(shl); |
| 4122 | } |
| 4123 | |
| 4124 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4125 | HandleShift(shl); |
| 4126 | } |
| 4127 | |
| 4128 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4129 | HandleShift(shr); |
| 4130 | } |
| 4131 | |
| 4132 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4133 | HandleShift(shr); |
| 4134 | } |
| 4135 | |
| 4136 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4137 | HandleShift(ushr); |
| 4138 | } |
| 4139 | |
| 4140 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4141 | HandleShift(ushr); |
| 4142 | } |
| 4143 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4144 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4145 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4146 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4147 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4148 | if (instruction->IsStringAlloc()) { |
| 4149 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4150 | } else { |
| 4151 | InvokeRuntimeCallingConvention calling_convention; |
| 4152 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4153 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4154 | } |
| 4155 | |
| 4156 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4157 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4158 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4159 | if (instruction->IsStringAlloc()) { |
| 4160 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4161 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4162 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4163 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4164 | __ call(Address(temp, code_offset.Int32Value())); |
| 4165 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4166 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4167 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame^] | 4168 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4169 | DCHECK(!codegen_->IsLeafMethod()); |
| 4170 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4171 | } |
| 4172 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4173 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 4174 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4175 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4176 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4177 | InvokeRuntimeCallingConvention calling_convention; |
| 4178 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4179 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4180 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4181 | } |
| 4182 | |
| 4183 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 4184 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4185 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex().index_)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4186 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4187 | // of poisoning the reference. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4188 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4189 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4190 | DCHECK(!codegen_->IsLeafMethod()); |
| 4191 | } |
| 4192 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4193 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4194 | LocationSummary* locations = |
| 4195 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4196 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4197 | if (location.IsStackSlot()) { |
| 4198 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4199 | } else if (location.IsDoubleStackSlot()) { |
| 4200 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4201 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4202 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4203 | } |
| 4204 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4205 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4206 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4207 | } |
| 4208 | |
| 4209 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4210 | LocationSummary* locations = |
| 4211 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4212 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4213 | } |
| 4214 | |
| 4215 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4216 | } |
| 4217 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4218 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4219 | LocationSummary* locations = |
| 4220 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4221 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4222 | locations->SetOut(Location::RequiresRegister()); |
| 4223 | } |
| 4224 | |
| 4225 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4226 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4227 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4228 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4229 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4230 | __ movl(locations->Out().AsRegister<Register>(), |
| 4231 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4232 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4233 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4234 | instruction->GetIndex(), kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4235 | __ movl(locations->Out().AsRegister<Register>(), |
| 4236 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4237 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4238 | // temp = temp->GetImtEntryAt(method_offset); |
| 4239 | __ movl(locations->Out().AsRegister<Register>(), |
| 4240 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4241 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4242 | } |
| 4243 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4244 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4245 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4246 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4247 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4248 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4249 | } |
| 4250 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4251 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4252 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4253 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4254 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4255 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4256 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4257 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4258 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4259 | break; |
| 4260 | |
| 4261 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4262 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4263 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4264 | break; |
| 4265 | |
| 4266 | default: |
| 4267 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4268 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4269 | } |
| 4270 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4271 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4272 | LocationSummary* locations = |
| 4273 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4274 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4275 | locations->SetOut(Location::SameAsFirstInput()); |
| 4276 | } |
| 4277 | |
| 4278 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4279 | LocationSummary* locations = bool_not->GetLocations(); |
| 4280 | Location in = locations->InAt(0); |
| 4281 | Location out = locations->Out(); |
| 4282 | DCHECK(in.Equals(out)); |
| 4283 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4284 | } |
| 4285 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4286 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4287 | LocationSummary* locations = |
| 4288 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4289 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4290 | case Primitive::kPrimBoolean: |
| 4291 | case Primitive::kPrimByte: |
| 4292 | case Primitive::kPrimShort: |
| 4293 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4294 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4295 | case Primitive::kPrimLong: { |
| 4296 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4297 | locations->SetInAt(1, Location::Any()); |
| 4298 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4299 | break; |
| 4300 | } |
| 4301 | case Primitive::kPrimFloat: |
| 4302 | case Primitive::kPrimDouble: { |
| 4303 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4304 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4305 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4306 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4307 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4308 | } else { |
| 4309 | locations->SetInAt(1, Location::Any()); |
| 4310 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4311 | locations->SetOut(Location::RequiresRegister()); |
| 4312 | break; |
| 4313 | } |
| 4314 | default: |
| 4315 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4316 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4317 | } |
| 4318 | |
| 4319 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4320 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4321 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4322 | Location left = locations->InAt(0); |
| 4323 | Location right = locations->InAt(1); |
| 4324 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4325 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4326 | Condition less_cond = kLess; |
| 4327 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4328 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4329 | case Primitive::kPrimBoolean: |
| 4330 | case Primitive::kPrimByte: |
| 4331 | case Primitive::kPrimShort: |
| 4332 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4333 | case Primitive::kPrimInt: { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4334 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4335 | break; |
| 4336 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4337 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4338 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4339 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4340 | int32_t val_low = 0; |
| 4341 | int32_t val_high = 0; |
| 4342 | bool right_is_const = false; |
| 4343 | |
| 4344 | if (right.IsConstant()) { |
| 4345 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4346 | right_is_const = true; |
| 4347 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4348 | val_low = Low32Bits(val); |
| 4349 | val_high = High32Bits(val); |
| 4350 | } |
| 4351 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4352 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4353 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4354 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4355 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4356 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4357 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4358 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4359 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4360 | __ j(kLess, &less); // Signed compare. |
| 4361 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4362 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4363 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4364 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4365 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4366 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4367 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4368 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4369 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4370 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4371 | break; |
| 4372 | } |
| 4373 | case Primitive::kPrimFloat: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4374 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4375 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4376 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4377 | break; |
| 4378 | } |
| 4379 | case Primitive::kPrimDouble: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4380 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4381 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4382 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4383 | break; |
| 4384 | } |
| 4385 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4386 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4387 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4388 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4389 | __ movl(out, Immediate(0)); |
| 4390 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4391 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4392 | |
| 4393 | __ Bind(&greater); |
| 4394 | __ movl(out, Immediate(1)); |
| 4395 | __ jmp(&done); |
| 4396 | |
| 4397 | __ Bind(&less); |
| 4398 | __ movl(out, Immediate(-1)); |
| 4399 | |
| 4400 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4401 | } |
| 4402 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4403 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4404 | LocationSummary* locations = |
| 4405 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4406 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4407 | locations->SetInAt(i, Location::Any()); |
| 4408 | } |
| 4409 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4410 | } |
| 4411 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4412 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4413 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4414 | } |
| 4415 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4416 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4417 | /* |
| 4418 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4419 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4420 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4421 | */ |
| 4422 | switch (kind) { |
| 4423 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4424 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4425 | break; |
| 4426 | } |
| 4427 | case MemBarrierKind::kAnyStore: |
| 4428 | case MemBarrierKind::kLoadAny: |
| 4429 | case MemBarrierKind::kStoreStore: { |
| 4430 | // nop |
| 4431 | break; |
| 4432 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4433 | case MemBarrierKind::kNTStoreStore: |
| 4434 | // Non-Temporal Store/Store needs an explicit fence. |
| 4435 | MemoryFence(/* non-temporal */ true); |
| 4436 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4437 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4438 | } |
| 4439 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4440 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4441 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4442 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4443 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 4444 | |
| 4445 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 4446 | // is incompatible with it. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4447 | // TODO: Create as many X86ComputeBaseMethodAddress instructions |
| 4448 | // as needed for methods with irreducible loops. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4449 | if (GetGraph()->HasIrreducibleLoops() && |
| 4450 | (dispatch_info.method_load_kind == |
| 4451 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 4452 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 4453 | } |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 4454 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4455 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4456 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4457 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4458 | Register temp) { |
| 4459 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4460 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4461 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4462 | return location.AsRegister<Register>(); |
| 4463 | } |
| 4464 | // For intrinsics we allow any location, so it may be on the stack. |
| 4465 | if (!location.IsRegister()) { |
| 4466 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4467 | return temp; |
| 4468 | } |
| 4469 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4470 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4471 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4472 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4473 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4474 | if (slow_path != nullptr) { |
| 4475 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4476 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4477 | __ movl(temp, Address(ESP, stack_offset)); |
| 4478 | return temp; |
| 4479 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4480 | } |
| 4481 | return location.AsRegister<Register>(); |
| 4482 | } |
| 4483 | |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4484 | Location CodeGeneratorX86::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 4485 | Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4486 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4487 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4488 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4489 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4490 | uint32_t offset = |
| 4491 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4492 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4493 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4494 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4495 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4496 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4497 | break; |
| 4498 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4499 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4500 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4501 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4502 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4503 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4504 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4505 | // Bind a new fixup label at the end of the "movl" insn. |
| 4506 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4507 | __ Bind(NewPcRelativeDexCacheArrayPatch(invoke->GetDexFile(), offset)); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4508 | break; |
| 4509 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4510 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4511 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4512 | Register method_reg; |
| 4513 | Register reg = temp.AsRegister<Register>(); |
| 4514 | if (current_method.IsRegister()) { |
| 4515 | method_reg = current_method.AsRegister<Register>(); |
| 4516 | } else { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4517 | DCHECK(invoke->GetLocations()->Intrinsified()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4518 | DCHECK(!current_method.IsValid()); |
| 4519 | method_reg = reg; |
| 4520 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4521 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4522 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4523 | __ movl(reg, Address(method_reg, |
| 4524 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 4525 | // temp = temp[index_in_cache]; |
| 4526 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 4527 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4528 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4529 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4530 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4531 | } |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4532 | return callee_method; |
| 4533 | } |
| 4534 | |
| 4535 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4536 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4537 | |
| 4538 | switch (invoke->GetCodePtrLocation()) { |
| 4539 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4540 | __ call(GetFrameEntryLabel()); |
| 4541 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4542 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4543 | // (callee_method + offset_of_quick_compiled_code)() |
| 4544 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4545 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4546 | kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4547 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4548 | } |
| 4549 | |
| 4550 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4551 | } |
| 4552 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4553 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4554 | Register temp = temp_in.AsRegister<Register>(); |
| 4555 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4556 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4557 | |
| 4558 | // Use the calling convention instead of the location of the receiver, as |
| 4559 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4560 | // slow path, the arguments have been moved to the right place, so here we are |
| 4561 | // guaranteed that the receiver is the first register of the calling convention. |
| 4562 | InvokeDexCallingConvention calling_convention; |
| 4563 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4564 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4565 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4566 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4567 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4568 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4569 | // emit a read barrier for the previous class reference load. |
| 4570 | // However this is not required in practice, as this is an |
| 4571 | // intermediate/temporary reference and because the current |
| 4572 | // concurrent copying collector keeps the from-space memory |
| 4573 | // intact/accessible until the end of the marking phase (the |
| 4574 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4575 | __ MaybeUnpoisonHeapReference(temp); |
| 4576 | // temp = temp->GetMethodAt(method_offset); |
| 4577 | __ movl(temp, Address(temp, method_offset)); |
| 4578 | // call temp->GetEntryPoint(); |
| 4579 | __ call(Address( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4580 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4581 | } |
| 4582 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4583 | void CodeGeneratorX86::RecordSimplePatch() { |
| 4584 | if (GetCompilerOptions().GetIncludePatchInformation()) { |
| 4585 | simple_patches_.emplace_back(); |
| 4586 | __ Bind(&simple_patches_.back()); |
| 4587 | } |
| 4588 | } |
| 4589 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4590 | void CodeGeneratorX86::RecordBootStringPatch(HLoadString* load_string) { |
| 4591 | DCHECK(GetCompilerOptions().IsBootImage()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 4592 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4593 | __ Bind(&string_patches_.back().label); |
| 4594 | } |
| 4595 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4596 | void CodeGeneratorX86::RecordTypePatch(HLoadClass* load_class) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4597 | type_patches_.emplace_back(load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4598 | __ Bind(&type_patches_.back().label); |
| 4599 | } |
| 4600 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4601 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
| 4602 | DCHECK(!GetCompilerOptions().IsBootImage()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 4603 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4604 | return &string_patches_.back().label; |
| 4605 | } |
| 4606 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4607 | Label* CodeGeneratorX86::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 4608 | uint32_t element_offset) { |
| 4609 | // Add the patch entry and bind its label at the end of the instruction. |
| 4610 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 4611 | return &pc_relative_dex_cache_patches_.back().label; |
| 4612 | } |
| 4613 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4614 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 4615 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4616 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 4617 | |
| 4618 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 4619 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
| 4620 | const ArenaDeque<PatchInfo<Label>>& infos, |
| 4621 | ArenaVector<LinkerPatch>* linker_patches) { |
| 4622 | for (const PatchInfo<Label>& info : infos) { |
| 4623 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4624 | linker_patches->push_back( |
| 4625 | Factory(literal_offset, &info.dex_file, GetMethodAddressOffset(), info.index)); |
| 4626 | } |
| 4627 | } |
| 4628 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4629 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4630 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4631 | size_t size = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4632 | pc_relative_dex_cache_patches_.size() + |
| 4633 | simple_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4634 | string_patches_.size() + |
| 4635 | type_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4636 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4637 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 4638 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4639 | for (const Label& label : simple_patches_) { |
| 4640 | uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4641 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 4642 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4643 | if (!GetCompilerOptions().IsBootImage()) { |
| 4644 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(string_patches_, linker_patches); |
| 4645 | } else if (GetCompilerOptions().GetCompilePic()) { |
| 4646 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(string_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4647 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4648 | for (const PatchInfo<Label>& info : string_patches_) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4649 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4650 | linker_patches->push_back( |
| 4651 | LinkerPatch::StringPatch(literal_offset, &info.dex_file, info.index)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4652 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4653 | } |
| 4654 | if (GetCompilerOptions().GetCompilePic()) { |
| 4655 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(type_patches_, linker_patches); |
| 4656 | } else { |
| 4657 | for (const PatchInfo<Label>& info : type_patches_) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4658 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4659 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, &info.dex_file, info.index)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4660 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4661 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4662 | } |
| 4663 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4664 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4665 | Register card, |
| 4666 | Register object, |
| 4667 | Register value, |
| 4668 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4669 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4670 | if (value_can_be_null) { |
| 4671 | __ testl(value, value); |
| 4672 | __ j(kEqual, &is_null); |
| 4673 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4674 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4675 | __ movl(temp, object); |
| 4676 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4677 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4678 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4679 | if (value_can_be_null) { |
| 4680 | __ Bind(&is_null); |
| 4681 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4682 | } |
| 4683 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4684 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4685 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4686 | |
| 4687 | bool object_field_get_with_read_barrier = |
| 4688 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4689 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4690 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4691 | kEmitCompilerReadBarrier ? |
| 4692 | LocationSummary::kCallOnSlowPath : |
| 4693 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4694 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4695 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4696 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4697 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4698 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4699 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4700 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4701 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4702 | // The output overlaps in case of long: we don't want the low move |
| 4703 | // to overwrite the object's location. Likewise, in the case of |
| 4704 | // an object field get with read barriers enabled, we do not want |
| 4705 | // the move to overwrite the object's location, as we need it to emit |
| 4706 | // the read barrier. |
| 4707 | locations->SetOut( |
| 4708 | Location::RequiresRegister(), |
| 4709 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4710 | Location::kOutputOverlap : |
| 4711 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4712 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4713 | |
| 4714 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4715 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4716 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4717 | // load the temp into the XMM and then copy the XMM into the |
| 4718 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4719 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4720 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4721 | } |
| 4722 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4723 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4724 | const FieldInfo& field_info) { |
| 4725 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4726 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4727 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4728 | Location base_loc = locations->InAt(0); |
| 4729 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4730 | Location out = locations->Out(); |
| 4731 | bool is_volatile = field_info.IsVolatile(); |
| 4732 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4733 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4734 | |
| 4735 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4736 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4737 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4738 | break; |
| 4739 | } |
| 4740 | |
| 4741 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4742 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4743 | break; |
| 4744 | } |
| 4745 | |
| 4746 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4747 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4748 | break; |
| 4749 | } |
| 4750 | |
| 4751 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4752 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4753 | break; |
| 4754 | } |
| 4755 | |
| 4756 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4757 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4758 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4759 | |
| 4760 | case Primitive::kPrimNot: { |
| 4761 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4762 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4763 | // Note that a potential implicit null check is handled in this |
| 4764 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4765 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4766 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4767 | if (is_volatile) { |
| 4768 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4769 | } |
| 4770 | } else { |
| 4771 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4772 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4773 | if (is_volatile) { |
| 4774 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4775 | } |
| 4776 | // If read barriers are enabled, emit read barriers other than |
| 4777 | // Baker's using a slow path (and also unpoison the loaded |
| 4778 | // reference, if heap poisoning is enabled). |
| 4779 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4780 | } |
| 4781 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4782 | } |
| 4783 | |
| 4784 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4785 | if (is_volatile) { |
| 4786 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4787 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4788 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4789 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4790 | __ psrlq(temp, Immediate(32)); |
| 4791 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4792 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4793 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4794 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4795 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4796 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4797 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4798 | break; |
| 4799 | } |
| 4800 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4801 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4802 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4803 | break; |
| 4804 | } |
| 4805 | |
| 4806 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4807 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4808 | break; |
| 4809 | } |
| 4810 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4811 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4812 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4813 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4814 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4815 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4816 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4817 | // Potential implicit null checks, in the case of reference or |
| 4818 | // long fields, are handled in the previous switch statement. |
| 4819 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4820 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4821 | } |
| 4822 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4823 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4824 | if (field_type == Primitive::kPrimNot) { |
| 4825 | // Memory barriers, in the case of references, are also handled |
| 4826 | // in the previous switch statement. |
| 4827 | } else { |
| 4828 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4829 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4830 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4831 | } |
| 4832 | |
| 4833 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4834 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4835 | |
| 4836 | LocationSummary* locations = |
| 4837 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4838 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4839 | bool is_volatile = field_info.IsVolatile(); |
| 4840 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4841 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4842 | || (field_type == Primitive::kPrimByte); |
| 4843 | |
| 4844 | // The register allocator does not support multiple |
| 4845 | // inputs that die at entry with one in a specific register. |
| 4846 | if (is_byte_type) { |
| 4847 | // Ensure the value is in a byte register. |
| 4848 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4849 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4850 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4851 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4852 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4853 | } else { |
| 4854 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4855 | } |
| 4856 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4857 | // 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] | 4858 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4859 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4860 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4861 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4862 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4863 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4864 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4865 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4866 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4867 | } else { |
| 4868 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4869 | |
| 4870 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4871 | // Temporary registers for the write barrier. |
| 4872 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4873 | // Ensure the card is in a byte register. |
| 4874 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4875 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4876 | } |
| 4877 | } |
| 4878 | |
| 4879 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4880 | const FieldInfo& field_info, |
| 4881 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4882 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4883 | |
| 4884 | LocationSummary* locations = instruction->GetLocations(); |
| 4885 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4886 | Location value = locations->InAt(1); |
| 4887 | bool is_volatile = field_info.IsVolatile(); |
| 4888 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4889 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4890 | bool needs_write_barrier = |
| 4891 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4892 | |
| 4893 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4894 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4895 | } |
| 4896 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4897 | bool maybe_record_implicit_null_check_done = false; |
| 4898 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4899 | switch (field_type) { |
| 4900 | case Primitive::kPrimBoolean: |
| 4901 | case Primitive::kPrimByte: { |
| 4902 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4903 | break; |
| 4904 | } |
| 4905 | |
| 4906 | case Primitive::kPrimShort: |
| 4907 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4908 | if (value.IsConstant()) { |
| 4909 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4910 | __ movw(Address(base, offset), Immediate(v)); |
| 4911 | } else { |
| 4912 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4913 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4914 | break; |
| 4915 | } |
| 4916 | |
| 4917 | case Primitive::kPrimInt: |
| 4918 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4919 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4920 | // Note that in the case where `value` is a null reference, |
| 4921 | // we do not enter this block, as the reference does not |
| 4922 | // need poisoning. |
| 4923 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4924 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4925 | __ movl(temp, value.AsRegister<Register>()); |
| 4926 | __ PoisonHeapReference(temp); |
| 4927 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4928 | } else if (value.IsConstant()) { |
| 4929 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4930 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4931 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 4932 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4933 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4934 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4935 | break; |
| 4936 | } |
| 4937 | |
| 4938 | case Primitive::kPrimLong: { |
| 4939 | if (is_volatile) { |
| 4940 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4941 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4942 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4943 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4944 | __ punpckldq(temp1, temp2); |
| 4945 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4946 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4947 | } else if (value.IsConstant()) { |
| 4948 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4949 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4950 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4951 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4952 | } else { |
| 4953 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4954 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4955 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4956 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4957 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4958 | break; |
| 4959 | } |
| 4960 | |
| 4961 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4962 | if (value.IsConstant()) { |
| 4963 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4964 | __ movl(Address(base, offset), Immediate(v)); |
| 4965 | } else { |
| 4966 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4967 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4968 | break; |
| 4969 | } |
| 4970 | |
| 4971 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4972 | if (value.IsConstant()) { |
| 4973 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4974 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4975 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4976 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4977 | maybe_record_implicit_null_check_done = true; |
| 4978 | } else { |
| 4979 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4980 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4981 | break; |
| 4982 | } |
| 4983 | |
| 4984 | case Primitive::kPrimVoid: |
| 4985 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4986 | UNREACHABLE(); |
| 4987 | } |
| 4988 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4989 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4990 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4991 | } |
| 4992 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4993 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4994 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4995 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4996 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4997 | } |
| 4998 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4999 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5000 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5001 | } |
| 5002 | } |
| 5003 | |
| 5004 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5005 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5006 | } |
| 5007 | |
| 5008 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5009 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5010 | } |
| 5011 | |
| 5012 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5013 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5014 | } |
| 5015 | |
| 5016 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5017 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5018 | } |
| 5019 | |
| 5020 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5021 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5022 | } |
| 5023 | |
| 5024 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5025 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5026 | } |
| 5027 | |
| 5028 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5029 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5030 | } |
| 5031 | |
| 5032 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5033 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5034 | } |
| 5035 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5036 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 5037 | HUnresolvedInstanceFieldGet* instruction) { |
| 5038 | FieldAccessCallingConventionX86 calling_convention; |
| 5039 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5040 | instruction, instruction->GetFieldType(), calling_convention); |
| 5041 | } |
| 5042 | |
| 5043 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 5044 | HUnresolvedInstanceFieldGet* instruction) { |
| 5045 | FieldAccessCallingConventionX86 calling_convention; |
| 5046 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5047 | instruction->GetFieldType(), |
| 5048 | instruction->GetFieldIndex(), |
| 5049 | instruction->GetDexPc(), |
| 5050 | calling_convention); |
| 5051 | } |
| 5052 | |
| 5053 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 5054 | HUnresolvedInstanceFieldSet* instruction) { |
| 5055 | FieldAccessCallingConventionX86 calling_convention; |
| 5056 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5057 | instruction, instruction->GetFieldType(), calling_convention); |
| 5058 | } |
| 5059 | |
| 5060 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 5061 | HUnresolvedInstanceFieldSet* instruction) { |
| 5062 | FieldAccessCallingConventionX86 calling_convention; |
| 5063 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5064 | instruction->GetFieldType(), |
| 5065 | instruction->GetFieldIndex(), |
| 5066 | instruction->GetDexPc(), |
| 5067 | calling_convention); |
| 5068 | } |
| 5069 | |
| 5070 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 5071 | HUnresolvedStaticFieldGet* instruction) { |
| 5072 | FieldAccessCallingConventionX86 calling_convention; |
| 5073 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5074 | instruction, instruction->GetFieldType(), calling_convention); |
| 5075 | } |
| 5076 | |
| 5077 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 5078 | HUnresolvedStaticFieldGet* instruction) { |
| 5079 | FieldAccessCallingConventionX86 calling_convention; |
| 5080 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5081 | instruction->GetFieldType(), |
| 5082 | instruction->GetFieldIndex(), |
| 5083 | instruction->GetDexPc(), |
| 5084 | calling_convention); |
| 5085 | } |
| 5086 | |
| 5087 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 5088 | HUnresolvedStaticFieldSet* instruction) { |
| 5089 | FieldAccessCallingConventionX86 calling_convention; |
| 5090 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5091 | instruction, instruction->GetFieldType(), calling_convention); |
| 5092 | } |
| 5093 | |
| 5094 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 5095 | HUnresolvedStaticFieldSet* instruction) { |
| 5096 | FieldAccessCallingConventionX86 calling_convention; |
| 5097 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5098 | instruction->GetFieldType(), |
| 5099 | instruction->GetFieldIndex(), |
| 5100 | instruction->GetDexPc(), |
| 5101 | calling_convention); |
| 5102 | } |
| 5103 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5104 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5105 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5106 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5107 | ? Location::RequiresRegister() |
| 5108 | : Location::Any(); |
| 5109 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5110 | } |
| 5111 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5112 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5113 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5114 | return; |
| 5115 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5116 | LocationSummary* locations = instruction->GetLocations(); |
| 5117 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5118 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5119 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5120 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5121 | } |
| 5122 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5123 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5124 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5125 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5126 | |
| 5127 | LocationSummary* locations = instruction->GetLocations(); |
| 5128 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5129 | |
| 5130 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5131 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5132 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5133 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5134 | } else { |
| 5135 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5136 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5137 | __ jmp(slow_path->GetEntryLabel()); |
| 5138 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5139 | } |
| 5140 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5141 | } |
| 5142 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5143 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5144 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5145 | } |
| 5146 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5147 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5148 | bool object_array_get_with_read_barrier = |
| 5149 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5150 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5151 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5152 | object_array_get_with_read_barrier ? |
| 5153 | LocationSummary::kCallOnSlowPath : |
| 5154 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5155 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5156 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5157 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5158 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5159 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5160 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5161 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5162 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5163 | // The output overlaps in case of long: we don't want the low move |
| 5164 | // to overwrite the array's location. Likewise, in the case of an |
| 5165 | // object array get with read barriers enabled, we do not want the |
| 5166 | // move to overwrite the array's location, as we need it to emit |
| 5167 | // the read barrier. |
| 5168 | locations->SetOut( |
| 5169 | Location::RequiresRegister(), |
| 5170 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 5171 | Location::kOutputOverlap : |
| 5172 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5173 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5174 | } |
| 5175 | |
| 5176 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5177 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5178 | Location obj_loc = locations->InAt(0); |
| 5179 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5180 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5181 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5182 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5183 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5184 | Primitive::Type type = instruction->GetType(); |
| 5185 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5186 | case Primitive::kPrimBoolean: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5187 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5188 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5189 | break; |
| 5190 | } |
| 5191 | |
| 5192 | case Primitive::kPrimByte: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5193 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5194 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5195 | break; |
| 5196 | } |
| 5197 | |
| 5198 | case Primitive::kPrimShort: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5199 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5200 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5201 | break; |
| 5202 | } |
| 5203 | |
| 5204 | case Primitive::kPrimChar: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5205 | Register out = out_loc.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5206 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5207 | // Branch cases into compressed and uncompressed for each index's type. |
| 5208 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5209 | NearLabel done, not_compressed; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5210 | __ testl(Address(obj, count_offset), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5211 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5212 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5213 | "Expecting 0=compressed, 1=uncompressed"); |
| 5214 | __ j(kNotZero, ¬_compressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5215 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5216 | __ jmp(&done); |
| 5217 | __ Bind(¬_compressed); |
| 5218 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5219 | __ Bind(&done); |
| 5220 | } else { |
| 5221 | // Common case for charAt of array of char or when string compression's |
| 5222 | // feature is turned off. |
| 5223 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5224 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5225 | break; |
| 5226 | } |
| 5227 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5228 | case Primitive::kPrimInt: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5229 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5230 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5231 | break; |
| 5232 | } |
| 5233 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5234 | case Primitive::kPrimNot: { |
| 5235 | static_assert( |
| 5236 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5237 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5238 | // /* HeapReference<Object> */ out = |
| 5239 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5240 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5241 | // Note that a potential implicit null check is handled in this |
| 5242 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5243 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5244 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5245 | } else { |
| 5246 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5247 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5248 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5249 | // If read barriers are enabled, emit read barriers other than |
| 5250 | // Baker's using a slow path (and also unpoison the loaded |
| 5251 | // reference, if heap poisoning is enabled). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5252 | if (index.IsConstant()) { |
| 5253 | uint32_t offset = |
| 5254 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5255 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5256 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5257 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5258 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5259 | } |
| 5260 | } |
| 5261 | break; |
| 5262 | } |
| 5263 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5264 | case Primitive::kPrimLong: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5265 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5266 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 5267 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 5268 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5269 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 5270 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5271 | break; |
| 5272 | } |
| 5273 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5274 | case Primitive::kPrimFloat: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5275 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5276 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5277 | break; |
| 5278 | } |
| 5279 | |
| 5280 | case Primitive::kPrimDouble: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5281 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5282 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5283 | break; |
| 5284 | } |
| 5285 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5286 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5287 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5288 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5289 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5290 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5291 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5292 | // Potential implicit null checks, in the case of reference or |
| 5293 | // long arrays, are handled in the previous switch statement. |
| 5294 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5295 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5296 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5297 | } |
| 5298 | |
| 5299 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5300 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5301 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5302 | bool needs_write_barrier = |
| 5303 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5304 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5305 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5306 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5307 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5308 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5309 | LocationSummary::kCallOnSlowPath : |
| 5310 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5311 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5312 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5313 | || (value_type == Primitive::kPrimByte); |
| 5314 | // We need the inputs to be different than the output in case of long operation. |
| 5315 | // In case of a byte operation, the register allocator does not support multiple |
| 5316 | // inputs that die at entry with one in a specific register. |
| 5317 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5318 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5319 | if (is_byte_type) { |
| 5320 | // Ensure the value is in a byte register. |
| 5321 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5322 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5323 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5324 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5325 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5326 | } |
| 5327 | if (needs_write_barrier) { |
| 5328 | // Temporary registers for the write barrier. |
| 5329 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5330 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5331 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5332 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5333 | } |
| 5334 | |
| 5335 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5336 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5337 | Location array_loc = locations->InAt(0); |
| 5338 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5339 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5340 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5341 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5342 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5343 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5344 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5345 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5346 | bool needs_write_barrier = |
| 5347 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5348 | |
| 5349 | switch (value_type) { |
| 5350 | case Primitive::kPrimBoolean: |
| 5351 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5352 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5353 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5354 | if (value.IsRegister()) { |
| 5355 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5356 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5357 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5358 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5359 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5360 | break; |
| 5361 | } |
| 5362 | |
| 5363 | case Primitive::kPrimShort: |
| 5364 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5365 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5366 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5367 | if (value.IsRegister()) { |
| 5368 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5369 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5370 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5371 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5372 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5373 | break; |
| 5374 | } |
| 5375 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5376 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5377 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5378 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5379 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5380 | if (!value.IsRegister()) { |
| 5381 | // Just setting null. |
| 5382 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5383 | DCHECK(value.IsConstant()) << value; |
| 5384 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5385 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5386 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5387 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5388 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5389 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5390 | |
| 5391 | DCHECK(needs_write_barrier); |
| 5392 | Register register_value = value.AsRegister<Register>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5393 | // We cannot use a NearLabel for `done`, as its range may be too |
| 5394 | // short when Baker read barriers are enabled. |
| 5395 | Label done; |
| 5396 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5397 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5398 | Location temp_loc = locations->GetTemp(0); |
| 5399 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5400 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5401 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5402 | codegen_->AddSlowPath(slow_path); |
| 5403 | if (instruction->GetValueCanBeNull()) { |
| 5404 | __ testl(register_value, register_value); |
| 5405 | __ j(kNotEqual, ¬_null); |
| 5406 | __ movl(address, Immediate(0)); |
| 5407 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5408 | __ jmp(&done); |
| 5409 | __ Bind(¬_null); |
| 5410 | } |
| 5411 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5412 | // Note that when Baker read barriers are enabled, the type |
| 5413 | // checks are performed without read barriers. This is fine, |
| 5414 | // even in the case where a class object is in the from-space |
| 5415 | // after the flip, as a comparison involving such a type would |
| 5416 | // not produce a false positive; it may of course produce a |
| 5417 | // false negative, in which case we would take the ArraySet |
| 5418 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5419 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5420 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5421 | __ movl(temp, Address(array, class_offset)); |
| 5422 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5423 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5424 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5425 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5426 | __ movl(temp, Address(temp, component_offset)); |
| 5427 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5428 | // nor the object reference in `register_value->klass`, as |
| 5429 | // we are comparing two poisoned references. |
| 5430 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5431 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5432 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5433 | __ j(kEqual, &do_put); |
| 5434 | // If heap poisoning is enabled, the `temp` reference has |
| 5435 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5436 | __ MaybeUnpoisonHeapReference(temp); |
| 5437 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5438 | // If heap poisoning is enabled, no need to unpoison the |
| 5439 | // heap reference loaded below, as it is only used for a |
| 5440 | // comparison with null. |
| 5441 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5442 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5443 | __ Bind(&do_put); |
| 5444 | } else { |
| 5445 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5446 | } |
| 5447 | } |
| 5448 | |
| 5449 | if (kPoisonHeapReferences) { |
| 5450 | __ movl(temp, register_value); |
| 5451 | __ PoisonHeapReference(temp); |
| 5452 | __ movl(address, temp); |
| 5453 | } else { |
| 5454 | __ movl(address, register_value); |
| 5455 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5456 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5457 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5458 | } |
| 5459 | |
| 5460 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5461 | codegen_->MarkGCCard( |
| 5462 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5463 | __ Bind(&done); |
| 5464 | |
| 5465 | if (slow_path != nullptr) { |
| 5466 | __ Bind(slow_path->GetExitLabel()); |
| 5467 | } |
| 5468 | |
| 5469 | break; |
| 5470 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5471 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5472 | case Primitive::kPrimInt: { |
| 5473 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5474 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5475 | if (value.IsRegister()) { |
| 5476 | __ movl(address, value.AsRegister<Register>()); |
| 5477 | } else { |
| 5478 | DCHECK(value.IsConstant()) << value; |
| 5479 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5480 | __ movl(address, Immediate(v)); |
| 5481 | } |
| 5482 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5483 | break; |
| 5484 | } |
| 5485 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5486 | case Primitive::kPrimLong: { |
| 5487 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5488 | if (value.IsRegisterPair()) { |
| 5489 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5490 | value.AsRegisterPairLow<Register>()); |
| 5491 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5492 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5493 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5494 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5495 | DCHECK(value.IsConstant()); |
| 5496 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 5497 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5498 | Immediate(Low32Bits(val))); |
| 5499 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5500 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5501 | Immediate(High32Bits(val))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5502 | } |
| 5503 | break; |
| 5504 | } |
| 5505 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5506 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5507 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5508 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5509 | if (value.IsFpuRegister()) { |
| 5510 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5511 | } else { |
| 5512 | DCHECK(value.IsConstant()); |
| 5513 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5514 | __ movl(address, Immediate(v)); |
| 5515 | } |
| 5516 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5517 | break; |
| 5518 | } |
| 5519 | |
| 5520 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5521 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5522 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5523 | if (value.IsFpuRegister()) { |
| 5524 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5525 | } else { |
| 5526 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5527 | Address address_hi = |
| 5528 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5529 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5530 | __ movl(address, Immediate(Low32Bits(v))); |
| 5531 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5532 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5533 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5534 | break; |
| 5535 | } |
| 5536 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5537 | case Primitive::kPrimVoid: |
| 5538 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5539 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5540 | } |
| 5541 | } |
| 5542 | |
| 5543 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5544 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5545 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5546 | if (!instruction->IsEmittedAtUseSite()) { |
| 5547 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5548 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5549 | } |
| 5550 | |
| 5551 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5552 | if (instruction->IsEmittedAtUseSite()) { |
| 5553 | return; |
| 5554 | } |
| 5555 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5556 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5557 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5558 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5559 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5560 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5561 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5562 | // Mask out most significant bit in case the array is String's array of char. |
| 5563 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5564 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5565 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5566 | } |
| 5567 | |
| 5568 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5569 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5570 | InvokeRuntimeCallingConvention calling_convention; |
| 5571 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5572 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5573 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5574 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5575 | HInstruction* length = instruction->InputAt(1); |
| 5576 | if (!length->IsEmittedAtUseSite()) { |
| 5577 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5578 | } |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5579 | // Need register to see array's length. |
| 5580 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5581 | locations->AddTemp(Location::RequiresRegister()); |
| 5582 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5583 | } |
| 5584 | |
| 5585 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5586 | const bool is_string_compressed_char_at = |
| 5587 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5588 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5589 | Location index_loc = locations->InAt(0); |
| 5590 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5591 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5592 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5593 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5594 | if (length_loc.IsConstant()) { |
| 5595 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5596 | if (index_loc.IsConstant()) { |
| 5597 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5598 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5599 | if (index < 0 || index >= length) { |
| 5600 | codegen_->AddSlowPath(slow_path); |
| 5601 | __ jmp(slow_path->GetEntryLabel()); |
| 5602 | } else { |
| 5603 | // Some optimization after BCE may have generated this, and we should not |
| 5604 | // generate a bounds check if it is a valid range. |
| 5605 | } |
| 5606 | return; |
| 5607 | } |
| 5608 | |
| 5609 | // We have to reverse the jump condition because the length is the constant. |
| 5610 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5611 | __ cmpl(index_reg, Immediate(length)); |
| 5612 | codegen_->AddSlowPath(slow_path); |
| 5613 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5614 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5615 | HInstruction* array_length = instruction->InputAt(1); |
| 5616 | if (array_length->IsEmittedAtUseSite()) { |
| 5617 | // Address the length field in the array. |
| 5618 | DCHECK(array_length->IsArrayLength()); |
| 5619 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5620 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5621 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5622 | if (is_string_compressed_char_at) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5623 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5624 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5625 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 5626 | __ movl(length_reg, array_len); |
| 5627 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5628 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5629 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5630 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5631 | // Checking bounds for general case: |
| 5632 | // Array of char or string's array with feature compression off. |
| 5633 | if (index_loc.IsConstant()) { |
| 5634 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5635 | __ cmpl(array_len, Immediate(value)); |
| 5636 | } else { |
| 5637 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 5638 | } |
| 5639 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5640 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5641 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5642 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5643 | } |
| 5644 | codegen_->AddSlowPath(slow_path); |
| 5645 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5646 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5647 | } |
| 5648 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5649 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5650 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5651 | } |
| 5652 | |
| 5653 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5654 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5655 | } |
| 5656 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5657 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5658 | LocationSummary* locations = |
| 5659 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5660 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5661 | } |
| 5662 | |
| 5663 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5664 | HBasicBlock* block = instruction->GetBlock(); |
| 5665 | if (block->GetLoopInformation() != nullptr) { |
| 5666 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5667 | // The back edge will generate the suspend check. |
| 5668 | return; |
| 5669 | } |
| 5670 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5671 | // The goto will generate the suspend check. |
| 5672 | return; |
| 5673 | } |
| 5674 | GenerateSuspendCheck(instruction, nullptr); |
| 5675 | } |
| 5676 | |
| 5677 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5678 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5679 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5680 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5681 | if (slow_path == nullptr) { |
| 5682 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5683 | instruction->SetSlowPath(slow_path); |
| 5684 | codegen_->AddSlowPath(slow_path); |
| 5685 | if (successor != nullptr) { |
| 5686 | DCHECK(successor->IsLoopHeader()); |
| 5687 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5688 | } |
| 5689 | } else { |
| 5690 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5691 | } |
| 5692 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5693 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5694 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5695 | if (successor == nullptr) { |
| 5696 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5697 | __ Bind(slow_path->GetReturnLabel()); |
| 5698 | } else { |
| 5699 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5700 | __ jmp(slow_path->GetEntryLabel()); |
| 5701 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5702 | } |
| 5703 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5704 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5705 | return codegen_->GetAssembler(); |
| 5706 | } |
| 5707 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5708 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5709 | ScratchRegisterScope ensure_scratch( |
| 5710 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5711 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5712 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5713 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5714 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5715 | } |
| 5716 | |
| 5717 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5718 | ScratchRegisterScope ensure_scratch( |
| 5719 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5720 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5721 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5722 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5723 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5724 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5725 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5726 | } |
| 5727 | |
| 5728 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5729 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5730 | Location source = move->GetSource(); |
| 5731 | Location destination = move->GetDestination(); |
| 5732 | |
| 5733 | if (source.IsRegister()) { |
| 5734 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5735 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5736 | } else if (destination.IsFpuRegister()) { |
| 5737 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5738 | } else { |
| 5739 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5740 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5741 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5742 | } else if (source.IsRegisterPair()) { |
| 5743 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 5744 | // Create stack space for 2 elements. |
| 5745 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5746 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5747 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5748 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5749 | // And remove the temporary stack space we allocated. |
| 5750 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5751 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5752 | if (destination.IsRegister()) { |
| 5753 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5754 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5755 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5756 | } else if (destination.IsRegisterPair()) { |
| 5757 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5758 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5759 | __ psrlq(src_reg, Immediate(32)); |
| 5760 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5761 | } else if (destination.IsStackSlot()) { |
| 5762 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5763 | } else { |
| 5764 | DCHECK(destination.IsDoubleStackSlot()); |
| 5765 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5766 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5767 | } else if (source.IsStackSlot()) { |
| 5768 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5769 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5770 | } else if (destination.IsFpuRegister()) { |
| 5771 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5772 | } else { |
| 5773 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5774 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5775 | } |
| 5776 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5777 | if (destination.IsRegisterPair()) { |
| 5778 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5779 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5780 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5781 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5782 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5783 | } else { |
| 5784 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5785 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5786 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5787 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5788 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5789 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5790 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5791 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5792 | if (value == 0) { |
| 5793 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5794 | } else { |
| 5795 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5796 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5797 | } else { |
| 5798 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5799 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5800 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5801 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5802 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5803 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5804 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5805 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5806 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5807 | if (value == 0) { |
| 5808 | // Easy handling of 0.0. |
| 5809 | __ xorps(dest, dest); |
| 5810 | } else { |
| 5811 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5812 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5813 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5814 | __ movl(temp, Immediate(value)); |
| 5815 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5816 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5817 | } else { |
| 5818 | DCHECK(destination.IsStackSlot()) << destination; |
| 5819 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5820 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5821 | } else if (constant->IsLongConstant()) { |
| 5822 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5823 | int32_t low_value = Low32Bits(value); |
| 5824 | int32_t high_value = High32Bits(value); |
| 5825 | Immediate low(low_value); |
| 5826 | Immediate high(high_value); |
| 5827 | if (destination.IsDoubleStackSlot()) { |
| 5828 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5829 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5830 | } else { |
| 5831 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5832 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5833 | } |
| 5834 | } else { |
| 5835 | DCHECK(constant->IsDoubleConstant()); |
| 5836 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5837 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5838 | int32_t low_value = Low32Bits(value); |
| 5839 | int32_t high_value = High32Bits(value); |
| 5840 | Immediate low(low_value); |
| 5841 | Immediate high(high_value); |
| 5842 | if (destination.IsFpuRegister()) { |
| 5843 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5844 | if (value == 0) { |
| 5845 | // Easy handling of 0.0. |
| 5846 | __ xorpd(dest, dest); |
| 5847 | } else { |
| 5848 | __ pushl(high); |
| 5849 | __ pushl(low); |
| 5850 | __ movsd(dest, Address(ESP, 0)); |
| 5851 | __ addl(ESP, Immediate(8)); |
| 5852 | } |
| 5853 | } else { |
| 5854 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5855 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5856 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5857 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5858 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5859 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5860 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5861 | } |
| 5862 | } |
| 5863 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5864 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5865 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5866 | ScratchRegisterScope ensure_scratch( |
| 5867 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5868 | |
| 5869 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5870 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5871 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5872 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5873 | } |
| 5874 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5875 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5876 | ScratchRegisterScope ensure_scratch( |
| 5877 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5878 | |
| 5879 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5880 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5881 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5882 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5883 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5884 | } |
| 5885 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5886 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5887 | ScratchRegisterScope ensure_scratch1( |
| 5888 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5889 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5890 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5891 | ScratchRegisterScope ensure_scratch2( |
| 5892 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5893 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5894 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5895 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5896 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5897 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5898 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5899 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5900 | } |
| 5901 | |
| 5902 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5903 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5904 | Location source = move->GetSource(); |
| 5905 | Location destination = move->GetDestination(); |
| 5906 | |
| 5907 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5908 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5909 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5910 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5911 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5912 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5913 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5914 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5915 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5916 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5917 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5918 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5919 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5920 | // Use XOR Swap algorithm to avoid a temporary. |
| 5921 | DCHECK_NE(source.reg(), destination.reg()); |
| 5922 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5923 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5924 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5925 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5926 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5927 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5928 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5929 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5930 | // Take advantage of the 16 bytes in the XMM register. |
| 5931 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5932 | Address stack(ESP, destination.GetStackIndex()); |
| 5933 | // Load the double into the high doubleword. |
| 5934 | __ movhpd(reg, stack); |
| 5935 | |
| 5936 | // Store the low double into the destination. |
| 5937 | __ movsd(stack, reg); |
| 5938 | |
| 5939 | // Move the high double to the low double. |
| 5940 | __ psrldq(reg, Immediate(8)); |
| 5941 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5942 | // Take advantage of the 16 bytes in the XMM register. |
| 5943 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5944 | Address stack(ESP, source.GetStackIndex()); |
| 5945 | // Load the double into the high doubleword. |
| 5946 | __ movhpd(reg, stack); |
| 5947 | |
| 5948 | // Store the low double into the destination. |
| 5949 | __ movsd(stack, reg); |
| 5950 | |
| 5951 | // Move the high double to the low double. |
| 5952 | __ psrldq(reg, Immediate(8)); |
| 5953 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5954 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5955 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5956 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5957 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5958 | } |
| 5959 | } |
| 5960 | |
| 5961 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5962 | __ pushl(static_cast<Register>(reg)); |
| 5963 | } |
| 5964 | |
| 5965 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5966 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5967 | } |
| 5968 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5969 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 5970 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5971 | switch (desired_class_load_kind) { |
| 5972 | case HLoadClass::LoadKind::kReferrersClass: |
| 5973 | break; |
| 5974 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5975 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5976 | break; |
| 5977 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5978 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5979 | FALLTHROUGH_INTENDED; |
| 5980 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5981 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
| 5982 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5983 | // is incompatible with it. |
| 5984 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 5985 | // with irreducible loops. |
| 5986 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5987 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5988 | } |
| 5989 | break; |
| 5990 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5991 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5992 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5993 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5994 | break; |
| 5995 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5996 | break; |
| 5997 | } |
| 5998 | return desired_class_load_kind; |
| 5999 | } |
| 6000 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6001 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6002 | if (cls->NeedsAccessCheck()) { |
| 6003 | InvokeRuntimeCallingConvention calling_convention; |
| 6004 | CodeGenerator::CreateLoadClassLocationSummary( |
| 6005 | cls, |
| 6006 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 6007 | Location::RegisterLocation(EAX), |
| 6008 | /* code_generator_supports_read_barrier */ true); |
| 6009 | return; |
| 6010 | } |
| 6011 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6012 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6013 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6014 | ? LocationSummary::kCallOnSlowPath |
| 6015 | : LocationSummary::kNoCall; |
| 6016 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6017 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6018 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6019 | } |
| 6020 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6021 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6022 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 6023 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod || |
| 6024 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
| 6025 | load_kind == HLoadClass::LoadKind::kDexCachePcRelative) { |
| 6026 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6027 | } |
| 6028 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6029 | } |
| 6030 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6031 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, |
| 6032 | dex::TypeIndex dex_index, |
| 6033 | uint64_t address) { |
| 6034 | jit_class_roots_.Overwrite(TypeReference(&dex_file, dex_index), address); |
| 6035 | // Add a patch entry and return the label. |
| 6036 | jit_class_patches_.emplace_back(dex_file, dex_index.index_); |
| 6037 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 6038 | return &info->label; |
| 6039 | } |
| 6040 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6041 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6042 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6043 | if (cls->NeedsAccessCheck()) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6044 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex().index_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6045 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6046 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6047 | return; |
| 6048 | } |
| 6049 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6050 | Location out_loc = locations->Out(); |
| 6051 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6052 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6053 | bool generate_null_check = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6054 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6055 | ? kWithoutReadBarrier |
| 6056 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6057 | switch (cls->GetLoadKind()) { |
| 6058 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6059 | DCHECK(!cls->CanCallRuntime()); |
| 6060 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6061 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6062 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6063 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6064 | cls, |
| 6065 | out_loc, |
| 6066 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6067 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6068 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6069 | break; |
| 6070 | } |
| 6071 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6072 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6073 | __ movl(out, Immediate(/* placeholder */ 0)); |
| 6074 | codegen_->RecordTypePatch(cls); |
| 6075 | break; |
| 6076 | } |
| 6077 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6078 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6079 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6080 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6081 | codegen_->RecordTypePatch(cls); |
| 6082 | break; |
| 6083 | } |
| 6084 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6085 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6086 | DCHECK_NE(cls->GetAddress(), 0u); |
| 6087 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 6088 | __ movl(out, Immediate(address)); |
| 6089 | codegen_->RecordSimplePatch(); |
| 6090 | break; |
| 6091 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6092 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6093 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6094 | Label* fixup_label = codegen_->NewJitRootClassPatch( |
| 6095 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetAddress()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6096 | // /* GcRoot<mirror::Class> */ out = *address |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6097 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6098 | break; |
| 6099 | } |
| 6100 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 6101 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 6102 | uint32_t offset = cls->GetDexCacheElementOffset(); |
| 6103 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(cls->GetDexFile(), offset); |
| 6104 | // /* GcRoot<mirror::Class> */ out = *(base + offset) /* PC-relative */ |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6105 | GenerateGcRootFieldLoad(cls, |
| 6106 | out_loc, |
| 6107 | Address(base_reg, CodeGeneratorX86::kDummy32BitOffset), |
| 6108 | fixup_label, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6109 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6110 | generate_null_check = !cls->IsInDexCache(); |
| 6111 | break; |
| 6112 | } |
| 6113 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 6114 | // /* GcRoot<mirror::Class>[] */ out = |
| 6115 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 6116 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6117 | __ movl(out, Address(current_method, |
| 6118 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
| 6119 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6120 | GenerateGcRootFieldLoad(cls, |
| 6121 | out_loc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6122 | Address(out, |
| 6123 | CodeGenerator::GetCacheOffset(cls->GetTypeIndex().index_)), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6124 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6125 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6126 | generate_null_check = !cls->IsInDexCache(); |
| 6127 | break; |
| 6128 | } |
| 6129 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6130 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6131 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6132 | DCHECK(cls->CanCallRuntime()); |
| 6133 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 6134 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6135 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6136 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6137 | if (generate_null_check) { |
| 6138 | __ testl(out, out); |
| 6139 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6140 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6141 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6142 | if (cls->MustGenerateClinitCheck()) { |
| 6143 | GenerateClassInitializationCheck(slow_path, out); |
| 6144 | } else { |
| 6145 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6146 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6147 | } |
| 6148 | } |
| 6149 | |
| 6150 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6151 | LocationSummary* locations = |
| 6152 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6153 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6154 | if (check->HasUses()) { |
| 6155 | locations->SetOut(Location::SameAsFirstInput()); |
| 6156 | } |
| 6157 | } |
| 6158 | |
| 6159 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6160 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6161 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6162 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6163 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6164 | GenerateClassInitializationCheck(slow_path, |
| 6165 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6166 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6167 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6168 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6169 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6170 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 6171 | Immediate(mirror::Class::kStatusInitialized)); |
| 6172 | __ j(kLess, slow_path->GetEntryLabel()); |
| 6173 | __ Bind(slow_path->GetExitLabel()); |
| 6174 | // No need for memory fence, thanks to the X86 memory model. |
| 6175 | } |
| 6176 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6177 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6178 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6179 | switch (desired_string_load_kind) { |
| 6180 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 6181 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6182 | break; |
| 6183 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6184 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6185 | FALLTHROUGH_INTENDED; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6186 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6187 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6188 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 6189 | // is incompatible with it. |
| 6190 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 6191 | // with irreducible loops. |
| 6192 | if (GetGraph()->HasIrreducibleLoops()) { |
| 6193 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 6194 | } |
| 6195 | break; |
| 6196 | case HLoadString::LoadKind::kBootImageAddress: |
| 6197 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6198 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 6199 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6200 | case HLoadString::LoadKind::kJitTableAddress: |
| 6201 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6202 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6203 | } |
| 6204 | return desired_string_load_kind; |
| 6205 | } |
| 6206 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6207 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6208 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6209 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6210 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6211 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6212 | load_kind == HLoadString::LoadKind::kBssEntry) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6213 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6214 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6215 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 6216 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 6217 | } else { |
| 6218 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6219 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6220 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6221 | // Rely on the pResolveString and/or marking to save everything. |
| 6222 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6223 | InvokeRuntimeCallingConvention calling_convention; |
| 6224 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6225 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6226 | } else { |
| 6227 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6228 | } |
| 6229 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6230 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6231 | } |
| 6232 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6233 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6234 | dex::StringIndex dex_index, |
| 6235 | Handle<mirror::String> handle) { |
| 6236 | jit_string_roots_.Overwrite( |
| 6237 | StringReference(&dex_file, dex_index), reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6238 | // Add a patch entry and return the label. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6239 | jit_string_patches_.emplace_back(dex_file, dex_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6240 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6241 | return &info->label; |
| 6242 | } |
| 6243 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6244 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6245 | // move. |
| 6246 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6247 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6248 | Location out_loc = locations->Out(); |
| 6249 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6250 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6251 | switch (load->GetLoadKind()) { |
| 6252 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6253 | __ movl(out, Immediate(/* placeholder */ 0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6254 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6255 | return; // No dex cache slow path. |
| 6256 | } |
| 6257 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6258 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6259 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6260 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6261 | return; // No dex cache slow path. |
| 6262 | } |
| 6263 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6264 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6265 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6266 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6267 | __ movl(out, Immediate(address)); |
| 6268 | codegen_->RecordSimplePatch(); |
| 6269 | return; // No dex cache slow path. |
| 6270 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6271 | case HLoadString::LoadKind::kBssEntry: { |
| 6272 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6273 | Address address = Address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6274 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6275 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6276 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6277 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 6278 | codegen_->AddSlowPath(slow_path); |
| 6279 | __ testl(out, out); |
| 6280 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6281 | __ Bind(slow_path->GetExitLabel()); |
| 6282 | return; |
| 6283 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6284 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6285 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6286 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6287 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6288 | // /* GcRoot<mirror::String> */ out = *address |
| 6289 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6290 | return; |
| 6291 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6292 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6293 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6294 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6295 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6296 | // 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] | 6297 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6298 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6299 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6300 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6301 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6302 | } |
| 6303 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6304 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6305 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6306 | } |
| 6307 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6308 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6309 | LocationSummary* locations = |
| 6310 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6311 | locations->SetOut(Location::RequiresRegister()); |
| 6312 | } |
| 6313 | |
| 6314 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6315 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6316 | } |
| 6317 | |
| 6318 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 6319 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6320 | } |
| 6321 | |
| 6322 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6323 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6324 | } |
| 6325 | |
| 6326 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 6327 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6328 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6329 | InvokeRuntimeCallingConvention calling_convention; |
| 6330 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6331 | } |
| 6332 | |
| 6333 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6334 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6335 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6336 | } |
| 6337 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6338 | // Temp is used for read barrier. |
| 6339 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6340 | if (kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6341 | !kUseBakerReadBarrier && |
| 6342 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6343 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6344 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6345 | return 1; |
| 6346 | } |
| 6347 | return 0; |
| 6348 | } |
| 6349 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6350 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6351 | // interface pointer, one for loading the current interface. |
| 6352 | // The other checks have one temp for loading the object's class. |
| 6353 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6354 | if (type_check_kind == TypeCheckKind::kInterfaceCheck && !kPoisonHeapReferences) { |
| 6355 | return 2; |
| 6356 | } |
| 6357 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6358 | } |
| 6359 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6360 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6361 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6362 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6363 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6364 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6365 | case TypeCheckKind::kExactCheck: |
| 6366 | case TypeCheckKind::kAbstractClassCheck: |
| 6367 | case TypeCheckKind::kClassHierarchyCheck: |
| 6368 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6369 | call_kind = |
| 6370 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6371 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6372 | break; |
| 6373 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6374 | case TypeCheckKind::kUnresolvedCheck: |
| 6375 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6376 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6377 | break; |
| 6378 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6379 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6380 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6381 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6382 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6383 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6384 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6385 | locations->SetInAt(1, Location::Any()); |
| 6386 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6387 | locations->SetOut(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6388 | // When read barriers are enabled, we need a temporary register for some cases. |
| 6389 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6390 | } |
| 6391 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6392 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6393 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6394 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6395 | Location obj_loc = locations->InAt(0); |
| 6396 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6397 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6398 | Location out_loc = locations->Out(); |
| 6399 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6400 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6401 | DCHECK_LE(num_temps, 1u); |
| 6402 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6403 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6404 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6405 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6406 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6407 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6408 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6409 | |
| 6410 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6411 | // Avoid null check if we know obj is not null. |
| 6412 | if (instruction->MustDoNullCheck()) { |
| 6413 | __ testl(obj, obj); |
| 6414 | __ j(kEqual, &zero); |
| 6415 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6416 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6417 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6418 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6419 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6420 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6421 | out_loc, |
| 6422 | obj_loc, |
| 6423 | class_offset, |
| 6424 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6425 | if (cls.IsRegister()) { |
| 6426 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6427 | } else { |
| 6428 | DCHECK(cls.IsStackSlot()) << cls; |
| 6429 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6430 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6431 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6432 | // Classes must be equal for the instanceof to succeed. |
| 6433 | __ j(kNotEqual, &zero); |
| 6434 | __ movl(out, Immediate(1)); |
| 6435 | __ jmp(&done); |
| 6436 | break; |
| 6437 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6438 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6439 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6440 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6441 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6442 | out_loc, |
| 6443 | obj_loc, |
| 6444 | class_offset, |
| 6445 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6446 | // If the class is abstract, we eagerly fetch the super class of the |
| 6447 | // object to avoid doing a comparison we know will fail. |
| 6448 | NearLabel loop; |
| 6449 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6450 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6451 | GenerateReferenceLoadOneRegister(instruction, |
| 6452 | out_loc, |
| 6453 | super_offset, |
| 6454 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6455 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6456 | __ testl(out, out); |
| 6457 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6458 | __ j(kEqual, &done); |
| 6459 | if (cls.IsRegister()) { |
| 6460 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6461 | } else { |
| 6462 | DCHECK(cls.IsStackSlot()) << cls; |
| 6463 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6464 | } |
| 6465 | __ j(kNotEqual, &loop); |
| 6466 | __ movl(out, Immediate(1)); |
| 6467 | if (zero.IsLinked()) { |
| 6468 | __ jmp(&done); |
| 6469 | } |
| 6470 | break; |
| 6471 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6472 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6473 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6474 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6475 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6476 | out_loc, |
| 6477 | obj_loc, |
| 6478 | class_offset, |
| 6479 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6480 | // Walk over the class hierarchy to find a match. |
| 6481 | NearLabel loop, success; |
| 6482 | __ Bind(&loop); |
| 6483 | if (cls.IsRegister()) { |
| 6484 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6485 | } else { |
| 6486 | DCHECK(cls.IsStackSlot()) << cls; |
| 6487 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6488 | } |
| 6489 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6490 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6491 | GenerateReferenceLoadOneRegister(instruction, |
| 6492 | out_loc, |
| 6493 | super_offset, |
| 6494 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6495 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6496 | __ testl(out, out); |
| 6497 | __ j(kNotEqual, &loop); |
| 6498 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6499 | __ jmp(&done); |
| 6500 | __ Bind(&success); |
| 6501 | __ movl(out, Immediate(1)); |
| 6502 | if (zero.IsLinked()) { |
| 6503 | __ jmp(&done); |
| 6504 | } |
| 6505 | break; |
| 6506 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6507 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6508 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6509 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6510 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6511 | out_loc, |
| 6512 | obj_loc, |
| 6513 | class_offset, |
| 6514 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6515 | // Do an exact check. |
| 6516 | NearLabel exact_check; |
| 6517 | if (cls.IsRegister()) { |
| 6518 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6519 | } else { |
| 6520 | DCHECK(cls.IsStackSlot()) << cls; |
| 6521 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6522 | } |
| 6523 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6524 | // 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] | 6525 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6526 | GenerateReferenceLoadOneRegister(instruction, |
| 6527 | out_loc, |
| 6528 | component_offset, |
| 6529 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6530 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6531 | __ testl(out, out); |
| 6532 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6533 | __ j(kEqual, &done); |
| 6534 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6535 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6536 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6537 | __ movl(out, Immediate(1)); |
| 6538 | __ jmp(&done); |
| 6539 | break; |
| 6540 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6541 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6542 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6543 | // No read barrier since the slow path will retry upon failure. |
| 6544 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6545 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6546 | out_loc, |
| 6547 | obj_loc, |
| 6548 | class_offset, |
| 6549 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6550 | if (cls.IsRegister()) { |
| 6551 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6552 | } else { |
| 6553 | DCHECK(cls.IsStackSlot()) << cls; |
| 6554 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6555 | } |
| 6556 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6557 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6558 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6559 | codegen_->AddSlowPath(slow_path); |
| 6560 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6561 | __ movl(out, Immediate(1)); |
| 6562 | if (zero.IsLinked()) { |
| 6563 | __ jmp(&done); |
| 6564 | } |
| 6565 | break; |
| 6566 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6567 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6568 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6569 | case TypeCheckKind::kInterfaceCheck: { |
| 6570 | // 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] | 6571 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6572 | // cases. |
| 6573 | // |
| 6574 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6575 | // entry point without resorting to a type checking slow path |
| 6576 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6577 | // require to assign fixed registers for the inputs of this |
| 6578 | // HInstanceOf instruction (following the runtime calling |
| 6579 | // convention), which might be cluttered by the potential first |
| 6580 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6581 | // |
| 6582 | // TODO: Introduce a new runtime entry point taking the object |
| 6583 | // to test (instead of its class) as argument, and let it deal |
| 6584 | // with the read barrier issues. This will let us refactor this |
| 6585 | // case of the `switch` code as it was previously (with a direct |
| 6586 | // call to the runtime not using a type checking slow path). |
| 6587 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6588 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6589 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6590 | /* is_fatal */ false); |
| 6591 | codegen_->AddSlowPath(slow_path); |
| 6592 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6593 | if (zero.IsLinked()) { |
| 6594 | __ jmp(&done); |
| 6595 | } |
| 6596 | break; |
| 6597 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6598 | } |
| 6599 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6600 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6601 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6602 | __ xorl(out, out); |
| 6603 | } |
| 6604 | |
| 6605 | if (done.IsLinked()) { |
| 6606 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6607 | } |
| 6608 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6609 | if (slow_path != nullptr) { |
| 6610 | __ Bind(slow_path->GetExitLabel()); |
| 6611 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6612 | } |
| 6613 | |
Mathieu Chartier | 5ac321b | 2016-11-09 16:33:54 -0800 | [diff] [blame] | 6614 | static bool IsTypeCheckSlowPathFatal(TypeCheckKind type_check_kind, bool throws_into_catch) { |
| 6615 | switch (type_check_kind) { |
| 6616 | case TypeCheckKind::kExactCheck: |
| 6617 | case TypeCheckKind::kAbstractClassCheck: |
| 6618 | case TypeCheckKind::kClassHierarchyCheck: |
| 6619 | case TypeCheckKind::kArrayObjectCheck: |
| 6620 | return !throws_into_catch && !kEmitCompilerReadBarrier; |
| 6621 | case TypeCheckKind::kInterfaceCheck: |
| 6622 | return !throws_into_catch && !kEmitCompilerReadBarrier && !kPoisonHeapReferences; |
| 6623 | case TypeCheckKind::kArrayCheck: |
| 6624 | case TypeCheckKind::kUnresolvedCheck: |
| 6625 | return false; |
| 6626 | } |
| 6627 | LOG(FATAL) << "Unreachable"; |
| 6628 | UNREACHABLE(); |
| 6629 | } |
| 6630 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6631 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6632 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6633 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Mathieu Chartier | 5ac321b | 2016-11-09 16:33:54 -0800 | [diff] [blame] | 6634 | LocationSummary::CallKind call_kind = |
| 6635 | IsTypeCheckSlowPathFatal(type_check_kind, throws_into_catch) |
| 6636 | ? LocationSummary::kNoCall |
| 6637 | : LocationSummary::kCallOnSlowPath; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6638 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6639 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6640 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6641 | // Require a register for the interface check since there is a loop that compares the class to |
| 6642 | // a memory address. |
| 6643 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6644 | } else { |
| 6645 | locations->SetInAt(1, Location::Any()); |
| 6646 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6647 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6648 | locations->AddTemp(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6649 | // When read barriers are enabled, we need an additional temporary register for some cases. |
| 6650 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 6651 | } |
| 6652 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6653 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6654 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6655 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6656 | Location obj_loc = locations->InAt(0); |
| 6657 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6658 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6659 | Location temp_loc = locations->GetTemp(0); |
| 6660 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6661 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6662 | DCHECK_GE(num_temps, 1u); |
| 6663 | DCHECK_LE(num_temps, 2u); |
| 6664 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 6665 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6666 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6667 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6668 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6669 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6670 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6671 | const uint32_t object_array_data_offset = |
| 6672 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6673 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6674 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 6675 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 6676 | // read barriers is done for performance and code size reasons. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6677 | bool is_type_check_slow_path_fatal = |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6678 | IsTypeCheckSlowPathFatal(type_check_kind, instruction->CanThrowIntoCatchBlock()); |
| 6679 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6680 | SlowPathCode* type_check_slow_path = |
| 6681 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6682 | is_type_check_slow_path_fatal); |
| 6683 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6684 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6685 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6686 | // Avoid null check if we know obj is not null. |
| 6687 | if (instruction->MustDoNullCheck()) { |
| 6688 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6689 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6690 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6691 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6692 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6693 | case TypeCheckKind::kExactCheck: |
| 6694 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6695 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6696 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6697 | temp_loc, |
| 6698 | obj_loc, |
| 6699 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6700 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6701 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6702 | if (cls.IsRegister()) { |
| 6703 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6704 | } else { |
| 6705 | DCHECK(cls.IsStackSlot()) << cls; |
| 6706 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6707 | } |
| 6708 | // Jump to slow path for throwing the exception or doing a |
| 6709 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6710 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6711 | break; |
| 6712 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6713 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6714 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6715 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6716 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6717 | temp_loc, |
| 6718 | obj_loc, |
| 6719 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6720 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6721 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6722 | // If the class is abstract, we eagerly fetch the super class of the |
| 6723 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6724 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6725 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6726 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6727 | GenerateReferenceLoadOneRegister(instruction, |
| 6728 | temp_loc, |
| 6729 | super_offset, |
| 6730 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6731 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6732 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6733 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6734 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6735 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6736 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6737 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6738 | // Otherwise, compare the classes |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6739 | if (cls.IsRegister()) { |
| 6740 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6741 | } else { |
| 6742 | DCHECK(cls.IsStackSlot()) << cls; |
| 6743 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6744 | } |
| 6745 | __ j(kNotEqual, &loop); |
| 6746 | break; |
| 6747 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6748 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6749 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6750 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6751 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6752 | temp_loc, |
| 6753 | obj_loc, |
| 6754 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6755 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6756 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6757 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6758 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6759 | __ Bind(&loop); |
| 6760 | if (cls.IsRegister()) { |
| 6761 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6762 | } else { |
| 6763 | DCHECK(cls.IsStackSlot()) << cls; |
| 6764 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6765 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6766 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6767 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6768 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6769 | GenerateReferenceLoadOneRegister(instruction, |
| 6770 | temp_loc, |
| 6771 | super_offset, |
| 6772 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6773 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6774 | |
| 6775 | // If the class reference currently in `temp` is not null, jump |
| 6776 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6777 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6778 | __ j(kNotZero, &loop); |
| 6779 | // Otherwise, jump to the slow path to throw the exception.; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6780 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6781 | break; |
| 6782 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6783 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6784 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6785 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6786 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6787 | temp_loc, |
| 6788 | obj_loc, |
| 6789 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6790 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6791 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6792 | // Do an exact check. |
| 6793 | if (cls.IsRegister()) { |
| 6794 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6795 | } else { |
| 6796 | DCHECK(cls.IsStackSlot()) << cls; |
| 6797 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6798 | } |
| 6799 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6800 | |
| 6801 | // 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] | 6802 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6803 | GenerateReferenceLoadOneRegister(instruction, |
| 6804 | temp_loc, |
| 6805 | component_offset, |
| 6806 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6807 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6808 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6809 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 6810 | // throw the exception. Otherwise proceed with the check. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6811 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6812 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6813 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6814 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6815 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6816 | break; |
| 6817 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6818 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6819 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6820 | // 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] | 6821 | // We cannot directly call the CheckCast runtime entry point |
| 6822 | // without resorting to a type checking slow path here (i.e. by |
| 6823 | // calling InvokeRuntime directly), as it would require to |
| 6824 | // assign fixed registers for the inputs of this HInstanceOf |
| 6825 | // instruction (following the runtime calling convention), which |
| 6826 | // might be cluttered by the potential first read barrier |
| 6827 | // emission at the beginning of this method. |
| 6828 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6829 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6830 | |
| 6831 | case TypeCheckKind::kInterfaceCheck: { |
| 6832 | // Fast path for the interface check. Since we compare with a memory location in the inner |
| 6833 | // loop we would need to have cls poisoned. However unpoisoning cls would reset the |
| 6834 | // conditional flags and cause the conditional jump to be incorrect. Therefore we just jump |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6835 | // to the slow path if we are running under poisoning. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6836 | if (!kPoisonHeapReferences) { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6837 | // Try to avoid read barriers to improve the fast path. We can not get false positives by |
| 6838 | // doing this. |
| 6839 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6840 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6841 | temp_loc, |
| 6842 | obj_loc, |
| 6843 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6844 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6845 | |
| 6846 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6847 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6848 | temp_loc, |
| 6849 | temp_loc, |
| 6850 | iftable_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6851 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6852 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6853 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6854 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6855 | NearLabel start_loop; |
| 6856 | __ Bind(&start_loop); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6857 | // Need to subtract first to handle the empty array case. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6858 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6859 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 6860 | // Go to next interface if the classes do not match. |
| 6861 | __ cmpl(cls.AsRegister<Register>(), |
| 6862 | CodeGeneratorX86::ArrayAddress(temp, |
| 6863 | maybe_temp2_loc, |
| 6864 | TIMES_4, |
| 6865 | object_array_data_offset)); |
| 6866 | __ j(kNotEqual, &start_loop); |
| 6867 | } else { |
| 6868 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6869 | } |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6870 | break; |
| 6871 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6872 | } |
| 6873 | __ Bind(&done); |
| 6874 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6875 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6876 | } |
| 6877 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6878 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6879 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6880 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6881 | InvokeRuntimeCallingConvention calling_convention; |
| 6882 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6883 | } |
| 6884 | |
| 6885 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6886 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 6887 | : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6888 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6889 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6890 | if (instruction->IsEnter()) { |
| 6891 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6892 | } else { |
| 6893 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6894 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6895 | } |
| 6896 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6897 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6898 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6899 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6900 | |
| 6901 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6902 | LocationSummary* locations = |
| 6903 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6904 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6905 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6906 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6907 | locations->SetInAt(1, Location::Any()); |
| 6908 | locations->SetOut(Location::SameAsFirstInput()); |
| 6909 | } |
| 6910 | |
| 6911 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6912 | HandleBitwiseOperation(instruction); |
| 6913 | } |
| 6914 | |
| 6915 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6916 | HandleBitwiseOperation(instruction); |
| 6917 | } |
| 6918 | |
| 6919 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6920 | HandleBitwiseOperation(instruction); |
| 6921 | } |
| 6922 | |
| 6923 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6924 | LocationSummary* locations = instruction->GetLocations(); |
| 6925 | Location first = locations->InAt(0); |
| 6926 | Location second = locations->InAt(1); |
| 6927 | DCHECK(first.Equals(locations->Out())); |
| 6928 | |
| 6929 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6930 | if (second.IsRegister()) { |
| 6931 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6932 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6933 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6934 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6935 | } else { |
| 6936 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6937 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6938 | } |
| 6939 | } else if (second.IsConstant()) { |
| 6940 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6941 | __ andl(first.AsRegister<Register>(), |
| 6942 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6943 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6944 | __ orl(first.AsRegister<Register>(), |
| 6945 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6946 | } else { |
| 6947 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6948 | __ xorl(first.AsRegister<Register>(), |
| 6949 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6950 | } |
| 6951 | } else { |
| 6952 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6953 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6954 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6955 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6956 | } else { |
| 6957 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6958 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6959 | } |
| 6960 | } |
| 6961 | } else { |
| 6962 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6963 | if (second.IsRegisterPair()) { |
| 6964 | if (instruction->IsAnd()) { |
| 6965 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6966 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6967 | } else if (instruction->IsOr()) { |
| 6968 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6969 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6970 | } else { |
| 6971 | DCHECK(instruction->IsXor()); |
| 6972 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6973 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6974 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6975 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6976 | if (instruction->IsAnd()) { |
| 6977 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6978 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6979 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6980 | } else if (instruction->IsOr()) { |
| 6981 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6982 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6983 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6984 | } else { |
| 6985 | DCHECK(instruction->IsXor()); |
| 6986 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6987 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 6988 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6989 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6990 | } else { |
| 6991 | DCHECK(second.IsConstant()) << second; |
| 6992 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6993 | int32_t low_value = Low32Bits(value); |
| 6994 | int32_t high_value = High32Bits(value); |
| 6995 | Immediate low(low_value); |
| 6996 | Immediate high(high_value); |
| 6997 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6998 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6999 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7000 | if (low_value == 0) { |
| 7001 | __ xorl(first_low, first_low); |
| 7002 | } else if (low_value != -1) { |
| 7003 | __ andl(first_low, low); |
| 7004 | } |
| 7005 | if (high_value == 0) { |
| 7006 | __ xorl(first_high, first_high); |
| 7007 | } else if (high_value != -1) { |
| 7008 | __ andl(first_high, high); |
| 7009 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7010 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7011 | if (low_value != 0) { |
| 7012 | __ orl(first_low, low); |
| 7013 | } |
| 7014 | if (high_value != 0) { |
| 7015 | __ orl(first_high, high); |
| 7016 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7017 | } else { |
| 7018 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7019 | if (low_value != 0) { |
| 7020 | __ xorl(first_low, low); |
| 7021 | } |
| 7022 | if (high_value != 0) { |
| 7023 | __ xorl(first_high, high); |
| 7024 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7025 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7026 | } |
| 7027 | } |
| 7028 | } |
| 7029 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7030 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( |
| 7031 | HInstruction* instruction, |
| 7032 | Location out, |
| 7033 | uint32_t offset, |
| 7034 | Location maybe_temp, |
| 7035 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7036 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7037 | if (read_barrier_option == kWithReadBarrier) { |
| 7038 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7039 | if (kUseBakerReadBarrier) { |
| 7040 | // Load with fast path based Baker's read barrier. |
| 7041 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7042 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7043 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7044 | } else { |
| 7045 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7046 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7047 | // in the following move operation, as we will need it for the |
| 7048 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7049 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7050 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7051 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7052 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7053 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7054 | } |
| 7055 | } else { |
| 7056 | // Plain load with no read barrier. |
| 7057 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7058 | __ movl(out_reg, Address(out_reg, offset)); |
| 7059 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7060 | } |
| 7061 | } |
| 7062 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7063 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( |
| 7064 | HInstruction* instruction, |
| 7065 | Location out, |
| 7066 | Location obj, |
| 7067 | uint32_t offset, |
| 7068 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7069 | Register out_reg = out.AsRegister<Register>(); |
| 7070 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7071 | if (read_barrier_option == kWithReadBarrier) { |
| 7072 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7073 | if (kUseBakerReadBarrier) { |
| 7074 | // Load with fast path based Baker's read barrier. |
| 7075 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7076 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7077 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7078 | } else { |
| 7079 | // Load with slow path based read barrier. |
| 7080 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7081 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7082 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7083 | } |
| 7084 | } else { |
| 7085 | // Plain load with no read barrier. |
| 7086 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7087 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7088 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7089 | } |
| 7090 | } |
| 7091 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7092 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( |
| 7093 | HInstruction* instruction, |
| 7094 | Location root, |
| 7095 | const Address& address, |
| 7096 | Label* fixup_label, |
| 7097 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7098 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7099 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7100 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7101 | if (kUseBakerReadBarrier) { |
| 7102 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7103 | // Baker's read barrier are used: |
| 7104 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7105 | // root = *address; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7106 | // if (Thread::Current()->GetIsGcMarking()) { |
| 7107 | // root = ReadBarrier::Mark(root) |
| 7108 | // } |
| 7109 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7110 | // /* GcRoot<mirror::Object> */ root = *address |
| 7111 | __ movl(root_reg, address); |
| 7112 | if (fixup_label != nullptr) { |
| 7113 | __ Bind(fixup_label); |
| 7114 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7115 | static_assert( |
| 7116 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7117 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7118 | "have different sizes."); |
| 7119 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7120 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7121 | "have different sizes."); |
| 7122 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7123 | // Slow path marking the GC root `root`. |
| 7124 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7125 | instruction, root, /* unpoison_ref_before_marking */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7126 | codegen_->AddSlowPath(slow_path); |
| 7127 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7128 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7129 | Immediate(0)); |
| 7130 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7131 | __ Bind(slow_path->GetExitLabel()); |
| 7132 | } else { |
| 7133 | // GC root loaded through a slow path for read barriers other |
| 7134 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7135 | // /* GcRoot<mirror::Object>* */ root = address |
| 7136 | __ leal(root_reg, address); |
| 7137 | if (fixup_label != nullptr) { |
| 7138 | __ Bind(fixup_label); |
| 7139 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7140 | // /* mirror::Object* */ root = root->Read() |
| 7141 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7142 | } |
| 7143 | } else { |
| 7144 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7145 | // /* GcRoot<mirror::Object> */ root = *address |
| 7146 | __ movl(root_reg, address); |
| 7147 | if (fixup_label != nullptr) { |
| 7148 | __ Bind(fixup_label); |
| 7149 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7150 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7151 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7152 | } |
| 7153 | } |
| 7154 | |
| 7155 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7156 | Location ref, |
| 7157 | Register obj, |
| 7158 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7159 | bool needs_null_check) { |
| 7160 | DCHECK(kEmitCompilerReadBarrier); |
| 7161 | DCHECK(kUseBakerReadBarrier); |
| 7162 | |
| 7163 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7164 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7165 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7166 | } |
| 7167 | |
| 7168 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7169 | Location ref, |
| 7170 | Register obj, |
| 7171 | uint32_t data_offset, |
| 7172 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7173 | bool needs_null_check) { |
| 7174 | DCHECK(kEmitCompilerReadBarrier); |
| 7175 | DCHECK(kUseBakerReadBarrier); |
| 7176 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7177 | static_assert( |
| 7178 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7179 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7180 | // /* HeapReference<Object> */ ref = |
| 7181 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7182 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7183 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7184 | } |
| 7185 | |
| 7186 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7187 | Location ref, |
| 7188 | Register obj, |
| 7189 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7190 | bool needs_null_check, |
| 7191 | bool always_update_field, |
| 7192 | Register* temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7193 | DCHECK(kEmitCompilerReadBarrier); |
| 7194 | DCHECK(kUseBakerReadBarrier); |
| 7195 | |
| 7196 | // In slow path based read barriers, the read barrier call is |
| 7197 | // inserted after the original load. However, in fast path based |
| 7198 | // Baker's read barriers, we need to perform the load of |
| 7199 | // mirror::Object::monitor_ *before* the original reference load. |
| 7200 | // This load-load ordering is required by the read barrier. |
| 7201 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7202 | // |
| 7203 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7204 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7205 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7206 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7207 | // if (is_gray) { |
| 7208 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7209 | // } |
| 7210 | // |
| 7211 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7212 | // slightly more complex as: |
| 7213 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7214 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7215 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7216 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7217 | // - it performs additional checks that we do not do here for |
| 7218 | // performance reasons. |
| 7219 | |
| 7220 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7221 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7222 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7223 | // 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] | 7224 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7225 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7226 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7227 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7228 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7229 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7230 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7231 | // ref = ReadBarrier::Mark(ref); |
| 7232 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7233 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7234 | if (needs_null_check) { |
| 7235 | MaybeRecordImplicitNullCheck(instruction); |
| 7236 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7237 | |
| 7238 | // Load fence to prevent load-load reordering. |
| 7239 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7240 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7241 | |
| 7242 | // The actual reference load. |
| 7243 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7244 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7245 | |
| 7246 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7247 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7248 | SlowPathCode* slow_path; |
| 7249 | if (always_update_field) { |
| 7250 | DCHECK(temp != nullptr); |
| 7251 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
| 7252 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp); |
| 7253 | } else { |
| 7254 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86( |
| 7255 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 7256 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7257 | AddSlowPath(slow_path); |
| 7258 | |
| 7259 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7260 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7261 | |
| 7262 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7263 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7264 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7265 | __ Bind(slow_path->GetExitLabel()); |
| 7266 | } |
| 7267 | |
| 7268 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7269 | Location out, |
| 7270 | Location ref, |
| 7271 | Location obj, |
| 7272 | uint32_t offset, |
| 7273 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7274 | DCHECK(kEmitCompilerReadBarrier); |
| 7275 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7276 | // Insert a slow path based read barrier *after* the reference load. |
| 7277 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7278 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7279 | // reference will be carried out by the runtime within the slow |
| 7280 | // path. |
| 7281 | // |
| 7282 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7283 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7284 | // not used by the artReadBarrierSlow entry point. |
| 7285 | // |
| 7286 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 7287 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 7288 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 7289 | AddSlowPath(slow_path); |
| 7290 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7291 | __ jmp(slow_path->GetEntryLabel()); |
| 7292 | __ Bind(slow_path->GetExitLabel()); |
| 7293 | } |
| 7294 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7295 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7296 | Location out, |
| 7297 | Location ref, |
| 7298 | Location obj, |
| 7299 | uint32_t offset, |
| 7300 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7301 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7302 | // Baker's read barriers shall be handled by the fast path |
| 7303 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 7304 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7305 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7306 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7307 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7308 | } else if (kPoisonHeapReferences) { |
| 7309 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7310 | } |
| 7311 | } |
| 7312 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7313 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7314 | Location out, |
| 7315 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7316 | DCHECK(kEmitCompilerReadBarrier); |
| 7317 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7318 | // Insert a slow path based read barrier *after* the GC root load. |
| 7319 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7320 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7321 | // not need to do anything special for this here. |
| 7322 | SlowPathCode* slow_path = |
| 7323 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 7324 | AddSlowPath(slow_path); |
| 7325 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7326 | __ jmp(slow_path->GetEntryLabel()); |
| 7327 | __ Bind(slow_path->GetExitLabel()); |
| 7328 | } |
| 7329 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7330 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7331 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7332 | LOG(FATAL) << "Unreachable"; |
| 7333 | } |
| 7334 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7335 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7336 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7337 | LOG(FATAL) << "Unreachable"; |
| 7338 | } |
| 7339 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7340 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7341 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7342 | LocationSummary* locations = |
| 7343 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7344 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7345 | } |
| 7346 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7347 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7348 | int32_t lower_bound, |
| 7349 | uint32_t num_entries, |
| 7350 | HBasicBlock* switch_block, |
| 7351 | HBasicBlock* default_block) { |
| 7352 | // Figure out the correct compare values and jump conditions. |
| 7353 | // Handle the first compare/branch as a special case because it might |
| 7354 | // jump to the default case. |
| 7355 | DCHECK_GT(num_entries, 2u); |
| 7356 | Condition first_condition; |
| 7357 | uint32_t index; |
| 7358 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7359 | if (lower_bound != 0) { |
| 7360 | first_condition = kLess; |
| 7361 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7362 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7363 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7364 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7365 | index = 1; |
| 7366 | } else { |
| 7367 | // Handle all the compare/jumps below. |
| 7368 | first_condition = kBelow; |
| 7369 | index = 0; |
| 7370 | } |
| 7371 | |
| 7372 | // Handle the rest of the compare/jumps. |
| 7373 | for (; index + 1 < num_entries; index += 2) { |
| 7374 | int32_t compare_to_value = lower_bound + index + 1; |
| 7375 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7376 | // Jump to successors[index] if value < case_value[index]. |
| 7377 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7378 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7379 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7380 | } |
| 7381 | |
| 7382 | if (index != num_entries) { |
| 7383 | // There are an odd number of entries. Handle the last one. |
| 7384 | DCHECK_EQ(index + 1, num_entries); |
| 7385 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7386 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7387 | } |
| 7388 | |
| 7389 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7390 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7391 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7392 | } |
| 7393 | } |
| 7394 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7395 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7396 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7397 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7398 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7399 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7400 | |
| 7401 | GenPackedSwitchWithCompares(value_reg, |
| 7402 | lower_bound, |
| 7403 | num_entries, |
| 7404 | switch_instr->GetBlock(), |
| 7405 | switch_instr->GetDefaultBlock()); |
| 7406 | } |
| 7407 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7408 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7409 | LocationSummary* locations = |
| 7410 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7411 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7412 | |
| 7413 | // Constant area pointer. |
| 7414 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7415 | |
| 7416 | // And the temporary we need. |
| 7417 | locations->AddTemp(Location::RequiresRegister()); |
| 7418 | } |
| 7419 | |
| 7420 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7421 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7422 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7423 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7424 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7425 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7426 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7427 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7428 | GenPackedSwitchWithCompares(value_reg, |
| 7429 | lower_bound, |
| 7430 | num_entries, |
| 7431 | switch_instr->GetBlock(), |
| 7432 | default_block); |
| 7433 | return; |
| 7434 | } |
| 7435 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7436 | // Optimizing has a jump area. |
| 7437 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7438 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7439 | |
| 7440 | // Remove the bias, if needed. |
| 7441 | if (lower_bound != 0) { |
| 7442 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7443 | value_reg = temp_reg; |
| 7444 | } |
| 7445 | |
| 7446 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7447 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7448 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7449 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7450 | |
| 7451 | // We are in the range of the table. |
| 7452 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7453 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7454 | |
| 7455 | // Compute the actual target address by adding in constant_area. |
| 7456 | __ addl(temp_reg, constant_area); |
| 7457 | |
| 7458 | // And jump. |
| 7459 | __ jmp(temp_reg); |
| 7460 | } |
| 7461 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7462 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7463 | HX86ComputeBaseMethodAddress* insn) { |
| 7464 | LocationSummary* locations = |
| 7465 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7466 | locations->SetOut(Location::RequiresRegister()); |
| 7467 | } |
| 7468 | |
| 7469 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7470 | HX86ComputeBaseMethodAddress* insn) { |
| 7471 | LocationSummary* locations = insn->GetLocations(); |
| 7472 | Register reg = locations->Out().AsRegister<Register>(); |
| 7473 | |
| 7474 | // Generate call to next instruction. |
| 7475 | Label next_instruction; |
| 7476 | __ call(&next_instruction); |
| 7477 | __ Bind(&next_instruction); |
| 7478 | |
| 7479 | // Remember this offset for later use with constant area. |
| 7480 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 7481 | |
| 7482 | // Grab the return address off the stack. |
| 7483 | __ popl(reg); |
| 7484 | } |
| 7485 | |
| 7486 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7487 | HX86LoadFromConstantTable* insn) { |
| 7488 | LocationSummary* locations = |
| 7489 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7490 | |
| 7491 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7492 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7493 | |
| 7494 | // 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] | 7495 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7496 | return; |
| 7497 | } |
| 7498 | |
| 7499 | switch (insn->GetType()) { |
| 7500 | case Primitive::kPrimFloat: |
| 7501 | case Primitive::kPrimDouble: |
| 7502 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7503 | break; |
| 7504 | |
| 7505 | case Primitive::kPrimInt: |
| 7506 | locations->SetOut(Location::RequiresRegister()); |
| 7507 | break; |
| 7508 | |
| 7509 | default: |
| 7510 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7511 | } |
| 7512 | } |
| 7513 | |
| 7514 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7515 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7516 | return; |
| 7517 | } |
| 7518 | |
| 7519 | LocationSummary* locations = insn->GetLocations(); |
| 7520 | Location out = locations->Out(); |
| 7521 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7522 | HConstant *value = insn->GetConstant(); |
| 7523 | |
| 7524 | switch (insn->GetType()) { |
| 7525 | case Primitive::kPrimFloat: |
| 7526 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 7527 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 7528 | break; |
| 7529 | |
| 7530 | case Primitive::kPrimDouble: |
| 7531 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 7532 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 7533 | break; |
| 7534 | |
| 7535 | case Primitive::kPrimInt: |
| 7536 | __ movl(out.AsRegister<Register>(), |
| 7537 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 7538 | break; |
| 7539 | |
| 7540 | default: |
| 7541 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7542 | } |
| 7543 | } |
| 7544 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7545 | /** |
| 7546 | * Class to handle late fixup of offsets into constant area. |
| 7547 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7548 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7549 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7550 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 7551 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7552 | |
| 7553 | protected: |
| 7554 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7555 | |
| 7556 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7557 | |
| 7558 | private: |
| 7559 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7560 | // Patch the correct offset for the instruction. The place to patch is the |
| 7561 | // last 4 bytes of the instruction. |
| 7562 | // The value to patch is the distance from the offset in the constant area |
| 7563 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7564 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7565 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset(); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7566 | |
| 7567 | // Patch in the right value. |
| 7568 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7569 | } |
| 7570 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7571 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7572 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7573 | }; |
| 7574 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7575 | /** |
| 7576 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7577 | * constant area. |
| 7578 | */ |
| 7579 | class JumpTableRIPFixup : public RIPFixup { |
| 7580 | public: |
| 7581 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 7582 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 7583 | |
| 7584 | void CreateJumpTable() { |
| 7585 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7586 | |
| 7587 | // Ensure that the reference to the jump table has the correct offset. |
| 7588 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7589 | SetOffset(offset_in_constant_table); |
| 7590 | |
| 7591 | // The label values in the jump table are computed relative to the |
| 7592 | // instruction addressing the constant area. |
| 7593 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 7594 | |
| 7595 | // Populate the jump table with the correct values for the jump table. |
| 7596 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7597 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7598 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7599 | // The value that we want is the target offset - the position of the table. |
| 7600 | for (int32_t i = 0; i < num_entries; i++) { |
| 7601 | HBasicBlock* b = successors[i]; |
| 7602 | Label* l = codegen_->GetLabelOf(b); |
| 7603 | DCHECK(l->IsBound()); |
| 7604 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7605 | assembler->AppendInt32(offset_to_block); |
| 7606 | } |
| 7607 | } |
| 7608 | |
| 7609 | private: |
| 7610 | const HX86PackedSwitch* switch_instr_; |
| 7611 | }; |
| 7612 | |
| 7613 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7614 | // Generate the constant area if needed. |
| 7615 | X86Assembler* assembler = GetAssembler(); |
| 7616 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7617 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7618 | // byte values. |
| 7619 | assembler->Align(4, 0); |
| 7620 | constant_area_start_ = assembler->CodeSize(); |
| 7621 | |
| 7622 | // Populate any jump tables. |
| 7623 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7624 | jump_table->CreateJumpTable(); |
| 7625 | } |
| 7626 | |
| 7627 | // And now add the constant area to the generated code. |
| 7628 | assembler->AddConstantArea(); |
| 7629 | } |
| 7630 | |
| 7631 | // And finish up. |
| 7632 | CodeGenerator::Finalize(allocator); |
| 7633 | } |
| 7634 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7635 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7636 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7637 | return Address(reg, kDummy32BitOffset, fixup); |
| 7638 | } |
| 7639 | |
| 7640 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7641 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7642 | return Address(reg, kDummy32BitOffset, fixup); |
| 7643 | } |
| 7644 | |
| 7645 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7646 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7647 | return Address(reg, kDummy32BitOffset, fixup); |
| 7648 | } |
| 7649 | |
| 7650 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7651 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7652 | return Address(reg, kDummy32BitOffset, fixup); |
| 7653 | } |
| 7654 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7655 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7656 | if (value == 0) { |
| 7657 | __ xorl(dest, dest); |
| 7658 | } else { |
| 7659 | __ movl(dest, Immediate(value)); |
| 7660 | } |
| 7661 | } |
| 7662 | |
| 7663 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7664 | if (value == 0) { |
| 7665 | __ testl(dest, dest); |
| 7666 | } else { |
| 7667 | __ cmpl(dest, Immediate(value)); |
| 7668 | } |
| 7669 | } |
| 7670 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7671 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 7672 | Register lhs_reg = lhs.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7673 | GenerateIntCompare(lhs_reg, rhs); |
| 7674 | } |
| 7675 | |
| 7676 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7677 | if (rhs.IsConstant()) { |
| 7678 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7679 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7680 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7681 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7682 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7683 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7684 | } |
| 7685 | } |
| 7686 | |
| 7687 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 7688 | Location index, |
| 7689 | ScaleFactor scale, |
| 7690 | uint32_t data_offset) { |
| 7691 | return index.IsConstant() ? |
| 7692 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 7693 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 7694 | } |
| 7695 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7696 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7697 | Register reg, |
| 7698 | Register value) { |
| 7699 | // Create a fixup to be used to create and address the jump table. |
| 7700 | JumpTableRIPFixup* table_fixup = |
| 7701 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7702 | |
| 7703 | // We have to populate the jump tables. |
| 7704 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7705 | |
| 7706 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7707 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7708 | } |
| 7709 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7710 | // TODO: target as memory. |
| 7711 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7712 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7713 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7714 | return; |
| 7715 | } |
| 7716 | |
| 7717 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7718 | |
| 7719 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7720 | if (target.Equals(return_loc)) { |
| 7721 | return; |
| 7722 | } |
| 7723 | |
| 7724 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7725 | // with the else branch. |
| 7726 | if (type == Primitive::kPrimLong) { |
| 7727 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7728 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7729 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7730 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7731 | } else { |
| 7732 | // Let the parallel move resolver take care of all of this. |
| 7733 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7734 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7735 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7736 | } |
| 7737 | } |
| 7738 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7739 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, |
| 7740 | const uint8_t* roots_data, |
| 7741 | const PatchInfo<Label>& info, |
| 7742 | uint64_t index_in_table) const { |
| 7743 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7744 | uintptr_t address = |
| 7745 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7746 | typedef __attribute__((__aligned__(1))) uint32_t unaligned_uint32_t; |
| 7747 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7748 | dchecked_integral_cast<uint32_t>(address); |
| 7749 | } |
| 7750 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7751 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7752 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7753 | const auto& it = jit_string_roots_.find( |
| 7754 | StringReference(&info.dex_file, dex::StringIndex(info.index))); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7755 | DCHECK(it != jit_string_roots_.end()); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7756 | PatchJitRootUse(code, roots_data, info, it->second); |
| 7757 | } |
| 7758 | |
| 7759 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
| 7760 | const auto& it = jit_class_roots_.find( |
| 7761 | TypeReference(&info.dex_file, dex::TypeIndex(info.index))); |
| 7762 | DCHECK(it != jit_class_roots_.end()); |
| 7763 | PatchJitRootUse(code, roots_data, info, it->second); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7764 | } |
| 7765 | } |
| 7766 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7767 | #undef __ |
| 7768 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7769 | } // namespace x86 |
| 7770 | } // namespace art |