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; |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 44 | // The compare/jump sequence will generate about (1.5 * num_entries) instructions. A jump |
| 45 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 46 | // generates less code/data with a small num_entries. |
| 47 | static constexpr uint32_t kPackedSwitchJumpTableThreshold = 5; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 48 | |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 49 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 50 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 51 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 52 | static constexpr int kC2ConditionMask = 0x400; |
| 53 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 54 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 55 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 56 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 57 | class NullCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 58 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 59 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 60 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 61 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 62 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 63 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 64 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 65 | // Live registers will be restored in the catch block if caught. |
| 66 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 67 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 68 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 69 | instruction_, |
| 70 | instruction_->GetDexPc(), |
| 71 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 72 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 73 | } |
| 74 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 75 | bool IsFatal() const OVERRIDE { return true; } |
| 76 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 77 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86_64"; } |
| 78 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 79 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 80 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 81 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 82 | }; |
| 83 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 84 | class DivZeroCheckSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 85 | public: |
| 86 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 87 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 88 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 89 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 90 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 91 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 92 | // Live registers will be restored in the catch block if caught. |
| 93 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 94 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 95 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 96 | instruction_, |
| 97 | instruction_->GetDexPc(), |
| 98 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 99 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 102 | bool IsFatal() const OVERRIDE { return true; } |
| 103 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 104 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86_64"; } |
| 105 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 106 | private: |
| 107 | HDivZeroCheck* const instruction_; |
| 108 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 109 | }; |
| 110 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 111 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 112 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 113 | DivRemMinusOneSlowPathX86_64(Register reg, Primitive::Type type, bool is_div) |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 114 | : cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 115 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 116 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 117 | __ Bind(GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 118 | if (type_ == Primitive::kPrimInt) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 119 | if (is_div_) { |
| 120 | __ negl(cpu_reg_); |
| 121 | } else { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 122 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 125 | } else { |
| 126 | DCHECK_EQ(Primitive::kPrimLong, type_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 127 | if (is_div_) { |
| 128 | __ negq(cpu_reg_); |
| 129 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 130 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 131 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 132 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 133 | __ jmp(GetExitLabel()); |
| 134 | } |
| 135 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 136 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86_64"; } |
| 137 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 138 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 139 | const CpuRegister cpu_reg_; |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 140 | const Primitive::Type type_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 141 | const bool is_div_; |
| 142 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 143 | }; |
| 144 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 145 | class SuspendCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 146 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 147 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 148 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 149 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 150 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 151 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 152 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 153 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 154 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 155 | instruction_, |
| 156 | instruction_->GetDexPc(), |
| 157 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 158 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 159 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 160 | if (successor_ == nullptr) { |
| 161 | __ jmp(GetReturnLabel()); |
| 162 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 163 | __ jmp(x86_64_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 164 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 167 | Label* GetReturnLabel() { |
| 168 | DCHECK(successor_ == nullptr); |
| 169 | return &return_label_; |
| 170 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 171 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 172 | HBasicBlock* GetSuccessor() const { |
| 173 | return successor_; |
| 174 | } |
| 175 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 176 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 177 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 178 | private: |
| 179 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 180 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 181 | Label return_label_; |
| 182 | |
| 183 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 184 | }; |
| 185 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 186 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 187 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 188 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
| 189 | : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 190 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 191 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 192 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 193 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 194 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 195 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 196 | // Live registers will be restored in the catch block if caught. |
| 197 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 198 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 199 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 200 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 201 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 202 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 203 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 204 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 205 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 206 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 207 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 208 | Primitive::kPrimInt); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 209 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 210 | instruction_, |
| 211 | instruction_->GetDexPc(), |
| 212 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 213 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 214 | } |
| 215 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 216 | bool IsFatal() const OVERRIDE { return true; } |
| 217 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 218 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 219 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 220 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 221 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 222 | |
| 223 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 224 | }; |
| 225 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 226 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 227 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 228 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 229 | HInstruction* at, |
| 230 | uint32_t dex_pc, |
| 231 | bool do_clinit) |
| 232 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 233 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 234 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 235 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 236 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 237 | LocationSummary* locations = at_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 238 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 239 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 240 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 241 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 242 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 243 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 244 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(cls_->GetTypeIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 245 | x86_64_codegen->InvokeRuntime(do_clinit_ ? |
| 246 | QUICK_ENTRY_POINT(pInitializeStaticStorage) : |
| 247 | QUICK_ENTRY_POINT(pInitializeType), |
| 248 | at_, |
| 249 | dex_pc_, |
| 250 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 251 | if (do_clinit_) { |
| 252 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 253 | } else { |
| 254 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 255 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 256 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 257 | Location out = locations->Out(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 258 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 259 | if (out.IsValid()) { |
| 260 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 261 | x86_64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 262 | } |
| 263 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 264 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 265 | __ jmp(GetExitLabel()); |
| 266 | } |
| 267 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 268 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 269 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 270 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 271 | // The class this slow path will load. |
| 272 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 273 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 274 | // The instruction where this slow path is happening. |
| 275 | // (Might be the load class or an initialization check). |
| 276 | HInstruction* const at_; |
| 277 | |
| 278 | // The dex PC of `at_`. |
| 279 | const uint32_t dex_pc_; |
| 280 | |
| 281 | // Whether to initialize the class. |
| 282 | const bool do_clinit_; |
| 283 | |
| 284 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 285 | }; |
| 286 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 287 | class LoadStringSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 288 | public: |
| 289 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : instruction_(instruction) {} |
| 290 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 291 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 292 | LocationSummary* locations = instruction_->GetLocations(); |
| 293 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 294 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 295 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 296 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 297 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 298 | |
| 299 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 300 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 301 | Immediate(instruction_->GetStringIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 302 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 303 | instruction_, |
| 304 | instruction_->GetDexPc(), |
| 305 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 306 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 307 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 308 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 309 | __ jmp(GetExitLabel()); |
| 310 | } |
| 311 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 312 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86_64"; } |
| 313 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 314 | private: |
| 315 | HLoadString* const instruction_; |
| 316 | |
| 317 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 318 | }; |
| 319 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 320 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 321 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 322 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
| 323 | : instruction_(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 324 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 325 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 326 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 327 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 328 | : locations->Out(); |
| 329 | uint32_t dex_pc = instruction_->GetDexPc(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 330 | DCHECK(instruction_->IsCheckCast() |
| 331 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 332 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 333 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 334 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 335 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 336 | if (!is_fatal_) { |
| 337 | SaveLiveRegisters(codegen, locations); |
| 338 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 339 | |
| 340 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 341 | // move resolver. |
| 342 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 343 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 344 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 345 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 346 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 347 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 348 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 349 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 350 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 351 | if (instruction_->IsInstanceOf()) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 352 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 353 | instruction_, |
| 354 | dex_pc, |
| 355 | this); |
| 356 | CheckEntrypointTypes< |
| 357 | kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 358 | } else { |
| 359 | DCHECK(instruction_->IsCheckCast()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 360 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 361 | instruction_, |
| 362 | dex_pc, |
| 363 | this); |
| 364 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 365 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 366 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 367 | if (!is_fatal_) { |
| 368 | if (instruction_->IsInstanceOf()) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 369 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 370 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 371 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 372 | RestoreLiveRegisters(codegen, locations); |
| 373 | __ jmp(GetExitLabel()); |
| 374 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 377 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 378 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 379 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 380 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 381 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 382 | HInstruction* const instruction_; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 383 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 384 | |
| 385 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 386 | }; |
| 387 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 388 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 389 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 390 | explicit DeoptimizationSlowPathX86_64(HDeoptimize* instruction) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 391 | : instruction_(instruction) {} |
| 392 | |
| 393 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 394 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 395 | __ Bind(GetEntryLabel()); |
| 396 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 397 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 398 | instruction_, |
| 399 | instruction_->GetDexPc(), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 400 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 401 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 404 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 405 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 406 | private: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 407 | HDeoptimize* const instruction_; |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 408 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 409 | }; |
| 410 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 411 | class ArraySetSlowPathX86_64 : public SlowPathCode { |
| 412 | public: |
| 413 | explicit ArraySetSlowPathX86_64(HInstruction* instruction) : instruction_(instruction) {} |
| 414 | |
| 415 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 416 | LocationSummary* locations = instruction_->GetLocations(); |
| 417 | __ Bind(GetEntryLabel()); |
| 418 | SaveLiveRegisters(codegen, locations); |
| 419 | |
| 420 | InvokeRuntimeCallingConvention calling_convention; |
| 421 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 422 | parallel_move.AddMove( |
| 423 | locations->InAt(0), |
| 424 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 425 | Primitive::kPrimNot, |
| 426 | nullptr); |
| 427 | parallel_move.AddMove( |
| 428 | locations->InAt(1), |
| 429 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 430 | Primitive::kPrimInt, |
| 431 | nullptr); |
| 432 | parallel_move.AddMove( |
| 433 | locations->InAt(2), |
| 434 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 435 | Primitive::kPrimNot, |
| 436 | nullptr); |
| 437 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 438 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 439 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 440 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 441 | instruction_, |
| 442 | instruction_->GetDexPc(), |
| 443 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 444 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 445 | RestoreLiveRegisters(codegen, locations); |
| 446 | __ jmp(GetExitLabel()); |
| 447 | } |
| 448 | |
| 449 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86_64"; } |
| 450 | |
| 451 | private: |
| 452 | HInstruction* const instruction_; |
| 453 | |
| 454 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 455 | }; |
| 456 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 457 | // Slow path marking an object during a read barrier. |
| 458 | class ReadBarrierMarkSlowPathX86_64 : public SlowPathCode { |
| 459 | public: |
| 460 | ReadBarrierMarkSlowPathX86_64(HInstruction* instruction, Location out, Location obj) |
| 461 | : instruction_(instruction), out_(out), obj_(obj) { |
| 462 | DCHECK(kEmitCompilerReadBarrier); |
| 463 | } |
| 464 | |
| 465 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86_64"; } |
| 466 | |
| 467 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 468 | LocationSummary* locations = instruction_->GetLocations(); |
| 469 | Register reg_out = out_.AsRegister<Register>(); |
| 470 | DCHECK(locations->CanCall()); |
| 471 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 472 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 473 | instruction_->IsStaticFieldGet() || |
| 474 | instruction_->IsArrayGet() || |
| 475 | instruction_->IsLoadClass() || |
| 476 | instruction_->IsLoadString() || |
| 477 | instruction_->IsInstanceOf() || |
| 478 | instruction_->IsCheckCast()) |
| 479 | << "Unexpected instruction in read barrier marking slow path: " |
| 480 | << instruction_->DebugName(); |
| 481 | |
| 482 | __ Bind(GetEntryLabel()); |
| 483 | SaveLiveRegisters(codegen, locations); |
| 484 | |
| 485 | InvokeRuntimeCallingConvention calling_convention; |
| 486 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 487 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), obj_); |
| 488 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierMark), |
| 489 | instruction_, |
| 490 | instruction_->GetDexPc(), |
| 491 | this); |
| 492 | CheckEntrypointTypes<kQuickReadBarrierMark, mirror::Object*, mirror::Object*>(); |
| 493 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 494 | |
| 495 | RestoreLiveRegisters(codegen, locations); |
| 496 | __ jmp(GetExitLabel()); |
| 497 | } |
| 498 | |
| 499 | private: |
| 500 | HInstruction* const instruction_; |
| 501 | const Location out_; |
| 502 | const Location obj_; |
| 503 | |
| 504 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86_64); |
| 505 | }; |
| 506 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 507 | // Slow path generating a read barrier for a heap reference. |
| 508 | class ReadBarrierForHeapReferenceSlowPathX86_64 : public SlowPathCode { |
| 509 | public: |
| 510 | ReadBarrierForHeapReferenceSlowPathX86_64(HInstruction* instruction, |
| 511 | Location out, |
| 512 | Location ref, |
| 513 | Location obj, |
| 514 | uint32_t offset, |
| 515 | Location index) |
| 516 | : instruction_(instruction), |
| 517 | out_(out), |
| 518 | ref_(ref), |
| 519 | obj_(obj), |
| 520 | offset_(offset), |
| 521 | index_(index) { |
| 522 | DCHECK(kEmitCompilerReadBarrier); |
| 523 | // If `obj` is equal to `out` or `ref`, it means the initial |
| 524 | // object has been overwritten by (or after) the heap object |
| 525 | // reference load to be instrumented, e.g.: |
| 526 | // |
| 527 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 528 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 529 | // |
| 530 | // In that case, we have lost the information about the original |
| 531 | // object, and the emitted read barrier cannot work properly. |
| 532 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 533 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 534 | } |
| 535 | |
| 536 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 537 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 538 | LocationSummary* locations = instruction_->GetLocations(); |
| 539 | CpuRegister reg_out = out_.AsRegister<CpuRegister>(); |
| 540 | DCHECK(locations->CanCall()); |
| 541 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.AsRegister())) << out_; |
| 542 | DCHECK(!instruction_->IsInvoke() || |
| 543 | (instruction_->IsInvokeStaticOrDirect() && |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 544 | instruction_->GetLocations()->Intrinsified())) |
| 545 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 546 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 547 | |
| 548 | __ Bind(GetEntryLabel()); |
| 549 | SaveLiveRegisters(codegen, locations); |
| 550 | |
| 551 | // We may have to change the index's value, but as `index_` is a |
| 552 | // constant member (like other "inputs" of this slow path), |
| 553 | // introduce a copy of it, `index`. |
| 554 | Location index = index_; |
| 555 | if (index_.IsValid()) { |
| 556 | // Handle `index_` for HArrayGet and intrinsic UnsafeGetObject. |
| 557 | if (instruction_->IsArrayGet()) { |
| 558 | // Compute real offset and store it in index_. |
| 559 | Register index_reg = index_.AsRegister<CpuRegister>().AsRegister(); |
| 560 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 561 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 562 | // We are about to change the value of `index_reg` (see the |
| 563 | // calls to art::x86_64::X86_64Assembler::shll and |
| 564 | // art::x86_64::X86_64Assembler::AddImmediate below), but it |
| 565 | // has not been saved by the previous call to |
| 566 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 567 | // callee-save register -- |
| 568 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 569 | // callee-save registers, as it has been designed with the |
| 570 | // assumption that callee-save registers are supposed to be |
| 571 | // handled by the called function. So, as a callee-save |
| 572 | // register, `index_reg` _would_ eventually be saved onto |
| 573 | // the stack, but it would be too late: we would have |
| 574 | // changed its value earlier. Therefore, we manually save |
| 575 | // it here into another freely available register, |
| 576 | // `free_reg`, chosen of course among the caller-save |
| 577 | // registers (as a callee-save `free_reg` register would |
| 578 | // exhibit the same problem). |
| 579 | // |
| 580 | // Note we could have requested a temporary register from |
| 581 | // the register allocator instead; but we prefer not to, as |
| 582 | // this is a slow path, and we know we can find a |
| 583 | // caller-save register that is available. |
| 584 | Register free_reg = FindAvailableCallerSaveRegister(codegen).AsRegister(); |
| 585 | __ movl(CpuRegister(free_reg), CpuRegister(index_reg)); |
| 586 | index_reg = free_reg; |
| 587 | index = Location::RegisterLocation(index_reg); |
| 588 | } else { |
| 589 | // The initial register stored in `index_` has already been |
| 590 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 591 | // (as it is not a callee-save register), so we can freely |
| 592 | // use it. |
| 593 | } |
| 594 | // Shifting the index value contained in `index_reg` by the |
| 595 | // scale factor (2) cannot overflow in practice, as the |
| 596 | // runtime is unable to allocate object arrays with a size |
| 597 | // larger than 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 598 | __ shll(CpuRegister(index_reg), Immediate(TIMES_4)); |
| 599 | static_assert( |
| 600 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 601 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 602 | __ AddImmediate(CpuRegister(index_reg), Immediate(offset_)); |
| 603 | } else { |
| 604 | DCHECK(instruction_->IsInvoke()); |
| 605 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 606 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 607 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 608 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 609 | DCHECK_EQ(offset_, 0U); |
| 610 | DCHECK(index_.IsRegister()); |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | // We're moving two or three locations to locations that could |
| 615 | // overlap, so we need a parallel move resolver. |
| 616 | InvokeRuntimeCallingConvention calling_convention; |
| 617 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 618 | parallel_move.AddMove(ref_, |
| 619 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 620 | Primitive::kPrimNot, |
| 621 | nullptr); |
| 622 | parallel_move.AddMove(obj_, |
| 623 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 624 | Primitive::kPrimNot, |
| 625 | nullptr); |
| 626 | if (index.IsValid()) { |
| 627 | parallel_move.AddMove(index, |
| 628 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 629 | Primitive::kPrimInt, |
| 630 | nullptr); |
| 631 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 632 | } else { |
| 633 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 634 | __ movl(CpuRegister(calling_convention.GetRegisterAt(2)), Immediate(offset_)); |
| 635 | } |
| 636 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 637 | instruction_, |
| 638 | instruction_->GetDexPc(), |
| 639 | this); |
| 640 | CheckEntrypointTypes< |
| 641 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 642 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 643 | |
| 644 | RestoreLiveRegisters(codegen, locations); |
| 645 | __ jmp(GetExitLabel()); |
| 646 | } |
| 647 | |
| 648 | const char* GetDescription() const OVERRIDE { |
| 649 | return "ReadBarrierForHeapReferenceSlowPathX86_64"; |
| 650 | } |
| 651 | |
| 652 | private: |
| 653 | CpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 654 | size_t ref = static_cast<int>(ref_.AsRegister<CpuRegister>().AsRegister()); |
| 655 | size_t obj = static_cast<int>(obj_.AsRegister<CpuRegister>().AsRegister()); |
| 656 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 657 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 658 | return static_cast<CpuRegister>(i); |
| 659 | } |
| 660 | } |
| 661 | // We shall never fail to find a free caller-save register, as |
| 662 | // there are more than two core caller-save registers on x86-64 |
| 663 | // (meaning it is possible to find one which is different from |
| 664 | // `ref` and `obj`). |
| 665 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 666 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 667 | UNREACHABLE(); |
| 668 | } |
| 669 | |
| 670 | HInstruction* const instruction_; |
| 671 | const Location out_; |
| 672 | const Location ref_; |
| 673 | const Location obj_; |
| 674 | const uint32_t offset_; |
| 675 | // An additional location containing an index to an array. |
| 676 | // Only used for HArrayGet and the UnsafeGetObject & |
| 677 | // UnsafeGetObjectVolatile intrinsics. |
| 678 | const Location index_; |
| 679 | |
| 680 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86_64); |
| 681 | }; |
| 682 | |
| 683 | // Slow path generating a read barrier for a GC root. |
| 684 | class ReadBarrierForRootSlowPathX86_64 : public SlowPathCode { |
| 685 | public: |
| 686 | ReadBarrierForRootSlowPathX86_64(HInstruction* instruction, Location out, Location root) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 687 | : instruction_(instruction), out_(out), root_(root) { |
| 688 | DCHECK(kEmitCompilerReadBarrier); |
| 689 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 690 | |
| 691 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 692 | LocationSummary* locations = instruction_->GetLocations(); |
| 693 | DCHECK(locations->CanCall()); |
| 694 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 695 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 696 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 697 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 698 | |
| 699 | __ Bind(GetEntryLabel()); |
| 700 | SaveLiveRegisters(codegen, locations); |
| 701 | |
| 702 | InvokeRuntimeCallingConvention calling_convention; |
| 703 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 704 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| 705 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 706 | instruction_, |
| 707 | instruction_->GetDexPc(), |
| 708 | this); |
| 709 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 710 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 711 | |
| 712 | RestoreLiveRegisters(codegen, locations); |
| 713 | __ jmp(GetExitLabel()); |
| 714 | } |
| 715 | |
| 716 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86_64"; } |
| 717 | |
| 718 | private: |
| 719 | HInstruction* const instruction_; |
| 720 | const Location out_; |
| 721 | const Location root_; |
| 722 | |
| 723 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86_64); |
| 724 | }; |
| 725 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 726 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 727 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 728 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 729 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 730 | switch (cond) { |
| 731 | case kCondEQ: return kEqual; |
| 732 | case kCondNE: return kNotEqual; |
| 733 | case kCondLT: return kLess; |
| 734 | case kCondLE: return kLessEqual; |
| 735 | case kCondGT: return kGreater; |
| 736 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 737 | case kCondB: return kBelow; |
| 738 | case kCondBE: return kBelowEqual; |
| 739 | case kCondA: return kAbove; |
| 740 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 741 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 742 | LOG(FATAL) << "Unreachable"; |
| 743 | UNREACHABLE(); |
| 744 | } |
| 745 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 746 | // Maps FP condition to x86_64 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 747 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 748 | switch (cond) { |
| 749 | case kCondEQ: return kEqual; |
| 750 | case kCondNE: return kNotEqual; |
| 751 | case kCondLT: return kBelow; |
| 752 | case kCondLE: return kBelowEqual; |
| 753 | case kCondGT: return kAbove; |
| 754 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 755 | default: break; // should not happen |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 756 | }; |
| 757 | LOG(FATAL) << "Unreachable"; |
| 758 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 759 | } |
| 760 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 761 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86_64::GetSupportedInvokeStaticOrDirectDispatch( |
| 762 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 763 | MethodReference target_method ATTRIBUTE_UNUSED) { |
| 764 | switch (desired_dispatch_info.code_ptr_location) { |
| 765 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 766 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 767 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 768 | return HInvokeStaticOrDirect::DispatchInfo { |
| 769 | desired_dispatch_info.method_load_kind, |
| 770 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 771 | desired_dispatch_info.method_load_data, |
| 772 | 0u |
| 773 | }; |
| 774 | default: |
| 775 | return desired_dispatch_info; |
| 776 | } |
| 777 | } |
| 778 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 779 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 780 | Location temp) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 781 | // All registers are assumed to be correctly set up. |
| 782 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 783 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 784 | switch (invoke->GetMethodLoadKind()) { |
| 785 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 786 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | 7f59d59 | 2015-12-29 16:20:52 +0000 | [diff] [blame] | 787 | __ gs()->movq(temp.AsRegister<CpuRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 788 | Address::Absolute(invoke->GetStringInitOffset(), /* no_rip */ true)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 789 | break; |
| 790 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 791 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 792 | break; |
| 793 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 794 | __ movq(temp.AsRegister<CpuRegister>(), Immediate(invoke->GetMethodAddress())); |
| 795 | break; |
| 796 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 797 | __ movl(temp.AsRegister<CpuRegister>(), Immediate(0)); // Placeholder. |
| 798 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 799 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 800 | break; |
| 801 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 802 | pc_relative_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 803 | invoke->GetDexCacheArrayOffset()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 804 | __ movq(temp.AsRegister<CpuRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 805 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 806 | // Bind the label at the end of the "movl" insn. |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 807 | __ Bind(&pc_relative_dex_cache_patches_.back().label); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 808 | break; |
| 809 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 810 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 811 | Register method_reg; |
| 812 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
| 813 | if (current_method.IsRegister()) { |
| 814 | method_reg = current_method.AsRegister<Register>(); |
| 815 | } else { |
| 816 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 817 | DCHECK(!current_method.IsValid()); |
| 818 | method_reg = reg.AsRegister(); |
| 819 | __ movq(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 820 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 821 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 822 | __ movq(reg, |
| 823 | Address(CpuRegister(method_reg), |
| 824 | ArtMethod::DexCacheResolvedMethodsOffset(kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 825 | // temp = temp[index_in_cache] |
| 826 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 827 | __ movq(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 828 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 829 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | switch (invoke->GetCodePtrLocation()) { |
| 833 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 834 | __ call(&frame_entry_label_); |
| 835 | break; |
| 836 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 837 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 838 | Label* label = &relative_call_patches_.back().label; |
| 839 | __ call(label); // Bind to the patch label, override at link time. |
| 840 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 841 | break; |
| 842 | } |
| 843 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 844 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 845 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 846 | LOG(FATAL) << "Unsupported"; |
| 847 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 848 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 849 | // (callee_method + offset_of_quick_compiled_code)() |
| 850 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 851 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 852 | kX86_64WordSize).SizeValue())); |
| 853 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 854 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 855 | |
| 856 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 857 | } |
| 858 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 859 | void CodeGeneratorX86_64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 860 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 861 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 862 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 863 | |
| 864 | // Use the calling convention instead of the location of the receiver, as |
| 865 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 866 | // slow path, the arguments have been moved to the right place, so here we are |
| 867 | // guaranteed that the receiver is the first register of the calling convention. |
| 868 | InvokeDexCallingConvention calling_convention; |
| 869 | Register receiver = calling_convention.GetRegisterAt(0); |
| 870 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 871 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 872 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 873 | __ movl(temp, Address(CpuRegister(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 874 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 875 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 876 | // emit a read barrier for the previous class reference load. |
| 877 | // However this is not required in practice, as this is an |
| 878 | // intermediate/temporary reference and because the current |
| 879 | // concurrent copying collector keeps the from-space memory |
| 880 | // intact/accessible until the end of the marking phase (the |
| 881 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 882 | __ MaybeUnpoisonHeapReference(temp); |
| 883 | // temp = temp->GetMethodAt(method_offset); |
| 884 | __ movq(temp, Address(temp, method_offset)); |
| 885 | // call temp->GetEntryPoint(); |
| 886 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 887 | kX86_64WordSize).SizeValue())); |
| 888 | } |
| 889 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 890 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 891 | DCHECK(linker_patches->empty()); |
| 892 | size_t size = |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 893 | method_patches_.size() + |
| 894 | relative_call_patches_.size() + |
| 895 | pc_relative_dex_cache_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 896 | linker_patches->reserve(size); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 897 | // The label points to the end of the "movl" insn but the literal offset for method |
| 898 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 899 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 900 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 901 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 902 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 903 | info.target_method.dex_file, |
| 904 | info.target_method.dex_method_index)); |
| 905 | } |
| 906 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 907 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 908 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 909 | info.target_method.dex_file, |
| 910 | info.target_method.dex_method_index)); |
| 911 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 912 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 913 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 914 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 915 | &info.target_dex_file, |
| 916 | info.label.Position(), |
| 917 | info.element_offset)); |
| 918 | } |
| 919 | } |
| 920 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 921 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 922 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 926 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 927 | } |
| 928 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 929 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 930 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 931 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 932 | } |
| 933 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 934 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 935 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 936 | return kX86_64WordSize; |
| 937 | } |
| 938 | |
| 939 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 940 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 941 | return kX86_64WordSize; |
| 942 | } |
| 943 | |
| 944 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 945 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 946 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 947 | } |
| 948 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 949 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 950 | HInstruction* instruction, |
| 951 | uint32_t dex_pc, |
| 952 | SlowPathCode* slow_path) { |
| 953 | InvokeRuntime(GetThreadOffset<kX86_64WordSize>(entrypoint).Int32Value(), |
| 954 | instruction, |
| 955 | dex_pc, |
| 956 | slow_path); |
| 957 | } |
| 958 | |
| 959 | void CodeGeneratorX86_64::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 960 | HInstruction* instruction, |
| 961 | uint32_t dex_pc, |
| 962 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 963 | ValidateInvokeRuntime(instruction, slow_path); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 964 | __ gs()->call(Address::Absolute(entry_point_offset, /* no_rip */ true)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 965 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 966 | } |
| 967 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 968 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 969 | // Use a fake return address register to mimic Quick. |
| 970 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 971 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 972 | const X86_64InstructionSetFeatures& isa_features, |
| 973 | const CompilerOptions& compiler_options, |
| 974 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 975 | : CodeGenerator(graph, |
| 976 | kNumberOfCpuRegisters, |
| 977 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 978 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 979 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 980 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 981 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 982 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 983 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 984 | compiler_options, |
| 985 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 986 | block_labels_(nullptr), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 987 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 988 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 989 | move_resolver_(graph->GetArena(), this), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 990 | isa_features_(isa_features), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 991 | constant_area_start_(0), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 992 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 993 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 994 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 995 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 996 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 997 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 998 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 999 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 1000 | CodeGeneratorX86_64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1001 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1002 | assembler_(codegen->GetAssembler()), |
| 1003 | codegen_(codegen) {} |
| 1004 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame^] | 1005 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1006 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1007 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1008 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1009 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1010 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1011 | } |
| 1012 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1013 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1014 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1015 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1016 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1017 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1018 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1019 | } |
| 1020 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1021 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1022 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1023 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1024 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1025 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1026 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1027 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1028 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1029 | __ testq(CpuRegister(RAX), Address( |
| 1030 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1031 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1032 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1033 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1034 | if (HasEmptyFrame()) { |
| 1035 | return; |
| 1036 | } |
| 1037 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1038 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1039 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1040 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1041 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1042 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1043 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1044 | } |
| 1045 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1046 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1047 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1048 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 1049 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1050 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1051 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1052 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1053 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1054 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1055 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1056 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1057 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1058 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1059 | } |
| 1060 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1061 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1062 | CpuRegister(kMethodRegisterArgument)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1066 | __ cfi().RememberState(); |
| 1067 | if (!HasEmptyFrame()) { |
| 1068 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1069 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 1070 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1071 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1072 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1073 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1074 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1079 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 1080 | __ cfi().AdjustCFAOffset(-adjust); |
| 1081 | |
| 1082 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1083 | Register reg = kCoreCalleeSaves[i]; |
| 1084 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1085 | __ popq(CpuRegister(reg)); |
| 1086 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1087 | __ cfi().Restore(DWARFReg(reg)); |
| 1088 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1089 | } |
| 1090 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1091 | __ ret(); |
| 1092 | __ cfi().RestoreState(); |
| 1093 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1094 | } |
| 1095 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1096 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1097 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1098 | } |
| 1099 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1100 | Location CodeGeneratorX86_64::GetStackLocation(HLoadLocal* load) const { |
| 1101 | switch (load->GetType()) { |
| 1102 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1103 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1104 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1105 | |
| 1106 | case Primitive::kPrimInt: |
| 1107 | case Primitive::kPrimNot: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1108 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1109 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1110 | |
| 1111 | case Primitive::kPrimBoolean: |
| 1112 | case Primitive::kPrimByte: |
| 1113 | case Primitive::kPrimChar: |
| 1114 | case Primitive::kPrimShort: |
| 1115 | case Primitive::kPrimVoid: |
| 1116 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 1117 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 1121 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1125 | if (source.Equals(destination)) { |
| 1126 | return; |
| 1127 | } |
| 1128 | if (destination.IsRegister()) { |
| 1129 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1130 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1131 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1132 | __ movd(destination.AsRegister<CpuRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1133 | } else if (source.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1134 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1135 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1136 | } else { |
| 1137 | DCHECK(source.IsDoubleStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1138 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1139 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1140 | } |
| 1141 | } else if (destination.IsFpuRegister()) { |
| 1142 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1143 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1144 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1145 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1146 | } else if (source.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1147 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1148 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1149 | } else { |
| 1150 | DCHECK(source.IsDoubleStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1151 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1152 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1153 | } |
| 1154 | } else if (destination.IsStackSlot()) { |
| 1155 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1156 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1157 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1158 | } else if (source.IsFpuRegister()) { |
| 1159 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1160 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1161 | } else if (source.IsConstant()) { |
| 1162 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1163 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1164 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1165 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1166 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1167 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1168 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1169 | } |
| 1170 | } else { |
| 1171 | DCHECK(destination.IsDoubleStackSlot()); |
| 1172 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1173 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1174 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1175 | } else if (source.IsFpuRegister()) { |
| 1176 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1177 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1178 | } else if (source.IsConstant()) { |
| 1179 | HConstant* constant = source.GetConstant(); |
Zheng Xu | 12bca97 | 2015-03-30 19:35:50 +0800 | [diff] [blame] | 1180 | int64_t value; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1181 | if (constant->IsDoubleConstant()) { |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1182 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1183 | } else { |
| 1184 | DCHECK(constant->IsLongConstant()); |
| 1185 | value = constant->AsLongConstant()->GetValue(); |
| 1186 | } |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1187 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1188 | } else { |
| 1189 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1190 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1191 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1192 | } |
| 1193 | } |
| 1194 | } |
| 1195 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1196 | void CodeGeneratorX86_64::Move(HInstruction* instruction, |
| 1197 | Location location, |
| 1198 | HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1199 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1200 | if (instruction->IsCurrentMethod()) { |
Mathieu Chartier | e3b034a | 2015-05-31 14:29:23 -0700 | [diff] [blame] | 1201 | Move(location, Location::DoubleStackSlot(kCurrentMethodStackOffset)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1202 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1203 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1204 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1205 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1206 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 1207 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1208 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1209 | __ movl(location.AsRegister<CpuRegister>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1210 | } else if (location.IsStackSlot()) { |
| 1211 | __ movl(Address(CpuRegister(RSP), location.GetStackIndex()), imm); |
| 1212 | } else { |
| 1213 | DCHECK(location.IsConstant()); |
| 1214 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 1215 | } |
| 1216 | } else if (const_to_move->IsLongConstant()) { |
| 1217 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 1218 | if (location.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 1219 | Load64BitValue(location.AsRegister<CpuRegister>(), value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1220 | } else if (location.IsDoubleStackSlot()) { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1221 | Store64BitValueToStack(location, value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1222 | } else { |
| 1223 | DCHECK(location.IsConstant()); |
| 1224 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 1225 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1226 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 1227 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1228 | switch (instruction->GetType()) { |
| 1229 | case Primitive::kPrimBoolean: |
| 1230 | case Primitive::kPrimByte: |
| 1231 | case Primitive::kPrimChar: |
| 1232 | case Primitive::kPrimShort: |
| 1233 | case Primitive::kPrimInt: |
| 1234 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1235 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1236 | Move(location, Location::StackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
| 1237 | break; |
| 1238 | |
| 1239 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1240 | case Primitive::kPrimDouble: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1241 | Move(location, |
| 1242 | Location::DoubleStackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1243 | break; |
| 1244 | |
| 1245 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1246 | LOG(FATAL) << "Unexpected local type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1247 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 1248 | } else if (instruction->IsTemporary()) { |
| 1249 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
| 1250 | Move(location, temp_location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1251 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1252 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1253 | switch (instruction->GetType()) { |
| 1254 | case Primitive::kPrimBoolean: |
| 1255 | case Primitive::kPrimByte: |
| 1256 | case Primitive::kPrimChar: |
| 1257 | case Primitive::kPrimShort: |
| 1258 | case Primitive::kPrimInt: |
| 1259 | case Primitive::kPrimNot: |
| 1260 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1261 | case Primitive::kPrimFloat: |
| 1262 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1263 | Move(location, locations->Out()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1264 | break; |
| 1265 | |
| 1266 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1267 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1268 | } |
| 1269 | } |
| 1270 | } |
| 1271 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1272 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1273 | DCHECK(location.IsRegister()); |
| 1274 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1275 | } |
| 1276 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1277 | void CodeGeneratorX86_64::MoveLocation( |
| 1278 | Location dst, Location src, Primitive::Type dst_type ATTRIBUTE_UNUSED) { |
| 1279 | Move(dst, src); |
| 1280 | } |
| 1281 | |
| 1282 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1283 | if (location.IsRegister()) { |
| 1284 | locations->AddTemp(location); |
| 1285 | } else { |
| 1286 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1287 | } |
| 1288 | } |
| 1289 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1290 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1291 | DCHECK(!successor->IsExitBlock()); |
| 1292 | |
| 1293 | HBasicBlock* block = got->GetBlock(); |
| 1294 | HInstruction* previous = got->GetPrevious(); |
| 1295 | |
| 1296 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1297 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1298 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1299 | return; |
| 1300 | } |
| 1301 | |
| 1302 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1303 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1304 | } |
| 1305 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1306 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1307 | } |
| 1308 | } |
| 1309 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1310 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1311 | got->SetLocations(nullptr); |
| 1312 | } |
| 1313 | |
| 1314 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1315 | HandleGoto(got, got->GetSuccessor()); |
| 1316 | } |
| 1317 | |
| 1318 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1319 | try_boundary->SetLocations(nullptr); |
| 1320 | } |
| 1321 | |
| 1322 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1323 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1324 | if (!successor->IsExitBlock()) { |
| 1325 | HandleGoto(try_boundary, successor); |
| 1326 | } |
| 1327 | } |
| 1328 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1329 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1330 | exit->SetLocations(nullptr); |
| 1331 | } |
| 1332 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1333 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1334 | } |
| 1335 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1336 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1337 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1338 | LabelType* true_label, |
| 1339 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1340 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1341 | __ j(kUnordered, true_label); |
| 1342 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1343 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1344 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1345 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1346 | } |
| 1347 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1348 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1349 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1350 | LabelType* true_target_in, |
| 1351 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1352 | // Generated branching requires both targets to be explicit. If either of the |
| 1353 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1354 | LabelType fallthrough_target; |
| 1355 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1356 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1357 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1358 | LocationSummary* locations = condition->GetLocations(); |
| 1359 | Location left = locations->InAt(0); |
| 1360 | Location right = locations->InAt(1); |
| 1361 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1362 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1363 | switch (type) { |
| 1364 | case Primitive::kPrimLong: { |
| 1365 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1366 | if (right.IsConstant()) { |
| 1367 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1368 | if (IsInt<32>(value)) { |
| 1369 | if (value == 0) { |
| 1370 | __ testq(left_reg, left_reg); |
| 1371 | } else { |
| 1372 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 1373 | } |
| 1374 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1375 | // Value won't fit in a 32-bit integer. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1376 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
| 1377 | } |
| 1378 | } else if (right.IsDoubleStackSlot()) { |
| 1379 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1380 | } else { |
| 1381 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1382 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1383 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1384 | break; |
| 1385 | } |
| 1386 | case Primitive::kPrimFloat: { |
| 1387 | if (right.IsFpuRegister()) { |
| 1388 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1389 | } else if (right.IsConstant()) { |
| 1390 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1391 | codegen_->LiteralFloatAddress( |
| 1392 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1393 | } else { |
| 1394 | DCHECK(right.IsStackSlot()); |
| 1395 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1396 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1397 | } |
| 1398 | GenerateFPJumps(condition, true_target, false_target); |
| 1399 | break; |
| 1400 | } |
| 1401 | case Primitive::kPrimDouble: { |
| 1402 | if (right.IsFpuRegister()) { |
| 1403 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1404 | } else if (right.IsConstant()) { |
| 1405 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1406 | codegen_->LiteralDoubleAddress( |
| 1407 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1408 | } else { |
| 1409 | DCHECK(right.IsDoubleStackSlot()); |
| 1410 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1411 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1412 | } |
| 1413 | GenerateFPJumps(condition, true_target, false_target); |
| 1414 | break; |
| 1415 | } |
| 1416 | default: |
| 1417 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1418 | } |
| 1419 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1420 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1421 | __ jmp(false_target); |
| 1422 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1423 | |
| 1424 | if (fallthrough_target.IsLinked()) { |
| 1425 | __ Bind(&fallthrough_target); |
| 1426 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1427 | } |
| 1428 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1429 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1430 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1431 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1432 | // conditions if they are materialized due to the complex branching. |
| 1433 | return cond->IsCondition() && |
| 1434 | cond->GetNext() == branch && |
| 1435 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1436 | } |
| 1437 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1438 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1439 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1440 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1441 | LabelType* true_target, |
| 1442 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1443 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1444 | |
| 1445 | if (true_target == nullptr && false_target == nullptr) { |
| 1446 | // Nothing to do. The code always falls through. |
| 1447 | return; |
| 1448 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1449 | // Constant condition, statically compared against 1. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1450 | if (cond->AsIntConstant()->IsOne()) { |
| 1451 | if (true_target != nullptr) { |
| 1452 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1453 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1454 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1455 | DCHECK(cond->AsIntConstant()->IsZero()); |
| 1456 | if (false_target != nullptr) { |
| 1457 | __ jmp(false_target); |
| 1458 | } |
| 1459 | } |
| 1460 | return; |
| 1461 | } |
| 1462 | |
| 1463 | // The following code generates these patterns: |
| 1464 | // (1) true_target == nullptr && false_target != nullptr |
| 1465 | // - opposite condition true => branch to false_target |
| 1466 | // (2) true_target != nullptr && false_target == nullptr |
| 1467 | // - condition true => branch to true_target |
| 1468 | // (3) true_target != nullptr && false_target != nullptr |
| 1469 | // - condition true => branch to true_target |
| 1470 | // - branch to false_target |
| 1471 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1472 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1473 | if (true_target == nullptr) { |
| 1474 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1475 | } else { |
| 1476 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1477 | } |
| 1478 | } else { |
| 1479 | // Materialized condition, compare against 0. |
| 1480 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1481 | if (lhs.IsRegister()) { |
| 1482 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1483 | } else { |
| 1484 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1485 | } |
| 1486 | if (true_target == nullptr) { |
| 1487 | __ j(kEqual, false_target); |
| 1488 | } else { |
| 1489 | __ j(kNotEqual, true_target); |
| 1490 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1491 | } |
| 1492 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1493 | // Condition has not been materialized, use its inputs as the |
| 1494 | // comparison and its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1495 | HCondition* condition = cond->AsCondition(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1496 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1497 | // If this is a long or FP comparison that has been folded into |
| 1498 | // the HCondition, generate the comparison directly. |
| 1499 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1500 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1501 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1502 | return; |
| 1503 | } |
| 1504 | |
| 1505 | Location lhs = condition->GetLocations()->InAt(0); |
| 1506 | Location rhs = condition->GetLocations()->InAt(1); |
| 1507 | if (rhs.IsRegister()) { |
| 1508 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1509 | } else if (rhs.IsConstant()) { |
| 1510 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1511 | if (constant == 0) { |
| 1512 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1513 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1514 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1515 | } |
| 1516 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1517 | __ cmpl(lhs.AsRegister<CpuRegister>(), |
| 1518 | Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1519 | } |
| 1520 | if (true_target == nullptr) { |
| 1521 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1522 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1523 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1524 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1525 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1526 | |
| 1527 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1528 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1529 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1530 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1531 | } |
| 1532 | } |
| 1533 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1534 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1535 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1536 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1537 | locations->SetInAt(0, Location::Any()); |
| 1538 | } |
| 1539 | } |
| 1540 | |
| 1541 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1542 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1543 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1544 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1545 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1546 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1547 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1548 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1552 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1553 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1554 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1555 | locations->SetInAt(0, Location::Any()); |
| 1556 | } |
| 1557 | } |
| 1558 | |
| 1559 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1560 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1561 | GenerateTestAndBranch(deoptimize, |
| 1562 | /* condition_input_index */ 0, |
| 1563 | slow_path->GetEntryLabel(), |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1564 | /* false_target */ static_cast<Label*>(nullptr)); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1565 | } |
| 1566 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1567 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1568 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1569 | } |
| 1570 | |
| 1571 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
David Srbecky | b7070a2 | 2016-01-08 18:13:53 +0000 | [diff] [blame] | 1572 | if (codegen_->HasStackMapAtCurrentPc()) { |
| 1573 | // Ensure that we do not collide with the stack map of the previous instruction. |
| 1574 | __ nop(); |
| 1575 | } |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1576 | codegen_->RecordPcInfo(info, info->GetDexPc()); |
| 1577 | } |
| 1578 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1579 | void LocationsBuilderX86_64::VisitLocal(HLocal* local) { |
| 1580 | local->SetLocations(nullptr); |
| 1581 | } |
| 1582 | |
| 1583 | void InstructionCodeGeneratorX86_64::VisitLocal(HLocal* local) { |
| 1584 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 1585 | } |
| 1586 | |
| 1587 | void LocationsBuilderX86_64::VisitLoadLocal(HLoadLocal* local) { |
| 1588 | local->SetLocations(nullptr); |
| 1589 | } |
| 1590 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1591 | void InstructionCodeGeneratorX86_64::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1592 | // Nothing to do, this is driven by the code generator. |
| 1593 | } |
| 1594 | |
| 1595 | void LocationsBuilderX86_64::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1596 | LocationSummary* locations = |
| 1597 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1598 | switch (store->InputAt(1)->GetType()) { |
| 1599 | case Primitive::kPrimBoolean: |
| 1600 | case Primitive::kPrimByte: |
| 1601 | case Primitive::kPrimChar: |
| 1602 | case Primitive::kPrimShort: |
| 1603 | case Primitive::kPrimInt: |
| 1604 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1605 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1606 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1607 | break; |
| 1608 | |
| 1609 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1610 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1611 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1612 | break; |
| 1613 | |
| 1614 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1615 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1616 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1617 | } |
| 1618 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1619 | void InstructionCodeGeneratorX86_64::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1620 | } |
| 1621 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1622 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1623 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1624 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1625 | // Handle the long/FP comparisons made in instruction simplification. |
| 1626 | switch (cond->InputAt(0)->GetType()) { |
| 1627 | case Primitive::kPrimLong: |
| 1628 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1629 | locations->SetInAt(1, Location::Any()); |
| 1630 | break; |
| 1631 | case Primitive::kPrimFloat: |
| 1632 | case Primitive::kPrimDouble: |
| 1633 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1634 | locations->SetInAt(1, Location::Any()); |
| 1635 | break; |
| 1636 | default: |
| 1637 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1638 | locations->SetInAt(1, Location::Any()); |
| 1639 | break; |
| 1640 | } |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1641 | if (cond->NeedsMaterialization()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1642 | locations->SetOut(Location::RequiresRegister()); |
| 1643 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1644 | } |
| 1645 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1646 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1647 | if (!cond->NeedsMaterialization()) { |
| 1648 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1649 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1650 | |
| 1651 | LocationSummary* locations = cond->GetLocations(); |
| 1652 | Location lhs = locations->InAt(0); |
| 1653 | Location rhs = locations->InAt(1); |
| 1654 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1655 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1656 | |
| 1657 | switch (cond->InputAt(0)->GetType()) { |
| 1658 | default: |
| 1659 | // Integer case. |
| 1660 | |
| 1661 | // Clear output register: setcc only sets the low byte. |
| 1662 | __ xorl(reg, reg); |
| 1663 | |
| 1664 | if (rhs.IsRegister()) { |
| 1665 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1666 | } else if (rhs.IsConstant()) { |
| 1667 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1668 | if (constant == 0) { |
| 1669 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1670 | } else { |
| 1671 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
| 1672 | } |
| 1673 | } else { |
| 1674 | __ cmpl(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1675 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1676 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1677 | return; |
| 1678 | case Primitive::kPrimLong: |
| 1679 | // Clear output register: setcc only sets the low byte. |
| 1680 | __ xorl(reg, reg); |
| 1681 | |
| 1682 | if (rhs.IsRegister()) { |
| 1683 | __ cmpq(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1684 | } else if (rhs.IsConstant()) { |
| 1685 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 1686 | if (IsInt<32>(value)) { |
| 1687 | if (value == 0) { |
| 1688 | __ testq(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1689 | } else { |
| 1690 | __ cmpq(lhs.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 1691 | } |
| 1692 | } else { |
| 1693 | // Value won't fit in an int. |
| 1694 | __ cmpq(lhs.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 1695 | } |
| 1696 | } else { |
| 1697 | __ cmpq(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1698 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1699 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1700 | return; |
| 1701 | case Primitive::kPrimFloat: { |
| 1702 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1703 | if (rhs.IsConstant()) { |
| 1704 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1705 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1706 | } else if (rhs.IsStackSlot()) { |
| 1707 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1708 | } else { |
| 1709 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1710 | } |
| 1711 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1712 | break; |
| 1713 | } |
| 1714 | case Primitive::kPrimDouble: { |
| 1715 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1716 | if (rhs.IsConstant()) { |
| 1717 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1718 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1719 | } else if (rhs.IsDoubleStackSlot()) { |
| 1720 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1721 | } else { |
| 1722 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1723 | } |
| 1724 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1725 | break; |
| 1726 | } |
| 1727 | } |
| 1728 | |
| 1729 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1730 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1731 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1732 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1733 | __ Bind(&false_label); |
| 1734 | __ xorl(reg, reg); |
| 1735 | __ jmp(&done_label); |
| 1736 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1737 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1738 | __ Bind(&true_label); |
| 1739 | __ movl(reg, Immediate(1)); |
| 1740 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1744 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1748 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1752 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1753 | } |
| 1754 | |
| 1755 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1756 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1757 | } |
| 1758 | |
| 1759 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1760 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1764 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1765 | } |
| 1766 | |
| 1767 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1768 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1772 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1776 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1780 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1784 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1788 | HandleCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1789 | } |
| 1790 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1791 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1792 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1793 | } |
| 1794 | |
| 1795 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1796 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1800 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1804 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1808 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1812 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1813 | } |
| 1814 | |
| 1815 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1816 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1820 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1823 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1824 | LocationSummary* locations = |
| 1825 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1826 | switch (compare->InputAt(0)->GetType()) { |
| 1827 | case Primitive::kPrimLong: { |
| 1828 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1829 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1830 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1831 | break; |
| 1832 | } |
| 1833 | case Primitive::kPrimFloat: |
| 1834 | case Primitive::kPrimDouble: { |
| 1835 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1836 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1837 | locations->SetOut(Location::RequiresRegister()); |
| 1838 | break; |
| 1839 | } |
| 1840 | default: |
| 1841 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 1842 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1846 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1847 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1848 | Location left = locations->InAt(0); |
| 1849 | Location right = locations->InAt(1); |
| 1850 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1851 | NearLabel less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1852 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 1853 | switch (type) { |
| 1854 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1855 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1856 | if (right.IsConstant()) { |
| 1857 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1858 | if (IsInt<32>(value)) { |
| 1859 | if (value == 0) { |
| 1860 | __ testq(left_reg, left_reg); |
| 1861 | } else { |
| 1862 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 1863 | } |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1864 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1865 | // Value won't fit in an int. |
| 1866 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1867 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1868 | } else if (right.IsDoubleStackSlot()) { |
| 1869 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1870 | } else { |
| 1871 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1872 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1873 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1874 | } |
| 1875 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1876 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1877 | if (right.IsConstant()) { |
| 1878 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 1879 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 1880 | } else if (right.IsStackSlot()) { |
| 1881 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1882 | } else { |
| 1883 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1884 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1885 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 1886 | break; |
| 1887 | } |
| 1888 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1889 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1890 | if (right.IsConstant()) { |
| 1891 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1892 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 1893 | } else if (right.IsDoubleStackSlot()) { |
| 1894 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1895 | } else { |
| 1896 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1897 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1898 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 1899 | break; |
| 1900 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1901 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1902 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1903 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1904 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1905 | __ j(kEqual, &done); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1906 | __ 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] | 1907 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1908 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1909 | __ movl(out, Immediate(1)); |
| 1910 | __ jmp(&done); |
| 1911 | |
| 1912 | __ Bind(&less); |
| 1913 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1914 | |
| 1915 | __ Bind(&done); |
| 1916 | } |
| 1917 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1918 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1919 | LocationSummary* locations = |
| 1920 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1921 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1922 | } |
| 1923 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1924 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1925 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1926 | } |
| 1927 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1928 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1929 | LocationSummary* locations = |
| 1930 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1931 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1932 | } |
| 1933 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1934 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1935 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1936 | } |
| 1937 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1938 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1939 | LocationSummary* locations = |
| 1940 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1941 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1942 | } |
| 1943 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1944 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1945 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1946 | } |
| 1947 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1948 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1949 | LocationSummary* locations = |
| 1950 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1951 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1952 | } |
| 1953 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1954 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1955 | // Will be generated at use site. |
| 1956 | } |
| 1957 | |
| 1958 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1959 | LocationSummary* locations = |
| 1960 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1961 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1962 | } |
| 1963 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1964 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 1965 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1966 | // Will be generated at use site. |
| 1967 | } |
| 1968 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1969 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1970 | memory_barrier->SetLocations(nullptr); |
| 1971 | } |
| 1972 | |
| 1973 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 1974 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1975 | } |
| 1976 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1977 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 1978 | ret->SetLocations(nullptr); |
| 1979 | } |
| 1980 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1981 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1982 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1986 | LocationSummary* locations = |
| 1987 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1988 | switch (ret->InputAt(0)->GetType()) { |
| 1989 | case Primitive::kPrimBoolean: |
| 1990 | case Primitive::kPrimByte: |
| 1991 | case Primitive::kPrimChar: |
| 1992 | case Primitive::kPrimShort: |
| 1993 | case Primitive::kPrimInt: |
| 1994 | case Primitive::kPrimNot: |
| 1995 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1996 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1997 | break; |
| 1998 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1999 | case Primitive::kPrimFloat: |
| 2000 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2001 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2002 | break; |
| 2003 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2004 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2005 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2006 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 2010 | if (kIsDebugBuild) { |
| 2011 | switch (ret->InputAt(0)->GetType()) { |
| 2012 | case Primitive::kPrimBoolean: |
| 2013 | case Primitive::kPrimByte: |
| 2014 | case Primitive::kPrimChar: |
| 2015 | case Primitive::kPrimShort: |
| 2016 | case Primitive::kPrimInt: |
| 2017 | case Primitive::kPrimNot: |
| 2018 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2019 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2020 | break; |
| 2021 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2022 | case Primitive::kPrimFloat: |
| 2023 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2024 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2025 | XMM0); |
| 2026 | break; |
| 2027 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2028 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2029 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2030 | } |
| 2031 | } |
| 2032 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2033 | } |
| 2034 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2035 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 2036 | switch (type) { |
| 2037 | case Primitive::kPrimBoolean: |
| 2038 | case Primitive::kPrimByte: |
| 2039 | case Primitive::kPrimChar: |
| 2040 | case Primitive::kPrimShort: |
| 2041 | case Primitive::kPrimInt: |
| 2042 | case Primitive::kPrimNot: |
| 2043 | case Primitive::kPrimLong: |
| 2044 | return Location::RegisterLocation(RAX); |
| 2045 | |
| 2046 | case Primitive::kPrimVoid: |
| 2047 | return Location::NoLocation(); |
| 2048 | |
| 2049 | case Primitive::kPrimDouble: |
| 2050 | case Primitive::kPrimFloat: |
| 2051 | return Location::FpuRegisterLocation(XMM0); |
| 2052 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2053 | |
| 2054 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2058 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2059 | } |
| 2060 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2061 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2062 | switch (type) { |
| 2063 | case Primitive::kPrimBoolean: |
| 2064 | case Primitive::kPrimByte: |
| 2065 | case Primitive::kPrimChar: |
| 2066 | case Primitive::kPrimShort: |
| 2067 | case Primitive::kPrimInt: |
| 2068 | case Primitive::kPrimNot: { |
| 2069 | uint32_t index = gp_index_++; |
| 2070 | stack_index_++; |
| 2071 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2072 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2073 | } else { |
| 2074 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2075 | } |
| 2076 | } |
| 2077 | |
| 2078 | case Primitive::kPrimLong: { |
| 2079 | uint32_t index = gp_index_; |
| 2080 | stack_index_ += 2; |
| 2081 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2082 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2083 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2084 | } else { |
| 2085 | gp_index_ += 2; |
| 2086 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2087 | } |
| 2088 | } |
| 2089 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2090 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2091 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2092 | stack_index_++; |
| 2093 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2094 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2095 | } else { |
| 2096 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2097 | } |
| 2098 | } |
| 2099 | |
| 2100 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2101 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2102 | stack_index_ += 2; |
| 2103 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2104 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2105 | } else { |
| 2106 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2107 | } |
| 2108 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2109 | |
| 2110 | case Primitive::kPrimVoid: |
| 2111 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2112 | break; |
| 2113 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2114 | return Location::NoLocation(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2115 | } |
| 2116 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2117 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2118 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2119 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2120 | // the method_idx. |
| 2121 | HandleInvoke(invoke); |
| 2122 | } |
| 2123 | |
| 2124 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2125 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2126 | } |
| 2127 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2128 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame^] | 2129 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2130 | // art::PrepareForRegisterAllocation. |
| 2131 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2132 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2133 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2134 | if (intrinsic.TryDispatch(invoke)) { |
| 2135 | return; |
| 2136 | } |
| 2137 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2138 | HandleInvoke(invoke); |
| 2139 | } |
| 2140 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2141 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2142 | if (invoke->GetLocations()->Intrinsified()) { |
| 2143 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2144 | intrinsic.Dispatch(invoke); |
| 2145 | return true; |
| 2146 | } |
| 2147 | return false; |
| 2148 | } |
| 2149 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2150 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame^] | 2151 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2152 | // art::PrepareForRegisterAllocation. |
| 2153 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2154 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2155 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2156 | return; |
| 2157 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2158 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2159 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2160 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2161 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2162 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2163 | } |
| 2164 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2165 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2166 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2167 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2168 | } |
| 2169 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2170 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2171 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2172 | if (intrinsic.TryDispatch(invoke)) { |
| 2173 | return; |
| 2174 | } |
| 2175 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2176 | HandleInvoke(invoke); |
| 2177 | } |
| 2178 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2179 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2180 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2181 | return; |
| 2182 | } |
| 2183 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2184 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2185 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2186 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2187 | } |
| 2188 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2189 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2190 | HandleInvoke(invoke); |
| 2191 | // Add the hidden argument. |
| 2192 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2193 | } |
| 2194 | |
| 2195 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2196 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2197 | LocationSummary* locations = invoke->GetLocations(); |
| 2198 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2199 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2200 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2201 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2202 | Location receiver = locations->InAt(0); |
| 2203 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2204 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2205 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2206 | // won't be modified thereafter, before the `call` instruction. |
| 2207 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2208 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2209 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2210 | if (receiver.IsStackSlot()) { |
| 2211 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2212 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2213 | __ movl(temp, Address(temp, class_offset)); |
| 2214 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2215 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2216 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2217 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2218 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2219 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2220 | // emit a read barrier for the previous class reference load. |
| 2221 | // However this is not required in practice, as this is an |
| 2222 | // intermediate/temporary reference and because the current |
| 2223 | // concurrent copying collector keeps the from-space memory |
| 2224 | // intact/accessible until the end of the marking phase (the |
| 2225 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2226 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2227 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2228 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2229 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2230 | __ call(Address(temp, |
| 2231 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2232 | |
| 2233 | DCHECK(!codegen_->IsLeafMethod()); |
| 2234 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2235 | } |
| 2236 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2237 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2238 | LocationSummary* locations = |
| 2239 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2240 | switch (neg->GetResultType()) { |
| 2241 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2242 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2243 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2244 | locations->SetOut(Location::SameAsFirstInput()); |
| 2245 | break; |
| 2246 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2247 | case Primitive::kPrimFloat: |
| 2248 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2249 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2250 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2251 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2252 | break; |
| 2253 | |
| 2254 | default: |
| 2255 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2256 | } |
| 2257 | } |
| 2258 | |
| 2259 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2260 | LocationSummary* locations = neg->GetLocations(); |
| 2261 | Location out = locations->Out(); |
| 2262 | Location in = locations->InAt(0); |
| 2263 | switch (neg->GetResultType()) { |
| 2264 | case Primitive::kPrimInt: |
| 2265 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2266 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2267 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2268 | break; |
| 2269 | |
| 2270 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2271 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2272 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2273 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2274 | break; |
| 2275 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2276 | case Primitive::kPrimFloat: { |
| 2277 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2278 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2279 | // Implement float negation with an exclusive or with value |
| 2280 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2281 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2282 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2283 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2284 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2285 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2286 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2287 | case Primitive::kPrimDouble: { |
| 2288 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2289 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2290 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2291 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2292 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2293 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2294 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2295 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2296 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2297 | |
| 2298 | default: |
| 2299 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2300 | } |
| 2301 | } |
| 2302 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2303 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2304 | LocationSummary* locations = |
| 2305 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 2306 | Primitive::Type result_type = conversion->GetResultType(); |
| 2307 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2308 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2309 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2310 | // The Java language does not allow treating boolean as an integral type but |
| 2311 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2312 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2313 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2314 | case Primitive::kPrimByte: |
| 2315 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2316 | case Primitive::kPrimBoolean: |
| 2317 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2318 | case Primitive::kPrimShort: |
| 2319 | case Primitive::kPrimInt: |
| 2320 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2321 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2322 | locations->SetInAt(0, Location::Any()); |
| 2323 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2324 | break; |
| 2325 | |
| 2326 | default: |
| 2327 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2328 | << " to " << result_type; |
| 2329 | } |
| 2330 | break; |
| 2331 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2332 | case Primitive::kPrimShort: |
| 2333 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2334 | case Primitive::kPrimBoolean: |
| 2335 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2336 | case Primitive::kPrimByte: |
| 2337 | case Primitive::kPrimInt: |
| 2338 | case Primitive::kPrimChar: |
| 2339 | // Processing a Dex `int-to-short' instruction. |
| 2340 | locations->SetInAt(0, Location::Any()); |
| 2341 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2342 | break; |
| 2343 | |
| 2344 | default: |
| 2345 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2346 | << " to " << result_type; |
| 2347 | } |
| 2348 | break; |
| 2349 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2350 | case Primitive::kPrimInt: |
| 2351 | switch (input_type) { |
| 2352 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2353 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2354 | locations->SetInAt(0, Location::Any()); |
| 2355 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2356 | break; |
| 2357 | |
| 2358 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2359 | // Processing a Dex `float-to-int' instruction. |
| 2360 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2361 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2362 | break; |
| 2363 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2364 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2365 | // Processing a Dex `double-to-int' instruction. |
| 2366 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2367 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2368 | break; |
| 2369 | |
| 2370 | default: |
| 2371 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2372 | << " to " << result_type; |
| 2373 | } |
| 2374 | break; |
| 2375 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2376 | case Primitive::kPrimLong: |
| 2377 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2378 | case Primitive::kPrimBoolean: |
| 2379 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2380 | case Primitive::kPrimByte: |
| 2381 | case Primitive::kPrimShort: |
| 2382 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2383 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2384 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2385 | // TODO: We would benefit from a (to-be-implemented) |
| 2386 | // Location::RegisterOrStackSlot requirement for this input. |
| 2387 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2388 | locations->SetOut(Location::RequiresRegister()); |
| 2389 | break; |
| 2390 | |
| 2391 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2392 | // Processing a Dex `float-to-long' instruction. |
| 2393 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2394 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2395 | break; |
| 2396 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2397 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2398 | // Processing a Dex `double-to-long' instruction. |
| 2399 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2400 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2401 | break; |
| 2402 | |
| 2403 | default: |
| 2404 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2405 | << " to " << result_type; |
| 2406 | } |
| 2407 | break; |
| 2408 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2409 | case Primitive::kPrimChar: |
| 2410 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2411 | case Primitive::kPrimBoolean: |
| 2412 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2413 | case Primitive::kPrimByte: |
| 2414 | case Primitive::kPrimShort: |
| 2415 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2416 | // Processing a Dex `int-to-char' instruction. |
| 2417 | locations->SetInAt(0, Location::Any()); |
| 2418 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2419 | break; |
| 2420 | |
| 2421 | default: |
| 2422 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2423 | << " to " << result_type; |
| 2424 | } |
| 2425 | break; |
| 2426 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2427 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2428 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2429 | case Primitive::kPrimBoolean: |
| 2430 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2431 | case Primitive::kPrimByte: |
| 2432 | case Primitive::kPrimShort: |
| 2433 | case Primitive::kPrimInt: |
| 2434 | case Primitive::kPrimChar: |
| 2435 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2436 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2437 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2438 | break; |
| 2439 | |
| 2440 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2441 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2442 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2443 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2444 | break; |
| 2445 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2446 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2447 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2448 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2449 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2450 | break; |
| 2451 | |
| 2452 | default: |
| 2453 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2454 | << " to " << result_type; |
| 2455 | }; |
| 2456 | break; |
| 2457 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2458 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2459 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2460 | case Primitive::kPrimBoolean: |
| 2461 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2462 | case Primitive::kPrimByte: |
| 2463 | case Primitive::kPrimShort: |
| 2464 | case Primitive::kPrimInt: |
| 2465 | case Primitive::kPrimChar: |
| 2466 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2467 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2468 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2469 | break; |
| 2470 | |
| 2471 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2472 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2473 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2474 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2475 | break; |
| 2476 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2477 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2478 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2479 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2480 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2481 | break; |
| 2482 | |
| 2483 | default: |
| 2484 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2485 | << " to " << result_type; |
| 2486 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2487 | break; |
| 2488 | |
| 2489 | default: |
| 2490 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2491 | << " to " << result_type; |
| 2492 | } |
| 2493 | } |
| 2494 | |
| 2495 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2496 | LocationSummary* locations = conversion->GetLocations(); |
| 2497 | Location out = locations->Out(); |
| 2498 | Location in = locations->InAt(0); |
| 2499 | Primitive::Type result_type = conversion->GetResultType(); |
| 2500 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2501 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2502 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2503 | case Primitive::kPrimByte: |
| 2504 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2505 | case Primitive::kPrimBoolean: |
| 2506 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2507 | case Primitive::kPrimShort: |
| 2508 | case Primitive::kPrimInt: |
| 2509 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2510 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2511 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2512 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2513 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2514 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2515 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2516 | } else { |
| 2517 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2518 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2519 | Immediate(static_cast<int8_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2520 | } |
| 2521 | break; |
| 2522 | |
| 2523 | default: |
| 2524 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2525 | << " to " << result_type; |
| 2526 | } |
| 2527 | break; |
| 2528 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2529 | case Primitive::kPrimShort: |
| 2530 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2531 | case Primitive::kPrimBoolean: |
| 2532 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2533 | case Primitive::kPrimByte: |
| 2534 | case Primitive::kPrimInt: |
| 2535 | case Primitive::kPrimChar: |
| 2536 | // Processing a Dex `int-to-short' instruction. |
| 2537 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2538 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2539 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2540 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2541 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2542 | } else { |
| 2543 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2544 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2545 | Immediate(static_cast<int16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2546 | } |
| 2547 | break; |
| 2548 | |
| 2549 | default: |
| 2550 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2551 | << " to " << result_type; |
| 2552 | } |
| 2553 | break; |
| 2554 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2555 | case Primitive::kPrimInt: |
| 2556 | switch (input_type) { |
| 2557 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2558 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2559 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2560 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2561 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2562 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2563 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2564 | } else { |
| 2565 | DCHECK(in.IsConstant()); |
| 2566 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2567 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2568 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2569 | } |
| 2570 | break; |
| 2571 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2572 | case Primitive::kPrimFloat: { |
| 2573 | // Processing a Dex `float-to-int' instruction. |
| 2574 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2575 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2576 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2577 | |
| 2578 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2579 | // if input >= (float)INT_MAX goto done |
| 2580 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2581 | __ j(kAboveEqual, &done); |
| 2582 | // if input == NaN goto nan |
| 2583 | __ j(kUnordered, &nan); |
| 2584 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2585 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2586 | __ jmp(&done); |
| 2587 | __ Bind(&nan); |
| 2588 | // output = 0 |
| 2589 | __ xorl(output, output); |
| 2590 | __ Bind(&done); |
| 2591 | break; |
| 2592 | } |
| 2593 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2594 | case Primitive::kPrimDouble: { |
| 2595 | // Processing a Dex `double-to-int' instruction. |
| 2596 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2597 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2598 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2599 | |
| 2600 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2601 | // if input >= (double)INT_MAX goto done |
| 2602 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2603 | __ j(kAboveEqual, &done); |
| 2604 | // if input == NaN goto nan |
| 2605 | __ j(kUnordered, &nan); |
| 2606 | // output = double-to-int-truncate(input) |
| 2607 | __ cvttsd2si(output, input); |
| 2608 | __ jmp(&done); |
| 2609 | __ Bind(&nan); |
| 2610 | // output = 0 |
| 2611 | __ xorl(output, output); |
| 2612 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2613 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2614 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2615 | |
| 2616 | default: |
| 2617 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2618 | << " to " << result_type; |
| 2619 | } |
| 2620 | break; |
| 2621 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2622 | case Primitive::kPrimLong: |
| 2623 | switch (input_type) { |
| 2624 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2625 | case Primitive::kPrimBoolean: |
| 2626 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2627 | case Primitive::kPrimByte: |
| 2628 | case Primitive::kPrimShort: |
| 2629 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2630 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2631 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2632 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2633 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2634 | break; |
| 2635 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2636 | case Primitive::kPrimFloat: { |
| 2637 | // Processing a Dex `float-to-long' instruction. |
| 2638 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2639 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2640 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2641 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2642 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2643 | // if input >= (float)LONG_MAX goto done |
| 2644 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2645 | __ j(kAboveEqual, &done); |
| 2646 | // if input == NaN goto nan |
| 2647 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2648 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2649 | __ cvttss2si(output, input, true); |
| 2650 | __ jmp(&done); |
| 2651 | __ Bind(&nan); |
| 2652 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2653 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2654 | __ Bind(&done); |
| 2655 | break; |
| 2656 | } |
| 2657 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2658 | case Primitive::kPrimDouble: { |
| 2659 | // Processing a Dex `double-to-long' instruction. |
| 2660 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2661 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2662 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2663 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2664 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2665 | // if input >= (double)LONG_MAX goto done |
| 2666 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2667 | __ j(kAboveEqual, &done); |
| 2668 | // if input == NaN goto nan |
| 2669 | __ j(kUnordered, &nan); |
| 2670 | // output = double-to-long-truncate(input) |
| 2671 | __ cvttsd2si(output, input, true); |
| 2672 | __ jmp(&done); |
| 2673 | __ Bind(&nan); |
| 2674 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2675 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2676 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2677 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2678 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2679 | |
| 2680 | default: |
| 2681 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2682 | << " to " << result_type; |
| 2683 | } |
| 2684 | break; |
| 2685 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2686 | case Primitive::kPrimChar: |
| 2687 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2688 | case Primitive::kPrimBoolean: |
| 2689 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2690 | case Primitive::kPrimByte: |
| 2691 | case Primitive::kPrimShort: |
| 2692 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2693 | // Processing a Dex `int-to-char' instruction. |
| 2694 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2695 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2696 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2697 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2698 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2699 | } else { |
| 2700 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2701 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2702 | Immediate(static_cast<uint16_t>( |
| 2703 | in.GetConstant()->AsIntConstant()->GetValue()))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2704 | } |
| 2705 | break; |
| 2706 | |
| 2707 | default: |
| 2708 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2709 | << " to " << result_type; |
| 2710 | } |
| 2711 | break; |
| 2712 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2713 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2714 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2715 | case Primitive::kPrimBoolean: |
| 2716 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2717 | case Primitive::kPrimByte: |
| 2718 | case Primitive::kPrimShort: |
| 2719 | case Primitive::kPrimInt: |
| 2720 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2721 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2722 | if (in.IsRegister()) { |
| 2723 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2724 | } else if (in.IsConstant()) { |
| 2725 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2726 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2727 | if (v == 0) { |
| 2728 | __ xorps(dest, dest); |
| 2729 | } else { |
| 2730 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2731 | } |
| 2732 | } else { |
| 2733 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2734 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2735 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2736 | break; |
| 2737 | |
| 2738 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2739 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2740 | if (in.IsRegister()) { |
| 2741 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2742 | } else if (in.IsConstant()) { |
| 2743 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2744 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2745 | if (v == 0) { |
| 2746 | __ xorps(dest, dest); |
| 2747 | } else { |
| 2748 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2749 | } |
| 2750 | } else { |
| 2751 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2752 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2753 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2754 | break; |
| 2755 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2756 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2757 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2758 | if (in.IsFpuRegister()) { |
| 2759 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2760 | } else if (in.IsConstant()) { |
| 2761 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2762 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2763 | if (bit_cast<int64_t, double>(v) == 0) { |
| 2764 | __ xorps(dest, dest); |
| 2765 | } else { |
| 2766 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2767 | } |
| 2768 | } else { |
| 2769 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2770 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2771 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2772 | break; |
| 2773 | |
| 2774 | default: |
| 2775 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2776 | << " to " << result_type; |
| 2777 | }; |
| 2778 | break; |
| 2779 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2780 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2781 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2782 | case Primitive::kPrimBoolean: |
| 2783 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2784 | case Primitive::kPrimByte: |
| 2785 | case Primitive::kPrimShort: |
| 2786 | case Primitive::kPrimInt: |
| 2787 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2788 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2789 | if (in.IsRegister()) { |
| 2790 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2791 | } else if (in.IsConstant()) { |
| 2792 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2793 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2794 | if (v == 0) { |
| 2795 | __ xorpd(dest, dest); |
| 2796 | } else { |
| 2797 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2798 | } |
| 2799 | } else { |
| 2800 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2801 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2802 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2803 | break; |
| 2804 | |
| 2805 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2806 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2807 | if (in.IsRegister()) { |
| 2808 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2809 | } else if (in.IsConstant()) { |
| 2810 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2811 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2812 | if (v == 0) { |
| 2813 | __ xorpd(dest, dest); |
| 2814 | } else { |
| 2815 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2816 | } |
| 2817 | } else { |
| 2818 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2819 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2820 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2821 | break; |
| 2822 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2823 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2824 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2825 | if (in.IsFpuRegister()) { |
| 2826 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2827 | } else if (in.IsConstant()) { |
| 2828 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 2829 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2830 | if (bit_cast<int32_t, float>(v) == 0) { |
| 2831 | __ xorpd(dest, dest); |
| 2832 | } else { |
| 2833 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2834 | } |
| 2835 | } else { |
| 2836 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 2837 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2838 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2839 | break; |
| 2840 | |
| 2841 | default: |
| 2842 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2843 | << " to " << result_type; |
| 2844 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2845 | break; |
| 2846 | |
| 2847 | default: |
| 2848 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2849 | << " to " << result_type; |
| 2850 | } |
| 2851 | } |
| 2852 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2853 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2854 | LocationSummary* locations = |
| 2855 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2856 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2857 | case Primitive::kPrimInt: { |
| 2858 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2859 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2860 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2861 | break; |
| 2862 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2863 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2864 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2865 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2866 | // 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] | 2867 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2868 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2869 | break; |
| 2870 | } |
| 2871 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2872 | case Primitive::kPrimDouble: |
| 2873 | case Primitive::kPrimFloat: { |
| 2874 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2875 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2876 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2877 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2878 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2879 | |
| 2880 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2881 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2882 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2883 | } |
| 2884 | |
| 2885 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 2886 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2887 | Location first = locations->InAt(0); |
| 2888 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2889 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2890 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2891 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2892 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2893 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2894 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2895 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2896 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2897 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2898 | } else { |
| 2899 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2900 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2901 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2902 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2903 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2904 | __ addl(out.AsRegister<CpuRegister>(), |
| 2905 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 2906 | } else { |
| 2907 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2908 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 2909 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2910 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2911 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2912 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2913 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2914 | break; |
| 2915 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2916 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2917 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2918 | if (second.IsRegister()) { |
| 2919 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2920 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2921 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2922 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2923 | } else { |
| 2924 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2925 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2926 | } |
| 2927 | } else { |
| 2928 | DCHECK(second.IsConstant()); |
| 2929 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2930 | int32_t int32_value = Low32Bits(value); |
| 2931 | DCHECK_EQ(int32_value, value); |
| 2932 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2933 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 2934 | } else { |
| 2935 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2936 | first.AsRegister<CpuRegister>(), int32_value)); |
| 2937 | } |
| 2938 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2939 | break; |
| 2940 | } |
| 2941 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2942 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2943 | if (second.IsFpuRegister()) { |
| 2944 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2945 | } else if (second.IsConstant()) { |
| 2946 | __ addss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2947 | codegen_->LiteralFloatAddress( |
| 2948 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2949 | } else { |
| 2950 | DCHECK(second.IsStackSlot()); |
| 2951 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2952 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2953 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2954 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2955 | } |
| 2956 | |
| 2957 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2958 | if (second.IsFpuRegister()) { |
| 2959 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2960 | } else if (second.IsConstant()) { |
| 2961 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2962 | codegen_->LiteralDoubleAddress( |
| 2963 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2964 | } else { |
| 2965 | DCHECK(second.IsDoubleStackSlot()); |
| 2966 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2967 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2968 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2969 | break; |
| 2970 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2971 | |
| 2972 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2973 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2974 | } |
| 2975 | } |
| 2976 | |
| 2977 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2978 | LocationSummary* locations = |
| 2979 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2980 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2981 | case Primitive::kPrimInt: { |
| 2982 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2983 | locations->SetInAt(1, Location::Any()); |
| 2984 | locations->SetOut(Location::SameAsFirstInput()); |
| 2985 | break; |
| 2986 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2987 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2988 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 2989 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2990 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2991 | break; |
| 2992 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2993 | case Primitive::kPrimFloat: |
| 2994 | case Primitive::kPrimDouble: { |
| 2995 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2996 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2997 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2998 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2999 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3000 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3001 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3002 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3003 | } |
| 3004 | |
| 3005 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3006 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3007 | Location first = locations->InAt(0); |
| 3008 | Location second = locations->InAt(1); |
| 3009 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3010 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3011 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3012 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3013 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3014 | } else if (second.IsConstant()) { |
| 3015 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3016 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3017 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3018 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3019 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3020 | break; |
| 3021 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3022 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3023 | if (second.IsConstant()) { |
| 3024 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3025 | DCHECK(IsInt<32>(value)); |
| 3026 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3027 | } else { |
| 3028 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3029 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3030 | break; |
| 3031 | } |
| 3032 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3033 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3034 | if (second.IsFpuRegister()) { |
| 3035 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3036 | } else if (second.IsConstant()) { |
| 3037 | __ subss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3038 | codegen_->LiteralFloatAddress( |
| 3039 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3040 | } else { |
| 3041 | DCHECK(second.IsStackSlot()); |
| 3042 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3043 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3044 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3045 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3046 | } |
| 3047 | |
| 3048 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3049 | if (second.IsFpuRegister()) { |
| 3050 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3051 | } else if (second.IsConstant()) { |
| 3052 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3053 | codegen_->LiteralDoubleAddress( |
| 3054 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3055 | } else { |
| 3056 | DCHECK(second.IsDoubleStackSlot()); |
| 3057 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3058 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3059 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3060 | break; |
| 3061 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3062 | |
| 3063 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3064 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3065 | } |
| 3066 | } |
| 3067 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3068 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3069 | LocationSummary* locations = |
| 3070 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3071 | switch (mul->GetResultType()) { |
| 3072 | case Primitive::kPrimInt: { |
| 3073 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3074 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3075 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3076 | // Can use 3 operand multiply. |
| 3077 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3078 | } else { |
| 3079 | locations->SetOut(Location::SameAsFirstInput()); |
| 3080 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3081 | break; |
| 3082 | } |
| 3083 | case Primitive::kPrimLong: { |
| 3084 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3085 | locations->SetInAt(1, Location::Any()); |
| 3086 | if (mul->InputAt(1)->IsLongConstant() && |
| 3087 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3088 | // Can use 3 operand multiply. |
| 3089 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3090 | } else { |
| 3091 | locations->SetOut(Location::SameAsFirstInput()); |
| 3092 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3093 | break; |
| 3094 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3095 | case Primitive::kPrimFloat: |
| 3096 | case Primitive::kPrimDouble: { |
| 3097 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3098 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3099 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3100 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3101 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3102 | |
| 3103 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3104 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3105 | } |
| 3106 | } |
| 3107 | |
| 3108 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3109 | LocationSummary* locations = mul->GetLocations(); |
| 3110 | Location first = locations->InAt(0); |
| 3111 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3112 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3113 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3114 | case Primitive::kPrimInt: |
| 3115 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3116 | // problems where the output may not be the same as the first operand. |
| 3117 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3118 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3119 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3120 | } else if (second.IsRegister()) { |
| 3121 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3122 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3123 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3124 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3125 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3126 | __ imull(first.AsRegister<CpuRegister>(), |
| 3127 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3128 | } |
| 3129 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3130 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3131 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3132 | // problems where the output may not be the same as the first operand. |
| 3133 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3134 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3135 | if (IsInt<32>(value)) { |
| 3136 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3137 | Immediate(static_cast<int32_t>(value))); |
| 3138 | } else { |
| 3139 | // Have to use the constant area. |
| 3140 | DCHECK(first.Equals(out)); |
| 3141 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3142 | } |
| 3143 | } else if (second.IsRegister()) { |
| 3144 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3145 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3146 | } else { |
| 3147 | DCHECK(second.IsDoubleStackSlot()); |
| 3148 | DCHECK(first.Equals(out)); |
| 3149 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3150 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3151 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3152 | break; |
| 3153 | } |
| 3154 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3155 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3156 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3157 | if (second.IsFpuRegister()) { |
| 3158 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3159 | } else if (second.IsConstant()) { |
| 3160 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3161 | codegen_->LiteralFloatAddress( |
| 3162 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3163 | } else { |
| 3164 | DCHECK(second.IsStackSlot()); |
| 3165 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3166 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3167 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3168 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3169 | } |
| 3170 | |
| 3171 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3172 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3173 | if (second.IsFpuRegister()) { |
| 3174 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3175 | } else if (second.IsConstant()) { |
| 3176 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3177 | codegen_->LiteralDoubleAddress( |
| 3178 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3179 | } else { |
| 3180 | DCHECK(second.IsDoubleStackSlot()); |
| 3181 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3182 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3183 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3184 | break; |
| 3185 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3186 | |
| 3187 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3188 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3189 | } |
| 3190 | } |
| 3191 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3192 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3193 | uint32_t stack_adjustment, bool is_float) { |
| 3194 | if (source.IsStackSlot()) { |
| 3195 | DCHECK(is_float); |
| 3196 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3197 | } else if (source.IsDoubleStackSlot()) { |
| 3198 | DCHECK(!is_float); |
| 3199 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3200 | } else { |
| 3201 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3202 | if (is_float) { |
| 3203 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3204 | codegen_->Move(stack_temp, source); |
| 3205 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3206 | } else { |
| 3207 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3208 | codegen_->Move(stack_temp, source); |
| 3209 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3210 | } |
| 3211 | } |
| 3212 | } |
| 3213 | |
| 3214 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 3215 | Primitive::Type type = rem->GetResultType(); |
| 3216 | bool is_float = type == Primitive::kPrimFloat; |
| 3217 | size_t elem_size = Primitive::ComponentSize(type); |
| 3218 | LocationSummary* locations = rem->GetLocations(); |
| 3219 | Location first = locations->InAt(0); |
| 3220 | Location second = locations->InAt(1); |
| 3221 | Location out = locations->Out(); |
| 3222 | |
| 3223 | // Create stack space for 2 elements. |
| 3224 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3225 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3226 | |
| 3227 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3228 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3229 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3230 | |
| 3231 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3232 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3233 | __ Bind(&retry); |
| 3234 | __ fprem(); |
| 3235 | |
| 3236 | // Move FP status to AX. |
| 3237 | __ fstsw(); |
| 3238 | |
| 3239 | // And see if the argument reduction is complete. This is signaled by the |
| 3240 | // C2 FPU flag bit set to 0. |
| 3241 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3242 | __ j(kNotEqual, &retry); |
| 3243 | |
| 3244 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3245 | // Store FP top of stack to real stack. |
| 3246 | if (is_float) { |
| 3247 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3248 | } else { |
| 3249 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3250 | } |
| 3251 | |
| 3252 | // Pop the 2 items from the FP stack. |
| 3253 | __ fucompp(); |
| 3254 | |
| 3255 | // Load the value from the stack into an XMM register. |
| 3256 | DCHECK(out.IsFpuRegister()) << out; |
| 3257 | if (is_float) { |
| 3258 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3259 | } else { |
| 3260 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3261 | } |
| 3262 | |
| 3263 | // And remove the temporary stack space we allocated. |
| 3264 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3265 | } |
| 3266 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3267 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3268 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3269 | |
| 3270 | LocationSummary* locations = instruction->GetLocations(); |
| 3271 | Location second = locations->InAt(1); |
| 3272 | DCHECK(second.IsConstant()); |
| 3273 | |
| 3274 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3275 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3276 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3277 | |
| 3278 | DCHECK(imm == 1 || imm == -1); |
| 3279 | |
| 3280 | switch (instruction->GetResultType()) { |
| 3281 | case Primitive::kPrimInt: { |
| 3282 | if (instruction->IsRem()) { |
| 3283 | __ xorl(output_register, output_register); |
| 3284 | } else { |
| 3285 | __ movl(output_register, input_register); |
| 3286 | if (imm == -1) { |
| 3287 | __ negl(output_register); |
| 3288 | } |
| 3289 | } |
| 3290 | break; |
| 3291 | } |
| 3292 | |
| 3293 | case Primitive::kPrimLong: { |
| 3294 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3295 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3296 | } else { |
| 3297 | __ movq(output_register, input_register); |
| 3298 | if (imm == -1) { |
| 3299 | __ negq(output_register); |
| 3300 | } |
| 3301 | } |
| 3302 | break; |
| 3303 | } |
| 3304 | |
| 3305 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3306 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3307 | } |
| 3308 | } |
| 3309 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3310 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3311 | LocationSummary* locations = instruction->GetLocations(); |
| 3312 | Location second = locations->InAt(1); |
| 3313 | |
| 3314 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3315 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3316 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3317 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3318 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3319 | uint64_t abs_imm = AbsOrMin(imm); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3320 | |
| 3321 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3322 | |
| 3323 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3324 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3325 | __ testl(numerator, numerator); |
| 3326 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3327 | int shift = CTZ(imm); |
| 3328 | __ sarl(tmp, Immediate(shift)); |
| 3329 | |
| 3330 | if (imm < 0) { |
| 3331 | __ negl(tmp); |
| 3332 | } |
| 3333 | |
| 3334 | __ movl(output_register, tmp); |
| 3335 | } else { |
| 3336 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3337 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3338 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3339 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3340 | __ addq(rdx, numerator); |
| 3341 | __ testq(numerator, numerator); |
| 3342 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3343 | int shift = CTZ(imm); |
| 3344 | __ sarq(rdx, Immediate(shift)); |
| 3345 | |
| 3346 | if (imm < 0) { |
| 3347 | __ negq(rdx); |
| 3348 | } |
| 3349 | |
| 3350 | __ movq(output_register, rdx); |
| 3351 | } |
| 3352 | } |
| 3353 | |
| 3354 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3355 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3356 | |
| 3357 | LocationSummary* locations = instruction->GetLocations(); |
| 3358 | Location second = locations->InAt(1); |
| 3359 | |
| 3360 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3361 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3362 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3363 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3364 | : locations->Out().AsRegister<CpuRegister>(); |
| 3365 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3366 | |
| 3367 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3368 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3369 | if (instruction->IsDiv()) { |
| 3370 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3371 | } else { |
| 3372 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3373 | } |
| 3374 | |
| 3375 | int64_t magic; |
| 3376 | int shift; |
| 3377 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3378 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3379 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3380 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3381 | |
| 3382 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3383 | |
| 3384 | __ movl(numerator, eax); |
| 3385 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3386 | NearLabel no_div; |
| 3387 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3388 | __ testl(eax, eax); |
| 3389 | __ j(kNotEqual, &no_div); |
| 3390 | |
| 3391 | __ xorl(out, out); |
| 3392 | __ jmp(&end); |
| 3393 | |
| 3394 | __ Bind(&no_div); |
| 3395 | |
| 3396 | __ movl(eax, Immediate(magic)); |
| 3397 | __ imull(numerator); |
| 3398 | |
| 3399 | if (imm > 0 && magic < 0) { |
| 3400 | __ addl(edx, numerator); |
| 3401 | } else if (imm < 0 && magic > 0) { |
| 3402 | __ subl(edx, numerator); |
| 3403 | } |
| 3404 | |
| 3405 | if (shift != 0) { |
| 3406 | __ sarl(edx, Immediate(shift)); |
| 3407 | } |
| 3408 | |
| 3409 | __ movl(eax, edx); |
| 3410 | __ shrl(edx, Immediate(31)); |
| 3411 | __ addl(edx, eax); |
| 3412 | |
| 3413 | if (instruction->IsRem()) { |
| 3414 | __ movl(eax, numerator); |
| 3415 | __ imull(edx, Immediate(imm)); |
| 3416 | __ subl(eax, edx); |
| 3417 | __ movl(edx, eax); |
| 3418 | } else { |
| 3419 | __ movl(eax, edx); |
| 3420 | } |
| 3421 | __ Bind(&end); |
| 3422 | } else { |
| 3423 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3424 | |
| 3425 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3426 | |
| 3427 | CpuRegister rax = eax; |
| 3428 | CpuRegister rdx = edx; |
| 3429 | |
| 3430 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3431 | |
| 3432 | // Save the numerator. |
| 3433 | __ movq(numerator, rax); |
| 3434 | |
| 3435 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3436 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3437 | |
| 3438 | // RDX:RAX = magic * numerator |
| 3439 | __ imulq(numerator); |
| 3440 | |
| 3441 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3442 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3443 | __ addq(rdx, numerator); |
| 3444 | } else if (imm < 0 && magic > 0) { |
| 3445 | // RDX -= numerator |
| 3446 | __ subq(rdx, numerator); |
| 3447 | } |
| 3448 | |
| 3449 | // Shift if needed. |
| 3450 | if (shift != 0) { |
| 3451 | __ sarq(rdx, Immediate(shift)); |
| 3452 | } |
| 3453 | |
| 3454 | // RDX += 1 if RDX < 0 |
| 3455 | __ movq(rax, rdx); |
| 3456 | __ shrq(rdx, Immediate(63)); |
| 3457 | __ addq(rdx, rax); |
| 3458 | |
| 3459 | if (instruction->IsRem()) { |
| 3460 | __ movq(rax, numerator); |
| 3461 | |
| 3462 | if (IsInt<32>(imm)) { |
| 3463 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3464 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3465 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3466 | } |
| 3467 | |
| 3468 | __ subq(rax, rdx); |
| 3469 | __ movq(rdx, rax); |
| 3470 | } else { |
| 3471 | __ movq(rax, rdx); |
| 3472 | } |
| 3473 | } |
| 3474 | } |
| 3475 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3476 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3477 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3478 | Primitive::Type type = instruction->GetResultType(); |
| 3479 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3480 | |
| 3481 | bool is_div = instruction->IsDiv(); |
| 3482 | LocationSummary* locations = instruction->GetLocations(); |
| 3483 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3484 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3485 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3486 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3487 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3488 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3489 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3490 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3491 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3492 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3493 | if (imm == 0) { |
| 3494 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3495 | } else if (imm == 1 || imm == -1) { |
| 3496 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3497 | } else if (instruction->IsDiv() && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3498 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3499 | } else { |
| 3500 | DCHECK(imm <= -2 || imm >= 2); |
| 3501 | GenerateDivRemWithAnyConstant(instruction); |
| 3502 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3503 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3504 | SlowPathCode* slow_path = |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3505 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
| 3506 | out.AsRegister(), type, is_div); |
| 3507 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3508 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3509 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3510 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3511 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3512 | // so it's safe to just use negl instead of more complex comparisons. |
| 3513 | if (type == Primitive::kPrimInt) { |
| 3514 | __ cmpl(second_reg, Immediate(-1)); |
| 3515 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3516 | // edx:eax <- sign-extended of eax |
| 3517 | __ cdq(); |
| 3518 | // eax = quotient, edx = remainder |
| 3519 | __ idivl(second_reg); |
| 3520 | } else { |
| 3521 | __ cmpq(second_reg, Immediate(-1)); |
| 3522 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3523 | // rdx:rax <- sign-extended of rax |
| 3524 | __ cqo(); |
| 3525 | // rax = quotient, rdx = remainder |
| 3526 | __ idivq(second_reg); |
| 3527 | } |
| 3528 | __ Bind(slow_path->GetExitLabel()); |
| 3529 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3530 | } |
| 3531 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3532 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3533 | LocationSummary* locations = |
| 3534 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3535 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3536 | case Primitive::kPrimInt: |
| 3537 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3538 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3539 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3540 | locations->SetOut(Location::SameAsFirstInput()); |
| 3541 | // Intel uses edx:eax as the dividend. |
| 3542 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3543 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3544 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3545 | // output and request another temp. |
| 3546 | if (div->InputAt(1)->IsConstant()) { |
| 3547 | locations->AddTemp(Location::RequiresRegister()); |
| 3548 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3549 | break; |
| 3550 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3551 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3552 | case Primitive::kPrimFloat: |
| 3553 | case Primitive::kPrimDouble: { |
| 3554 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3555 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3556 | locations->SetOut(Location::SameAsFirstInput()); |
| 3557 | break; |
| 3558 | } |
| 3559 | |
| 3560 | default: |
| 3561 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3562 | } |
| 3563 | } |
| 3564 | |
| 3565 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3566 | LocationSummary* locations = div->GetLocations(); |
| 3567 | Location first = locations->InAt(0); |
| 3568 | Location second = locations->InAt(1); |
| 3569 | DCHECK(first.Equals(locations->Out())); |
| 3570 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3571 | Primitive::Type type = div->GetResultType(); |
| 3572 | switch (type) { |
| 3573 | case Primitive::kPrimInt: |
| 3574 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3575 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3576 | break; |
| 3577 | } |
| 3578 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3579 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3580 | if (second.IsFpuRegister()) { |
| 3581 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3582 | } else if (second.IsConstant()) { |
| 3583 | __ divss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3584 | codegen_->LiteralFloatAddress( |
| 3585 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3586 | } else { |
| 3587 | DCHECK(second.IsStackSlot()); |
| 3588 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3589 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3590 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3591 | break; |
| 3592 | } |
| 3593 | |
| 3594 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3595 | if (second.IsFpuRegister()) { |
| 3596 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3597 | } else if (second.IsConstant()) { |
| 3598 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3599 | codegen_->LiteralDoubleAddress( |
| 3600 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3601 | } else { |
| 3602 | DCHECK(second.IsDoubleStackSlot()); |
| 3603 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3604 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3605 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3606 | break; |
| 3607 | } |
| 3608 | |
| 3609 | default: |
| 3610 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3611 | } |
| 3612 | } |
| 3613 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3614 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3615 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3616 | LocationSummary* locations = |
| 3617 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3618 | |
| 3619 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3620 | case Primitive::kPrimInt: |
| 3621 | case Primitive::kPrimLong: { |
| 3622 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3623 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3624 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3625 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3626 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3627 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3628 | // output and request another temp. |
| 3629 | if (rem->InputAt(1)->IsConstant()) { |
| 3630 | locations->AddTemp(Location::RequiresRegister()); |
| 3631 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3632 | break; |
| 3633 | } |
| 3634 | |
| 3635 | case Primitive::kPrimFloat: |
| 3636 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3637 | locations->SetInAt(0, Location::Any()); |
| 3638 | locations->SetInAt(1, Location::Any()); |
| 3639 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3640 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3641 | break; |
| 3642 | } |
| 3643 | |
| 3644 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3645 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3646 | } |
| 3647 | } |
| 3648 | |
| 3649 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3650 | Primitive::Type type = rem->GetResultType(); |
| 3651 | switch (type) { |
| 3652 | case Primitive::kPrimInt: |
| 3653 | case Primitive::kPrimLong: { |
| 3654 | GenerateDivRemIntegral(rem); |
| 3655 | break; |
| 3656 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3657 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3658 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3659 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3660 | break; |
| 3661 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3662 | default: |
| 3663 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3664 | } |
| 3665 | } |
| 3666 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3667 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3668 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3669 | ? LocationSummary::kCallOnSlowPath |
| 3670 | : LocationSummary::kNoCall; |
| 3671 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3672 | locations->SetInAt(0, Location::Any()); |
| 3673 | if (instruction->HasUses()) { |
| 3674 | locations->SetOut(Location::SameAsFirstInput()); |
| 3675 | } |
| 3676 | } |
| 3677 | |
| 3678 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3679 | SlowPathCode* slow_path = |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3680 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3681 | codegen_->AddSlowPath(slow_path); |
| 3682 | |
| 3683 | LocationSummary* locations = instruction->GetLocations(); |
| 3684 | Location value = locations->InAt(0); |
| 3685 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3686 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3687 | case Primitive::kPrimByte: |
| 3688 | case Primitive::kPrimChar: |
| 3689 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3690 | case Primitive::kPrimInt: { |
| 3691 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3692 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3693 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3694 | } else if (value.IsStackSlot()) { |
| 3695 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3696 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3697 | } else { |
| 3698 | DCHECK(value.IsConstant()) << value; |
| 3699 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3700 | __ jmp(slow_path->GetEntryLabel()); |
| 3701 | } |
| 3702 | } |
| 3703 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3704 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3705 | case Primitive::kPrimLong: { |
| 3706 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3707 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3708 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3709 | } else if (value.IsDoubleStackSlot()) { |
| 3710 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3711 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3712 | } else { |
| 3713 | DCHECK(value.IsConstant()) << value; |
| 3714 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3715 | __ jmp(slow_path->GetEntryLabel()); |
| 3716 | } |
| 3717 | } |
| 3718 | break; |
| 3719 | } |
| 3720 | default: |
| 3721 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3722 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3723 | } |
| 3724 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3725 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3726 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3727 | |
| 3728 | LocationSummary* locations = |
| 3729 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3730 | |
| 3731 | switch (op->GetResultType()) { |
| 3732 | case Primitive::kPrimInt: |
| 3733 | case Primitive::kPrimLong: { |
| 3734 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3735 | // The shift count needs to be in CL. |
| 3736 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3737 | locations->SetOut(Location::SameAsFirstInput()); |
| 3738 | break; |
| 3739 | } |
| 3740 | default: |
| 3741 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3742 | } |
| 3743 | } |
| 3744 | |
| 3745 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3746 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3747 | |
| 3748 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3749 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3750 | Location second = locations->InAt(1); |
| 3751 | |
| 3752 | switch (op->GetResultType()) { |
| 3753 | case Primitive::kPrimInt: { |
| 3754 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3755 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3756 | if (op->IsShl()) { |
| 3757 | __ shll(first_reg, second_reg); |
| 3758 | } else if (op->IsShr()) { |
| 3759 | __ sarl(first_reg, second_reg); |
| 3760 | } else { |
| 3761 | __ shrl(first_reg, second_reg); |
| 3762 | } |
| 3763 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3764 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3765 | if (op->IsShl()) { |
| 3766 | __ shll(first_reg, imm); |
| 3767 | } else if (op->IsShr()) { |
| 3768 | __ sarl(first_reg, imm); |
| 3769 | } else { |
| 3770 | __ shrl(first_reg, imm); |
| 3771 | } |
| 3772 | } |
| 3773 | break; |
| 3774 | } |
| 3775 | case Primitive::kPrimLong: { |
| 3776 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3777 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3778 | if (op->IsShl()) { |
| 3779 | __ shlq(first_reg, second_reg); |
| 3780 | } else if (op->IsShr()) { |
| 3781 | __ sarq(first_reg, second_reg); |
| 3782 | } else { |
| 3783 | __ shrq(first_reg, second_reg); |
| 3784 | } |
| 3785 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3786 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3787 | if (op->IsShl()) { |
| 3788 | __ shlq(first_reg, imm); |
| 3789 | } else if (op->IsShr()) { |
| 3790 | __ sarq(first_reg, imm); |
| 3791 | } else { |
| 3792 | __ shrq(first_reg, imm); |
| 3793 | } |
| 3794 | } |
| 3795 | break; |
| 3796 | } |
| 3797 | default: |
| 3798 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3799 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3800 | } |
| 3801 | } |
| 3802 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3803 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 3804 | LocationSummary* locations = |
| 3805 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3806 | |
| 3807 | switch (ror->GetResultType()) { |
| 3808 | case Primitive::kPrimInt: |
| 3809 | case Primitive::kPrimLong: { |
| 3810 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3811 | // The shift count needs to be in CL (unless it is a constant). |
| 3812 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 3813 | locations->SetOut(Location::SameAsFirstInput()); |
| 3814 | break; |
| 3815 | } |
| 3816 | default: |
| 3817 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3818 | UNREACHABLE(); |
| 3819 | } |
| 3820 | } |
| 3821 | |
| 3822 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 3823 | LocationSummary* locations = ror->GetLocations(); |
| 3824 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3825 | Location second = locations->InAt(1); |
| 3826 | |
| 3827 | switch (ror->GetResultType()) { |
| 3828 | case Primitive::kPrimInt: |
| 3829 | if (second.IsRegister()) { |
| 3830 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3831 | __ rorl(first_reg, second_reg); |
| 3832 | } else { |
| 3833 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
| 3834 | __ rorl(first_reg, imm); |
| 3835 | } |
| 3836 | break; |
| 3837 | case Primitive::kPrimLong: |
| 3838 | if (second.IsRegister()) { |
| 3839 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3840 | __ rorq(first_reg, second_reg); |
| 3841 | } else { |
| 3842 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue); |
| 3843 | __ rorq(first_reg, imm); |
| 3844 | } |
| 3845 | break; |
| 3846 | default: |
| 3847 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3848 | UNREACHABLE(); |
| 3849 | } |
| 3850 | } |
| 3851 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3852 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 3853 | HandleShift(shl); |
| 3854 | } |
| 3855 | |
| 3856 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 3857 | HandleShift(shl); |
| 3858 | } |
| 3859 | |
| 3860 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 3861 | HandleShift(shr); |
| 3862 | } |
| 3863 | |
| 3864 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 3865 | HandleShift(shr); |
| 3866 | } |
| 3867 | |
| 3868 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 3869 | HandleShift(ushr); |
| 3870 | } |
| 3871 | |
| 3872 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 3873 | HandleShift(ushr); |
| 3874 | } |
| 3875 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3876 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3877 | LocationSummary* locations = |
| 3878 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3879 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3880 | if (instruction->IsStringAlloc()) { |
| 3881 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3882 | } else { |
| 3883 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3884 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3885 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3886 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3887 | } |
| 3888 | |
| 3889 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3890 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3891 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3892 | if (instruction->IsStringAlloc()) { |
| 3893 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3894 | CpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
| 3895 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64WordSize); |
| 3896 | __ gs()->movq(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString), /* no_rip */ true)); |
| 3897 | __ call(Address(temp, code_offset.SizeValue())); |
| 3898 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3899 | } else { |
| 3900 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3901 | instruction, |
| 3902 | instruction->GetDexPc(), |
| 3903 | nullptr); |
| 3904 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3905 | DCHECK(!codegen_->IsLeafMethod()); |
| 3906 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3907 | } |
| 3908 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3909 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 3910 | LocationSummary* locations = |
| 3911 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3912 | InvokeRuntimeCallingConvention calling_convention; |
| 3913 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3914 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3915 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3916 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3917 | } |
| 3918 | |
| 3919 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 3920 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3921 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3922 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3923 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3924 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3925 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3926 | instruction, |
| 3927 | instruction->GetDexPc(), |
| 3928 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3929 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3930 | |
| 3931 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3932 | } |
| 3933 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3934 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3935 | LocationSummary* locations = |
| 3936 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3937 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3938 | if (location.IsStackSlot()) { |
| 3939 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3940 | } else if (location.IsDoubleStackSlot()) { |
| 3941 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3942 | } |
| 3943 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3944 | } |
| 3945 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3946 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 3947 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3948 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3949 | } |
| 3950 | |
| 3951 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3952 | LocationSummary* locations = |
| 3953 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3954 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3955 | } |
| 3956 | |
| 3957 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 3958 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3959 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3960 | } |
| 3961 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3962 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3963 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3964 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3965 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3966 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3967 | } |
| 3968 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3969 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 3970 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3971 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3972 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3973 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3974 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3975 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3976 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3977 | break; |
| 3978 | |
| 3979 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3980 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3981 | break; |
| 3982 | |
| 3983 | default: |
| 3984 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3985 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3986 | } |
| 3987 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3988 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3989 | LocationSummary* locations = |
| 3990 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3991 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3992 | locations->SetOut(Location::SameAsFirstInput()); |
| 3993 | } |
| 3994 | |
| 3995 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3996 | LocationSummary* locations = bool_not->GetLocations(); |
| 3997 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3998 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 3999 | Location out = locations->Out(); |
| 4000 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4001 | } |
| 4002 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4003 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4004 | LocationSummary* locations = |
| 4005 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4006 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 4007 | locations->SetInAt(i, Location::Any()); |
| 4008 | } |
| 4009 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4010 | } |
| 4011 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4012 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4013 | LOG(FATAL) << "Unimplemented"; |
| 4014 | } |
| 4015 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4016 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4017 | /* |
| 4018 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4019 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86-64 memory model. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4020 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4021 | */ |
| 4022 | switch (kind) { |
| 4023 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4024 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4025 | break; |
| 4026 | } |
| 4027 | case MemBarrierKind::kAnyStore: |
| 4028 | case MemBarrierKind::kLoadAny: |
| 4029 | case MemBarrierKind::kStoreStore: { |
| 4030 | // nop |
| 4031 | break; |
| 4032 | } |
| 4033 | default: |
| 4034 | LOG(FATAL) << "Unexpected memory barier " << kind; |
| 4035 | } |
| 4036 | } |
| 4037 | |
| 4038 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4039 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4040 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4041 | bool object_field_get_with_read_barrier = |
| 4042 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4043 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4044 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4045 | object_field_get_with_read_barrier ? |
| 4046 | LocationSummary::kCallOnSlowPath : |
| 4047 | LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4048 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4049 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4050 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4051 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4052 | // The output overlaps for an object field get when read barriers |
| 4053 | // are enabled: we do not want the move to overwrite the object's |
| 4054 | // location, as we need it to emit the read barrier. |
| 4055 | locations->SetOut( |
| 4056 | Location::RequiresRegister(), |
| 4057 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4058 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4059 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4060 | // We need a temporary register for the read barrier marking slow |
| 4061 | // path in CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier. |
| 4062 | locations->AddTemp(Location::RequiresRegister()); |
| 4063 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4064 | } |
| 4065 | |
| 4066 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4067 | const FieldInfo& field_info) { |
| 4068 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4069 | |
| 4070 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4071 | Location base_loc = locations->InAt(0); |
| 4072 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4073 | Location out = locations->Out(); |
| 4074 | bool is_volatile = field_info.IsVolatile(); |
| 4075 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4076 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4077 | |
| 4078 | switch (field_type) { |
| 4079 | case Primitive::kPrimBoolean: { |
| 4080 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4081 | break; |
| 4082 | } |
| 4083 | |
| 4084 | case Primitive::kPrimByte: { |
| 4085 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4086 | break; |
| 4087 | } |
| 4088 | |
| 4089 | case Primitive::kPrimShort: { |
| 4090 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4091 | break; |
| 4092 | } |
| 4093 | |
| 4094 | case Primitive::kPrimChar: { |
| 4095 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4096 | break; |
| 4097 | } |
| 4098 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4099 | case Primitive::kPrimInt: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4100 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4101 | break; |
| 4102 | } |
| 4103 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4104 | case Primitive::kPrimNot: { |
| 4105 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4106 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4107 | Location temp_loc = locations->GetTemp(0); |
| 4108 | // Note that a potential implicit null check is handled in this |
| 4109 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4110 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4111 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4112 | if (is_volatile) { |
| 4113 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4114 | } |
| 4115 | } else { |
| 4116 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4117 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4118 | if (is_volatile) { |
| 4119 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4120 | } |
| 4121 | // If read barriers are enabled, emit read barriers other than |
| 4122 | // Baker's using a slow path (and also unpoison the loaded |
| 4123 | // reference, if heap poisoning is enabled). |
| 4124 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4125 | } |
| 4126 | break; |
| 4127 | } |
| 4128 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4129 | case Primitive::kPrimLong: { |
| 4130 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4131 | break; |
| 4132 | } |
| 4133 | |
| 4134 | case Primitive::kPrimFloat: { |
| 4135 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4136 | break; |
| 4137 | } |
| 4138 | |
| 4139 | case Primitive::kPrimDouble: { |
| 4140 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4141 | break; |
| 4142 | } |
| 4143 | |
| 4144 | case Primitive::kPrimVoid: |
| 4145 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4146 | UNREACHABLE(); |
| 4147 | } |
| 4148 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4149 | if (field_type == Primitive::kPrimNot) { |
| 4150 | // Potential implicit null checks, in the case of reference |
| 4151 | // fields, are handled in the previous switch statement. |
| 4152 | } else { |
| 4153 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4154 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4155 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4156 | if (is_volatile) { |
| 4157 | if (field_type == Primitive::kPrimNot) { |
| 4158 | // Memory barriers, in the case of references, are also handled |
| 4159 | // in the previous switch statement. |
| 4160 | } else { |
| 4161 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4162 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4163 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4164 | } |
| 4165 | |
| 4166 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4167 | const FieldInfo& field_info) { |
| 4168 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4169 | |
| 4170 | LocationSummary* locations = |
| 4171 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4172 | Primitive::Type field_type = field_info.GetFieldType(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4173 | bool is_volatile = field_info.IsVolatile(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4174 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4175 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4176 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4177 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4178 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4179 | if (is_volatile) { |
| 4180 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4181 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4182 | } else { |
| 4183 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4184 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4185 | } else { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4186 | if (is_volatile) { |
| 4187 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4188 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4189 | } else { |
| 4190 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4191 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4192 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4193 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4194 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4195 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4196 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4197 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4198 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4199 | locations->AddTemp(Location::RequiresRegister()); |
| 4200 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4201 | } |
| 4202 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4203 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4204 | const FieldInfo& field_info, |
| 4205 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4206 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4207 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4208 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4209 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4210 | Location value = locations->InAt(1); |
| 4211 | bool is_volatile = field_info.IsVolatile(); |
| 4212 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4213 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4214 | |
| 4215 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4216 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4217 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4218 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4219 | bool maybe_record_implicit_null_check_done = false; |
| 4220 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4221 | switch (field_type) { |
| 4222 | case Primitive::kPrimBoolean: |
| 4223 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4224 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4225 | int8_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4226 | __ movb(Address(base, offset), Immediate(v)); |
| 4227 | } else { |
| 4228 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4229 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4230 | break; |
| 4231 | } |
| 4232 | |
| 4233 | case Primitive::kPrimShort: |
| 4234 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4235 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4236 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4237 | __ movw(Address(base, offset), Immediate(v)); |
| 4238 | } else { |
| 4239 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4240 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4241 | break; |
| 4242 | } |
| 4243 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4244 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4245 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4246 | if (value.IsConstant()) { |
| 4247 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4248 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 4249 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 4250 | // Note: if heap poisoning is enabled, no need to poison |
| 4251 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4252 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4253 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4254 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4255 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4256 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4257 | __ PoisonHeapReference(temp); |
| 4258 | __ movl(Address(base, offset), temp); |
| 4259 | } else { |
| 4260 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4261 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4262 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4263 | break; |
| 4264 | } |
| 4265 | |
| 4266 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4267 | if (value.IsConstant()) { |
| 4268 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4269 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4270 | Address(base, offset + sizeof(int32_t)), |
| 4271 | v, |
| 4272 | instruction); |
| 4273 | maybe_record_implicit_null_check_done = true; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4274 | } else { |
| 4275 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4276 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4277 | break; |
| 4278 | } |
| 4279 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4280 | case Primitive::kPrimFloat: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4281 | if (value.IsConstant()) { |
| 4282 | int32_t v = |
| 4283 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4284 | __ movl(Address(base, offset), Immediate(v)); |
| 4285 | } else { |
| 4286 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4287 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4288 | break; |
| 4289 | } |
| 4290 | |
| 4291 | case Primitive::kPrimDouble: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4292 | if (value.IsConstant()) { |
| 4293 | int64_t v = |
| 4294 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4295 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4296 | Address(base, offset + sizeof(int32_t)), |
| 4297 | v, |
| 4298 | instruction); |
| 4299 | maybe_record_implicit_null_check_done = true; |
| 4300 | } else { |
| 4301 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4302 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4303 | break; |
| 4304 | } |
| 4305 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4306 | case Primitive::kPrimVoid: |
| 4307 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4308 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4309 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4310 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4311 | if (!maybe_record_implicit_null_check_done) { |
| 4312 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4313 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4314 | |
| 4315 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4316 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4317 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4318 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4319 | } |
| 4320 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4321 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4322 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4323 | } |
| 4324 | } |
| 4325 | |
| 4326 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4327 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4328 | } |
| 4329 | |
| 4330 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4331 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4332 | } |
| 4333 | |
| 4334 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4335 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4336 | } |
| 4337 | |
| 4338 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4339 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4340 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4341 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4342 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4343 | HandleFieldGet(instruction); |
| 4344 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4345 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4346 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4347 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4348 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4349 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4350 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4351 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4352 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4353 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4354 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4355 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4356 | } |
| 4357 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4358 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4359 | HUnresolvedInstanceFieldGet* instruction) { |
| 4360 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4361 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4362 | instruction, instruction->GetFieldType(), calling_convention); |
| 4363 | } |
| 4364 | |
| 4365 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4366 | HUnresolvedInstanceFieldGet* instruction) { |
| 4367 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4368 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4369 | instruction->GetFieldType(), |
| 4370 | instruction->GetFieldIndex(), |
| 4371 | instruction->GetDexPc(), |
| 4372 | calling_convention); |
| 4373 | } |
| 4374 | |
| 4375 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4376 | HUnresolvedInstanceFieldSet* instruction) { |
| 4377 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4378 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4379 | instruction, instruction->GetFieldType(), calling_convention); |
| 4380 | } |
| 4381 | |
| 4382 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4383 | HUnresolvedInstanceFieldSet* instruction) { |
| 4384 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4385 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4386 | instruction->GetFieldType(), |
| 4387 | instruction->GetFieldIndex(), |
| 4388 | instruction->GetDexPc(), |
| 4389 | calling_convention); |
| 4390 | } |
| 4391 | |
| 4392 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4393 | HUnresolvedStaticFieldGet* instruction) { |
| 4394 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4395 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4396 | instruction, instruction->GetFieldType(), calling_convention); |
| 4397 | } |
| 4398 | |
| 4399 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4400 | HUnresolvedStaticFieldGet* instruction) { |
| 4401 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4402 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4403 | instruction->GetFieldType(), |
| 4404 | instruction->GetFieldIndex(), |
| 4405 | instruction->GetDexPc(), |
| 4406 | calling_convention); |
| 4407 | } |
| 4408 | |
| 4409 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4410 | HUnresolvedStaticFieldSet* instruction) { |
| 4411 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4412 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4413 | instruction, instruction->GetFieldType(), calling_convention); |
| 4414 | } |
| 4415 | |
| 4416 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4417 | HUnresolvedStaticFieldSet* instruction) { |
| 4418 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4419 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4420 | instruction->GetFieldType(), |
| 4421 | instruction->GetFieldIndex(), |
| 4422 | instruction->GetDexPc(), |
| 4423 | calling_convention); |
| 4424 | } |
| 4425 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4426 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4427 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4428 | ? LocationSummary::kCallOnSlowPath |
| 4429 | : LocationSummary::kNoCall; |
| 4430 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4431 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4432 | ? Location::RequiresRegister() |
| 4433 | : Location::Any(); |
| 4434 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4435 | if (instruction->HasUses()) { |
| 4436 | locations->SetOut(Location::SameAsFirstInput()); |
| 4437 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4438 | } |
| 4439 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4440 | void InstructionCodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4441 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4442 | return; |
| 4443 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4444 | LocationSummary* locations = instruction->GetLocations(); |
| 4445 | Location obj = locations->InAt(0); |
| 4446 | |
| 4447 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
| 4448 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4449 | } |
| 4450 | |
| 4451 | void InstructionCodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4452 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4453 | codegen_->AddSlowPath(slow_path); |
| 4454 | |
| 4455 | LocationSummary* locations = instruction->GetLocations(); |
| 4456 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4457 | |
| 4458 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4459 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4460 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4461 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4462 | } else { |
| 4463 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4464 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4465 | __ jmp(slow_path->GetEntryLabel()); |
| 4466 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4467 | } |
| 4468 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4469 | } |
| 4470 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4471 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4472 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4473 | GenerateImplicitNullCheck(instruction); |
| 4474 | } else { |
| 4475 | GenerateExplicitNullCheck(instruction); |
| 4476 | } |
| 4477 | } |
| 4478 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4479 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4480 | bool object_array_get_with_read_barrier = |
| 4481 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4482 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4483 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4484 | object_array_get_with_read_barrier ? |
| 4485 | LocationSummary::kCallOnSlowPath : |
| 4486 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4487 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4488 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4489 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4490 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4491 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4492 | // The output overlaps for an object array get when read barriers |
| 4493 | // are enabled: we do not want the move to overwrite the array's |
| 4494 | // location, as we need it to emit the read barrier. |
| 4495 | locations->SetOut( |
| 4496 | Location::RequiresRegister(), |
| 4497 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4498 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4499 | // We need a temporary register for the read barrier marking slow |
| 4500 | // path in CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier. |
| 4501 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4502 | locations->AddTemp(Location::RequiresRegister()); |
| 4503 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4504 | } |
| 4505 | |
| 4506 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4507 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4508 | Location obj_loc = locations->InAt(0); |
| 4509 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4510 | Location index = locations->InAt(1); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4511 | Location out_loc = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4512 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4513 | Primitive::Type type = instruction->GetType(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4514 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4515 | case Primitive::kPrimBoolean: { |
| 4516 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4517 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4518 | if (index.IsConstant()) { |
| 4519 | __ movzxb(out, Address(obj, |
| 4520 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4521 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4522 | __ movzxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4523 | } |
| 4524 | break; |
| 4525 | } |
| 4526 | |
| 4527 | case Primitive::kPrimByte: { |
| 4528 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4529 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4530 | if (index.IsConstant()) { |
| 4531 | __ movsxb(out, Address(obj, |
| 4532 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4533 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4534 | __ movsxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4535 | } |
| 4536 | break; |
| 4537 | } |
| 4538 | |
| 4539 | case Primitive::kPrimShort: { |
| 4540 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4541 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4542 | if (index.IsConstant()) { |
| 4543 | __ movsxw(out, Address(obj, |
| 4544 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4545 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4546 | __ movsxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4547 | } |
| 4548 | break; |
| 4549 | } |
| 4550 | |
| 4551 | case Primitive::kPrimChar: { |
| 4552 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4553 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4554 | if (index.IsConstant()) { |
| 4555 | __ movzxw(out, Address(obj, |
| 4556 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4557 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4558 | __ movzxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4559 | } |
| 4560 | break; |
| 4561 | } |
| 4562 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4563 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4564 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4565 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4566 | if (index.IsConstant()) { |
| 4567 | __ movl(out, Address(obj, |
| 4568 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4569 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4570 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4571 | } |
| 4572 | break; |
| 4573 | } |
| 4574 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4575 | case Primitive::kPrimNot: { |
| 4576 | static_assert( |
| 4577 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4578 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 4579 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4580 | // /* HeapReference<Object> */ out = |
| 4581 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4582 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4583 | Location temp = locations->GetTemp(0); |
| 4584 | // Note that a potential implicit null check is handled in this |
| 4585 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 4586 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4587 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4588 | } else { |
| 4589 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| 4590 | if (index.IsConstant()) { |
| 4591 | uint32_t offset = |
| 4592 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4593 | __ movl(out, Address(obj, offset)); |
| 4594 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4595 | // If read barriers are enabled, emit read barriers other than |
| 4596 | // Baker's using a slow path (and also unpoison the loaded |
| 4597 | // reference, if heap poisoning is enabled). |
| 4598 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4599 | } else { |
| 4600 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
| 4601 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4602 | // If read barriers are enabled, emit read barriers other than |
| 4603 | // Baker's using a slow path (and also unpoison the loaded |
| 4604 | // reference, if heap poisoning is enabled). |
| 4605 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4606 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4607 | } |
| 4608 | } |
| 4609 | break; |
| 4610 | } |
| 4611 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4612 | case Primitive::kPrimLong: { |
| 4613 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4614 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4615 | if (index.IsConstant()) { |
| 4616 | __ movq(out, Address(obj, |
| 4617 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4618 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4619 | __ movq(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4620 | } |
| 4621 | break; |
| 4622 | } |
| 4623 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4624 | case Primitive::kPrimFloat: { |
| 4625 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4626 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4627 | if (index.IsConstant()) { |
| 4628 | __ movss(out, Address(obj, |
| 4629 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4630 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4631 | __ movss(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4632 | } |
| 4633 | break; |
| 4634 | } |
| 4635 | |
| 4636 | case Primitive::kPrimDouble: { |
| 4637 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4638 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4639 | if (index.IsConstant()) { |
| 4640 | __ movsd(out, Address(obj, |
| 4641 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4642 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4643 | __ movsd(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4644 | } |
| 4645 | break; |
| 4646 | } |
| 4647 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4648 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4649 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4650 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4651 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4652 | |
| 4653 | if (type == Primitive::kPrimNot) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4654 | // Potential implicit null checks, in the case of reference |
| 4655 | // arrays, are handled in the previous switch statement. |
| 4656 | } else { |
| 4657 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4658 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4659 | } |
| 4660 | |
| 4661 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4662 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4663 | |
| 4664 | bool needs_write_barrier = |
| 4665 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4666 | bool may_need_runtime_call = instruction->NeedsTypeCheck(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4667 | bool object_array_set_with_read_barrier = |
| 4668 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4669 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4670 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4671 | instruction, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4672 | (may_need_runtime_call || object_array_set_with_read_barrier) ? |
| 4673 | LocationSummary::kCallOnSlowPath : |
| 4674 | LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4675 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4676 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4677 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4678 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4679 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4680 | } else { |
| 4681 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4682 | } |
| 4683 | |
| 4684 | if (needs_write_barrier) { |
| 4685 | // Temporary registers for the write barrier. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4686 | |
| 4687 | // This first temporary register is possibly used for heap |
| 4688 | // reference poisoning and/or read barrier emission too. |
| 4689 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4690 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4691 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4692 | } |
| 4693 | |
| 4694 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4695 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4696 | Location array_loc = locations->InAt(0); |
| 4697 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4698 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4699 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4700 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4701 | bool may_need_runtime_call = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4702 | bool needs_write_barrier = |
| 4703 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4704 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4705 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4706 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4707 | |
| 4708 | switch (value_type) { |
| 4709 | case Primitive::kPrimBoolean: |
| 4710 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4711 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 4712 | Address address = index.IsConstant() |
| 4713 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 4714 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_1, offset); |
| 4715 | if (value.IsRegister()) { |
| 4716 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4717 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4718 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4719 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4720 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4721 | break; |
| 4722 | } |
| 4723 | |
| 4724 | case Primitive::kPrimShort: |
| 4725 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4726 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 4727 | Address address = index.IsConstant() |
| 4728 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 4729 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_2, offset); |
| 4730 | if (value.IsRegister()) { |
| 4731 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4732 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4733 | DCHECK(value.IsConstant()) << value; |
| 4734 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4735 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4736 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4737 | break; |
| 4738 | } |
| 4739 | |
| 4740 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4741 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4742 | Address address = index.IsConstant() |
| 4743 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4744 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4745 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4746 | if (!value.IsRegister()) { |
| 4747 | // Just setting null. |
| 4748 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4749 | DCHECK(value.IsConstant()) << value; |
| 4750 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4751 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4752 | DCHECK(!needs_write_barrier); |
| 4753 | DCHECK(!may_need_runtime_call); |
| 4754 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4755 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4756 | |
| 4757 | DCHECK(needs_write_barrier); |
| 4758 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
| 4759 | NearLabel done, not_null, do_put; |
| 4760 | SlowPathCode* slow_path = nullptr; |
| 4761 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4762 | if (may_need_runtime_call) { |
| 4763 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86_64(instruction); |
| 4764 | codegen_->AddSlowPath(slow_path); |
| 4765 | if (instruction->GetValueCanBeNull()) { |
| 4766 | __ testl(register_value, register_value); |
| 4767 | __ j(kNotEqual, ¬_null); |
| 4768 | __ movl(address, Immediate(0)); |
| 4769 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4770 | __ jmp(&done); |
| 4771 | __ Bind(¬_null); |
| 4772 | } |
| 4773 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4774 | if (kEmitCompilerReadBarrier) { |
| 4775 | // When read barriers are enabled, the type checking |
| 4776 | // instrumentation requires two read barriers: |
| 4777 | // |
| 4778 | // __ movl(temp2, temp); |
| 4779 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4780 | // __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4781 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4782 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 4783 | // |
| 4784 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 4785 | // __ movl(temp2, Address(register_value, class_offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4786 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4787 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 4788 | // |
| 4789 | // __ cmpl(temp, temp2); |
| 4790 | // |
| 4791 | // However, the second read barrier may trash `temp`, as it |
| 4792 | // is a temporary register, and as such would not be saved |
| 4793 | // along with live registers before calling the runtime (nor |
| 4794 | // restored afterwards). So in this case, we bail out and |
| 4795 | // delegate the work to the array set slow path. |
| 4796 | // |
| 4797 | // TODO: Extend the register allocator to support a new |
| 4798 | // "(locally) live temp" location so as to avoid always |
| 4799 | // going into the slow path when read barriers are enabled. |
| 4800 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4801 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4802 | // /* HeapReference<Class> */ temp = array->klass_ |
| 4803 | __ movl(temp, Address(array, class_offset)); |
| 4804 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4805 | __ MaybeUnpoisonHeapReference(temp); |
| 4806 | |
| 4807 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4808 | __ movl(temp, Address(temp, component_offset)); |
| 4809 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 4810 | // nor the object reference in `register_value->klass`, as |
| 4811 | // we are comparing two poisoned references. |
| 4812 | __ cmpl(temp, Address(register_value, class_offset)); |
| 4813 | |
| 4814 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4815 | __ j(kEqual, &do_put); |
| 4816 | // If heap poisoning is enabled, the `temp` reference has |
| 4817 | // not been unpoisoned yet; unpoison it now. |
| 4818 | __ MaybeUnpoisonHeapReference(temp); |
| 4819 | |
| 4820 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 4821 | __ movl(temp, Address(temp, super_offset)); |
| 4822 | // If heap poisoning is enabled, no need to unpoison |
| 4823 | // `temp`, as we are comparing against null below. |
| 4824 | __ testl(temp, temp); |
| 4825 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4826 | __ Bind(&do_put); |
| 4827 | } else { |
| 4828 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4829 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4830 | } |
| 4831 | } |
| 4832 | |
| 4833 | if (kPoisonHeapReferences) { |
| 4834 | __ movl(temp, register_value); |
| 4835 | __ PoisonHeapReference(temp); |
| 4836 | __ movl(address, temp); |
| 4837 | } else { |
| 4838 | __ movl(address, register_value); |
| 4839 | } |
| 4840 | if (!may_need_runtime_call) { |
| 4841 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4842 | } |
| 4843 | |
| 4844 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4845 | codegen_->MarkGCCard( |
| 4846 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4847 | __ Bind(&done); |
| 4848 | |
| 4849 | if (slow_path != nullptr) { |
| 4850 | __ Bind(slow_path->GetExitLabel()); |
| 4851 | } |
| 4852 | |
| 4853 | break; |
| 4854 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4855 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4856 | case Primitive::kPrimInt: { |
| 4857 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4858 | Address address = index.IsConstant() |
| 4859 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4860 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
| 4861 | if (value.IsRegister()) { |
| 4862 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 4863 | } else { |
| 4864 | DCHECK(value.IsConstant()) << value; |
| 4865 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4866 | __ movl(address, Immediate(v)); |
| 4867 | } |
| 4868 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4869 | break; |
| 4870 | } |
| 4871 | |
| 4872 | case Primitive::kPrimLong: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4873 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 4874 | Address address = index.IsConstant() |
| 4875 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4876 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
| 4877 | if (value.IsRegister()) { |
| 4878 | __ movq(address, value.AsRegister<CpuRegister>()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4879 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4880 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4881 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4882 | Address address_high = index.IsConstant() |
| 4883 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 4884 | offset + sizeof(int32_t)) |
| 4885 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset + sizeof(int32_t)); |
| 4886 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4887 | } |
| 4888 | break; |
| 4889 | } |
| 4890 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4891 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4892 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4893 | Address address = index.IsConstant() |
| 4894 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4895 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4896 | if (value.IsFpuRegister()) { |
| 4897 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 4898 | } else { |
| 4899 | DCHECK(value.IsConstant()); |
| 4900 | int32_t v = |
| 4901 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4902 | __ movl(address, Immediate(v)); |
| 4903 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4904 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4905 | break; |
| 4906 | } |
| 4907 | |
| 4908 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4909 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4910 | Address address = index.IsConstant() |
| 4911 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4912 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4913 | if (value.IsFpuRegister()) { |
| 4914 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 4915 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4916 | } else { |
| 4917 | int64_t v = |
| 4918 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4919 | Address address_high = index.IsConstant() |
| 4920 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 4921 | offset + sizeof(int32_t)) |
| 4922 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset + sizeof(int32_t)); |
| 4923 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 4924 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4925 | break; |
| 4926 | } |
| 4927 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4928 | case Primitive::kPrimVoid: |
| 4929 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4930 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4931 | } |
| 4932 | } |
| 4933 | |
| 4934 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4935 | LocationSummary* locations = |
| 4936 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4937 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4938 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4939 | } |
| 4940 | |
| 4941 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 4942 | LocationSummary* locations = instruction->GetLocations(); |
| 4943 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4944 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4945 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4946 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4947 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4948 | } |
| 4949 | |
| 4950 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4951 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4952 | ? LocationSummary::kCallOnSlowPath |
| 4953 | : LocationSummary::kNoCall; |
| 4954 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4955 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4956 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4957 | if (instruction->HasUses()) { |
| 4958 | locations->SetOut(Location::SameAsFirstInput()); |
| 4959 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4960 | } |
| 4961 | |
| 4962 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4963 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4964 | Location index_loc = locations->InAt(0); |
| 4965 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4966 | SlowPathCode* slow_path = |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4967 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4968 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4969 | if (length_loc.IsConstant()) { |
| 4970 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4971 | if (index_loc.IsConstant()) { |
| 4972 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4973 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4974 | if (index < 0 || index >= length) { |
| 4975 | codegen_->AddSlowPath(slow_path); |
| 4976 | __ jmp(slow_path->GetEntryLabel()); |
| 4977 | } else { |
| 4978 | // Some optimization after BCE may have generated this, and we should not |
| 4979 | // generate a bounds check if it is a valid range. |
| 4980 | } |
| 4981 | return; |
| 4982 | } |
| 4983 | |
| 4984 | // We have to reverse the jump condition because the length is the constant. |
| 4985 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 4986 | __ cmpl(index_reg, Immediate(length)); |
| 4987 | codegen_->AddSlowPath(slow_path); |
| 4988 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4989 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4990 | CpuRegister length = length_loc.AsRegister<CpuRegister>(); |
| 4991 | if (index_loc.IsConstant()) { |
| 4992 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4993 | __ cmpl(length, Immediate(value)); |
| 4994 | } else { |
| 4995 | __ cmpl(length, index_loc.AsRegister<CpuRegister>()); |
| 4996 | } |
| 4997 | codegen_->AddSlowPath(slow_path); |
| 4998 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4999 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5000 | } |
| 5001 | |
| 5002 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5003 | CpuRegister card, |
| 5004 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5005 | CpuRegister value, |
| 5006 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5007 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5008 | if (value_can_be_null) { |
| 5009 | __ testl(value, value); |
| 5010 | __ j(kEqual, &is_null); |
| 5011 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5012 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), |
| 5013 | /* no_rip */ true)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5014 | __ movq(temp, object); |
| 5015 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5016 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5017 | if (value_can_be_null) { |
| 5018 | __ Bind(&is_null); |
| 5019 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5020 | } |
| 5021 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5022 | void LocationsBuilderX86_64::VisitTemporary(HTemporary* temp) { |
| 5023 | temp->SetLocations(nullptr); |
| 5024 | } |
| 5025 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5026 | void InstructionCodeGeneratorX86_64::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5027 | // Nothing to do, this is driven by the code generator. |
| 5028 | } |
| 5029 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5030 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5031 | LOG(FATAL) << "Unimplemented"; |
| 5032 | } |
| 5033 | |
| 5034 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5035 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5036 | } |
| 5037 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5038 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5039 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5040 | } |
| 5041 | |
| 5042 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5043 | HBasicBlock* block = instruction->GetBlock(); |
| 5044 | if (block->GetLoopInformation() != nullptr) { |
| 5045 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5046 | // The back edge will generate the suspend check. |
| 5047 | return; |
| 5048 | } |
| 5049 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5050 | // The goto will generate the suspend check. |
| 5051 | return; |
| 5052 | } |
| 5053 | GenerateSuspendCheck(instruction, nullptr); |
| 5054 | } |
| 5055 | |
| 5056 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5057 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5058 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5059 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5060 | if (slow_path == nullptr) { |
| 5061 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 5062 | instruction->SetSlowPath(slow_path); |
| 5063 | codegen_->AddSlowPath(slow_path); |
| 5064 | if (successor != nullptr) { |
| 5065 | DCHECK(successor->IsLoopHeader()); |
| 5066 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5067 | } |
| 5068 | } else { |
| 5069 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5070 | } |
| 5071 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5072 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), |
| 5073 | /* no_rip */ true), |
| 5074 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5075 | if (successor == nullptr) { |
| 5076 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5077 | __ Bind(slow_path->GetReturnLabel()); |
| 5078 | } else { |
| 5079 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5080 | __ jmp(slow_path->GetEntryLabel()); |
| 5081 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5082 | } |
| 5083 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5084 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5085 | return codegen_->GetAssembler(); |
| 5086 | } |
| 5087 | |
| 5088 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5089 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5090 | Location source = move->GetSource(); |
| 5091 | Location destination = move->GetDestination(); |
| 5092 | |
| 5093 | if (source.IsRegister()) { |
| 5094 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5095 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5096 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5097 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5098 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5099 | } else { |
| 5100 | DCHECK(destination.IsDoubleStackSlot()); |
| 5101 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5102 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5103 | } |
| 5104 | } else if (source.IsStackSlot()) { |
| 5105 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5106 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5107 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5108 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5109 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5110 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5111 | } else { |
| 5112 | DCHECK(destination.IsStackSlot()); |
| 5113 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5114 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5115 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5116 | } else if (source.IsDoubleStackSlot()) { |
| 5117 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5118 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5119 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5120 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5121 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5122 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5123 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5124 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5125 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5126 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5127 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5128 | } else if (source.IsConstant()) { |
| 5129 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5130 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5131 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5132 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5133 | if (value == 0) { |
| 5134 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5135 | } else { |
| 5136 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5137 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5138 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5139 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5140 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5141 | } |
| 5142 | } else if (constant->IsLongConstant()) { |
| 5143 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5144 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5145 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5146 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5147 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5148 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5149 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5150 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5151 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5152 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5153 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5154 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5155 | if (value == 0) { |
| 5156 | // easy FP 0.0. |
| 5157 | __ xorps(dest, dest); |
| 5158 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5159 | __ movss(dest, codegen_->LiteralFloatAddress(fp_value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5160 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5161 | } else { |
| 5162 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5163 | Immediate imm(value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5164 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5165 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5166 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5167 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5168 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5169 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5170 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5171 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5172 | if (value == 0) { |
| 5173 | __ xorpd(dest, dest); |
| 5174 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5175 | __ movsd(dest, codegen_->LiteralDoubleAddress(fp_value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5176 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5177 | } else { |
| 5178 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5179 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5180 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5181 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5182 | } else if (source.IsFpuRegister()) { |
| 5183 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5184 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5185 | } else if (destination.IsStackSlot()) { |
| 5186 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5187 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5188 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 5189 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5190 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5191 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5192 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5193 | } |
| 5194 | } |
| 5195 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5196 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5197 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5198 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5199 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5200 | } |
| 5201 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5202 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5203 | ScratchRegisterScope ensure_scratch( |
| 5204 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5205 | |
| 5206 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5207 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5208 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5209 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5210 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5211 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5212 | CpuRegister(ensure_scratch.GetRegister())); |
| 5213 | } |
| 5214 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5215 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5216 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5217 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5218 | __ movq(reg, CpuRegister(TMP)); |
| 5219 | } |
| 5220 | |
| 5221 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 5222 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5223 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5224 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5225 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5226 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5227 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5228 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5229 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5230 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5231 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5232 | } |
| 5233 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5234 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5235 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5236 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5237 | __ movd(reg, CpuRegister(TMP)); |
| 5238 | } |
| 5239 | |
| 5240 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5241 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5242 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5243 | __ movd(reg, CpuRegister(TMP)); |
| 5244 | } |
| 5245 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5246 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5247 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5248 | Location source = move->GetSource(); |
| 5249 | Location destination = move->GetDestination(); |
| 5250 | |
| 5251 | if (source.IsRegister() && destination.IsRegister()) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5252 | __ xchgq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5253 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5254 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5255 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5256 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5257 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5258 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5259 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5260 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5261 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5262 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5263 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 5264 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5265 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5266 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5267 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5268 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5269 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5270 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5271 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5272 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5273 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5274 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5275 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5276 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5277 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5278 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5279 | } |
| 5280 | } |
| 5281 | |
| 5282 | |
| 5283 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5284 | __ pushq(CpuRegister(reg)); |
| 5285 | } |
| 5286 | |
| 5287 | |
| 5288 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5289 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5290 | } |
| 5291 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5292 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5293 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5294 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5295 | Immediate(mirror::Class::kStatusInitialized)); |
| 5296 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5297 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5298 | // No need for memory fence, thanks to the x86-64 memory model. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5299 | } |
| 5300 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5301 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5302 | InvokeRuntimeCallingConvention calling_convention; |
| 5303 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5304 | cls, |
| 5305 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5306 | Location::RegisterLocation(RAX), |
| 5307 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5308 | } |
| 5309 | |
| 5310 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5311 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5312 | if (cls->NeedsAccessCheck()) { |
| 5313 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5314 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5315 | cls, |
| 5316 | cls->GetDexPc(), |
| 5317 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5318 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5319 | return; |
| 5320 | } |
| 5321 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5322 | Location out_loc = locations->Out(); |
| 5323 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5324 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5325 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5326 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5327 | DCHECK(!cls->CanCallRuntime()); |
| 5328 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5329 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5330 | GenerateGcRootFieldLoad( |
| 5331 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5332 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5333 | // /* GcRoot<mirror::Class>[] */ out = |
| 5334 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5335 | __ movq(out, Address(current_method, |
| 5336 | ArtMethod::DexCacheResolvedTypesOffset(kX86_64PointerSize).Int32Value())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5337 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5338 | GenerateGcRootFieldLoad(cls, out_loc, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5339 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5340 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5341 | DCHECK(cls->CanCallRuntime()); |
| 5342 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 5343 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5344 | codegen_->AddSlowPath(slow_path); |
| 5345 | if (!cls->IsInDexCache()) { |
| 5346 | __ testl(out, out); |
| 5347 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5348 | } |
| 5349 | if (cls->MustGenerateClinitCheck()) { |
| 5350 | GenerateClassInitializationCheck(slow_path, out); |
| 5351 | } else { |
| 5352 | __ Bind(slow_path->GetExitLabel()); |
| 5353 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5354 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5355 | } |
| 5356 | } |
| 5357 | |
| 5358 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 5359 | LocationSummary* locations = |
| 5360 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5361 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5362 | if (check->HasUses()) { |
| 5363 | locations->SetOut(Location::SameAsFirstInput()); |
| 5364 | } |
| 5365 | } |
| 5366 | |
| 5367 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5368 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5369 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5370 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5371 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5372 | GenerateClassInitializationCheck(slow_path, |
| 5373 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5374 | } |
| 5375 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5376 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5377 | LocationSummary::CallKind call_kind = (!load->IsInDexCache() || kEmitCompilerReadBarrier) |
| 5378 | ? LocationSummary::kCallOnSlowPath |
| 5379 | : LocationSummary::kNoCall; |
| 5380 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5381 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5382 | locations->SetOut(Location::RequiresRegister()); |
| 5383 | } |
| 5384 | |
| 5385 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5386 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5387 | Location out_loc = locations->Out(); |
| 5388 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5389 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5390 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5391 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5392 | GenerateGcRootFieldLoad( |
| 5393 | load, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5394 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
| 5395 | __ movq(out, Address(out, mirror::Class::DexCacheStringsOffset().Uint32Value())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5396 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5397 | GenerateGcRootFieldLoad( |
| 5398 | load, out_loc, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5399 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5400 | if (!load->IsInDexCache()) { |
| 5401 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
| 5402 | codegen_->AddSlowPath(slow_path); |
| 5403 | __ testl(out, out); |
| 5404 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5405 | __ Bind(slow_path->GetExitLabel()); |
| 5406 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5407 | } |
| 5408 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5409 | static Address GetExceptionTlsAddress() { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5410 | return Address::Absolute(Thread::ExceptionOffset<kX86_64WordSize>().Int32Value(), |
| 5411 | /* no_rip */ true); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5412 | } |
| 5413 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5414 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 5415 | LocationSummary* locations = |
| 5416 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5417 | locations->SetOut(Location::RequiresRegister()); |
| 5418 | } |
| 5419 | |
| 5420 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5421 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 5422 | } |
| 5423 | |
| 5424 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 5425 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5426 | } |
| 5427 | |
| 5428 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5429 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5430 | } |
| 5431 | |
| 5432 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 5433 | LocationSummary* locations = |
| 5434 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5435 | InvokeRuntimeCallingConvention calling_convention; |
| 5436 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5437 | } |
| 5438 | |
| 5439 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5440 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 5441 | instruction, |
| 5442 | instruction->GetDexPc(), |
| 5443 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5444 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5445 | } |
| 5446 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5447 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5448 | return kEmitCompilerReadBarrier && |
| 5449 | (kUseBakerReadBarrier || |
| 5450 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5451 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5452 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5453 | } |
| 5454 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5455 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5456 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5457 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5458 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5459 | case TypeCheckKind::kExactCheck: |
| 5460 | case TypeCheckKind::kAbstractClassCheck: |
| 5461 | case TypeCheckKind::kClassHierarchyCheck: |
| 5462 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5463 | call_kind = |
| 5464 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5465 | break; |
| 5466 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5467 | case TypeCheckKind::kUnresolvedCheck: |
| 5468 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5469 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5470 | break; |
| 5471 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5472 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5473 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5474 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5475 | locations->SetInAt(1, Location::Any()); |
| 5476 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 5477 | locations->SetOut(Location::RequiresRegister()); |
| 5478 | // When read barriers are enabled, we need a temporary register for |
| 5479 | // some cases. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5480 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5481 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5482 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5483 | } |
| 5484 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5485 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5486 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5487 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5488 | Location obj_loc = locations->InAt(0); |
| 5489 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5490 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5491 | Location out_loc = locations->Out(); |
| 5492 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5493 | Location temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
| 5494 | locations->GetTemp(0) : |
| 5495 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5496 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5497 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5498 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5499 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5500 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5501 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5502 | |
| 5503 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5504 | // Avoid null check if we know obj is not null. |
| 5505 | if (instruction->MustDoNullCheck()) { |
| 5506 | __ testl(obj, obj); |
| 5507 | __ j(kEqual, &zero); |
| 5508 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5509 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5510 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5511 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5512 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5513 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5514 | case TypeCheckKind::kExactCheck: { |
| 5515 | if (cls.IsRegister()) { |
| 5516 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5517 | } else { |
| 5518 | DCHECK(cls.IsStackSlot()) << cls; |
| 5519 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5520 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5521 | if (zero.IsLinked()) { |
| 5522 | // Classes must be equal for the instanceof to succeed. |
| 5523 | __ j(kNotEqual, &zero); |
| 5524 | __ movl(out, Immediate(1)); |
| 5525 | __ jmp(&done); |
| 5526 | } else { |
| 5527 | __ setcc(kEqual, out); |
| 5528 | // setcc only sets the low byte. |
| 5529 | __ andl(out, Immediate(1)); |
| 5530 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5531 | break; |
| 5532 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5533 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5534 | case TypeCheckKind::kAbstractClassCheck: { |
| 5535 | // If the class is abstract, we eagerly fetch the super class of the |
| 5536 | // object to avoid doing a comparison we know will fail. |
| 5537 | NearLabel loop, success; |
| 5538 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5539 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5540 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5541 | __ testl(out, out); |
| 5542 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5543 | __ j(kEqual, &done); |
| 5544 | if (cls.IsRegister()) { |
| 5545 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5546 | } else { |
| 5547 | DCHECK(cls.IsStackSlot()) << cls; |
| 5548 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5549 | } |
| 5550 | __ j(kNotEqual, &loop); |
| 5551 | __ movl(out, Immediate(1)); |
| 5552 | if (zero.IsLinked()) { |
| 5553 | __ jmp(&done); |
| 5554 | } |
| 5555 | break; |
| 5556 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5557 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5558 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5559 | // Walk over the class hierarchy to find a match. |
| 5560 | NearLabel loop, success; |
| 5561 | __ Bind(&loop); |
| 5562 | if (cls.IsRegister()) { |
| 5563 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5564 | } else { |
| 5565 | DCHECK(cls.IsStackSlot()) << cls; |
| 5566 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5567 | } |
| 5568 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5569 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5570 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5571 | __ testl(out, out); |
| 5572 | __ j(kNotEqual, &loop); |
| 5573 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5574 | __ jmp(&done); |
| 5575 | __ Bind(&success); |
| 5576 | __ movl(out, Immediate(1)); |
| 5577 | if (zero.IsLinked()) { |
| 5578 | __ jmp(&done); |
| 5579 | } |
| 5580 | break; |
| 5581 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5582 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5583 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5584 | // Do an exact check. |
| 5585 | NearLabel exact_check; |
| 5586 | if (cls.IsRegister()) { |
| 5587 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5588 | } else { |
| 5589 | DCHECK(cls.IsStackSlot()) << cls; |
| 5590 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5591 | } |
| 5592 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5593 | // Otherwise, we need to check that the object's class is a non-primitive array. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5594 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5595 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5596 | __ testl(out, out); |
| 5597 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5598 | __ j(kEqual, &done); |
| 5599 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5600 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5601 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5602 | __ movl(out, Immediate(1)); |
| 5603 | __ jmp(&done); |
| 5604 | break; |
| 5605 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5606 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5607 | case TypeCheckKind::kArrayCheck: { |
| 5608 | if (cls.IsRegister()) { |
| 5609 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5610 | } else { |
| 5611 | DCHECK(cls.IsStackSlot()) << cls; |
| 5612 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5613 | } |
| 5614 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5615 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5616 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5617 | codegen_->AddSlowPath(slow_path); |
| 5618 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5619 | __ movl(out, Immediate(1)); |
| 5620 | if (zero.IsLinked()) { |
| 5621 | __ jmp(&done); |
| 5622 | } |
| 5623 | break; |
| 5624 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5625 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5626 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5627 | case TypeCheckKind::kInterfaceCheck: { |
| 5628 | // Note that we indeed only call on slow path, but we always go |
| 5629 | // into the slow path for the unresolved & interface check |
| 5630 | // cases. |
| 5631 | // |
| 5632 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5633 | // entry point without resorting to a type checking slow path |
| 5634 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5635 | // require to assign fixed registers for the inputs of this |
| 5636 | // HInstanceOf instruction (following the runtime calling |
| 5637 | // convention), which might be cluttered by the potential first |
| 5638 | // read barrier emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5639 | // |
| 5640 | // TODO: Introduce a new runtime entry point taking the object |
| 5641 | // to test (instead of its class) as argument, and let it deal |
| 5642 | // with the read barrier issues. This will let us refactor this |
| 5643 | // case of the `switch` code as it was previously (with a direct |
| 5644 | // call to the runtime not using a type checking slow path). |
| 5645 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5646 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5647 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5648 | /* is_fatal */ false); |
| 5649 | codegen_->AddSlowPath(slow_path); |
| 5650 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5651 | if (zero.IsLinked()) { |
| 5652 | __ jmp(&done); |
| 5653 | } |
| 5654 | break; |
| 5655 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5656 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5657 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5658 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5659 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5660 | __ xorl(out, out); |
| 5661 | } |
| 5662 | |
| 5663 | if (done.IsLinked()) { |
| 5664 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5665 | } |
| 5666 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5667 | if (slow_path != nullptr) { |
| 5668 | __ Bind(slow_path->GetExitLabel()); |
| 5669 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5670 | } |
| 5671 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5672 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5673 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5674 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5675 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5676 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5677 | case TypeCheckKind::kExactCheck: |
| 5678 | case TypeCheckKind::kAbstractClassCheck: |
| 5679 | case TypeCheckKind::kClassHierarchyCheck: |
| 5680 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5681 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 5682 | LocationSummary::kCallOnSlowPath : |
| 5683 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5684 | break; |
| 5685 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5686 | case TypeCheckKind::kUnresolvedCheck: |
| 5687 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5688 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5689 | break; |
| 5690 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5691 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5692 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5693 | locations->SetInAt(1, Location::Any()); |
| 5694 | // Note that TypeCheckSlowPathX86_64 uses this "temp" register too. |
| 5695 | locations->AddTemp(Location::RequiresRegister()); |
| 5696 | // When read barriers are enabled, we need an additional temporary |
| 5697 | // register for some cases. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5698 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5699 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5700 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5701 | } |
| 5702 | |
| 5703 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5704 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5705 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5706 | Location obj_loc = locations->InAt(0); |
| 5707 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5708 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5709 | Location temp_loc = locations->GetTemp(0); |
| 5710 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5711 | Location temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
| 5712 | locations->GetTemp(1) : |
| 5713 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5714 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5715 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5716 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5717 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5718 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5719 | bool is_type_check_slow_path_fatal = |
| 5720 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 5721 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5722 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5723 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 5724 | !instruction->CanThrowIntoCatchBlock(); |
| 5725 | SlowPathCode* type_check_slow_path = |
| 5726 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5727 | is_type_check_slow_path_fatal); |
| 5728 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5729 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 5730 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5731 | // Avoid null check if we know obj is not null. |
| 5732 | if (instruction->MustDoNullCheck()) { |
| 5733 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5734 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5735 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5736 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5737 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5738 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5739 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5740 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5741 | case TypeCheckKind::kExactCheck: |
| 5742 | case TypeCheckKind::kArrayCheck: { |
| 5743 | if (cls.IsRegister()) { |
| 5744 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5745 | } else { |
| 5746 | DCHECK(cls.IsStackSlot()) << cls; |
| 5747 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5748 | } |
| 5749 | // Jump to slow path for throwing the exception or doing a |
| 5750 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5751 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5752 | break; |
| 5753 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5754 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5755 | case TypeCheckKind::kAbstractClassCheck: { |
| 5756 | // If the class is abstract, we eagerly fetch the super class of the |
| 5757 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5758 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5759 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5760 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5761 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5762 | |
| 5763 | // If the class reference currently in `temp` is not null, jump |
| 5764 | // to the `compare_classes` label to compare it with the checked |
| 5765 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5766 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5767 | __ j(kNotEqual, &compare_classes); |
| 5768 | // Otherwise, jump to the slow path to throw the exception. |
| 5769 | // |
| 5770 | // But before, move back the object's class into `temp` before |
| 5771 | // going into the slow path, as it has been overwritten in the |
| 5772 | // meantime. |
| 5773 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5774 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5775 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 5776 | |
| 5777 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5778 | if (cls.IsRegister()) { |
| 5779 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5780 | } else { |
| 5781 | DCHECK(cls.IsStackSlot()) << cls; |
| 5782 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5783 | } |
| 5784 | __ j(kNotEqual, &loop); |
| 5785 | break; |
| 5786 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5787 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5788 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5789 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5790 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5791 | __ Bind(&loop); |
| 5792 | if (cls.IsRegister()) { |
| 5793 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5794 | } else { |
| 5795 | DCHECK(cls.IsStackSlot()) << cls; |
| 5796 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5797 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5798 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5799 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5800 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5801 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5802 | |
| 5803 | // If the class reference currently in `temp` is not null, jump |
| 5804 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5805 | __ testl(temp, temp); |
| 5806 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5807 | // Otherwise, jump to the slow path to throw the exception. |
| 5808 | // |
| 5809 | // But before, move back the object's class into `temp` before |
| 5810 | // going into the slow path, as it has been overwritten in the |
| 5811 | // meantime. |
| 5812 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5813 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5814 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5815 | break; |
| 5816 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5817 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5818 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5819 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5820 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5821 | if (cls.IsRegister()) { |
| 5822 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5823 | } else { |
| 5824 | DCHECK(cls.IsStackSlot()) << cls; |
| 5825 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5826 | } |
| 5827 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5828 | |
| 5829 | // Otherwise, we need to check that the object's class is a non-primitive array. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5830 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5831 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5832 | |
| 5833 | // If the component type is not null (i.e. the object is indeed |
| 5834 | // an array), jump to label `check_non_primitive_component_type` |
| 5835 | // to further check that this component type is not a primitive |
| 5836 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5837 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5838 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 5839 | // Otherwise, jump to the slow path to throw the exception. |
| 5840 | // |
| 5841 | // But before, move back the object's class into `temp` before |
| 5842 | // going into the slow path, as it has been overwritten in the |
| 5843 | // meantime. |
| 5844 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5845 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5846 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 5847 | |
| 5848 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5849 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5850 | __ j(kEqual, &done); |
| 5851 | // Same comment as above regarding `temp` and the slow path. |
| 5852 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5853 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5854 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5855 | break; |
| 5856 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5857 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5858 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5859 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5860 | // We always go into the type check slow path for the unresolved & |
| 5861 | // interface check cases. |
| 5862 | // |
| 5863 | // We cannot directly call the CheckCast runtime entry point |
| 5864 | // without resorting to a type checking slow path here (i.e. by |
| 5865 | // calling InvokeRuntime directly), as it would require to |
| 5866 | // assign fixed registers for the inputs of this HInstanceOf |
| 5867 | // instruction (following the runtime calling convention), which |
| 5868 | // might be cluttered by the potential first read barrier |
| 5869 | // emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5870 | // |
| 5871 | // TODO: Introduce a new runtime entry point taking the object |
| 5872 | // to test (instead of its class) as argument, and let it deal |
| 5873 | // with the read barrier issues. This will let us refactor this |
| 5874 | // case of the `switch` code as it was previously (with a direct |
| 5875 | // call to the runtime not using a type checking slow path). |
| 5876 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5877 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5878 | break; |
| 5879 | } |
| 5880 | __ Bind(&done); |
| 5881 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5882 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5883 | } |
| 5884 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5885 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5886 | LocationSummary* locations = |
| 5887 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5888 | InvokeRuntimeCallingConvention calling_convention; |
| 5889 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5890 | } |
| 5891 | |
| 5892 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5893 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 5894 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 5895 | instruction, |
| 5896 | instruction->GetDexPc(), |
| 5897 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5898 | if (instruction->IsEnter()) { |
| 5899 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5900 | } else { |
| 5901 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5902 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5903 | } |
| 5904 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5905 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 5906 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 5907 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 5908 | |
| 5909 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5910 | LocationSummary* locations = |
| 5911 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5912 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 5913 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 5914 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5915 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5916 | locations->SetOut(Location::SameAsFirstInput()); |
| 5917 | } |
| 5918 | |
| 5919 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 5920 | HandleBitwiseOperation(instruction); |
| 5921 | } |
| 5922 | |
| 5923 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 5924 | HandleBitwiseOperation(instruction); |
| 5925 | } |
| 5926 | |
| 5927 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 5928 | HandleBitwiseOperation(instruction); |
| 5929 | } |
| 5930 | |
| 5931 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5932 | LocationSummary* locations = instruction->GetLocations(); |
| 5933 | Location first = locations->InAt(0); |
| 5934 | Location second = locations->InAt(1); |
| 5935 | DCHECK(first.Equals(locations->Out())); |
| 5936 | |
| 5937 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 5938 | if (second.IsRegister()) { |
| 5939 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5940 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5941 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5942 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5943 | } else { |
| 5944 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5945 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5946 | } |
| 5947 | } else if (second.IsConstant()) { |
| 5948 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 5949 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5950 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5951 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5952 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5953 | } else { |
| 5954 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5955 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5956 | } |
| 5957 | } else { |
| 5958 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 5959 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5960 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5961 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5962 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5963 | } else { |
| 5964 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5965 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5966 | } |
| 5967 | } |
| 5968 | } else { |
| 5969 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5970 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 5971 | bool second_is_constant = false; |
| 5972 | int64_t value = 0; |
| 5973 | if (second.IsConstant()) { |
| 5974 | second_is_constant = true; |
| 5975 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5976 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5977 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5978 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5979 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5980 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5981 | if (is_int32_value) { |
| 5982 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 5983 | } else { |
| 5984 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 5985 | } |
| 5986 | } else if (second.IsDoubleStackSlot()) { |
| 5987 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5988 | } else { |
| 5989 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 5990 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5991 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5992 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5993 | if (is_int32_value) { |
| 5994 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 5995 | } else { |
| 5996 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 5997 | } |
| 5998 | } else if (second.IsDoubleStackSlot()) { |
| 5999 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6000 | } else { |
| 6001 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6002 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6003 | } else { |
| 6004 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6005 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6006 | if (is_int32_value) { |
| 6007 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6008 | } else { |
| 6009 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6010 | } |
| 6011 | } else if (second.IsDoubleStackSlot()) { |
| 6012 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6013 | } else { |
| 6014 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 6015 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6016 | } |
| 6017 | } |
| 6018 | } |
| 6019 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6020 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6021 | Location out, |
| 6022 | uint32_t offset, |
| 6023 | Location temp) { |
| 6024 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6025 | if (kEmitCompilerReadBarrier) { |
| 6026 | if (kUseBakerReadBarrier) { |
| 6027 | // Load with fast path based Baker's read barrier. |
| 6028 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6029 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 6030 | instruction, out, out_reg, offset, temp, /* needs_null_check */ false); |
| 6031 | } else { |
| 6032 | // Load with slow path based read barrier. |
| 6033 | // Save the value of `out` into `temp` before overwriting it |
| 6034 | // in the following move operation, as we will need it for the |
| 6035 | // read barrier below. |
| 6036 | __ movl(temp.AsRegister<CpuRegister>(), out_reg); |
| 6037 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6038 | __ movl(out_reg, Address(out_reg, offset)); |
| 6039 | codegen_->GenerateReadBarrierSlow(instruction, out, out, temp, offset); |
| 6040 | } |
| 6041 | } else { |
| 6042 | // Plain load with no read barrier. |
| 6043 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6044 | __ movl(out_reg, Address(out_reg, offset)); |
| 6045 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6046 | } |
| 6047 | } |
| 6048 | |
| 6049 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6050 | Location out, |
| 6051 | Location obj, |
| 6052 | uint32_t offset, |
| 6053 | Location temp) { |
| 6054 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6055 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
| 6056 | if (kEmitCompilerReadBarrier) { |
| 6057 | if (kUseBakerReadBarrier) { |
| 6058 | // Load with fast path based Baker's read barrier. |
| 6059 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6060 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 6061 | instruction, out, obj_reg, offset, temp, /* needs_null_check */ false); |
| 6062 | } else { |
| 6063 | // Load with slow path based read barrier. |
| 6064 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6065 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6066 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6067 | } |
| 6068 | } else { |
| 6069 | // Plain load with no read barrier. |
| 6070 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6071 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6072 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6073 | } |
| 6074 | } |
| 6075 | |
| 6076 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6077 | Location root, |
| 6078 | CpuRegister obj, |
| 6079 | uint32_t offset) { |
| 6080 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
| 6081 | if (kEmitCompilerReadBarrier) { |
| 6082 | if (kUseBakerReadBarrier) { |
| 6083 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6084 | // Baker's read barrier are used: |
| 6085 | // |
| 6086 | // root = obj.field; |
| 6087 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6088 | // root = ReadBarrier::Mark(root) |
| 6089 | // } |
| 6090 | |
| 6091 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6092 | __ movl(root_reg, Address(obj, offset)); |
| 6093 | static_assert( |
| 6094 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6095 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6096 | "have different sizes."); |
| 6097 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6098 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6099 | "have different sizes."); |
| 6100 | |
| 6101 | // Slow path used to mark the GC root `root`. |
| 6102 | SlowPathCode* slow_path = |
| 6103 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64(instruction, root, root); |
| 6104 | codegen_->AddSlowPath(slow_path); |
| 6105 | |
| 6106 | __ gs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86_64WordSize>().Int32Value(), |
| 6107 | /* no_rip */ true), |
| 6108 | Immediate(0)); |
| 6109 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6110 | __ Bind(slow_path->GetExitLabel()); |
| 6111 | } else { |
| 6112 | // GC root loaded through a slow path for read barriers other |
| 6113 | // than Baker's. |
| 6114 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6115 | __ leaq(root_reg, Address(obj, offset)); |
| 6116 | // /* mirror::Object* */ root = root->Read() |
| 6117 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6118 | } |
| 6119 | } else { |
| 6120 | // Plain GC root load with no read barrier. |
| 6121 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6122 | __ movl(root_reg, Address(obj, offset)); |
| 6123 | } |
| 6124 | } |
| 6125 | |
| 6126 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6127 | Location ref, |
| 6128 | CpuRegister obj, |
| 6129 | uint32_t offset, |
| 6130 | Location temp, |
| 6131 | bool needs_null_check) { |
| 6132 | DCHECK(kEmitCompilerReadBarrier); |
| 6133 | DCHECK(kUseBakerReadBarrier); |
| 6134 | |
| 6135 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6136 | Address src(obj, offset); |
| 6137 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6138 | } |
| 6139 | |
| 6140 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6141 | Location ref, |
| 6142 | CpuRegister obj, |
| 6143 | uint32_t data_offset, |
| 6144 | Location index, |
| 6145 | Location temp, |
| 6146 | bool needs_null_check) { |
| 6147 | DCHECK(kEmitCompilerReadBarrier); |
| 6148 | DCHECK(kUseBakerReadBarrier); |
| 6149 | |
| 6150 | // /* HeapReference<Object> */ ref = |
| 6151 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6152 | Address src = index.IsConstant() ? |
| 6153 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 6154 | Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset); |
| 6155 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6156 | } |
| 6157 | |
| 6158 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6159 | Location ref, |
| 6160 | CpuRegister obj, |
| 6161 | const Address& src, |
| 6162 | Location temp, |
| 6163 | bool needs_null_check) { |
| 6164 | DCHECK(kEmitCompilerReadBarrier); |
| 6165 | DCHECK(kUseBakerReadBarrier); |
| 6166 | |
| 6167 | // In slow path based read barriers, the read barrier call is |
| 6168 | // inserted after the original load. However, in fast path based |
| 6169 | // Baker's read barriers, we need to perform the load of |
| 6170 | // mirror::Object::monitor_ *before* the original reference load. |
| 6171 | // This load-load ordering is required by the read barrier. |
| 6172 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6173 | // |
| 6174 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6175 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6176 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6177 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6178 | // if (is_gray) { |
| 6179 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6180 | // } |
| 6181 | // |
| 6182 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6183 | // slightly more complex as: |
| 6184 | // - it implements the load-load fence using a data dependency on |
| 6185 | // the high-bits of rb_state, which are expected to be all zeroes; |
| 6186 | // - it performs additional checks that we do not do here for |
| 6187 | // performance reasons. |
| 6188 | |
| 6189 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
| 6190 | CpuRegister temp_reg = temp.AsRegister<CpuRegister>(); |
| 6191 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6192 | |
| 6193 | // /* int32_t */ monitor = obj->monitor_ |
| 6194 | __ movl(temp_reg, Address(obj, monitor_offset)); |
| 6195 | if (needs_null_check) { |
| 6196 | MaybeRecordImplicitNullCheck(instruction); |
| 6197 | } |
| 6198 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6199 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6200 | "art::LockWord and int32_t have different sizes."); |
| 6201 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 6202 | __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); |
| 6203 | __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); |
| 6204 | static_assert( |
| 6205 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 6206 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 6207 | |
| 6208 | // Load fence to prevent load-load reordering. |
| 6209 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 6210 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6211 | |
| 6212 | // The actual reference load. |
| 6213 | // /* HeapReference<Object> */ ref = *src |
| 6214 | __ movl(ref_reg, src); |
| 6215 | |
| 6216 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6217 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6218 | |
| 6219 | // Slow path used to mark the object `ref` when it is gray. |
| 6220 | SlowPathCode* slow_path = |
| 6221 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64(instruction, ref, ref); |
| 6222 | AddSlowPath(slow_path); |
| 6223 | |
| 6224 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6225 | // ref = ReadBarrier::Mark(ref); |
| 6226 | __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); |
| 6227 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6228 | __ Bind(slow_path->GetExitLabel()); |
| 6229 | } |
| 6230 | |
| 6231 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6232 | Location out, |
| 6233 | Location ref, |
| 6234 | Location obj, |
| 6235 | uint32_t offset, |
| 6236 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6237 | DCHECK(kEmitCompilerReadBarrier); |
| 6238 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6239 | // Insert a slow path based read barrier *after* the reference load. |
| 6240 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6241 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6242 | // reference will be carried out by the runtime within the slow |
| 6243 | // path. |
| 6244 | // |
| 6245 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6246 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6247 | // not used by the artReadBarrierSlow entry point. |
| 6248 | // |
| 6249 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6250 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6251 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 6252 | AddSlowPath(slow_path); |
| 6253 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6254 | __ jmp(slow_path->GetEntryLabel()); |
| 6255 | __ Bind(slow_path->GetExitLabel()); |
| 6256 | } |
| 6257 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6258 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6259 | Location out, |
| 6260 | Location ref, |
| 6261 | Location obj, |
| 6262 | uint32_t offset, |
| 6263 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6264 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6265 | // Baker's read barriers shall be handled by the fast path |
| 6266 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6267 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6268 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6269 | // by the runtime within the slow path. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6270 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6271 | } else if (kPoisonHeapReferences) { |
| 6272 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 6273 | } |
| 6274 | } |
| 6275 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6276 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6277 | Location out, |
| 6278 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6279 | DCHECK(kEmitCompilerReadBarrier); |
| 6280 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6281 | // Insert a slow path based read barrier *after* the GC root load. |
| 6282 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6283 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6284 | // not need to do anything special for this here. |
| 6285 | SlowPathCode* slow_path = |
| 6286 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
| 6287 | AddSlowPath(slow_path); |
| 6288 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6289 | __ jmp(slow_path->GetEntryLabel()); |
| 6290 | __ Bind(slow_path->GetExitLabel()); |
| 6291 | } |
| 6292 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6293 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6294 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6295 | LOG(FATAL) << "Unreachable"; |
| 6296 | } |
| 6297 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6298 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6299 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6300 | LOG(FATAL) << "Unreachable"; |
| 6301 | } |
| 6302 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6303 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6304 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6305 | LocationSummary* locations = |
| 6306 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6307 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6308 | locations->AddTemp(Location::RequiresRegister()); |
| 6309 | locations->AddTemp(Location::RequiresRegister()); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6310 | } |
| 6311 | |
| 6312 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6313 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6314 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6315 | LocationSummary* locations = switch_instr->GetLocations(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6316 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 6317 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 6318 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6319 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6320 | |
| 6321 | // Should we generate smaller inline compare/jumps? |
| 6322 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6323 | // Figure out the correct compare values and jump conditions. |
| 6324 | // Handle the first compare/branch as a special case because it might |
| 6325 | // jump to the default case. |
| 6326 | DCHECK_GT(num_entries, 2u); |
| 6327 | Condition first_condition; |
| 6328 | uint32_t index; |
| 6329 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6330 | if (lower_bound != 0) { |
| 6331 | first_condition = kLess; |
| 6332 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 6333 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6334 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 6335 | |
| 6336 | index = 1; |
| 6337 | } else { |
| 6338 | // Handle all the compare/jumps below. |
| 6339 | first_condition = kBelow; |
| 6340 | index = 0; |
| 6341 | } |
| 6342 | |
| 6343 | // Handle the rest of the compare/jumps. |
| 6344 | for (; index + 1 < num_entries; index += 2) { |
| 6345 | int32_t compare_to_value = lower_bound + index + 1; |
| 6346 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 6347 | // Jump to successors[index] if value < case_value[index]. |
| 6348 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6349 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6350 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6351 | } |
| 6352 | |
| 6353 | if (index != num_entries) { |
| 6354 | // There are an odd number of entries. Handle the last one. |
| 6355 | DCHECK_EQ(index + 1, num_entries); |
Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 6356 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6357 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 6358 | } |
| 6359 | |
| 6360 | // And the default for any other value. |
| 6361 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6362 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 6363 | } |
| 6364 | return; |
| 6365 | } |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6366 | |
| 6367 | // Remove the bias, if needed. |
| 6368 | Register value_reg_out = value_reg_in.AsRegister(); |
| 6369 | if (lower_bound != 0) { |
| 6370 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 6371 | value_reg_out = temp_reg.AsRegister(); |
| 6372 | } |
| 6373 | CpuRegister value_reg(value_reg_out); |
| 6374 | |
| 6375 | // Is the value in range? |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6376 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6377 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6378 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6379 | // We are in the range of the table. |
| 6380 | // Load the address of the jump table in the constant area. |
| 6381 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6382 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6383 | // Load the (signed) offset from the jump table. |
| 6384 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 6385 | |
| 6386 | // Add the offset to the address of the table base. |
| 6387 | __ addq(temp_reg, base_reg); |
| 6388 | |
| 6389 | // And jump. |
| 6390 | __ jmp(temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6391 | } |
| 6392 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6393 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 6394 | if (value == 0) { |
| 6395 | __ xorl(dest, dest); |
| 6396 | } else if (value > 0 && IsInt<32>(value)) { |
| 6397 | // We can use a 32 bit move, as it will zero-extend and is one byte shorter. |
| 6398 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 6399 | } else { |
| 6400 | __ movq(dest, Immediate(value)); |
| 6401 | } |
| 6402 | } |
| 6403 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 6404 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 6405 | DCHECK(dest.IsDoubleStackSlot()); |
| 6406 | if (IsInt<32>(value)) { |
| 6407 | // Can move directly as an int32 constant. |
| 6408 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 6409 | Immediate(static_cast<int32_t>(value))); |
| 6410 | } else { |
| 6411 | Load64BitValue(CpuRegister(TMP), value); |
| 6412 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 6413 | } |
| 6414 | } |
| 6415 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6416 | /** |
| 6417 | * Class to handle late fixup of offsets into constant area. |
| 6418 | */ |
| 6419 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 6420 | public: |
| 6421 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 6422 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6423 | |
| 6424 | protected: |
| 6425 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6426 | |
| 6427 | CodeGeneratorX86_64* codegen_; |
| 6428 | |
| 6429 | private: |
| 6430 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6431 | // Patch the correct offset for the instruction. We use the address of the |
| 6432 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 6433 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 6434 | int32_t relative_position = constant_offset - pos; |
| 6435 | |
| 6436 | // Patch in the right value. |
| 6437 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 6438 | } |
| 6439 | |
| 6440 | // Location in constant area that the fixup refers to. |
| 6441 | size_t offset_into_constant_area_; |
| 6442 | }; |
| 6443 | |
| 6444 | /** |
| 6445 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 6446 | * constant area. |
| 6447 | */ |
| 6448 | class JumpTableRIPFixup : public RIPFixup { |
| 6449 | public: |
| 6450 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 6451 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 6452 | |
| 6453 | void CreateJumpTable() { |
| 6454 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 6455 | |
| 6456 | // Ensure that the reference to the jump table has the correct offset. |
| 6457 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 6458 | SetOffset(offset_in_constant_table); |
| 6459 | |
| 6460 | // Compute the offset from the start of the function to this jump table. |
| 6461 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 6462 | |
| 6463 | // Populate the jump table with the correct values for the jump table. |
| 6464 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 6465 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 6466 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 6467 | // The value that we want is the target offset - the position of the table. |
| 6468 | for (int32_t i = 0; i < num_entries; i++) { |
| 6469 | HBasicBlock* b = successors[i]; |
| 6470 | Label* l = codegen_->GetLabelOf(b); |
| 6471 | DCHECK(l->IsBound()); |
| 6472 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 6473 | assembler->AppendInt32(offset_to_block); |
| 6474 | } |
| 6475 | } |
| 6476 | |
| 6477 | private: |
| 6478 | const HPackedSwitch* switch_instr_; |
| 6479 | }; |
| 6480 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6481 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 6482 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6483 | X86_64Assembler* assembler = GetAssembler(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6484 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 6485 | // 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] | 6486 | assembler->Align(4, 0); |
| 6487 | constant_area_start_ = assembler->CodeSize(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6488 | |
| 6489 | // Populate any jump tables. |
| 6490 | for (auto jump_table : fixups_to_jump_tables_) { |
| 6491 | jump_table->CreateJumpTable(); |
| 6492 | } |
| 6493 | |
| 6494 | // And now add the constant area to the generated code. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6495 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6496 | } |
| 6497 | |
| 6498 | // And finish up. |
| 6499 | CodeGenerator::Finalize(allocator); |
| 6500 | } |
| 6501 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6502 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 6503 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 6504 | return Address::RIP(fixup); |
| 6505 | } |
| 6506 | |
| 6507 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 6508 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 6509 | return Address::RIP(fixup); |
| 6510 | } |
| 6511 | |
| 6512 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 6513 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 6514 | return Address::RIP(fixup); |
| 6515 | } |
| 6516 | |
| 6517 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 6518 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 6519 | return Address::RIP(fixup); |
| 6520 | } |
| 6521 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6522 | // TODO: trg as memory. |
| 6523 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 6524 | if (!trg.IsValid()) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6525 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6526 | return; |
| 6527 | } |
| 6528 | |
| 6529 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 6530 | |
| 6531 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 6532 | if (trg.Equals(return_loc)) { |
| 6533 | return; |
| 6534 | } |
| 6535 | |
| 6536 | // Let the parallel move resolver take care of all of this. |
| 6537 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6538 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 6539 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6540 | } |
| 6541 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6542 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 6543 | // Create a fixup to be used to create and address the jump table. |
| 6544 | JumpTableRIPFixup* table_fixup = |
| 6545 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 6546 | |
| 6547 | // We have to populate the jump tables. |
| 6548 | fixups_to_jump_tables_.push_back(table_fixup); |
| 6549 | return Address::RIP(table_fixup); |
| 6550 | } |
| 6551 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 6552 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 6553 | const Address& addr_high, |
| 6554 | int64_t v, |
| 6555 | HInstruction* instruction) { |
| 6556 | if (IsInt<32>(v)) { |
| 6557 | int32_t v_32 = v; |
| 6558 | __ movq(addr_low, Immediate(v_32)); |
| 6559 | MaybeRecordImplicitNullCheck(instruction); |
| 6560 | } else { |
| 6561 | // Didn't fit in a register. Do it in pieces. |
| 6562 | int32_t low_v = Low32Bits(v); |
| 6563 | int32_t high_v = High32Bits(v); |
| 6564 | __ movl(addr_low, Immediate(low_v)); |
| 6565 | MaybeRecordImplicitNullCheck(instruction); |
| 6566 | __ movl(addr_high, Immediate(high_v)); |
| 6567 | } |
| 6568 | } |
| 6569 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6570 | #undef __ |
| 6571 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 6572 | } // namespace x86_64 |
| 6573 | } // namespace art |