Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_x86_64.h" |
| 18 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method.h" |
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 | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 23 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 24 | #include "intrinsics.h" |
| 25 | #include "intrinsics_x86_64.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 26 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 27 | #include "mirror/class-inl.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 28 | #include "mirror/object_reference.h" |
| 29 | #include "thread.h" |
| 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 | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 32 | #include "utils/x86_64/assembler_x86_64.h" |
| 33 | #include "utils/x86_64/managed_register_x86_64.h" |
| 34 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 35 | namespace art { |
| 36 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 37 | template<class MirrorType> |
| 38 | class GcRoot; |
| 39 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 40 | namespace x86_64 { |
| 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 = RDI; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 44 | |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 45 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 46 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 47 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 48 | static constexpr int kC2ConditionMask = 0x400; |
| 49 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 50 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 51 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 52 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 53 | class NullCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 54 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 55 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 56 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 57 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 58 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 59 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 60 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 61 | // Live registers will be restored in the catch block if caught. |
| 62 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 63 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 64 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 65 | instruction_, |
| 66 | instruction_->GetDexPc(), |
| 67 | this); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 68 | } |
| 69 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 70 | bool IsFatal() const OVERRIDE { return true; } |
| 71 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 72 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86_64"; } |
| 73 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 74 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 75 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 76 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 77 | }; |
| 78 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 79 | class DivZeroCheckSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 80 | public: |
| 81 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 82 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 83 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 84 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 85 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 86 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 87 | // Live registers will be restored in the catch block if caught. |
| 88 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 89 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 90 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 91 | instruction_, |
| 92 | instruction_->GetDexPc(), |
| 93 | this); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 96 | bool IsFatal() const OVERRIDE { return true; } |
| 97 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 98 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86_64"; } |
| 99 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 100 | private: |
| 101 | HDivZeroCheck* const instruction_; |
| 102 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 103 | }; |
| 104 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 105 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 106 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 107 | DivRemMinusOneSlowPathX86_64(Register reg, Primitive::Type type, bool is_div) |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 108 | : cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 110 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 | __ Bind(GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 112 | if (type_ == Primitive::kPrimInt) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 113 | if (is_div_) { |
| 114 | __ negl(cpu_reg_); |
| 115 | } else { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 116 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 119 | } else { |
| 120 | DCHECK_EQ(Primitive::kPrimLong, type_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 121 | if (is_div_) { |
| 122 | __ negq(cpu_reg_); |
| 123 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 124 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 125 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 126 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 127 | __ jmp(GetExitLabel()); |
| 128 | } |
| 129 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 130 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86_64"; } |
| 131 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 132 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 133 | const CpuRegister cpu_reg_; |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 134 | const Primitive::Type type_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 135 | const bool is_div_; |
| 136 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 137 | }; |
| 138 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 139 | class SuspendCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 140 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 141 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 142 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 143 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 144 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 145 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 146 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 147 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 148 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 149 | instruction_, |
| 150 | instruction_->GetDexPc(), |
| 151 | this); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 152 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 153 | if (successor_ == nullptr) { |
| 154 | __ jmp(GetReturnLabel()); |
| 155 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 156 | __ jmp(x86_64_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 157 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 160 | Label* GetReturnLabel() { |
| 161 | DCHECK(successor_ == nullptr); |
| 162 | return &return_label_; |
| 163 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 164 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 165 | HBasicBlock* GetSuccessor() const { |
| 166 | return successor_; |
| 167 | } |
| 168 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 169 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 170 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 171 | private: |
| 172 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 173 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 174 | Label return_label_; |
| 175 | |
| 176 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 177 | }; |
| 178 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 179 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 180 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 181 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
| 182 | : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 183 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 184 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 185 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 186 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 187 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 188 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 189 | // Live registers will be restored in the catch block if caught. |
| 190 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 191 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 192 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 193 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 194 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 195 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 196 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 197 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 198 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 199 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 200 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 201 | Primitive::kPrimInt); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 202 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 203 | instruction_, |
| 204 | instruction_->GetDexPc(), |
| 205 | this); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 206 | } |
| 207 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 208 | bool IsFatal() const OVERRIDE { return true; } |
| 209 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 210 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 211 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 212 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 213 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 214 | |
| 215 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 216 | }; |
| 217 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 218 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 219 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 220 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 221 | HInstruction* at, |
| 222 | uint32_t dex_pc, |
| 223 | bool do_clinit) |
| 224 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 225 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 226 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 227 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 228 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 229 | LocationSummary* locations = at_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 230 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 231 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 232 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 233 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 234 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 235 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 236 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(cls_->GetTypeIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 237 | x86_64_codegen->InvokeRuntime(do_clinit_ ? |
| 238 | QUICK_ENTRY_POINT(pInitializeStaticStorage) : |
| 239 | QUICK_ENTRY_POINT(pInitializeType), |
| 240 | at_, |
| 241 | dex_pc_, |
| 242 | this); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 243 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 244 | Location out = locations->Out(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 245 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 246 | if (out.IsValid()) { |
| 247 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 248 | x86_64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 249 | } |
| 250 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 251 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 252 | __ jmp(GetExitLabel()); |
| 253 | } |
| 254 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 255 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 256 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 257 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 258 | // The class this slow path will load. |
| 259 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 260 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 261 | // The instruction where this slow path is happening. |
| 262 | // (Might be the load class or an initialization check). |
| 263 | HInstruction* const at_; |
| 264 | |
| 265 | // The dex PC of `at_`. |
| 266 | const uint32_t dex_pc_; |
| 267 | |
| 268 | // Whether to initialize the class. |
| 269 | const bool do_clinit_; |
| 270 | |
| 271 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 272 | }; |
| 273 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 274 | class LoadStringSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 275 | public: |
| 276 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : instruction_(instruction) {} |
| 277 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 278 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 279 | LocationSummary* locations = instruction_->GetLocations(); |
| 280 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 281 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 282 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 283 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 284 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 285 | |
| 286 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 287 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 288 | Immediate(instruction_->GetStringIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 289 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 290 | instruction_, |
| 291 | instruction_->GetDexPc(), |
| 292 | this); |
| 293 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 294 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 295 | __ jmp(GetExitLabel()); |
| 296 | } |
| 297 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 298 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86_64"; } |
| 299 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 300 | private: |
| 301 | HLoadString* const instruction_; |
| 302 | |
| 303 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 304 | }; |
| 305 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 306 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 307 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 308 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
| 309 | : instruction_(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 310 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 311 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 312 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 313 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 314 | : locations->Out(); |
| 315 | uint32_t dex_pc = instruction_->GetDexPc(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 316 | DCHECK(instruction_->IsCheckCast() |
| 317 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 318 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 319 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 320 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 321 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 322 | if (!is_fatal_) { |
| 323 | SaveLiveRegisters(codegen, locations); |
| 324 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 325 | |
| 326 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 327 | // move resolver. |
| 328 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 329 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 330 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 331 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 332 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 333 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 334 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 335 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 336 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 337 | if (instruction_->IsInstanceOf()) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 338 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 339 | instruction_, |
| 340 | dex_pc, |
| 341 | this); |
| 342 | CheckEntrypointTypes< |
| 343 | kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 344 | } else { |
| 345 | DCHECK(instruction_->IsCheckCast()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 346 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 347 | instruction_, |
| 348 | dex_pc, |
| 349 | this); |
| 350 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 351 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 352 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 353 | if (!is_fatal_) { |
| 354 | if (instruction_->IsInstanceOf()) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 355 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 356 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 357 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 358 | RestoreLiveRegisters(codegen, locations); |
| 359 | __ jmp(GetExitLabel()); |
| 360 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 361 | } |
| 362 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 363 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 364 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 365 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 366 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 367 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 368 | HInstruction* const instruction_; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 369 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 370 | |
| 371 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 372 | }; |
| 373 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 374 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 375 | public: |
| 376 | explicit DeoptimizationSlowPathX86_64(HInstruction* instruction) |
| 377 | : instruction_(instruction) {} |
| 378 | |
| 379 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 380 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 381 | __ Bind(GetEntryLabel()); |
| 382 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 383 | DCHECK(instruction_->IsDeoptimize()); |
| 384 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 385 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 386 | deoptimize, |
| 387 | deoptimize->GetDexPc(), |
| 388 | this); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 391 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 392 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 393 | private: |
| 394 | HInstruction* const instruction_; |
| 395 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 396 | }; |
| 397 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 398 | class ArraySetSlowPathX86_64 : public SlowPathCode { |
| 399 | public: |
| 400 | explicit ArraySetSlowPathX86_64(HInstruction* instruction) : instruction_(instruction) {} |
| 401 | |
| 402 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 403 | LocationSummary* locations = instruction_->GetLocations(); |
| 404 | __ Bind(GetEntryLabel()); |
| 405 | SaveLiveRegisters(codegen, locations); |
| 406 | |
| 407 | InvokeRuntimeCallingConvention calling_convention; |
| 408 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 409 | parallel_move.AddMove( |
| 410 | locations->InAt(0), |
| 411 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 412 | Primitive::kPrimNot, |
| 413 | nullptr); |
| 414 | parallel_move.AddMove( |
| 415 | locations->InAt(1), |
| 416 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 417 | Primitive::kPrimInt, |
| 418 | nullptr); |
| 419 | parallel_move.AddMove( |
| 420 | locations->InAt(2), |
| 421 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 422 | Primitive::kPrimNot, |
| 423 | nullptr); |
| 424 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 425 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 426 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 427 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 428 | instruction_, |
| 429 | instruction_->GetDexPc(), |
| 430 | this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 431 | RestoreLiveRegisters(codegen, locations); |
| 432 | __ jmp(GetExitLabel()); |
| 433 | } |
| 434 | |
| 435 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86_64"; } |
| 436 | |
| 437 | private: |
| 438 | HInstruction* const instruction_; |
| 439 | |
| 440 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 441 | }; |
| 442 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 443 | // Slow path generating a read barrier for a heap reference. |
| 444 | class ReadBarrierForHeapReferenceSlowPathX86_64 : public SlowPathCode { |
| 445 | public: |
| 446 | ReadBarrierForHeapReferenceSlowPathX86_64(HInstruction* instruction, |
| 447 | Location out, |
| 448 | Location ref, |
| 449 | Location obj, |
| 450 | uint32_t offset, |
| 451 | Location index) |
| 452 | : instruction_(instruction), |
| 453 | out_(out), |
| 454 | ref_(ref), |
| 455 | obj_(obj), |
| 456 | offset_(offset), |
| 457 | index_(index) { |
| 458 | DCHECK(kEmitCompilerReadBarrier); |
| 459 | // If `obj` is equal to `out` or `ref`, it means the initial |
| 460 | // object has been overwritten by (or after) the heap object |
| 461 | // reference load to be instrumented, e.g.: |
| 462 | // |
| 463 | // __ movl(out, Address(out, offset)); |
| 464 | // codegen_->GenerateReadBarrier(instruction, out_loc, out_loc, out_loc, offset); |
| 465 | // |
| 466 | // In that case, we have lost the information about the original |
| 467 | // object, and the emitted read barrier cannot work properly. |
| 468 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 469 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 470 | } |
| 471 | |
| 472 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 473 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 474 | LocationSummary* locations = instruction_->GetLocations(); |
| 475 | CpuRegister reg_out = out_.AsRegister<CpuRegister>(); |
| 476 | DCHECK(locations->CanCall()); |
| 477 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.AsRegister())) << out_; |
| 478 | DCHECK(!instruction_->IsInvoke() || |
| 479 | (instruction_->IsInvokeStaticOrDirect() && |
| 480 | instruction_->GetLocations()->Intrinsified())); |
| 481 | |
| 482 | __ Bind(GetEntryLabel()); |
| 483 | SaveLiveRegisters(codegen, locations); |
| 484 | |
| 485 | // We may have to change the index's value, but as `index_` is a |
| 486 | // constant member (like other "inputs" of this slow path), |
| 487 | // introduce a copy of it, `index`. |
| 488 | Location index = index_; |
| 489 | if (index_.IsValid()) { |
| 490 | // Handle `index_` for HArrayGet and intrinsic UnsafeGetObject. |
| 491 | if (instruction_->IsArrayGet()) { |
| 492 | // Compute real offset and store it in index_. |
| 493 | Register index_reg = index_.AsRegister<CpuRegister>().AsRegister(); |
| 494 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 495 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 496 | // We are about to change the value of `index_reg` (see the |
| 497 | // calls to art::x86_64::X86_64Assembler::shll and |
| 498 | // art::x86_64::X86_64Assembler::AddImmediate below), but it |
| 499 | // has not been saved by the previous call to |
| 500 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 501 | // callee-save register -- |
| 502 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 503 | // callee-save registers, as it has been designed with the |
| 504 | // assumption that callee-save registers are supposed to be |
| 505 | // handled by the called function. So, as a callee-save |
| 506 | // register, `index_reg` _would_ eventually be saved onto |
| 507 | // the stack, but it would be too late: we would have |
| 508 | // changed its value earlier. Therefore, we manually save |
| 509 | // it here into another freely available register, |
| 510 | // `free_reg`, chosen of course among the caller-save |
| 511 | // registers (as a callee-save `free_reg` register would |
| 512 | // exhibit the same problem). |
| 513 | // |
| 514 | // Note we could have requested a temporary register from |
| 515 | // the register allocator instead; but we prefer not to, as |
| 516 | // this is a slow path, and we know we can find a |
| 517 | // caller-save register that is available. |
| 518 | Register free_reg = FindAvailableCallerSaveRegister(codegen).AsRegister(); |
| 519 | __ movl(CpuRegister(free_reg), CpuRegister(index_reg)); |
| 520 | index_reg = free_reg; |
| 521 | index = Location::RegisterLocation(index_reg); |
| 522 | } else { |
| 523 | // The initial register stored in `index_` has already been |
| 524 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 525 | // (as it is not a callee-save register), so we can freely |
| 526 | // use it. |
| 527 | } |
| 528 | // Shifting the index value contained in `index_reg` by the |
| 529 | // scale factor (2) cannot overflow in practice, as the |
| 530 | // runtime is unable to allocate object arrays with a size |
| 531 | // larger than 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 532 | __ shll(CpuRegister(index_reg), Immediate(TIMES_4)); |
| 533 | static_assert( |
| 534 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 535 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 536 | __ AddImmediate(CpuRegister(index_reg), Immediate(offset_)); |
| 537 | } else { |
| 538 | DCHECK(instruction_->IsInvoke()); |
| 539 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 540 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 541 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 542 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 543 | DCHECK_EQ(offset_, 0U); |
| 544 | DCHECK(index_.IsRegister()); |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | // We're moving two or three locations to locations that could |
| 549 | // overlap, so we need a parallel move resolver. |
| 550 | InvokeRuntimeCallingConvention calling_convention; |
| 551 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 552 | parallel_move.AddMove(ref_, |
| 553 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 554 | Primitive::kPrimNot, |
| 555 | nullptr); |
| 556 | parallel_move.AddMove(obj_, |
| 557 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 558 | Primitive::kPrimNot, |
| 559 | nullptr); |
| 560 | if (index.IsValid()) { |
| 561 | parallel_move.AddMove(index, |
| 562 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 563 | Primitive::kPrimInt, |
| 564 | nullptr); |
| 565 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 566 | } else { |
| 567 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 568 | __ movl(CpuRegister(calling_convention.GetRegisterAt(2)), Immediate(offset_)); |
| 569 | } |
| 570 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 571 | instruction_, |
| 572 | instruction_->GetDexPc(), |
| 573 | this); |
| 574 | CheckEntrypointTypes< |
| 575 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 576 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 577 | |
| 578 | RestoreLiveRegisters(codegen, locations); |
| 579 | __ jmp(GetExitLabel()); |
| 580 | } |
| 581 | |
| 582 | const char* GetDescription() const OVERRIDE { |
| 583 | return "ReadBarrierForHeapReferenceSlowPathX86_64"; |
| 584 | } |
| 585 | |
| 586 | private: |
| 587 | CpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 588 | size_t ref = static_cast<int>(ref_.AsRegister<CpuRegister>().AsRegister()); |
| 589 | size_t obj = static_cast<int>(obj_.AsRegister<CpuRegister>().AsRegister()); |
| 590 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 591 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 592 | return static_cast<CpuRegister>(i); |
| 593 | } |
| 594 | } |
| 595 | // We shall never fail to find a free caller-save register, as |
| 596 | // there are more than two core caller-save registers on x86-64 |
| 597 | // (meaning it is possible to find one which is different from |
| 598 | // `ref` and `obj`). |
| 599 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 600 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 601 | UNREACHABLE(); |
| 602 | } |
| 603 | |
| 604 | HInstruction* const instruction_; |
| 605 | const Location out_; |
| 606 | const Location ref_; |
| 607 | const Location obj_; |
| 608 | const uint32_t offset_; |
| 609 | // An additional location containing an index to an array. |
| 610 | // Only used for HArrayGet and the UnsafeGetObject & |
| 611 | // UnsafeGetObjectVolatile intrinsics. |
| 612 | const Location index_; |
| 613 | |
| 614 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86_64); |
| 615 | }; |
| 616 | |
| 617 | // Slow path generating a read barrier for a GC root. |
| 618 | class ReadBarrierForRootSlowPathX86_64 : public SlowPathCode { |
| 619 | public: |
| 620 | ReadBarrierForRootSlowPathX86_64(HInstruction* instruction, Location out, Location root) |
| 621 | : instruction_(instruction), out_(out), root_(root) {} |
| 622 | |
| 623 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 624 | LocationSummary* locations = instruction_->GetLocations(); |
| 625 | DCHECK(locations->CanCall()); |
| 626 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
| 627 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()); |
| 628 | |
| 629 | __ Bind(GetEntryLabel()); |
| 630 | SaveLiveRegisters(codegen, locations); |
| 631 | |
| 632 | InvokeRuntimeCallingConvention calling_convention; |
| 633 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 634 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| 635 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 636 | instruction_, |
| 637 | instruction_->GetDexPc(), |
| 638 | this); |
| 639 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 640 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 641 | |
| 642 | RestoreLiveRegisters(codegen, locations); |
| 643 | __ jmp(GetExitLabel()); |
| 644 | } |
| 645 | |
| 646 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86_64"; } |
| 647 | |
| 648 | private: |
| 649 | HInstruction* const instruction_; |
| 650 | const Location out_; |
| 651 | const Location root_; |
| 652 | |
| 653 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86_64); |
| 654 | }; |
| 655 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 656 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 657 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 658 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 659 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 660 | switch (cond) { |
| 661 | case kCondEQ: return kEqual; |
| 662 | case kCondNE: return kNotEqual; |
| 663 | case kCondLT: return kLess; |
| 664 | case kCondLE: return kLessEqual; |
| 665 | case kCondGT: return kGreater; |
| 666 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 667 | case kCondB: return kBelow; |
| 668 | case kCondBE: return kBelowEqual; |
| 669 | case kCondA: return kAbove; |
| 670 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 671 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 672 | LOG(FATAL) << "Unreachable"; |
| 673 | UNREACHABLE(); |
| 674 | } |
| 675 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 676 | // Maps FP condition to x86_64 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 677 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 678 | switch (cond) { |
| 679 | case kCondEQ: return kEqual; |
| 680 | case kCondNE: return kNotEqual; |
| 681 | case kCondLT: return kBelow; |
| 682 | case kCondLE: return kBelowEqual; |
| 683 | case kCondGT: return kAbove; |
| 684 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 685 | default: break; // should not happen |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 686 | }; |
| 687 | LOG(FATAL) << "Unreachable"; |
| 688 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 689 | } |
| 690 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 691 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86_64::GetSupportedInvokeStaticOrDirectDispatch( |
| 692 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 693 | MethodReference target_method ATTRIBUTE_UNUSED) { |
| 694 | switch (desired_dispatch_info.code_ptr_location) { |
| 695 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 696 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 697 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 698 | return HInvokeStaticOrDirect::DispatchInfo { |
| 699 | desired_dispatch_info.method_load_kind, |
| 700 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 701 | desired_dispatch_info.method_load_data, |
| 702 | 0u |
| 703 | }; |
| 704 | default: |
| 705 | return desired_dispatch_info; |
| 706 | } |
| 707 | } |
| 708 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 709 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 710 | Location temp) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 711 | // All registers are assumed to be correctly set up. |
| 712 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 713 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 714 | switch (invoke->GetMethodLoadKind()) { |
| 715 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 716 | // temp = thread->string_init_entrypoint |
| 717 | __ gs()->movl(temp.AsRegister<CpuRegister>(), |
| 718 | Address::Absolute(invoke->GetStringInitOffset(), true)); |
| 719 | break; |
| 720 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 721 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 722 | break; |
| 723 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 724 | __ movq(temp.AsRegister<CpuRegister>(), Immediate(invoke->GetMethodAddress())); |
| 725 | break; |
| 726 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 727 | __ movl(temp.AsRegister<CpuRegister>(), Immediate(0)); // Placeholder. |
| 728 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 729 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 730 | break; |
| 731 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 732 | pc_relative_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 733 | invoke->GetDexCacheArrayOffset()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 734 | __ movq(temp.AsRegister<CpuRegister>(), |
| 735 | Address::Absolute(kDummy32BitOffset, false /* no_rip */)); |
| 736 | // Bind the label at the end of the "movl" insn. |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 737 | __ Bind(&pc_relative_dex_cache_patches_.back().label); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 738 | break; |
| 739 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 740 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 741 | Register method_reg; |
| 742 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
| 743 | if (current_method.IsRegister()) { |
| 744 | method_reg = current_method.AsRegister<Register>(); |
| 745 | } else { |
| 746 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 747 | DCHECK(!current_method.IsValid()); |
| 748 | method_reg = reg.AsRegister(); |
| 749 | __ movq(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 750 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 751 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 752 | __ movq(reg, |
| 753 | Address(CpuRegister(method_reg), |
| 754 | ArtMethod::DexCacheResolvedMethodsOffset(kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 755 | // temp = temp[index_in_cache] |
| 756 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 757 | __ movq(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 758 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 759 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | switch (invoke->GetCodePtrLocation()) { |
| 763 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 764 | __ call(&frame_entry_label_); |
| 765 | break; |
| 766 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 767 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 768 | Label* label = &relative_call_patches_.back().label; |
| 769 | __ call(label); // Bind to the patch label, override at link time. |
| 770 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 771 | break; |
| 772 | } |
| 773 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 774 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 775 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 776 | LOG(FATAL) << "Unsupported"; |
| 777 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 778 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 779 | // (callee_method + offset_of_quick_compiled_code)() |
| 780 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 781 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 782 | kX86_64WordSize).SizeValue())); |
| 783 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 784 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 785 | |
| 786 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 787 | } |
| 788 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 789 | void CodeGeneratorX86_64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 790 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 791 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 792 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
| 793 | LocationSummary* locations = invoke->GetLocations(); |
| 794 | Location receiver = locations->InAt(0); |
| 795 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 796 | DCHECK(receiver.IsRegister()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 797 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 798 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
| 799 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 800 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 801 | // emit a read barrier for the previous class reference load. |
| 802 | // However this is not required in practice, as this is an |
| 803 | // intermediate/temporary reference and because the current |
| 804 | // concurrent copying collector keeps the from-space memory |
| 805 | // intact/accessible until the end of the marking phase (the |
| 806 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 807 | __ MaybeUnpoisonHeapReference(temp); |
| 808 | // temp = temp->GetMethodAt(method_offset); |
| 809 | __ movq(temp, Address(temp, method_offset)); |
| 810 | // call temp->GetEntryPoint(); |
| 811 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 812 | kX86_64WordSize).SizeValue())); |
| 813 | } |
| 814 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 815 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 816 | DCHECK(linker_patches->empty()); |
| 817 | size_t size = |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 818 | method_patches_.size() + |
| 819 | relative_call_patches_.size() + |
| 820 | pc_relative_dex_cache_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 821 | linker_patches->reserve(size); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 822 | // The label points to the end of the "movl" insn but the literal offset for method |
| 823 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 824 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 825 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 826 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 827 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 828 | info.target_method.dex_file, |
| 829 | info.target_method.dex_method_index)); |
| 830 | } |
| 831 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 832 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 833 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 834 | info.target_method.dex_file, |
| 835 | info.target_method.dex_method_index)); |
| 836 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 837 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 838 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 839 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 840 | &info.target_dex_file, |
| 841 | info.label.Position(), |
| 842 | info.element_offset)); |
| 843 | } |
| 844 | } |
| 845 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 846 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 847 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 851 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 852 | } |
| 853 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 854 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 855 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 856 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 857 | } |
| 858 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 859 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 860 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 861 | return kX86_64WordSize; |
| 862 | } |
| 863 | |
| 864 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 865 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 866 | return kX86_64WordSize; |
| 867 | } |
| 868 | |
| 869 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 870 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 871 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 872 | } |
| 873 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 874 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 875 | HInstruction* instruction, |
| 876 | uint32_t dex_pc, |
| 877 | SlowPathCode* slow_path) { |
| 878 | InvokeRuntime(GetThreadOffset<kX86_64WordSize>(entrypoint).Int32Value(), |
| 879 | instruction, |
| 880 | dex_pc, |
| 881 | slow_path); |
| 882 | } |
| 883 | |
| 884 | void CodeGeneratorX86_64::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 885 | HInstruction* instruction, |
| 886 | uint32_t dex_pc, |
| 887 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 888 | ValidateInvokeRuntime(instruction, slow_path); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 889 | __ gs()->call(Address::Absolute(entry_point_offset, true)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 890 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 891 | } |
| 892 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 893 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 894 | // Use a fake return address register to mimic Quick. |
| 895 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 896 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 897 | const X86_64InstructionSetFeatures& isa_features, |
| 898 | const CompilerOptions& compiler_options, |
| 899 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 900 | : CodeGenerator(graph, |
| 901 | kNumberOfCpuRegisters, |
| 902 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 903 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 904 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 905 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 906 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 907 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 908 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 909 | compiler_options, |
| 910 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 911 | block_labels_(nullptr), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 912 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 913 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 914 | move_resolver_(graph->GetArena(), this), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 915 | isa_features_(isa_features), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 916 | constant_area_start_(0), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 917 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 918 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 919 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 920 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 921 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 922 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 923 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 924 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 925 | CodeGeneratorX86_64* codegen) |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 926 | : HGraphVisitor(graph), |
| 927 | assembler_(codegen->GetAssembler()), |
| 928 | codegen_(codegen) {} |
| 929 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 930 | Location CodeGeneratorX86_64::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 931 | switch (type) { |
| 932 | case Primitive::kPrimLong: |
| 933 | case Primitive::kPrimByte: |
| 934 | case Primitive::kPrimBoolean: |
| 935 | case Primitive::kPrimChar: |
| 936 | case Primitive::kPrimShort: |
| 937 | case Primitive::kPrimInt: |
| 938 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 939 | size_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 940 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 944 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 945 | size_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfFloatRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 946 | return Location::FpuRegisterLocation(reg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 947 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 948 | |
| 949 | case Primitive::kPrimVoid: |
| 950 | LOG(FATAL) << "Unreachable type " << type; |
| 951 | } |
| 952 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 953 | return Location::NoLocation(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 954 | } |
| 955 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 956 | void CodeGeneratorX86_64::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 957 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 958 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 959 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 960 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 961 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 962 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 963 | if (is_baseline) { |
| 964 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 965 | blocked_core_registers_[kCoreCalleeSaves[i]] = true; |
| 966 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 967 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 968 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 969 | } |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 970 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 971 | } |
| 972 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 973 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 974 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 975 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 976 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 977 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 978 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 979 | } |
| 980 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 981 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 982 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 983 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 984 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 985 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 986 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 987 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 988 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 989 | __ testq(CpuRegister(RAX), Address( |
| 990 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 991 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 992 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 993 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 994 | if (HasEmptyFrame()) { |
| 995 | return; |
| 996 | } |
| 997 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 998 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 999 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1000 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1001 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1002 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1003 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1004 | } |
| 1005 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1006 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1007 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1008 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 1009 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1010 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1011 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1012 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1013 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1014 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1015 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1016 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1017 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1018 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1019 | } |
| 1020 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1021 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1022 | CpuRegister(kMethodRegisterArgument)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1026 | __ cfi().RememberState(); |
| 1027 | if (!HasEmptyFrame()) { |
| 1028 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1029 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 1030 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1031 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1032 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1033 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1034 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1035 | } |
| 1036 | } |
| 1037 | |
| 1038 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1039 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 1040 | __ cfi().AdjustCFAOffset(-adjust); |
| 1041 | |
| 1042 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1043 | Register reg = kCoreCalleeSaves[i]; |
| 1044 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1045 | __ popq(CpuRegister(reg)); |
| 1046 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1047 | __ cfi().Restore(DWARFReg(reg)); |
| 1048 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1049 | } |
| 1050 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1051 | __ ret(); |
| 1052 | __ cfi().RestoreState(); |
| 1053 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1054 | } |
| 1055 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1056 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1057 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1058 | } |
| 1059 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1060 | Location CodeGeneratorX86_64::GetStackLocation(HLoadLocal* load) const { |
| 1061 | switch (load->GetType()) { |
| 1062 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1063 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1064 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1065 | |
| 1066 | case Primitive::kPrimInt: |
| 1067 | case Primitive::kPrimNot: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1068 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1069 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1070 | |
| 1071 | case Primitive::kPrimBoolean: |
| 1072 | case Primitive::kPrimByte: |
| 1073 | case Primitive::kPrimChar: |
| 1074 | case Primitive::kPrimShort: |
| 1075 | case Primitive::kPrimVoid: |
| 1076 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 1077 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 1081 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1085 | if (source.Equals(destination)) { |
| 1086 | return; |
| 1087 | } |
| 1088 | if (destination.IsRegister()) { |
| 1089 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1090 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1091 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1092 | __ movd(destination.AsRegister<CpuRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1093 | } else if (source.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1094 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1095 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1096 | } else { |
| 1097 | DCHECK(source.IsDoubleStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1098 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1099 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1100 | } |
| 1101 | } else if (destination.IsFpuRegister()) { |
| 1102 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1103 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1104 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1105 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1106 | } else if (source.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1107 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1108 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1109 | } else { |
| 1110 | DCHECK(source.IsDoubleStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1111 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1112 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1113 | } |
| 1114 | } else if (destination.IsStackSlot()) { |
| 1115 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1116 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1117 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1118 | } else if (source.IsFpuRegister()) { |
| 1119 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1120 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1121 | } else if (source.IsConstant()) { |
| 1122 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1123 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1124 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1125 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1126 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1127 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1128 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1129 | } |
| 1130 | } else { |
| 1131 | DCHECK(destination.IsDoubleStackSlot()); |
| 1132 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1133 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1134 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1135 | } else if (source.IsFpuRegister()) { |
| 1136 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1137 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1138 | } else if (source.IsConstant()) { |
| 1139 | HConstant* constant = source.GetConstant(); |
Zheng Xu | 12bca97 | 2015-03-30 19:35:50 +0800 | [diff] [blame] | 1140 | int64_t value; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1141 | if (constant->IsDoubleConstant()) { |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1142 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1143 | } else { |
| 1144 | DCHECK(constant->IsLongConstant()); |
| 1145 | value = constant->AsLongConstant()->GetValue(); |
| 1146 | } |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1147 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1148 | } else { |
| 1149 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1150 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1151 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1152 | } |
| 1153 | } |
| 1154 | } |
| 1155 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1156 | void CodeGeneratorX86_64::Move(HInstruction* instruction, |
| 1157 | Location location, |
| 1158 | HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1159 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1160 | if (instruction->IsCurrentMethod()) { |
Mathieu Chartier | e3b034a | 2015-05-31 14:29:23 -0700 | [diff] [blame] | 1161 | Move(location, Location::DoubleStackSlot(kCurrentMethodStackOffset)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1162 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1163 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1164 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1165 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1166 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 1167 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1168 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1169 | __ movl(location.AsRegister<CpuRegister>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1170 | } else if (location.IsStackSlot()) { |
| 1171 | __ movl(Address(CpuRegister(RSP), location.GetStackIndex()), imm); |
| 1172 | } else { |
| 1173 | DCHECK(location.IsConstant()); |
| 1174 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 1175 | } |
| 1176 | } else if (const_to_move->IsLongConstant()) { |
| 1177 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 1178 | if (location.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 1179 | Load64BitValue(location.AsRegister<CpuRegister>(), value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1180 | } else if (location.IsDoubleStackSlot()) { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1181 | Store64BitValueToStack(location, value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1182 | } else { |
| 1183 | DCHECK(location.IsConstant()); |
| 1184 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 1185 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1186 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 1187 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1188 | switch (instruction->GetType()) { |
| 1189 | case Primitive::kPrimBoolean: |
| 1190 | case Primitive::kPrimByte: |
| 1191 | case Primitive::kPrimChar: |
| 1192 | case Primitive::kPrimShort: |
| 1193 | case Primitive::kPrimInt: |
| 1194 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1195 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1196 | Move(location, Location::StackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
| 1197 | break; |
| 1198 | |
| 1199 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1200 | case Primitive::kPrimDouble: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1201 | Move(location, |
| 1202 | Location::DoubleStackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1203 | break; |
| 1204 | |
| 1205 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1206 | LOG(FATAL) << "Unexpected local type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1207 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 1208 | } else if (instruction->IsTemporary()) { |
| 1209 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
| 1210 | Move(location, temp_location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1211 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1212 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1213 | switch (instruction->GetType()) { |
| 1214 | case Primitive::kPrimBoolean: |
| 1215 | case Primitive::kPrimByte: |
| 1216 | case Primitive::kPrimChar: |
| 1217 | case Primitive::kPrimShort: |
| 1218 | case Primitive::kPrimInt: |
| 1219 | case Primitive::kPrimNot: |
| 1220 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1221 | case Primitive::kPrimFloat: |
| 1222 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1223 | Move(location, locations->Out()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1224 | break; |
| 1225 | |
| 1226 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1227 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1228 | } |
| 1229 | } |
| 1230 | } |
| 1231 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1232 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1233 | DCHECK(location.IsRegister()); |
| 1234 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1235 | } |
| 1236 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1237 | void CodeGeneratorX86_64::MoveLocation( |
| 1238 | Location dst, Location src, Primitive::Type dst_type ATTRIBUTE_UNUSED) { |
| 1239 | Move(dst, src); |
| 1240 | } |
| 1241 | |
| 1242 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1243 | if (location.IsRegister()) { |
| 1244 | locations->AddTemp(location); |
| 1245 | } else { |
| 1246 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1247 | } |
| 1248 | } |
| 1249 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1250 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1251 | DCHECK(!successor->IsExitBlock()); |
| 1252 | |
| 1253 | HBasicBlock* block = got->GetBlock(); |
| 1254 | HInstruction* previous = got->GetPrevious(); |
| 1255 | |
| 1256 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1257 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1258 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1259 | return; |
| 1260 | } |
| 1261 | |
| 1262 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1263 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1264 | } |
| 1265 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1266 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1267 | } |
| 1268 | } |
| 1269 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1270 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1271 | got->SetLocations(nullptr); |
| 1272 | } |
| 1273 | |
| 1274 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1275 | HandleGoto(got, got->GetSuccessor()); |
| 1276 | } |
| 1277 | |
| 1278 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1279 | try_boundary->SetLocations(nullptr); |
| 1280 | } |
| 1281 | |
| 1282 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1283 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1284 | if (!successor->IsExitBlock()) { |
| 1285 | HandleGoto(try_boundary, successor); |
| 1286 | } |
| 1287 | } |
| 1288 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1289 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1290 | exit->SetLocations(nullptr); |
| 1291 | } |
| 1292 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1293 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1294 | } |
| 1295 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1296 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
| 1297 | Label* true_label, |
| 1298 | Label* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1299 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1300 | __ j(kUnordered, true_label); |
| 1301 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1302 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1303 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1304 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1305 | } |
| 1306 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame^] | 1307 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1308 | Label* true_target_in, |
| 1309 | Label* false_target_in) { |
| 1310 | // Generated branching requires both targets to be explicit. If either of the |
| 1311 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1312 | Label fallthrough_target; |
| 1313 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1314 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1315 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1316 | LocationSummary* locations = condition->GetLocations(); |
| 1317 | Location left = locations->InAt(0); |
| 1318 | Location right = locations->InAt(1); |
| 1319 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1320 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1321 | switch (type) { |
| 1322 | case Primitive::kPrimLong: { |
| 1323 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1324 | if (right.IsConstant()) { |
| 1325 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1326 | if (IsInt<32>(value)) { |
| 1327 | if (value == 0) { |
| 1328 | __ testq(left_reg, left_reg); |
| 1329 | } else { |
| 1330 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 1331 | } |
| 1332 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1333 | // Value won't fit in a 32-bit integer. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1334 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
| 1335 | } |
| 1336 | } else if (right.IsDoubleStackSlot()) { |
| 1337 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1338 | } else { |
| 1339 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1340 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1341 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1342 | break; |
| 1343 | } |
| 1344 | case Primitive::kPrimFloat: { |
| 1345 | if (right.IsFpuRegister()) { |
| 1346 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1347 | } else if (right.IsConstant()) { |
| 1348 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1349 | codegen_->LiteralFloatAddress( |
| 1350 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1351 | } else { |
| 1352 | DCHECK(right.IsStackSlot()); |
| 1353 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1354 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1355 | } |
| 1356 | GenerateFPJumps(condition, true_target, false_target); |
| 1357 | break; |
| 1358 | } |
| 1359 | case Primitive::kPrimDouble: { |
| 1360 | if (right.IsFpuRegister()) { |
| 1361 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1362 | } else if (right.IsConstant()) { |
| 1363 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1364 | codegen_->LiteralDoubleAddress( |
| 1365 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1366 | } else { |
| 1367 | DCHECK(right.IsDoubleStackSlot()); |
| 1368 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1369 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1370 | } |
| 1371 | GenerateFPJumps(condition, true_target, false_target); |
| 1372 | break; |
| 1373 | } |
| 1374 | default: |
| 1375 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1376 | } |
| 1377 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame^] | 1378 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1379 | __ jmp(false_target); |
| 1380 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame^] | 1381 | |
| 1382 | if (fallthrough_target.IsLinked()) { |
| 1383 | __ Bind(&fallthrough_target); |
| 1384 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1385 | } |
| 1386 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame^] | 1387 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1388 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1389 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1390 | // conditions if they are materialized due to the complex branching. |
| 1391 | return cond->IsCondition() && |
| 1392 | cond->GetNext() == branch && |
| 1393 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1394 | } |
| 1395 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1396 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame^] | 1397 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1398 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame^] | 1399 | Label* false_target) { |
| 1400 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1401 | |
| 1402 | if (true_target == nullptr && false_target == nullptr) { |
| 1403 | // Nothing to do. The code always falls through. |
| 1404 | return; |
| 1405 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1406 | // Constant condition, statically compared against 1. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame^] | 1407 | if (cond->AsIntConstant()->IsOne()) { |
| 1408 | if (true_target != nullptr) { |
| 1409 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1410 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1411 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame^] | 1412 | DCHECK(cond->AsIntConstant()->IsZero()); |
| 1413 | if (false_target != nullptr) { |
| 1414 | __ jmp(false_target); |
| 1415 | } |
| 1416 | } |
| 1417 | return; |
| 1418 | } |
| 1419 | |
| 1420 | // The following code generates these patterns: |
| 1421 | // (1) true_target == nullptr && false_target != nullptr |
| 1422 | // - opposite condition true => branch to false_target |
| 1423 | // (2) true_target != nullptr && false_target == nullptr |
| 1424 | // - condition true => branch to true_target |
| 1425 | // (3) true_target != nullptr && false_target != nullptr |
| 1426 | // - condition true => branch to true_target |
| 1427 | // - branch to false_target |
| 1428 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1429 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1430 | if (true_target == nullptr) { |
| 1431 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1432 | } else { |
| 1433 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1434 | } |
| 1435 | } else { |
| 1436 | // Materialized condition, compare against 0. |
| 1437 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1438 | if (lhs.IsRegister()) { |
| 1439 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1440 | } else { |
| 1441 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1442 | } |
| 1443 | if (true_target == nullptr) { |
| 1444 | __ j(kEqual, false_target); |
| 1445 | } else { |
| 1446 | __ j(kNotEqual, true_target); |
| 1447 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1448 | } |
| 1449 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame^] | 1450 | // Condition has not been materialized, use its inputs as the |
| 1451 | // comparison and its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1452 | HCondition* condition = cond->AsCondition(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1453 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame^] | 1454 | // If this is a long or FP comparison that has been folded into |
| 1455 | // the HCondition, generate the comparison directly. |
| 1456 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1457 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1458 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1459 | return; |
| 1460 | } |
| 1461 | |
| 1462 | Location lhs = condition->GetLocations()->InAt(0); |
| 1463 | Location rhs = condition->GetLocations()->InAt(1); |
| 1464 | if (rhs.IsRegister()) { |
| 1465 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1466 | } else if (rhs.IsConstant()) { |
| 1467 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1468 | if (constant == 0) { |
| 1469 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1470 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame^] | 1471 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1472 | } |
| 1473 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame^] | 1474 | __ cmpl(lhs.AsRegister<CpuRegister>(), |
| 1475 | Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1476 | } |
| 1477 | if (true_target == nullptr) { |
| 1478 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1479 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1480 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1481 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1482 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame^] | 1483 | |
| 1484 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1485 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1486 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1487 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1488 | } |
| 1489 | } |
| 1490 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1491 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame^] | 1492 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1493 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1494 | locations->SetInAt(0, Location::Any()); |
| 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame^] | 1499 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1500 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1501 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1502 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1503 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1504 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1505 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1509 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1510 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame^] | 1511 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1512 | locations->SetInAt(0, Location::Any()); |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 1517 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1518 | DeoptimizationSlowPathX86_64(deoptimize); |
| 1519 | codegen_->AddSlowPath(slow_path); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame^] | 1520 | GenerateTestAndBranch(deoptimize, |
| 1521 | /* condition_input_index */ 0, |
| 1522 | slow_path->GetEntryLabel(), |
| 1523 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1524 | } |
| 1525 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1526 | void LocationsBuilderX86_64::VisitLocal(HLocal* local) { |
| 1527 | local->SetLocations(nullptr); |
| 1528 | } |
| 1529 | |
| 1530 | void InstructionCodeGeneratorX86_64::VisitLocal(HLocal* local) { |
| 1531 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 1532 | } |
| 1533 | |
| 1534 | void LocationsBuilderX86_64::VisitLoadLocal(HLoadLocal* local) { |
| 1535 | local->SetLocations(nullptr); |
| 1536 | } |
| 1537 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1538 | void InstructionCodeGeneratorX86_64::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1539 | // Nothing to do, this is driven by the code generator. |
| 1540 | } |
| 1541 | |
| 1542 | void LocationsBuilderX86_64::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1543 | LocationSummary* locations = |
| 1544 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1545 | switch (store->InputAt(1)->GetType()) { |
| 1546 | case Primitive::kPrimBoolean: |
| 1547 | case Primitive::kPrimByte: |
| 1548 | case Primitive::kPrimChar: |
| 1549 | case Primitive::kPrimShort: |
| 1550 | case Primitive::kPrimInt: |
| 1551 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1552 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1553 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1554 | break; |
| 1555 | |
| 1556 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1557 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1558 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1559 | break; |
| 1560 | |
| 1561 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1562 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1563 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1564 | } |
| 1565 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1566 | void InstructionCodeGeneratorX86_64::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1567 | } |
| 1568 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1569 | void LocationsBuilderX86_64::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1570 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1571 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1572 | // Handle the long/FP comparisons made in instruction simplification. |
| 1573 | switch (cond->InputAt(0)->GetType()) { |
| 1574 | case Primitive::kPrimLong: |
| 1575 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1576 | locations->SetInAt(1, Location::Any()); |
| 1577 | break; |
| 1578 | case Primitive::kPrimFloat: |
| 1579 | case Primitive::kPrimDouble: |
| 1580 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1581 | locations->SetInAt(1, Location::Any()); |
| 1582 | break; |
| 1583 | default: |
| 1584 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1585 | locations->SetInAt(1, Location::Any()); |
| 1586 | break; |
| 1587 | } |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1588 | if (cond->NeedsMaterialization()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1589 | locations->SetOut(Location::RequiresRegister()); |
| 1590 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1591 | } |
| 1592 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1593 | void InstructionCodeGeneratorX86_64::VisitCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1594 | if (!cond->NeedsMaterialization()) { |
| 1595 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1596 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1597 | |
| 1598 | LocationSummary* locations = cond->GetLocations(); |
| 1599 | Location lhs = locations->InAt(0); |
| 1600 | Location rhs = locations->InAt(1); |
| 1601 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
| 1602 | Label true_label, false_label; |
| 1603 | |
| 1604 | switch (cond->InputAt(0)->GetType()) { |
| 1605 | default: |
| 1606 | // Integer case. |
| 1607 | |
| 1608 | // Clear output register: setcc only sets the low byte. |
| 1609 | __ xorl(reg, reg); |
| 1610 | |
| 1611 | if (rhs.IsRegister()) { |
| 1612 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1613 | } else if (rhs.IsConstant()) { |
| 1614 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1615 | if (constant == 0) { |
| 1616 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1617 | } else { |
| 1618 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
| 1619 | } |
| 1620 | } else { |
| 1621 | __ cmpl(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1622 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1623 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1624 | return; |
| 1625 | case Primitive::kPrimLong: |
| 1626 | // Clear output register: setcc only sets the low byte. |
| 1627 | __ xorl(reg, reg); |
| 1628 | |
| 1629 | if (rhs.IsRegister()) { |
| 1630 | __ cmpq(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1631 | } else if (rhs.IsConstant()) { |
| 1632 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 1633 | if (IsInt<32>(value)) { |
| 1634 | if (value == 0) { |
| 1635 | __ testq(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1636 | } else { |
| 1637 | __ cmpq(lhs.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 1638 | } |
| 1639 | } else { |
| 1640 | // Value won't fit in an int. |
| 1641 | __ cmpq(lhs.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 1642 | } |
| 1643 | } else { |
| 1644 | __ cmpq(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1645 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1646 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1647 | return; |
| 1648 | case Primitive::kPrimFloat: { |
| 1649 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1650 | if (rhs.IsConstant()) { |
| 1651 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1652 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1653 | } else if (rhs.IsStackSlot()) { |
| 1654 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1655 | } else { |
| 1656 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1657 | } |
| 1658 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1659 | break; |
| 1660 | } |
| 1661 | case Primitive::kPrimDouble: { |
| 1662 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1663 | if (rhs.IsConstant()) { |
| 1664 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1665 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1666 | } else if (rhs.IsDoubleStackSlot()) { |
| 1667 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1668 | } else { |
| 1669 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1670 | } |
| 1671 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1672 | break; |
| 1673 | } |
| 1674 | } |
| 1675 | |
| 1676 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1677 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1678 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1679 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1680 | __ Bind(&false_label); |
| 1681 | __ xorl(reg, reg); |
| 1682 | __ jmp(&done_label); |
| 1683 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1684 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1685 | __ Bind(&true_label); |
| 1686 | __ movl(reg, Immediate(1)); |
| 1687 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
| 1691 | VisitCondition(comp); |
| 1692 | } |
| 1693 | |
| 1694 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
| 1695 | VisitCondition(comp); |
| 1696 | } |
| 1697 | |
| 1698 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
| 1699 | VisitCondition(comp); |
| 1700 | } |
| 1701 | |
| 1702 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
| 1703 | VisitCondition(comp); |
| 1704 | } |
| 1705 | |
| 1706 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
| 1707 | VisitCondition(comp); |
| 1708 | } |
| 1709 | |
| 1710 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
| 1711 | VisitCondition(comp); |
| 1712 | } |
| 1713 | |
| 1714 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1715 | VisitCondition(comp); |
| 1716 | } |
| 1717 | |
| 1718 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1719 | VisitCondition(comp); |
| 1720 | } |
| 1721 | |
| 1722 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 1723 | VisitCondition(comp); |
| 1724 | } |
| 1725 | |
| 1726 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 1727 | VisitCondition(comp); |
| 1728 | } |
| 1729 | |
| 1730 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1731 | VisitCondition(comp); |
| 1732 | } |
| 1733 | |
| 1734 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1735 | VisitCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1736 | } |
| 1737 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1738 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
| 1739 | VisitCondition(comp); |
| 1740 | } |
| 1741 | |
| 1742 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
| 1743 | VisitCondition(comp); |
| 1744 | } |
| 1745 | |
| 1746 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 1747 | VisitCondition(comp); |
| 1748 | } |
| 1749 | |
| 1750 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 1751 | VisitCondition(comp); |
| 1752 | } |
| 1753 | |
| 1754 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
| 1755 | VisitCondition(comp); |
| 1756 | } |
| 1757 | |
| 1758 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
| 1759 | VisitCondition(comp); |
| 1760 | } |
| 1761 | |
| 1762 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 1763 | VisitCondition(comp); |
| 1764 | } |
| 1765 | |
| 1766 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 1767 | VisitCondition(comp); |
| 1768 | } |
| 1769 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1770 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1771 | LocationSummary* locations = |
| 1772 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1773 | switch (compare->InputAt(0)->GetType()) { |
| 1774 | case Primitive::kPrimLong: { |
| 1775 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1776 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1777 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1778 | break; |
| 1779 | } |
| 1780 | case Primitive::kPrimFloat: |
| 1781 | case Primitive::kPrimDouble: { |
| 1782 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1783 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1784 | locations->SetOut(Location::RequiresRegister()); |
| 1785 | break; |
| 1786 | } |
| 1787 | default: |
| 1788 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 1789 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1793 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1794 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1795 | Location left = locations->InAt(0); |
| 1796 | Location right = locations->InAt(1); |
| 1797 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1798 | NearLabel less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1799 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 1800 | switch (type) { |
| 1801 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1802 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1803 | if (right.IsConstant()) { |
| 1804 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1805 | if (IsInt<32>(value)) { |
| 1806 | if (value == 0) { |
| 1807 | __ testq(left_reg, left_reg); |
| 1808 | } else { |
| 1809 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 1810 | } |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1811 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1812 | // Value won't fit in an int. |
| 1813 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1814 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1815 | } else if (right.IsDoubleStackSlot()) { |
| 1816 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1817 | } else { |
| 1818 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1819 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1820 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1821 | } |
| 1822 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1823 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1824 | if (right.IsConstant()) { |
| 1825 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 1826 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 1827 | } else if (right.IsStackSlot()) { |
| 1828 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1829 | } else { |
| 1830 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1831 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1832 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 1833 | break; |
| 1834 | } |
| 1835 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1836 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1837 | if (right.IsConstant()) { |
| 1838 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1839 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 1840 | } else if (right.IsDoubleStackSlot()) { |
| 1841 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1842 | } else { |
| 1843 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1844 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1845 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 1846 | break; |
| 1847 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1848 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1849 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1850 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1851 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1852 | __ j(kEqual, &done); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1853 | __ j(type == Primitive::kPrimLong ? kLess : kBelow, &less); // ucomis{s,d} sets CF (kBelow) |
Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1854 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1855 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1856 | __ movl(out, Immediate(1)); |
| 1857 | __ jmp(&done); |
| 1858 | |
| 1859 | __ Bind(&less); |
| 1860 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1861 | |
| 1862 | __ Bind(&done); |
| 1863 | } |
| 1864 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1865 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1866 | LocationSummary* locations = |
| 1867 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1868 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1869 | } |
| 1870 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1871 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1872 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1873 | } |
| 1874 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1875 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1876 | LocationSummary* locations = |
| 1877 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1878 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1879 | } |
| 1880 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1881 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1882 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1883 | } |
| 1884 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1885 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1886 | LocationSummary* locations = |
| 1887 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1888 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1889 | } |
| 1890 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1891 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1892 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1893 | } |
| 1894 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1895 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1896 | LocationSummary* locations = |
| 1897 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1898 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1899 | } |
| 1900 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1901 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1902 | // Will be generated at use site. |
| 1903 | } |
| 1904 | |
| 1905 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1906 | LocationSummary* locations = |
| 1907 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1908 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1909 | } |
| 1910 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1911 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 1912 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1913 | // Will be generated at use site. |
| 1914 | } |
| 1915 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1916 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1917 | memory_barrier->SetLocations(nullptr); |
| 1918 | } |
| 1919 | |
| 1920 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1921 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1922 | } |
| 1923 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1924 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 1925 | ret->SetLocations(nullptr); |
| 1926 | } |
| 1927 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1928 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1929 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1933 | LocationSummary* locations = |
| 1934 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1935 | switch (ret->InputAt(0)->GetType()) { |
| 1936 | case Primitive::kPrimBoolean: |
| 1937 | case Primitive::kPrimByte: |
| 1938 | case Primitive::kPrimChar: |
| 1939 | case Primitive::kPrimShort: |
| 1940 | case Primitive::kPrimInt: |
| 1941 | case Primitive::kPrimNot: |
| 1942 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1943 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1944 | break; |
| 1945 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1946 | case Primitive::kPrimFloat: |
| 1947 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1948 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1949 | break; |
| 1950 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1951 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1952 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1953 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 1957 | if (kIsDebugBuild) { |
| 1958 | switch (ret->InputAt(0)->GetType()) { |
| 1959 | case Primitive::kPrimBoolean: |
| 1960 | case Primitive::kPrimByte: |
| 1961 | case Primitive::kPrimChar: |
| 1962 | case Primitive::kPrimShort: |
| 1963 | case Primitive::kPrimInt: |
| 1964 | case Primitive::kPrimNot: |
| 1965 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1966 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1967 | break; |
| 1968 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1969 | case Primitive::kPrimFloat: |
| 1970 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1971 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1972 | XMM0); |
| 1973 | break; |
| 1974 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1975 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1976 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1977 | } |
| 1978 | } |
| 1979 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1980 | } |
| 1981 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1982 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 1983 | switch (type) { |
| 1984 | case Primitive::kPrimBoolean: |
| 1985 | case Primitive::kPrimByte: |
| 1986 | case Primitive::kPrimChar: |
| 1987 | case Primitive::kPrimShort: |
| 1988 | case Primitive::kPrimInt: |
| 1989 | case Primitive::kPrimNot: |
| 1990 | case Primitive::kPrimLong: |
| 1991 | return Location::RegisterLocation(RAX); |
| 1992 | |
| 1993 | case Primitive::kPrimVoid: |
| 1994 | return Location::NoLocation(); |
| 1995 | |
| 1996 | case Primitive::kPrimDouble: |
| 1997 | case Primitive::kPrimFloat: |
| 1998 | return Location::FpuRegisterLocation(XMM0); |
| 1999 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2000 | |
| 2001 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2005 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2006 | } |
| 2007 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2008 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2009 | switch (type) { |
| 2010 | case Primitive::kPrimBoolean: |
| 2011 | case Primitive::kPrimByte: |
| 2012 | case Primitive::kPrimChar: |
| 2013 | case Primitive::kPrimShort: |
| 2014 | case Primitive::kPrimInt: |
| 2015 | case Primitive::kPrimNot: { |
| 2016 | uint32_t index = gp_index_++; |
| 2017 | stack_index_++; |
| 2018 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2019 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2020 | } else { |
| 2021 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2022 | } |
| 2023 | } |
| 2024 | |
| 2025 | case Primitive::kPrimLong: { |
| 2026 | uint32_t index = gp_index_; |
| 2027 | stack_index_ += 2; |
| 2028 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2029 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2030 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2031 | } else { |
| 2032 | gp_index_ += 2; |
| 2033 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2034 | } |
| 2035 | } |
| 2036 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2037 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2038 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2039 | stack_index_++; |
| 2040 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2041 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2042 | } else { |
| 2043 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2044 | } |
| 2045 | } |
| 2046 | |
| 2047 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2048 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2049 | stack_index_ += 2; |
| 2050 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2051 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2052 | } else { |
| 2053 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2054 | } |
| 2055 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2056 | |
| 2057 | case Primitive::kPrimVoid: |
| 2058 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2059 | break; |
| 2060 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2061 | return Location::NoLocation(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2062 | } |
| 2063 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2064 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2065 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2066 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2067 | // the method_idx. |
| 2068 | HandleInvoke(invoke); |
| 2069 | } |
| 2070 | |
| 2071 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2072 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2073 | } |
| 2074 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2075 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 2076 | // When we do not run baseline, explicit clinit checks triggered by static |
| 2077 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 2078 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2079 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2080 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2081 | if (intrinsic.TryDispatch(invoke)) { |
| 2082 | return; |
| 2083 | } |
| 2084 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2085 | HandleInvoke(invoke); |
| 2086 | } |
| 2087 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2088 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2089 | if (invoke->GetLocations()->Intrinsified()) { |
| 2090 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2091 | intrinsic.Dispatch(invoke); |
| 2092 | return true; |
| 2093 | } |
| 2094 | return false; |
| 2095 | } |
| 2096 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2097 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 2098 | // When we do not run baseline, explicit clinit checks triggered by static |
| 2099 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 2100 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2101 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2102 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2103 | return; |
| 2104 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2105 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2106 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2107 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2108 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2109 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2110 | } |
| 2111 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2112 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2113 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2114 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2115 | } |
| 2116 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2117 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2118 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2119 | if (intrinsic.TryDispatch(invoke)) { |
| 2120 | return; |
| 2121 | } |
| 2122 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2123 | HandleInvoke(invoke); |
| 2124 | } |
| 2125 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2126 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2127 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2128 | return; |
| 2129 | } |
| 2130 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2131 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2132 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2133 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2134 | } |
| 2135 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2136 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2137 | HandleInvoke(invoke); |
| 2138 | // Add the hidden argument. |
| 2139 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2140 | } |
| 2141 | |
| 2142 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2143 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2144 | LocationSummary* locations = invoke->GetLocations(); |
| 2145 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2146 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2147 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2148 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2149 | Location receiver = locations->InAt(0); |
| 2150 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2151 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2152 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2153 | // won't be modified thereafter, before the `call` instruction. |
| 2154 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2155 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2156 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2157 | if (receiver.IsStackSlot()) { |
| 2158 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2159 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2160 | __ movl(temp, Address(temp, class_offset)); |
| 2161 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2162 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2163 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2164 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2165 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2166 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2167 | // emit a read barrier for the previous class reference load. |
| 2168 | // However this is not required in practice, as this is an |
| 2169 | // intermediate/temporary reference and because the current |
| 2170 | // concurrent copying collector keeps the from-space memory |
| 2171 | // intact/accessible until the end of the marking phase (the |
| 2172 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2173 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2174 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2175 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2176 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2177 | __ call(Address(temp, |
| 2178 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2179 | |
| 2180 | DCHECK(!codegen_->IsLeafMethod()); |
| 2181 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2182 | } |
| 2183 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2184 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2185 | LocationSummary* locations = |
| 2186 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2187 | switch (neg->GetResultType()) { |
| 2188 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2189 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2190 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2191 | locations->SetOut(Location::SameAsFirstInput()); |
| 2192 | break; |
| 2193 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2194 | case Primitive::kPrimFloat: |
| 2195 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2196 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2197 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2198 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2199 | break; |
| 2200 | |
| 2201 | default: |
| 2202 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2203 | } |
| 2204 | } |
| 2205 | |
| 2206 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2207 | LocationSummary* locations = neg->GetLocations(); |
| 2208 | Location out = locations->Out(); |
| 2209 | Location in = locations->InAt(0); |
| 2210 | switch (neg->GetResultType()) { |
| 2211 | case Primitive::kPrimInt: |
| 2212 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2213 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2214 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2215 | break; |
| 2216 | |
| 2217 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2218 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2219 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2220 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2221 | break; |
| 2222 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2223 | case Primitive::kPrimFloat: { |
| 2224 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2225 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2226 | // Implement float negation with an exclusive or with value |
| 2227 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2228 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2229 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2230 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2231 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2232 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2233 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2234 | case Primitive::kPrimDouble: { |
| 2235 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2236 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2237 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2238 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2239 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2240 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2241 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2242 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2243 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2244 | |
| 2245 | default: |
| 2246 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2247 | } |
| 2248 | } |
| 2249 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2250 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2251 | LocationSummary* locations = |
| 2252 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 2253 | Primitive::Type result_type = conversion->GetResultType(); |
| 2254 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2255 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2256 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2257 | // The Java language does not allow treating boolean as an integral type but |
| 2258 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2259 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2260 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2261 | case Primitive::kPrimByte: |
| 2262 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2263 | case Primitive::kPrimBoolean: |
| 2264 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2265 | case Primitive::kPrimShort: |
| 2266 | case Primitive::kPrimInt: |
| 2267 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2268 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2269 | locations->SetInAt(0, Location::Any()); |
| 2270 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2271 | break; |
| 2272 | |
| 2273 | default: |
| 2274 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2275 | << " to " << result_type; |
| 2276 | } |
| 2277 | break; |
| 2278 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2279 | case Primitive::kPrimShort: |
| 2280 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2281 | case Primitive::kPrimBoolean: |
| 2282 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2283 | case Primitive::kPrimByte: |
| 2284 | case Primitive::kPrimInt: |
| 2285 | case Primitive::kPrimChar: |
| 2286 | // Processing a Dex `int-to-short' instruction. |
| 2287 | locations->SetInAt(0, Location::Any()); |
| 2288 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2289 | break; |
| 2290 | |
| 2291 | default: |
| 2292 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2293 | << " to " << result_type; |
| 2294 | } |
| 2295 | break; |
| 2296 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2297 | case Primitive::kPrimInt: |
| 2298 | switch (input_type) { |
| 2299 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2300 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2301 | locations->SetInAt(0, Location::Any()); |
| 2302 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2303 | break; |
| 2304 | |
| 2305 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2306 | // Processing a Dex `float-to-int' instruction. |
| 2307 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2308 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2309 | break; |
| 2310 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2311 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2312 | // Processing a Dex `double-to-int' instruction. |
| 2313 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2314 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2315 | break; |
| 2316 | |
| 2317 | default: |
| 2318 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2319 | << " to " << result_type; |
| 2320 | } |
| 2321 | break; |
| 2322 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2323 | case Primitive::kPrimLong: |
| 2324 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2325 | case Primitive::kPrimBoolean: |
| 2326 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2327 | case Primitive::kPrimByte: |
| 2328 | case Primitive::kPrimShort: |
| 2329 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2330 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2331 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2332 | // TODO: We would benefit from a (to-be-implemented) |
| 2333 | // Location::RegisterOrStackSlot requirement for this input. |
| 2334 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2335 | locations->SetOut(Location::RequiresRegister()); |
| 2336 | break; |
| 2337 | |
| 2338 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2339 | // Processing a Dex `float-to-long' instruction. |
| 2340 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2341 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2342 | break; |
| 2343 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2344 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2345 | // Processing a Dex `double-to-long' instruction. |
| 2346 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2347 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2348 | break; |
| 2349 | |
| 2350 | default: |
| 2351 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2352 | << " to " << result_type; |
| 2353 | } |
| 2354 | break; |
| 2355 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2356 | case Primitive::kPrimChar: |
| 2357 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2358 | case Primitive::kPrimBoolean: |
| 2359 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2360 | case Primitive::kPrimByte: |
| 2361 | case Primitive::kPrimShort: |
| 2362 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2363 | // Processing a Dex `int-to-char' instruction. |
| 2364 | locations->SetInAt(0, Location::Any()); |
| 2365 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2366 | break; |
| 2367 | |
| 2368 | default: |
| 2369 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2370 | << " to " << result_type; |
| 2371 | } |
| 2372 | break; |
| 2373 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2374 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2375 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2376 | case Primitive::kPrimBoolean: |
| 2377 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2378 | case Primitive::kPrimByte: |
| 2379 | case Primitive::kPrimShort: |
| 2380 | case Primitive::kPrimInt: |
| 2381 | case Primitive::kPrimChar: |
| 2382 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2383 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2384 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2385 | break; |
| 2386 | |
| 2387 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2388 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2389 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2390 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2391 | break; |
| 2392 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2393 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2394 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2395 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2396 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2397 | break; |
| 2398 | |
| 2399 | default: |
| 2400 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2401 | << " to " << result_type; |
| 2402 | }; |
| 2403 | break; |
| 2404 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2405 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2406 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2407 | case Primitive::kPrimBoolean: |
| 2408 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2409 | case Primitive::kPrimByte: |
| 2410 | case Primitive::kPrimShort: |
| 2411 | case Primitive::kPrimInt: |
| 2412 | case Primitive::kPrimChar: |
| 2413 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2414 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2415 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2416 | break; |
| 2417 | |
| 2418 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2419 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2420 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2421 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2422 | break; |
| 2423 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2424 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2425 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2426 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2427 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2428 | break; |
| 2429 | |
| 2430 | default: |
| 2431 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2432 | << " to " << result_type; |
| 2433 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2434 | break; |
| 2435 | |
| 2436 | default: |
| 2437 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2438 | << " to " << result_type; |
| 2439 | } |
| 2440 | } |
| 2441 | |
| 2442 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2443 | LocationSummary* locations = conversion->GetLocations(); |
| 2444 | Location out = locations->Out(); |
| 2445 | Location in = locations->InAt(0); |
| 2446 | Primitive::Type result_type = conversion->GetResultType(); |
| 2447 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2448 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2449 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2450 | case Primitive::kPrimByte: |
| 2451 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2452 | case Primitive::kPrimBoolean: |
| 2453 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2454 | case Primitive::kPrimShort: |
| 2455 | case Primitive::kPrimInt: |
| 2456 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2457 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2458 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2459 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2460 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2461 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2462 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2463 | } else { |
| 2464 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2465 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2466 | Immediate(static_cast<int8_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2467 | } |
| 2468 | break; |
| 2469 | |
| 2470 | default: |
| 2471 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2472 | << " to " << result_type; |
| 2473 | } |
| 2474 | break; |
| 2475 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2476 | case Primitive::kPrimShort: |
| 2477 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2478 | case Primitive::kPrimBoolean: |
| 2479 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2480 | case Primitive::kPrimByte: |
| 2481 | case Primitive::kPrimInt: |
| 2482 | case Primitive::kPrimChar: |
| 2483 | // Processing a Dex `int-to-short' instruction. |
| 2484 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2485 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2486 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2487 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2488 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2489 | } else { |
| 2490 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2491 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2492 | Immediate(static_cast<int16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2493 | } |
| 2494 | break; |
| 2495 | |
| 2496 | default: |
| 2497 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2498 | << " to " << result_type; |
| 2499 | } |
| 2500 | break; |
| 2501 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2502 | case Primitive::kPrimInt: |
| 2503 | switch (input_type) { |
| 2504 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2505 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2506 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2507 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2508 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2509 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2510 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2511 | } else { |
| 2512 | DCHECK(in.IsConstant()); |
| 2513 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2514 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2515 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2516 | } |
| 2517 | break; |
| 2518 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2519 | case Primitive::kPrimFloat: { |
| 2520 | // Processing a Dex `float-to-int' instruction. |
| 2521 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2522 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2523 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2524 | |
| 2525 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2526 | // if input >= (float)INT_MAX goto done |
| 2527 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2528 | __ j(kAboveEqual, &done); |
| 2529 | // if input == NaN goto nan |
| 2530 | __ j(kUnordered, &nan); |
| 2531 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2532 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2533 | __ jmp(&done); |
| 2534 | __ Bind(&nan); |
| 2535 | // output = 0 |
| 2536 | __ xorl(output, output); |
| 2537 | __ Bind(&done); |
| 2538 | break; |
| 2539 | } |
| 2540 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2541 | case Primitive::kPrimDouble: { |
| 2542 | // Processing a Dex `double-to-int' instruction. |
| 2543 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2544 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2545 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2546 | |
| 2547 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2548 | // if input >= (double)INT_MAX goto done |
| 2549 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2550 | __ j(kAboveEqual, &done); |
| 2551 | // if input == NaN goto nan |
| 2552 | __ j(kUnordered, &nan); |
| 2553 | // output = double-to-int-truncate(input) |
| 2554 | __ cvttsd2si(output, input); |
| 2555 | __ jmp(&done); |
| 2556 | __ Bind(&nan); |
| 2557 | // output = 0 |
| 2558 | __ xorl(output, output); |
| 2559 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2560 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2561 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2562 | |
| 2563 | default: |
| 2564 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2565 | << " to " << result_type; |
| 2566 | } |
| 2567 | break; |
| 2568 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2569 | case Primitive::kPrimLong: |
| 2570 | switch (input_type) { |
| 2571 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2572 | case Primitive::kPrimBoolean: |
| 2573 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2574 | case Primitive::kPrimByte: |
| 2575 | case Primitive::kPrimShort: |
| 2576 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2577 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2578 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2579 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2580 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2581 | break; |
| 2582 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2583 | case Primitive::kPrimFloat: { |
| 2584 | // Processing a Dex `float-to-long' instruction. |
| 2585 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2586 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2587 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2588 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2589 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2590 | // if input >= (float)LONG_MAX goto done |
| 2591 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2592 | __ j(kAboveEqual, &done); |
| 2593 | // if input == NaN goto nan |
| 2594 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2595 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2596 | __ cvttss2si(output, input, true); |
| 2597 | __ jmp(&done); |
| 2598 | __ Bind(&nan); |
| 2599 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2600 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2601 | __ Bind(&done); |
| 2602 | break; |
| 2603 | } |
| 2604 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2605 | case Primitive::kPrimDouble: { |
| 2606 | // Processing a Dex `double-to-long' instruction. |
| 2607 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2608 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2609 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2610 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2611 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2612 | // if input >= (double)LONG_MAX goto done |
| 2613 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2614 | __ j(kAboveEqual, &done); |
| 2615 | // if input == NaN goto nan |
| 2616 | __ j(kUnordered, &nan); |
| 2617 | // output = double-to-long-truncate(input) |
| 2618 | __ cvttsd2si(output, input, true); |
| 2619 | __ jmp(&done); |
| 2620 | __ Bind(&nan); |
| 2621 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2622 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2623 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2624 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2625 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2626 | |
| 2627 | default: |
| 2628 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2629 | << " to " << result_type; |
| 2630 | } |
| 2631 | break; |
| 2632 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2633 | case Primitive::kPrimChar: |
| 2634 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2635 | case Primitive::kPrimBoolean: |
| 2636 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2637 | case Primitive::kPrimByte: |
| 2638 | case Primitive::kPrimShort: |
| 2639 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2640 | // Processing a Dex `int-to-char' instruction. |
| 2641 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2642 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2643 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2644 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2645 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2646 | } else { |
| 2647 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2648 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2649 | Immediate(static_cast<uint16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2650 | } |
| 2651 | break; |
| 2652 | |
| 2653 | default: |
| 2654 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2655 | << " to " << result_type; |
| 2656 | } |
| 2657 | break; |
| 2658 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2659 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2660 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2661 | case Primitive::kPrimBoolean: |
| 2662 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2663 | case Primitive::kPrimByte: |
| 2664 | case Primitive::kPrimShort: |
| 2665 | case Primitive::kPrimInt: |
| 2666 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2667 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2668 | if (in.IsRegister()) { |
| 2669 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2670 | } else if (in.IsConstant()) { |
| 2671 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2672 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2673 | if (v == 0) { |
| 2674 | __ xorps(dest, dest); |
| 2675 | } else { |
| 2676 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2677 | } |
| 2678 | } else { |
| 2679 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2680 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2681 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2682 | break; |
| 2683 | |
| 2684 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2685 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2686 | if (in.IsRegister()) { |
| 2687 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2688 | } else if (in.IsConstant()) { |
| 2689 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2690 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2691 | if (v == 0) { |
| 2692 | __ xorps(dest, dest); |
| 2693 | } else { |
| 2694 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2695 | } |
| 2696 | } else { |
| 2697 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2698 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2699 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2700 | break; |
| 2701 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2702 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2703 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2704 | if (in.IsFpuRegister()) { |
| 2705 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2706 | } else if (in.IsConstant()) { |
| 2707 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2708 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2709 | if (bit_cast<int64_t, double>(v) == 0) { |
| 2710 | __ xorps(dest, dest); |
| 2711 | } else { |
| 2712 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2713 | } |
| 2714 | } else { |
| 2715 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2716 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2717 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2718 | break; |
| 2719 | |
| 2720 | default: |
| 2721 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2722 | << " to " << result_type; |
| 2723 | }; |
| 2724 | break; |
| 2725 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2726 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2727 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2728 | case Primitive::kPrimBoolean: |
| 2729 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2730 | case Primitive::kPrimByte: |
| 2731 | case Primitive::kPrimShort: |
| 2732 | case Primitive::kPrimInt: |
| 2733 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2734 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2735 | if (in.IsRegister()) { |
| 2736 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2737 | } else if (in.IsConstant()) { |
| 2738 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2739 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2740 | if (v == 0) { |
| 2741 | __ xorpd(dest, dest); |
| 2742 | } else { |
| 2743 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2744 | } |
| 2745 | } else { |
| 2746 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2747 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2748 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2749 | break; |
| 2750 | |
| 2751 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2752 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2753 | if (in.IsRegister()) { |
| 2754 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2755 | } else if (in.IsConstant()) { |
| 2756 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2757 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2758 | if (v == 0) { |
| 2759 | __ xorpd(dest, dest); |
| 2760 | } else { |
| 2761 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2762 | } |
| 2763 | } else { |
| 2764 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2765 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2766 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2767 | break; |
| 2768 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2769 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2770 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2771 | if (in.IsFpuRegister()) { |
| 2772 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2773 | } else if (in.IsConstant()) { |
| 2774 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 2775 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2776 | if (bit_cast<int32_t, float>(v) == 0) { |
| 2777 | __ xorpd(dest, dest); |
| 2778 | } else { |
| 2779 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2780 | } |
| 2781 | } else { |
| 2782 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 2783 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2784 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2785 | break; |
| 2786 | |
| 2787 | default: |
| 2788 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2789 | << " to " << result_type; |
| 2790 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2791 | break; |
| 2792 | |
| 2793 | default: |
| 2794 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2795 | << " to " << result_type; |
| 2796 | } |
| 2797 | } |
| 2798 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2799 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2800 | LocationSummary* locations = |
| 2801 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2802 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2803 | case Primitive::kPrimInt: { |
| 2804 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2805 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2806 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2807 | break; |
| 2808 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2809 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2810 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2811 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2812 | // We can use a leaq or addq if the constant can fit in an immediate. |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 2813 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2814 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2815 | break; |
| 2816 | } |
| 2817 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2818 | case Primitive::kPrimDouble: |
| 2819 | case Primitive::kPrimFloat: { |
| 2820 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2821 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2822 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2823 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2824 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2825 | |
| 2826 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2827 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2828 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2829 | } |
| 2830 | |
| 2831 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 2832 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2833 | Location first = locations->InAt(0); |
| 2834 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2835 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2836 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2837 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2838 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2839 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2840 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2841 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2842 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2843 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2844 | } else { |
| 2845 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2846 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2847 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2848 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2849 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2850 | __ addl(out.AsRegister<CpuRegister>(), |
| 2851 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 2852 | } else { |
| 2853 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2854 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 2855 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2856 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2857 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2858 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2859 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2860 | break; |
| 2861 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2862 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2863 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2864 | if (second.IsRegister()) { |
| 2865 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2866 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2867 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2868 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2869 | } else { |
| 2870 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2871 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2872 | } |
| 2873 | } else { |
| 2874 | DCHECK(second.IsConstant()); |
| 2875 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2876 | int32_t int32_value = Low32Bits(value); |
| 2877 | DCHECK_EQ(int32_value, value); |
| 2878 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2879 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 2880 | } else { |
| 2881 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2882 | first.AsRegister<CpuRegister>(), int32_value)); |
| 2883 | } |
| 2884 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2885 | break; |
| 2886 | } |
| 2887 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2888 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2889 | if (second.IsFpuRegister()) { |
| 2890 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2891 | } else if (second.IsConstant()) { |
| 2892 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2893 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2894 | } else { |
| 2895 | DCHECK(second.IsStackSlot()); |
| 2896 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2897 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2898 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2899 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2900 | } |
| 2901 | |
| 2902 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2903 | if (second.IsFpuRegister()) { |
| 2904 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2905 | } else if (second.IsConstant()) { |
| 2906 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2907 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2908 | } else { |
| 2909 | DCHECK(second.IsDoubleStackSlot()); |
| 2910 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2911 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2912 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2913 | break; |
| 2914 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2915 | |
| 2916 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2917 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2918 | } |
| 2919 | } |
| 2920 | |
| 2921 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2922 | LocationSummary* locations = |
| 2923 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2924 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2925 | case Primitive::kPrimInt: { |
| 2926 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2927 | locations->SetInAt(1, Location::Any()); |
| 2928 | locations->SetOut(Location::SameAsFirstInput()); |
| 2929 | break; |
| 2930 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2931 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2932 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 2933 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2934 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2935 | break; |
| 2936 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2937 | case Primitive::kPrimFloat: |
| 2938 | case Primitive::kPrimDouble: { |
| 2939 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2940 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2941 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2942 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2943 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2944 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2945 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2946 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 2950 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2951 | Location first = locations->InAt(0); |
| 2952 | Location second = locations->InAt(1); |
| 2953 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2954 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2955 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2956 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2957 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2958 | } else if (second.IsConstant()) { |
| 2959 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2960 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2961 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2962 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2963 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2964 | break; |
| 2965 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2966 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2967 | if (second.IsConstant()) { |
| 2968 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2969 | DCHECK(IsInt<32>(value)); |
| 2970 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 2971 | } else { |
| 2972 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 2973 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2974 | break; |
| 2975 | } |
| 2976 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2977 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2978 | if (second.IsFpuRegister()) { |
| 2979 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2980 | } else if (second.IsConstant()) { |
| 2981 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2982 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2983 | } else { |
| 2984 | DCHECK(second.IsStackSlot()); |
| 2985 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2986 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2987 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2988 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2989 | } |
| 2990 | |
| 2991 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2992 | if (second.IsFpuRegister()) { |
| 2993 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2994 | } else if (second.IsConstant()) { |
| 2995 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2996 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2997 | } else { |
| 2998 | DCHECK(second.IsDoubleStackSlot()); |
| 2999 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3000 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3001 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3002 | break; |
| 3003 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3004 | |
| 3005 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3006 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3007 | } |
| 3008 | } |
| 3009 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3010 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3011 | LocationSummary* locations = |
| 3012 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3013 | switch (mul->GetResultType()) { |
| 3014 | case Primitive::kPrimInt: { |
| 3015 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3016 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3017 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3018 | // Can use 3 operand multiply. |
| 3019 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3020 | } else { |
| 3021 | locations->SetOut(Location::SameAsFirstInput()); |
| 3022 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3023 | break; |
| 3024 | } |
| 3025 | case Primitive::kPrimLong: { |
| 3026 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3027 | locations->SetInAt(1, Location::Any()); |
| 3028 | if (mul->InputAt(1)->IsLongConstant() && |
| 3029 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3030 | // Can use 3 operand multiply. |
| 3031 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3032 | } else { |
| 3033 | locations->SetOut(Location::SameAsFirstInput()); |
| 3034 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3035 | break; |
| 3036 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3037 | case Primitive::kPrimFloat: |
| 3038 | case Primitive::kPrimDouble: { |
| 3039 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3040 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3041 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3042 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3043 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3044 | |
| 3045 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3046 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3047 | } |
| 3048 | } |
| 3049 | |
| 3050 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3051 | LocationSummary* locations = mul->GetLocations(); |
| 3052 | Location first = locations->InAt(0); |
| 3053 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3054 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3055 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3056 | case Primitive::kPrimInt: |
| 3057 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3058 | // problems where the output may not be the same as the first operand. |
| 3059 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3060 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3061 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3062 | } else if (second.IsRegister()) { |
| 3063 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3064 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3065 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3066 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3067 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3068 | __ imull(first.AsRegister<CpuRegister>(), |
| 3069 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3070 | } |
| 3071 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3072 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3073 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3074 | // problems where the output may not be the same as the first operand. |
| 3075 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3076 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3077 | if (IsInt<32>(value)) { |
| 3078 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3079 | Immediate(static_cast<int32_t>(value))); |
| 3080 | } else { |
| 3081 | // Have to use the constant area. |
| 3082 | DCHECK(first.Equals(out)); |
| 3083 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3084 | } |
| 3085 | } else if (second.IsRegister()) { |
| 3086 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3087 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3088 | } else { |
| 3089 | DCHECK(second.IsDoubleStackSlot()); |
| 3090 | DCHECK(first.Equals(out)); |
| 3091 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3092 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3093 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3094 | break; |
| 3095 | } |
| 3096 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3097 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3098 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3099 | if (second.IsFpuRegister()) { |
| 3100 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3101 | } else if (second.IsConstant()) { |
| 3102 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3103 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 3104 | } else { |
| 3105 | DCHECK(second.IsStackSlot()); |
| 3106 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3107 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3108 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3109 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3110 | } |
| 3111 | |
| 3112 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3113 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3114 | if (second.IsFpuRegister()) { |
| 3115 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3116 | } else if (second.IsConstant()) { |
| 3117 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3118 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 3119 | } else { |
| 3120 | DCHECK(second.IsDoubleStackSlot()); |
| 3121 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3122 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3123 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3124 | break; |
| 3125 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3126 | |
| 3127 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3128 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3129 | } |
| 3130 | } |
| 3131 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3132 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3133 | uint32_t stack_adjustment, bool is_float) { |
| 3134 | if (source.IsStackSlot()) { |
| 3135 | DCHECK(is_float); |
| 3136 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3137 | } else if (source.IsDoubleStackSlot()) { |
| 3138 | DCHECK(!is_float); |
| 3139 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3140 | } else { |
| 3141 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3142 | if (is_float) { |
| 3143 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3144 | codegen_->Move(stack_temp, source); |
| 3145 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3146 | } else { |
| 3147 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3148 | codegen_->Move(stack_temp, source); |
| 3149 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3150 | } |
| 3151 | } |
| 3152 | } |
| 3153 | |
| 3154 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 3155 | Primitive::Type type = rem->GetResultType(); |
| 3156 | bool is_float = type == Primitive::kPrimFloat; |
| 3157 | size_t elem_size = Primitive::ComponentSize(type); |
| 3158 | LocationSummary* locations = rem->GetLocations(); |
| 3159 | Location first = locations->InAt(0); |
| 3160 | Location second = locations->InAt(1); |
| 3161 | Location out = locations->Out(); |
| 3162 | |
| 3163 | // Create stack space for 2 elements. |
| 3164 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3165 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3166 | |
| 3167 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3168 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3169 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3170 | |
| 3171 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3172 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3173 | __ Bind(&retry); |
| 3174 | __ fprem(); |
| 3175 | |
| 3176 | // Move FP status to AX. |
| 3177 | __ fstsw(); |
| 3178 | |
| 3179 | // And see if the argument reduction is complete. This is signaled by the |
| 3180 | // C2 FPU flag bit set to 0. |
| 3181 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3182 | __ j(kNotEqual, &retry); |
| 3183 | |
| 3184 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3185 | // Store FP top of stack to real stack. |
| 3186 | if (is_float) { |
| 3187 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3188 | } else { |
| 3189 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3190 | } |
| 3191 | |
| 3192 | // Pop the 2 items from the FP stack. |
| 3193 | __ fucompp(); |
| 3194 | |
| 3195 | // Load the value from the stack into an XMM register. |
| 3196 | DCHECK(out.IsFpuRegister()) << out; |
| 3197 | if (is_float) { |
| 3198 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3199 | } else { |
| 3200 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3201 | } |
| 3202 | |
| 3203 | // And remove the temporary stack space we allocated. |
| 3204 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3205 | } |
| 3206 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3207 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3208 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3209 | |
| 3210 | LocationSummary* locations = instruction->GetLocations(); |
| 3211 | Location second = locations->InAt(1); |
| 3212 | DCHECK(second.IsConstant()); |
| 3213 | |
| 3214 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3215 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3216 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3217 | |
| 3218 | DCHECK(imm == 1 || imm == -1); |
| 3219 | |
| 3220 | switch (instruction->GetResultType()) { |
| 3221 | case Primitive::kPrimInt: { |
| 3222 | if (instruction->IsRem()) { |
| 3223 | __ xorl(output_register, output_register); |
| 3224 | } else { |
| 3225 | __ movl(output_register, input_register); |
| 3226 | if (imm == -1) { |
| 3227 | __ negl(output_register); |
| 3228 | } |
| 3229 | } |
| 3230 | break; |
| 3231 | } |
| 3232 | |
| 3233 | case Primitive::kPrimLong: { |
| 3234 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3235 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3236 | } else { |
| 3237 | __ movq(output_register, input_register); |
| 3238 | if (imm == -1) { |
| 3239 | __ negq(output_register); |
| 3240 | } |
| 3241 | } |
| 3242 | break; |
| 3243 | } |
| 3244 | |
| 3245 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3246 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3247 | } |
| 3248 | } |
| 3249 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3250 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3251 | LocationSummary* locations = instruction->GetLocations(); |
| 3252 | Location second = locations->InAt(1); |
| 3253 | |
| 3254 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3255 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3256 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3257 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3258 | |
| 3259 | DCHECK(IsPowerOfTwo(std::abs(imm))); |
| 3260 | |
| 3261 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3262 | |
| 3263 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3264 | __ leal(tmp, Address(numerator, std::abs(imm) - 1)); |
| 3265 | __ testl(numerator, numerator); |
| 3266 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3267 | int shift = CTZ(imm); |
| 3268 | __ sarl(tmp, Immediate(shift)); |
| 3269 | |
| 3270 | if (imm < 0) { |
| 3271 | __ negl(tmp); |
| 3272 | } |
| 3273 | |
| 3274 | __ movl(output_register, tmp); |
| 3275 | } else { |
| 3276 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3277 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3278 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3279 | codegen_->Load64BitValue(rdx, std::abs(imm) - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3280 | __ addq(rdx, numerator); |
| 3281 | __ testq(numerator, numerator); |
| 3282 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3283 | int shift = CTZ(imm); |
| 3284 | __ sarq(rdx, Immediate(shift)); |
| 3285 | |
| 3286 | if (imm < 0) { |
| 3287 | __ negq(rdx); |
| 3288 | } |
| 3289 | |
| 3290 | __ movq(output_register, rdx); |
| 3291 | } |
| 3292 | } |
| 3293 | |
| 3294 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3295 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3296 | |
| 3297 | LocationSummary* locations = instruction->GetLocations(); |
| 3298 | Location second = locations->InAt(1); |
| 3299 | |
| 3300 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3301 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3302 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3303 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3304 | : locations->Out().AsRegister<CpuRegister>(); |
| 3305 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3306 | |
| 3307 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3308 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3309 | if (instruction->IsDiv()) { |
| 3310 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3311 | } else { |
| 3312 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3313 | } |
| 3314 | |
| 3315 | int64_t magic; |
| 3316 | int shift; |
| 3317 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3318 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3319 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3320 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3321 | |
| 3322 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3323 | |
| 3324 | __ movl(numerator, eax); |
| 3325 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3326 | NearLabel no_div; |
| 3327 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3328 | __ testl(eax, eax); |
| 3329 | __ j(kNotEqual, &no_div); |
| 3330 | |
| 3331 | __ xorl(out, out); |
| 3332 | __ jmp(&end); |
| 3333 | |
| 3334 | __ Bind(&no_div); |
| 3335 | |
| 3336 | __ movl(eax, Immediate(magic)); |
| 3337 | __ imull(numerator); |
| 3338 | |
| 3339 | if (imm > 0 && magic < 0) { |
| 3340 | __ addl(edx, numerator); |
| 3341 | } else if (imm < 0 && magic > 0) { |
| 3342 | __ subl(edx, numerator); |
| 3343 | } |
| 3344 | |
| 3345 | if (shift != 0) { |
| 3346 | __ sarl(edx, Immediate(shift)); |
| 3347 | } |
| 3348 | |
| 3349 | __ movl(eax, edx); |
| 3350 | __ shrl(edx, Immediate(31)); |
| 3351 | __ addl(edx, eax); |
| 3352 | |
| 3353 | if (instruction->IsRem()) { |
| 3354 | __ movl(eax, numerator); |
| 3355 | __ imull(edx, Immediate(imm)); |
| 3356 | __ subl(eax, edx); |
| 3357 | __ movl(edx, eax); |
| 3358 | } else { |
| 3359 | __ movl(eax, edx); |
| 3360 | } |
| 3361 | __ Bind(&end); |
| 3362 | } else { |
| 3363 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3364 | |
| 3365 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3366 | |
| 3367 | CpuRegister rax = eax; |
| 3368 | CpuRegister rdx = edx; |
| 3369 | |
| 3370 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3371 | |
| 3372 | // Save the numerator. |
| 3373 | __ movq(numerator, rax); |
| 3374 | |
| 3375 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3376 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3377 | |
| 3378 | // RDX:RAX = magic * numerator |
| 3379 | __ imulq(numerator); |
| 3380 | |
| 3381 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3382 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3383 | __ addq(rdx, numerator); |
| 3384 | } else if (imm < 0 && magic > 0) { |
| 3385 | // RDX -= numerator |
| 3386 | __ subq(rdx, numerator); |
| 3387 | } |
| 3388 | |
| 3389 | // Shift if needed. |
| 3390 | if (shift != 0) { |
| 3391 | __ sarq(rdx, Immediate(shift)); |
| 3392 | } |
| 3393 | |
| 3394 | // RDX += 1 if RDX < 0 |
| 3395 | __ movq(rax, rdx); |
| 3396 | __ shrq(rdx, Immediate(63)); |
| 3397 | __ addq(rdx, rax); |
| 3398 | |
| 3399 | if (instruction->IsRem()) { |
| 3400 | __ movq(rax, numerator); |
| 3401 | |
| 3402 | if (IsInt<32>(imm)) { |
| 3403 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3404 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3405 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3406 | } |
| 3407 | |
| 3408 | __ subq(rax, rdx); |
| 3409 | __ movq(rdx, rax); |
| 3410 | } else { |
| 3411 | __ movq(rax, rdx); |
| 3412 | } |
| 3413 | } |
| 3414 | } |
| 3415 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3416 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3417 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3418 | Primitive::Type type = instruction->GetResultType(); |
| 3419 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3420 | |
| 3421 | bool is_div = instruction->IsDiv(); |
| 3422 | LocationSummary* locations = instruction->GetLocations(); |
| 3423 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3424 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3425 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3426 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3427 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3428 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3429 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3430 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3431 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3432 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3433 | if (imm == 0) { |
| 3434 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3435 | } else if (imm == 1 || imm == -1) { |
| 3436 | DivRemOneOrMinusOne(instruction); |
| 3437 | } else if (instruction->IsDiv() && IsPowerOfTwo(std::abs(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3438 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3439 | } else { |
| 3440 | DCHECK(imm <= -2 || imm >= 2); |
| 3441 | GenerateDivRemWithAnyConstant(instruction); |
| 3442 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3443 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3444 | SlowPathCode* slow_path = |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3445 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
| 3446 | out.AsRegister(), type, is_div); |
| 3447 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3448 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3449 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3450 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3451 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3452 | // so it's safe to just use negl instead of more complex comparisons. |
| 3453 | if (type == Primitive::kPrimInt) { |
| 3454 | __ cmpl(second_reg, Immediate(-1)); |
| 3455 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3456 | // edx:eax <- sign-extended of eax |
| 3457 | __ cdq(); |
| 3458 | // eax = quotient, edx = remainder |
| 3459 | __ idivl(second_reg); |
| 3460 | } else { |
| 3461 | __ cmpq(second_reg, Immediate(-1)); |
| 3462 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3463 | // rdx:rax <- sign-extended of rax |
| 3464 | __ cqo(); |
| 3465 | // rax = quotient, rdx = remainder |
| 3466 | __ idivq(second_reg); |
| 3467 | } |
| 3468 | __ Bind(slow_path->GetExitLabel()); |
| 3469 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3470 | } |
| 3471 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3472 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3473 | LocationSummary* locations = |
| 3474 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3475 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3476 | case Primitive::kPrimInt: |
| 3477 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3478 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3479 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3480 | locations->SetOut(Location::SameAsFirstInput()); |
| 3481 | // Intel uses edx:eax as the dividend. |
| 3482 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3483 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3484 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3485 | // output and request another temp. |
| 3486 | if (div->InputAt(1)->IsConstant()) { |
| 3487 | locations->AddTemp(Location::RequiresRegister()); |
| 3488 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3489 | break; |
| 3490 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3491 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3492 | case Primitive::kPrimFloat: |
| 3493 | case Primitive::kPrimDouble: { |
| 3494 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3495 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3496 | locations->SetOut(Location::SameAsFirstInput()); |
| 3497 | break; |
| 3498 | } |
| 3499 | |
| 3500 | default: |
| 3501 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3502 | } |
| 3503 | } |
| 3504 | |
| 3505 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3506 | LocationSummary* locations = div->GetLocations(); |
| 3507 | Location first = locations->InAt(0); |
| 3508 | Location second = locations->InAt(1); |
| 3509 | DCHECK(first.Equals(locations->Out())); |
| 3510 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3511 | Primitive::Type type = div->GetResultType(); |
| 3512 | switch (type) { |
| 3513 | case Primitive::kPrimInt: |
| 3514 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3515 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3516 | break; |
| 3517 | } |
| 3518 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3519 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3520 | if (second.IsFpuRegister()) { |
| 3521 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3522 | } else if (second.IsConstant()) { |
| 3523 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3524 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 3525 | } else { |
| 3526 | DCHECK(second.IsStackSlot()); |
| 3527 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3528 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3529 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3530 | break; |
| 3531 | } |
| 3532 | |
| 3533 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3534 | if (second.IsFpuRegister()) { |
| 3535 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3536 | } else if (second.IsConstant()) { |
| 3537 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3538 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 3539 | } else { |
| 3540 | DCHECK(second.IsDoubleStackSlot()); |
| 3541 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3542 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3543 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3544 | break; |
| 3545 | } |
| 3546 | |
| 3547 | default: |
| 3548 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3549 | } |
| 3550 | } |
| 3551 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3552 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3553 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3554 | LocationSummary* locations = |
| 3555 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3556 | |
| 3557 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3558 | case Primitive::kPrimInt: |
| 3559 | case Primitive::kPrimLong: { |
| 3560 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3561 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3562 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3563 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3564 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3565 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3566 | // output and request another temp. |
| 3567 | if (rem->InputAt(1)->IsConstant()) { |
| 3568 | locations->AddTemp(Location::RequiresRegister()); |
| 3569 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3570 | break; |
| 3571 | } |
| 3572 | |
| 3573 | case Primitive::kPrimFloat: |
| 3574 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3575 | locations->SetInAt(0, Location::Any()); |
| 3576 | locations->SetInAt(1, Location::Any()); |
| 3577 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3578 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3579 | break; |
| 3580 | } |
| 3581 | |
| 3582 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3583 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3584 | } |
| 3585 | } |
| 3586 | |
| 3587 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3588 | Primitive::Type type = rem->GetResultType(); |
| 3589 | switch (type) { |
| 3590 | case Primitive::kPrimInt: |
| 3591 | case Primitive::kPrimLong: { |
| 3592 | GenerateDivRemIntegral(rem); |
| 3593 | break; |
| 3594 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3595 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3596 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3597 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3598 | break; |
| 3599 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3600 | default: |
| 3601 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3602 | } |
| 3603 | } |
| 3604 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3605 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3606 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3607 | ? LocationSummary::kCallOnSlowPath |
| 3608 | : LocationSummary::kNoCall; |
| 3609 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3610 | locations->SetInAt(0, Location::Any()); |
| 3611 | if (instruction->HasUses()) { |
| 3612 | locations->SetOut(Location::SameAsFirstInput()); |
| 3613 | } |
| 3614 | } |
| 3615 | |
| 3616 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3617 | SlowPathCode* slow_path = |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3618 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3619 | codegen_->AddSlowPath(slow_path); |
| 3620 | |
| 3621 | LocationSummary* locations = instruction->GetLocations(); |
| 3622 | Location value = locations->InAt(0); |
| 3623 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3624 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3625 | case Primitive::kPrimByte: |
| 3626 | case Primitive::kPrimChar: |
| 3627 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3628 | case Primitive::kPrimInt: { |
| 3629 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3630 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3631 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3632 | } else if (value.IsStackSlot()) { |
| 3633 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3634 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3635 | } else { |
| 3636 | DCHECK(value.IsConstant()) << value; |
| 3637 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3638 | __ jmp(slow_path->GetEntryLabel()); |
| 3639 | } |
| 3640 | } |
| 3641 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3642 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3643 | case Primitive::kPrimLong: { |
| 3644 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3645 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3646 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3647 | } else if (value.IsDoubleStackSlot()) { |
| 3648 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3649 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3650 | } else { |
| 3651 | DCHECK(value.IsConstant()) << value; |
| 3652 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3653 | __ jmp(slow_path->GetEntryLabel()); |
| 3654 | } |
| 3655 | } |
| 3656 | break; |
| 3657 | } |
| 3658 | default: |
| 3659 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3660 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3661 | } |
| 3662 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3663 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3664 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3665 | |
| 3666 | LocationSummary* locations = |
| 3667 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3668 | |
| 3669 | switch (op->GetResultType()) { |
| 3670 | case Primitive::kPrimInt: |
| 3671 | case Primitive::kPrimLong: { |
| 3672 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3673 | // The shift count needs to be in CL. |
| 3674 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3675 | locations->SetOut(Location::SameAsFirstInput()); |
| 3676 | break; |
| 3677 | } |
| 3678 | default: |
| 3679 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3680 | } |
| 3681 | } |
| 3682 | |
| 3683 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3684 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3685 | |
| 3686 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3687 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3688 | Location second = locations->InAt(1); |
| 3689 | |
| 3690 | switch (op->GetResultType()) { |
| 3691 | case Primitive::kPrimInt: { |
| 3692 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3693 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3694 | if (op->IsShl()) { |
| 3695 | __ shll(first_reg, second_reg); |
| 3696 | } else if (op->IsShr()) { |
| 3697 | __ sarl(first_reg, second_reg); |
| 3698 | } else { |
| 3699 | __ shrl(first_reg, second_reg); |
| 3700 | } |
| 3701 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3702 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3703 | if (op->IsShl()) { |
| 3704 | __ shll(first_reg, imm); |
| 3705 | } else if (op->IsShr()) { |
| 3706 | __ sarl(first_reg, imm); |
| 3707 | } else { |
| 3708 | __ shrl(first_reg, imm); |
| 3709 | } |
| 3710 | } |
| 3711 | break; |
| 3712 | } |
| 3713 | case Primitive::kPrimLong: { |
| 3714 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3715 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3716 | if (op->IsShl()) { |
| 3717 | __ shlq(first_reg, second_reg); |
| 3718 | } else if (op->IsShr()) { |
| 3719 | __ sarq(first_reg, second_reg); |
| 3720 | } else { |
| 3721 | __ shrq(first_reg, second_reg); |
| 3722 | } |
| 3723 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3724 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3725 | if (op->IsShl()) { |
| 3726 | __ shlq(first_reg, imm); |
| 3727 | } else if (op->IsShr()) { |
| 3728 | __ sarq(first_reg, imm); |
| 3729 | } else { |
| 3730 | __ shrq(first_reg, imm); |
| 3731 | } |
| 3732 | } |
| 3733 | break; |
| 3734 | } |
| 3735 | default: |
| 3736 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3737 | } |
| 3738 | } |
| 3739 | |
| 3740 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 3741 | HandleShift(shl); |
| 3742 | } |
| 3743 | |
| 3744 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 3745 | HandleShift(shl); |
| 3746 | } |
| 3747 | |
| 3748 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 3749 | HandleShift(shr); |
| 3750 | } |
| 3751 | |
| 3752 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 3753 | HandleShift(shr); |
| 3754 | } |
| 3755 | |
| 3756 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 3757 | HandleShift(ushr); |
| 3758 | } |
| 3759 | |
| 3760 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 3761 | HandleShift(ushr); |
| 3762 | } |
| 3763 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3764 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3765 | LocationSummary* locations = |
| 3766 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3767 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3768 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3769 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3770 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3771 | } |
| 3772 | |
| 3773 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
| 3774 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3775 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3776 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3777 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3778 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3779 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3780 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3781 | instruction, |
| 3782 | instruction->GetDexPc(), |
| 3783 | nullptr); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3784 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3785 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3786 | } |
| 3787 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3788 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 3789 | LocationSummary* locations = |
| 3790 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3791 | InvokeRuntimeCallingConvention calling_convention; |
| 3792 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3793 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3794 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3795 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3796 | } |
| 3797 | |
| 3798 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 3799 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3800 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3801 | instruction->GetTypeIndex()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3802 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3803 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3804 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3805 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3806 | instruction, |
| 3807 | instruction->GetDexPc(), |
| 3808 | nullptr); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3809 | |
| 3810 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3811 | } |
| 3812 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3813 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3814 | LocationSummary* locations = |
| 3815 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3816 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3817 | if (location.IsStackSlot()) { |
| 3818 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3819 | } else if (location.IsDoubleStackSlot()) { |
| 3820 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3821 | } |
| 3822 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3823 | } |
| 3824 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3825 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 3826 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3827 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3828 | } |
| 3829 | |
| 3830 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3831 | LocationSummary* locations = |
| 3832 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3833 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3834 | } |
| 3835 | |
| 3836 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 3837 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3838 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3839 | } |
| 3840 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3841 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3842 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3843 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3844 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3845 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3846 | } |
| 3847 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3848 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 3849 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3850 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3851 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3852 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3853 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3854 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3855 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3856 | break; |
| 3857 | |
| 3858 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3859 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3860 | break; |
| 3861 | |
| 3862 | default: |
| 3863 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3864 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3865 | } |
| 3866 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3867 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3868 | LocationSummary* locations = |
| 3869 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3870 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3871 | locations->SetOut(Location::SameAsFirstInput()); |
| 3872 | } |
| 3873 | |
| 3874 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3875 | LocationSummary* locations = bool_not->GetLocations(); |
| 3876 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3877 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 3878 | Location out = locations->Out(); |
| 3879 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 3880 | } |
| 3881 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3882 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3883 | LocationSummary* locations = |
| 3884 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3885 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3886 | locations->SetInAt(i, Location::Any()); |
| 3887 | } |
| 3888 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3889 | } |
| 3890 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3891 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3892 | LOG(FATAL) << "Unimplemented"; |
| 3893 | } |
| 3894 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3895 | void InstructionCodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3896 | /* |
| 3897 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 3898 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 3899 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 3900 | */ |
| 3901 | switch (kind) { |
| 3902 | case MemBarrierKind::kAnyAny: { |
| 3903 | __ mfence(); |
| 3904 | break; |
| 3905 | } |
| 3906 | case MemBarrierKind::kAnyStore: |
| 3907 | case MemBarrierKind::kLoadAny: |
| 3908 | case MemBarrierKind::kStoreStore: { |
| 3909 | // nop |
| 3910 | break; |
| 3911 | } |
| 3912 | default: |
| 3913 | LOG(FATAL) << "Unexpected memory barier " << kind; |
| 3914 | } |
| 3915 | } |
| 3916 | |
| 3917 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 3918 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 3919 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 3920 | bool object_field_get_with_read_barrier = |
| 3921 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3922 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 3923 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 3924 | object_field_get_with_read_barrier ? |
| 3925 | LocationSummary::kCallOnSlowPath : |
| 3926 | LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3927 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3928 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3929 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3930 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 3931 | // The output overlaps for an object field get when read barriers |
| 3932 | // are enabled: we do not want the move to overwrite the object's |
| 3933 | // location, as we need it to emit the read barrier. |
| 3934 | locations->SetOut( |
| 3935 | Location::RequiresRegister(), |
| 3936 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3937 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3938 | } |
| 3939 | |
| 3940 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 3941 | const FieldInfo& field_info) { |
| 3942 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 3943 | |
| 3944 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 3945 | Location base_loc = locations->InAt(0); |
| 3946 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3947 | Location out = locations->Out(); |
| 3948 | bool is_volatile = field_info.IsVolatile(); |
| 3949 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3950 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3951 | |
| 3952 | switch (field_type) { |
| 3953 | case Primitive::kPrimBoolean: { |
| 3954 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3955 | break; |
| 3956 | } |
| 3957 | |
| 3958 | case Primitive::kPrimByte: { |
| 3959 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3960 | break; |
| 3961 | } |
| 3962 | |
| 3963 | case Primitive::kPrimShort: { |
| 3964 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3965 | break; |
| 3966 | } |
| 3967 | |
| 3968 | case Primitive::kPrimChar: { |
| 3969 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3970 | break; |
| 3971 | } |
| 3972 | |
| 3973 | case Primitive::kPrimInt: |
| 3974 | case Primitive::kPrimNot: { |
| 3975 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3976 | break; |
| 3977 | } |
| 3978 | |
| 3979 | case Primitive::kPrimLong: { |
| 3980 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3981 | break; |
| 3982 | } |
| 3983 | |
| 3984 | case Primitive::kPrimFloat: { |
| 3985 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 3986 | break; |
| 3987 | } |
| 3988 | |
| 3989 | case Primitive::kPrimDouble: { |
| 3990 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 3991 | break; |
| 3992 | } |
| 3993 | |
| 3994 | case Primitive::kPrimVoid: |
| 3995 | LOG(FATAL) << "Unreachable type " << field_type; |
| 3996 | UNREACHABLE(); |
| 3997 | } |
| 3998 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3999 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4000 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4001 | if (is_volatile) { |
| 4002 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4003 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4004 | |
| 4005 | if (field_type == Primitive::kPrimNot) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4006 | codegen_->MaybeGenerateReadBarrier(instruction, out, out, base_loc, offset); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4007 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4008 | } |
| 4009 | |
| 4010 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4011 | const FieldInfo& field_info) { |
| 4012 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4013 | |
| 4014 | LocationSummary* locations = |
| 4015 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4016 | Primitive::Type field_type = field_info.GetFieldType(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4017 | bool is_volatile = field_info.IsVolatile(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4018 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4019 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4020 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4021 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4022 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4023 | if (is_volatile) { |
| 4024 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4025 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4026 | } else { |
| 4027 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4028 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4029 | } else { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4030 | if (is_volatile) { |
| 4031 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4032 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4033 | } else { |
| 4034 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4035 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4036 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4037 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4038 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4039 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4040 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4041 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4042 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4043 | locations->AddTemp(Location::RequiresRegister()); |
| 4044 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4045 | } |
| 4046 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4047 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4048 | const FieldInfo& field_info, |
| 4049 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4050 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4051 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4052 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4053 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4054 | Location value = locations->InAt(1); |
| 4055 | bool is_volatile = field_info.IsVolatile(); |
| 4056 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4057 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4058 | |
| 4059 | if (is_volatile) { |
| 4060 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 4061 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4062 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4063 | bool maybe_record_implicit_null_check_done = false; |
| 4064 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4065 | switch (field_type) { |
| 4066 | case Primitive::kPrimBoolean: |
| 4067 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4068 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4069 | int8_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4070 | __ movb(Address(base, offset), Immediate(v)); |
| 4071 | } else { |
| 4072 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4073 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4074 | break; |
| 4075 | } |
| 4076 | |
| 4077 | case Primitive::kPrimShort: |
| 4078 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4079 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4080 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4081 | __ movw(Address(base, offset), Immediate(v)); |
| 4082 | } else { |
| 4083 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4084 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4085 | break; |
| 4086 | } |
| 4087 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4088 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4089 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4090 | if (value.IsConstant()) { |
| 4091 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4092 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 4093 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 4094 | // Note: if heap poisoning is enabled, no need to poison |
| 4095 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4096 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4097 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4098 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4099 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4100 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4101 | __ PoisonHeapReference(temp); |
| 4102 | __ movl(Address(base, offset), temp); |
| 4103 | } else { |
| 4104 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4105 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4106 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4107 | break; |
| 4108 | } |
| 4109 | |
| 4110 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4111 | if (value.IsConstant()) { |
| 4112 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4113 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4114 | Address(base, offset + sizeof(int32_t)), |
| 4115 | v, |
| 4116 | instruction); |
| 4117 | maybe_record_implicit_null_check_done = true; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4118 | } else { |
| 4119 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4120 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4121 | break; |
| 4122 | } |
| 4123 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4124 | case Primitive::kPrimFloat: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4125 | if (value.IsConstant()) { |
| 4126 | int32_t v = |
| 4127 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4128 | __ movl(Address(base, offset), Immediate(v)); |
| 4129 | } else { |
| 4130 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4131 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4132 | break; |
| 4133 | } |
| 4134 | |
| 4135 | case Primitive::kPrimDouble: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4136 | if (value.IsConstant()) { |
| 4137 | int64_t v = |
| 4138 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4139 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4140 | Address(base, offset + sizeof(int32_t)), |
| 4141 | v, |
| 4142 | instruction); |
| 4143 | maybe_record_implicit_null_check_done = true; |
| 4144 | } else { |
| 4145 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4146 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4147 | break; |
| 4148 | } |
| 4149 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4150 | case Primitive::kPrimVoid: |
| 4151 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4152 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4153 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4154 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4155 | if (!maybe_record_implicit_null_check_done) { |
| 4156 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4157 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4158 | |
| 4159 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4160 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4161 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4162 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4163 | } |
| 4164 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4165 | if (is_volatile) { |
| 4166 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 4167 | } |
| 4168 | } |
| 4169 | |
| 4170 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4171 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4172 | } |
| 4173 | |
| 4174 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4175 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4176 | } |
| 4177 | |
| 4178 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4179 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4180 | } |
| 4181 | |
| 4182 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4183 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4184 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4185 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4186 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4187 | HandleFieldGet(instruction); |
| 4188 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4189 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4190 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4191 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4192 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4193 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4194 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4195 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4196 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4197 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4198 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4199 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4200 | } |
| 4201 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4202 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4203 | HUnresolvedInstanceFieldGet* instruction) { |
| 4204 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4205 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4206 | instruction, instruction->GetFieldType(), calling_convention); |
| 4207 | } |
| 4208 | |
| 4209 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4210 | HUnresolvedInstanceFieldGet* instruction) { |
| 4211 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4212 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4213 | instruction->GetFieldType(), |
| 4214 | instruction->GetFieldIndex(), |
| 4215 | instruction->GetDexPc(), |
| 4216 | calling_convention); |
| 4217 | } |
| 4218 | |
| 4219 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4220 | HUnresolvedInstanceFieldSet* instruction) { |
| 4221 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4222 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4223 | instruction, instruction->GetFieldType(), calling_convention); |
| 4224 | } |
| 4225 | |
| 4226 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4227 | HUnresolvedInstanceFieldSet* instruction) { |
| 4228 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4229 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4230 | instruction->GetFieldType(), |
| 4231 | instruction->GetFieldIndex(), |
| 4232 | instruction->GetDexPc(), |
| 4233 | calling_convention); |
| 4234 | } |
| 4235 | |
| 4236 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4237 | HUnresolvedStaticFieldGet* instruction) { |
| 4238 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4239 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4240 | instruction, instruction->GetFieldType(), calling_convention); |
| 4241 | } |
| 4242 | |
| 4243 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4244 | HUnresolvedStaticFieldGet* instruction) { |
| 4245 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4246 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4247 | instruction->GetFieldType(), |
| 4248 | instruction->GetFieldIndex(), |
| 4249 | instruction->GetDexPc(), |
| 4250 | calling_convention); |
| 4251 | } |
| 4252 | |
| 4253 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4254 | HUnresolvedStaticFieldSet* instruction) { |
| 4255 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4256 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4257 | instruction, instruction->GetFieldType(), calling_convention); |
| 4258 | } |
| 4259 | |
| 4260 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4261 | HUnresolvedStaticFieldSet* instruction) { |
| 4262 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4263 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4264 | instruction->GetFieldType(), |
| 4265 | instruction->GetFieldIndex(), |
| 4266 | instruction->GetDexPc(), |
| 4267 | calling_convention); |
| 4268 | } |
| 4269 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4270 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4271 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4272 | ? LocationSummary::kCallOnSlowPath |
| 4273 | : LocationSummary::kNoCall; |
| 4274 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4275 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4276 | ? Location::RequiresRegister() |
| 4277 | : Location::Any(); |
| 4278 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4279 | if (instruction->HasUses()) { |
| 4280 | locations->SetOut(Location::SameAsFirstInput()); |
| 4281 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4282 | } |
| 4283 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4284 | void InstructionCodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4285 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4286 | return; |
| 4287 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4288 | LocationSummary* locations = instruction->GetLocations(); |
| 4289 | Location obj = locations->InAt(0); |
| 4290 | |
| 4291 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
| 4292 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4293 | } |
| 4294 | |
| 4295 | void InstructionCodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4296 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4297 | codegen_->AddSlowPath(slow_path); |
| 4298 | |
| 4299 | LocationSummary* locations = instruction->GetLocations(); |
| 4300 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4301 | |
| 4302 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4303 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4304 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4305 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4306 | } else { |
| 4307 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4308 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4309 | __ jmp(slow_path->GetEntryLabel()); |
| 4310 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4311 | } |
| 4312 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4313 | } |
| 4314 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4315 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4316 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4317 | GenerateImplicitNullCheck(instruction); |
| 4318 | } else { |
| 4319 | GenerateExplicitNullCheck(instruction); |
| 4320 | } |
| 4321 | } |
| 4322 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4323 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4324 | bool object_array_get_with_read_barrier = |
| 4325 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4326 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4327 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4328 | object_array_get_with_read_barrier ? |
| 4329 | LocationSummary::kCallOnSlowPath : |
| 4330 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4331 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4332 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4333 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4334 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4335 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4336 | // The output overlaps for an object array get when read barriers |
| 4337 | // are enabled: we do not want the move to overwrite the array's |
| 4338 | // location, as we need it to emit the read barrier. |
| 4339 | locations->SetOut( |
| 4340 | Location::RequiresRegister(), |
| 4341 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4342 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4343 | } |
| 4344 | |
| 4345 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4346 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4347 | Location obj_loc = locations->InAt(0); |
| 4348 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4349 | Location index = locations->InAt(1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4350 | Primitive::Type type = instruction->GetType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4351 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4352 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4353 | case Primitive::kPrimBoolean: { |
| 4354 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4355 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4356 | if (index.IsConstant()) { |
| 4357 | __ movzxb(out, Address(obj, |
| 4358 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4359 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4360 | __ movzxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4361 | } |
| 4362 | break; |
| 4363 | } |
| 4364 | |
| 4365 | case Primitive::kPrimByte: { |
| 4366 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4367 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4368 | if (index.IsConstant()) { |
| 4369 | __ movsxb(out, Address(obj, |
| 4370 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4371 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4372 | __ movsxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4373 | } |
| 4374 | break; |
| 4375 | } |
| 4376 | |
| 4377 | case Primitive::kPrimShort: { |
| 4378 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4379 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4380 | if (index.IsConstant()) { |
| 4381 | __ movsxw(out, Address(obj, |
| 4382 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4383 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4384 | __ movsxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4385 | } |
| 4386 | break; |
| 4387 | } |
| 4388 | |
| 4389 | case Primitive::kPrimChar: { |
| 4390 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4391 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4392 | if (index.IsConstant()) { |
| 4393 | __ movzxw(out, Address(obj, |
| 4394 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4395 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4396 | __ movzxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4397 | } |
| 4398 | break; |
| 4399 | } |
| 4400 | |
| 4401 | case Primitive::kPrimInt: |
| 4402 | case Primitive::kPrimNot: { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4403 | static_assert( |
| 4404 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4405 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4406 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4407 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4408 | if (index.IsConstant()) { |
| 4409 | __ movl(out, Address(obj, |
| 4410 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4411 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4412 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4413 | } |
| 4414 | break; |
| 4415 | } |
| 4416 | |
| 4417 | case Primitive::kPrimLong: { |
| 4418 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4419 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4420 | if (index.IsConstant()) { |
| 4421 | __ movq(out, Address(obj, |
| 4422 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4423 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4424 | __ movq(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4425 | } |
| 4426 | break; |
| 4427 | } |
| 4428 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4429 | case Primitive::kPrimFloat: { |
| 4430 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4431 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4432 | if (index.IsConstant()) { |
| 4433 | __ movss(out, Address(obj, |
| 4434 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4435 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4436 | __ movss(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4437 | } |
| 4438 | break; |
| 4439 | } |
| 4440 | |
| 4441 | case Primitive::kPrimDouble: { |
| 4442 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4443 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4444 | if (index.IsConstant()) { |
| 4445 | __ movsd(out, Address(obj, |
| 4446 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4447 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4448 | __ movsd(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4449 | } |
| 4450 | break; |
| 4451 | } |
| 4452 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4453 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4454 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4455 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4456 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4457 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4458 | |
| 4459 | if (type == Primitive::kPrimNot) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4460 | static_assert( |
| 4461 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4462 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 4463 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4464 | Location out = locations->Out(); |
| 4465 | if (index.IsConstant()) { |
| 4466 | uint32_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4467 | codegen_->MaybeGenerateReadBarrier(instruction, out, out, obj_loc, offset); |
| 4468 | } else { |
| 4469 | codegen_->MaybeGenerateReadBarrier(instruction, out, out, obj_loc, data_offset, index); |
| 4470 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4471 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4472 | } |
| 4473 | |
| 4474 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4475 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4476 | |
| 4477 | bool needs_write_barrier = |
| 4478 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4479 | bool may_need_runtime_call = instruction->NeedsTypeCheck(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4480 | bool object_array_set_with_read_barrier = |
| 4481 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4482 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4483 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4484 | instruction, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4485 | (may_need_runtime_call || object_array_set_with_read_barrier) ? |
| 4486 | LocationSummary::kCallOnSlowPath : |
| 4487 | LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4488 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4489 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4490 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4491 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4492 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4493 | } else { |
| 4494 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4495 | } |
| 4496 | |
| 4497 | if (needs_write_barrier) { |
| 4498 | // Temporary registers for the write barrier. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4499 | |
| 4500 | // This first temporary register is possibly used for heap |
| 4501 | // reference poisoning and/or read barrier emission too. |
| 4502 | locations->AddTemp(Location::RequiresRegister()); |
| 4503 | // This second temporary register is possibly used for read |
| 4504 | // barrier emission too. |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4505 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4506 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4507 | } |
| 4508 | |
| 4509 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4510 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4511 | Location array_loc = locations->InAt(0); |
| 4512 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4513 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4514 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4515 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4516 | bool may_need_runtime_call = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4517 | bool needs_write_barrier = |
| 4518 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4519 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4520 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4521 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4522 | |
| 4523 | switch (value_type) { |
| 4524 | case Primitive::kPrimBoolean: |
| 4525 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4526 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 4527 | Address address = index.IsConstant() |
| 4528 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 4529 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_1, offset); |
| 4530 | if (value.IsRegister()) { |
| 4531 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4532 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4533 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4534 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4535 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4536 | break; |
| 4537 | } |
| 4538 | |
| 4539 | case Primitive::kPrimShort: |
| 4540 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4541 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 4542 | Address address = index.IsConstant() |
| 4543 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 4544 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_2, offset); |
| 4545 | if (value.IsRegister()) { |
| 4546 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4547 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4548 | DCHECK(value.IsConstant()) << value; |
| 4549 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4550 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4551 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4552 | break; |
| 4553 | } |
| 4554 | |
| 4555 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4556 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4557 | Address address = index.IsConstant() |
| 4558 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4559 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4560 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4561 | if (!value.IsRegister()) { |
| 4562 | // Just setting null. |
| 4563 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4564 | DCHECK(value.IsConstant()) << value; |
| 4565 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4566 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4567 | DCHECK(!needs_write_barrier); |
| 4568 | DCHECK(!may_need_runtime_call); |
| 4569 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4570 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4571 | |
| 4572 | DCHECK(needs_write_barrier); |
| 4573 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
| 4574 | NearLabel done, not_null, do_put; |
| 4575 | SlowPathCode* slow_path = nullptr; |
| 4576 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4577 | if (may_need_runtime_call) { |
| 4578 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86_64(instruction); |
| 4579 | codegen_->AddSlowPath(slow_path); |
| 4580 | if (instruction->GetValueCanBeNull()) { |
| 4581 | __ testl(register_value, register_value); |
| 4582 | __ j(kNotEqual, ¬_null); |
| 4583 | __ movl(address, Immediate(0)); |
| 4584 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4585 | __ jmp(&done); |
| 4586 | __ Bind(¬_null); |
| 4587 | } |
| 4588 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4589 | if (kEmitCompilerReadBarrier) { |
| 4590 | // When read barriers are enabled, the type checking |
| 4591 | // instrumentation requires two read barriers: |
| 4592 | // |
| 4593 | // __ movl(temp2, temp); |
| 4594 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4595 | // __ movl(temp, Address(temp, component_offset)); |
| 4596 | // codegen_->GenerateReadBarrier( |
| 4597 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 4598 | // |
| 4599 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 4600 | // __ movl(temp2, Address(register_value, class_offset)); |
| 4601 | // codegen_->GenerateReadBarrier( |
| 4602 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 4603 | // |
| 4604 | // __ cmpl(temp, temp2); |
| 4605 | // |
| 4606 | // However, the second read barrier may trash `temp`, as it |
| 4607 | // is a temporary register, and as such would not be saved |
| 4608 | // along with live registers before calling the runtime (nor |
| 4609 | // restored afterwards). So in this case, we bail out and |
| 4610 | // delegate the work to the array set slow path. |
| 4611 | // |
| 4612 | // TODO: Extend the register allocator to support a new |
| 4613 | // "(locally) live temp" location so as to avoid always |
| 4614 | // going into the slow path when read barriers are enabled. |
| 4615 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4616 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4617 | // /* HeapReference<Class> */ temp = array->klass_ |
| 4618 | __ movl(temp, Address(array, class_offset)); |
| 4619 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4620 | __ MaybeUnpoisonHeapReference(temp); |
| 4621 | |
| 4622 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4623 | __ movl(temp, Address(temp, component_offset)); |
| 4624 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 4625 | // nor the object reference in `register_value->klass`, as |
| 4626 | // we are comparing two poisoned references. |
| 4627 | __ cmpl(temp, Address(register_value, class_offset)); |
| 4628 | |
| 4629 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4630 | __ j(kEqual, &do_put); |
| 4631 | // If heap poisoning is enabled, the `temp` reference has |
| 4632 | // not been unpoisoned yet; unpoison it now. |
| 4633 | __ MaybeUnpoisonHeapReference(temp); |
| 4634 | |
| 4635 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 4636 | __ movl(temp, Address(temp, super_offset)); |
| 4637 | // If heap poisoning is enabled, no need to unpoison |
| 4638 | // `temp`, as we are comparing against null below. |
| 4639 | __ testl(temp, temp); |
| 4640 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4641 | __ Bind(&do_put); |
| 4642 | } else { |
| 4643 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4644 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4645 | } |
| 4646 | } |
| 4647 | |
| 4648 | if (kPoisonHeapReferences) { |
| 4649 | __ movl(temp, register_value); |
| 4650 | __ PoisonHeapReference(temp); |
| 4651 | __ movl(address, temp); |
| 4652 | } else { |
| 4653 | __ movl(address, register_value); |
| 4654 | } |
| 4655 | if (!may_need_runtime_call) { |
| 4656 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4657 | } |
| 4658 | |
| 4659 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4660 | codegen_->MarkGCCard( |
| 4661 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4662 | __ Bind(&done); |
| 4663 | |
| 4664 | if (slow_path != nullptr) { |
| 4665 | __ Bind(slow_path->GetExitLabel()); |
| 4666 | } |
| 4667 | |
| 4668 | break; |
| 4669 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4670 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4671 | case Primitive::kPrimInt: { |
| 4672 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4673 | Address address = index.IsConstant() |
| 4674 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4675 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
| 4676 | if (value.IsRegister()) { |
| 4677 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 4678 | } else { |
| 4679 | DCHECK(value.IsConstant()) << value; |
| 4680 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4681 | __ movl(address, Immediate(v)); |
| 4682 | } |
| 4683 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4684 | break; |
| 4685 | } |
| 4686 | |
| 4687 | case Primitive::kPrimLong: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4688 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 4689 | Address address = index.IsConstant() |
| 4690 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4691 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
| 4692 | if (value.IsRegister()) { |
| 4693 | __ movq(address, value.AsRegister<CpuRegister>()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4694 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4695 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4696 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4697 | Address address_high = index.IsConstant() |
| 4698 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 4699 | offset + sizeof(int32_t)) |
| 4700 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset + sizeof(int32_t)); |
| 4701 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4702 | } |
| 4703 | break; |
| 4704 | } |
| 4705 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4706 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4707 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4708 | Address address = index.IsConstant() |
| 4709 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4710 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4711 | if (value.IsFpuRegister()) { |
| 4712 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 4713 | } else { |
| 4714 | DCHECK(value.IsConstant()); |
| 4715 | int32_t v = |
| 4716 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4717 | __ movl(address, Immediate(v)); |
| 4718 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4719 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4720 | break; |
| 4721 | } |
| 4722 | |
| 4723 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4724 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4725 | Address address = index.IsConstant() |
| 4726 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4727 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4728 | if (value.IsFpuRegister()) { |
| 4729 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 4730 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4731 | } else { |
| 4732 | int64_t v = |
| 4733 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4734 | Address address_high = index.IsConstant() |
| 4735 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 4736 | offset + sizeof(int32_t)) |
| 4737 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset + sizeof(int32_t)); |
| 4738 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 4739 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4740 | break; |
| 4741 | } |
| 4742 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4743 | case Primitive::kPrimVoid: |
| 4744 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4745 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4746 | } |
| 4747 | } |
| 4748 | |
| 4749 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4750 | LocationSummary* locations = |
| 4751 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4752 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4753 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4754 | } |
| 4755 | |
| 4756 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 4757 | LocationSummary* locations = instruction->GetLocations(); |
| 4758 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4759 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4760 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4761 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4762 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4763 | } |
| 4764 | |
| 4765 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4766 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4767 | ? LocationSummary::kCallOnSlowPath |
| 4768 | : LocationSummary::kNoCall; |
| 4769 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4770 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4771 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4772 | if (instruction->HasUses()) { |
| 4773 | locations->SetOut(Location::SameAsFirstInput()); |
| 4774 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4775 | } |
| 4776 | |
| 4777 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4778 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4779 | Location index_loc = locations->InAt(0); |
| 4780 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4781 | SlowPathCode* slow_path = |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4782 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4783 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4784 | if (length_loc.IsConstant()) { |
| 4785 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4786 | if (index_loc.IsConstant()) { |
| 4787 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4788 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4789 | if (index < 0 || index >= length) { |
| 4790 | codegen_->AddSlowPath(slow_path); |
| 4791 | __ jmp(slow_path->GetEntryLabel()); |
| 4792 | } else { |
| 4793 | // Some optimization after BCE may have generated this, and we should not |
| 4794 | // generate a bounds check if it is a valid range. |
| 4795 | } |
| 4796 | return; |
| 4797 | } |
| 4798 | |
| 4799 | // We have to reverse the jump condition because the length is the constant. |
| 4800 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 4801 | __ cmpl(index_reg, Immediate(length)); |
| 4802 | codegen_->AddSlowPath(slow_path); |
| 4803 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4804 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4805 | CpuRegister length = length_loc.AsRegister<CpuRegister>(); |
| 4806 | if (index_loc.IsConstant()) { |
| 4807 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4808 | __ cmpl(length, Immediate(value)); |
| 4809 | } else { |
| 4810 | __ cmpl(length, index_loc.AsRegister<CpuRegister>()); |
| 4811 | } |
| 4812 | codegen_->AddSlowPath(slow_path); |
| 4813 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4814 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4815 | } |
| 4816 | |
| 4817 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 4818 | CpuRegister card, |
| 4819 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4820 | CpuRegister value, |
| 4821 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4822 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4823 | if (value_can_be_null) { |
| 4824 | __ testl(value, value); |
| 4825 | __ j(kEqual, &is_null); |
| 4826 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4827 | __ gs()->movq(card, Address::Absolute( |
| 4828 | Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), true)); |
| 4829 | __ movq(temp, object); |
| 4830 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4831 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4832 | if (value_can_be_null) { |
| 4833 | __ Bind(&is_null); |
| 4834 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4835 | } |
| 4836 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4837 | void LocationsBuilderX86_64::VisitTemporary(HTemporary* temp) { |
| 4838 | temp->SetLocations(nullptr); |
| 4839 | } |
| 4840 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4841 | void InstructionCodeGeneratorX86_64::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4842 | // Nothing to do, this is driven by the code generator. |
| 4843 | } |
| 4844 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4845 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4846 | LOG(FATAL) << "Unimplemented"; |
| 4847 | } |
| 4848 | |
| 4849 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4850 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4851 | } |
| 4852 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4853 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4854 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4855 | } |
| 4856 | |
| 4857 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4858 | HBasicBlock* block = instruction->GetBlock(); |
| 4859 | if (block->GetLoopInformation() != nullptr) { |
| 4860 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4861 | // The back edge will generate the suspend check. |
| 4862 | return; |
| 4863 | } |
| 4864 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4865 | // The goto will generate the suspend check. |
| 4866 | return; |
| 4867 | } |
| 4868 | GenerateSuspendCheck(instruction, nullptr); |
| 4869 | } |
| 4870 | |
| 4871 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4872 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4873 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4874 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 4875 | if (slow_path == nullptr) { |
| 4876 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 4877 | instruction->SetSlowPath(slow_path); |
| 4878 | codegen_->AddSlowPath(slow_path); |
| 4879 | if (successor != nullptr) { |
| 4880 | DCHECK(successor->IsLoopHeader()); |
| 4881 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4882 | } |
| 4883 | } else { |
| 4884 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4885 | } |
| 4886 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4887 | __ gs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4888 | Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), true), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4889 | if (successor == nullptr) { |
| 4890 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4891 | __ Bind(slow_path->GetReturnLabel()); |
| 4892 | } else { |
| 4893 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 4894 | __ jmp(slow_path->GetEntryLabel()); |
| 4895 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4896 | } |
| 4897 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4898 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 4899 | return codegen_->GetAssembler(); |
| 4900 | } |
| 4901 | |
| 4902 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4903 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4904 | Location source = move->GetSource(); |
| 4905 | Location destination = move->GetDestination(); |
| 4906 | |
| 4907 | if (source.IsRegister()) { |
| 4908 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4909 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4910 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4911 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4912 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4913 | } else { |
| 4914 | DCHECK(destination.IsDoubleStackSlot()); |
| 4915 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4916 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4917 | } |
| 4918 | } else if (source.IsStackSlot()) { |
| 4919 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4920 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4921 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4922 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4923 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4924 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4925 | } else { |
| 4926 | DCHECK(destination.IsStackSlot()); |
| 4927 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 4928 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4929 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4930 | } else if (source.IsDoubleStackSlot()) { |
| 4931 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4932 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4933 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4934 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4935 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 4936 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4937 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 4938 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4939 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 4940 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4941 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4942 | } else if (source.IsConstant()) { |
| 4943 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4944 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 4945 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4946 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4947 | if (value == 0) { |
| 4948 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 4949 | } else { |
| 4950 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 4951 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4952 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4953 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4954 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4955 | } |
| 4956 | } else if (constant->IsLongConstant()) { |
| 4957 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 4958 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4959 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4960 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4961 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 4962 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4963 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4964 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4965 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4966 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4967 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4968 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4969 | if (value == 0) { |
| 4970 | // easy FP 0.0. |
| 4971 | __ xorps(dest, dest); |
| 4972 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4973 | __ movss(dest, codegen_->LiteralFloatAddress(fp_value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4974 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4975 | } else { |
| 4976 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4977 | Immediate imm(value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4978 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 4979 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4980 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4981 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4982 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4983 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4984 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4985 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4986 | if (value == 0) { |
| 4987 | __ xorpd(dest, dest); |
| 4988 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4989 | __ movsd(dest, codegen_->LiteralDoubleAddress(fp_value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4990 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4991 | } else { |
| 4992 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 4993 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4994 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4995 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4996 | } else if (source.IsFpuRegister()) { |
| 4997 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4998 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4999 | } else if (destination.IsStackSlot()) { |
| 5000 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5001 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5002 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 5003 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5004 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5005 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5006 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5007 | } |
| 5008 | } |
| 5009 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5010 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5011 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5012 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5013 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5014 | } |
| 5015 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5016 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5017 | ScratchRegisterScope ensure_scratch( |
| 5018 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5019 | |
| 5020 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5021 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5022 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5023 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5024 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5025 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5026 | CpuRegister(ensure_scratch.GetRegister())); |
| 5027 | } |
| 5028 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5029 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5030 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5031 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5032 | __ movq(reg, CpuRegister(TMP)); |
| 5033 | } |
| 5034 | |
| 5035 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 5036 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5037 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5038 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5039 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5040 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5041 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5042 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5043 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5044 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5045 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5046 | } |
| 5047 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5048 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5049 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5050 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5051 | __ movd(reg, CpuRegister(TMP)); |
| 5052 | } |
| 5053 | |
| 5054 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5055 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5056 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5057 | __ movd(reg, CpuRegister(TMP)); |
| 5058 | } |
| 5059 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5060 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5061 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5062 | Location source = move->GetSource(); |
| 5063 | Location destination = move->GetDestination(); |
| 5064 | |
| 5065 | if (source.IsRegister() && destination.IsRegister()) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5066 | __ xchgq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5067 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5068 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5069 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5070 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5071 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5072 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5073 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5074 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5075 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5076 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5077 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 5078 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5079 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5080 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5081 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5082 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5083 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5084 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5085 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5086 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5087 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5088 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5089 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5090 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5091 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5092 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5093 | } |
| 5094 | } |
| 5095 | |
| 5096 | |
| 5097 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5098 | __ pushq(CpuRegister(reg)); |
| 5099 | } |
| 5100 | |
| 5101 | |
| 5102 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5103 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5104 | } |
| 5105 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5106 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5107 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5108 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5109 | Immediate(mirror::Class::kStatusInitialized)); |
| 5110 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5111 | __ Bind(slow_path->GetExitLabel()); |
| 5112 | // No need for memory fence, thanks to the X86_64 memory model. |
| 5113 | } |
| 5114 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5115 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5116 | InvokeRuntimeCallingConvention calling_convention; |
| 5117 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5118 | cls, |
| 5119 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5120 | Location::RegisterLocation(RAX), |
| 5121 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5122 | } |
| 5123 | |
| 5124 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5125 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5126 | if (cls->NeedsAccessCheck()) { |
| 5127 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5128 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5129 | cls, |
| 5130 | cls->GetDexPc(), |
| 5131 | nullptr); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5132 | return; |
| 5133 | } |
| 5134 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5135 | Location out_loc = locations->Out(); |
| 5136 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5137 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5138 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5139 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5140 | DCHECK(!cls->CanCallRuntime()); |
| 5141 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5142 | uint32_t declaring_class_offset = ArtMethod::DeclaringClassOffset().Int32Value(); |
| 5143 | if (kEmitCompilerReadBarrier) { |
| 5144 | // /* GcRoot<mirror::Class>* */ out = &(current_method->declaring_class_) |
| 5145 | __ leaq(out, Address(current_method, declaring_class_offset)); |
| 5146 | // /* mirror::Class* */ out = out->Read() |
| 5147 | codegen_->GenerateReadBarrierForRoot(cls, out_loc, out_loc); |
| 5148 | } else { |
| 5149 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5150 | __ movl(out, Address(current_method, declaring_class_offset)); |
| 5151 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5152 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5153 | DCHECK(cls->CanCallRuntime()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5154 | // /* GcRoot<mirror::Class>[] */ out = |
| 5155 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5156 | __ movq(out, Address(current_method, |
| 5157 | ArtMethod::DexCacheResolvedTypesOffset(kX86_64PointerSize).Int32Value())); |
| 5158 | |
| 5159 | size_t cache_offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex()); |
| 5160 | if (kEmitCompilerReadBarrier) { |
| 5161 | // /* GcRoot<mirror::Class>* */ out = &out[type_index] |
| 5162 | __ leaq(out, Address(out, cache_offset)); |
| 5163 | // /* mirror::Class* */ out = out->Read() |
| 5164 | codegen_->GenerateReadBarrierForRoot(cls, out_loc, out_loc); |
| 5165 | } else { |
| 5166 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5167 | __ movl(out, Address(out, cache_offset)); |
| 5168 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5169 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5170 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5171 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5172 | codegen_->AddSlowPath(slow_path); |
| 5173 | __ testl(out, out); |
| 5174 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5175 | if (cls->MustGenerateClinitCheck()) { |
| 5176 | GenerateClassInitializationCheck(slow_path, out); |
| 5177 | } else { |
| 5178 | __ Bind(slow_path->GetExitLabel()); |
| 5179 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5180 | } |
| 5181 | } |
| 5182 | |
| 5183 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 5184 | LocationSummary* locations = |
| 5185 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5186 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5187 | if (check->HasUses()) { |
| 5188 | locations->SetOut(Location::SameAsFirstInput()); |
| 5189 | } |
| 5190 | } |
| 5191 | |
| 5192 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5193 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5194 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5195 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5196 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5197 | GenerateClassInitializationCheck(slow_path, |
| 5198 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5199 | } |
| 5200 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5201 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
| 5202 | LocationSummary* locations = |
| 5203 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5204 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5205 | locations->SetOut(Location::RequiresRegister()); |
| 5206 | } |
| 5207 | |
| 5208 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5209 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5210 | codegen_->AddSlowPath(slow_path); |
| 5211 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5212 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5213 | Location out_loc = locations->Out(); |
| 5214 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5215 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5216 | |
| 5217 | uint32_t declaring_class_offset = ArtMethod::DeclaringClassOffset().Int32Value(); |
| 5218 | if (kEmitCompilerReadBarrier) { |
| 5219 | // /* GcRoot<mirror::Class>* */ out = &(current_method->declaring_class_) |
| 5220 | __ leaq(out, Address(current_method, declaring_class_offset)); |
| 5221 | // /* mirror::Class* */ out = out->Read() |
| 5222 | codegen_->GenerateReadBarrierForRoot(load, out_loc, out_loc); |
| 5223 | } else { |
| 5224 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5225 | __ movl(out, Address(current_method, declaring_class_offset)); |
| 5226 | } |
| 5227 | |
| 5228 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
| 5229 | __ movq(out, Address(out, mirror::Class::DexCacheStringsOffset().Uint32Value())); |
| 5230 | |
| 5231 | size_t cache_offset = CodeGenerator::GetCacheOffset(load->GetStringIndex()); |
| 5232 | if (kEmitCompilerReadBarrier) { |
| 5233 | // /* GcRoot<mirror::String>* */ out = &out[string_index] |
| 5234 | __ leaq(out, Address(out, cache_offset)); |
| 5235 | // /* mirror::String* */ out = out->Read() |
| 5236 | codegen_->GenerateReadBarrierForRoot(load, out_loc, out_loc); |
| 5237 | } else { |
| 5238 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5239 | __ movl(out, Address(out, cache_offset)); |
| 5240 | } |
| 5241 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5242 | __ testl(out, out); |
| 5243 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5244 | __ Bind(slow_path->GetExitLabel()); |
| 5245 | } |
| 5246 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5247 | static Address GetExceptionTlsAddress() { |
| 5248 | return Address::Absolute(Thread::ExceptionOffset<kX86_64WordSize>().Int32Value(), true); |
| 5249 | } |
| 5250 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5251 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 5252 | LocationSummary* locations = |
| 5253 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5254 | locations->SetOut(Location::RequiresRegister()); |
| 5255 | } |
| 5256 | |
| 5257 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5258 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 5259 | } |
| 5260 | |
| 5261 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 5262 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5263 | } |
| 5264 | |
| 5265 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5266 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5267 | } |
| 5268 | |
| 5269 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 5270 | LocationSummary* locations = |
| 5271 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5272 | InvokeRuntimeCallingConvention calling_convention; |
| 5273 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5274 | } |
| 5275 | |
| 5276 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5277 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 5278 | instruction, |
| 5279 | instruction->GetDexPc(), |
| 5280 | nullptr); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5281 | } |
| 5282 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5283 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5284 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5285 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5286 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5287 | case TypeCheckKind::kExactCheck: |
| 5288 | case TypeCheckKind::kAbstractClassCheck: |
| 5289 | case TypeCheckKind::kClassHierarchyCheck: |
| 5290 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5291 | call_kind = |
| 5292 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5293 | break; |
| 5294 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5295 | case TypeCheckKind::kUnresolvedCheck: |
| 5296 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5297 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5298 | break; |
| 5299 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5300 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5301 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5302 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5303 | locations->SetInAt(1, Location::Any()); |
| 5304 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 5305 | locations->SetOut(Location::RequiresRegister()); |
| 5306 | // When read barriers are enabled, we need a temporary register for |
| 5307 | // some cases. |
| 5308 | if (kEmitCompilerReadBarrier && |
| 5309 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5310 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5311 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 5312 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5313 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5314 | } |
| 5315 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5316 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5317 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5318 | Location obj_loc = locations->InAt(0); |
| 5319 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5320 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5321 | Location out_loc = locations->Out(); |
| 5322 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5323 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5324 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5325 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5326 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5327 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5328 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5329 | |
| 5330 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5331 | // Avoid null check if we know obj is not null. |
| 5332 | if (instruction->MustDoNullCheck()) { |
| 5333 | __ testl(obj, obj); |
| 5334 | __ j(kEqual, &zero); |
| 5335 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5336 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5337 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5338 | __ movl(out, Address(obj, class_offset)); |
| 5339 | codegen_->MaybeGenerateReadBarrier(instruction, out_loc, out_loc, obj_loc, class_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5340 | |
| 5341 | switch (instruction->GetTypeCheckKind()) { |
| 5342 | case TypeCheckKind::kExactCheck: { |
| 5343 | if (cls.IsRegister()) { |
| 5344 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5345 | } else { |
| 5346 | DCHECK(cls.IsStackSlot()) << cls; |
| 5347 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5348 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5349 | if (zero.IsLinked()) { |
| 5350 | // Classes must be equal for the instanceof to succeed. |
| 5351 | __ j(kNotEqual, &zero); |
| 5352 | __ movl(out, Immediate(1)); |
| 5353 | __ jmp(&done); |
| 5354 | } else { |
| 5355 | __ setcc(kEqual, out); |
| 5356 | // setcc only sets the low byte. |
| 5357 | __ andl(out, Immediate(1)); |
| 5358 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5359 | break; |
| 5360 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5361 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5362 | case TypeCheckKind::kAbstractClassCheck: { |
| 5363 | // If the class is abstract, we eagerly fetch the super class of the |
| 5364 | // object to avoid doing a comparison we know will fail. |
| 5365 | NearLabel loop, success; |
| 5366 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5367 | Location temp_loc = kEmitCompilerReadBarrier ? locations->GetTemp(0) : Location::NoLocation(); |
| 5368 | if (kEmitCompilerReadBarrier) { |
| 5369 | // Save the value of `out` into `temp` before overwriting it |
| 5370 | // in the following move operation, as we will need it for the |
| 5371 | // read barrier below. |
| 5372 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
| 5373 | __ movl(temp, out); |
| 5374 | } |
| 5375 | // /* HeapReference<Class> */ out = out->super_class_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5376 | __ movl(out, Address(out, super_offset)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5377 | codegen_->MaybeGenerateReadBarrier(instruction, out_loc, out_loc, temp_loc, super_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5378 | __ testl(out, out); |
| 5379 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5380 | __ j(kEqual, &done); |
| 5381 | if (cls.IsRegister()) { |
| 5382 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5383 | } else { |
| 5384 | DCHECK(cls.IsStackSlot()) << cls; |
| 5385 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5386 | } |
| 5387 | __ j(kNotEqual, &loop); |
| 5388 | __ movl(out, Immediate(1)); |
| 5389 | if (zero.IsLinked()) { |
| 5390 | __ jmp(&done); |
| 5391 | } |
| 5392 | break; |
| 5393 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5394 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5395 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5396 | // Walk over the class hierarchy to find a match. |
| 5397 | NearLabel loop, success; |
| 5398 | __ Bind(&loop); |
| 5399 | if (cls.IsRegister()) { |
| 5400 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5401 | } else { |
| 5402 | DCHECK(cls.IsStackSlot()) << cls; |
| 5403 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5404 | } |
| 5405 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5406 | Location temp_loc = kEmitCompilerReadBarrier ? locations->GetTemp(0) : Location::NoLocation(); |
| 5407 | if (kEmitCompilerReadBarrier) { |
| 5408 | // Save the value of `out` into `temp` before overwriting it |
| 5409 | // in the following move operation, as we will need it for the |
| 5410 | // read barrier below. |
| 5411 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
| 5412 | __ movl(temp, out); |
| 5413 | } |
| 5414 | // /* HeapReference<Class> */ out = out->super_class_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5415 | __ movl(out, Address(out, super_offset)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5416 | codegen_->MaybeGenerateReadBarrier(instruction, out_loc, out_loc, temp_loc, super_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5417 | __ testl(out, out); |
| 5418 | __ j(kNotEqual, &loop); |
| 5419 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5420 | __ jmp(&done); |
| 5421 | __ Bind(&success); |
| 5422 | __ movl(out, Immediate(1)); |
| 5423 | if (zero.IsLinked()) { |
| 5424 | __ jmp(&done); |
| 5425 | } |
| 5426 | break; |
| 5427 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5428 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5429 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5430 | // Do an exact check. |
| 5431 | NearLabel exact_check; |
| 5432 | if (cls.IsRegister()) { |
| 5433 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5434 | } else { |
| 5435 | DCHECK(cls.IsStackSlot()) << cls; |
| 5436 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5437 | } |
| 5438 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5439 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 5440 | Location temp_loc = kEmitCompilerReadBarrier ? locations->GetTemp(0) : Location::NoLocation(); |
| 5441 | if (kEmitCompilerReadBarrier) { |
| 5442 | // Save the value of `out` into `temp` before overwriting it |
| 5443 | // in the following move operation, as we will need it for the |
| 5444 | // read barrier below. |
| 5445 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
| 5446 | __ movl(temp, out); |
| 5447 | } |
| 5448 | // /* HeapReference<Class> */ out = out->component_type_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5449 | __ movl(out, Address(out, component_offset)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5450 | codegen_->MaybeGenerateReadBarrier(instruction, out_loc, out_loc, temp_loc, component_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5451 | __ testl(out, out); |
| 5452 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5453 | __ j(kEqual, &done); |
| 5454 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5455 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5456 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5457 | __ movl(out, Immediate(1)); |
| 5458 | __ jmp(&done); |
| 5459 | break; |
| 5460 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5461 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5462 | case TypeCheckKind::kArrayCheck: { |
| 5463 | if (cls.IsRegister()) { |
| 5464 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5465 | } else { |
| 5466 | DCHECK(cls.IsStackSlot()) << cls; |
| 5467 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5468 | } |
| 5469 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5470 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5471 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5472 | codegen_->AddSlowPath(slow_path); |
| 5473 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5474 | __ movl(out, Immediate(1)); |
| 5475 | if (zero.IsLinked()) { |
| 5476 | __ jmp(&done); |
| 5477 | } |
| 5478 | break; |
| 5479 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5480 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5481 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5482 | case TypeCheckKind::kInterfaceCheck: { |
| 5483 | // Note that we indeed only call on slow path, but we always go |
| 5484 | // into the slow path for the unresolved & interface check |
| 5485 | // cases. |
| 5486 | // |
| 5487 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5488 | // entry point without resorting to a type checking slow path |
| 5489 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5490 | // require to assign fixed registers for the inputs of this |
| 5491 | // HInstanceOf instruction (following the runtime calling |
| 5492 | // convention), which might be cluttered by the potential first |
| 5493 | // read barrier emission at the beginning of this method. |
| 5494 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5495 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5496 | /* is_fatal */ false); |
| 5497 | codegen_->AddSlowPath(slow_path); |
| 5498 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5499 | if (zero.IsLinked()) { |
| 5500 | __ jmp(&done); |
| 5501 | } |
| 5502 | break; |
| 5503 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5504 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5505 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5506 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5507 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5508 | __ xorl(out, out); |
| 5509 | } |
| 5510 | |
| 5511 | if (done.IsLinked()) { |
| 5512 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5513 | } |
| 5514 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5515 | if (slow_path != nullptr) { |
| 5516 | __ Bind(slow_path->GetExitLabel()); |
| 5517 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5518 | } |
| 5519 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5520 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5521 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5522 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5523 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5524 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5525 | case TypeCheckKind::kExactCheck: |
| 5526 | case TypeCheckKind::kAbstractClassCheck: |
| 5527 | case TypeCheckKind::kClassHierarchyCheck: |
| 5528 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5529 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 5530 | LocationSummary::kCallOnSlowPath : |
| 5531 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5532 | break; |
| 5533 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5534 | case TypeCheckKind::kUnresolvedCheck: |
| 5535 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5536 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5537 | break; |
| 5538 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5539 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5540 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5541 | locations->SetInAt(1, Location::Any()); |
| 5542 | // Note that TypeCheckSlowPathX86_64 uses this "temp" register too. |
| 5543 | locations->AddTemp(Location::RequiresRegister()); |
| 5544 | // When read barriers are enabled, we need an additional temporary |
| 5545 | // register for some cases. |
| 5546 | if (kEmitCompilerReadBarrier && |
| 5547 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5548 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5549 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5550 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5551 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5552 | } |
| 5553 | |
| 5554 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 5555 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5556 | Location obj_loc = locations->InAt(0); |
| 5557 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5558 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5559 | Location temp_loc = locations->GetTemp(0); |
| 5560 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5561 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5562 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5563 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5564 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5565 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5566 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5567 | bool is_type_check_slow_path_fatal = |
| 5568 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 5569 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5570 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5571 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 5572 | !instruction->CanThrowIntoCatchBlock(); |
| 5573 | SlowPathCode* type_check_slow_path = |
| 5574 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5575 | is_type_check_slow_path_fatal); |
| 5576 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5577 | |
| 5578 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5579 | // Avoid null check if we know obj is not null. |
| 5580 | if (instruction->MustDoNullCheck()) { |
| 5581 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5582 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5583 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5584 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5585 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5586 | __ movl(temp, Address(obj, class_offset)); |
| 5587 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, obj_loc, class_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5588 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5589 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5590 | case TypeCheckKind::kExactCheck: |
| 5591 | case TypeCheckKind::kArrayCheck: { |
| 5592 | if (cls.IsRegister()) { |
| 5593 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5594 | } else { |
| 5595 | DCHECK(cls.IsStackSlot()) << cls; |
| 5596 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5597 | } |
| 5598 | // Jump to slow path for throwing the exception or doing a |
| 5599 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5600 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5601 | break; |
| 5602 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5603 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5604 | case TypeCheckKind::kAbstractClassCheck: { |
| 5605 | // If the class is abstract, we eagerly fetch the super class of the |
| 5606 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5607 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5608 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5609 | Location temp2_loc = |
| 5610 | kEmitCompilerReadBarrier ? locations->GetTemp(1) : Location::NoLocation(); |
| 5611 | if (kEmitCompilerReadBarrier) { |
| 5612 | // Save the value of `temp` into `temp2` before overwriting it |
| 5613 | // in the following move operation, as we will need it for the |
| 5614 | // read barrier below. |
| 5615 | CpuRegister temp2 = temp2_loc.AsRegister<CpuRegister>(); |
| 5616 | __ movl(temp2, temp); |
| 5617 | } |
| 5618 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5619 | __ movl(temp, Address(temp, super_offset)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5620 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, temp2_loc, super_offset); |
| 5621 | |
| 5622 | // If the class reference currently in `temp` is not null, jump |
| 5623 | // to the `compare_classes` label to compare it with the checked |
| 5624 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5625 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5626 | __ j(kNotEqual, &compare_classes); |
| 5627 | // Otherwise, jump to the slow path to throw the exception. |
| 5628 | // |
| 5629 | // But before, move back the object's class into `temp` before |
| 5630 | // going into the slow path, as it has been overwritten in the |
| 5631 | // meantime. |
| 5632 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5633 | __ movl(temp, Address(obj, class_offset)); |
| 5634 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, obj_loc, class_offset); |
| 5635 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 5636 | |
| 5637 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5638 | if (cls.IsRegister()) { |
| 5639 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5640 | } else { |
| 5641 | DCHECK(cls.IsStackSlot()) << cls; |
| 5642 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5643 | } |
| 5644 | __ j(kNotEqual, &loop); |
| 5645 | break; |
| 5646 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5647 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5648 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5649 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5650 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5651 | __ Bind(&loop); |
| 5652 | if (cls.IsRegister()) { |
| 5653 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5654 | } else { |
| 5655 | DCHECK(cls.IsStackSlot()) << cls; |
| 5656 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5657 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5658 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5659 | |
| 5660 | Location temp2_loc = |
| 5661 | kEmitCompilerReadBarrier ? locations->GetTemp(1) : Location::NoLocation(); |
| 5662 | if (kEmitCompilerReadBarrier) { |
| 5663 | // Save the value of `temp` into `temp2` before overwriting it |
| 5664 | // in the following move operation, as we will need it for the |
| 5665 | // read barrier below. |
| 5666 | CpuRegister temp2 = temp2_loc.AsRegister<CpuRegister>(); |
| 5667 | __ movl(temp2, temp); |
| 5668 | } |
| 5669 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5670 | __ movl(temp, Address(temp, super_offset)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5671 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, temp2_loc, super_offset); |
| 5672 | |
| 5673 | // If the class reference currently in `temp` is not null, jump |
| 5674 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5675 | __ testl(temp, temp); |
| 5676 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5677 | // Otherwise, jump to the slow path to throw the exception. |
| 5678 | // |
| 5679 | // But before, move back the object's class into `temp` before |
| 5680 | // going into the slow path, as it has been overwritten in the |
| 5681 | // meantime. |
| 5682 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5683 | __ movl(temp, Address(obj, class_offset)); |
| 5684 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, obj_loc, class_offset); |
| 5685 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5686 | break; |
| 5687 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5688 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5689 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5690 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5691 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5692 | if (cls.IsRegister()) { |
| 5693 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5694 | } else { |
| 5695 | DCHECK(cls.IsStackSlot()) << cls; |
| 5696 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5697 | } |
| 5698 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5699 | |
| 5700 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 5701 | Location temp2_loc = |
| 5702 | kEmitCompilerReadBarrier ? locations->GetTemp(1) : Location::NoLocation(); |
| 5703 | if (kEmitCompilerReadBarrier) { |
| 5704 | // Save the value of `temp` into `temp2` before overwriting it |
| 5705 | // in the following move operation, as we will need it for the |
| 5706 | // read barrier below. |
| 5707 | CpuRegister temp2 = temp2_loc.AsRegister<CpuRegister>(); |
| 5708 | __ movl(temp2, temp); |
| 5709 | } |
| 5710 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5711 | __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5712 | codegen_->MaybeGenerateReadBarrier( |
| 5713 | instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 5714 | |
| 5715 | // If the component type is not null (i.e. the object is indeed |
| 5716 | // an array), jump to label `check_non_primitive_component_type` |
| 5717 | // to further check that this component type is not a primitive |
| 5718 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5719 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5720 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 5721 | // Otherwise, jump to the slow path to throw the exception. |
| 5722 | // |
| 5723 | // But before, move back the object's class into `temp` before |
| 5724 | // going into the slow path, as it has been overwritten in the |
| 5725 | // meantime. |
| 5726 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5727 | __ movl(temp, Address(obj, class_offset)); |
| 5728 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, obj_loc, class_offset); |
| 5729 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 5730 | |
| 5731 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5732 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5733 | __ j(kEqual, &done); |
| 5734 | // Same comment as above regarding `temp` and the slow path. |
| 5735 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5736 | __ movl(temp, Address(obj, class_offset)); |
| 5737 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, obj_loc, class_offset); |
| 5738 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5739 | break; |
| 5740 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5741 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5742 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5743 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5744 | // We always go into the type check slow path for the unresolved & |
| 5745 | // interface check cases. |
| 5746 | // |
| 5747 | // We cannot directly call the CheckCast runtime entry point |
| 5748 | // without resorting to a type checking slow path here (i.e. by |
| 5749 | // calling InvokeRuntime directly), as it would require to |
| 5750 | // assign fixed registers for the inputs of this HInstanceOf |
| 5751 | // instruction (following the runtime calling convention), which |
| 5752 | // might be cluttered by the potential first read barrier |
| 5753 | // emission at the beginning of this method. |
| 5754 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5755 | break; |
| 5756 | } |
| 5757 | __ Bind(&done); |
| 5758 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5759 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5760 | } |
| 5761 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5762 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5763 | LocationSummary* locations = |
| 5764 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5765 | InvokeRuntimeCallingConvention calling_convention; |
| 5766 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5767 | } |
| 5768 | |
| 5769 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5770 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 5771 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 5772 | instruction, |
| 5773 | instruction->GetDexPc(), |
| 5774 | nullptr); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5775 | } |
| 5776 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5777 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 5778 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 5779 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 5780 | |
| 5781 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5782 | LocationSummary* locations = |
| 5783 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5784 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 5785 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 5786 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5787 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5788 | locations->SetOut(Location::SameAsFirstInput()); |
| 5789 | } |
| 5790 | |
| 5791 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 5792 | HandleBitwiseOperation(instruction); |
| 5793 | } |
| 5794 | |
| 5795 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 5796 | HandleBitwiseOperation(instruction); |
| 5797 | } |
| 5798 | |
| 5799 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 5800 | HandleBitwiseOperation(instruction); |
| 5801 | } |
| 5802 | |
| 5803 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5804 | LocationSummary* locations = instruction->GetLocations(); |
| 5805 | Location first = locations->InAt(0); |
| 5806 | Location second = locations->InAt(1); |
| 5807 | DCHECK(first.Equals(locations->Out())); |
| 5808 | |
| 5809 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 5810 | if (second.IsRegister()) { |
| 5811 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5812 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5813 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5814 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5815 | } else { |
| 5816 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5817 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5818 | } |
| 5819 | } else if (second.IsConstant()) { |
| 5820 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 5821 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5822 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5823 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5824 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5825 | } else { |
| 5826 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5827 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5828 | } |
| 5829 | } else { |
| 5830 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 5831 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5832 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5833 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5834 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5835 | } else { |
| 5836 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5837 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5838 | } |
| 5839 | } |
| 5840 | } else { |
| 5841 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5842 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 5843 | bool second_is_constant = false; |
| 5844 | int64_t value = 0; |
| 5845 | if (second.IsConstant()) { |
| 5846 | second_is_constant = true; |
| 5847 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5848 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5849 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5850 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5851 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5852 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5853 | if (is_int32_value) { |
| 5854 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 5855 | } else { |
| 5856 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 5857 | } |
| 5858 | } else if (second.IsDoubleStackSlot()) { |
| 5859 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5860 | } else { |
| 5861 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 5862 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5863 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5864 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5865 | if (is_int32_value) { |
| 5866 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 5867 | } else { |
| 5868 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 5869 | } |
| 5870 | } else if (second.IsDoubleStackSlot()) { |
| 5871 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5872 | } else { |
| 5873 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 5874 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5875 | } else { |
| 5876 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5877 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5878 | if (is_int32_value) { |
| 5879 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 5880 | } else { |
| 5881 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 5882 | } |
| 5883 | } else if (second.IsDoubleStackSlot()) { |
| 5884 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5885 | } else { |
| 5886 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 5887 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5888 | } |
| 5889 | } |
| 5890 | } |
| 5891 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5892 | void CodeGeneratorX86_64::GenerateReadBarrier(HInstruction* instruction, |
| 5893 | Location out, |
| 5894 | Location ref, |
| 5895 | Location obj, |
| 5896 | uint32_t offset, |
| 5897 | Location index) { |
| 5898 | DCHECK(kEmitCompilerReadBarrier); |
| 5899 | |
| 5900 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 5901 | // reference will be carried out by the runtime within the slow |
| 5902 | // path. |
| 5903 | // |
| 5904 | // Note that `ref` currently does not get unpoisoned (when heap |
| 5905 | // poisoning is enabled), which is alright as the `ref` argument is |
| 5906 | // not used by the artReadBarrierSlow entry point. |
| 5907 | // |
| 5908 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 5909 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 5910 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 5911 | AddSlowPath(slow_path); |
| 5912 | |
| 5913 | // TODO: When read barrier has a fast path, add it here. |
| 5914 | /* Currently the read barrier call is inserted after the original load. |
| 5915 | * However, if we have a fast path, we need to perform the load of obj.LockWord *before* the |
| 5916 | * original load. This load-load ordering is required by the read barrier. |
| 5917 | * The fast path/slow path (for Baker's algorithm) should look like: |
| 5918 | * |
| 5919 | * bool isGray = obj.LockWord & kReadBarrierMask; |
| 5920 | * lfence; // load fence or artificial data dependence to prevent load-load reordering |
| 5921 | * ref = obj.field; // this is the original load |
| 5922 | * if (isGray) { |
| 5923 | * ref = Mark(ref); // ideally the slow path just does Mark(ref) |
| 5924 | * } |
| 5925 | */ |
| 5926 | |
| 5927 | __ jmp(slow_path->GetEntryLabel()); |
| 5928 | __ Bind(slow_path->GetExitLabel()); |
| 5929 | } |
| 5930 | |
| 5931 | void CodeGeneratorX86_64::MaybeGenerateReadBarrier(HInstruction* instruction, |
| 5932 | Location out, |
| 5933 | Location ref, |
| 5934 | Location obj, |
| 5935 | uint32_t offset, |
| 5936 | Location index) { |
| 5937 | if (kEmitCompilerReadBarrier) { |
| 5938 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 5939 | // by the runtime within the slow path. |
| 5940 | GenerateReadBarrier(instruction, out, ref, obj, offset, index); |
| 5941 | } else if (kPoisonHeapReferences) { |
| 5942 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 5943 | } |
| 5944 | } |
| 5945 | |
| 5946 | void CodeGeneratorX86_64::GenerateReadBarrierForRoot(HInstruction* instruction, |
| 5947 | Location out, |
| 5948 | Location root) { |
| 5949 | DCHECK(kEmitCompilerReadBarrier); |
| 5950 | |
| 5951 | // Note that GC roots are not affected by heap poisoning, so we do |
| 5952 | // not need to do anything special for this here. |
| 5953 | SlowPathCode* slow_path = |
| 5954 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
| 5955 | AddSlowPath(slow_path); |
| 5956 | |
| 5957 | // TODO: Implement a fast path for ReadBarrierForRoot, performing |
| 5958 | // the following operation (for Baker's algorithm): |
| 5959 | // |
| 5960 | // if (thread.tls32_.is_gc_marking) { |
| 5961 | // root = Mark(root); |
| 5962 | // } |
| 5963 | |
| 5964 | __ jmp(slow_path->GetEntryLabel()); |
| 5965 | __ Bind(slow_path->GetExitLabel()); |
| 5966 | } |
| 5967 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5968 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5969 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5970 | LOG(FATAL) << "Unreachable"; |
| 5971 | } |
| 5972 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5973 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5974 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5975 | LOG(FATAL) << "Unreachable"; |
| 5976 | } |
| 5977 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5978 | void LocationsBuilderX86_64::VisitFakeString(HFakeString* instruction) { |
| 5979 | DCHECK(codegen_->IsBaseline()); |
| 5980 | LocationSummary* locations = |
| 5981 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5982 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 5983 | } |
| 5984 | |
| 5985 | void InstructionCodeGeneratorX86_64::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 5986 | DCHECK(codegen_->IsBaseline()); |
| 5987 | // Will be generated at use site. |
| 5988 | } |
| 5989 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5990 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5991 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5992 | LocationSummary* locations = |
| 5993 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 5994 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 5995 | locations->AddTemp(Location::RequiresRegister()); |
| 5996 | locations->AddTemp(Location::RequiresRegister()); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5997 | } |
| 5998 | |
| 5999 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6000 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 6001 | int32_t num_entries = switch_instr->GetNumEntries(); |
| 6002 | LocationSummary* locations = switch_instr->GetLocations(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6003 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 6004 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 6005 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 6006 | |
| 6007 | // Remove the bias, if needed. |
| 6008 | Register value_reg_out = value_reg_in.AsRegister(); |
| 6009 | if (lower_bound != 0) { |
| 6010 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 6011 | value_reg_out = temp_reg.AsRegister(); |
| 6012 | } |
| 6013 | CpuRegister value_reg(value_reg_out); |
| 6014 | |
| 6015 | // Is the value in range? |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6016 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6017 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6018 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6019 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6020 | // We are in the range of the table. |
| 6021 | // Load the address of the jump table in the constant area. |
| 6022 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6023 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6024 | // Load the (signed) offset from the jump table. |
| 6025 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 6026 | |
| 6027 | // Add the offset to the address of the table base. |
| 6028 | __ addq(temp_reg, base_reg); |
| 6029 | |
| 6030 | // And jump. |
| 6031 | __ jmp(temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6032 | } |
| 6033 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6034 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 6035 | if (value == 0) { |
| 6036 | __ xorl(dest, dest); |
| 6037 | } else if (value > 0 && IsInt<32>(value)) { |
| 6038 | // We can use a 32 bit move, as it will zero-extend and is one byte shorter. |
| 6039 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 6040 | } else { |
| 6041 | __ movq(dest, Immediate(value)); |
| 6042 | } |
| 6043 | } |
| 6044 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 6045 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 6046 | DCHECK(dest.IsDoubleStackSlot()); |
| 6047 | if (IsInt<32>(value)) { |
| 6048 | // Can move directly as an int32 constant. |
| 6049 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 6050 | Immediate(static_cast<int32_t>(value))); |
| 6051 | } else { |
| 6052 | Load64BitValue(CpuRegister(TMP), value); |
| 6053 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 6054 | } |
| 6055 | } |
| 6056 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6057 | /** |
| 6058 | * Class to handle late fixup of offsets into constant area. |
| 6059 | */ |
| 6060 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 6061 | public: |
| 6062 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 6063 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6064 | |
| 6065 | protected: |
| 6066 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6067 | |
| 6068 | CodeGeneratorX86_64* codegen_; |
| 6069 | |
| 6070 | private: |
| 6071 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6072 | // Patch the correct offset for the instruction. We use the address of the |
| 6073 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 6074 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 6075 | int32_t relative_position = constant_offset - pos; |
| 6076 | |
| 6077 | // Patch in the right value. |
| 6078 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 6079 | } |
| 6080 | |
| 6081 | // Location in constant area that the fixup refers to. |
| 6082 | size_t offset_into_constant_area_; |
| 6083 | }; |
| 6084 | |
| 6085 | /** |
| 6086 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 6087 | * constant area. |
| 6088 | */ |
| 6089 | class JumpTableRIPFixup : public RIPFixup { |
| 6090 | public: |
| 6091 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 6092 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 6093 | |
| 6094 | void CreateJumpTable() { |
| 6095 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 6096 | |
| 6097 | // Ensure that the reference to the jump table has the correct offset. |
| 6098 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 6099 | SetOffset(offset_in_constant_table); |
| 6100 | |
| 6101 | // Compute the offset from the start of the function to this jump table. |
| 6102 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 6103 | |
| 6104 | // Populate the jump table with the correct values for the jump table. |
| 6105 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 6106 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 6107 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 6108 | // The value that we want is the target offset - the position of the table. |
| 6109 | for (int32_t i = 0; i < num_entries; i++) { |
| 6110 | HBasicBlock* b = successors[i]; |
| 6111 | Label* l = codegen_->GetLabelOf(b); |
| 6112 | DCHECK(l->IsBound()); |
| 6113 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 6114 | assembler->AppendInt32(offset_to_block); |
| 6115 | } |
| 6116 | } |
| 6117 | |
| 6118 | private: |
| 6119 | const HPackedSwitch* switch_instr_; |
| 6120 | }; |
| 6121 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6122 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 6123 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6124 | X86_64Assembler* assembler = GetAssembler(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6125 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 6126 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 byte values. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6127 | assembler->Align(4, 0); |
| 6128 | constant_area_start_ = assembler->CodeSize(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6129 | |
| 6130 | // Populate any jump tables. |
| 6131 | for (auto jump_table : fixups_to_jump_tables_) { |
| 6132 | jump_table->CreateJumpTable(); |
| 6133 | } |
| 6134 | |
| 6135 | // And now add the constant area to the generated code. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6136 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6137 | } |
| 6138 | |
| 6139 | // And finish up. |
| 6140 | CodeGenerator::Finalize(allocator); |
| 6141 | } |
| 6142 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6143 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 6144 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 6145 | return Address::RIP(fixup); |
| 6146 | } |
| 6147 | |
| 6148 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 6149 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 6150 | return Address::RIP(fixup); |
| 6151 | } |
| 6152 | |
| 6153 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 6154 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 6155 | return Address::RIP(fixup); |
| 6156 | } |
| 6157 | |
| 6158 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 6159 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 6160 | return Address::RIP(fixup); |
| 6161 | } |
| 6162 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6163 | // TODO: trg as memory. |
| 6164 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 6165 | if (!trg.IsValid()) { |
| 6166 | DCHECK(type == Primitive::kPrimVoid); |
| 6167 | return; |
| 6168 | } |
| 6169 | |
| 6170 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 6171 | |
| 6172 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 6173 | if (trg.Equals(return_loc)) { |
| 6174 | return; |
| 6175 | } |
| 6176 | |
| 6177 | // Let the parallel move resolver take care of all of this. |
| 6178 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6179 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 6180 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6181 | } |
| 6182 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6183 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 6184 | // Create a fixup to be used to create and address the jump table. |
| 6185 | JumpTableRIPFixup* table_fixup = |
| 6186 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 6187 | |
| 6188 | // We have to populate the jump tables. |
| 6189 | fixups_to_jump_tables_.push_back(table_fixup); |
| 6190 | return Address::RIP(table_fixup); |
| 6191 | } |
| 6192 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 6193 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 6194 | const Address& addr_high, |
| 6195 | int64_t v, |
| 6196 | HInstruction* instruction) { |
| 6197 | if (IsInt<32>(v)) { |
| 6198 | int32_t v_32 = v; |
| 6199 | __ movq(addr_low, Immediate(v_32)); |
| 6200 | MaybeRecordImplicitNullCheck(instruction); |
| 6201 | } else { |
| 6202 | // Didn't fit in a register. Do it in pieces. |
| 6203 | int32_t low_v = Low32Bits(v); |
| 6204 | int32_t high_v = High32Bits(v); |
| 6205 | __ movl(addr_low, Immediate(low_v)); |
| 6206 | MaybeRecordImplicitNullCheck(instruction); |
| 6207 | __ movl(addr_high, Immediate(high_v)); |
| 6208 | } |
| 6209 | } |
| 6210 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6211 | #undef __ |
| 6212 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 6213 | } // namespace x86_64 |
| 6214 | } // namespace art |