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; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 228 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 229 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index.index_)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 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) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 257 | : SlowPathCode(at), cls_(cls), 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 { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 262 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 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; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 268 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 269 | __ movl(calling_convention.GetRegisterAt(0), Immediate(type_index.index_)); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 270 | x86_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage |
| 271 | : kQuickInitializeType, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 272 | instruction_, |
| 273 | dex_pc_, |
| 274 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 275 | if (do_clinit_) { |
| 276 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 277 | } else { |
| 278 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 279 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 280 | |
| 281 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 282 | Location out = locations->Out(); |
| 283 | if (out.IsValid()) { |
| 284 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 285 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 286 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 287 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 288 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 289 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 290 | if (cls_ == instruction_ && cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 291 | DCHECK(out.IsValid()); |
| 292 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 293 | __ movl(Address(method_address, CodeGeneratorX86::kDummy32BitOffset), |
| 294 | locations->Out().AsRegister<Register>()); |
| 295 | Label* fixup_label = x86_codegen->NewTypeBssEntryPatch(cls_); |
| 296 | __ Bind(fixup_label); |
| 297 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 298 | __ jmp(GetExitLabel()); |
| 299 | } |
| 300 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 301 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 302 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 303 | private: |
| 304 | // The class this slow path will load. |
| 305 | HLoadClass* const cls_; |
| 306 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 307 | // The dex PC of `at_`. |
| 308 | const uint32_t dex_pc_; |
| 309 | |
| 310 | // Whether to initialize the class. |
| 311 | const bool do_clinit_; |
| 312 | |
| 313 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 314 | }; |
| 315 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 316 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 317 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 318 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 319 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 320 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 321 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 322 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 323 | DCHECK(instruction_->IsCheckCast() |
| 324 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 325 | |
| 326 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 327 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 328 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 329 | if (!is_fatal_) { |
| 330 | SaveLiveRegisters(codegen, locations); |
| 331 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 332 | |
| 333 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 334 | // move resolver. |
| 335 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 336 | x86_codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 337 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 338 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 339 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 340 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 341 | Primitive::kPrimNot); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 342 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 343 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 344 | instruction_, |
| 345 | instruction_->GetDexPc(), |
| 346 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 347 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 348 | } else { |
| 349 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 350 | x86_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 351 | instruction_, |
| 352 | instruction_->GetDexPc(), |
| 353 | this); |
| 354 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 357 | if (!is_fatal_) { |
| 358 | if (instruction_->IsInstanceOf()) { |
| 359 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 360 | } |
| 361 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 362 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 363 | __ jmp(GetExitLabel()); |
| 364 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 367 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 368 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 369 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 370 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 371 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 372 | |
| 373 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 374 | }; |
| 375 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 376 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 377 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 378 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 379 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 380 | |
| 381 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 382 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 383 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 384 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 385 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 388 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 389 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 390 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 391 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 392 | }; |
| 393 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 394 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 395 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 396 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 397 | |
| 398 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 399 | LocationSummary* locations = instruction_->GetLocations(); |
| 400 | __ Bind(GetEntryLabel()); |
| 401 | SaveLiveRegisters(codegen, locations); |
| 402 | |
| 403 | InvokeRuntimeCallingConvention calling_convention; |
| 404 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 405 | parallel_move.AddMove( |
| 406 | locations->InAt(0), |
| 407 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 408 | Primitive::kPrimNot, |
| 409 | nullptr); |
| 410 | parallel_move.AddMove( |
| 411 | locations->InAt(1), |
| 412 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 413 | Primitive::kPrimInt, |
| 414 | nullptr); |
| 415 | parallel_move.AddMove( |
| 416 | locations->InAt(2), |
| 417 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 418 | Primitive::kPrimNot, |
| 419 | nullptr); |
| 420 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 421 | |
| 422 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 423 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 424 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 425 | RestoreLiveRegisters(codegen, locations); |
| 426 | __ jmp(GetExitLabel()); |
| 427 | } |
| 428 | |
| 429 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 430 | |
| 431 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 432 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 433 | }; |
| 434 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 435 | // Slow path marking an object reference `ref` during a read |
| 436 | // barrier. The field `obj.field` in the object `obj` holding this |
| 437 | // reference does not get updated by this slow path after marking (see |
| 438 | // ReadBarrierMarkAndUpdateFieldSlowPathX86 below for that). |
| 439 | // |
| 440 | // This means that after the execution of this slow path, `ref` will |
| 441 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 442 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 443 | // probably still be a from-space reference (unless it gets updated by |
| 444 | // another thread, or if another thread installed another object |
| 445 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 446 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 447 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 448 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, |
| 449 | Location ref, |
| 450 | bool unpoison_ref_before_marking) |
| 451 | : SlowPathCode(instruction), |
| 452 | ref_(ref), |
| 453 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 454 | DCHECK(kEmitCompilerReadBarrier); |
| 455 | } |
| 456 | |
| 457 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 458 | |
| 459 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 460 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 461 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 462 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 463 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 464 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 465 | instruction_->IsStaticFieldGet() || |
| 466 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 467 | instruction_->IsArraySet() || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 468 | instruction_->IsLoadClass() || |
| 469 | instruction_->IsLoadString() || |
| 470 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 471 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 472 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 473 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 474 | << "Unexpected instruction in read barrier marking slow path: " |
| 475 | << instruction_->DebugName(); |
| 476 | |
| 477 | __ Bind(GetEntryLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 478 | if (unpoison_ref_before_marking_) { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 479 | // Object* ref = ref_addr->AsMirrorPtr() |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 480 | __ MaybeUnpoisonHeapReference(ref_reg); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 481 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 482 | // No need to save live registers; it's taken care of by the |
| 483 | // entrypoint. Also, there is no need to update the stack mask, |
| 484 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 485 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 486 | DCHECK_NE(ref_reg, ESP); |
| 487 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 488 | // "Compact" slow path, saving two moves. |
| 489 | // |
| 490 | // Instead of using the standard runtime calling convention (input |
| 491 | // and output in EAX): |
| 492 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 493 | // EAX <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 494 | // EAX <- ReadBarrierMark(EAX) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 495 | // ref <- EAX |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 496 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 497 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 498 | // of a dedicated entrypoint: |
| 499 | // |
| 500 | // rX <- ReadBarrierMarkRegX(rX) |
| 501 | // |
| 502 | int32_t entry_point_offset = |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 503 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 504 | // This runtime call does not require a stack map. |
| 505 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 506 | __ jmp(GetExitLabel()); |
| 507 | } |
| 508 | |
| 509 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 510 | // The location (register) of the marked object reference. |
| 511 | const Location ref_; |
| 512 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 513 | const bool unpoison_ref_before_marking_; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 514 | |
| 515 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 516 | }; |
| 517 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 518 | // Slow path marking an object reference `ref` during a read barrier, |
| 519 | // and if needed, atomically updating the field `obj.field` in the |
| 520 | // object `obj` holding this reference after marking (contrary to |
| 521 | // ReadBarrierMarkSlowPathX86 above, which never tries to update |
| 522 | // `obj.field`). |
| 523 | // |
| 524 | // This means that after the execution of this slow path, both `ref` |
| 525 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 526 | // hold the same to-space reference (unless another thread installed |
| 527 | // another object reference (different from `ref`) in `obj.field`). |
| 528 | class ReadBarrierMarkAndUpdateFieldSlowPathX86 : public SlowPathCode { |
| 529 | public: |
| 530 | ReadBarrierMarkAndUpdateFieldSlowPathX86(HInstruction* instruction, |
| 531 | Location ref, |
| 532 | Register obj, |
| 533 | const Address& field_addr, |
| 534 | bool unpoison_ref_before_marking, |
| 535 | Register temp) |
| 536 | : SlowPathCode(instruction), |
| 537 | ref_(ref), |
| 538 | obj_(obj), |
| 539 | field_addr_(field_addr), |
| 540 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 541 | temp_(temp) { |
| 542 | DCHECK(kEmitCompilerReadBarrier); |
| 543 | } |
| 544 | |
| 545 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkAndUpdateFieldSlowPathX86"; } |
| 546 | |
| 547 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 548 | LocationSummary* locations = instruction_->GetLocations(); |
| 549 | Register ref_reg = ref_.AsRegister<Register>(); |
| 550 | DCHECK(locations->CanCall()); |
| 551 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 552 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 553 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 554 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 555 | << instruction_->DebugName(); |
| 556 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 557 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 558 | |
| 559 | __ Bind(GetEntryLabel()); |
| 560 | if (unpoison_ref_before_marking_) { |
| 561 | // Object* ref = ref_addr->AsMirrorPtr() |
| 562 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 563 | } |
| 564 | |
| 565 | // Save the old (unpoisoned) reference. |
| 566 | __ movl(temp_, ref_reg); |
| 567 | |
| 568 | // No need to save live registers; it's taken care of by the |
| 569 | // entrypoint. Also, there is no need to update the stack mask, |
| 570 | // as this runtime call will not trigger a garbage collection. |
| 571 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 572 | DCHECK_NE(ref_reg, ESP); |
| 573 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 574 | // "Compact" slow path, saving two moves. |
| 575 | // |
| 576 | // Instead of using the standard runtime calling convention (input |
| 577 | // and output in EAX): |
| 578 | // |
| 579 | // EAX <- ref |
| 580 | // EAX <- ReadBarrierMark(EAX) |
| 581 | // ref <- EAX |
| 582 | // |
| 583 | // we just use rX (the register containing `ref`) as input and output |
| 584 | // of a dedicated entrypoint: |
| 585 | // |
| 586 | // rX <- ReadBarrierMarkRegX(rX) |
| 587 | // |
| 588 | int32_t entry_point_offset = |
| 589 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
| 590 | // This runtime call does not require a stack map. |
| 591 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 592 | |
| 593 | // If the new reference is different from the old reference, |
| 594 | // update the field in the holder (`*field_addr`). |
| 595 | // |
| 596 | // Note that this field could also hold a different object, if |
| 597 | // another thread had concurrently changed it. In that case, the |
| 598 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 599 | // operation below would abort the CAS, leaving the field as-is. |
| 600 | NearLabel done; |
| 601 | __ cmpl(temp_, ref_reg); |
| 602 | __ j(kEqual, &done); |
| 603 | |
| 604 | // Update the the holder's field atomically. This may fail if |
| 605 | // mutator updates before us, but it's OK. This is achieved |
| 606 | // using a strong compare-and-set (CAS) operation with relaxed |
| 607 | // memory synchronization ordering, where the expected value is |
| 608 | // the old reference and the desired value is the new reference. |
| 609 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 610 | // instruction, which requires the expected value (the old |
| 611 | // reference) to be in EAX. Save EAX beforehand, and move the |
| 612 | // expected value (stored in `temp_`) into EAX. |
| 613 | __ pushl(EAX); |
| 614 | __ movl(EAX, temp_); |
| 615 | |
| 616 | // Convenience aliases. |
| 617 | Register base = obj_; |
| 618 | Register expected = EAX; |
| 619 | Register value = ref_reg; |
| 620 | |
| 621 | bool base_equals_value = (base == value); |
| 622 | if (kPoisonHeapReferences) { |
| 623 | if (base_equals_value) { |
| 624 | // If `base` and `value` are the same register location, move |
| 625 | // `value` to a temporary register. This way, poisoning |
| 626 | // `value` won't invalidate `base`. |
| 627 | value = temp_; |
| 628 | __ movl(value, base); |
| 629 | } |
| 630 | |
| 631 | // Check that the register allocator did not assign the location |
| 632 | // of `expected` (EAX) to `value` nor to `base`, so that heap |
| 633 | // poisoning (when enabled) works as intended below. |
| 634 | // - If `value` were equal to `expected`, both references would |
| 635 | // be poisoned twice, meaning they would not be poisoned at |
| 636 | // all, as heap poisoning uses address negation. |
| 637 | // - If `base` were equal to `expected`, poisoning `expected` |
| 638 | // would invalidate `base`. |
| 639 | DCHECK_NE(value, expected); |
| 640 | DCHECK_NE(base, expected); |
| 641 | |
| 642 | __ PoisonHeapReference(expected); |
| 643 | __ PoisonHeapReference(value); |
| 644 | } |
| 645 | |
| 646 | __ LockCmpxchgl(field_addr_, value); |
| 647 | |
| 648 | // If heap poisoning is enabled, we need to unpoison the values |
| 649 | // that were poisoned earlier. |
| 650 | if (kPoisonHeapReferences) { |
| 651 | if (base_equals_value) { |
| 652 | // `value` has been moved to a temporary register, no need |
| 653 | // to unpoison it. |
| 654 | } else { |
| 655 | __ UnpoisonHeapReference(value); |
| 656 | } |
| 657 | // No need to unpoison `expected` (EAX), as it is be overwritten below. |
| 658 | } |
| 659 | |
| 660 | // Restore EAX. |
| 661 | __ popl(EAX); |
| 662 | |
| 663 | __ Bind(&done); |
| 664 | __ jmp(GetExitLabel()); |
| 665 | } |
| 666 | |
| 667 | private: |
| 668 | // The location (register) of the marked object reference. |
| 669 | const Location ref_; |
| 670 | // The register containing the object holding the marked object reference field. |
| 671 | const Register obj_; |
| 672 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 673 | const Address field_addr_; |
| 674 | |
| 675 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 676 | const bool unpoison_ref_before_marking_; |
| 677 | |
| 678 | const Register temp_; |
| 679 | |
| 680 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86); |
| 681 | }; |
| 682 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 683 | // Slow path generating a read barrier for a heap reference. |
| 684 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 685 | public: |
| 686 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 687 | Location out, |
| 688 | Location ref, |
| 689 | Location obj, |
| 690 | uint32_t offset, |
| 691 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 692 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 693 | out_(out), |
| 694 | ref_(ref), |
| 695 | obj_(obj), |
| 696 | offset_(offset), |
| 697 | index_(index) { |
| 698 | DCHECK(kEmitCompilerReadBarrier); |
| 699 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 700 | // has been overwritten by (or after) the heap object reference load |
| 701 | // to be instrumented, e.g.: |
| 702 | // |
| 703 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 704 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 705 | // |
| 706 | // In that case, we have lost the information about the original |
| 707 | // object, and the emitted read barrier cannot work properly. |
| 708 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 709 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 710 | } |
| 711 | |
| 712 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 713 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 714 | LocationSummary* locations = instruction_->GetLocations(); |
| 715 | Register reg_out = out_.AsRegister<Register>(); |
| 716 | DCHECK(locations->CanCall()); |
| 717 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 718 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 719 | instruction_->IsStaticFieldGet() || |
| 720 | instruction_->IsArrayGet() || |
| 721 | instruction_->IsInstanceOf() || |
| 722 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 723 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 724 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 725 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 726 | |
| 727 | __ Bind(GetEntryLabel()); |
| 728 | SaveLiveRegisters(codegen, locations); |
| 729 | |
| 730 | // We may have to change the index's value, but as `index_` is a |
| 731 | // constant member (like other "inputs" of this slow path), |
| 732 | // introduce a copy of it, `index`. |
| 733 | Location index = index_; |
| 734 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 735 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 736 | if (instruction_->IsArrayGet()) { |
| 737 | // Compute the actual memory offset and store it in `index`. |
| 738 | Register index_reg = index_.AsRegister<Register>(); |
| 739 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 740 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 741 | // We are about to change the value of `index_reg` (see the |
| 742 | // calls to art::x86::X86Assembler::shll and |
| 743 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 744 | // not been saved by the previous call to |
| 745 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 746 | // callee-save register -- |
| 747 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 748 | // callee-save registers, as it has been designed with the |
| 749 | // assumption that callee-save registers are supposed to be |
| 750 | // handled by the called function. So, as a callee-save |
| 751 | // register, `index_reg` _would_ eventually be saved onto |
| 752 | // the stack, but it would be too late: we would have |
| 753 | // changed its value earlier. Therefore, we manually save |
| 754 | // it here into another freely available register, |
| 755 | // `free_reg`, chosen of course among the caller-save |
| 756 | // registers (as a callee-save `free_reg` register would |
| 757 | // exhibit the same problem). |
| 758 | // |
| 759 | // Note we could have requested a temporary register from |
| 760 | // the register allocator instead; but we prefer not to, as |
| 761 | // this is a slow path, and we know we can find a |
| 762 | // caller-save register that is available. |
| 763 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 764 | __ movl(free_reg, index_reg); |
| 765 | index_reg = free_reg; |
| 766 | index = Location::RegisterLocation(index_reg); |
| 767 | } else { |
| 768 | // The initial register stored in `index_` has already been |
| 769 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 770 | // (as it is not a callee-save register), so we can freely |
| 771 | // use it. |
| 772 | } |
| 773 | // Shifting the index value contained in `index_reg` by the scale |
| 774 | // factor (2) cannot overflow in practice, as the runtime is |
| 775 | // unable to allocate object arrays with a size larger than |
| 776 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 777 | __ shll(index_reg, Immediate(TIMES_4)); |
| 778 | static_assert( |
| 779 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 780 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 781 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 782 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 783 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 784 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 785 | // (as in the case of ArrayGet), as it is actually an offset |
| 786 | // to an object field within an object. |
| 787 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 788 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 789 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 790 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 791 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 792 | DCHECK_EQ(offset_, 0U); |
| 793 | DCHECK(index_.IsRegisterPair()); |
| 794 | // UnsafeGet's offset location is a register pair, the low |
| 795 | // part contains the correct offset. |
| 796 | index = index_.ToLow(); |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | // We're moving two or three locations to locations that could |
| 801 | // overlap, so we need a parallel move resolver. |
| 802 | InvokeRuntimeCallingConvention calling_convention; |
| 803 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 804 | parallel_move.AddMove(ref_, |
| 805 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 806 | Primitive::kPrimNot, |
| 807 | nullptr); |
| 808 | parallel_move.AddMove(obj_, |
| 809 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 810 | Primitive::kPrimNot, |
| 811 | nullptr); |
| 812 | if (index.IsValid()) { |
| 813 | parallel_move.AddMove(index, |
| 814 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 815 | Primitive::kPrimInt, |
| 816 | nullptr); |
| 817 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 818 | } else { |
| 819 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 820 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 821 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 822 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 823 | CheckEntrypointTypes< |
| 824 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 825 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 826 | |
| 827 | RestoreLiveRegisters(codegen, locations); |
| 828 | __ jmp(GetExitLabel()); |
| 829 | } |
| 830 | |
| 831 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 832 | |
| 833 | private: |
| 834 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 835 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 836 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 837 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 838 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 839 | return static_cast<Register>(i); |
| 840 | } |
| 841 | } |
| 842 | // We shall never fail to find a free caller-save register, as |
| 843 | // there are more than two core caller-save registers on x86 |
| 844 | // (meaning it is possible to find one which is different from |
| 845 | // `ref` and `obj`). |
| 846 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 847 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 848 | UNREACHABLE(); |
| 849 | } |
| 850 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 851 | const Location out_; |
| 852 | const Location ref_; |
| 853 | const Location obj_; |
| 854 | const uint32_t offset_; |
| 855 | // An additional location containing an index to an array. |
| 856 | // Only used for HArrayGet and the UnsafeGetObject & |
| 857 | // UnsafeGetObjectVolatile intrinsics. |
| 858 | const Location index_; |
| 859 | |
| 860 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 861 | }; |
| 862 | |
| 863 | // Slow path generating a read barrier for a GC root. |
| 864 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 865 | public: |
| 866 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 867 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 868 | DCHECK(kEmitCompilerReadBarrier); |
| 869 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 870 | |
| 871 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 872 | LocationSummary* locations = instruction_->GetLocations(); |
| 873 | Register reg_out = out_.AsRegister<Register>(); |
| 874 | DCHECK(locations->CanCall()); |
| 875 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 876 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 877 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 878 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 879 | |
| 880 | __ Bind(GetEntryLabel()); |
| 881 | SaveLiveRegisters(codegen, locations); |
| 882 | |
| 883 | InvokeRuntimeCallingConvention calling_convention; |
| 884 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 885 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 886 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 887 | instruction_, |
| 888 | instruction_->GetDexPc(), |
| 889 | this); |
| 890 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 891 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 892 | |
| 893 | RestoreLiveRegisters(codegen, locations); |
| 894 | __ jmp(GetExitLabel()); |
| 895 | } |
| 896 | |
| 897 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 898 | |
| 899 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 900 | const Location out_; |
| 901 | const Location root_; |
| 902 | |
| 903 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 904 | }; |
| 905 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 906 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 907 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 908 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 909 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 910 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 911 | switch (cond) { |
| 912 | case kCondEQ: return kEqual; |
| 913 | case kCondNE: return kNotEqual; |
| 914 | case kCondLT: return kLess; |
| 915 | case kCondLE: return kLessEqual; |
| 916 | case kCondGT: return kGreater; |
| 917 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 918 | case kCondB: return kBelow; |
| 919 | case kCondBE: return kBelowEqual; |
| 920 | case kCondA: return kAbove; |
| 921 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 922 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 923 | LOG(FATAL) << "Unreachable"; |
| 924 | UNREACHABLE(); |
| 925 | } |
| 926 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 927 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 928 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 929 | switch (cond) { |
| 930 | case kCondEQ: return kEqual; |
| 931 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 932 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 933 | case kCondLT: return kBelow; |
| 934 | case kCondLE: return kBelowEqual; |
| 935 | case kCondGT: return kAbove; |
| 936 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 937 | // Unsigned remain unchanged. |
| 938 | case kCondB: return kBelow; |
| 939 | case kCondBE: return kBelowEqual; |
| 940 | case kCondA: return kAbove; |
| 941 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 942 | } |
| 943 | LOG(FATAL) << "Unreachable"; |
| 944 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 945 | } |
| 946 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 947 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 948 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 952 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 953 | } |
| 954 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 955 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 956 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 957 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 958 | } |
| 959 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 960 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 961 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 962 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 963 | } |
| 964 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 965 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 966 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 967 | return GetFloatingPointSpillSlotSize(); |
| 968 | } |
| 969 | |
| 970 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 971 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 972 | return GetFloatingPointSpillSlotSize(); |
| 973 | } |
| 974 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 975 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 976 | HInstruction* instruction, |
| 977 | uint32_t dex_pc, |
| 978 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 979 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 980 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 981 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 982 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 983 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 984 | } |
| 985 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 986 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 987 | HInstruction* instruction, |
| 988 | SlowPathCode* slow_path) { |
| 989 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 990 | GenerateInvokeRuntime(entry_point_offset); |
| 991 | } |
| 992 | |
| 993 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 994 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 995 | } |
| 996 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 997 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 998 | const X86InstructionSetFeatures& isa_features, |
| 999 | const CompilerOptions& compiler_options, |
| 1000 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1001 | : CodeGenerator(graph, |
| 1002 | kNumberOfCpuRegisters, |
| 1003 | kNumberOfXmmRegisters, |
| 1004 | kNumberOfRegisterPairs, |
| 1005 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1006 | arraysize(kCoreCalleeSaves)) |
| 1007 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1008 | 0, |
| 1009 | compiler_options, |
| 1010 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1011 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1012 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1013 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1014 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1015 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1016 | isa_features_(isa_features), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1017 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1018 | simple_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1019 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1020 | boot_image_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1021 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1022 | jit_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1023 | jit_class_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1024 | constant_area_start_(-1), |
| 1025 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1026 | method_address_offset_(std::less<uint32_t>(), |
| 1027 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1028 | // Use a fake return address register to mimic Quick. |
| 1029 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1030 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1031 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1032 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1033 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1034 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1035 | } |
| 1036 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1037 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1038 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1039 | assembler_(codegen->GetAssembler()), |
| 1040 | codegen_(codegen) {} |
| 1041 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1042 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1043 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1044 | } |
| 1045 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1046 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1047 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1048 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1049 | bool skip_overflow_check = |
| 1050 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1051 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1052 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1053 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1054 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1055 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1056 | } |
| 1057 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1058 | if (HasEmptyFrame()) { |
| 1059 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1060 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1061 | |
| 1062 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1063 | Register reg = kCoreCalleeSaves[i]; |
| 1064 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1065 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1066 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1067 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1068 | } |
| 1069 | } |
| 1070 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1071 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1072 | // Initialize should_deoptimize flag to 0. |
| 1073 | __ movl(Address(ESP, -kShouldDeoptimizeFlagSize), Immediate(0)); |
| 1074 | } |
| 1075 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1076 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1077 | __ subl(ESP, Immediate(adjust)); |
| 1078 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1079 | // Save the current method if we need it. Note that we do not |
| 1080 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1081 | // in the SSA graph. |
| 1082 | if (RequiresCurrentMethod()) { |
| 1083 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1084 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1088 | __ cfi().RememberState(); |
| 1089 | if (!HasEmptyFrame()) { |
| 1090 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1091 | __ addl(ESP, Immediate(adjust)); |
| 1092 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1093 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1094 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1095 | Register reg = kCoreCalleeSaves[i]; |
| 1096 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1097 | __ popl(reg); |
| 1098 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1099 | __ cfi().Restore(DWARFReg(reg)); |
| 1100 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1101 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1102 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1103 | __ ret(); |
| 1104 | __ cfi().RestoreState(); |
| 1105 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1106 | } |
| 1107 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1108 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1109 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1112 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 1113 | switch (type) { |
| 1114 | case Primitive::kPrimBoolean: |
| 1115 | case Primitive::kPrimByte: |
| 1116 | case Primitive::kPrimChar: |
| 1117 | case Primitive::kPrimShort: |
| 1118 | case Primitive::kPrimInt: |
| 1119 | case Primitive::kPrimNot: |
| 1120 | return Location::RegisterLocation(EAX); |
| 1121 | |
| 1122 | case Primitive::kPrimLong: |
| 1123 | return Location::RegisterPairLocation(EAX, EDX); |
| 1124 | |
| 1125 | case Primitive::kPrimVoid: |
| 1126 | return Location::NoLocation(); |
| 1127 | |
| 1128 | case Primitive::kPrimDouble: |
| 1129 | case Primitive::kPrimFloat: |
| 1130 | return Location::FpuRegisterLocation(XMM0); |
| 1131 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1132 | |
| 1133 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1137 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1138 | } |
| 1139 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1140 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1141 | switch (type) { |
| 1142 | case Primitive::kPrimBoolean: |
| 1143 | case Primitive::kPrimByte: |
| 1144 | case Primitive::kPrimChar: |
| 1145 | case Primitive::kPrimShort: |
| 1146 | case Primitive::kPrimInt: |
| 1147 | case Primitive::kPrimNot: { |
| 1148 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1149 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1150 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1151 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1152 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1153 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1154 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1155 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1156 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1157 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1158 | uint32_t index = gp_index_; |
| 1159 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1160 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1161 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1162 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1163 | calling_convention.GetRegisterPairAt(index)); |
| 1164 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1165 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1166 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | case Primitive::kPrimFloat: { |
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_++; |
| 1173 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1174 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1175 | } else { |
| 1176 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1177 | } |
| 1178 | } |
| 1179 | |
| 1180 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1181 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1182 | stack_index_ += 2; |
| 1183 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1184 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1185 | } else { |
| 1186 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1187 | } |
| 1188 | } |
| 1189 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1190 | case Primitive::kPrimVoid: |
| 1191 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1192 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1193 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1194 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1195 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1196 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1197 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1198 | if (source.Equals(destination)) { |
| 1199 | return; |
| 1200 | } |
| 1201 | if (destination.IsRegister()) { |
| 1202 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1203 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1204 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1205 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1206 | } else { |
| 1207 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1208 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1209 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1210 | } else if (destination.IsFpuRegister()) { |
| 1211 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1212 | __ movd(destination.AsFpuRegister<XmmRegister>(), 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 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1215 | } else { |
| 1216 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1217 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1218 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1219 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1220 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1221 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1222 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1223 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1224 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1225 | } else if (source.IsConstant()) { |
| 1226 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1227 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1228 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1229 | } else { |
| 1230 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1231 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1232 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1233 | } |
| 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1238 | if (source.Equals(destination)) { |
| 1239 | return; |
| 1240 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1241 | if (destination.IsRegisterPair()) { |
| 1242 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1243 | EmitParallelMoves( |
| 1244 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1245 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1246 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1247 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1248 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1249 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1250 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1251 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1252 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1253 | __ psrlq(src_reg, Immediate(32)); |
| 1254 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1255 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1256 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1257 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1258 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1259 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1260 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1261 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1262 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1263 | if (source.IsFpuRegister()) { |
| 1264 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1265 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1266 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1267 | } else if (source.IsRegisterPair()) { |
| 1268 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1269 | // Create stack space for 2 elements. |
| 1270 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1271 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1272 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1273 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1274 | // And remove the temporary stack space we allocated. |
| 1275 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1276 | } else { |
| 1277 | LOG(FATAL) << "Unimplemented"; |
| 1278 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1279 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1280 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1281 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1282 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1283 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1284 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1285 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1286 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1287 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1288 | } else if (source.IsConstant()) { |
| 1289 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1290 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1291 | int64_t value = GetInt64ValueOf(constant); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1292 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1293 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1294 | Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1295 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1296 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1297 | EmitParallelMoves( |
| 1298 | Location::StackSlot(source.GetStackIndex()), |
| 1299 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1300 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1301 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1302 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1303 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1304 | } |
| 1305 | } |
| 1306 | } |
| 1307 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1308 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1309 | DCHECK(location.IsRegister()); |
| 1310 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1311 | } |
| 1312 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1313 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1314 | HParallelMove move(GetGraph()->GetArena()); |
| 1315 | if (dst_type == Primitive::kPrimLong && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1316 | move.AddMove(src.ToLow(), dst.ToLow(), Primitive::kPrimInt, nullptr); |
| 1317 | move.AddMove(src.ToHigh(), dst.ToHigh(), Primitive::kPrimInt, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1318 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1319 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1320 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1321 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1325 | if (location.IsRegister()) { |
| 1326 | locations->AddTemp(location); |
| 1327 | } else if (location.IsRegisterPair()) { |
| 1328 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1329 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1330 | } else { |
| 1331 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1332 | } |
| 1333 | } |
| 1334 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1335 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1336 | DCHECK(!successor->IsExitBlock()); |
| 1337 | |
| 1338 | HBasicBlock* block = got->GetBlock(); |
| 1339 | HInstruction* previous = got->GetPrevious(); |
| 1340 | |
| 1341 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1342 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1343 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1344 | return; |
| 1345 | } |
| 1346 | |
| 1347 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1348 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1349 | } |
| 1350 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1351 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1352 | } |
| 1353 | } |
| 1354 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1355 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1356 | got->SetLocations(nullptr); |
| 1357 | } |
| 1358 | |
| 1359 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1360 | HandleGoto(got, got->GetSuccessor()); |
| 1361 | } |
| 1362 | |
| 1363 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1364 | try_boundary->SetLocations(nullptr); |
| 1365 | } |
| 1366 | |
| 1367 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1368 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1369 | if (!successor->IsExitBlock()) { |
| 1370 | HandleGoto(try_boundary, successor); |
| 1371 | } |
| 1372 | } |
| 1373 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1374 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1375 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1376 | } |
| 1377 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1378 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1379 | } |
| 1380 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1381 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1382 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1383 | LabelType* true_label, |
| 1384 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1385 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1386 | __ j(kUnordered, true_label); |
| 1387 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1388 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1389 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1390 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1391 | } |
| 1392 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1393 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1394 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1395 | LabelType* true_label, |
| 1396 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1397 | LocationSummary* locations = cond->GetLocations(); |
| 1398 | Location left = locations->InAt(0); |
| 1399 | Location right = locations->InAt(1); |
| 1400 | IfCondition if_cond = cond->GetCondition(); |
| 1401 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1402 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1403 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1404 | IfCondition true_high_cond = if_cond; |
| 1405 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1406 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1407 | |
| 1408 | // Set the conditions for the test, remembering that == needs to be |
| 1409 | // decided using the low words. |
| 1410 | switch (if_cond) { |
| 1411 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1412 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1413 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1414 | break; |
| 1415 | case kCondLT: |
| 1416 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1417 | break; |
| 1418 | case kCondLE: |
| 1419 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1420 | break; |
| 1421 | case kCondGT: |
| 1422 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1423 | break; |
| 1424 | case kCondGE: |
| 1425 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1426 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1427 | case kCondB: |
| 1428 | false_high_cond = kCondA; |
| 1429 | break; |
| 1430 | case kCondBE: |
| 1431 | true_high_cond = kCondB; |
| 1432 | break; |
| 1433 | case kCondA: |
| 1434 | false_high_cond = kCondB; |
| 1435 | break; |
| 1436 | case kCondAE: |
| 1437 | true_high_cond = kCondA; |
| 1438 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | if (right.IsConstant()) { |
| 1442 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1443 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1444 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1445 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1446 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1447 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1448 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1449 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1450 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1451 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1452 | __ j(X86Condition(true_high_cond), true_label); |
| 1453 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1454 | } |
| 1455 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1456 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1457 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1458 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1459 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1460 | |
| 1461 | __ cmpl(left_high, right_high); |
| 1462 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1463 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1464 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1465 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1466 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1467 | __ j(X86Condition(true_high_cond), true_label); |
| 1468 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1469 | } |
| 1470 | // Must be equal high, so compare the lows. |
| 1471 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1472 | } else { |
| 1473 | DCHECK(right.IsDoubleStackSlot()); |
| 1474 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1475 | if (if_cond == kCondNE) { |
| 1476 | __ j(X86Condition(true_high_cond), true_label); |
| 1477 | } else if (if_cond == kCondEQ) { |
| 1478 | __ j(X86Condition(false_high_cond), false_label); |
| 1479 | } else { |
| 1480 | __ j(X86Condition(true_high_cond), true_label); |
| 1481 | __ j(X86Condition(false_high_cond), false_label); |
| 1482 | } |
| 1483 | // Must be equal high, so compare the lows. |
| 1484 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1485 | } |
| 1486 | // The last comparison might be unsigned. |
| 1487 | __ j(final_condition, true_label); |
| 1488 | } |
| 1489 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1490 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1491 | Location rhs, |
| 1492 | HInstruction* insn, |
| 1493 | bool is_double) { |
| 1494 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1495 | if (is_double) { |
| 1496 | if (rhs.IsFpuRegister()) { |
| 1497 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1498 | } else if (const_area != nullptr) { |
| 1499 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1500 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1501 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1502 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1503 | const_area->GetBaseMethodAddress(), |
| 1504 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1505 | } else { |
| 1506 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1507 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1508 | } |
| 1509 | } else { |
| 1510 | if (rhs.IsFpuRegister()) { |
| 1511 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1512 | } else if (const_area != nullptr) { |
| 1513 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1514 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1515 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1516 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1517 | const_area->GetBaseMethodAddress(), |
| 1518 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1519 | } else { |
| 1520 | DCHECK(rhs.IsStackSlot()); |
| 1521 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1522 | } |
| 1523 | } |
| 1524 | } |
| 1525 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1526 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1527 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1528 | LabelType* true_target_in, |
| 1529 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1530 | // Generated branching requires both targets to be explicit. If either of the |
| 1531 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1532 | LabelType fallthrough_target; |
| 1533 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1534 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1535 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1536 | LocationSummary* locations = condition->GetLocations(); |
| 1537 | Location left = locations->InAt(0); |
| 1538 | Location right = locations->InAt(1); |
| 1539 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1540 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1541 | switch (type) { |
| 1542 | case Primitive::kPrimLong: |
| 1543 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1544 | break; |
| 1545 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1546 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1547 | GenerateFPJumps(condition, true_target, false_target); |
| 1548 | break; |
| 1549 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1550 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1551 | GenerateFPJumps(condition, true_target, false_target); |
| 1552 | break; |
| 1553 | default: |
| 1554 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1555 | } |
| 1556 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1557 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1558 | __ jmp(false_target); |
| 1559 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1560 | |
| 1561 | if (fallthrough_target.IsLinked()) { |
| 1562 | __ Bind(&fallthrough_target); |
| 1563 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1564 | } |
| 1565 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1566 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1567 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1568 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1569 | // conditions if they are materialized due to the complex branching. |
| 1570 | return cond->IsCondition() && |
| 1571 | cond->GetNext() == branch && |
| 1572 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1573 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1574 | } |
| 1575 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1576 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1577 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1578 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1579 | LabelType* true_target, |
| 1580 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1581 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1582 | |
| 1583 | if (true_target == nullptr && false_target == nullptr) { |
| 1584 | // Nothing to do. The code always falls through. |
| 1585 | return; |
| 1586 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1587 | // Constant condition, statically compared against "true" (integer value 1). |
| 1588 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1589 | if (true_target != nullptr) { |
| 1590 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1591 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1592 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1593 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1594 | if (false_target != nullptr) { |
| 1595 | __ jmp(false_target); |
| 1596 | } |
| 1597 | } |
| 1598 | return; |
| 1599 | } |
| 1600 | |
| 1601 | // The following code generates these patterns: |
| 1602 | // (1) true_target == nullptr && false_target != nullptr |
| 1603 | // - opposite condition true => branch to false_target |
| 1604 | // (2) true_target != nullptr && false_target == nullptr |
| 1605 | // - condition true => branch to true_target |
| 1606 | // (3) true_target != nullptr && false_target != nullptr |
| 1607 | // - condition true => branch to true_target |
| 1608 | // - branch to false_target |
| 1609 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1610 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1611 | if (true_target == nullptr) { |
| 1612 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1613 | } else { |
| 1614 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1615 | } |
| 1616 | } else { |
| 1617 | // Materialized condition, compare against 0. |
| 1618 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1619 | if (lhs.IsRegister()) { |
| 1620 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1621 | } else { |
| 1622 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1623 | } |
| 1624 | if (true_target == nullptr) { |
| 1625 | __ j(kEqual, false_target); |
| 1626 | } else { |
| 1627 | __ j(kNotEqual, true_target); |
| 1628 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1629 | } |
| 1630 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1631 | // Condition has not been materialized, use its inputs as the comparison and |
| 1632 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1633 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1634 | |
| 1635 | // If this is a long or FP comparison that has been folded into |
| 1636 | // the HCondition, generate the comparison directly. |
| 1637 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1638 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1639 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1640 | return; |
| 1641 | } |
| 1642 | |
| 1643 | Location lhs = condition->GetLocations()->InAt(0); |
| 1644 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1645 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1646 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1647 | if (true_target == nullptr) { |
| 1648 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1649 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1650 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1651 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1652 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1653 | |
| 1654 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1655 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1656 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1657 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1658 | } |
| 1659 | } |
| 1660 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1661 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1662 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1663 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1664 | locations->SetInAt(0, Location::Any()); |
| 1665 | } |
| 1666 | } |
| 1667 | |
| 1668 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1669 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1670 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1671 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1672 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1673 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1674 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1675 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1679 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1680 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1681 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1682 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1683 | locations->SetInAt(0, Location::Any()); |
| 1684 | } |
| 1685 | } |
| 1686 | |
| 1687 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1688 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1689 | GenerateTestAndBranch<Label>(deoptimize, |
| 1690 | /* condition_input_index */ 0, |
| 1691 | slow_path->GetEntryLabel(), |
| 1692 | /* false_target */ nullptr); |
| 1693 | } |
| 1694 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1695 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1696 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1697 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1698 | locations->SetOut(Location::RequiresRegister()); |
| 1699 | } |
| 1700 | |
| 1701 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1702 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), |
| 1703 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1704 | } |
| 1705 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1706 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1707 | // There are no conditional move instructions for XMMs. |
| 1708 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1709 | return false; |
| 1710 | } |
| 1711 | |
| 1712 | // A FP condition doesn't generate the single CC that we need. |
| 1713 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1714 | HInstruction* condition = select->GetCondition(); |
| 1715 | if (condition->IsCondition()) { |
| 1716 | Primitive::Type compare_type = condition->InputAt(0)->GetType(); |
| 1717 | if (compare_type == Primitive::kPrimLong || |
| 1718 | Primitive::IsFloatingPointType(compare_type)) { |
| 1719 | return false; |
| 1720 | } |
| 1721 | } |
| 1722 | |
| 1723 | // We can generate a CMOV for this Select. |
| 1724 | return true; |
| 1725 | } |
| 1726 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1727 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| 1728 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1729 | if (Primitive::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1730 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1731 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1732 | } else { |
| 1733 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1734 | if (SelectCanUseCMOV(select)) { |
| 1735 | if (select->InputAt(1)->IsConstant()) { |
| 1736 | // Cmov can't handle a constant value. |
| 1737 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1738 | } else { |
| 1739 | locations->SetInAt(1, Location::Any()); |
| 1740 | } |
| 1741 | } else { |
| 1742 | locations->SetInAt(1, Location::Any()); |
| 1743 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1744 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1745 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1746 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1747 | } |
| 1748 | locations->SetOut(Location::SameAsFirstInput()); |
| 1749 | } |
| 1750 | |
| 1751 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1752 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1753 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1754 | if (SelectCanUseCMOV(select)) { |
| 1755 | // If both the condition and the source types are integer, we can generate |
| 1756 | // a CMOV to implement Select. |
| 1757 | |
| 1758 | HInstruction* select_condition = select->GetCondition(); |
| 1759 | Condition cond = kNotEqual; |
| 1760 | |
| 1761 | // Figure out how to test the 'condition'. |
| 1762 | if (select_condition->IsCondition()) { |
| 1763 | HCondition* condition = select_condition->AsCondition(); |
| 1764 | if (!condition->IsEmittedAtUseSite()) { |
| 1765 | // This was a previously materialized condition. |
| 1766 | // Can we use the existing condition code? |
| 1767 | if (AreEflagsSetFrom(condition, select)) { |
| 1768 | // Materialization was the previous instruction. Condition codes are right. |
| 1769 | cond = X86Condition(condition->GetCondition()); |
| 1770 | } else { |
| 1771 | // No, we have to recreate the condition code. |
| 1772 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1773 | __ testl(cond_reg, cond_reg); |
| 1774 | } |
| 1775 | } else { |
| 1776 | // We can't handle FP or long here. |
| 1777 | DCHECK_NE(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 1778 | DCHECK(!Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| 1779 | LocationSummary* cond_locations = condition->GetLocations(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1780 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1781 | cond = X86Condition(condition->GetCondition()); |
| 1782 | } |
| 1783 | } else { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1784 | // Must be a Boolean condition, which needs to be compared to 0. |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1785 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1786 | __ testl(cond_reg, cond_reg); |
| 1787 | } |
| 1788 | |
| 1789 | // If the condition is true, overwrite the output, which already contains false. |
| 1790 | Location false_loc = locations->InAt(0); |
| 1791 | Location true_loc = locations->InAt(1); |
| 1792 | if (select->GetType() == Primitive::kPrimLong) { |
| 1793 | // 64 bit conditional move. |
| 1794 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1795 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1796 | if (true_loc.IsRegisterPair()) { |
| 1797 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1798 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1799 | } else { |
| 1800 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1801 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1802 | } |
| 1803 | } else { |
| 1804 | // 32 bit conditional move. |
| 1805 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1806 | if (true_loc.IsRegister()) { |
| 1807 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1808 | } else { |
| 1809 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1810 | } |
| 1811 | } |
| 1812 | } else { |
| 1813 | NearLabel false_target; |
| 1814 | GenerateTestAndBranch<NearLabel>( |
| 1815 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1816 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1817 | __ Bind(&false_target); |
| 1818 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1821 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1822 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1823 | } |
| 1824 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1825 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1826 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | void CodeGeneratorX86::GenerateNop() { |
| 1830 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1831 | } |
| 1832 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1833 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1834 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1835 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1836 | // Handle the long/FP comparisons made in instruction simplification. |
| 1837 | switch (cond->InputAt(0)->GetType()) { |
| 1838 | case Primitive::kPrimLong: { |
| 1839 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1840 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1841 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1842 | locations->SetOut(Location::RequiresRegister()); |
| 1843 | } |
| 1844 | break; |
| 1845 | } |
| 1846 | case Primitive::kPrimFloat: |
| 1847 | case Primitive::kPrimDouble: { |
| 1848 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1849 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1850 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1851 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1852 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1853 | } else { |
| 1854 | locations->SetInAt(1, Location::Any()); |
| 1855 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1856 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1857 | locations->SetOut(Location::RequiresRegister()); |
| 1858 | } |
| 1859 | break; |
| 1860 | } |
| 1861 | default: |
| 1862 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1863 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1864 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1865 | // We need a byte register. |
| 1866 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1867 | } |
| 1868 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1869 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1870 | } |
| 1871 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1872 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1873 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1874 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1875 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1876 | |
| 1877 | LocationSummary* locations = cond->GetLocations(); |
| 1878 | Location lhs = locations->InAt(0); |
| 1879 | Location rhs = locations->InAt(1); |
| 1880 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1881 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1882 | |
| 1883 | switch (cond->InputAt(0)->GetType()) { |
| 1884 | default: { |
| 1885 | // Integer case. |
| 1886 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1887 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1888 | __ xorl(reg, reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1889 | codegen_->GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1890 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1891 | return; |
| 1892 | } |
| 1893 | case Primitive::kPrimLong: |
| 1894 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1895 | break; |
| 1896 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1897 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1898 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1899 | break; |
| 1900 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1901 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1902 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1903 | break; |
| 1904 | } |
| 1905 | |
| 1906 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1907 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1908 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1909 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1910 | __ Bind(&false_label); |
| 1911 | __ xorl(reg, reg); |
| 1912 | __ jmp(&done_label); |
| 1913 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1914 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1915 | __ Bind(&true_label); |
| 1916 | __ movl(reg, Immediate(1)); |
| 1917 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1918 | } |
| 1919 | |
| 1920 | void LocationsBuilderX86::VisitEqual(HEqual* 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 InstructionCodeGeneratorX86::VisitEqual(HEqual* 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 LocationsBuilderX86::VisitNotEqual(HNotEqual* 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 InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* 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 LocationsBuilderX86::VisitLessThan(HLessThan* 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 InstructionCodeGeneratorX86::VisitLessThan(HLessThan* 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 LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* 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 InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* 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 LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1953 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1957 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1961 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1965 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1966 | } |
| 1967 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1968 | void LocationsBuilderX86::VisitBelow(HBelow* 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 InstructionCodeGeneratorX86::VisitBelow(HBelow* 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 LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* 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 InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* 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 LocationsBuilderX86::VisitAbove(HAbove* 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 | |
| 1988 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1989 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1993 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1994 | } |
| 1995 | |
| 1996 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1997 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2000 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2001 | LocationSummary* locations = |
| 2002 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2003 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2004 | } |
| 2005 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2006 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2007 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2008 | } |
| 2009 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2010 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 2011 | LocationSummary* locations = |
| 2012 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2013 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2014 | } |
| 2015 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2016 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2017 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2018 | } |
| 2019 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2020 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2021 | LocationSummary* locations = |
| 2022 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2023 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2024 | } |
| 2025 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2026 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2027 | // Will be generated at use site. |
| 2028 | } |
| 2029 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2030 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2031 | LocationSummary* locations = |
| 2032 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2033 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2034 | } |
| 2035 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2036 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2037 | // Will be generated at use site. |
| 2038 | } |
| 2039 | |
| 2040 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2041 | LocationSummary* locations = |
| 2042 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2043 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2044 | } |
| 2045 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2046 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2047 | // Will be generated at use site. |
| 2048 | } |
| 2049 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2050 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2051 | memory_barrier->SetLocations(nullptr); |
| 2052 | } |
| 2053 | |
| 2054 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2055 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2056 | } |
| 2057 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2058 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2059 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2060 | } |
| 2061 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2062 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2063 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2064 | } |
| 2065 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2066 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2067 | LocationSummary* locations = |
| 2068 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2069 | switch (ret->InputAt(0)->GetType()) { |
| 2070 | case Primitive::kPrimBoolean: |
| 2071 | case Primitive::kPrimByte: |
| 2072 | case Primitive::kPrimChar: |
| 2073 | case Primitive::kPrimShort: |
| 2074 | case Primitive::kPrimInt: |
| 2075 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2076 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2077 | break; |
| 2078 | |
| 2079 | case Primitive::kPrimLong: |
| 2080 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2081 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2082 | break; |
| 2083 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2084 | case Primitive::kPrimFloat: |
| 2085 | case Primitive::kPrimDouble: |
| 2086 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2087 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2088 | break; |
| 2089 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2090 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2091 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2092 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2093 | } |
| 2094 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2095 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2096 | if (kIsDebugBuild) { |
| 2097 | switch (ret->InputAt(0)->GetType()) { |
| 2098 | case Primitive::kPrimBoolean: |
| 2099 | case Primitive::kPrimByte: |
| 2100 | case Primitive::kPrimChar: |
| 2101 | case Primitive::kPrimShort: |
| 2102 | case Primitive::kPrimInt: |
| 2103 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2104 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2105 | break; |
| 2106 | |
| 2107 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2108 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2109 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2110 | break; |
| 2111 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2112 | case Primitive::kPrimFloat: |
| 2113 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2114 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2115 | break; |
| 2116 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2117 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2118 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2119 | } |
| 2120 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2121 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2122 | } |
| 2123 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2124 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2125 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2126 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2127 | // the method_idx. |
| 2128 | HandleInvoke(invoke); |
| 2129 | } |
| 2130 | |
| 2131 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2132 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2133 | } |
| 2134 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2135 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2136 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2137 | // art::PrepareForRegisterAllocation. |
| 2138 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2139 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2140 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2141 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2142 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2143 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2144 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2145 | return; |
| 2146 | } |
| 2147 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2148 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2149 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2150 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2151 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2152 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2153 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2154 | } |
| 2155 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2156 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2157 | if (invoke->GetLocations()->Intrinsified()) { |
| 2158 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2159 | intrinsic.Dispatch(invoke); |
| 2160 | return true; |
| 2161 | } |
| 2162 | return false; |
| 2163 | } |
| 2164 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2165 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2166 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2167 | // art::PrepareForRegisterAllocation. |
| 2168 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2169 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2170 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2171 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2172 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2173 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2174 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2175 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2176 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 2177 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2178 | } |
| 2179 | |
| 2180 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2181 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2182 | if (intrinsic.TryDispatch(invoke)) { |
| 2183 | return; |
| 2184 | } |
| 2185 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2186 | HandleInvoke(invoke); |
| 2187 | } |
| 2188 | |
| 2189 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2190 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2191 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2192 | } |
| 2193 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2194 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2195 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2196 | return; |
| 2197 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2198 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2199 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2200 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2201 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2202 | } |
| 2203 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2204 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2205 | // This call to HandleInvoke allocates a temporary (core) register |
| 2206 | // which is also used to transfer the hidden argument from FP to |
| 2207 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2208 | HandleInvoke(invoke); |
| 2209 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2210 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2211 | } |
| 2212 | |
| 2213 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2214 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2215 | LocationSummary* locations = invoke->GetLocations(); |
| 2216 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2217 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2218 | Location receiver = locations->InAt(0); |
| 2219 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2220 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2221 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2222 | // won't be modified thereafter, before the `call` instruction. |
| 2223 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2224 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2225 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2226 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2227 | if (receiver.IsStackSlot()) { |
| 2228 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2229 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2230 | __ movl(temp, Address(temp, class_offset)); |
| 2231 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2232 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2233 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2234 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2235 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2236 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2237 | // emit a read barrier for the previous class reference load. |
| 2238 | // However this is not required in practice, as this is an |
| 2239 | // intermediate/temporary reference and because the current |
| 2240 | // concurrent copying collector keeps the from-space memory |
| 2241 | // intact/accessible until the end of the marking phase (the |
| 2242 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2243 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2244 | // temp = temp->GetAddressOfIMT() |
| 2245 | __ movl(temp, |
| 2246 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2247 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2248 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2249 | invoke->GetImtIndex(), kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2250 | __ movl(temp, Address(temp, method_offset)); |
| 2251 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2252 | __ call(Address(temp, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2253 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2254 | |
| 2255 | DCHECK(!codegen_->IsLeafMethod()); |
| 2256 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2257 | } |
| 2258 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2259 | void LocationsBuilderX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2260 | HandleInvoke(invoke); |
| 2261 | } |
| 2262 | |
| 2263 | void InstructionCodeGeneratorX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2264 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2265 | } |
| 2266 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2267 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2268 | LocationSummary* locations = |
| 2269 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2270 | switch (neg->GetResultType()) { |
| 2271 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2272 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2273 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2274 | locations->SetOut(Location::SameAsFirstInput()); |
| 2275 | break; |
| 2276 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2277 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2278 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2279 | locations->SetOut(Location::SameAsFirstInput()); |
| 2280 | locations->AddTemp(Location::RequiresRegister()); |
| 2281 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2282 | break; |
| 2283 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2284 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2285 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2286 | locations->SetOut(Location::SameAsFirstInput()); |
| 2287 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2288 | break; |
| 2289 | |
| 2290 | default: |
| 2291 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2292 | } |
| 2293 | } |
| 2294 | |
| 2295 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2296 | LocationSummary* locations = neg->GetLocations(); |
| 2297 | Location out = locations->Out(); |
| 2298 | Location in = locations->InAt(0); |
| 2299 | switch (neg->GetResultType()) { |
| 2300 | case Primitive::kPrimInt: |
| 2301 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2302 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2303 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2304 | break; |
| 2305 | |
| 2306 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2307 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2308 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2309 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2310 | // Negation is similar to subtraction from zero. The least |
| 2311 | // significant byte triggers a borrow when it is different from |
| 2312 | // zero; to take it into account, add 1 to the most significant |
| 2313 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2314 | // operation. |
| 2315 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2316 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2317 | break; |
| 2318 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2319 | case Primitive::kPrimFloat: { |
| 2320 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2321 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2322 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2323 | // Implement float negation with an exclusive or with value |
| 2324 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2325 | // single-precision floating-point number). |
| 2326 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2327 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2328 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2329 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2330 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2331 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2332 | case Primitive::kPrimDouble: { |
| 2333 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2334 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2335 | // Implement double negation with an exclusive or with value |
| 2336 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2337 | // a double-precision floating-point number). |
| 2338 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2339 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2340 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2341 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2342 | |
| 2343 | default: |
| 2344 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2345 | } |
| 2346 | } |
| 2347 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2348 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2349 | LocationSummary* locations = |
| 2350 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2351 | DCHECK(Primitive::IsFloatingPointType(neg->GetType())); |
| 2352 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2353 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2354 | locations->SetOut(Location::SameAsFirstInput()); |
| 2355 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2356 | } |
| 2357 | |
| 2358 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2359 | LocationSummary* locations = neg->GetLocations(); |
| 2360 | Location out = locations->Out(); |
| 2361 | DCHECK(locations->InAt(0).Equals(out)); |
| 2362 | |
| 2363 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2364 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2365 | if (neg->GetType() == Primitive::kPrimFloat) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2366 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), |
| 2367 | neg->GetBaseMethodAddress(), |
| 2368 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2369 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2370 | } else { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2371 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), |
| 2372 | neg->GetBaseMethodAddress(), |
| 2373 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2374 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2375 | } |
| 2376 | } |
| 2377 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2378 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2379 | Primitive::Type result_type = conversion->GetResultType(); |
| 2380 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2381 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2382 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2383 | // The float-to-long and double-to-long type conversions rely on a |
| 2384 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2385 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2386 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2387 | && result_type == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2388 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2389 | : LocationSummary::kNoCall; |
| 2390 | LocationSummary* locations = |
| 2391 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2392 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2393 | // The Java language does not allow treating boolean as an integral type but |
| 2394 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2395 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2396 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2397 | case Primitive::kPrimByte: |
| 2398 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2399 | case Primitive::kPrimLong: { |
| 2400 | // Type conversion from long to byte is a result of code transformations. |
| 2401 | HInstruction* input = conversion->InputAt(0); |
| 2402 | Location input_location = input->IsConstant() |
| 2403 | ? Location::ConstantLocation(input->AsConstant()) |
| 2404 | : Location::RegisterPairLocation(EAX, EDX); |
| 2405 | locations->SetInAt(0, input_location); |
| 2406 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2407 | // the validation of the linear scan implementation |
| 2408 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2409 | break; |
| 2410 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2411 | case Primitive::kPrimBoolean: |
| 2412 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2413 | case Primitive::kPrimShort: |
| 2414 | case Primitive::kPrimInt: |
| 2415 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2416 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2417 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2418 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2419 | // the validation of the linear scan implementation |
| 2420 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2421 | break; |
| 2422 | |
| 2423 | default: |
| 2424 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2425 | << " to " << result_type; |
| 2426 | } |
| 2427 | break; |
| 2428 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2429 | case Primitive::kPrimShort: |
| 2430 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2431 | case Primitive::kPrimLong: |
| 2432 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2433 | case Primitive::kPrimBoolean: |
| 2434 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2435 | case Primitive::kPrimByte: |
| 2436 | case Primitive::kPrimInt: |
| 2437 | case Primitive::kPrimChar: |
| 2438 | // Processing a Dex `int-to-short' instruction. |
| 2439 | locations->SetInAt(0, Location::Any()); |
| 2440 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2441 | break; |
| 2442 | |
| 2443 | default: |
| 2444 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2445 | << " to " << result_type; |
| 2446 | } |
| 2447 | break; |
| 2448 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2449 | case Primitive::kPrimInt: |
| 2450 | switch (input_type) { |
| 2451 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2452 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2453 | locations->SetInAt(0, Location::Any()); |
| 2454 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2455 | break; |
| 2456 | |
| 2457 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2458 | // Processing a Dex `float-to-int' instruction. |
| 2459 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2460 | locations->SetOut(Location::RequiresRegister()); |
| 2461 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2462 | break; |
| 2463 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2464 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2465 | // Processing a Dex `double-to-int' instruction. |
| 2466 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2467 | locations->SetOut(Location::RequiresRegister()); |
| 2468 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2469 | break; |
| 2470 | |
| 2471 | default: |
| 2472 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2473 | << " to " << result_type; |
| 2474 | } |
| 2475 | break; |
| 2476 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2477 | case Primitive::kPrimLong: |
| 2478 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2479 | case Primitive::kPrimBoolean: |
| 2480 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2481 | case Primitive::kPrimByte: |
| 2482 | case Primitive::kPrimShort: |
| 2483 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2484 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2485 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2486 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2487 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2488 | break; |
| 2489 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2490 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2491 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2492 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2493 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2494 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2495 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2496 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2497 | // The runtime helper puts the result in EAX, EDX. |
| 2498 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2499 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2500 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2501 | |
| 2502 | default: |
| 2503 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2504 | << " to " << result_type; |
| 2505 | } |
| 2506 | break; |
| 2507 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2508 | case Primitive::kPrimChar: |
| 2509 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2510 | case Primitive::kPrimLong: |
| 2511 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2512 | case Primitive::kPrimBoolean: |
| 2513 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2514 | case Primitive::kPrimByte: |
| 2515 | case Primitive::kPrimShort: |
| 2516 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2517 | // Processing a Dex `int-to-char' instruction. |
| 2518 | locations->SetInAt(0, Location::Any()); |
| 2519 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2520 | break; |
| 2521 | |
| 2522 | default: |
| 2523 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2524 | << " to " << result_type; |
| 2525 | } |
| 2526 | break; |
| 2527 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2528 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2529 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2530 | case Primitive::kPrimBoolean: |
| 2531 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2532 | case Primitive::kPrimByte: |
| 2533 | case Primitive::kPrimShort: |
| 2534 | case Primitive::kPrimInt: |
| 2535 | case Primitive::kPrimChar: |
| 2536 | // Processing a Dex `int-to-float' instruction. |
| 2537 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2538 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2539 | break; |
| 2540 | |
| 2541 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2542 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2543 | locations->SetInAt(0, Location::Any()); |
| 2544 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2545 | break; |
| 2546 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2547 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2548 | // Processing a Dex `double-to-float' instruction. |
| 2549 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2550 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2551 | break; |
| 2552 | |
| 2553 | default: |
| 2554 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2555 | << " to " << result_type; |
| 2556 | }; |
| 2557 | break; |
| 2558 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2559 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2560 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2561 | case Primitive::kPrimBoolean: |
| 2562 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2563 | case Primitive::kPrimByte: |
| 2564 | case Primitive::kPrimShort: |
| 2565 | case Primitive::kPrimInt: |
| 2566 | case Primitive::kPrimChar: |
| 2567 | // Processing a Dex `int-to-double' instruction. |
| 2568 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2569 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2570 | break; |
| 2571 | |
| 2572 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2573 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2574 | locations->SetInAt(0, Location::Any()); |
| 2575 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2576 | break; |
| 2577 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2578 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2579 | // Processing a Dex `float-to-double' instruction. |
| 2580 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2581 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2582 | break; |
| 2583 | |
| 2584 | default: |
| 2585 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2586 | << " to " << result_type; |
| 2587 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2588 | break; |
| 2589 | |
| 2590 | default: |
| 2591 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2592 | << " to " << result_type; |
| 2593 | } |
| 2594 | } |
| 2595 | |
| 2596 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2597 | LocationSummary* locations = conversion->GetLocations(); |
| 2598 | Location out = locations->Out(); |
| 2599 | Location in = locations->InAt(0); |
| 2600 | Primitive::Type result_type = conversion->GetResultType(); |
| 2601 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2602 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2603 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2604 | case Primitive::kPrimByte: |
| 2605 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2606 | case Primitive::kPrimLong: |
| 2607 | // Type conversion from long to byte is a result of code transformations. |
| 2608 | if (in.IsRegisterPair()) { |
| 2609 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2610 | } else { |
| 2611 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2612 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2613 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2614 | } |
| 2615 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2616 | case Primitive::kPrimBoolean: |
| 2617 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2618 | case Primitive::kPrimShort: |
| 2619 | case Primitive::kPrimInt: |
| 2620 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2621 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2622 | if (in.IsRegister()) { |
| 2623 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2624 | } else { |
| 2625 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2626 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2627 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2628 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2629 | break; |
| 2630 | |
| 2631 | default: |
| 2632 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2633 | << " to " << result_type; |
| 2634 | } |
| 2635 | break; |
| 2636 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2637 | case Primitive::kPrimShort: |
| 2638 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2639 | case Primitive::kPrimLong: |
| 2640 | // Type conversion from long to short is a result of code transformations. |
| 2641 | if (in.IsRegisterPair()) { |
| 2642 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2643 | } else if (in.IsDoubleStackSlot()) { |
| 2644 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2645 | } else { |
| 2646 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2647 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2648 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2649 | } |
| 2650 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2651 | case Primitive::kPrimBoolean: |
| 2652 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2653 | case Primitive::kPrimByte: |
| 2654 | case Primitive::kPrimInt: |
| 2655 | case Primitive::kPrimChar: |
| 2656 | // Processing a Dex `int-to-short' instruction. |
| 2657 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2658 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2659 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2660 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2661 | } else { |
| 2662 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2663 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2664 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2665 | } |
| 2666 | break; |
| 2667 | |
| 2668 | default: |
| 2669 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2670 | << " to " << result_type; |
| 2671 | } |
| 2672 | break; |
| 2673 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2674 | case Primitive::kPrimInt: |
| 2675 | switch (input_type) { |
| 2676 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2677 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2678 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2679 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2680 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2681 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2682 | } else { |
| 2683 | DCHECK(in.IsConstant()); |
| 2684 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2685 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2686 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2687 | } |
| 2688 | break; |
| 2689 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2690 | case Primitive::kPrimFloat: { |
| 2691 | // Processing a Dex `float-to-int' instruction. |
| 2692 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2693 | Register output = out.AsRegister<Register>(); |
| 2694 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2695 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2696 | |
| 2697 | __ movl(output, Immediate(kPrimIntMax)); |
| 2698 | // temp = int-to-float(output) |
| 2699 | __ cvtsi2ss(temp, output); |
| 2700 | // if input >= temp goto done |
| 2701 | __ comiss(input, temp); |
| 2702 | __ j(kAboveEqual, &done); |
| 2703 | // if input == NaN goto nan |
| 2704 | __ j(kUnordered, &nan); |
| 2705 | // output = float-to-int-truncate(input) |
| 2706 | __ cvttss2si(output, input); |
| 2707 | __ jmp(&done); |
| 2708 | __ Bind(&nan); |
| 2709 | // output = 0 |
| 2710 | __ xorl(output, output); |
| 2711 | __ Bind(&done); |
| 2712 | break; |
| 2713 | } |
| 2714 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2715 | case Primitive::kPrimDouble: { |
| 2716 | // Processing a Dex `double-to-int' instruction. |
| 2717 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2718 | Register output = out.AsRegister<Register>(); |
| 2719 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2720 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2721 | |
| 2722 | __ movl(output, Immediate(kPrimIntMax)); |
| 2723 | // temp = int-to-double(output) |
| 2724 | __ cvtsi2sd(temp, output); |
| 2725 | // if input >= temp goto done |
| 2726 | __ comisd(input, temp); |
| 2727 | __ j(kAboveEqual, &done); |
| 2728 | // if input == NaN goto nan |
| 2729 | __ j(kUnordered, &nan); |
| 2730 | // output = double-to-int-truncate(input) |
| 2731 | __ cvttsd2si(output, input); |
| 2732 | __ jmp(&done); |
| 2733 | __ Bind(&nan); |
| 2734 | // output = 0 |
| 2735 | __ xorl(output, output); |
| 2736 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2737 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2738 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2739 | |
| 2740 | default: |
| 2741 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2742 | << " to " << result_type; |
| 2743 | } |
| 2744 | break; |
| 2745 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2746 | case Primitive::kPrimLong: |
| 2747 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2748 | case Primitive::kPrimBoolean: |
| 2749 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2750 | case Primitive::kPrimByte: |
| 2751 | case Primitive::kPrimShort: |
| 2752 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2753 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2754 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2755 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2756 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2757 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2758 | __ cdq(); |
| 2759 | break; |
| 2760 | |
| 2761 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2762 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2763 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2764 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2765 | break; |
| 2766 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2767 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2768 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2769 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2770 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2771 | break; |
| 2772 | |
| 2773 | default: |
| 2774 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2775 | << " to " << result_type; |
| 2776 | } |
| 2777 | break; |
| 2778 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2779 | case Primitive::kPrimChar: |
| 2780 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2781 | case Primitive::kPrimLong: |
| 2782 | // Type conversion from long to short is a result of code transformations. |
| 2783 | if (in.IsRegisterPair()) { |
| 2784 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2785 | } else if (in.IsDoubleStackSlot()) { |
| 2786 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2787 | } else { |
| 2788 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2789 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2790 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2791 | } |
| 2792 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2793 | case Primitive::kPrimBoolean: |
| 2794 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2795 | case Primitive::kPrimByte: |
| 2796 | case Primitive::kPrimShort: |
| 2797 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2798 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2799 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2800 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2801 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2802 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2803 | } else { |
| 2804 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2805 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2806 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2807 | } |
| 2808 | break; |
| 2809 | |
| 2810 | default: |
| 2811 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2812 | << " to " << result_type; |
| 2813 | } |
| 2814 | break; |
| 2815 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2816 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2817 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2818 | case Primitive::kPrimBoolean: |
| 2819 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2820 | case Primitive::kPrimByte: |
| 2821 | case Primitive::kPrimShort: |
| 2822 | case Primitive::kPrimInt: |
| 2823 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2824 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2825 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2826 | break; |
| 2827 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2828 | case Primitive::kPrimLong: { |
| 2829 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2830 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2831 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2832 | // Create stack space for the call to |
| 2833 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2834 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2835 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2836 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2837 | __ subl(ESP, Immediate(adjustment)); |
| 2838 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2839 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2840 | // Load the value to the FP stack, using temporaries if needed. |
| 2841 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2842 | |
| 2843 | if (out.IsStackSlot()) { |
| 2844 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2845 | } else { |
| 2846 | __ fstps(Address(ESP, 0)); |
| 2847 | Location stack_temp = Location::StackSlot(0); |
| 2848 | codegen_->Move32(out, stack_temp); |
| 2849 | } |
| 2850 | |
| 2851 | // Remove the temporary stack space we allocated. |
| 2852 | if (adjustment != 0) { |
| 2853 | __ addl(ESP, Immediate(adjustment)); |
| 2854 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2855 | break; |
| 2856 | } |
| 2857 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2858 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2859 | // Processing a Dex `double-to-float' instruction. |
| 2860 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2861 | break; |
| 2862 | |
| 2863 | default: |
| 2864 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2865 | << " to " << result_type; |
| 2866 | }; |
| 2867 | break; |
| 2868 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2869 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2870 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2871 | case Primitive::kPrimBoolean: |
| 2872 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2873 | case Primitive::kPrimByte: |
| 2874 | case Primitive::kPrimShort: |
| 2875 | case Primitive::kPrimInt: |
| 2876 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2877 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2878 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2879 | break; |
| 2880 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2881 | case Primitive::kPrimLong: { |
| 2882 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2883 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2884 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2885 | // Create stack space for the call to |
| 2886 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2887 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2888 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2889 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2890 | __ subl(ESP, Immediate(adjustment)); |
| 2891 | } |
| 2892 | |
| 2893 | // Load the value to the FP stack, using temporaries if needed. |
| 2894 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2895 | |
| 2896 | if (out.IsDoubleStackSlot()) { |
| 2897 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2898 | } else { |
| 2899 | __ fstpl(Address(ESP, 0)); |
| 2900 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2901 | codegen_->Move64(out, stack_temp); |
| 2902 | } |
| 2903 | |
| 2904 | // Remove the temporary stack space we allocated. |
| 2905 | if (adjustment != 0) { |
| 2906 | __ addl(ESP, Immediate(adjustment)); |
| 2907 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2908 | break; |
| 2909 | } |
| 2910 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2911 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2912 | // Processing a Dex `float-to-double' instruction. |
| 2913 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2914 | break; |
| 2915 | |
| 2916 | default: |
| 2917 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2918 | << " to " << result_type; |
| 2919 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2920 | break; |
| 2921 | |
| 2922 | default: |
| 2923 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2924 | << " to " << result_type; |
| 2925 | } |
| 2926 | } |
| 2927 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2928 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2929 | LocationSummary* locations = |
| 2930 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2931 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2932 | case Primitive::kPrimInt: { |
| 2933 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2934 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2935 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2936 | break; |
| 2937 | } |
| 2938 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2939 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2940 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2941 | locations->SetInAt(1, Location::Any()); |
| 2942 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2943 | break; |
| 2944 | } |
| 2945 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2946 | case Primitive::kPrimFloat: |
| 2947 | case Primitive::kPrimDouble: { |
| 2948 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2949 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2950 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2951 | } else if (add->InputAt(1)->IsConstant()) { |
| 2952 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2953 | } else { |
| 2954 | locations->SetInAt(1, Location::Any()); |
| 2955 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2956 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2957 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2958 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2959 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2960 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2961 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2962 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2963 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2964 | } |
| 2965 | |
| 2966 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2967 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2968 | Location first = locations->InAt(0); |
| 2969 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2970 | Location out = locations->Out(); |
| 2971 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2972 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2973 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2974 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2975 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2976 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2977 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2978 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2979 | } else { |
| 2980 | __ leal(out.AsRegister<Register>(), Address( |
| 2981 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2982 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2983 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2984 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2985 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2986 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2987 | } else { |
| 2988 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2989 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2990 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2991 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2992 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2993 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2994 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2995 | } |
| 2996 | |
| 2997 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2998 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2999 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3000 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3001 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3002 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 3003 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3004 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3005 | } else { |
| 3006 | DCHECK(second.IsConstant()) << second; |
| 3007 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3008 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3009 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3010 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3011 | break; |
| 3012 | } |
| 3013 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3014 | case Primitive::kPrimFloat: { |
| 3015 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3016 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3017 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3018 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3019 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3020 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3021 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3022 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3023 | const_area->GetBaseMethodAddress(), |
| 3024 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3025 | } else { |
| 3026 | DCHECK(second.IsStackSlot()); |
| 3027 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3028 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3029 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3030 | } |
| 3031 | |
| 3032 | case Primitive::kPrimDouble: { |
| 3033 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3034 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3035 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3036 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3037 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3038 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3039 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3040 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3041 | const_area->GetBaseMethodAddress(), |
| 3042 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3043 | } else { |
| 3044 | DCHECK(second.IsDoubleStackSlot()); |
| 3045 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3046 | } |
| 3047 | break; |
| 3048 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3049 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3050 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3051 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3052 | } |
| 3053 | } |
| 3054 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3055 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3056 | LocationSummary* locations = |
| 3057 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3058 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3059 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3060 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3061 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3062 | locations->SetInAt(1, Location::Any()); |
| 3063 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3064 | break; |
| 3065 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3066 | case Primitive::kPrimFloat: |
| 3067 | case Primitive::kPrimDouble: { |
| 3068 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3069 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3070 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3071 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3072 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3073 | } else { |
| 3074 | locations->SetInAt(1, Location::Any()); |
| 3075 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3076 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3077 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3078 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3079 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3080 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3081 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3082 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3083 | } |
| 3084 | |
| 3085 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3086 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3087 | Location first = locations->InAt(0); |
| 3088 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3089 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3090 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3091 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3092 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3093 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3094 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3095 | __ subl(first.AsRegister<Register>(), |
| 3096 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3097 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3098 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3099 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3100 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3101 | } |
| 3102 | |
| 3103 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3104 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3105 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3106 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3107 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3108 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3109 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3110 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3111 | } else { |
| 3112 | DCHECK(second.IsConstant()) << second; |
| 3113 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3114 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3115 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3116 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3117 | break; |
| 3118 | } |
| 3119 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3120 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3121 | if (second.IsFpuRegister()) { |
| 3122 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3123 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3124 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3125 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3126 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3127 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3128 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3129 | const_area->GetBaseMethodAddress(), |
| 3130 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3131 | } else { |
| 3132 | DCHECK(second.IsStackSlot()); |
| 3133 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3134 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3135 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3136 | } |
| 3137 | |
| 3138 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3139 | if (second.IsFpuRegister()) { |
| 3140 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3141 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3142 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3143 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3144 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3145 | codegen_->LiteralDoubleAddress( |
| 3146 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3147 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3148 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3149 | } else { |
| 3150 | DCHECK(second.IsDoubleStackSlot()); |
| 3151 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3152 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3153 | break; |
| 3154 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3155 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3156 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3157 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3158 | } |
| 3159 | } |
| 3160 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3161 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3162 | LocationSummary* locations = |
| 3163 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3164 | switch (mul->GetResultType()) { |
| 3165 | case Primitive::kPrimInt: |
| 3166 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3167 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3168 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3169 | // Can use 3 operand multiply. |
| 3170 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3171 | } else { |
| 3172 | locations->SetOut(Location::SameAsFirstInput()); |
| 3173 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3174 | break; |
| 3175 | case Primitive::kPrimLong: { |
| 3176 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3177 | locations->SetInAt(1, Location::Any()); |
| 3178 | locations->SetOut(Location::SameAsFirstInput()); |
| 3179 | // Needed for imul on 32bits with 64bits output. |
| 3180 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3181 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3182 | break; |
| 3183 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3184 | case Primitive::kPrimFloat: |
| 3185 | case Primitive::kPrimDouble: { |
| 3186 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3187 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3188 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3189 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3190 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3191 | } else { |
| 3192 | locations->SetInAt(1, Location::Any()); |
| 3193 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3194 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3195 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3196 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3197 | |
| 3198 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3199 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3200 | } |
| 3201 | } |
| 3202 | |
| 3203 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3204 | LocationSummary* locations = mul->GetLocations(); |
| 3205 | Location first = locations->InAt(0); |
| 3206 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3207 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3208 | |
| 3209 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3210 | case Primitive::kPrimInt: |
| 3211 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3212 | // problems where the output may not be the same as the first operand. |
| 3213 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3214 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3215 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3216 | } else if (second.IsRegister()) { |
| 3217 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3218 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3219 | } else { |
| 3220 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3221 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3222 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3223 | } |
| 3224 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3225 | |
| 3226 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3227 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3228 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3229 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3230 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3231 | |
| 3232 | DCHECK_EQ(EAX, eax); |
| 3233 | DCHECK_EQ(EDX, edx); |
| 3234 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3235 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3236 | // output: in1 |
| 3237 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3238 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3239 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3240 | if (second.IsConstant()) { |
| 3241 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3242 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3243 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3244 | int32_t low_value = Low32Bits(value); |
| 3245 | int32_t high_value = High32Bits(value); |
| 3246 | Immediate low(low_value); |
| 3247 | Immediate high(high_value); |
| 3248 | |
| 3249 | __ movl(eax, high); |
| 3250 | // eax <- in1.lo * in2.hi |
| 3251 | __ imull(eax, in1_lo); |
| 3252 | // in1.hi <- in1.hi * in2.lo |
| 3253 | __ imull(in1_hi, low); |
| 3254 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3255 | __ addl(in1_hi, eax); |
| 3256 | // move in2_lo to eax to prepare for double precision |
| 3257 | __ movl(eax, low); |
| 3258 | // edx:eax <- in1.lo * in2.lo |
| 3259 | __ mull(in1_lo); |
| 3260 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3261 | __ addl(in1_hi, edx); |
| 3262 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3263 | __ movl(in1_lo, eax); |
| 3264 | } else if (second.IsRegisterPair()) { |
| 3265 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3266 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3267 | |
| 3268 | __ movl(eax, in2_hi); |
| 3269 | // eax <- in1.lo * in2.hi |
| 3270 | __ imull(eax, in1_lo); |
| 3271 | // in1.hi <- in1.hi * in2.lo |
| 3272 | __ imull(in1_hi, in2_lo); |
| 3273 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3274 | __ addl(in1_hi, eax); |
| 3275 | // move in1_lo to eax to prepare for double precision |
| 3276 | __ movl(eax, in1_lo); |
| 3277 | // edx:eax <- in1.lo * in2.lo |
| 3278 | __ mull(in2_lo); |
| 3279 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3280 | __ addl(in1_hi, edx); |
| 3281 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3282 | __ movl(in1_lo, eax); |
| 3283 | } else { |
| 3284 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3285 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3286 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3287 | |
| 3288 | __ movl(eax, in2_hi); |
| 3289 | // eax <- in1.lo * in2.hi |
| 3290 | __ imull(eax, in1_lo); |
| 3291 | // in1.hi <- in1.hi * in2.lo |
| 3292 | __ imull(in1_hi, in2_lo); |
| 3293 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3294 | __ addl(in1_hi, eax); |
| 3295 | // move in1_lo to eax to prepare for double precision |
| 3296 | __ movl(eax, in1_lo); |
| 3297 | // edx:eax <- in1.lo * in2.lo |
| 3298 | __ mull(in2_lo); |
| 3299 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3300 | __ addl(in1_hi, edx); |
| 3301 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3302 | __ movl(in1_lo, eax); |
| 3303 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3304 | |
| 3305 | break; |
| 3306 | } |
| 3307 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3308 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3309 | DCHECK(first.Equals(locations->Out())); |
| 3310 | if (second.IsFpuRegister()) { |
| 3311 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3312 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3313 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3314 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3315 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3316 | codegen_->LiteralFloatAddress( |
| 3317 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3318 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3319 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3320 | } else { |
| 3321 | DCHECK(second.IsStackSlot()); |
| 3322 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3323 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3324 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3325 | } |
| 3326 | |
| 3327 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3328 | DCHECK(first.Equals(locations->Out())); |
| 3329 | if (second.IsFpuRegister()) { |
| 3330 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3331 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3332 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3333 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3334 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3335 | codegen_->LiteralDoubleAddress( |
| 3336 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3337 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3338 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3339 | } else { |
| 3340 | DCHECK(second.IsDoubleStackSlot()); |
| 3341 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3342 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3343 | break; |
| 3344 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3345 | |
| 3346 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3347 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3348 | } |
| 3349 | } |
| 3350 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3351 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3352 | uint32_t temp_offset, |
| 3353 | uint32_t stack_adjustment, |
| 3354 | bool is_fp, |
| 3355 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3356 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3357 | DCHECK(!is_wide); |
| 3358 | if (is_fp) { |
| 3359 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3360 | } else { |
| 3361 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3362 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3363 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3364 | DCHECK(is_wide); |
| 3365 | if (is_fp) { |
| 3366 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3367 | } else { |
| 3368 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3369 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3370 | } else { |
| 3371 | // 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] | 3372 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3373 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3374 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3375 | if (is_fp) { |
| 3376 | __ flds(Address(ESP, temp_offset)); |
| 3377 | } else { |
| 3378 | __ filds(Address(ESP, temp_offset)); |
| 3379 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3380 | } else { |
| 3381 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3382 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3383 | if (is_fp) { |
| 3384 | __ fldl(Address(ESP, temp_offset)); |
| 3385 | } else { |
| 3386 | __ fildl(Address(ESP, temp_offset)); |
| 3387 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3388 | } |
| 3389 | } |
| 3390 | } |
| 3391 | |
| 3392 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3393 | Primitive::Type type = rem->GetResultType(); |
| 3394 | bool is_float = type == Primitive::kPrimFloat; |
| 3395 | size_t elem_size = Primitive::ComponentSize(type); |
| 3396 | LocationSummary* locations = rem->GetLocations(); |
| 3397 | Location first = locations->InAt(0); |
| 3398 | Location second = locations->InAt(1); |
| 3399 | Location out = locations->Out(); |
| 3400 | |
| 3401 | // Create stack space for 2 elements. |
| 3402 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3403 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3404 | |
| 3405 | // 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] | 3406 | const bool is_wide = !is_float; |
| 3407 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3408 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3409 | |
| 3410 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3411 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3412 | __ Bind(&retry); |
| 3413 | __ fprem(); |
| 3414 | |
| 3415 | // Move FP status to AX. |
| 3416 | __ fstsw(); |
| 3417 | |
| 3418 | // And see if the argument reduction is complete. This is signaled by the |
| 3419 | // C2 FPU flag bit set to 0. |
| 3420 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3421 | __ j(kNotEqual, &retry); |
| 3422 | |
| 3423 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3424 | // Store FP top of stack to real stack. |
| 3425 | if (is_float) { |
| 3426 | __ fsts(Address(ESP, 0)); |
| 3427 | } else { |
| 3428 | __ fstl(Address(ESP, 0)); |
| 3429 | } |
| 3430 | |
| 3431 | // Pop the 2 items from the FP stack. |
| 3432 | __ fucompp(); |
| 3433 | |
| 3434 | // Load the value from the stack into an XMM register. |
| 3435 | DCHECK(out.IsFpuRegister()) << out; |
| 3436 | if (is_float) { |
| 3437 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3438 | } else { |
| 3439 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3440 | } |
| 3441 | |
| 3442 | // And remove the temporary stack space we allocated. |
| 3443 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3444 | } |
| 3445 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3446 | |
| 3447 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3448 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3449 | |
| 3450 | LocationSummary* locations = instruction->GetLocations(); |
| 3451 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3452 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3453 | |
| 3454 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3455 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3456 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3457 | |
| 3458 | DCHECK(imm == 1 || imm == -1); |
| 3459 | |
| 3460 | if (instruction->IsRem()) { |
| 3461 | __ xorl(out_register, out_register); |
| 3462 | } else { |
| 3463 | __ movl(out_register, input_register); |
| 3464 | if (imm == -1) { |
| 3465 | __ negl(out_register); |
| 3466 | } |
| 3467 | } |
| 3468 | } |
| 3469 | |
| 3470 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3471 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3472 | LocationSummary* locations = instruction->GetLocations(); |
| 3473 | |
| 3474 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3475 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3476 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3477 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3478 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3479 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3480 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3481 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3482 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3483 | __ testl(input_register, input_register); |
| 3484 | __ cmovl(kGreaterEqual, num, input_register); |
| 3485 | int shift = CTZ(imm); |
| 3486 | __ sarl(num, Immediate(shift)); |
| 3487 | |
| 3488 | if (imm < 0) { |
| 3489 | __ negl(num); |
| 3490 | } |
| 3491 | |
| 3492 | __ movl(out_register, num); |
| 3493 | } |
| 3494 | |
| 3495 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3496 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3497 | |
| 3498 | LocationSummary* locations = instruction->GetLocations(); |
| 3499 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3500 | |
| 3501 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3502 | Register out = locations->Out().AsRegister<Register>(); |
| 3503 | Register num; |
| 3504 | Register edx; |
| 3505 | |
| 3506 | if (instruction->IsDiv()) { |
| 3507 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3508 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3509 | } else { |
| 3510 | edx = locations->Out().AsRegister<Register>(); |
| 3511 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3512 | } |
| 3513 | |
| 3514 | DCHECK_EQ(EAX, eax); |
| 3515 | DCHECK_EQ(EDX, edx); |
| 3516 | if (instruction->IsDiv()) { |
| 3517 | DCHECK_EQ(EAX, out); |
| 3518 | } else { |
| 3519 | DCHECK_EQ(EDX, out); |
| 3520 | } |
| 3521 | |
| 3522 | int64_t magic; |
| 3523 | int shift; |
| 3524 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3525 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3526 | // Save the numerator. |
| 3527 | __ movl(num, eax); |
| 3528 | |
| 3529 | // EAX = magic |
| 3530 | __ movl(eax, Immediate(magic)); |
| 3531 | |
| 3532 | // EDX:EAX = magic * numerator |
| 3533 | __ imull(num); |
| 3534 | |
| 3535 | if (imm > 0 && magic < 0) { |
| 3536 | // EDX += num |
| 3537 | __ addl(edx, num); |
| 3538 | } else if (imm < 0 && magic > 0) { |
| 3539 | __ subl(edx, num); |
| 3540 | } |
| 3541 | |
| 3542 | // Shift if needed. |
| 3543 | if (shift != 0) { |
| 3544 | __ sarl(edx, Immediate(shift)); |
| 3545 | } |
| 3546 | |
| 3547 | // EDX += 1 if EDX < 0 |
| 3548 | __ movl(eax, edx); |
| 3549 | __ shrl(edx, Immediate(31)); |
| 3550 | __ addl(edx, eax); |
| 3551 | |
| 3552 | if (instruction->IsRem()) { |
| 3553 | __ movl(eax, num); |
| 3554 | __ imull(edx, Immediate(imm)); |
| 3555 | __ subl(eax, edx); |
| 3556 | __ movl(edx, eax); |
| 3557 | } else { |
| 3558 | __ movl(eax, edx); |
| 3559 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3560 | } |
| 3561 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3562 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3563 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3564 | |
| 3565 | LocationSummary* locations = instruction->GetLocations(); |
| 3566 | Location out = locations->Out(); |
| 3567 | Location first = locations->InAt(0); |
| 3568 | Location second = locations->InAt(1); |
| 3569 | bool is_div = instruction->IsDiv(); |
| 3570 | |
| 3571 | switch (instruction->GetResultType()) { |
| 3572 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3573 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3574 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3575 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3576 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3577 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3578 | |
| 3579 | if (imm == 0) { |
| 3580 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3581 | } else if (imm == 1 || imm == -1) { |
| 3582 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3583 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3584 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3585 | } else { |
| 3586 | DCHECK(imm <= -2 || imm >= 2); |
| 3587 | GenerateDivRemWithAnyConstant(instruction); |
| 3588 | } |
| 3589 | } else { |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3590 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86( |
| 3591 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3592 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3593 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3594 | Register second_reg = second.AsRegister<Register>(); |
| 3595 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3596 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3597 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3598 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3599 | __ cmpl(second_reg, Immediate(-1)); |
| 3600 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3601 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3602 | // edx:eax <- sign-extended of eax |
| 3603 | __ cdq(); |
| 3604 | // eax = quotient, edx = remainder |
| 3605 | __ idivl(second_reg); |
| 3606 | __ Bind(slow_path->GetExitLabel()); |
| 3607 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3608 | break; |
| 3609 | } |
| 3610 | |
| 3611 | case Primitive::kPrimLong: { |
| 3612 | InvokeRuntimeCallingConvention calling_convention; |
| 3613 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3614 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3615 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3616 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3617 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3618 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3619 | |
| 3620 | if (is_div) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3621 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3622 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3623 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3624 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3625 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3626 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3627 | break; |
| 3628 | } |
| 3629 | |
| 3630 | default: |
| 3631 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3632 | } |
| 3633 | } |
| 3634 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3635 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3636 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3637 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3638 | : LocationSummary::kNoCall; |
| 3639 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3640 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3641 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3642 | case Primitive::kPrimInt: { |
| 3643 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3644 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3645 | locations->SetOut(Location::SameAsFirstInput()); |
| 3646 | // Intel uses edx:eax as the dividend. |
| 3647 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3648 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3649 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3650 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3651 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3652 | locations->AddTemp(Location::RequiresRegister()); |
| 3653 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3654 | break; |
| 3655 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3656 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3657 | InvokeRuntimeCallingConvention calling_convention; |
| 3658 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3659 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3660 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3661 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3662 | // Runtime helper puts the result in EAX, EDX. |
| 3663 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3664 | break; |
| 3665 | } |
| 3666 | case Primitive::kPrimFloat: |
| 3667 | case Primitive::kPrimDouble: { |
| 3668 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3669 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3670 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3671 | } else if (div->InputAt(1)->IsConstant()) { |
| 3672 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3673 | } else { |
| 3674 | locations->SetInAt(1, Location::Any()); |
| 3675 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3676 | locations->SetOut(Location::SameAsFirstInput()); |
| 3677 | break; |
| 3678 | } |
| 3679 | |
| 3680 | default: |
| 3681 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3682 | } |
| 3683 | } |
| 3684 | |
| 3685 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3686 | LocationSummary* locations = div->GetLocations(); |
| 3687 | Location first = locations->InAt(0); |
| 3688 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3689 | |
| 3690 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3691 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3692 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3693 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3694 | break; |
| 3695 | } |
| 3696 | |
| 3697 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3698 | if (second.IsFpuRegister()) { |
| 3699 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3700 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3701 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3702 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3703 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3704 | codegen_->LiteralFloatAddress( |
| 3705 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3706 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3707 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3708 | } else { |
| 3709 | DCHECK(second.IsStackSlot()); |
| 3710 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3711 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3712 | break; |
| 3713 | } |
| 3714 | |
| 3715 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3716 | if (second.IsFpuRegister()) { |
| 3717 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3718 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3719 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3720 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3721 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3722 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3723 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3724 | const_area->GetBaseMethodAddress(), |
| 3725 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3726 | } else { |
| 3727 | DCHECK(second.IsDoubleStackSlot()); |
| 3728 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3729 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3730 | break; |
| 3731 | } |
| 3732 | |
| 3733 | default: |
| 3734 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3735 | } |
| 3736 | } |
| 3737 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3738 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3739 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3740 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3741 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3742 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3743 | : LocationSummary::kNoCall; |
| 3744 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3745 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3746 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3747 | case Primitive::kPrimInt: { |
| 3748 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3749 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3750 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3751 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3752 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3753 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3754 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3755 | locations->AddTemp(Location::RequiresRegister()); |
| 3756 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3757 | break; |
| 3758 | } |
| 3759 | case Primitive::kPrimLong: { |
| 3760 | InvokeRuntimeCallingConvention calling_convention; |
| 3761 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3762 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3763 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3764 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3765 | // Runtime helper puts the result in EAX, EDX. |
| 3766 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3767 | break; |
| 3768 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3769 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3770 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3771 | locations->SetInAt(0, Location::Any()); |
| 3772 | locations->SetInAt(1, Location::Any()); |
| 3773 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3774 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3775 | break; |
| 3776 | } |
| 3777 | |
| 3778 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3779 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3780 | } |
| 3781 | } |
| 3782 | |
| 3783 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3784 | Primitive::Type type = rem->GetResultType(); |
| 3785 | switch (type) { |
| 3786 | case Primitive::kPrimInt: |
| 3787 | case Primitive::kPrimLong: { |
| 3788 | GenerateDivRemIntegral(rem); |
| 3789 | break; |
| 3790 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3791 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3792 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3793 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3794 | break; |
| 3795 | } |
| 3796 | default: |
| 3797 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3798 | } |
| 3799 | } |
| 3800 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3801 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3802 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3803 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3804 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3805 | case Primitive::kPrimByte: |
| 3806 | case Primitive::kPrimChar: |
| 3807 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3808 | case Primitive::kPrimInt: { |
| 3809 | locations->SetInAt(0, Location::Any()); |
| 3810 | break; |
| 3811 | } |
| 3812 | case Primitive::kPrimLong: { |
| 3813 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3814 | if (!instruction->IsConstant()) { |
| 3815 | locations->AddTemp(Location::RequiresRegister()); |
| 3816 | } |
| 3817 | break; |
| 3818 | } |
| 3819 | default: |
| 3820 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3821 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3822 | } |
| 3823 | |
| 3824 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3825 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3826 | codegen_->AddSlowPath(slow_path); |
| 3827 | |
| 3828 | LocationSummary* locations = instruction->GetLocations(); |
| 3829 | Location value = locations->InAt(0); |
| 3830 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3831 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3832 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3833 | case Primitive::kPrimByte: |
| 3834 | case Primitive::kPrimChar: |
| 3835 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3836 | case Primitive::kPrimInt: { |
| 3837 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3838 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3839 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3840 | } else if (value.IsStackSlot()) { |
| 3841 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3842 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3843 | } else { |
| 3844 | DCHECK(value.IsConstant()) << value; |
| 3845 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3846 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3847 | } |
| 3848 | } |
| 3849 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3850 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3851 | case Primitive::kPrimLong: { |
| 3852 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3853 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3854 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3855 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3856 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3857 | } else { |
| 3858 | DCHECK(value.IsConstant()) << value; |
| 3859 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3860 | __ jmp(slow_path->GetEntryLabel()); |
| 3861 | } |
| 3862 | } |
| 3863 | break; |
| 3864 | } |
| 3865 | default: |
| 3866 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3867 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3868 | } |
| 3869 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3870 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3871 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3872 | |
| 3873 | LocationSummary* locations = |
| 3874 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3875 | |
| 3876 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3877 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3878 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3879 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3880 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3881 | // The shift count needs to be in CL or a constant. |
| 3882 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3883 | locations->SetOut(Location::SameAsFirstInput()); |
| 3884 | break; |
| 3885 | } |
| 3886 | default: |
| 3887 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3888 | } |
| 3889 | } |
| 3890 | |
| 3891 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3892 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3893 | |
| 3894 | LocationSummary* locations = op->GetLocations(); |
| 3895 | Location first = locations->InAt(0); |
| 3896 | Location second = locations->InAt(1); |
| 3897 | DCHECK(first.Equals(locations->Out())); |
| 3898 | |
| 3899 | switch (op->GetResultType()) { |
| 3900 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3901 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3902 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3903 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3904 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3905 | DCHECK_EQ(ECX, second_reg); |
| 3906 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3907 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3908 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3909 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3910 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3911 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3912 | } |
| 3913 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3914 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3915 | if (shift == 0) { |
| 3916 | return; |
| 3917 | } |
| 3918 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3919 | if (op->IsShl()) { |
| 3920 | __ shll(first_reg, imm); |
| 3921 | } else if (op->IsShr()) { |
| 3922 | __ sarl(first_reg, imm); |
| 3923 | } else { |
| 3924 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3925 | } |
| 3926 | } |
| 3927 | break; |
| 3928 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3929 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3930 | if (second.IsRegister()) { |
| 3931 | Register second_reg = second.AsRegister<Register>(); |
| 3932 | DCHECK_EQ(ECX, second_reg); |
| 3933 | if (op->IsShl()) { |
| 3934 | GenerateShlLong(first, second_reg); |
| 3935 | } else if (op->IsShr()) { |
| 3936 | GenerateShrLong(first, second_reg); |
| 3937 | } else { |
| 3938 | GenerateUShrLong(first, second_reg); |
| 3939 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3940 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3941 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3942 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3943 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3944 | if (shift != 0) { |
| 3945 | if (op->IsShl()) { |
| 3946 | GenerateShlLong(first, shift); |
| 3947 | } else if (op->IsShr()) { |
| 3948 | GenerateShrLong(first, shift); |
| 3949 | } else { |
| 3950 | GenerateUShrLong(first, shift); |
| 3951 | } |
| 3952 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3953 | } |
| 3954 | break; |
| 3955 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3956 | default: |
| 3957 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3958 | } |
| 3959 | } |
| 3960 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3961 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3962 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3963 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3964 | if (shift == 1) { |
| 3965 | // This is just an addition. |
| 3966 | __ addl(low, low); |
| 3967 | __ adcl(high, high); |
| 3968 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3969 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3970 | codegen_->EmitParallelMoves( |
| 3971 | loc.ToLow(), |
| 3972 | loc.ToHigh(), |
| 3973 | Primitive::kPrimInt, |
| 3974 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3975 | loc.ToLow(), |
| 3976 | Primitive::kPrimInt); |
| 3977 | } else if (shift > 32) { |
| 3978 | // Low part becomes 0. High part is low part << (shift-32). |
| 3979 | __ movl(high, low); |
| 3980 | __ shll(high, Immediate(shift - 32)); |
| 3981 | __ xorl(low, low); |
| 3982 | } else { |
| 3983 | // Between 1 and 31. |
| 3984 | __ shld(high, low, Immediate(shift)); |
| 3985 | __ shll(low, Immediate(shift)); |
| 3986 | } |
| 3987 | } |
| 3988 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3989 | void InstructionCodeGeneratorX86::GenerateShlLong(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 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3992 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3993 | __ testl(shifter, Immediate(32)); |
| 3994 | __ j(kEqual, &done); |
| 3995 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3996 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3997 | __ Bind(&done); |
| 3998 | } |
| 3999 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4000 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 4001 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4002 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4003 | if (shift == 32) { |
| 4004 | // Need to copy the sign. |
| 4005 | DCHECK_NE(low, high); |
| 4006 | __ movl(low, high); |
| 4007 | __ sarl(high, Immediate(31)); |
| 4008 | } else if (shift > 32) { |
| 4009 | DCHECK_NE(low, high); |
| 4010 | // High part becomes sign. Low part is shifted by shift - 32. |
| 4011 | __ movl(low, high); |
| 4012 | __ sarl(high, Immediate(31)); |
| 4013 | __ sarl(low, Immediate(shift - 32)); |
| 4014 | } else { |
| 4015 | // Between 1 and 31. |
| 4016 | __ shrd(low, high, Immediate(shift)); |
| 4017 | __ sarl(high, Immediate(shift)); |
| 4018 | } |
| 4019 | } |
| 4020 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4021 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4022 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4023 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4024 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4025 | __ testl(shifter, Immediate(32)); |
| 4026 | __ j(kEqual, &done); |
| 4027 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4028 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 4029 | __ Bind(&done); |
| 4030 | } |
| 4031 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4032 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 4033 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4034 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4035 | if (shift == 32) { |
| 4036 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 4037 | codegen_->EmitParallelMoves( |
| 4038 | loc.ToHigh(), |
| 4039 | loc.ToLow(), |
| 4040 | Primitive::kPrimInt, |
| 4041 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4042 | loc.ToHigh(), |
| 4043 | Primitive::kPrimInt); |
| 4044 | } else if (shift > 32) { |
| 4045 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4046 | __ movl(low, high); |
| 4047 | __ shrl(low, Immediate(shift - 32)); |
| 4048 | __ xorl(high, high); |
| 4049 | } else { |
| 4050 | // Between 1 and 31. |
| 4051 | __ shrd(low, high, Immediate(shift)); |
| 4052 | __ shrl(high, Immediate(shift)); |
| 4053 | } |
| 4054 | } |
| 4055 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4056 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4057 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4058 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4059 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4060 | __ testl(shifter, Immediate(32)); |
| 4061 | __ j(kEqual, &done); |
| 4062 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4063 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4064 | __ Bind(&done); |
| 4065 | } |
| 4066 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4067 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4068 | LocationSummary* locations = |
| 4069 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 4070 | |
| 4071 | switch (ror->GetResultType()) { |
| 4072 | case Primitive::kPrimLong: |
| 4073 | // Add the temporary needed. |
| 4074 | locations->AddTemp(Location::RequiresRegister()); |
| 4075 | FALLTHROUGH_INTENDED; |
| 4076 | case Primitive::kPrimInt: |
| 4077 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4078 | // The shift count needs to be in CL (unless it is a constant). |
| 4079 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4080 | locations->SetOut(Location::SameAsFirstInput()); |
| 4081 | break; |
| 4082 | default: |
| 4083 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4084 | UNREACHABLE(); |
| 4085 | } |
| 4086 | } |
| 4087 | |
| 4088 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4089 | LocationSummary* locations = ror->GetLocations(); |
| 4090 | Location first = locations->InAt(0); |
| 4091 | Location second = locations->InAt(1); |
| 4092 | |
| 4093 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 4094 | Register first_reg = first.AsRegister<Register>(); |
| 4095 | if (second.IsRegister()) { |
| 4096 | Register second_reg = second.AsRegister<Register>(); |
| 4097 | __ rorl(first_reg, second_reg); |
| 4098 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4099 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4100 | __ rorl(first_reg, imm); |
| 4101 | } |
| 4102 | return; |
| 4103 | } |
| 4104 | |
| 4105 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 4106 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4107 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4108 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4109 | if (second.IsRegister()) { |
| 4110 | Register second_reg = second.AsRegister<Register>(); |
| 4111 | DCHECK_EQ(second_reg, ECX); |
| 4112 | __ movl(temp_reg, first_reg_hi); |
| 4113 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4114 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4115 | __ movl(temp_reg, first_reg_hi); |
| 4116 | __ testl(second_reg, Immediate(32)); |
| 4117 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4118 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4119 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4120 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4121 | if (shift_amt == 0) { |
| 4122 | // Already fine. |
| 4123 | return; |
| 4124 | } |
| 4125 | if (shift_amt == 32) { |
| 4126 | // Just swap. |
| 4127 | __ movl(temp_reg, first_reg_lo); |
| 4128 | __ movl(first_reg_lo, first_reg_hi); |
| 4129 | __ movl(first_reg_hi, temp_reg); |
| 4130 | return; |
| 4131 | } |
| 4132 | |
| 4133 | Immediate imm(shift_amt); |
| 4134 | // Save the constents of the low value. |
| 4135 | __ movl(temp_reg, first_reg_lo); |
| 4136 | |
| 4137 | // Shift right into low, feeding bits from high. |
| 4138 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4139 | |
| 4140 | // Shift right into high, feeding bits from the original low. |
| 4141 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4142 | |
| 4143 | // Swap if needed. |
| 4144 | if (shift_amt > 32) { |
| 4145 | __ movl(temp_reg, first_reg_lo); |
| 4146 | __ movl(first_reg_lo, first_reg_hi); |
| 4147 | __ movl(first_reg_hi, temp_reg); |
| 4148 | } |
| 4149 | } |
| 4150 | } |
| 4151 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4152 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4153 | HandleShift(shl); |
| 4154 | } |
| 4155 | |
| 4156 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4157 | HandleShift(shl); |
| 4158 | } |
| 4159 | |
| 4160 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4161 | HandleShift(shr); |
| 4162 | } |
| 4163 | |
| 4164 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4165 | HandleShift(shr); |
| 4166 | } |
| 4167 | |
| 4168 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4169 | HandleShift(ushr); |
| 4170 | } |
| 4171 | |
| 4172 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4173 | HandleShift(ushr); |
| 4174 | } |
| 4175 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4176 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4177 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4178 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4179 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4180 | if (instruction->IsStringAlloc()) { |
| 4181 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4182 | } else { |
| 4183 | InvokeRuntimeCallingConvention calling_convention; |
| 4184 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4185 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4186 | } |
| 4187 | |
| 4188 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4189 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4190 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4191 | if (instruction->IsStringAlloc()) { |
| 4192 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4193 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4194 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4195 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4196 | __ call(Address(temp, code_offset.Int32Value())); |
| 4197 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4198 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4199 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4200 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4201 | DCHECK(!codegen_->IsLeafMethod()); |
| 4202 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4203 | } |
| 4204 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4205 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 4206 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4207 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4208 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4209 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4210 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4211 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4212 | } |
| 4213 | |
| 4214 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4215 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4216 | // of poisoning the reference. |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4217 | codegen_->InvokeRuntime(kQuickAllocArrayResolved, instruction, instruction->GetDexPc()); |
| 4218 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4219 | DCHECK(!codegen_->IsLeafMethod()); |
| 4220 | } |
| 4221 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4222 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4223 | LocationSummary* locations = |
| 4224 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4225 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4226 | if (location.IsStackSlot()) { |
| 4227 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4228 | } else if (location.IsDoubleStackSlot()) { |
| 4229 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4230 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4231 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4232 | } |
| 4233 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4234 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4235 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4236 | } |
| 4237 | |
| 4238 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4239 | LocationSummary* locations = |
| 4240 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4241 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4242 | } |
| 4243 | |
| 4244 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4245 | } |
| 4246 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4247 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4248 | LocationSummary* locations = |
| 4249 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4250 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4251 | locations->SetOut(Location::RequiresRegister()); |
| 4252 | } |
| 4253 | |
| 4254 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4255 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4256 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4257 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4258 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4259 | __ movl(locations->Out().AsRegister<Register>(), |
| 4260 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4261 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4262 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4263 | instruction->GetIndex(), kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4264 | __ movl(locations->Out().AsRegister<Register>(), |
| 4265 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4266 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4267 | // temp = temp->GetImtEntryAt(method_offset); |
| 4268 | __ movl(locations->Out().AsRegister<Register>(), |
| 4269 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4270 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4271 | } |
| 4272 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4273 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4274 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4275 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4276 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4277 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4278 | } |
| 4279 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4280 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4281 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4282 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4283 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4284 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4285 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4286 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4287 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4288 | break; |
| 4289 | |
| 4290 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4291 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4292 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4293 | break; |
| 4294 | |
| 4295 | default: |
| 4296 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4297 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4298 | } |
| 4299 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4300 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4301 | LocationSummary* locations = |
| 4302 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4303 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4304 | locations->SetOut(Location::SameAsFirstInput()); |
| 4305 | } |
| 4306 | |
| 4307 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4308 | LocationSummary* locations = bool_not->GetLocations(); |
| 4309 | Location in = locations->InAt(0); |
| 4310 | Location out = locations->Out(); |
| 4311 | DCHECK(in.Equals(out)); |
| 4312 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4313 | } |
| 4314 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4315 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4316 | LocationSummary* locations = |
| 4317 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4318 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4319 | case Primitive::kPrimBoolean: |
| 4320 | case Primitive::kPrimByte: |
| 4321 | case Primitive::kPrimShort: |
| 4322 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4323 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4324 | case Primitive::kPrimLong: { |
| 4325 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4326 | locations->SetInAt(1, Location::Any()); |
| 4327 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4328 | break; |
| 4329 | } |
| 4330 | case Primitive::kPrimFloat: |
| 4331 | case Primitive::kPrimDouble: { |
| 4332 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4333 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4334 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4335 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4336 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4337 | } else { |
| 4338 | locations->SetInAt(1, Location::Any()); |
| 4339 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4340 | locations->SetOut(Location::RequiresRegister()); |
| 4341 | break; |
| 4342 | } |
| 4343 | default: |
| 4344 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4345 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4346 | } |
| 4347 | |
| 4348 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4349 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4350 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4351 | Location left = locations->InAt(0); |
| 4352 | Location right = locations->InAt(1); |
| 4353 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4354 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4355 | Condition less_cond = kLess; |
| 4356 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4357 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4358 | case Primitive::kPrimBoolean: |
| 4359 | case Primitive::kPrimByte: |
| 4360 | case Primitive::kPrimShort: |
| 4361 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4362 | case Primitive::kPrimInt: { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4363 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4364 | break; |
| 4365 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4366 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4367 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4368 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4369 | int32_t val_low = 0; |
| 4370 | int32_t val_high = 0; |
| 4371 | bool right_is_const = false; |
| 4372 | |
| 4373 | if (right.IsConstant()) { |
| 4374 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4375 | right_is_const = true; |
| 4376 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4377 | val_low = Low32Bits(val); |
| 4378 | val_high = High32Bits(val); |
| 4379 | } |
| 4380 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4381 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4382 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4383 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4384 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4385 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4386 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4387 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4388 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4389 | __ j(kLess, &less); // Signed compare. |
| 4390 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4391 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4392 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4393 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4394 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4395 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4396 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4397 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4398 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4399 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4400 | break; |
| 4401 | } |
| 4402 | case Primitive::kPrimFloat: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4403 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4404 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4405 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4406 | break; |
| 4407 | } |
| 4408 | case Primitive::kPrimDouble: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4409 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4410 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4411 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4412 | break; |
| 4413 | } |
| 4414 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4415 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4416 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4417 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4418 | __ movl(out, Immediate(0)); |
| 4419 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4420 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4421 | |
| 4422 | __ Bind(&greater); |
| 4423 | __ movl(out, Immediate(1)); |
| 4424 | __ jmp(&done); |
| 4425 | |
| 4426 | __ Bind(&less); |
| 4427 | __ movl(out, Immediate(-1)); |
| 4428 | |
| 4429 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4430 | } |
| 4431 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4432 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4433 | LocationSummary* locations = |
| 4434 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4435 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4436 | locations->SetInAt(i, Location::Any()); |
| 4437 | } |
| 4438 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4439 | } |
| 4440 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4441 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4442 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4443 | } |
| 4444 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4445 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4446 | /* |
| 4447 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4448 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4449 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4450 | */ |
| 4451 | switch (kind) { |
| 4452 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4453 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4454 | break; |
| 4455 | } |
| 4456 | case MemBarrierKind::kAnyStore: |
| 4457 | case MemBarrierKind::kLoadAny: |
| 4458 | case MemBarrierKind::kStoreStore: { |
| 4459 | // nop |
| 4460 | break; |
| 4461 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4462 | case MemBarrierKind::kNTStoreStore: |
| 4463 | // Non-Temporal Store/Store needs an explicit fence. |
| 4464 | MemoryFence(/* non-temporal */ true); |
| 4465 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4466 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4467 | } |
| 4468 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4469 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4470 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4471 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4472 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4473 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4474 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4475 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4476 | Register temp) { |
| 4477 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4478 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4479 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4480 | return location.AsRegister<Register>(); |
| 4481 | } |
| 4482 | // For intrinsics we allow any location, so it may be on the stack. |
| 4483 | if (!location.IsRegister()) { |
| 4484 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4485 | return temp; |
| 4486 | } |
| 4487 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4488 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4489 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4490 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4491 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4492 | if (slow_path != nullptr) { |
| 4493 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4494 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4495 | __ movl(temp, Address(ESP, stack_offset)); |
| 4496 | return temp; |
| 4497 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4498 | } |
| 4499 | return location.AsRegister<Register>(); |
| 4500 | } |
| 4501 | |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4502 | Location CodeGeneratorX86::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 4503 | Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4504 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4505 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4506 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4507 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4508 | uint32_t offset = |
| 4509 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4510 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4511 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4512 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4513 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4514 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4515 | break; |
| 4516 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4517 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4518 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4519 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4520 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4521 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4522 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4523 | // Bind a new fixup label at the end of the "movl" insn. |
| 4524 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4525 | __ Bind(NewPcRelativeDexCacheArrayPatch( |
| 4526 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(), |
| 4527 | invoke->GetDexFileForPcRelativeDexCache(), |
| 4528 | offset)); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4529 | break; |
| 4530 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4531 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4532 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4533 | Register method_reg; |
| 4534 | Register reg = temp.AsRegister<Register>(); |
| 4535 | if (current_method.IsRegister()) { |
| 4536 | method_reg = current_method.AsRegister<Register>(); |
| 4537 | } else { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4538 | DCHECK(invoke->GetLocations()->Intrinsified()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4539 | DCHECK(!current_method.IsValid()); |
| 4540 | method_reg = reg; |
| 4541 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4542 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4543 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4544 | __ movl(reg, Address(method_reg, |
| 4545 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 4546 | // temp = temp[index_in_cache]; |
| 4547 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 4548 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4549 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4550 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4551 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4552 | } |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4553 | return callee_method; |
| 4554 | } |
| 4555 | |
| 4556 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4557 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4558 | |
| 4559 | switch (invoke->GetCodePtrLocation()) { |
| 4560 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4561 | __ call(GetFrameEntryLabel()); |
| 4562 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4563 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4564 | // (callee_method + offset_of_quick_compiled_code)() |
| 4565 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4566 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4567 | kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4568 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4569 | } |
| 4570 | |
| 4571 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4572 | } |
| 4573 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4574 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4575 | Register temp = temp_in.AsRegister<Register>(); |
| 4576 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4577 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4578 | |
| 4579 | // Use the calling convention instead of the location of the receiver, as |
| 4580 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4581 | // slow path, the arguments have been moved to the right place, so here we are |
| 4582 | // guaranteed that the receiver is the first register of the calling convention. |
| 4583 | InvokeDexCallingConvention calling_convention; |
| 4584 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4585 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4586 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4587 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4588 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4589 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4590 | // emit a read barrier for the previous class reference load. |
| 4591 | // However this is not required in practice, as this is an |
| 4592 | // intermediate/temporary reference and because the current |
| 4593 | // concurrent copying collector keeps the from-space memory |
| 4594 | // intact/accessible until the end of the marking phase (the |
| 4595 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4596 | __ MaybeUnpoisonHeapReference(temp); |
| 4597 | // temp = temp->GetMethodAt(method_offset); |
| 4598 | __ movl(temp, Address(temp, method_offset)); |
| 4599 | // call temp->GetEntryPoint(); |
| 4600 | __ call(Address( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4601 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4602 | } |
| 4603 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4604 | void CodeGeneratorX86::RecordSimplePatch() { |
| 4605 | if (GetCompilerOptions().GetIncludePatchInformation()) { |
| 4606 | simple_patches_.emplace_back(); |
| 4607 | __ Bind(&simple_patches_.back()); |
| 4608 | } |
| 4609 | } |
| 4610 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4611 | void CodeGeneratorX86::RecordBootStringPatch(HLoadString* load_string) { |
| 4612 | DCHECK(GetCompilerOptions().IsBootImage()); |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4613 | HX86ComputeBaseMethodAddress* address = nullptr; |
| 4614 | if (GetCompilerOptions().GetCompilePic()) { |
| 4615 | address = load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4616 | } else { |
| 4617 | DCHECK_EQ(load_string->InputCount(), 0u); |
| 4618 | } |
| 4619 | string_patches_.emplace_back(address, |
| 4620 | load_string->GetDexFile(), |
| 4621 | load_string->GetStringIndex().index_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4622 | __ Bind(&string_patches_.back().label); |
| 4623 | } |
| 4624 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4625 | void CodeGeneratorX86::RecordBootTypePatch(HLoadClass* load_class) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4626 | HX86ComputeBaseMethodAddress* address = nullptr; |
| 4627 | if (GetCompilerOptions().GetCompilePic()) { |
| 4628 | address = load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4629 | } else { |
| 4630 | DCHECK_EQ(load_class->InputCount(), 0u); |
| 4631 | } |
| 4632 | boot_image_type_patches_.emplace_back(address, |
| 4633 | load_class->GetDexFile(), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4634 | load_class->GetTypeIndex().index_); |
| 4635 | __ Bind(&boot_image_type_patches_.back().label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4636 | } |
| 4637 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4638 | Label* CodeGeneratorX86::NewTypeBssEntryPatch(HLoadClass* load_class) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4639 | HX86ComputeBaseMethodAddress* address = |
| 4640 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4641 | type_bss_entry_patches_.emplace_back( |
| 4642 | address, load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4643 | return &type_bss_entry_patches_.back().label; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4644 | } |
| 4645 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4646 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
| 4647 | DCHECK(!GetCompilerOptions().IsBootImage()); |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4648 | HX86ComputeBaseMethodAddress* address = |
| 4649 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4650 | string_patches_.emplace_back( |
| 4651 | address, load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4652 | return &string_patches_.back().label; |
| 4653 | } |
| 4654 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4655 | Label* CodeGeneratorX86::NewPcRelativeDexCacheArrayPatch( |
| 4656 | HX86ComputeBaseMethodAddress* method_address, |
| 4657 | const DexFile& dex_file, |
| 4658 | uint32_t element_offset) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4659 | // Add the patch entry and bind its label at the end of the instruction. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4660 | pc_relative_dex_cache_patches_.emplace_back(method_address, dex_file, element_offset); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4661 | return &pc_relative_dex_cache_patches_.back().label; |
| 4662 | } |
| 4663 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4664 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 4665 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4666 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 4667 | |
| 4668 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 4669 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4670 | const ArenaDeque<X86PcRelativePatchInfo>& infos, |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4671 | ArenaVector<LinkerPatch>* linker_patches) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4672 | for (const X86PcRelativePatchInfo& info : infos) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4673 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4674 | linker_patches->push_back(Factory( |
| 4675 | literal_offset, &info.dex_file, GetMethodAddressOffset(info.method_address), info.index)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4676 | } |
| 4677 | } |
| 4678 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4679 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4680 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4681 | size_t size = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4682 | pc_relative_dex_cache_patches_.size() + |
| 4683 | simple_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4684 | string_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4685 | boot_image_type_patches_.size() + |
| 4686 | type_bss_entry_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4687 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4688 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 4689 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4690 | for (const Label& label : simple_patches_) { |
| 4691 | uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4692 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 4693 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4694 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4695 | DCHECK(boot_image_type_patches_.empty()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4696 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(string_patches_, linker_patches); |
| 4697 | } else if (GetCompilerOptions().GetCompilePic()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4698 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(boot_image_type_patches_, |
| 4699 | linker_patches); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4700 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(string_patches_, linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4701 | } else { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4702 | for (const PatchInfo<Label>& info : boot_image_type_patches_) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4703 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4704 | 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] | 4705 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4706 | for (const PatchInfo<Label>& info : string_patches_) { |
| 4707 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4708 | linker_patches->push_back( |
| 4709 | LinkerPatch::StringPatch(literal_offset, &info.dex_file, info.index)); |
| 4710 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4711 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4712 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 4713 | linker_patches); |
| 4714 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4715 | } |
| 4716 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4717 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4718 | Register card, |
| 4719 | Register object, |
| 4720 | Register value, |
| 4721 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4722 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4723 | if (value_can_be_null) { |
| 4724 | __ testl(value, value); |
| 4725 | __ j(kEqual, &is_null); |
| 4726 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4727 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4728 | __ movl(temp, object); |
| 4729 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4730 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4731 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4732 | if (value_can_be_null) { |
| 4733 | __ Bind(&is_null); |
| 4734 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4735 | } |
| 4736 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4737 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4738 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4739 | |
| 4740 | bool object_field_get_with_read_barrier = |
| 4741 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4742 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4743 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4744 | kEmitCompilerReadBarrier ? |
| 4745 | LocationSummary::kCallOnSlowPath : |
| 4746 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4747 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4748 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4749 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4750 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4751 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4752 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4753 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4754 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4755 | // The output overlaps in case of long: we don't want the low move |
| 4756 | // to overwrite the object's location. Likewise, in the case of |
| 4757 | // an object field get with read barriers enabled, we do not want |
| 4758 | // the move to overwrite the object's location, as we need it to emit |
| 4759 | // the read barrier. |
| 4760 | locations->SetOut( |
| 4761 | Location::RequiresRegister(), |
| 4762 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4763 | Location::kOutputOverlap : |
| 4764 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4765 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4766 | |
| 4767 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4768 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4769 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4770 | // load the temp into the XMM and then copy the XMM into the |
| 4771 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4772 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4773 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4774 | } |
| 4775 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4776 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4777 | const FieldInfo& field_info) { |
| 4778 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4779 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4780 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4781 | Location base_loc = locations->InAt(0); |
| 4782 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4783 | Location out = locations->Out(); |
| 4784 | bool is_volatile = field_info.IsVolatile(); |
| 4785 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4786 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4787 | |
| 4788 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4789 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4790 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4791 | break; |
| 4792 | } |
| 4793 | |
| 4794 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4795 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4796 | break; |
| 4797 | } |
| 4798 | |
| 4799 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4800 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4801 | break; |
| 4802 | } |
| 4803 | |
| 4804 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4805 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4806 | break; |
| 4807 | } |
| 4808 | |
| 4809 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4810 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4811 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4812 | |
| 4813 | case Primitive::kPrimNot: { |
| 4814 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4815 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4816 | // Note that a potential implicit null check is handled in this |
| 4817 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4818 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4819 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4820 | if (is_volatile) { |
| 4821 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4822 | } |
| 4823 | } else { |
| 4824 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4825 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4826 | if (is_volatile) { |
| 4827 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4828 | } |
| 4829 | // If read barriers are enabled, emit read barriers other than |
| 4830 | // Baker's using a slow path (and also unpoison the loaded |
| 4831 | // reference, if heap poisoning is enabled). |
| 4832 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4833 | } |
| 4834 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4835 | } |
| 4836 | |
| 4837 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4838 | if (is_volatile) { |
| 4839 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4840 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4841 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4842 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4843 | __ psrlq(temp, Immediate(32)); |
| 4844 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4845 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4846 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4847 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4848 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4849 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4850 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4851 | break; |
| 4852 | } |
| 4853 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4854 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4855 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4856 | break; |
| 4857 | } |
| 4858 | |
| 4859 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4860 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4861 | break; |
| 4862 | } |
| 4863 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4864 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4865 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4866 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4867 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4868 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4869 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4870 | // Potential implicit null checks, in the case of reference or |
| 4871 | // long fields, are handled in the previous switch statement. |
| 4872 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4873 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4874 | } |
| 4875 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4876 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4877 | if (field_type == Primitive::kPrimNot) { |
| 4878 | // Memory barriers, in the case of references, are also handled |
| 4879 | // in the previous switch statement. |
| 4880 | } else { |
| 4881 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4882 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4883 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4884 | } |
| 4885 | |
| 4886 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4887 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4888 | |
| 4889 | LocationSummary* locations = |
| 4890 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4891 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4892 | bool is_volatile = field_info.IsVolatile(); |
| 4893 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4894 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4895 | || (field_type == Primitive::kPrimByte); |
| 4896 | |
| 4897 | // The register allocator does not support multiple |
| 4898 | // inputs that die at entry with one in a specific register. |
| 4899 | if (is_byte_type) { |
| 4900 | // Ensure the value is in a byte register. |
| 4901 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4902 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4903 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4904 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4905 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4906 | } else { |
| 4907 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4908 | } |
| 4909 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4910 | // 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] | 4911 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4912 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4913 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4914 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4915 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4916 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4917 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4918 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4919 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4920 | } else { |
| 4921 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4922 | |
| 4923 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4924 | // Temporary registers for the write barrier. |
| 4925 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4926 | // Ensure the card is in a byte register. |
| 4927 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4928 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4929 | } |
| 4930 | } |
| 4931 | |
| 4932 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4933 | const FieldInfo& field_info, |
| 4934 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4935 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4936 | |
| 4937 | LocationSummary* locations = instruction->GetLocations(); |
| 4938 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4939 | Location value = locations->InAt(1); |
| 4940 | bool is_volatile = field_info.IsVolatile(); |
| 4941 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4942 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4943 | bool needs_write_barrier = |
| 4944 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4945 | |
| 4946 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4947 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4948 | } |
| 4949 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4950 | bool maybe_record_implicit_null_check_done = false; |
| 4951 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4952 | switch (field_type) { |
| 4953 | case Primitive::kPrimBoolean: |
| 4954 | case Primitive::kPrimByte: { |
| 4955 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4956 | break; |
| 4957 | } |
| 4958 | |
| 4959 | case Primitive::kPrimShort: |
| 4960 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4961 | if (value.IsConstant()) { |
| 4962 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4963 | __ movw(Address(base, offset), Immediate(v)); |
| 4964 | } else { |
| 4965 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4966 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4967 | break; |
| 4968 | } |
| 4969 | |
| 4970 | case Primitive::kPrimInt: |
| 4971 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4972 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4973 | // Note that in the case where `value` is a null reference, |
| 4974 | // we do not enter this block, as the reference does not |
| 4975 | // need poisoning. |
| 4976 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4977 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4978 | __ movl(temp, value.AsRegister<Register>()); |
| 4979 | __ PoisonHeapReference(temp); |
| 4980 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4981 | } else if (value.IsConstant()) { |
| 4982 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4983 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4984 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 4985 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4986 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4987 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4988 | break; |
| 4989 | } |
| 4990 | |
| 4991 | case Primitive::kPrimLong: { |
| 4992 | if (is_volatile) { |
| 4993 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4994 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4995 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4996 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4997 | __ punpckldq(temp1, temp2); |
| 4998 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4999 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5000 | } else if (value.IsConstant()) { |
| 5001 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5002 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5003 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5004 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5005 | } else { |
| 5006 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5007 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5008 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 5009 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5010 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5011 | break; |
| 5012 | } |
| 5013 | |
| 5014 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5015 | if (value.IsConstant()) { |
| 5016 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5017 | __ movl(Address(base, offset), Immediate(v)); |
| 5018 | } else { |
| 5019 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5020 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5021 | break; |
| 5022 | } |
| 5023 | |
| 5024 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5025 | if (value.IsConstant()) { |
| 5026 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5027 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5028 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5029 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 5030 | maybe_record_implicit_null_check_done = true; |
| 5031 | } else { |
| 5032 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5033 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5034 | break; |
| 5035 | } |
| 5036 | |
| 5037 | case Primitive::kPrimVoid: |
| 5038 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5039 | UNREACHABLE(); |
| 5040 | } |
| 5041 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5042 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5043 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5044 | } |
| 5045 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5046 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5047 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5048 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5049 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5050 | } |
| 5051 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5052 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5053 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5054 | } |
| 5055 | } |
| 5056 | |
| 5057 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5058 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5059 | } |
| 5060 | |
| 5061 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5062 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5063 | } |
| 5064 | |
| 5065 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5066 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5067 | } |
| 5068 | |
| 5069 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5070 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5071 | } |
| 5072 | |
| 5073 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5074 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5075 | } |
| 5076 | |
| 5077 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5078 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5079 | } |
| 5080 | |
| 5081 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5082 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5083 | } |
| 5084 | |
| 5085 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5086 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5087 | } |
| 5088 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5089 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 5090 | HUnresolvedInstanceFieldGet* instruction) { |
| 5091 | FieldAccessCallingConventionX86 calling_convention; |
| 5092 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5093 | instruction, instruction->GetFieldType(), calling_convention); |
| 5094 | } |
| 5095 | |
| 5096 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 5097 | HUnresolvedInstanceFieldGet* instruction) { |
| 5098 | FieldAccessCallingConventionX86 calling_convention; |
| 5099 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5100 | instruction->GetFieldType(), |
| 5101 | instruction->GetFieldIndex(), |
| 5102 | instruction->GetDexPc(), |
| 5103 | calling_convention); |
| 5104 | } |
| 5105 | |
| 5106 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 5107 | HUnresolvedInstanceFieldSet* instruction) { |
| 5108 | FieldAccessCallingConventionX86 calling_convention; |
| 5109 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5110 | instruction, instruction->GetFieldType(), calling_convention); |
| 5111 | } |
| 5112 | |
| 5113 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 5114 | HUnresolvedInstanceFieldSet* instruction) { |
| 5115 | FieldAccessCallingConventionX86 calling_convention; |
| 5116 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5117 | instruction->GetFieldType(), |
| 5118 | instruction->GetFieldIndex(), |
| 5119 | instruction->GetDexPc(), |
| 5120 | calling_convention); |
| 5121 | } |
| 5122 | |
| 5123 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 5124 | HUnresolvedStaticFieldGet* instruction) { |
| 5125 | FieldAccessCallingConventionX86 calling_convention; |
| 5126 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5127 | instruction, instruction->GetFieldType(), calling_convention); |
| 5128 | } |
| 5129 | |
| 5130 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 5131 | HUnresolvedStaticFieldGet* instruction) { |
| 5132 | FieldAccessCallingConventionX86 calling_convention; |
| 5133 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5134 | instruction->GetFieldType(), |
| 5135 | instruction->GetFieldIndex(), |
| 5136 | instruction->GetDexPc(), |
| 5137 | calling_convention); |
| 5138 | } |
| 5139 | |
| 5140 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 5141 | HUnresolvedStaticFieldSet* instruction) { |
| 5142 | FieldAccessCallingConventionX86 calling_convention; |
| 5143 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5144 | instruction, instruction->GetFieldType(), calling_convention); |
| 5145 | } |
| 5146 | |
| 5147 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 5148 | HUnresolvedStaticFieldSet* instruction) { |
| 5149 | FieldAccessCallingConventionX86 calling_convention; |
| 5150 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5151 | instruction->GetFieldType(), |
| 5152 | instruction->GetFieldIndex(), |
| 5153 | instruction->GetDexPc(), |
| 5154 | calling_convention); |
| 5155 | } |
| 5156 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5157 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5158 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5159 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5160 | ? Location::RequiresRegister() |
| 5161 | : Location::Any(); |
| 5162 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5163 | } |
| 5164 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5165 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5166 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5167 | return; |
| 5168 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5169 | LocationSummary* locations = instruction->GetLocations(); |
| 5170 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5171 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5172 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5173 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5174 | } |
| 5175 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5176 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5177 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5178 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5179 | |
| 5180 | LocationSummary* locations = instruction->GetLocations(); |
| 5181 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5182 | |
| 5183 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5184 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5185 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5186 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5187 | } else { |
| 5188 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5189 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5190 | __ jmp(slow_path->GetEntryLabel()); |
| 5191 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5192 | } |
| 5193 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5194 | } |
| 5195 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5196 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5197 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5198 | } |
| 5199 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5200 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5201 | bool object_array_get_with_read_barrier = |
| 5202 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5203 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5204 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5205 | object_array_get_with_read_barrier ? |
| 5206 | LocationSummary::kCallOnSlowPath : |
| 5207 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5208 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5209 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5210 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5211 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5212 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5213 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5214 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5215 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5216 | // The output overlaps in case of long: we don't want the low move |
| 5217 | // to overwrite the array's location. Likewise, in the case of an |
| 5218 | // object array get with read barriers enabled, we do not want the |
| 5219 | // move to overwrite the array's location, as we need it to emit |
| 5220 | // the read barrier. |
| 5221 | locations->SetOut( |
| 5222 | Location::RequiresRegister(), |
| 5223 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 5224 | Location::kOutputOverlap : |
| 5225 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5226 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5227 | } |
| 5228 | |
| 5229 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5230 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5231 | Location obj_loc = locations->InAt(0); |
| 5232 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5233 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5234 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5235 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5236 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5237 | Primitive::Type type = instruction->GetType(); |
| 5238 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5239 | case Primitive::kPrimBoolean: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5240 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5241 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5242 | break; |
| 5243 | } |
| 5244 | |
| 5245 | case Primitive::kPrimByte: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5246 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5247 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5248 | break; |
| 5249 | } |
| 5250 | |
| 5251 | case Primitive::kPrimShort: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5252 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5253 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5254 | break; |
| 5255 | } |
| 5256 | |
| 5257 | case Primitive::kPrimChar: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5258 | Register out = out_loc.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5259 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5260 | // Branch cases into compressed and uncompressed for each index's type. |
| 5261 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5262 | NearLabel done, not_compressed; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5263 | __ testl(Address(obj, count_offset), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5264 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5265 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5266 | "Expecting 0=compressed, 1=uncompressed"); |
| 5267 | __ j(kNotZero, ¬_compressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5268 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5269 | __ jmp(&done); |
| 5270 | __ Bind(¬_compressed); |
| 5271 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5272 | __ Bind(&done); |
| 5273 | } else { |
| 5274 | // Common case for charAt of array of char or when string compression's |
| 5275 | // feature is turned off. |
| 5276 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5277 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5278 | break; |
| 5279 | } |
| 5280 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5281 | case Primitive::kPrimInt: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5282 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5283 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5284 | break; |
| 5285 | } |
| 5286 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5287 | case Primitive::kPrimNot: { |
| 5288 | static_assert( |
| 5289 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5290 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5291 | // /* HeapReference<Object> */ out = |
| 5292 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5293 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5294 | // Note that a potential implicit null check is handled in this |
| 5295 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5296 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5297 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5298 | } else { |
| 5299 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5300 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5301 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5302 | // If read barriers are enabled, emit read barriers other than |
| 5303 | // Baker's using a slow path (and also unpoison the loaded |
| 5304 | // reference, if heap poisoning is enabled). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5305 | if (index.IsConstant()) { |
| 5306 | uint32_t offset = |
| 5307 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5308 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5309 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5310 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5311 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5312 | } |
| 5313 | } |
| 5314 | break; |
| 5315 | } |
| 5316 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5317 | case Primitive::kPrimLong: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5318 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5319 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 5320 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 5321 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5322 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 5323 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5324 | break; |
| 5325 | } |
| 5326 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5327 | case Primitive::kPrimFloat: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5328 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5329 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5330 | break; |
| 5331 | } |
| 5332 | |
| 5333 | case Primitive::kPrimDouble: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5334 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5335 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5336 | break; |
| 5337 | } |
| 5338 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5339 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5340 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5341 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5342 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5343 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5344 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5345 | // Potential implicit null checks, in the case of reference or |
| 5346 | // long arrays, are handled in the previous switch statement. |
| 5347 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5348 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5349 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5350 | } |
| 5351 | |
| 5352 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5353 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5354 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5355 | bool needs_write_barrier = |
| 5356 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5357 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5358 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5359 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5360 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5361 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5362 | LocationSummary::kCallOnSlowPath : |
| 5363 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5364 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5365 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5366 | || (value_type == Primitive::kPrimByte); |
| 5367 | // We need the inputs to be different than the output in case of long operation. |
| 5368 | // In case of a byte operation, the register allocator does not support multiple |
| 5369 | // inputs that die at entry with one in a specific register. |
| 5370 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5371 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5372 | if (is_byte_type) { |
| 5373 | // Ensure the value is in a byte register. |
| 5374 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5375 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5376 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5377 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5378 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5379 | } |
| 5380 | if (needs_write_barrier) { |
| 5381 | // Temporary registers for the write barrier. |
| 5382 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5383 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5384 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5385 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5386 | } |
| 5387 | |
| 5388 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5389 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5390 | Location array_loc = locations->InAt(0); |
| 5391 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5392 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5393 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5394 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5395 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5396 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5397 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5398 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5399 | bool needs_write_barrier = |
| 5400 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5401 | |
| 5402 | switch (value_type) { |
| 5403 | case Primitive::kPrimBoolean: |
| 5404 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5405 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5406 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5407 | if (value.IsRegister()) { |
| 5408 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5409 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5410 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5411 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5412 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5413 | break; |
| 5414 | } |
| 5415 | |
| 5416 | case Primitive::kPrimShort: |
| 5417 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5418 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5419 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5420 | if (value.IsRegister()) { |
| 5421 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5422 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5423 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5424 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5425 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5426 | break; |
| 5427 | } |
| 5428 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5429 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5430 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5431 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5432 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5433 | if (!value.IsRegister()) { |
| 5434 | // Just setting null. |
| 5435 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5436 | DCHECK(value.IsConstant()) << value; |
| 5437 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5438 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5439 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5440 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5441 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5442 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5443 | |
| 5444 | DCHECK(needs_write_barrier); |
| 5445 | Register register_value = value.AsRegister<Register>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5446 | // We cannot use a NearLabel for `done`, as its range may be too |
| 5447 | // short when Baker read barriers are enabled. |
| 5448 | Label done; |
| 5449 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5450 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5451 | Location temp_loc = locations->GetTemp(0); |
| 5452 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5453 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5454 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5455 | codegen_->AddSlowPath(slow_path); |
| 5456 | if (instruction->GetValueCanBeNull()) { |
| 5457 | __ testl(register_value, register_value); |
| 5458 | __ j(kNotEqual, ¬_null); |
| 5459 | __ movl(address, Immediate(0)); |
| 5460 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5461 | __ jmp(&done); |
| 5462 | __ Bind(¬_null); |
| 5463 | } |
| 5464 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5465 | // Note that when Baker read barriers are enabled, the type |
| 5466 | // checks are performed without read barriers. This is fine, |
| 5467 | // even in the case where a class object is in the from-space |
| 5468 | // after the flip, as a comparison involving such a type would |
| 5469 | // not produce a false positive; it may of course produce a |
| 5470 | // false negative, in which case we would take the ArraySet |
| 5471 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5472 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5473 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5474 | __ movl(temp, Address(array, class_offset)); |
| 5475 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5476 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5477 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5478 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5479 | __ movl(temp, Address(temp, component_offset)); |
| 5480 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5481 | // nor the object reference in `register_value->klass`, as |
| 5482 | // we are comparing two poisoned references. |
| 5483 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5484 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5485 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5486 | __ j(kEqual, &do_put); |
| 5487 | // If heap poisoning is enabled, the `temp` reference has |
| 5488 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5489 | __ MaybeUnpoisonHeapReference(temp); |
| 5490 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5491 | // If heap poisoning is enabled, no need to unpoison the |
| 5492 | // heap reference loaded below, as it is only used for a |
| 5493 | // comparison with null. |
| 5494 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5495 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5496 | __ Bind(&do_put); |
| 5497 | } else { |
| 5498 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5499 | } |
| 5500 | } |
| 5501 | |
| 5502 | if (kPoisonHeapReferences) { |
| 5503 | __ movl(temp, register_value); |
| 5504 | __ PoisonHeapReference(temp); |
| 5505 | __ movl(address, temp); |
| 5506 | } else { |
| 5507 | __ movl(address, register_value); |
| 5508 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5509 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5510 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5511 | } |
| 5512 | |
| 5513 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5514 | codegen_->MarkGCCard( |
| 5515 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5516 | __ Bind(&done); |
| 5517 | |
| 5518 | if (slow_path != nullptr) { |
| 5519 | __ Bind(slow_path->GetExitLabel()); |
| 5520 | } |
| 5521 | |
| 5522 | break; |
| 5523 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5524 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5525 | case Primitive::kPrimInt: { |
| 5526 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5527 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5528 | if (value.IsRegister()) { |
| 5529 | __ movl(address, value.AsRegister<Register>()); |
| 5530 | } else { |
| 5531 | DCHECK(value.IsConstant()) << value; |
| 5532 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5533 | __ movl(address, Immediate(v)); |
| 5534 | } |
| 5535 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5536 | break; |
| 5537 | } |
| 5538 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5539 | case Primitive::kPrimLong: { |
| 5540 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5541 | if (value.IsRegisterPair()) { |
| 5542 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5543 | value.AsRegisterPairLow<Register>()); |
| 5544 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5545 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5546 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5547 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5548 | DCHECK(value.IsConstant()); |
| 5549 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 5550 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5551 | Immediate(Low32Bits(val))); |
| 5552 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5553 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5554 | Immediate(High32Bits(val))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5555 | } |
| 5556 | break; |
| 5557 | } |
| 5558 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5559 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5560 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5561 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5562 | if (value.IsFpuRegister()) { |
| 5563 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5564 | } else { |
| 5565 | DCHECK(value.IsConstant()); |
| 5566 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5567 | __ movl(address, Immediate(v)); |
| 5568 | } |
| 5569 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5570 | break; |
| 5571 | } |
| 5572 | |
| 5573 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5574 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5575 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5576 | if (value.IsFpuRegister()) { |
| 5577 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5578 | } else { |
| 5579 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5580 | Address address_hi = |
| 5581 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5582 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5583 | __ movl(address, Immediate(Low32Bits(v))); |
| 5584 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5585 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5586 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5587 | break; |
| 5588 | } |
| 5589 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5590 | case Primitive::kPrimVoid: |
| 5591 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5592 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5593 | } |
| 5594 | } |
| 5595 | |
| 5596 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5597 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5598 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5599 | if (!instruction->IsEmittedAtUseSite()) { |
| 5600 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5601 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5602 | } |
| 5603 | |
| 5604 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5605 | if (instruction->IsEmittedAtUseSite()) { |
| 5606 | return; |
| 5607 | } |
| 5608 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5609 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5610 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5611 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5612 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5613 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5614 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5615 | // Mask out most significant bit in case the array is String's array of char. |
| 5616 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5617 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5618 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5619 | } |
| 5620 | |
| 5621 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5622 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5623 | InvokeRuntimeCallingConvention calling_convention; |
| 5624 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5625 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5626 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5627 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5628 | HInstruction* length = instruction->InputAt(1); |
| 5629 | if (!length->IsEmittedAtUseSite()) { |
| 5630 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5631 | } |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5632 | // Need register to see array's length. |
| 5633 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5634 | locations->AddTemp(Location::RequiresRegister()); |
| 5635 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5636 | } |
| 5637 | |
| 5638 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5639 | const bool is_string_compressed_char_at = |
| 5640 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5641 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5642 | Location index_loc = locations->InAt(0); |
| 5643 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5644 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5645 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5646 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5647 | if (length_loc.IsConstant()) { |
| 5648 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5649 | if (index_loc.IsConstant()) { |
| 5650 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5651 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5652 | if (index < 0 || index >= length) { |
| 5653 | codegen_->AddSlowPath(slow_path); |
| 5654 | __ jmp(slow_path->GetEntryLabel()); |
| 5655 | } else { |
| 5656 | // Some optimization after BCE may have generated this, and we should not |
| 5657 | // generate a bounds check if it is a valid range. |
| 5658 | } |
| 5659 | return; |
| 5660 | } |
| 5661 | |
| 5662 | // We have to reverse the jump condition because the length is the constant. |
| 5663 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5664 | __ cmpl(index_reg, Immediate(length)); |
| 5665 | codegen_->AddSlowPath(slow_path); |
| 5666 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5667 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5668 | HInstruction* array_length = instruction->InputAt(1); |
| 5669 | if (array_length->IsEmittedAtUseSite()) { |
| 5670 | // Address the length field in the array. |
| 5671 | DCHECK(array_length->IsArrayLength()); |
| 5672 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5673 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5674 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5675 | if (is_string_compressed_char_at) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5676 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5677 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5678 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 5679 | __ movl(length_reg, array_len); |
| 5680 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5681 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5682 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5683 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5684 | // Checking bounds for general case: |
| 5685 | // Array of char or string's array with feature compression off. |
| 5686 | if (index_loc.IsConstant()) { |
| 5687 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5688 | __ cmpl(array_len, Immediate(value)); |
| 5689 | } else { |
| 5690 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 5691 | } |
| 5692 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5693 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5694 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5695 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5696 | } |
| 5697 | codegen_->AddSlowPath(slow_path); |
| 5698 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5699 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5700 | } |
| 5701 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5702 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5703 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5704 | } |
| 5705 | |
| 5706 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5707 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5708 | } |
| 5709 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5710 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5711 | LocationSummary* locations = |
| 5712 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5713 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5714 | } |
| 5715 | |
| 5716 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5717 | HBasicBlock* block = instruction->GetBlock(); |
| 5718 | if (block->GetLoopInformation() != nullptr) { |
| 5719 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5720 | // The back edge will generate the suspend check. |
| 5721 | return; |
| 5722 | } |
| 5723 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5724 | // The goto will generate the suspend check. |
| 5725 | return; |
| 5726 | } |
| 5727 | GenerateSuspendCheck(instruction, nullptr); |
| 5728 | } |
| 5729 | |
| 5730 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5731 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5732 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5733 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5734 | if (slow_path == nullptr) { |
| 5735 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5736 | instruction->SetSlowPath(slow_path); |
| 5737 | codegen_->AddSlowPath(slow_path); |
| 5738 | if (successor != nullptr) { |
| 5739 | DCHECK(successor->IsLoopHeader()); |
| 5740 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5741 | } |
| 5742 | } else { |
| 5743 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5744 | } |
| 5745 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5746 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5747 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5748 | if (successor == nullptr) { |
| 5749 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5750 | __ Bind(slow_path->GetReturnLabel()); |
| 5751 | } else { |
| 5752 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5753 | __ jmp(slow_path->GetEntryLabel()); |
| 5754 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5755 | } |
| 5756 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5757 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5758 | return codegen_->GetAssembler(); |
| 5759 | } |
| 5760 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5761 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5762 | ScratchRegisterScope ensure_scratch( |
| 5763 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5764 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5765 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5766 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5767 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5768 | } |
| 5769 | |
| 5770 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5771 | ScratchRegisterScope ensure_scratch( |
| 5772 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5773 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5774 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5775 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5776 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5777 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5778 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5779 | } |
| 5780 | |
| 5781 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5782 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5783 | Location source = move->GetSource(); |
| 5784 | Location destination = move->GetDestination(); |
| 5785 | |
| 5786 | if (source.IsRegister()) { |
| 5787 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5788 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5789 | } else if (destination.IsFpuRegister()) { |
| 5790 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5791 | } else { |
| 5792 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5793 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5794 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5795 | } else if (source.IsRegisterPair()) { |
| 5796 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 5797 | // Create stack space for 2 elements. |
| 5798 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5799 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5800 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5801 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5802 | // And remove the temporary stack space we allocated. |
| 5803 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5804 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5805 | if (destination.IsRegister()) { |
| 5806 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5807 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5808 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5809 | } else if (destination.IsRegisterPair()) { |
| 5810 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5811 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5812 | __ psrlq(src_reg, Immediate(32)); |
| 5813 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5814 | } else if (destination.IsStackSlot()) { |
| 5815 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5816 | } else { |
| 5817 | DCHECK(destination.IsDoubleStackSlot()); |
| 5818 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5819 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5820 | } else if (source.IsStackSlot()) { |
| 5821 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5822 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5823 | } else if (destination.IsFpuRegister()) { |
| 5824 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5825 | } else { |
| 5826 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5827 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5828 | } |
| 5829 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5830 | if (destination.IsRegisterPair()) { |
| 5831 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5832 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5833 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5834 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5835 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5836 | } else { |
| 5837 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5838 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5839 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5840 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5841 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5842 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5843 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5844 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5845 | if (value == 0) { |
| 5846 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5847 | } else { |
| 5848 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5849 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5850 | } else { |
| 5851 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5852 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5853 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5854 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5855 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5856 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5857 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5858 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5859 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5860 | if (value == 0) { |
| 5861 | // Easy handling of 0.0. |
| 5862 | __ xorps(dest, dest); |
| 5863 | } else { |
| 5864 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5865 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5866 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5867 | __ movl(temp, Immediate(value)); |
| 5868 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5869 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5870 | } else { |
| 5871 | DCHECK(destination.IsStackSlot()) << destination; |
| 5872 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5873 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5874 | } else if (constant->IsLongConstant()) { |
| 5875 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5876 | int32_t low_value = Low32Bits(value); |
| 5877 | int32_t high_value = High32Bits(value); |
| 5878 | Immediate low(low_value); |
| 5879 | Immediate high(high_value); |
| 5880 | if (destination.IsDoubleStackSlot()) { |
| 5881 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5882 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5883 | } else { |
| 5884 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5885 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5886 | } |
| 5887 | } else { |
| 5888 | DCHECK(constant->IsDoubleConstant()); |
| 5889 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5890 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5891 | int32_t low_value = Low32Bits(value); |
| 5892 | int32_t high_value = High32Bits(value); |
| 5893 | Immediate low(low_value); |
| 5894 | Immediate high(high_value); |
| 5895 | if (destination.IsFpuRegister()) { |
| 5896 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5897 | if (value == 0) { |
| 5898 | // Easy handling of 0.0. |
| 5899 | __ xorpd(dest, dest); |
| 5900 | } else { |
| 5901 | __ pushl(high); |
| 5902 | __ pushl(low); |
| 5903 | __ movsd(dest, Address(ESP, 0)); |
| 5904 | __ addl(ESP, Immediate(8)); |
| 5905 | } |
| 5906 | } else { |
| 5907 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5908 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5909 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5910 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5911 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5912 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5913 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5914 | } |
| 5915 | } |
| 5916 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5917 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5918 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5919 | ScratchRegisterScope ensure_scratch( |
| 5920 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5921 | |
| 5922 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5923 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5924 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5925 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5926 | } |
| 5927 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5928 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5929 | ScratchRegisterScope ensure_scratch( |
| 5930 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5931 | |
| 5932 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5933 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5934 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5935 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5936 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5937 | } |
| 5938 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5939 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5940 | ScratchRegisterScope ensure_scratch1( |
| 5941 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5942 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5943 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5944 | ScratchRegisterScope ensure_scratch2( |
| 5945 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5946 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5947 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5948 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5949 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5950 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5951 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5952 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5953 | } |
| 5954 | |
| 5955 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5956 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5957 | Location source = move->GetSource(); |
| 5958 | Location destination = move->GetDestination(); |
| 5959 | |
| 5960 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5961 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5962 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5963 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5964 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5965 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5966 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5967 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5968 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5969 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5970 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5971 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5972 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5973 | // Use XOR Swap algorithm to avoid a temporary. |
| 5974 | DCHECK_NE(source.reg(), destination.reg()); |
| 5975 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5976 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5977 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5978 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5979 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5980 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5981 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5982 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5983 | // Take advantage of the 16 bytes in the XMM register. |
| 5984 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5985 | Address stack(ESP, destination.GetStackIndex()); |
| 5986 | // Load the double into the high doubleword. |
| 5987 | __ movhpd(reg, stack); |
| 5988 | |
| 5989 | // Store the low double into the destination. |
| 5990 | __ movsd(stack, reg); |
| 5991 | |
| 5992 | // Move the high double to the low double. |
| 5993 | __ psrldq(reg, Immediate(8)); |
| 5994 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5995 | // Take advantage of the 16 bytes in the XMM register. |
| 5996 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5997 | Address stack(ESP, source.GetStackIndex()); |
| 5998 | // Load the double into the high doubleword. |
| 5999 | __ movhpd(reg, stack); |
| 6000 | |
| 6001 | // Store the low double into the destination. |
| 6002 | __ movsd(stack, reg); |
| 6003 | |
| 6004 | // Move the high double to the low double. |
| 6005 | __ psrldq(reg, Immediate(8)); |
| 6006 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 6007 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 6008 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6009 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6010 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6011 | } |
| 6012 | } |
| 6013 | |
| 6014 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 6015 | __ pushl(static_cast<Register>(reg)); |
| 6016 | } |
| 6017 | |
| 6018 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 6019 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6020 | } |
| 6021 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6022 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 6023 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6024 | switch (desired_class_load_kind) { |
| 6025 | case HLoadClass::LoadKind::kReferrersClass: |
| 6026 | break; |
| 6027 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 6028 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6029 | break; |
| 6030 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 6031 | DCHECK(GetCompilerOptions().GetCompilePic()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6032 | FALLTHROUGH_INTENDED; |
| 6033 | case HLoadClass::LoadKind::kBssEntry: |
| 6034 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6035 | break; |
| 6036 | case HLoadClass::LoadKind::kBootImageAddress: |
| 6037 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6038 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6039 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6040 | break; |
| 6041 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 6042 | break; |
| 6043 | } |
| 6044 | return desired_class_load_kind; |
| 6045 | } |
| 6046 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6047 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6048 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6049 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6050 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6051 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6052 | cls, |
| 6053 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6054 | Location::RegisterLocation(EAX)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6055 | return; |
| 6056 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6057 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6058 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6059 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6060 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6061 | ? LocationSummary::kCallOnSlowPath |
| 6062 | : LocationSummary::kNoCall; |
| 6063 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6064 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6065 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6066 | } |
| 6067 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6068 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6069 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
| 6070 | load_kind == HLoadClass::LoadKind::kBssEntry) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6071 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6072 | } |
| 6073 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6074 | } |
| 6075 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6076 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, |
| 6077 | dex::TypeIndex dex_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6078 | Handle<mirror::Class> handle) { |
| 6079 | jit_class_roots_.Overwrite(TypeReference(&dex_file, dex_index), |
| 6080 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6081 | // Add a patch entry and return the label. |
| 6082 | jit_class_patches_.emplace_back(dex_file, dex_index.index_); |
| 6083 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 6084 | return &info->label; |
| 6085 | } |
| 6086 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6087 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6088 | // move. |
| 6089 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6090 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6091 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 6092 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6093 | return; |
| 6094 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6095 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6096 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6097 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6098 | Location out_loc = locations->Out(); |
| 6099 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6100 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6101 | bool generate_null_check = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6102 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6103 | ? kWithoutReadBarrier |
| 6104 | : kCompilerReadBarrierOption; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6105 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6106 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6107 | DCHECK(!cls->CanCallRuntime()); |
| 6108 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6109 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6110 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6111 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6112 | cls, |
| 6113 | out_loc, |
| 6114 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6115 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6116 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6117 | break; |
| 6118 | } |
| 6119 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6120 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6121 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6122 | __ movl(out, Immediate(/* placeholder */ 0)); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 6123 | codegen_->RecordBootTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6124 | break; |
| 6125 | } |
| 6126 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6127 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6128 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6129 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6130 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 6131 | codegen_->RecordBootTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6132 | break; |
| 6133 | } |
| 6134 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6135 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6136 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6137 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6138 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6139 | __ movl(out, Immediate(address)); |
| 6140 | codegen_->RecordSimplePatch(); |
| 6141 | break; |
| 6142 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6143 | case HLoadClass::LoadKind::kBssEntry: { |
| 6144 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6145 | Address address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6146 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 6147 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| 6148 | generate_null_check = true; |
| 6149 | break; |
| 6150 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6151 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6152 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6153 | Label* fixup_label = codegen_->NewJitRootClassPatch( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6154 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6155 | // /* GcRoot<mirror::Class> */ out = *address |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6156 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6157 | break; |
| 6158 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6159 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 6160 | LOG(FATAL) << "UNREACHABLE"; |
| 6161 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6162 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6163 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6164 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6165 | DCHECK(cls->CanCallRuntime()); |
| 6166 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 6167 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6168 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6169 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6170 | if (generate_null_check) { |
| 6171 | __ testl(out, out); |
| 6172 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6173 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6174 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6175 | if (cls->MustGenerateClinitCheck()) { |
| 6176 | GenerateClassInitializationCheck(slow_path, out); |
| 6177 | } else { |
| 6178 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6179 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6180 | } |
| 6181 | } |
| 6182 | |
| 6183 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6184 | LocationSummary* locations = |
| 6185 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6186 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6187 | if (check->HasUses()) { |
| 6188 | locations->SetOut(Location::SameAsFirstInput()); |
| 6189 | } |
| 6190 | } |
| 6191 | |
| 6192 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6193 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6194 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6195 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6196 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6197 | GenerateClassInitializationCheck(slow_path, |
| 6198 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6199 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6200 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6201 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6202 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6203 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 6204 | Immediate(mirror::Class::kStatusInitialized)); |
| 6205 | __ j(kLess, slow_path->GetEntryLabel()); |
| 6206 | __ Bind(slow_path->GetExitLabel()); |
| 6207 | // No need for memory fence, thanks to the X86 memory model. |
| 6208 | } |
| 6209 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6210 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6211 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6212 | switch (desired_string_load_kind) { |
| 6213 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 6214 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6215 | break; |
| 6216 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6217 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6218 | FALLTHROUGH_INTENDED; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6219 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6220 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6221 | break; |
| 6222 | case HLoadString::LoadKind::kBootImageAddress: |
| 6223 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6224 | case HLoadString::LoadKind::kJitTableAddress: |
| 6225 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6226 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6227 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 6228 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6229 | } |
| 6230 | return desired_string_load_kind; |
| 6231 | } |
| 6232 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6233 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6234 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6235 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6236 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6237 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6238 | load_kind == HLoadString::LoadKind::kBssEntry) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6239 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6240 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6241 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 6242 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 6243 | } else { |
| 6244 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6245 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6246 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6247 | // Rely on the pResolveString and/or marking to save everything. |
| 6248 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6249 | InvokeRuntimeCallingConvention calling_convention; |
| 6250 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6251 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6252 | } else { |
| 6253 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6254 | } |
| 6255 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6256 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6257 | } |
| 6258 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6259 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6260 | dex::StringIndex dex_index, |
| 6261 | Handle<mirror::String> handle) { |
| 6262 | jit_string_roots_.Overwrite( |
| 6263 | StringReference(&dex_file, dex_index), reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6264 | // Add a patch entry and return the label. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6265 | jit_string_patches_.emplace_back(dex_file, dex_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6266 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6267 | return &info->label; |
| 6268 | } |
| 6269 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6270 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6271 | // move. |
| 6272 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6273 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6274 | Location out_loc = locations->Out(); |
| 6275 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6276 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6277 | switch (load->GetLoadKind()) { |
| 6278 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6279 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6280 | __ movl(out, Immediate(/* placeholder */ 0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6281 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6282 | return; // No dex cache slow path. |
| 6283 | } |
| 6284 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6285 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6286 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6287 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6288 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6289 | return; // No dex cache slow path. |
| 6290 | } |
| 6291 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6292 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6293 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6294 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6295 | __ movl(out, Immediate(address)); |
| 6296 | codegen_->RecordSimplePatch(); |
| 6297 | return; // No dex cache slow path. |
| 6298 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6299 | case HLoadString::LoadKind::kBssEntry: { |
| 6300 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6301 | Address address = Address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6302 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6303 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6304 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6305 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 6306 | codegen_->AddSlowPath(slow_path); |
| 6307 | __ testl(out, out); |
| 6308 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6309 | __ Bind(slow_path->GetExitLabel()); |
| 6310 | return; |
| 6311 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6312 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6313 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6314 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6315 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6316 | // /* GcRoot<mirror::String> */ out = *address |
| 6317 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6318 | return; |
| 6319 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6320 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6321 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6322 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6323 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6324 | // 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] | 6325 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6326 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6327 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6328 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6329 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6330 | } |
| 6331 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6332 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6333 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6334 | } |
| 6335 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6336 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6337 | LocationSummary* locations = |
| 6338 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6339 | locations->SetOut(Location::RequiresRegister()); |
| 6340 | } |
| 6341 | |
| 6342 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6343 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6344 | } |
| 6345 | |
| 6346 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 6347 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6348 | } |
| 6349 | |
| 6350 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6351 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6352 | } |
| 6353 | |
| 6354 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 6355 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6356 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6357 | InvokeRuntimeCallingConvention calling_convention; |
| 6358 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6359 | } |
| 6360 | |
| 6361 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6362 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6363 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6364 | } |
| 6365 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6366 | // Temp is used for read barrier. |
| 6367 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6368 | if (kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6369 | !kUseBakerReadBarrier && |
| 6370 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6371 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6372 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6373 | return 1; |
| 6374 | } |
| 6375 | return 0; |
| 6376 | } |
| 6377 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6378 | // 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] | 6379 | // interface pointer, one for loading the current interface. |
| 6380 | // The other checks have one temp for loading the object's class. |
| 6381 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6382 | if (type_check_kind == TypeCheckKind::kInterfaceCheck && !kPoisonHeapReferences) { |
| 6383 | return 2; |
| 6384 | } |
| 6385 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6386 | } |
| 6387 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6388 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6389 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6390 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6391 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6392 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6393 | case TypeCheckKind::kExactCheck: |
| 6394 | case TypeCheckKind::kAbstractClassCheck: |
| 6395 | case TypeCheckKind::kClassHierarchyCheck: |
| 6396 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6397 | call_kind = |
| 6398 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6399 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6400 | break; |
| 6401 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6402 | case TypeCheckKind::kUnresolvedCheck: |
| 6403 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6404 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6405 | break; |
| 6406 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6407 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6408 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6409 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6410 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6411 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6412 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6413 | locations->SetInAt(1, Location::Any()); |
| 6414 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6415 | locations->SetOut(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6416 | // When read barriers are enabled, we need a temporary register for some cases. |
| 6417 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6418 | } |
| 6419 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6420 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6421 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6422 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6423 | Location obj_loc = locations->InAt(0); |
| 6424 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6425 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6426 | Location out_loc = locations->Out(); |
| 6427 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6428 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6429 | DCHECK_LE(num_temps, 1u); |
| 6430 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6431 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6432 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6433 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6434 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6435 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6436 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6437 | |
| 6438 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6439 | // Avoid null check if we know obj is not null. |
| 6440 | if (instruction->MustDoNullCheck()) { |
| 6441 | __ testl(obj, obj); |
| 6442 | __ j(kEqual, &zero); |
| 6443 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6444 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6445 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6446 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6447 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6448 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6449 | out_loc, |
| 6450 | obj_loc, |
| 6451 | class_offset, |
| 6452 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6453 | if (cls.IsRegister()) { |
| 6454 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6455 | } else { |
| 6456 | DCHECK(cls.IsStackSlot()) << cls; |
| 6457 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6458 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6459 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6460 | // Classes must be equal for the instanceof to succeed. |
| 6461 | __ j(kNotEqual, &zero); |
| 6462 | __ movl(out, Immediate(1)); |
| 6463 | __ jmp(&done); |
| 6464 | break; |
| 6465 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6466 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6467 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6468 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6469 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6470 | out_loc, |
| 6471 | obj_loc, |
| 6472 | class_offset, |
| 6473 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6474 | // If the class is abstract, we eagerly fetch the super class of the |
| 6475 | // object to avoid doing a comparison we know will fail. |
| 6476 | NearLabel loop; |
| 6477 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6478 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6479 | GenerateReferenceLoadOneRegister(instruction, |
| 6480 | out_loc, |
| 6481 | super_offset, |
| 6482 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6483 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6484 | __ testl(out, out); |
| 6485 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6486 | __ j(kEqual, &done); |
| 6487 | if (cls.IsRegister()) { |
| 6488 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6489 | } else { |
| 6490 | DCHECK(cls.IsStackSlot()) << cls; |
| 6491 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6492 | } |
| 6493 | __ j(kNotEqual, &loop); |
| 6494 | __ movl(out, Immediate(1)); |
| 6495 | if (zero.IsLinked()) { |
| 6496 | __ jmp(&done); |
| 6497 | } |
| 6498 | break; |
| 6499 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6500 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6501 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6502 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6503 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6504 | out_loc, |
| 6505 | obj_loc, |
| 6506 | class_offset, |
| 6507 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6508 | // Walk over the class hierarchy to find a match. |
| 6509 | NearLabel loop, success; |
| 6510 | __ Bind(&loop); |
| 6511 | if (cls.IsRegister()) { |
| 6512 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6513 | } else { |
| 6514 | DCHECK(cls.IsStackSlot()) << cls; |
| 6515 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6516 | } |
| 6517 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6518 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6519 | GenerateReferenceLoadOneRegister(instruction, |
| 6520 | out_loc, |
| 6521 | super_offset, |
| 6522 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6523 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6524 | __ testl(out, out); |
| 6525 | __ j(kNotEqual, &loop); |
| 6526 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6527 | __ jmp(&done); |
| 6528 | __ Bind(&success); |
| 6529 | __ movl(out, Immediate(1)); |
| 6530 | if (zero.IsLinked()) { |
| 6531 | __ jmp(&done); |
| 6532 | } |
| 6533 | break; |
| 6534 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6535 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6536 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6537 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6538 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6539 | out_loc, |
| 6540 | obj_loc, |
| 6541 | class_offset, |
| 6542 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6543 | // Do an exact check. |
| 6544 | NearLabel exact_check; |
| 6545 | if (cls.IsRegister()) { |
| 6546 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6547 | } else { |
| 6548 | DCHECK(cls.IsStackSlot()) << cls; |
| 6549 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6550 | } |
| 6551 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6552 | // 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] | 6553 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6554 | GenerateReferenceLoadOneRegister(instruction, |
| 6555 | out_loc, |
| 6556 | component_offset, |
| 6557 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6558 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6559 | __ testl(out, out); |
| 6560 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6561 | __ j(kEqual, &done); |
| 6562 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6563 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6564 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6565 | __ movl(out, Immediate(1)); |
| 6566 | __ jmp(&done); |
| 6567 | break; |
| 6568 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6569 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6570 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6571 | // No read barrier since the slow path will retry upon failure. |
| 6572 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6573 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6574 | out_loc, |
| 6575 | obj_loc, |
| 6576 | class_offset, |
| 6577 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6578 | if (cls.IsRegister()) { |
| 6579 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6580 | } else { |
| 6581 | DCHECK(cls.IsStackSlot()) << cls; |
| 6582 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6583 | } |
| 6584 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6585 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6586 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6587 | codegen_->AddSlowPath(slow_path); |
| 6588 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6589 | __ movl(out, Immediate(1)); |
| 6590 | if (zero.IsLinked()) { |
| 6591 | __ jmp(&done); |
| 6592 | } |
| 6593 | break; |
| 6594 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6595 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6596 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6597 | case TypeCheckKind::kInterfaceCheck: { |
| 6598 | // 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] | 6599 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6600 | // cases. |
| 6601 | // |
| 6602 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6603 | // entry point without resorting to a type checking slow path |
| 6604 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6605 | // require to assign fixed registers for the inputs of this |
| 6606 | // HInstanceOf instruction (following the runtime calling |
| 6607 | // convention), which might be cluttered by the potential first |
| 6608 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6609 | // |
| 6610 | // TODO: Introduce a new runtime entry point taking the object |
| 6611 | // to test (instead of its class) as argument, and let it deal |
| 6612 | // with the read barrier issues. This will let us refactor this |
| 6613 | // case of the `switch` code as it was previously (with a direct |
| 6614 | // call to the runtime not using a type checking slow path). |
| 6615 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6616 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6617 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6618 | /* is_fatal */ false); |
| 6619 | codegen_->AddSlowPath(slow_path); |
| 6620 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6621 | if (zero.IsLinked()) { |
| 6622 | __ jmp(&done); |
| 6623 | } |
| 6624 | break; |
| 6625 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6626 | } |
| 6627 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6628 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6629 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6630 | __ xorl(out, out); |
| 6631 | } |
| 6632 | |
| 6633 | if (done.IsLinked()) { |
| 6634 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6635 | } |
| 6636 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6637 | if (slow_path != nullptr) { |
| 6638 | __ Bind(slow_path->GetExitLabel()); |
| 6639 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6640 | } |
| 6641 | |
Mathieu Chartier | 5ac321b | 2016-11-09 16:33:54 -0800 | [diff] [blame] | 6642 | static bool IsTypeCheckSlowPathFatal(TypeCheckKind type_check_kind, bool throws_into_catch) { |
| 6643 | switch (type_check_kind) { |
| 6644 | case TypeCheckKind::kExactCheck: |
| 6645 | case TypeCheckKind::kAbstractClassCheck: |
| 6646 | case TypeCheckKind::kClassHierarchyCheck: |
| 6647 | case TypeCheckKind::kArrayObjectCheck: |
| 6648 | return !throws_into_catch && !kEmitCompilerReadBarrier; |
| 6649 | case TypeCheckKind::kInterfaceCheck: |
| 6650 | return !throws_into_catch && !kEmitCompilerReadBarrier && !kPoisonHeapReferences; |
| 6651 | case TypeCheckKind::kArrayCheck: |
| 6652 | case TypeCheckKind::kUnresolvedCheck: |
| 6653 | return false; |
| 6654 | } |
| 6655 | LOG(FATAL) << "Unreachable"; |
| 6656 | UNREACHABLE(); |
| 6657 | } |
| 6658 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6659 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6660 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6661 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Mathieu Chartier | 5ac321b | 2016-11-09 16:33:54 -0800 | [diff] [blame] | 6662 | LocationSummary::CallKind call_kind = |
| 6663 | IsTypeCheckSlowPathFatal(type_check_kind, throws_into_catch) |
| 6664 | ? LocationSummary::kNoCall |
| 6665 | : LocationSummary::kCallOnSlowPath; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6666 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6667 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6668 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6669 | // Require a register for the interface check since there is a loop that compares the class to |
| 6670 | // a memory address. |
| 6671 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6672 | } else { |
| 6673 | locations->SetInAt(1, Location::Any()); |
| 6674 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6675 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6676 | locations->AddTemp(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6677 | // When read barriers are enabled, we need an additional temporary register for some cases. |
| 6678 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 6679 | } |
| 6680 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6681 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6682 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6683 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6684 | Location obj_loc = locations->InAt(0); |
| 6685 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6686 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6687 | Location temp_loc = locations->GetTemp(0); |
| 6688 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6689 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6690 | DCHECK_GE(num_temps, 1u); |
| 6691 | DCHECK_LE(num_temps, 2u); |
| 6692 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 6693 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6694 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6695 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6696 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6697 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6698 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6699 | const uint32_t object_array_data_offset = |
| 6700 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6701 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6702 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 6703 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 6704 | // read barriers is done for performance and code size reasons. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6705 | bool is_type_check_slow_path_fatal = |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6706 | IsTypeCheckSlowPathFatal(type_check_kind, instruction->CanThrowIntoCatchBlock()); |
| 6707 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6708 | SlowPathCode* type_check_slow_path = |
| 6709 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6710 | is_type_check_slow_path_fatal); |
| 6711 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6712 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6713 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6714 | // Avoid null check if we know obj is not null. |
| 6715 | if (instruction->MustDoNullCheck()) { |
| 6716 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6717 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6718 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6719 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6720 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6721 | case TypeCheckKind::kExactCheck: |
| 6722 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6723 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6724 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6725 | temp_loc, |
| 6726 | obj_loc, |
| 6727 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6728 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6729 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6730 | if (cls.IsRegister()) { |
| 6731 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6732 | } else { |
| 6733 | DCHECK(cls.IsStackSlot()) << cls; |
| 6734 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6735 | } |
| 6736 | // Jump to slow path for throwing the exception or doing a |
| 6737 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6738 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6739 | break; |
| 6740 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6741 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6742 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6743 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6744 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6745 | temp_loc, |
| 6746 | obj_loc, |
| 6747 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6748 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6749 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6750 | // If the class is abstract, we eagerly fetch the super class of the |
| 6751 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6752 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6753 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6754 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6755 | GenerateReferenceLoadOneRegister(instruction, |
| 6756 | temp_loc, |
| 6757 | super_offset, |
| 6758 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6759 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6760 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6761 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6762 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6763 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6764 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6765 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6766 | // Otherwise, compare the classes |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6767 | if (cls.IsRegister()) { |
| 6768 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6769 | } else { |
| 6770 | DCHECK(cls.IsStackSlot()) << cls; |
| 6771 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6772 | } |
| 6773 | __ j(kNotEqual, &loop); |
| 6774 | break; |
| 6775 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6776 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6777 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6778 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6779 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6780 | temp_loc, |
| 6781 | obj_loc, |
| 6782 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6783 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6784 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6785 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6786 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6787 | __ Bind(&loop); |
| 6788 | if (cls.IsRegister()) { |
| 6789 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6790 | } else { |
| 6791 | DCHECK(cls.IsStackSlot()) << cls; |
| 6792 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6793 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6794 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6795 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6796 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6797 | GenerateReferenceLoadOneRegister(instruction, |
| 6798 | temp_loc, |
| 6799 | super_offset, |
| 6800 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6801 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6802 | |
| 6803 | // If the class reference currently in `temp` is not null, jump |
| 6804 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6805 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6806 | __ j(kNotZero, &loop); |
| 6807 | // Otherwise, jump to the slow path to throw the exception.; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6808 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6809 | break; |
| 6810 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6811 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6812 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6813 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6814 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6815 | temp_loc, |
| 6816 | obj_loc, |
| 6817 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6818 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6819 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6820 | // Do an exact check. |
| 6821 | if (cls.IsRegister()) { |
| 6822 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6823 | } else { |
| 6824 | DCHECK(cls.IsStackSlot()) << cls; |
| 6825 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6826 | } |
| 6827 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6828 | |
| 6829 | // 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] | 6830 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6831 | GenerateReferenceLoadOneRegister(instruction, |
| 6832 | temp_loc, |
| 6833 | component_offset, |
| 6834 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6835 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6836 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6837 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 6838 | // throw the exception. Otherwise proceed with the check. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6839 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6840 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6841 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6842 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6843 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6844 | break; |
| 6845 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6846 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6847 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6848 | // 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] | 6849 | // We cannot directly call the CheckCast runtime entry point |
| 6850 | // without resorting to a type checking slow path here (i.e. by |
| 6851 | // calling InvokeRuntime directly), as it would require to |
| 6852 | // assign fixed registers for the inputs of this HInstanceOf |
| 6853 | // instruction (following the runtime calling convention), which |
| 6854 | // might be cluttered by the potential first read barrier |
| 6855 | // emission at the beginning of this method. |
| 6856 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6857 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6858 | |
| 6859 | case TypeCheckKind::kInterfaceCheck: { |
| 6860 | // Fast path for the interface check. Since we compare with a memory location in the inner |
| 6861 | // loop we would need to have cls poisoned. However unpoisoning cls would reset the |
| 6862 | // 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] | 6863 | // to the slow path if we are running under poisoning. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6864 | if (!kPoisonHeapReferences) { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6865 | // Try to avoid read barriers to improve the fast path. We can not get false positives by |
| 6866 | // doing this. |
| 6867 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6868 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6869 | temp_loc, |
| 6870 | obj_loc, |
| 6871 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6872 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6873 | |
| 6874 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6875 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6876 | temp_loc, |
| 6877 | temp_loc, |
| 6878 | iftable_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6879 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6880 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6881 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6882 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6883 | NearLabel start_loop; |
| 6884 | __ Bind(&start_loop); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6885 | // Need to subtract first to handle the empty array case. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6886 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6887 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 6888 | // Go to next interface if the classes do not match. |
| 6889 | __ cmpl(cls.AsRegister<Register>(), |
| 6890 | CodeGeneratorX86::ArrayAddress(temp, |
| 6891 | maybe_temp2_loc, |
| 6892 | TIMES_4, |
| 6893 | object_array_data_offset)); |
| 6894 | __ j(kNotEqual, &start_loop); |
| 6895 | } else { |
| 6896 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6897 | } |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6898 | break; |
| 6899 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6900 | } |
| 6901 | __ Bind(&done); |
| 6902 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6903 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6904 | } |
| 6905 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6906 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6907 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6908 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6909 | InvokeRuntimeCallingConvention calling_convention; |
| 6910 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6911 | } |
| 6912 | |
| 6913 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6914 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 6915 | : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6916 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6917 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6918 | if (instruction->IsEnter()) { |
| 6919 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6920 | } else { |
| 6921 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6922 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6923 | } |
| 6924 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6925 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6926 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6927 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6928 | |
| 6929 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6930 | LocationSummary* locations = |
| 6931 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6932 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6933 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6934 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6935 | locations->SetInAt(1, Location::Any()); |
| 6936 | locations->SetOut(Location::SameAsFirstInput()); |
| 6937 | } |
| 6938 | |
| 6939 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6940 | HandleBitwiseOperation(instruction); |
| 6941 | } |
| 6942 | |
| 6943 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6944 | HandleBitwiseOperation(instruction); |
| 6945 | } |
| 6946 | |
| 6947 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6948 | HandleBitwiseOperation(instruction); |
| 6949 | } |
| 6950 | |
| 6951 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6952 | LocationSummary* locations = instruction->GetLocations(); |
| 6953 | Location first = locations->InAt(0); |
| 6954 | Location second = locations->InAt(1); |
| 6955 | DCHECK(first.Equals(locations->Out())); |
| 6956 | |
| 6957 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6958 | if (second.IsRegister()) { |
| 6959 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6960 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6961 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6962 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6963 | } else { |
| 6964 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6965 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6966 | } |
| 6967 | } else if (second.IsConstant()) { |
| 6968 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6969 | __ andl(first.AsRegister<Register>(), |
| 6970 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6971 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6972 | __ orl(first.AsRegister<Register>(), |
| 6973 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6974 | } else { |
| 6975 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6976 | __ xorl(first.AsRegister<Register>(), |
| 6977 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6978 | } |
| 6979 | } else { |
| 6980 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6981 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6982 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6983 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6984 | } else { |
| 6985 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6986 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6987 | } |
| 6988 | } |
| 6989 | } else { |
| 6990 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6991 | if (second.IsRegisterPair()) { |
| 6992 | if (instruction->IsAnd()) { |
| 6993 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6994 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6995 | } else if (instruction->IsOr()) { |
| 6996 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6997 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6998 | } else { |
| 6999 | DCHECK(instruction->IsXor()); |
| 7000 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7001 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7002 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7003 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7004 | if (instruction->IsAnd()) { |
| 7005 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7006 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 7007 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7008 | } else if (instruction->IsOr()) { |
| 7009 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7010 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 7011 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7012 | } else { |
| 7013 | DCHECK(instruction->IsXor()); |
| 7014 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7015 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 7016 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7017 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7018 | } else { |
| 7019 | DCHECK(second.IsConstant()) << second; |
| 7020 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7021 | int32_t low_value = Low32Bits(value); |
| 7022 | int32_t high_value = High32Bits(value); |
| 7023 | Immediate low(low_value); |
| 7024 | Immediate high(high_value); |
| 7025 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7026 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7027 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7028 | if (low_value == 0) { |
| 7029 | __ xorl(first_low, first_low); |
| 7030 | } else if (low_value != -1) { |
| 7031 | __ andl(first_low, low); |
| 7032 | } |
| 7033 | if (high_value == 0) { |
| 7034 | __ xorl(first_high, first_high); |
| 7035 | } else if (high_value != -1) { |
| 7036 | __ andl(first_high, high); |
| 7037 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7038 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7039 | if (low_value != 0) { |
| 7040 | __ orl(first_low, low); |
| 7041 | } |
| 7042 | if (high_value != 0) { |
| 7043 | __ orl(first_high, high); |
| 7044 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7045 | } else { |
| 7046 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7047 | if (low_value != 0) { |
| 7048 | __ xorl(first_low, low); |
| 7049 | } |
| 7050 | if (high_value != 0) { |
| 7051 | __ xorl(first_high, high); |
| 7052 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7053 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7054 | } |
| 7055 | } |
| 7056 | } |
| 7057 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7058 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( |
| 7059 | HInstruction* instruction, |
| 7060 | Location out, |
| 7061 | uint32_t offset, |
| 7062 | Location maybe_temp, |
| 7063 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7064 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7065 | if (read_barrier_option == kWithReadBarrier) { |
| 7066 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7067 | if (kUseBakerReadBarrier) { |
| 7068 | // Load with fast path based Baker's read barrier. |
| 7069 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7070 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7071 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7072 | } else { |
| 7073 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7074 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7075 | // in the following move operation, as we will need it for the |
| 7076 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7077 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7078 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7079 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7080 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7081 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7082 | } |
| 7083 | } else { |
| 7084 | // Plain load with no read barrier. |
| 7085 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7086 | __ movl(out_reg, Address(out_reg, offset)); |
| 7087 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7088 | } |
| 7089 | } |
| 7090 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7091 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( |
| 7092 | HInstruction* instruction, |
| 7093 | Location out, |
| 7094 | Location obj, |
| 7095 | uint32_t offset, |
| 7096 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7097 | Register out_reg = out.AsRegister<Register>(); |
| 7098 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7099 | if (read_barrier_option == kWithReadBarrier) { |
| 7100 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7101 | if (kUseBakerReadBarrier) { |
| 7102 | // Load with fast path based Baker's read barrier. |
| 7103 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7104 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7105 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7106 | } else { |
| 7107 | // Load with slow path based read barrier. |
| 7108 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7109 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7110 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7111 | } |
| 7112 | } else { |
| 7113 | // Plain load with no read barrier. |
| 7114 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7115 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7116 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7117 | } |
| 7118 | } |
| 7119 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7120 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( |
| 7121 | HInstruction* instruction, |
| 7122 | Location root, |
| 7123 | const Address& address, |
| 7124 | Label* fixup_label, |
| 7125 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7126 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7127 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7128 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7129 | if (kUseBakerReadBarrier) { |
| 7130 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7131 | // Baker's read barrier are used: |
| 7132 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7133 | // root = *address; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7134 | // if (Thread::Current()->GetIsGcMarking()) { |
| 7135 | // root = ReadBarrier::Mark(root) |
| 7136 | // } |
| 7137 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7138 | // /* GcRoot<mirror::Object> */ root = *address |
| 7139 | __ movl(root_reg, address); |
| 7140 | if (fixup_label != nullptr) { |
| 7141 | __ Bind(fixup_label); |
| 7142 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7143 | static_assert( |
| 7144 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7145 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7146 | "have different sizes."); |
| 7147 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7148 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7149 | "have different sizes."); |
| 7150 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7151 | // Slow path marking the GC root `root`. |
| 7152 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7153 | instruction, root, /* unpoison_ref_before_marking */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7154 | codegen_->AddSlowPath(slow_path); |
| 7155 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7156 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7157 | Immediate(0)); |
| 7158 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7159 | __ Bind(slow_path->GetExitLabel()); |
| 7160 | } else { |
| 7161 | // GC root loaded through a slow path for read barriers other |
| 7162 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7163 | // /* GcRoot<mirror::Object>* */ root = address |
| 7164 | __ leal(root_reg, address); |
| 7165 | if (fixup_label != nullptr) { |
| 7166 | __ Bind(fixup_label); |
| 7167 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7168 | // /* mirror::Object* */ root = root->Read() |
| 7169 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7170 | } |
| 7171 | } else { |
| 7172 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7173 | // /* GcRoot<mirror::Object> */ root = *address |
| 7174 | __ movl(root_reg, address); |
| 7175 | if (fixup_label != nullptr) { |
| 7176 | __ Bind(fixup_label); |
| 7177 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7178 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7179 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7180 | } |
| 7181 | } |
| 7182 | |
| 7183 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7184 | Location ref, |
| 7185 | Register obj, |
| 7186 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7187 | bool needs_null_check) { |
| 7188 | DCHECK(kEmitCompilerReadBarrier); |
| 7189 | DCHECK(kUseBakerReadBarrier); |
| 7190 | |
| 7191 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7192 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7193 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7194 | } |
| 7195 | |
| 7196 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7197 | Location ref, |
| 7198 | Register obj, |
| 7199 | uint32_t data_offset, |
| 7200 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7201 | bool needs_null_check) { |
| 7202 | DCHECK(kEmitCompilerReadBarrier); |
| 7203 | DCHECK(kUseBakerReadBarrier); |
| 7204 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7205 | static_assert( |
| 7206 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7207 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7208 | // /* HeapReference<Object> */ ref = |
| 7209 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7210 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7211 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7212 | } |
| 7213 | |
| 7214 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7215 | Location ref, |
| 7216 | Register obj, |
| 7217 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7218 | bool needs_null_check, |
| 7219 | bool always_update_field, |
| 7220 | Register* temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7221 | DCHECK(kEmitCompilerReadBarrier); |
| 7222 | DCHECK(kUseBakerReadBarrier); |
| 7223 | |
| 7224 | // In slow path based read barriers, the read barrier call is |
| 7225 | // inserted after the original load. However, in fast path based |
| 7226 | // Baker's read barriers, we need to perform the load of |
| 7227 | // mirror::Object::monitor_ *before* the original reference load. |
| 7228 | // This load-load ordering is required by the read barrier. |
| 7229 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7230 | // |
| 7231 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7232 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7233 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7234 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7235 | // if (is_gray) { |
| 7236 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7237 | // } |
| 7238 | // |
| 7239 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7240 | // slightly more complex as: |
| 7241 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7242 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7243 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7244 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7245 | // - it performs additional checks that we do not do here for |
| 7246 | // performance reasons. |
| 7247 | |
| 7248 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7249 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7250 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7251 | // 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] | 7252 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7253 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7254 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7255 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7256 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7257 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7258 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7259 | // ref = ReadBarrier::Mark(ref); |
| 7260 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7261 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7262 | if (needs_null_check) { |
| 7263 | MaybeRecordImplicitNullCheck(instruction); |
| 7264 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7265 | |
| 7266 | // Load fence to prevent load-load reordering. |
| 7267 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7268 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7269 | |
| 7270 | // The actual reference load. |
| 7271 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7272 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7273 | |
| 7274 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7275 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7276 | SlowPathCode* slow_path; |
| 7277 | if (always_update_field) { |
| 7278 | DCHECK(temp != nullptr); |
| 7279 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
| 7280 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp); |
| 7281 | } else { |
| 7282 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86( |
| 7283 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 7284 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7285 | AddSlowPath(slow_path); |
| 7286 | |
| 7287 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7288 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7289 | |
| 7290 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7291 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7292 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7293 | __ Bind(slow_path->GetExitLabel()); |
| 7294 | } |
| 7295 | |
| 7296 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7297 | Location out, |
| 7298 | Location ref, |
| 7299 | Location obj, |
| 7300 | uint32_t offset, |
| 7301 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7302 | DCHECK(kEmitCompilerReadBarrier); |
| 7303 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7304 | // Insert a slow path based read barrier *after* the reference load. |
| 7305 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7306 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7307 | // reference will be carried out by the runtime within the slow |
| 7308 | // path. |
| 7309 | // |
| 7310 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7311 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7312 | // not used by the artReadBarrierSlow entry point. |
| 7313 | // |
| 7314 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 7315 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 7316 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 7317 | AddSlowPath(slow_path); |
| 7318 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7319 | __ jmp(slow_path->GetEntryLabel()); |
| 7320 | __ Bind(slow_path->GetExitLabel()); |
| 7321 | } |
| 7322 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7323 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7324 | Location out, |
| 7325 | Location ref, |
| 7326 | Location obj, |
| 7327 | uint32_t offset, |
| 7328 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7329 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7330 | // Baker's read barriers shall be handled by the fast path |
| 7331 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 7332 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7333 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7334 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7335 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7336 | } else if (kPoisonHeapReferences) { |
| 7337 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7338 | } |
| 7339 | } |
| 7340 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7341 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7342 | Location out, |
| 7343 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7344 | DCHECK(kEmitCompilerReadBarrier); |
| 7345 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7346 | // Insert a slow path based read barrier *after* the GC root load. |
| 7347 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7348 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7349 | // not need to do anything special for this here. |
| 7350 | SlowPathCode* slow_path = |
| 7351 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 7352 | AddSlowPath(slow_path); |
| 7353 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7354 | __ jmp(slow_path->GetEntryLabel()); |
| 7355 | __ Bind(slow_path->GetExitLabel()); |
| 7356 | } |
| 7357 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7358 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7359 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7360 | LOG(FATAL) << "Unreachable"; |
| 7361 | } |
| 7362 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7363 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7364 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7365 | LOG(FATAL) << "Unreachable"; |
| 7366 | } |
| 7367 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7368 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7369 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7370 | LocationSummary* locations = |
| 7371 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7372 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7373 | } |
| 7374 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7375 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7376 | int32_t lower_bound, |
| 7377 | uint32_t num_entries, |
| 7378 | HBasicBlock* switch_block, |
| 7379 | HBasicBlock* default_block) { |
| 7380 | // Figure out the correct compare values and jump conditions. |
| 7381 | // Handle the first compare/branch as a special case because it might |
| 7382 | // jump to the default case. |
| 7383 | DCHECK_GT(num_entries, 2u); |
| 7384 | Condition first_condition; |
| 7385 | uint32_t index; |
| 7386 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7387 | if (lower_bound != 0) { |
| 7388 | first_condition = kLess; |
| 7389 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7390 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7391 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7392 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7393 | index = 1; |
| 7394 | } else { |
| 7395 | // Handle all the compare/jumps below. |
| 7396 | first_condition = kBelow; |
| 7397 | index = 0; |
| 7398 | } |
| 7399 | |
| 7400 | // Handle the rest of the compare/jumps. |
| 7401 | for (; index + 1 < num_entries; index += 2) { |
| 7402 | int32_t compare_to_value = lower_bound + index + 1; |
| 7403 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7404 | // Jump to successors[index] if value < case_value[index]. |
| 7405 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7406 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7407 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7408 | } |
| 7409 | |
| 7410 | if (index != num_entries) { |
| 7411 | // There are an odd number of entries. Handle the last one. |
| 7412 | DCHECK_EQ(index + 1, num_entries); |
| 7413 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7414 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7415 | } |
| 7416 | |
| 7417 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7418 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7419 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7420 | } |
| 7421 | } |
| 7422 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7423 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7424 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7425 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7426 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7427 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7428 | |
| 7429 | GenPackedSwitchWithCompares(value_reg, |
| 7430 | lower_bound, |
| 7431 | num_entries, |
| 7432 | switch_instr->GetBlock(), |
| 7433 | switch_instr->GetDefaultBlock()); |
| 7434 | } |
| 7435 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7436 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7437 | LocationSummary* locations = |
| 7438 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7439 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7440 | |
| 7441 | // Constant area pointer. |
| 7442 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7443 | |
| 7444 | // And the temporary we need. |
| 7445 | locations->AddTemp(Location::RequiresRegister()); |
| 7446 | } |
| 7447 | |
| 7448 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7449 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7450 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7451 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7452 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7453 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7454 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7455 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7456 | GenPackedSwitchWithCompares(value_reg, |
| 7457 | lower_bound, |
| 7458 | num_entries, |
| 7459 | switch_instr->GetBlock(), |
| 7460 | default_block); |
| 7461 | return; |
| 7462 | } |
| 7463 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7464 | // Optimizing has a jump area. |
| 7465 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7466 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7467 | |
| 7468 | // Remove the bias, if needed. |
| 7469 | if (lower_bound != 0) { |
| 7470 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7471 | value_reg = temp_reg; |
| 7472 | } |
| 7473 | |
| 7474 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7475 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7476 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7477 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7478 | |
| 7479 | // We are in the range of the table. |
| 7480 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7481 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7482 | |
| 7483 | // Compute the actual target address by adding in constant_area. |
| 7484 | __ addl(temp_reg, constant_area); |
| 7485 | |
| 7486 | // And jump. |
| 7487 | __ jmp(temp_reg); |
| 7488 | } |
| 7489 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7490 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7491 | HX86ComputeBaseMethodAddress* insn) { |
| 7492 | LocationSummary* locations = |
| 7493 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7494 | locations->SetOut(Location::RequiresRegister()); |
| 7495 | } |
| 7496 | |
| 7497 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7498 | HX86ComputeBaseMethodAddress* insn) { |
| 7499 | LocationSummary* locations = insn->GetLocations(); |
| 7500 | Register reg = locations->Out().AsRegister<Register>(); |
| 7501 | |
| 7502 | // Generate call to next instruction. |
| 7503 | Label next_instruction; |
| 7504 | __ call(&next_instruction); |
| 7505 | __ Bind(&next_instruction); |
| 7506 | |
| 7507 | // Remember this offset for later use with constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7508 | codegen_->AddMethodAddressOffset(insn, GetAssembler()->CodeSize()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7509 | |
| 7510 | // Grab the return address off the stack. |
| 7511 | __ popl(reg); |
| 7512 | } |
| 7513 | |
| 7514 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7515 | HX86LoadFromConstantTable* insn) { |
| 7516 | LocationSummary* locations = |
| 7517 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7518 | |
| 7519 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7520 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7521 | |
| 7522 | // 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] | 7523 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7524 | return; |
| 7525 | } |
| 7526 | |
| 7527 | switch (insn->GetType()) { |
| 7528 | case Primitive::kPrimFloat: |
| 7529 | case Primitive::kPrimDouble: |
| 7530 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7531 | break; |
| 7532 | |
| 7533 | case Primitive::kPrimInt: |
| 7534 | locations->SetOut(Location::RequiresRegister()); |
| 7535 | break; |
| 7536 | |
| 7537 | default: |
| 7538 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7539 | } |
| 7540 | } |
| 7541 | |
| 7542 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7543 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7544 | return; |
| 7545 | } |
| 7546 | |
| 7547 | LocationSummary* locations = insn->GetLocations(); |
| 7548 | Location out = locations->Out(); |
| 7549 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7550 | HConstant *value = insn->GetConstant(); |
| 7551 | |
| 7552 | switch (insn->GetType()) { |
| 7553 | case Primitive::kPrimFloat: |
| 7554 | __ movss(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7555 | codegen_->LiteralFloatAddress( |
| 7556 | value->AsFloatConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7557 | break; |
| 7558 | |
| 7559 | case Primitive::kPrimDouble: |
| 7560 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7561 | codegen_->LiteralDoubleAddress( |
| 7562 | value->AsDoubleConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7563 | break; |
| 7564 | |
| 7565 | case Primitive::kPrimInt: |
| 7566 | __ movl(out.AsRegister<Register>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7567 | codegen_->LiteralInt32Address( |
| 7568 | value->AsIntConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7569 | break; |
| 7570 | |
| 7571 | default: |
| 7572 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7573 | } |
| 7574 | } |
| 7575 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7576 | /** |
| 7577 | * Class to handle late fixup of offsets into constant area. |
| 7578 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7579 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7580 | public: |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7581 | RIPFixup(CodeGeneratorX86& codegen, |
| 7582 | HX86ComputeBaseMethodAddress* base_method_address, |
| 7583 | size_t offset) |
| 7584 | : codegen_(&codegen), |
| 7585 | base_method_address_(base_method_address), |
| 7586 | offset_into_constant_area_(offset) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7587 | |
| 7588 | protected: |
| 7589 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7590 | |
| 7591 | CodeGeneratorX86* codegen_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7592 | HX86ComputeBaseMethodAddress* base_method_address_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7593 | |
| 7594 | private: |
| 7595 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7596 | // Patch the correct offset for the instruction. The place to patch is the |
| 7597 | // last 4 bytes of the instruction. |
| 7598 | // The value to patch is the distance from the offset in the constant area |
| 7599 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7600 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7601 | int32_t relative_position = |
| 7602 | constant_offset - codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7603 | |
| 7604 | // Patch in the right value. |
| 7605 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7606 | } |
| 7607 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7608 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7609 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7610 | }; |
| 7611 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7612 | /** |
| 7613 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7614 | * constant area. |
| 7615 | */ |
| 7616 | class JumpTableRIPFixup : public RIPFixup { |
| 7617 | public: |
| 7618 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7619 | : RIPFixup(codegen, switch_instr->GetBaseMethodAddress(), static_cast<size_t>(-1)), |
| 7620 | switch_instr_(switch_instr) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7621 | |
| 7622 | void CreateJumpTable() { |
| 7623 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7624 | |
| 7625 | // Ensure that the reference to the jump table has the correct offset. |
| 7626 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7627 | SetOffset(offset_in_constant_table); |
| 7628 | |
| 7629 | // The label values in the jump table are computed relative to the |
| 7630 | // instruction addressing the constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7631 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7632 | |
| 7633 | // Populate the jump table with the correct values for the jump table. |
| 7634 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7635 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7636 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7637 | // The value that we want is the target offset - the position of the table. |
| 7638 | for (int32_t i = 0; i < num_entries; i++) { |
| 7639 | HBasicBlock* b = successors[i]; |
| 7640 | Label* l = codegen_->GetLabelOf(b); |
| 7641 | DCHECK(l->IsBound()); |
| 7642 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7643 | assembler->AppendInt32(offset_to_block); |
| 7644 | } |
| 7645 | } |
| 7646 | |
| 7647 | private: |
| 7648 | const HX86PackedSwitch* switch_instr_; |
| 7649 | }; |
| 7650 | |
| 7651 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7652 | // Generate the constant area if needed. |
| 7653 | X86Assembler* assembler = GetAssembler(); |
| 7654 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7655 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7656 | // byte values. |
| 7657 | assembler->Align(4, 0); |
| 7658 | constant_area_start_ = assembler->CodeSize(); |
| 7659 | |
| 7660 | // Populate any jump tables. |
| 7661 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7662 | jump_table->CreateJumpTable(); |
| 7663 | } |
| 7664 | |
| 7665 | // And now add the constant area to the generated code. |
| 7666 | assembler->AddConstantArea(); |
| 7667 | } |
| 7668 | |
| 7669 | // And finish up. |
| 7670 | CodeGenerator::Finalize(allocator); |
| 7671 | } |
| 7672 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7673 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, |
| 7674 | HX86ComputeBaseMethodAddress* method_base, |
| 7675 | Register reg) { |
| 7676 | AssemblerFixup* fixup = |
| 7677 | new (GetGraph()->GetArena()) RIPFixup(*this, method_base, __ AddDouble(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7678 | return Address(reg, kDummy32BitOffset, fixup); |
| 7679 | } |
| 7680 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7681 | Address CodeGeneratorX86::LiteralFloatAddress(float v, |
| 7682 | HX86ComputeBaseMethodAddress* method_base, |
| 7683 | Register reg) { |
| 7684 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, method_base, __ AddFloat(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7685 | return Address(reg, kDummy32BitOffset, fixup); |
| 7686 | } |
| 7687 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7688 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, |
| 7689 | HX86ComputeBaseMethodAddress* method_base, |
| 7690 | Register reg) { |
| 7691 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, method_base, __ AddInt32(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7692 | return Address(reg, kDummy32BitOffset, fixup); |
| 7693 | } |
| 7694 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7695 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, |
| 7696 | HX86ComputeBaseMethodAddress* method_base, |
| 7697 | Register reg) { |
| 7698 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, method_base, __ AddInt64(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7699 | return Address(reg, kDummy32BitOffset, fixup); |
| 7700 | } |
| 7701 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7702 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7703 | if (value == 0) { |
| 7704 | __ xorl(dest, dest); |
| 7705 | } else { |
| 7706 | __ movl(dest, Immediate(value)); |
| 7707 | } |
| 7708 | } |
| 7709 | |
| 7710 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7711 | if (value == 0) { |
| 7712 | __ testl(dest, dest); |
| 7713 | } else { |
| 7714 | __ cmpl(dest, Immediate(value)); |
| 7715 | } |
| 7716 | } |
| 7717 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7718 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 7719 | Register lhs_reg = lhs.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7720 | GenerateIntCompare(lhs_reg, rhs); |
| 7721 | } |
| 7722 | |
| 7723 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7724 | if (rhs.IsConstant()) { |
| 7725 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7726 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7727 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7728 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7729 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7730 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7731 | } |
| 7732 | } |
| 7733 | |
| 7734 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 7735 | Location index, |
| 7736 | ScaleFactor scale, |
| 7737 | uint32_t data_offset) { |
| 7738 | return index.IsConstant() ? |
| 7739 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 7740 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 7741 | } |
| 7742 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7743 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7744 | Register reg, |
| 7745 | Register value) { |
| 7746 | // Create a fixup to be used to create and address the jump table. |
| 7747 | JumpTableRIPFixup* table_fixup = |
| 7748 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7749 | |
| 7750 | // We have to populate the jump tables. |
| 7751 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7752 | |
| 7753 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7754 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7755 | } |
| 7756 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7757 | // TODO: target as memory. |
| 7758 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7759 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7760 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7761 | return; |
| 7762 | } |
| 7763 | |
| 7764 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7765 | |
| 7766 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7767 | if (target.Equals(return_loc)) { |
| 7768 | return; |
| 7769 | } |
| 7770 | |
| 7771 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7772 | // with the else branch. |
| 7773 | if (type == Primitive::kPrimLong) { |
| 7774 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7775 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7776 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7777 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7778 | } else { |
| 7779 | // Let the parallel move resolver take care of all of this. |
| 7780 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7781 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7782 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7783 | } |
| 7784 | } |
| 7785 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7786 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, |
| 7787 | const uint8_t* roots_data, |
| 7788 | const PatchInfo<Label>& info, |
| 7789 | uint64_t index_in_table) const { |
| 7790 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7791 | uintptr_t address = |
| 7792 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7793 | typedef __attribute__((__aligned__(1))) uint32_t unaligned_uint32_t; |
| 7794 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7795 | dchecked_integral_cast<uint32_t>(address); |
| 7796 | } |
| 7797 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7798 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7799 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7800 | const auto& it = jit_string_roots_.find( |
| 7801 | StringReference(&info.dex_file, dex::StringIndex(info.index))); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7802 | DCHECK(it != jit_string_roots_.end()); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7803 | PatchJitRootUse(code, roots_data, info, it->second); |
| 7804 | } |
| 7805 | |
| 7806 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
| 7807 | const auto& it = jit_class_roots_.find( |
| 7808 | TypeReference(&info.dex_file, dex::TypeIndex(info.index))); |
| 7809 | DCHECK(it != jit_class_roots_.end()); |
| 7810 | PatchJitRootUse(code, roots_data, info, it->second); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7811 | } |
| 7812 | } |
| 7813 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7814 | #undef __ |
| 7815 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7816 | } // namespace x86 |
| 7817 | } // namespace art |