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()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1129 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1130 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1131 | __ movq(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1132 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1133 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1134 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1135 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1136 | } else if (source.IsConstant()) { |
| 1137 | HConstant* constant = source.GetConstant(); |
| 1138 | if (constant->IsLongConstant()) { |
| 1139 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
| 1140 | } else { |
| 1141 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1142 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1143 | } else { |
| 1144 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1145 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1146 | } |
| 1147 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1148 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1149 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1150 | __ movd(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1151 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1152 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1153 | } else if (source.IsConstant()) { |
| 1154 | HConstant* constant = source.GetConstant(); |
| 1155 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1156 | if (constant->IsFloatConstant()) { |
| 1157 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1158 | } else { |
| 1159 | Load64BitValue(dest, value); |
| 1160 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1161 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1162 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1163 | } else { |
| 1164 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1165 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1166 | } |
| 1167 | } else if (destination.IsStackSlot()) { |
| 1168 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1169 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1170 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1171 | } else if (source.IsFpuRegister()) { |
| 1172 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1173 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1174 | } else if (source.IsConstant()) { |
| 1175 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1176 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1177 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1178 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1179 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1180 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1181 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1182 | } |
| 1183 | } else { |
| 1184 | DCHECK(destination.IsDoubleStackSlot()); |
| 1185 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1186 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1187 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1188 | } else if (source.IsFpuRegister()) { |
| 1189 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1190 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1191 | } else if (source.IsConstant()) { |
| 1192 | HConstant* constant = source.GetConstant(); |
Zheng Xu | 12bca97 | 2015-03-30 19:35:50 +0800 | [diff] [blame] | 1193 | int64_t value; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1194 | if (constant->IsDoubleConstant()) { |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1195 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1196 | } else { |
| 1197 | DCHECK(constant->IsLongConstant()); |
| 1198 | value = constant->AsLongConstant()->GetValue(); |
| 1199 | } |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1200 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1201 | } else { |
| 1202 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1203 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1204 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1205 | } |
| 1206 | } |
| 1207 | } |
| 1208 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1209 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1210 | DCHECK(location.IsRegister()); |
| 1211 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1212 | } |
| 1213 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1214 | void CodeGeneratorX86_64::MoveLocation( |
| 1215 | Location dst, Location src, Primitive::Type dst_type ATTRIBUTE_UNUSED) { |
| 1216 | Move(dst, src); |
| 1217 | } |
| 1218 | |
| 1219 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1220 | if (location.IsRegister()) { |
| 1221 | locations->AddTemp(location); |
| 1222 | } else { |
| 1223 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1224 | } |
| 1225 | } |
| 1226 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1227 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1228 | DCHECK(!successor->IsExitBlock()); |
| 1229 | |
| 1230 | HBasicBlock* block = got->GetBlock(); |
| 1231 | HInstruction* previous = got->GetPrevious(); |
| 1232 | |
| 1233 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1234 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1235 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1236 | return; |
| 1237 | } |
| 1238 | |
| 1239 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1240 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1241 | } |
| 1242 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1243 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1244 | } |
| 1245 | } |
| 1246 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1247 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1248 | got->SetLocations(nullptr); |
| 1249 | } |
| 1250 | |
| 1251 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1252 | HandleGoto(got, got->GetSuccessor()); |
| 1253 | } |
| 1254 | |
| 1255 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1256 | try_boundary->SetLocations(nullptr); |
| 1257 | } |
| 1258 | |
| 1259 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1260 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1261 | if (!successor->IsExitBlock()) { |
| 1262 | HandleGoto(try_boundary, successor); |
| 1263 | } |
| 1264 | } |
| 1265 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1266 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1267 | exit->SetLocations(nullptr); |
| 1268 | } |
| 1269 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1270 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1271 | } |
| 1272 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1273 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1274 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1275 | LabelType* true_label, |
| 1276 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1277 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1278 | __ j(kUnordered, true_label); |
| 1279 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1280 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1281 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1282 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1283 | } |
| 1284 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1285 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1286 | LocationSummary* locations = condition->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1287 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1288 | Location left = locations->InAt(0); |
| 1289 | Location right = locations->InAt(1); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1290 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1291 | switch (type) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1292 | case Primitive::kPrimBoolean: |
| 1293 | case Primitive::kPrimByte: |
| 1294 | case Primitive::kPrimChar: |
| 1295 | case Primitive::kPrimShort: |
| 1296 | case Primitive::kPrimInt: |
| 1297 | case Primitive::kPrimNot: { |
| 1298 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1299 | if (right.IsConstant()) { |
| 1300 | int32_t value = CodeGenerator::GetInt32ValueOf(right.GetConstant()); |
| 1301 | if (value == 0) { |
| 1302 | __ testl(left_reg, left_reg); |
| 1303 | } else { |
| 1304 | __ cmpl(left_reg, Immediate(value)); |
| 1305 | } |
| 1306 | } else if (right.IsStackSlot()) { |
| 1307 | __ cmpl(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1308 | } else { |
| 1309 | __ cmpl(left_reg, right.AsRegister<CpuRegister>()); |
| 1310 | } |
| 1311 | break; |
| 1312 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1313 | case Primitive::kPrimLong: { |
| 1314 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1315 | if (right.IsConstant()) { |
| 1316 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1317 | codegen_->Compare64BitValue(left_reg, value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1318 | } else if (right.IsDoubleStackSlot()) { |
| 1319 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1320 | } else { |
| 1321 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1322 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1323 | break; |
| 1324 | } |
| 1325 | case Primitive::kPrimFloat: { |
| 1326 | if (right.IsFpuRegister()) { |
| 1327 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1328 | } else if (right.IsConstant()) { |
| 1329 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1330 | codegen_->LiteralFloatAddress( |
| 1331 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1332 | } else { |
| 1333 | DCHECK(right.IsStackSlot()); |
| 1334 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1335 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1336 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1337 | break; |
| 1338 | } |
| 1339 | case Primitive::kPrimDouble: { |
| 1340 | if (right.IsFpuRegister()) { |
| 1341 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1342 | } else if (right.IsConstant()) { |
| 1343 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1344 | codegen_->LiteralDoubleAddress( |
| 1345 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1346 | } else { |
| 1347 | DCHECK(right.IsDoubleStackSlot()); |
| 1348 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1349 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1350 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1351 | break; |
| 1352 | } |
| 1353 | default: |
| 1354 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1355 | } |
| 1356 | } |
| 1357 | |
| 1358 | template<class LabelType> |
| 1359 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1360 | LabelType* true_target_in, |
| 1361 | LabelType* false_target_in) { |
| 1362 | // Generated branching requires both targets to be explicit. If either of the |
| 1363 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1364 | LabelType fallthrough_target; |
| 1365 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1366 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1367 | |
| 1368 | // Generate the comparison to set the CC. |
| 1369 | GenerateCompareTest(condition); |
| 1370 | |
| 1371 | // Now generate the correct jump(s). |
| 1372 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1373 | switch (type) { |
| 1374 | case Primitive::kPrimLong: { |
| 1375 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1376 | break; |
| 1377 | } |
| 1378 | case Primitive::kPrimFloat: { |
| 1379 | GenerateFPJumps(condition, true_target, false_target); |
| 1380 | break; |
| 1381 | } |
| 1382 | case Primitive::kPrimDouble: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1383 | GenerateFPJumps(condition, true_target, false_target); |
| 1384 | break; |
| 1385 | } |
| 1386 | default: |
| 1387 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1388 | } |
| 1389 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1390 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1391 | __ jmp(false_target); |
| 1392 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1393 | |
| 1394 | if (fallthrough_target.IsLinked()) { |
| 1395 | __ Bind(&fallthrough_target); |
| 1396 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1397 | } |
| 1398 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1399 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1400 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1401 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1402 | // conditions if they are materialized due to the complex branching. |
| 1403 | return cond->IsCondition() && |
| 1404 | cond->GetNext() == branch && |
| 1405 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1406 | } |
| 1407 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1408 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1409 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1410 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1411 | LabelType* true_target, |
| 1412 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1413 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1414 | |
| 1415 | if (true_target == nullptr && false_target == nullptr) { |
| 1416 | // Nothing to do. The code always falls through. |
| 1417 | return; |
| 1418 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1419 | // Constant condition, statically compared against 1. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1420 | if (cond->AsIntConstant()->IsOne()) { |
| 1421 | if (true_target != nullptr) { |
| 1422 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1423 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1424 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1425 | DCHECK(cond->AsIntConstant()->IsZero()); |
| 1426 | if (false_target != nullptr) { |
| 1427 | __ jmp(false_target); |
| 1428 | } |
| 1429 | } |
| 1430 | return; |
| 1431 | } |
| 1432 | |
| 1433 | // The following code generates these patterns: |
| 1434 | // (1) true_target == nullptr && false_target != nullptr |
| 1435 | // - opposite condition true => branch to false_target |
| 1436 | // (2) true_target != nullptr && false_target == nullptr |
| 1437 | // - condition true => branch to true_target |
| 1438 | // (3) true_target != nullptr && false_target != nullptr |
| 1439 | // - condition true => branch to true_target |
| 1440 | // - branch to false_target |
| 1441 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1442 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1443 | if (true_target == nullptr) { |
| 1444 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1445 | } else { |
| 1446 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1447 | } |
| 1448 | } else { |
| 1449 | // Materialized condition, compare against 0. |
| 1450 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1451 | if (lhs.IsRegister()) { |
| 1452 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1453 | } else { |
| 1454 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1455 | } |
| 1456 | if (true_target == nullptr) { |
| 1457 | __ j(kEqual, false_target); |
| 1458 | } else { |
| 1459 | __ j(kNotEqual, true_target); |
| 1460 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1461 | } |
| 1462 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1463 | // Condition has not been materialized, use its inputs as the |
| 1464 | // comparison and its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1465 | HCondition* condition = cond->AsCondition(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1466 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1467 | // If this is a long or FP comparison that has been folded into |
| 1468 | // the HCondition, generate the comparison directly. |
| 1469 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1470 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1471 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1472 | return; |
| 1473 | } |
| 1474 | |
| 1475 | Location lhs = condition->GetLocations()->InAt(0); |
| 1476 | Location rhs = condition->GetLocations()->InAt(1); |
| 1477 | if (rhs.IsRegister()) { |
| 1478 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1479 | } else if (rhs.IsConstant()) { |
| 1480 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1481 | codegen_->Compare32BitValue(lhs.AsRegister<CpuRegister>(), constant); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1482 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1483 | __ cmpl(lhs.AsRegister<CpuRegister>(), |
| 1484 | Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1485 | } |
| 1486 | if (true_target == nullptr) { |
| 1487 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1488 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1489 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1490 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1491 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1492 | |
| 1493 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1494 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1495 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1496 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1497 | } |
| 1498 | } |
| 1499 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1500 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1501 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1502 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1503 | locations->SetInAt(0, Location::Any()); |
| 1504 | } |
| 1505 | } |
| 1506 | |
| 1507 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1508 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1509 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1510 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1511 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1512 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1513 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1514 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1515 | } |
| 1516 | |
| 1517 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1518 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1519 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1520 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1521 | locations->SetInAt(0, Location::Any()); |
| 1522 | } |
| 1523 | } |
| 1524 | |
| 1525 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1526 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1527 | GenerateTestAndBranch<Label>(deoptimize, |
| 1528 | /* condition_input_index */ 0, |
| 1529 | slow_path->GetEntryLabel(), |
| 1530 | /* false_target */ nullptr); |
| 1531 | } |
| 1532 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1533 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1534 | // There are no conditional move instructions for XMMs. |
| 1535 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1536 | return false; |
| 1537 | } |
| 1538 | |
| 1539 | // A FP condition doesn't generate the single CC that we need. |
| 1540 | HInstruction* condition = select->GetCondition(); |
| 1541 | if (condition->IsCondition() && |
| 1542 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
| 1543 | return false; |
| 1544 | } |
| 1545 | |
| 1546 | // We can generate a CMOV for this Select. |
| 1547 | return true; |
| 1548 | } |
| 1549 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1550 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
| 1551 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1552 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1553 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1554 | // Since we can't use CMOV, there is no need to force 'true' into a register. |
| 1555 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1556 | } else { |
| 1557 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1558 | if (SelectCanUseCMOV(select)) { |
| 1559 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1560 | } else { |
| 1561 | // Since we can't use CMOV, there is no need to force 'true' into a register. |
| 1562 | locations->SetInAt(1, Location::Any()); |
| 1563 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1564 | } |
| 1565 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1566 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1567 | } |
| 1568 | locations->SetOut(Location::SameAsFirstInput()); |
| 1569 | } |
| 1570 | |
| 1571 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 1572 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1573 | if (SelectCanUseCMOV(select)) { |
| 1574 | // If both the condition and the source types are integer, we can generate |
| 1575 | // a CMOV to implement Select. |
| 1576 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
| 1577 | CpuRegister value_true = locations->InAt(1).AsRegister<CpuRegister>(); |
| 1578 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1579 | |
| 1580 | HInstruction* select_condition = select->GetCondition(); |
| 1581 | Condition cond = kNotEqual; |
| 1582 | |
| 1583 | // Figure out how to test the 'condition'. |
| 1584 | if (select_condition->IsCondition()) { |
| 1585 | HCondition* condition = select_condition->AsCondition(); |
| 1586 | if (!condition->IsEmittedAtUseSite()) { |
| 1587 | // This was a previously materialized condition. |
| 1588 | // Can we use the existing condition code? |
| 1589 | if (AreEflagsSetFrom(condition, select)) { |
| 1590 | // Materialization was the previous instruction. Condition codes are right. |
| 1591 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1592 | } else { |
| 1593 | // No, we have to recreate the condition code. |
| 1594 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1595 | __ testl(cond_reg, cond_reg); |
| 1596 | } |
| 1597 | } else { |
| 1598 | GenerateCompareTest(condition); |
| 1599 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1600 | } |
| 1601 | } else { |
| 1602 | // Must be a boolean condition, which needs to be compared to 0. |
| 1603 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1604 | __ testl(cond_reg, cond_reg); |
| 1605 | } |
| 1606 | |
| 1607 | // If the condition is true, overwrite the output, which already contains false. |
| 1608 | // Generate the correct sized CMOV. |
| 1609 | __ cmov(cond, value_false, value_true, select->GetType() == Primitive::kPrimLong); |
| 1610 | } else { |
| 1611 | NearLabel false_target; |
| 1612 | GenerateTestAndBranch<NearLabel>(select, |
| 1613 | /* condition_input_index */ 2, |
| 1614 | /* true_target */ nullptr, |
| 1615 | &false_target); |
| 1616 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1617 | __ Bind(&false_target); |
| 1618 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1619 | } |
| 1620 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1621 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1622 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1623 | } |
| 1624 | |
| 1625 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
David Srbecky | b7070a2 | 2016-01-08 18:13:53 +0000 | [diff] [blame] | 1626 | if (codegen_->HasStackMapAtCurrentPc()) { |
| 1627 | // Ensure that we do not collide with the stack map of the previous instruction. |
| 1628 | __ nop(); |
| 1629 | } |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1630 | codegen_->RecordPcInfo(info, info->GetDexPc()); |
| 1631 | } |
| 1632 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1633 | void LocationsBuilderX86_64::VisitLocal(HLocal* local) { |
| 1634 | local->SetLocations(nullptr); |
| 1635 | } |
| 1636 | |
| 1637 | void InstructionCodeGeneratorX86_64::VisitLocal(HLocal* local) { |
| 1638 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 1639 | } |
| 1640 | |
| 1641 | void LocationsBuilderX86_64::VisitLoadLocal(HLoadLocal* local) { |
| 1642 | local->SetLocations(nullptr); |
| 1643 | } |
| 1644 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1645 | void InstructionCodeGeneratorX86_64::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1646 | // Nothing to do, this is driven by the code generator. |
| 1647 | } |
| 1648 | |
| 1649 | void LocationsBuilderX86_64::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1650 | LocationSummary* locations = |
| 1651 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1652 | switch (store->InputAt(1)->GetType()) { |
| 1653 | case Primitive::kPrimBoolean: |
| 1654 | case Primitive::kPrimByte: |
| 1655 | case Primitive::kPrimChar: |
| 1656 | case Primitive::kPrimShort: |
| 1657 | case Primitive::kPrimInt: |
| 1658 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1659 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1660 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1661 | break; |
| 1662 | |
| 1663 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1664 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1665 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1666 | break; |
| 1667 | |
| 1668 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1669 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1670 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1671 | } |
| 1672 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1673 | void InstructionCodeGeneratorX86_64::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1674 | } |
| 1675 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1676 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1677 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1678 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1679 | // Handle the long/FP comparisons made in instruction simplification. |
| 1680 | switch (cond->InputAt(0)->GetType()) { |
| 1681 | case Primitive::kPrimLong: |
| 1682 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1683 | locations->SetInAt(1, Location::Any()); |
| 1684 | break; |
| 1685 | case Primitive::kPrimFloat: |
| 1686 | case Primitive::kPrimDouble: |
| 1687 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1688 | locations->SetInAt(1, Location::Any()); |
| 1689 | break; |
| 1690 | default: |
| 1691 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1692 | locations->SetInAt(1, Location::Any()); |
| 1693 | break; |
| 1694 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1695 | if (!cond->IsEmittedAtUseSite()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1696 | locations->SetOut(Location::RequiresRegister()); |
| 1697 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1698 | } |
| 1699 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1700 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1701 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1702 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1703 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1704 | |
| 1705 | LocationSummary* locations = cond->GetLocations(); |
| 1706 | Location lhs = locations->InAt(0); |
| 1707 | Location rhs = locations->InAt(1); |
| 1708 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1709 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1710 | |
| 1711 | switch (cond->InputAt(0)->GetType()) { |
| 1712 | default: |
| 1713 | // Integer case. |
| 1714 | |
| 1715 | // Clear output register: setcc only sets the low byte. |
| 1716 | __ xorl(reg, reg); |
| 1717 | |
| 1718 | if (rhs.IsRegister()) { |
| 1719 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1720 | } else if (rhs.IsConstant()) { |
| 1721 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1722 | codegen_->Compare32BitValue(lhs.AsRegister<CpuRegister>(), constant); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1723 | } else { |
| 1724 | __ cmpl(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1725 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1726 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1727 | return; |
| 1728 | case Primitive::kPrimLong: |
| 1729 | // Clear output register: setcc only sets the low byte. |
| 1730 | __ xorl(reg, reg); |
| 1731 | |
| 1732 | if (rhs.IsRegister()) { |
| 1733 | __ cmpq(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1734 | } else if (rhs.IsConstant()) { |
| 1735 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1736 | codegen_->Compare64BitValue(lhs.AsRegister<CpuRegister>(), value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1737 | } else { |
| 1738 | __ cmpq(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1739 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1740 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1741 | return; |
| 1742 | case Primitive::kPrimFloat: { |
| 1743 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1744 | if (rhs.IsConstant()) { |
| 1745 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1746 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1747 | } else if (rhs.IsStackSlot()) { |
| 1748 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1749 | } else { |
| 1750 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1751 | } |
| 1752 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1753 | break; |
| 1754 | } |
| 1755 | case Primitive::kPrimDouble: { |
| 1756 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1757 | if (rhs.IsConstant()) { |
| 1758 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1759 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1760 | } else if (rhs.IsDoubleStackSlot()) { |
| 1761 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1762 | } else { |
| 1763 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1764 | } |
| 1765 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1766 | break; |
| 1767 | } |
| 1768 | } |
| 1769 | |
| 1770 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1771 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1772 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1773 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1774 | __ Bind(&false_label); |
| 1775 | __ xorl(reg, reg); |
| 1776 | __ jmp(&done_label); |
| 1777 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1778 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1779 | __ Bind(&true_label); |
| 1780 | __ movl(reg, Immediate(1)); |
| 1781 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1785 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1789 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1793 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1794 | } |
| 1795 | |
| 1796 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1797 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1801 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1805 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1809 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1813 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1817 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1821 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1825 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1829 | HandleCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1830 | } |
| 1831 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1832 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1833 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1837 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1838 | } |
| 1839 | |
| 1840 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1841 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1845 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1849 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1853 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1854 | } |
| 1855 | |
| 1856 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1857 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1861 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1862 | } |
| 1863 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1864 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1865 | LocationSummary* locations = |
| 1866 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1867 | switch (compare->InputAt(0)->GetType()) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1868 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1869 | case Primitive::kPrimLong: { |
| 1870 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1871 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1872 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1873 | break; |
| 1874 | } |
| 1875 | case Primitive::kPrimFloat: |
| 1876 | case Primitive::kPrimDouble: { |
| 1877 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1878 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1879 | locations->SetOut(Location::RequiresRegister()); |
| 1880 | break; |
| 1881 | } |
| 1882 | default: |
| 1883 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 1884 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1888 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1889 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1890 | Location left = locations->InAt(0); |
| 1891 | Location right = locations->InAt(1); |
| 1892 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1893 | NearLabel less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1894 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1895 | Condition less_cond = kLess; |
| 1896 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1897 | switch (type) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1898 | case Primitive::kPrimInt: { |
| 1899 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1900 | if (right.IsConstant()) { |
| 1901 | int32_t value = right.GetConstant()->AsIntConstant()->GetValue(); |
| 1902 | codegen_->Compare32BitValue(left_reg, value); |
| 1903 | } else if (right.IsStackSlot()) { |
| 1904 | __ cmpl(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1905 | } else { |
| 1906 | __ cmpl(left_reg, right.AsRegister<CpuRegister>()); |
| 1907 | } |
| 1908 | break; |
| 1909 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1910 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1911 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1912 | if (right.IsConstant()) { |
| 1913 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1914 | codegen_->Compare64BitValue(left_reg, value); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1915 | } else if (right.IsDoubleStackSlot()) { |
| 1916 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1917 | } else { |
| 1918 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1919 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1920 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1921 | } |
| 1922 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1923 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1924 | if (right.IsConstant()) { |
| 1925 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 1926 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 1927 | } else if (right.IsStackSlot()) { |
| 1928 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1929 | } else { |
| 1930 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1931 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1932 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1933 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1934 | break; |
| 1935 | } |
| 1936 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1937 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1938 | if (right.IsConstant()) { |
| 1939 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1940 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 1941 | } else if (right.IsDoubleStackSlot()) { |
| 1942 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1943 | } else { |
| 1944 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1945 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1946 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1947 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1948 | break; |
| 1949 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1950 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1951 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1952 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1953 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1954 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1955 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1956 | __ j(less_cond, &less); |
Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1957 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1958 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1959 | __ movl(out, Immediate(1)); |
| 1960 | __ jmp(&done); |
| 1961 | |
| 1962 | __ Bind(&less); |
| 1963 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1964 | |
| 1965 | __ Bind(&done); |
| 1966 | } |
| 1967 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1968 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1969 | LocationSummary* locations = |
| 1970 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1971 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1972 | } |
| 1973 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1974 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1975 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1976 | } |
| 1977 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1978 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1979 | LocationSummary* locations = |
| 1980 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1981 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1982 | } |
| 1983 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1984 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1985 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1986 | } |
| 1987 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1988 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1989 | LocationSummary* locations = |
| 1990 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1991 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1992 | } |
| 1993 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1994 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1995 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1996 | } |
| 1997 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1998 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1999 | LocationSummary* locations = |
| 2000 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2001 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2002 | } |
| 2003 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2004 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2005 | // Will be generated at use site. |
| 2006 | } |
| 2007 | |
| 2008 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2009 | LocationSummary* locations = |
| 2010 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2011 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2012 | } |
| 2013 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2014 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 2015 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2016 | // Will be generated at use site. |
| 2017 | } |
| 2018 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2019 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2020 | memory_barrier->SetLocations(nullptr); |
| 2021 | } |
| 2022 | |
| 2023 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2024 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2025 | } |
| 2026 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2027 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 2028 | ret->SetLocations(nullptr); |
| 2029 | } |
| 2030 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2031 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2032 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2033 | } |
| 2034 | |
| 2035 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2036 | LocationSummary* locations = |
| 2037 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2038 | switch (ret->InputAt(0)->GetType()) { |
| 2039 | case Primitive::kPrimBoolean: |
| 2040 | case Primitive::kPrimByte: |
| 2041 | case Primitive::kPrimChar: |
| 2042 | case Primitive::kPrimShort: |
| 2043 | case Primitive::kPrimInt: |
| 2044 | case Primitive::kPrimNot: |
| 2045 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2046 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2047 | break; |
| 2048 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2049 | case Primitive::kPrimFloat: |
| 2050 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2051 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2052 | break; |
| 2053 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2054 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2055 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2056 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 2060 | if (kIsDebugBuild) { |
| 2061 | switch (ret->InputAt(0)->GetType()) { |
| 2062 | case Primitive::kPrimBoolean: |
| 2063 | case Primitive::kPrimByte: |
| 2064 | case Primitive::kPrimChar: |
| 2065 | case Primitive::kPrimShort: |
| 2066 | case Primitive::kPrimInt: |
| 2067 | case Primitive::kPrimNot: |
| 2068 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2069 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2070 | break; |
| 2071 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2072 | case Primitive::kPrimFloat: |
| 2073 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2074 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2075 | XMM0); |
| 2076 | break; |
| 2077 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2078 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2079 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2080 | } |
| 2081 | } |
| 2082 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2083 | } |
| 2084 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2085 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 2086 | switch (type) { |
| 2087 | case Primitive::kPrimBoolean: |
| 2088 | case Primitive::kPrimByte: |
| 2089 | case Primitive::kPrimChar: |
| 2090 | case Primitive::kPrimShort: |
| 2091 | case Primitive::kPrimInt: |
| 2092 | case Primitive::kPrimNot: |
| 2093 | case Primitive::kPrimLong: |
| 2094 | return Location::RegisterLocation(RAX); |
| 2095 | |
| 2096 | case Primitive::kPrimVoid: |
| 2097 | return Location::NoLocation(); |
| 2098 | |
| 2099 | case Primitive::kPrimDouble: |
| 2100 | case Primitive::kPrimFloat: |
| 2101 | return Location::FpuRegisterLocation(XMM0); |
| 2102 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2103 | |
| 2104 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2105 | } |
| 2106 | |
| 2107 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2108 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2109 | } |
| 2110 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2111 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2112 | switch (type) { |
| 2113 | case Primitive::kPrimBoolean: |
| 2114 | case Primitive::kPrimByte: |
| 2115 | case Primitive::kPrimChar: |
| 2116 | case Primitive::kPrimShort: |
| 2117 | case Primitive::kPrimInt: |
| 2118 | case Primitive::kPrimNot: { |
| 2119 | uint32_t index = gp_index_++; |
| 2120 | stack_index_++; |
| 2121 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2122 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2123 | } else { |
| 2124 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2125 | } |
| 2126 | } |
| 2127 | |
| 2128 | case Primitive::kPrimLong: { |
| 2129 | uint32_t index = gp_index_; |
| 2130 | stack_index_ += 2; |
| 2131 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2132 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2133 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2134 | } else { |
| 2135 | gp_index_ += 2; |
| 2136 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2137 | } |
| 2138 | } |
| 2139 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2140 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2141 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2142 | stack_index_++; |
| 2143 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2144 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2145 | } else { |
| 2146 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2147 | } |
| 2148 | } |
| 2149 | |
| 2150 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2151 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2152 | stack_index_ += 2; |
| 2153 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2154 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2155 | } else { |
| 2156 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2157 | } |
| 2158 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2159 | |
| 2160 | case Primitive::kPrimVoid: |
| 2161 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2162 | break; |
| 2163 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2164 | return Location::NoLocation(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2165 | } |
| 2166 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2167 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2168 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2169 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2170 | // the method_idx. |
| 2171 | HandleInvoke(invoke); |
| 2172 | } |
| 2173 | |
| 2174 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2175 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2176 | } |
| 2177 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2178 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2179 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2180 | // art::PrepareForRegisterAllocation. |
| 2181 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2182 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2183 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2184 | if (intrinsic.TryDispatch(invoke)) { |
| 2185 | return; |
| 2186 | } |
| 2187 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2188 | HandleInvoke(invoke); |
| 2189 | } |
| 2190 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2191 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2192 | if (invoke->GetLocations()->Intrinsified()) { |
| 2193 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2194 | intrinsic.Dispatch(invoke); |
| 2195 | return true; |
| 2196 | } |
| 2197 | return false; |
| 2198 | } |
| 2199 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2200 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2201 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2202 | // art::PrepareForRegisterAllocation. |
| 2203 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2204 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2205 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2206 | return; |
| 2207 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2208 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2209 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2210 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2211 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2212 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2213 | } |
| 2214 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2215 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2216 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2217 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2218 | } |
| 2219 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2220 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2221 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2222 | if (intrinsic.TryDispatch(invoke)) { |
| 2223 | return; |
| 2224 | } |
| 2225 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2226 | HandleInvoke(invoke); |
| 2227 | } |
| 2228 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2229 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2230 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2231 | return; |
| 2232 | } |
| 2233 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2234 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2235 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2236 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2237 | } |
| 2238 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2239 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2240 | HandleInvoke(invoke); |
| 2241 | // Add the hidden argument. |
| 2242 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2243 | } |
| 2244 | |
| 2245 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2246 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2247 | LocationSummary* locations = invoke->GetLocations(); |
| 2248 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2249 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2250 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2251 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2252 | Location receiver = locations->InAt(0); |
| 2253 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2254 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2255 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2256 | // won't be modified thereafter, before the `call` instruction. |
| 2257 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2258 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2259 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2260 | if (receiver.IsStackSlot()) { |
| 2261 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2262 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2263 | __ movl(temp, Address(temp, class_offset)); |
| 2264 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2265 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2266 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2267 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2268 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2269 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2270 | // emit a read barrier for the previous class reference load. |
| 2271 | // However this is not required in practice, as this is an |
| 2272 | // intermediate/temporary reference and because the current |
| 2273 | // concurrent copying collector keeps the from-space memory |
| 2274 | // intact/accessible until the end of the marking phase (the |
| 2275 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2276 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2277 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2278 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2279 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2280 | __ call(Address(temp, |
| 2281 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2282 | |
| 2283 | DCHECK(!codegen_->IsLeafMethod()); |
| 2284 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2285 | } |
| 2286 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2287 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2288 | LocationSummary* locations = |
| 2289 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2290 | switch (neg->GetResultType()) { |
| 2291 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2292 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2293 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2294 | locations->SetOut(Location::SameAsFirstInput()); |
| 2295 | break; |
| 2296 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2297 | case Primitive::kPrimFloat: |
| 2298 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2299 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2300 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2301 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2302 | break; |
| 2303 | |
| 2304 | default: |
| 2305 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2306 | } |
| 2307 | } |
| 2308 | |
| 2309 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2310 | LocationSummary* locations = neg->GetLocations(); |
| 2311 | Location out = locations->Out(); |
| 2312 | Location in = locations->InAt(0); |
| 2313 | switch (neg->GetResultType()) { |
| 2314 | case Primitive::kPrimInt: |
| 2315 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2316 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2317 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2318 | break; |
| 2319 | |
| 2320 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2321 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2322 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2323 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2324 | break; |
| 2325 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2326 | case Primitive::kPrimFloat: { |
| 2327 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2328 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2329 | // Implement float negation with an exclusive or with value |
| 2330 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2331 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2332 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2333 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2334 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2335 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2336 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2337 | case Primitive::kPrimDouble: { |
| 2338 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2339 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2340 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2341 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2342 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2343 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2344 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2345 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2346 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2347 | |
| 2348 | default: |
| 2349 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2350 | } |
| 2351 | } |
| 2352 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2353 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2354 | LocationSummary* locations = |
| 2355 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 2356 | Primitive::Type result_type = conversion->GetResultType(); |
| 2357 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2358 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2359 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2360 | // The Java language does not allow treating boolean as an integral type but |
| 2361 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2362 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2363 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2364 | case Primitive::kPrimByte: |
| 2365 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame^] | 2366 | case Primitive::kPrimLong: |
| 2367 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2368 | case Primitive::kPrimBoolean: |
| 2369 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2370 | case Primitive::kPrimShort: |
| 2371 | case Primitive::kPrimInt: |
| 2372 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2373 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2374 | locations->SetInAt(0, Location::Any()); |
| 2375 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2376 | break; |
| 2377 | |
| 2378 | default: |
| 2379 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2380 | << " to " << result_type; |
| 2381 | } |
| 2382 | break; |
| 2383 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2384 | case Primitive::kPrimShort: |
| 2385 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame^] | 2386 | case Primitive::kPrimLong: |
| 2387 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2388 | case Primitive::kPrimBoolean: |
| 2389 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2390 | case Primitive::kPrimByte: |
| 2391 | case Primitive::kPrimInt: |
| 2392 | case Primitive::kPrimChar: |
| 2393 | // Processing a Dex `int-to-short' instruction. |
| 2394 | locations->SetInAt(0, Location::Any()); |
| 2395 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2396 | break; |
| 2397 | |
| 2398 | default: |
| 2399 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2400 | << " to " << result_type; |
| 2401 | } |
| 2402 | break; |
| 2403 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2404 | case Primitive::kPrimInt: |
| 2405 | switch (input_type) { |
| 2406 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2407 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2408 | locations->SetInAt(0, Location::Any()); |
| 2409 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2410 | break; |
| 2411 | |
| 2412 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2413 | // Processing a Dex `float-to-int' instruction. |
| 2414 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2415 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2416 | break; |
| 2417 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2418 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2419 | // Processing a Dex `double-to-int' instruction. |
| 2420 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2421 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2422 | break; |
| 2423 | |
| 2424 | default: |
| 2425 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2426 | << " to " << result_type; |
| 2427 | } |
| 2428 | break; |
| 2429 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2430 | case Primitive::kPrimLong: |
| 2431 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2432 | case Primitive::kPrimBoolean: |
| 2433 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2434 | case Primitive::kPrimByte: |
| 2435 | case Primitive::kPrimShort: |
| 2436 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2437 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2438 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2439 | // TODO: We would benefit from a (to-be-implemented) |
| 2440 | // Location::RegisterOrStackSlot requirement for this input. |
| 2441 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2442 | locations->SetOut(Location::RequiresRegister()); |
| 2443 | break; |
| 2444 | |
| 2445 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2446 | // Processing a Dex `float-to-long' instruction. |
| 2447 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2448 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2449 | break; |
| 2450 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2451 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2452 | // Processing a Dex `double-to-long' instruction. |
| 2453 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2454 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2455 | break; |
| 2456 | |
| 2457 | default: |
| 2458 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2459 | << " to " << result_type; |
| 2460 | } |
| 2461 | break; |
| 2462 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2463 | case Primitive::kPrimChar: |
| 2464 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame^] | 2465 | case Primitive::kPrimLong: |
| 2466 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2467 | case Primitive::kPrimBoolean: |
| 2468 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2469 | case Primitive::kPrimByte: |
| 2470 | case Primitive::kPrimShort: |
| 2471 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2472 | // Processing a Dex `int-to-char' instruction. |
| 2473 | locations->SetInAt(0, Location::Any()); |
| 2474 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2475 | break; |
| 2476 | |
| 2477 | default: |
| 2478 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2479 | << " to " << result_type; |
| 2480 | } |
| 2481 | break; |
| 2482 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2483 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2484 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2485 | case Primitive::kPrimBoolean: |
| 2486 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2487 | case Primitive::kPrimByte: |
| 2488 | case Primitive::kPrimShort: |
| 2489 | case Primitive::kPrimInt: |
| 2490 | case Primitive::kPrimChar: |
| 2491 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2492 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2493 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2494 | break; |
| 2495 | |
| 2496 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2497 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2498 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2499 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2500 | break; |
| 2501 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2502 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2503 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2504 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2505 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2506 | break; |
| 2507 | |
| 2508 | default: |
| 2509 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2510 | << " to " << result_type; |
| 2511 | }; |
| 2512 | break; |
| 2513 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2514 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2515 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2516 | case Primitive::kPrimBoolean: |
| 2517 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2518 | case Primitive::kPrimByte: |
| 2519 | case Primitive::kPrimShort: |
| 2520 | case Primitive::kPrimInt: |
| 2521 | case Primitive::kPrimChar: |
| 2522 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2523 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2524 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2525 | break; |
| 2526 | |
| 2527 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2528 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2529 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2530 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2531 | break; |
| 2532 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2533 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2534 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2535 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2536 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2537 | break; |
| 2538 | |
| 2539 | default: |
| 2540 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2541 | << " to " << result_type; |
| 2542 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2543 | break; |
| 2544 | |
| 2545 | default: |
| 2546 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2547 | << " to " << result_type; |
| 2548 | } |
| 2549 | } |
| 2550 | |
| 2551 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2552 | LocationSummary* locations = conversion->GetLocations(); |
| 2553 | Location out = locations->Out(); |
| 2554 | Location in = locations->InAt(0); |
| 2555 | Primitive::Type result_type = conversion->GetResultType(); |
| 2556 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2557 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2558 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2559 | case Primitive::kPrimByte: |
| 2560 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame^] | 2561 | case Primitive::kPrimLong: |
| 2562 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2563 | case Primitive::kPrimBoolean: |
| 2564 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2565 | case Primitive::kPrimShort: |
| 2566 | case Primitive::kPrimInt: |
| 2567 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2568 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2569 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2570 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame^] | 2571 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2572 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2573 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2574 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2575 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame^] | 2576 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2577 | } |
| 2578 | break; |
| 2579 | |
| 2580 | default: |
| 2581 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2582 | << " to " << result_type; |
| 2583 | } |
| 2584 | break; |
| 2585 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2586 | case Primitive::kPrimShort: |
| 2587 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame^] | 2588 | case Primitive::kPrimLong: |
| 2589 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2590 | case Primitive::kPrimBoolean: |
| 2591 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2592 | case Primitive::kPrimByte: |
| 2593 | case Primitive::kPrimInt: |
| 2594 | case Primitive::kPrimChar: |
| 2595 | // Processing a Dex `int-to-short' instruction. |
| 2596 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2597 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame^] | 2598 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2599 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2600 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2601 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2602 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame^] | 2603 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2604 | } |
| 2605 | break; |
| 2606 | |
| 2607 | default: |
| 2608 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2609 | << " to " << result_type; |
| 2610 | } |
| 2611 | break; |
| 2612 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2613 | case Primitive::kPrimInt: |
| 2614 | switch (input_type) { |
| 2615 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2616 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2617 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2618 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2619 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2620 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2621 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2622 | } else { |
| 2623 | DCHECK(in.IsConstant()); |
| 2624 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2625 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2626 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2627 | } |
| 2628 | break; |
| 2629 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2630 | case Primitive::kPrimFloat: { |
| 2631 | // Processing a Dex `float-to-int' instruction. |
| 2632 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2633 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2634 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2635 | |
| 2636 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2637 | // if input >= (float)INT_MAX goto done |
| 2638 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2639 | __ j(kAboveEqual, &done); |
| 2640 | // if input == NaN goto nan |
| 2641 | __ j(kUnordered, &nan); |
| 2642 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2643 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2644 | __ jmp(&done); |
| 2645 | __ Bind(&nan); |
| 2646 | // output = 0 |
| 2647 | __ xorl(output, output); |
| 2648 | __ Bind(&done); |
| 2649 | break; |
| 2650 | } |
| 2651 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2652 | case Primitive::kPrimDouble: { |
| 2653 | // Processing a Dex `double-to-int' instruction. |
| 2654 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2655 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2656 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2657 | |
| 2658 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2659 | // if input >= (double)INT_MAX goto done |
| 2660 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2661 | __ j(kAboveEqual, &done); |
| 2662 | // if input == NaN goto nan |
| 2663 | __ j(kUnordered, &nan); |
| 2664 | // output = double-to-int-truncate(input) |
| 2665 | __ cvttsd2si(output, input); |
| 2666 | __ jmp(&done); |
| 2667 | __ Bind(&nan); |
| 2668 | // output = 0 |
| 2669 | __ xorl(output, output); |
| 2670 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2671 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2672 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2673 | |
| 2674 | default: |
| 2675 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2676 | << " to " << result_type; |
| 2677 | } |
| 2678 | break; |
| 2679 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2680 | case Primitive::kPrimLong: |
| 2681 | switch (input_type) { |
| 2682 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2683 | case Primitive::kPrimBoolean: |
| 2684 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2685 | case Primitive::kPrimByte: |
| 2686 | case Primitive::kPrimShort: |
| 2687 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2688 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2689 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2690 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2691 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2692 | break; |
| 2693 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2694 | case Primitive::kPrimFloat: { |
| 2695 | // Processing a Dex `float-to-long' instruction. |
| 2696 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2697 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2698 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2699 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2700 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2701 | // if input >= (float)LONG_MAX goto done |
| 2702 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2703 | __ j(kAboveEqual, &done); |
| 2704 | // if input == NaN goto nan |
| 2705 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2706 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2707 | __ cvttss2si(output, input, true); |
| 2708 | __ jmp(&done); |
| 2709 | __ Bind(&nan); |
| 2710 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2711 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2712 | __ Bind(&done); |
| 2713 | break; |
| 2714 | } |
| 2715 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2716 | case Primitive::kPrimDouble: { |
| 2717 | // Processing a Dex `double-to-long' instruction. |
| 2718 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2719 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2720 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2721 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2722 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2723 | // if input >= (double)LONG_MAX goto done |
| 2724 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2725 | __ j(kAboveEqual, &done); |
| 2726 | // if input == NaN goto nan |
| 2727 | __ j(kUnordered, &nan); |
| 2728 | // output = double-to-long-truncate(input) |
| 2729 | __ cvttsd2si(output, input, true); |
| 2730 | __ jmp(&done); |
| 2731 | __ Bind(&nan); |
| 2732 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2733 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2734 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2735 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2736 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2737 | |
| 2738 | default: |
| 2739 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2740 | << " to " << result_type; |
| 2741 | } |
| 2742 | break; |
| 2743 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2744 | case Primitive::kPrimChar: |
| 2745 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame^] | 2746 | case Primitive::kPrimLong: |
| 2747 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2748 | case Primitive::kPrimBoolean: |
| 2749 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2750 | case Primitive::kPrimByte: |
| 2751 | case Primitive::kPrimShort: |
| 2752 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2753 | // Processing a Dex `int-to-char' instruction. |
| 2754 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2755 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame^] | 2756 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2757 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2758 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2759 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2760 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame^] | 2761 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2762 | } |
| 2763 | break; |
| 2764 | |
| 2765 | default: |
| 2766 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2767 | << " to " << result_type; |
| 2768 | } |
| 2769 | break; |
| 2770 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2771 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2772 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2773 | case Primitive::kPrimBoolean: |
| 2774 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2775 | case Primitive::kPrimByte: |
| 2776 | case Primitive::kPrimShort: |
| 2777 | case Primitive::kPrimInt: |
| 2778 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2779 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2780 | if (in.IsRegister()) { |
| 2781 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2782 | } else if (in.IsConstant()) { |
| 2783 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2784 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2785 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2786 | } else { |
| 2787 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2788 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2789 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2790 | break; |
| 2791 | |
| 2792 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2793 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2794 | if (in.IsRegister()) { |
| 2795 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2796 | } else if (in.IsConstant()) { |
| 2797 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2798 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2799 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2800 | } else { |
| 2801 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2802 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2803 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2804 | break; |
| 2805 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2806 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2807 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2808 | if (in.IsFpuRegister()) { |
| 2809 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2810 | } else if (in.IsConstant()) { |
| 2811 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2812 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2813 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2814 | } else { |
| 2815 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2816 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2817 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2818 | break; |
| 2819 | |
| 2820 | default: |
| 2821 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2822 | << " to " << result_type; |
| 2823 | }; |
| 2824 | break; |
| 2825 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2826 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2827 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2828 | case Primitive::kPrimBoolean: |
| 2829 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2830 | case Primitive::kPrimByte: |
| 2831 | case Primitive::kPrimShort: |
| 2832 | case Primitive::kPrimInt: |
| 2833 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2834 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2835 | if (in.IsRegister()) { |
| 2836 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2837 | } else if (in.IsConstant()) { |
| 2838 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2839 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2840 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2841 | } else { |
| 2842 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2843 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2844 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2845 | break; |
| 2846 | |
| 2847 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2848 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2849 | if (in.IsRegister()) { |
| 2850 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2851 | } else if (in.IsConstant()) { |
| 2852 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2853 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2854 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2855 | } else { |
| 2856 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2857 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2858 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2859 | break; |
| 2860 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2861 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2862 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2863 | if (in.IsFpuRegister()) { |
| 2864 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2865 | } else if (in.IsConstant()) { |
| 2866 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 2867 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2868 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2869 | } else { |
| 2870 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 2871 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2872 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2873 | break; |
| 2874 | |
| 2875 | default: |
| 2876 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2877 | << " to " << result_type; |
| 2878 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2879 | break; |
| 2880 | |
| 2881 | default: |
| 2882 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2883 | << " to " << result_type; |
| 2884 | } |
| 2885 | } |
| 2886 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2887 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2888 | LocationSummary* locations = |
| 2889 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2890 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2891 | case Primitive::kPrimInt: { |
| 2892 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2893 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2894 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2895 | break; |
| 2896 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2897 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2898 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2899 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2900 | // 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] | 2901 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2902 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2903 | break; |
| 2904 | } |
| 2905 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2906 | case Primitive::kPrimDouble: |
| 2907 | case Primitive::kPrimFloat: { |
| 2908 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2909 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2910 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2911 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2912 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2913 | |
| 2914 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2915 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2916 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 2920 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2921 | Location first = locations->InAt(0); |
| 2922 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2923 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2924 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2925 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2926 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2927 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2928 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2929 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2930 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2931 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2932 | } else { |
| 2933 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2934 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2935 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2936 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2937 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2938 | __ addl(out.AsRegister<CpuRegister>(), |
| 2939 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 2940 | } else { |
| 2941 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2942 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 2943 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2944 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2945 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2946 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2947 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2948 | break; |
| 2949 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2950 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2951 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2952 | if (second.IsRegister()) { |
| 2953 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2954 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2955 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2956 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2957 | } else { |
| 2958 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2959 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2960 | } |
| 2961 | } else { |
| 2962 | DCHECK(second.IsConstant()); |
| 2963 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2964 | int32_t int32_value = Low32Bits(value); |
| 2965 | DCHECK_EQ(int32_value, value); |
| 2966 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2967 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 2968 | } else { |
| 2969 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2970 | first.AsRegister<CpuRegister>(), int32_value)); |
| 2971 | } |
| 2972 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2973 | break; |
| 2974 | } |
| 2975 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2976 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2977 | if (second.IsFpuRegister()) { |
| 2978 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2979 | } else if (second.IsConstant()) { |
| 2980 | __ addss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2981 | codegen_->LiteralFloatAddress( |
| 2982 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2983 | } else { |
| 2984 | DCHECK(second.IsStackSlot()); |
| 2985 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2986 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2987 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2988 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2989 | } |
| 2990 | |
| 2991 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2992 | if (second.IsFpuRegister()) { |
| 2993 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2994 | } else if (second.IsConstant()) { |
| 2995 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2996 | codegen_->LiteralDoubleAddress( |
| 2997 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2998 | } else { |
| 2999 | DCHECK(second.IsDoubleStackSlot()); |
| 3000 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3001 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3002 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3003 | break; |
| 3004 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3005 | |
| 3006 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3007 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3008 | } |
| 3009 | } |
| 3010 | |
| 3011 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3012 | LocationSummary* locations = |
| 3013 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3014 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3015 | case Primitive::kPrimInt: { |
| 3016 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3017 | locations->SetInAt(1, Location::Any()); |
| 3018 | locations->SetOut(Location::SameAsFirstInput()); |
| 3019 | break; |
| 3020 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3021 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3022 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 3023 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3024 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3025 | break; |
| 3026 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3027 | case Primitive::kPrimFloat: |
| 3028 | case Primitive::kPrimDouble: { |
| 3029 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3030 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3031 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3032 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3033 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3034 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3035 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3036 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3037 | } |
| 3038 | |
| 3039 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3040 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3041 | Location first = locations->InAt(0); |
| 3042 | Location second = locations->InAt(1); |
| 3043 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3044 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3045 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3046 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3047 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3048 | } else if (second.IsConstant()) { |
| 3049 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3050 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3051 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3052 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3053 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3054 | break; |
| 3055 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3056 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3057 | if (second.IsConstant()) { |
| 3058 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3059 | DCHECK(IsInt<32>(value)); |
| 3060 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3061 | } else { |
| 3062 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3063 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3064 | break; |
| 3065 | } |
| 3066 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3067 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3068 | if (second.IsFpuRegister()) { |
| 3069 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3070 | } else if (second.IsConstant()) { |
| 3071 | __ subss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3072 | codegen_->LiteralFloatAddress( |
| 3073 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3074 | } else { |
| 3075 | DCHECK(second.IsStackSlot()); |
| 3076 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3077 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3078 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3079 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3080 | } |
| 3081 | |
| 3082 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3083 | if (second.IsFpuRegister()) { |
| 3084 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3085 | } else if (second.IsConstant()) { |
| 3086 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3087 | codegen_->LiteralDoubleAddress( |
| 3088 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3089 | } else { |
| 3090 | DCHECK(second.IsDoubleStackSlot()); |
| 3091 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3092 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3093 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3094 | break; |
| 3095 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3096 | |
| 3097 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3098 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3099 | } |
| 3100 | } |
| 3101 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3102 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3103 | LocationSummary* locations = |
| 3104 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3105 | switch (mul->GetResultType()) { |
| 3106 | case Primitive::kPrimInt: { |
| 3107 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3108 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3109 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3110 | // Can use 3 operand multiply. |
| 3111 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3112 | } else { |
| 3113 | locations->SetOut(Location::SameAsFirstInput()); |
| 3114 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3115 | break; |
| 3116 | } |
| 3117 | case Primitive::kPrimLong: { |
| 3118 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3119 | locations->SetInAt(1, Location::Any()); |
| 3120 | if (mul->InputAt(1)->IsLongConstant() && |
| 3121 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3122 | // Can use 3 operand multiply. |
| 3123 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3124 | } else { |
| 3125 | locations->SetOut(Location::SameAsFirstInput()); |
| 3126 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3127 | break; |
| 3128 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3129 | case Primitive::kPrimFloat: |
| 3130 | case Primitive::kPrimDouble: { |
| 3131 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3132 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3133 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3134 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3135 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3136 | |
| 3137 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3138 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3139 | } |
| 3140 | } |
| 3141 | |
| 3142 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3143 | LocationSummary* locations = mul->GetLocations(); |
| 3144 | Location first = locations->InAt(0); |
| 3145 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3146 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3147 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3148 | case Primitive::kPrimInt: |
| 3149 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3150 | // problems where the output may not be the same as the first operand. |
| 3151 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3152 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3153 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3154 | } else if (second.IsRegister()) { |
| 3155 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3156 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3157 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3158 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3159 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3160 | __ imull(first.AsRegister<CpuRegister>(), |
| 3161 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3162 | } |
| 3163 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3164 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3165 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3166 | // problems where the output may not be the same as the first operand. |
| 3167 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3168 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3169 | if (IsInt<32>(value)) { |
| 3170 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3171 | Immediate(static_cast<int32_t>(value))); |
| 3172 | } else { |
| 3173 | // Have to use the constant area. |
| 3174 | DCHECK(first.Equals(out)); |
| 3175 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3176 | } |
| 3177 | } else if (second.IsRegister()) { |
| 3178 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3179 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3180 | } else { |
| 3181 | DCHECK(second.IsDoubleStackSlot()); |
| 3182 | DCHECK(first.Equals(out)); |
| 3183 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3184 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3185 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3186 | break; |
| 3187 | } |
| 3188 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3189 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3190 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3191 | if (second.IsFpuRegister()) { |
| 3192 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3193 | } else if (second.IsConstant()) { |
| 3194 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3195 | codegen_->LiteralFloatAddress( |
| 3196 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3197 | } else { |
| 3198 | DCHECK(second.IsStackSlot()); |
| 3199 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3200 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3201 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3202 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3203 | } |
| 3204 | |
| 3205 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3206 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3207 | if (second.IsFpuRegister()) { |
| 3208 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3209 | } else if (second.IsConstant()) { |
| 3210 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3211 | codegen_->LiteralDoubleAddress( |
| 3212 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3213 | } else { |
| 3214 | DCHECK(second.IsDoubleStackSlot()); |
| 3215 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3216 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3217 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3218 | break; |
| 3219 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3220 | |
| 3221 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3222 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3223 | } |
| 3224 | } |
| 3225 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3226 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3227 | uint32_t stack_adjustment, bool is_float) { |
| 3228 | if (source.IsStackSlot()) { |
| 3229 | DCHECK(is_float); |
| 3230 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3231 | } else if (source.IsDoubleStackSlot()) { |
| 3232 | DCHECK(!is_float); |
| 3233 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3234 | } else { |
| 3235 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3236 | if (is_float) { |
| 3237 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3238 | codegen_->Move(stack_temp, source); |
| 3239 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3240 | } else { |
| 3241 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3242 | codegen_->Move(stack_temp, source); |
| 3243 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3244 | } |
| 3245 | } |
| 3246 | } |
| 3247 | |
| 3248 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 3249 | Primitive::Type type = rem->GetResultType(); |
| 3250 | bool is_float = type == Primitive::kPrimFloat; |
| 3251 | size_t elem_size = Primitive::ComponentSize(type); |
| 3252 | LocationSummary* locations = rem->GetLocations(); |
| 3253 | Location first = locations->InAt(0); |
| 3254 | Location second = locations->InAt(1); |
| 3255 | Location out = locations->Out(); |
| 3256 | |
| 3257 | // Create stack space for 2 elements. |
| 3258 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3259 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3260 | |
| 3261 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3262 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3263 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3264 | |
| 3265 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3266 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3267 | __ Bind(&retry); |
| 3268 | __ fprem(); |
| 3269 | |
| 3270 | // Move FP status to AX. |
| 3271 | __ fstsw(); |
| 3272 | |
| 3273 | // And see if the argument reduction is complete. This is signaled by the |
| 3274 | // C2 FPU flag bit set to 0. |
| 3275 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3276 | __ j(kNotEqual, &retry); |
| 3277 | |
| 3278 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3279 | // Store FP top of stack to real stack. |
| 3280 | if (is_float) { |
| 3281 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3282 | } else { |
| 3283 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3284 | } |
| 3285 | |
| 3286 | // Pop the 2 items from the FP stack. |
| 3287 | __ fucompp(); |
| 3288 | |
| 3289 | // Load the value from the stack into an XMM register. |
| 3290 | DCHECK(out.IsFpuRegister()) << out; |
| 3291 | if (is_float) { |
| 3292 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3293 | } else { |
| 3294 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3295 | } |
| 3296 | |
| 3297 | // And remove the temporary stack space we allocated. |
| 3298 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3299 | } |
| 3300 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3301 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3302 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3303 | |
| 3304 | LocationSummary* locations = instruction->GetLocations(); |
| 3305 | Location second = locations->InAt(1); |
| 3306 | DCHECK(second.IsConstant()); |
| 3307 | |
| 3308 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3309 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3310 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3311 | |
| 3312 | DCHECK(imm == 1 || imm == -1); |
| 3313 | |
| 3314 | switch (instruction->GetResultType()) { |
| 3315 | case Primitive::kPrimInt: { |
| 3316 | if (instruction->IsRem()) { |
| 3317 | __ xorl(output_register, output_register); |
| 3318 | } else { |
| 3319 | __ movl(output_register, input_register); |
| 3320 | if (imm == -1) { |
| 3321 | __ negl(output_register); |
| 3322 | } |
| 3323 | } |
| 3324 | break; |
| 3325 | } |
| 3326 | |
| 3327 | case Primitive::kPrimLong: { |
| 3328 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3329 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3330 | } else { |
| 3331 | __ movq(output_register, input_register); |
| 3332 | if (imm == -1) { |
| 3333 | __ negq(output_register); |
| 3334 | } |
| 3335 | } |
| 3336 | break; |
| 3337 | } |
| 3338 | |
| 3339 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3340 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3341 | } |
| 3342 | } |
| 3343 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3344 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3345 | LocationSummary* locations = instruction->GetLocations(); |
| 3346 | Location second = locations->InAt(1); |
| 3347 | |
| 3348 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3349 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3350 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3351 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3352 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3353 | uint64_t abs_imm = AbsOrMin(imm); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3354 | |
| 3355 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3356 | |
| 3357 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3358 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3359 | __ testl(numerator, numerator); |
| 3360 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3361 | int shift = CTZ(imm); |
| 3362 | __ sarl(tmp, Immediate(shift)); |
| 3363 | |
| 3364 | if (imm < 0) { |
| 3365 | __ negl(tmp); |
| 3366 | } |
| 3367 | |
| 3368 | __ movl(output_register, tmp); |
| 3369 | } else { |
| 3370 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3371 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3372 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3373 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3374 | __ addq(rdx, numerator); |
| 3375 | __ testq(numerator, numerator); |
| 3376 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3377 | int shift = CTZ(imm); |
| 3378 | __ sarq(rdx, Immediate(shift)); |
| 3379 | |
| 3380 | if (imm < 0) { |
| 3381 | __ negq(rdx); |
| 3382 | } |
| 3383 | |
| 3384 | __ movq(output_register, rdx); |
| 3385 | } |
| 3386 | } |
| 3387 | |
| 3388 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3389 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3390 | |
| 3391 | LocationSummary* locations = instruction->GetLocations(); |
| 3392 | Location second = locations->InAt(1); |
| 3393 | |
| 3394 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3395 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3396 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3397 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3398 | : locations->Out().AsRegister<CpuRegister>(); |
| 3399 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3400 | |
| 3401 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3402 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3403 | if (instruction->IsDiv()) { |
| 3404 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3405 | } else { |
| 3406 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3407 | } |
| 3408 | |
| 3409 | int64_t magic; |
| 3410 | int shift; |
| 3411 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3412 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3413 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3414 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3415 | |
| 3416 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3417 | |
| 3418 | __ movl(numerator, eax); |
| 3419 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3420 | NearLabel no_div; |
| 3421 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3422 | __ testl(eax, eax); |
| 3423 | __ j(kNotEqual, &no_div); |
| 3424 | |
| 3425 | __ xorl(out, out); |
| 3426 | __ jmp(&end); |
| 3427 | |
| 3428 | __ Bind(&no_div); |
| 3429 | |
| 3430 | __ movl(eax, Immediate(magic)); |
| 3431 | __ imull(numerator); |
| 3432 | |
| 3433 | if (imm > 0 && magic < 0) { |
| 3434 | __ addl(edx, numerator); |
| 3435 | } else if (imm < 0 && magic > 0) { |
| 3436 | __ subl(edx, numerator); |
| 3437 | } |
| 3438 | |
| 3439 | if (shift != 0) { |
| 3440 | __ sarl(edx, Immediate(shift)); |
| 3441 | } |
| 3442 | |
| 3443 | __ movl(eax, edx); |
| 3444 | __ shrl(edx, Immediate(31)); |
| 3445 | __ addl(edx, eax); |
| 3446 | |
| 3447 | if (instruction->IsRem()) { |
| 3448 | __ movl(eax, numerator); |
| 3449 | __ imull(edx, Immediate(imm)); |
| 3450 | __ subl(eax, edx); |
| 3451 | __ movl(edx, eax); |
| 3452 | } else { |
| 3453 | __ movl(eax, edx); |
| 3454 | } |
| 3455 | __ Bind(&end); |
| 3456 | } else { |
| 3457 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3458 | |
| 3459 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3460 | |
| 3461 | CpuRegister rax = eax; |
| 3462 | CpuRegister rdx = edx; |
| 3463 | |
| 3464 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3465 | |
| 3466 | // Save the numerator. |
| 3467 | __ movq(numerator, rax); |
| 3468 | |
| 3469 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3470 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3471 | |
| 3472 | // RDX:RAX = magic * numerator |
| 3473 | __ imulq(numerator); |
| 3474 | |
| 3475 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3476 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3477 | __ addq(rdx, numerator); |
| 3478 | } else if (imm < 0 && magic > 0) { |
| 3479 | // RDX -= numerator |
| 3480 | __ subq(rdx, numerator); |
| 3481 | } |
| 3482 | |
| 3483 | // Shift if needed. |
| 3484 | if (shift != 0) { |
| 3485 | __ sarq(rdx, Immediate(shift)); |
| 3486 | } |
| 3487 | |
| 3488 | // RDX += 1 if RDX < 0 |
| 3489 | __ movq(rax, rdx); |
| 3490 | __ shrq(rdx, Immediate(63)); |
| 3491 | __ addq(rdx, rax); |
| 3492 | |
| 3493 | if (instruction->IsRem()) { |
| 3494 | __ movq(rax, numerator); |
| 3495 | |
| 3496 | if (IsInt<32>(imm)) { |
| 3497 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3498 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3499 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3500 | } |
| 3501 | |
| 3502 | __ subq(rax, rdx); |
| 3503 | __ movq(rdx, rax); |
| 3504 | } else { |
| 3505 | __ movq(rax, rdx); |
| 3506 | } |
| 3507 | } |
| 3508 | } |
| 3509 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3510 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3511 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3512 | Primitive::Type type = instruction->GetResultType(); |
| 3513 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3514 | |
| 3515 | bool is_div = instruction->IsDiv(); |
| 3516 | LocationSummary* locations = instruction->GetLocations(); |
| 3517 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3518 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3519 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3520 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3521 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3522 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3523 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3524 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3525 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3526 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3527 | if (imm == 0) { |
| 3528 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3529 | } else if (imm == 1 || imm == -1) { |
| 3530 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3531 | } else if (instruction->IsDiv() && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3532 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3533 | } else { |
| 3534 | DCHECK(imm <= -2 || imm >= 2); |
| 3535 | GenerateDivRemWithAnyConstant(instruction); |
| 3536 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3537 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3538 | SlowPathCode* slow_path = |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3539 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
| 3540 | out.AsRegister(), type, is_div); |
| 3541 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3542 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3543 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3544 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3545 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3546 | // so it's safe to just use negl instead of more complex comparisons. |
| 3547 | if (type == Primitive::kPrimInt) { |
| 3548 | __ cmpl(second_reg, Immediate(-1)); |
| 3549 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3550 | // edx:eax <- sign-extended of eax |
| 3551 | __ cdq(); |
| 3552 | // eax = quotient, edx = remainder |
| 3553 | __ idivl(second_reg); |
| 3554 | } else { |
| 3555 | __ cmpq(second_reg, Immediate(-1)); |
| 3556 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3557 | // rdx:rax <- sign-extended of rax |
| 3558 | __ cqo(); |
| 3559 | // rax = quotient, rdx = remainder |
| 3560 | __ idivq(second_reg); |
| 3561 | } |
| 3562 | __ Bind(slow_path->GetExitLabel()); |
| 3563 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3564 | } |
| 3565 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3566 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3567 | LocationSummary* locations = |
| 3568 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3569 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3570 | case Primitive::kPrimInt: |
| 3571 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3572 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3573 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3574 | locations->SetOut(Location::SameAsFirstInput()); |
| 3575 | // Intel uses edx:eax as the dividend. |
| 3576 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3577 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3578 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3579 | // output and request another temp. |
| 3580 | if (div->InputAt(1)->IsConstant()) { |
| 3581 | locations->AddTemp(Location::RequiresRegister()); |
| 3582 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3583 | break; |
| 3584 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3585 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3586 | case Primitive::kPrimFloat: |
| 3587 | case Primitive::kPrimDouble: { |
| 3588 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3589 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3590 | locations->SetOut(Location::SameAsFirstInput()); |
| 3591 | break; |
| 3592 | } |
| 3593 | |
| 3594 | default: |
| 3595 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3596 | } |
| 3597 | } |
| 3598 | |
| 3599 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3600 | LocationSummary* locations = div->GetLocations(); |
| 3601 | Location first = locations->InAt(0); |
| 3602 | Location second = locations->InAt(1); |
| 3603 | DCHECK(first.Equals(locations->Out())); |
| 3604 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3605 | Primitive::Type type = div->GetResultType(); |
| 3606 | switch (type) { |
| 3607 | case Primitive::kPrimInt: |
| 3608 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3609 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3610 | break; |
| 3611 | } |
| 3612 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3613 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3614 | if (second.IsFpuRegister()) { |
| 3615 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3616 | } else if (second.IsConstant()) { |
| 3617 | __ divss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3618 | codegen_->LiteralFloatAddress( |
| 3619 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3620 | } else { |
| 3621 | DCHECK(second.IsStackSlot()); |
| 3622 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3623 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3624 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3625 | break; |
| 3626 | } |
| 3627 | |
| 3628 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3629 | if (second.IsFpuRegister()) { |
| 3630 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3631 | } else if (second.IsConstant()) { |
| 3632 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3633 | codegen_->LiteralDoubleAddress( |
| 3634 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3635 | } else { |
| 3636 | DCHECK(second.IsDoubleStackSlot()); |
| 3637 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3638 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3639 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3640 | break; |
| 3641 | } |
| 3642 | |
| 3643 | default: |
| 3644 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3645 | } |
| 3646 | } |
| 3647 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3648 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3649 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3650 | LocationSummary* locations = |
| 3651 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3652 | |
| 3653 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3654 | case Primitive::kPrimInt: |
| 3655 | case Primitive::kPrimLong: { |
| 3656 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3657 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3658 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3659 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3660 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3661 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3662 | // output and request another temp. |
| 3663 | if (rem->InputAt(1)->IsConstant()) { |
| 3664 | locations->AddTemp(Location::RequiresRegister()); |
| 3665 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3666 | break; |
| 3667 | } |
| 3668 | |
| 3669 | case Primitive::kPrimFloat: |
| 3670 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3671 | locations->SetInAt(0, Location::Any()); |
| 3672 | locations->SetInAt(1, Location::Any()); |
| 3673 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3674 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3675 | break; |
| 3676 | } |
| 3677 | |
| 3678 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3679 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3680 | } |
| 3681 | } |
| 3682 | |
| 3683 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3684 | Primitive::Type type = rem->GetResultType(); |
| 3685 | switch (type) { |
| 3686 | case Primitive::kPrimInt: |
| 3687 | case Primitive::kPrimLong: { |
| 3688 | GenerateDivRemIntegral(rem); |
| 3689 | break; |
| 3690 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3691 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3692 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3693 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3694 | break; |
| 3695 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3696 | default: |
| 3697 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3698 | } |
| 3699 | } |
| 3700 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3701 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3702 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3703 | ? LocationSummary::kCallOnSlowPath |
| 3704 | : LocationSummary::kNoCall; |
| 3705 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3706 | locations->SetInAt(0, Location::Any()); |
| 3707 | if (instruction->HasUses()) { |
| 3708 | locations->SetOut(Location::SameAsFirstInput()); |
| 3709 | } |
| 3710 | } |
| 3711 | |
| 3712 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3713 | SlowPathCode* slow_path = |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3714 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3715 | codegen_->AddSlowPath(slow_path); |
| 3716 | |
| 3717 | LocationSummary* locations = instruction->GetLocations(); |
| 3718 | Location value = locations->InAt(0); |
| 3719 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3720 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3721 | case Primitive::kPrimByte: |
| 3722 | case Primitive::kPrimChar: |
| 3723 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3724 | case Primitive::kPrimInt: { |
| 3725 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3726 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3727 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3728 | } else if (value.IsStackSlot()) { |
| 3729 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3730 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3731 | } else { |
| 3732 | DCHECK(value.IsConstant()) << value; |
| 3733 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3734 | __ jmp(slow_path->GetEntryLabel()); |
| 3735 | } |
| 3736 | } |
| 3737 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3738 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3739 | case Primitive::kPrimLong: { |
| 3740 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3741 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3742 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3743 | } else if (value.IsDoubleStackSlot()) { |
| 3744 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3745 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3746 | } else { |
| 3747 | DCHECK(value.IsConstant()) << value; |
| 3748 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3749 | __ jmp(slow_path->GetEntryLabel()); |
| 3750 | } |
| 3751 | } |
| 3752 | break; |
| 3753 | } |
| 3754 | default: |
| 3755 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3756 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3757 | } |
| 3758 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3759 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3760 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3761 | |
| 3762 | LocationSummary* locations = |
| 3763 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3764 | |
| 3765 | switch (op->GetResultType()) { |
| 3766 | case Primitive::kPrimInt: |
| 3767 | case Primitive::kPrimLong: { |
| 3768 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3769 | // The shift count needs to be in CL. |
| 3770 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3771 | locations->SetOut(Location::SameAsFirstInput()); |
| 3772 | break; |
| 3773 | } |
| 3774 | default: |
| 3775 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3776 | } |
| 3777 | } |
| 3778 | |
| 3779 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3780 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3781 | |
| 3782 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3783 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3784 | Location second = locations->InAt(1); |
| 3785 | |
| 3786 | switch (op->GetResultType()) { |
| 3787 | case Primitive::kPrimInt: { |
| 3788 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3789 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3790 | if (op->IsShl()) { |
| 3791 | __ shll(first_reg, second_reg); |
| 3792 | } else if (op->IsShr()) { |
| 3793 | __ sarl(first_reg, second_reg); |
| 3794 | } else { |
| 3795 | __ shrl(first_reg, second_reg); |
| 3796 | } |
| 3797 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3798 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3799 | if (op->IsShl()) { |
| 3800 | __ shll(first_reg, imm); |
| 3801 | } else if (op->IsShr()) { |
| 3802 | __ sarl(first_reg, imm); |
| 3803 | } else { |
| 3804 | __ shrl(first_reg, imm); |
| 3805 | } |
| 3806 | } |
| 3807 | break; |
| 3808 | } |
| 3809 | case Primitive::kPrimLong: { |
| 3810 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3811 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3812 | if (op->IsShl()) { |
| 3813 | __ shlq(first_reg, second_reg); |
| 3814 | } else if (op->IsShr()) { |
| 3815 | __ sarq(first_reg, second_reg); |
| 3816 | } else { |
| 3817 | __ shrq(first_reg, second_reg); |
| 3818 | } |
| 3819 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3820 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3821 | if (op->IsShl()) { |
| 3822 | __ shlq(first_reg, imm); |
| 3823 | } else if (op->IsShr()) { |
| 3824 | __ sarq(first_reg, imm); |
| 3825 | } else { |
| 3826 | __ shrq(first_reg, imm); |
| 3827 | } |
| 3828 | } |
| 3829 | break; |
| 3830 | } |
| 3831 | default: |
| 3832 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3833 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3834 | } |
| 3835 | } |
| 3836 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3837 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 3838 | LocationSummary* locations = |
| 3839 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3840 | |
| 3841 | switch (ror->GetResultType()) { |
| 3842 | case Primitive::kPrimInt: |
| 3843 | case Primitive::kPrimLong: { |
| 3844 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3845 | // The shift count needs to be in CL (unless it is a constant). |
| 3846 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 3847 | locations->SetOut(Location::SameAsFirstInput()); |
| 3848 | break; |
| 3849 | } |
| 3850 | default: |
| 3851 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3852 | UNREACHABLE(); |
| 3853 | } |
| 3854 | } |
| 3855 | |
| 3856 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 3857 | LocationSummary* locations = ror->GetLocations(); |
| 3858 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3859 | Location second = locations->InAt(1); |
| 3860 | |
| 3861 | switch (ror->GetResultType()) { |
| 3862 | case Primitive::kPrimInt: |
| 3863 | if (second.IsRegister()) { |
| 3864 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3865 | __ rorl(first_reg, second_reg); |
| 3866 | } else { |
| 3867 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
| 3868 | __ rorl(first_reg, imm); |
| 3869 | } |
| 3870 | break; |
| 3871 | case Primitive::kPrimLong: |
| 3872 | if (second.IsRegister()) { |
| 3873 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3874 | __ rorq(first_reg, second_reg); |
| 3875 | } else { |
| 3876 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue); |
| 3877 | __ rorq(first_reg, imm); |
| 3878 | } |
| 3879 | break; |
| 3880 | default: |
| 3881 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3882 | UNREACHABLE(); |
| 3883 | } |
| 3884 | } |
| 3885 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3886 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 3887 | HandleShift(shl); |
| 3888 | } |
| 3889 | |
| 3890 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 3891 | HandleShift(shl); |
| 3892 | } |
| 3893 | |
| 3894 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 3895 | HandleShift(shr); |
| 3896 | } |
| 3897 | |
| 3898 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 3899 | HandleShift(shr); |
| 3900 | } |
| 3901 | |
| 3902 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 3903 | HandleShift(ushr); |
| 3904 | } |
| 3905 | |
| 3906 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 3907 | HandleShift(ushr); |
| 3908 | } |
| 3909 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3910 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3911 | LocationSummary* locations = |
| 3912 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3913 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3914 | if (instruction->IsStringAlloc()) { |
| 3915 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3916 | } else { |
| 3917 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3918 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3919 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3920 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3921 | } |
| 3922 | |
| 3923 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3924 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3925 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3926 | if (instruction->IsStringAlloc()) { |
| 3927 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3928 | CpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
| 3929 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64WordSize); |
| 3930 | __ gs()->movq(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString), /* no_rip */ true)); |
| 3931 | __ call(Address(temp, code_offset.SizeValue())); |
| 3932 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3933 | } else { |
| 3934 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3935 | instruction, |
| 3936 | instruction->GetDexPc(), |
| 3937 | nullptr); |
| 3938 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3939 | DCHECK(!codegen_->IsLeafMethod()); |
| 3940 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3941 | } |
| 3942 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3943 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 3944 | LocationSummary* locations = |
| 3945 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3946 | InvokeRuntimeCallingConvention calling_convention; |
| 3947 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3948 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3949 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3950 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3951 | } |
| 3952 | |
| 3953 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 3954 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3955 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3956 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3957 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3958 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3959 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3960 | instruction, |
| 3961 | instruction->GetDexPc(), |
| 3962 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3963 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3964 | |
| 3965 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3966 | } |
| 3967 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3968 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3969 | LocationSummary* locations = |
| 3970 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3971 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3972 | if (location.IsStackSlot()) { |
| 3973 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3974 | } else if (location.IsDoubleStackSlot()) { |
| 3975 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3976 | } |
| 3977 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3978 | } |
| 3979 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3980 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 3981 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3982 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3983 | } |
| 3984 | |
| 3985 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3986 | LocationSummary* locations = |
| 3987 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3988 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3989 | } |
| 3990 | |
| 3991 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 3992 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3993 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3994 | } |
| 3995 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3996 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 3997 | LocationSummary* locations = |
| 3998 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3999 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4000 | locations->SetOut(Location::RequiresRegister()); |
| 4001 | } |
| 4002 | |
| 4003 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4004 | LocationSummary* locations = instruction->GetLocations(); |
| 4005 | uint32_t method_offset = 0; |
| 4006 | if (instruction->GetTableKind() == HClassTableGet::kVTable) { |
| 4007 | method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4008 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
| 4009 | } else { |
| 4010 | method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 4011 | instruction->GetIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
| 4012 | } |
| 4013 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4014 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
| 4015 | } |
| 4016 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4017 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4018 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4019 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4020 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4021 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4022 | } |
| 4023 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4024 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 4025 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4026 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4027 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4028 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4029 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4030 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4031 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4032 | break; |
| 4033 | |
| 4034 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4035 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4036 | break; |
| 4037 | |
| 4038 | default: |
| 4039 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4040 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4041 | } |
| 4042 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4043 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4044 | LocationSummary* locations = |
| 4045 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4046 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4047 | locations->SetOut(Location::SameAsFirstInput()); |
| 4048 | } |
| 4049 | |
| 4050 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4051 | LocationSummary* locations = bool_not->GetLocations(); |
| 4052 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4053 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 4054 | Location out = locations->Out(); |
| 4055 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4056 | } |
| 4057 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4058 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4059 | LocationSummary* locations = |
| 4060 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4061 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 4062 | locations->SetInAt(i, Location::Any()); |
| 4063 | } |
| 4064 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4065 | } |
| 4066 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4067 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4068 | LOG(FATAL) << "Unimplemented"; |
| 4069 | } |
| 4070 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4071 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4072 | /* |
| 4073 | * 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] | 4074 | * 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] | 4075 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4076 | */ |
| 4077 | switch (kind) { |
| 4078 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4079 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4080 | break; |
| 4081 | } |
| 4082 | case MemBarrierKind::kAnyStore: |
| 4083 | case MemBarrierKind::kLoadAny: |
| 4084 | case MemBarrierKind::kStoreStore: { |
| 4085 | // nop |
| 4086 | break; |
| 4087 | } |
| 4088 | default: |
| 4089 | LOG(FATAL) << "Unexpected memory barier " << kind; |
| 4090 | } |
| 4091 | } |
| 4092 | |
| 4093 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4094 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4095 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4096 | bool object_field_get_with_read_barrier = |
| 4097 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4098 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4099 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4100 | object_field_get_with_read_barrier ? |
| 4101 | LocationSummary::kCallOnSlowPath : |
| 4102 | LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4103 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4104 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4105 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4106 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4107 | // The output overlaps for an object field get when read barriers |
| 4108 | // are enabled: we do not want the move to overwrite the object's |
| 4109 | // location, as we need it to emit the read barrier. |
| 4110 | locations->SetOut( |
| 4111 | Location::RequiresRegister(), |
| 4112 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4113 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4114 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4115 | // We need a temporary register for the read barrier marking slow |
| 4116 | // path in CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier. |
| 4117 | locations->AddTemp(Location::RequiresRegister()); |
| 4118 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4119 | } |
| 4120 | |
| 4121 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4122 | const FieldInfo& field_info) { |
| 4123 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4124 | |
| 4125 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4126 | Location base_loc = locations->InAt(0); |
| 4127 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4128 | Location out = locations->Out(); |
| 4129 | bool is_volatile = field_info.IsVolatile(); |
| 4130 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4131 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4132 | |
| 4133 | switch (field_type) { |
| 4134 | case Primitive::kPrimBoolean: { |
| 4135 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4136 | break; |
| 4137 | } |
| 4138 | |
| 4139 | case Primitive::kPrimByte: { |
| 4140 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4141 | break; |
| 4142 | } |
| 4143 | |
| 4144 | case Primitive::kPrimShort: { |
| 4145 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4146 | break; |
| 4147 | } |
| 4148 | |
| 4149 | case Primitive::kPrimChar: { |
| 4150 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4151 | break; |
| 4152 | } |
| 4153 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4154 | case Primitive::kPrimInt: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4155 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4156 | break; |
| 4157 | } |
| 4158 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4159 | case Primitive::kPrimNot: { |
| 4160 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4161 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4162 | Location temp_loc = locations->GetTemp(0); |
| 4163 | // Note that a potential implicit null check is handled in this |
| 4164 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4165 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4166 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4167 | if (is_volatile) { |
| 4168 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4169 | } |
| 4170 | } else { |
| 4171 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4172 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4173 | if (is_volatile) { |
| 4174 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4175 | } |
| 4176 | // If read barriers are enabled, emit read barriers other than |
| 4177 | // Baker's using a slow path (and also unpoison the loaded |
| 4178 | // reference, if heap poisoning is enabled). |
| 4179 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4180 | } |
| 4181 | break; |
| 4182 | } |
| 4183 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4184 | case Primitive::kPrimLong: { |
| 4185 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4186 | break; |
| 4187 | } |
| 4188 | |
| 4189 | case Primitive::kPrimFloat: { |
| 4190 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4191 | break; |
| 4192 | } |
| 4193 | |
| 4194 | case Primitive::kPrimDouble: { |
| 4195 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4196 | break; |
| 4197 | } |
| 4198 | |
| 4199 | case Primitive::kPrimVoid: |
| 4200 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4201 | UNREACHABLE(); |
| 4202 | } |
| 4203 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4204 | if (field_type == Primitive::kPrimNot) { |
| 4205 | // Potential implicit null checks, in the case of reference |
| 4206 | // fields, are handled in the previous switch statement. |
| 4207 | } else { |
| 4208 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4209 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4210 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4211 | if (is_volatile) { |
| 4212 | if (field_type == Primitive::kPrimNot) { |
| 4213 | // Memory barriers, in the case of references, are also handled |
| 4214 | // in the previous switch statement. |
| 4215 | } else { |
| 4216 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4217 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4218 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4219 | } |
| 4220 | |
| 4221 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4222 | const FieldInfo& field_info) { |
| 4223 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4224 | |
| 4225 | LocationSummary* locations = |
| 4226 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4227 | Primitive::Type field_type = field_info.GetFieldType(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4228 | bool is_volatile = field_info.IsVolatile(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4229 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4230 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4231 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4232 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4233 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4234 | if (is_volatile) { |
| 4235 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4236 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4237 | } else { |
| 4238 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4239 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4240 | } else { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4241 | if (is_volatile) { |
| 4242 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4243 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4244 | } else { |
| 4245 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4246 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4247 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4248 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4249 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4250 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4251 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4252 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4253 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4254 | locations->AddTemp(Location::RequiresRegister()); |
| 4255 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4256 | } |
| 4257 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4258 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4259 | const FieldInfo& field_info, |
| 4260 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4261 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4262 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4263 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4264 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4265 | Location value = locations->InAt(1); |
| 4266 | bool is_volatile = field_info.IsVolatile(); |
| 4267 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4268 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4269 | |
| 4270 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4271 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4272 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4273 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4274 | bool maybe_record_implicit_null_check_done = false; |
| 4275 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4276 | switch (field_type) { |
| 4277 | case Primitive::kPrimBoolean: |
| 4278 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4279 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4280 | int8_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4281 | __ movb(Address(base, offset), Immediate(v)); |
| 4282 | } else { |
| 4283 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4284 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4285 | break; |
| 4286 | } |
| 4287 | |
| 4288 | case Primitive::kPrimShort: |
| 4289 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4290 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4291 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4292 | __ movw(Address(base, offset), Immediate(v)); |
| 4293 | } else { |
| 4294 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4295 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4296 | break; |
| 4297 | } |
| 4298 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4299 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4300 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4301 | if (value.IsConstant()) { |
| 4302 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4303 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 4304 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 4305 | // Note: if heap poisoning is enabled, no need to poison |
| 4306 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4307 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4308 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4309 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4310 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4311 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4312 | __ PoisonHeapReference(temp); |
| 4313 | __ movl(Address(base, offset), temp); |
| 4314 | } else { |
| 4315 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4316 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4317 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4318 | break; |
| 4319 | } |
| 4320 | |
| 4321 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4322 | if (value.IsConstant()) { |
| 4323 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4324 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4325 | Address(base, offset + sizeof(int32_t)), |
| 4326 | v, |
| 4327 | instruction); |
| 4328 | maybe_record_implicit_null_check_done = true; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4329 | } else { |
| 4330 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4331 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4332 | break; |
| 4333 | } |
| 4334 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4335 | case Primitive::kPrimFloat: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4336 | if (value.IsConstant()) { |
| 4337 | int32_t v = |
| 4338 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4339 | __ movl(Address(base, offset), Immediate(v)); |
| 4340 | } else { |
| 4341 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4342 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4343 | break; |
| 4344 | } |
| 4345 | |
| 4346 | case Primitive::kPrimDouble: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4347 | if (value.IsConstant()) { |
| 4348 | int64_t v = |
| 4349 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4350 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4351 | Address(base, offset + sizeof(int32_t)), |
| 4352 | v, |
| 4353 | instruction); |
| 4354 | maybe_record_implicit_null_check_done = true; |
| 4355 | } else { |
| 4356 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4357 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4358 | break; |
| 4359 | } |
| 4360 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4361 | case Primitive::kPrimVoid: |
| 4362 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4363 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4364 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4365 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4366 | if (!maybe_record_implicit_null_check_done) { |
| 4367 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4368 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4369 | |
| 4370 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4371 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4372 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4373 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4374 | } |
| 4375 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4376 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4377 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4378 | } |
| 4379 | } |
| 4380 | |
| 4381 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4382 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4383 | } |
| 4384 | |
| 4385 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4386 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4387 | } |
| 4388 | |
| 4389 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4390 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4391 | } |
| 4392 | |
| 4393 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4394 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4395 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4396 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4397 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4398 | HandleFieldGet(instruction); |
| 4399 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4400 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4401 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4402 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4403 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4404 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4405 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4406 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4407 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4408 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4409 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4410 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4411 | } |
| 4412 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4413 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4414 | HUnresolvedInstanceFieldGet* instruction) { |
| 4415 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4416 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4417 | instruction, instruction->GetFieldType(), calling_convention); |
| 4418 | } |
| 4419 | |
| 4420 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4421 | HUnresolvedInstanceFieldGet* instruction) { |
| 4422 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4423 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4424 | instruction->GetFieldType(), |
| 4425 | instruction->GetFieldIndex(), |
| 4426 | instruction->GetDexPc(), |
| 4427 | calling_convention); |
| 4428 | } |
| 4429 | |
| 4430 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4431 | HUnresolvedInstanceFieldSet* instruction) { |
| 4432 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4433 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4434 | instruction, instruction->GetFieldType(), calling_convention); |
| 4435 | } |
| 4436 | |
| 4437 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4438 | HUnresolvedInstanceFieldSet* instruction) { |
| 4439 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4440 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4441 | instruction->GetFieldType(), |
| 4442 | instruction->GetFieldIndex(), |
| 4443 | instruction->GetDexPc(), |
| 4444 | calling_convention); |
| 4445 | } |
| 4446 | |
| 4447 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4448 | HUnresolvedStaticFieldGet* instruction) { |
| 4449 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4450 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4451 | instruction, instruction->GetFieldType(), calling_convention); |
| 4452 | } |
| 4453 | |
| 4454 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4455 | HUnresolvedStaticFieldGet* instruction) { |
| 4456 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4457 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4458 | instruction->GetFieldType(), |
| 4459 | instruction->GetFieldIndex(), |
| 4460 | instruction->GetDexPc(), |
| 4461 | calling_convention); |
| 4462 | } |
| 4463 | |
| 4464 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4465 | HUnresolvedStaticFieldSet* instruction) { |
| 4466 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4467 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4468 | instruction, instruction->GetFieldType(), calling_convention); |
| 4469 | } |
| 4470 | |
| 4471 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4472 | HUnresolvedStaticFieldSet* instruction) { |
| 4473 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4474 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4475 | instruction->GetFieldType(), |
| 4476 | instruction->GetFieldIndex(), |
| 4477 | instruction->GetDexPc(), |
| 4478 | calling_convention); |
| 4479 | } |
| 4480 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4481 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4482 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4483 | ? LocationSummary::kCallOnSlowPath |
| 4484 | : LocationSummary::kNoCall; |
| 4485 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4486 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4487 | ? Location::RequiresRegister() |
| 4488 | : Location::Any(); |
| 4489 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4490 | if (instruction->HasUses()) { |
| 4491 | locations->SetOut(Location::SameAsFirstInput()); |
| 4492 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4493 | } |
| 4494 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4495 | void InstructionCodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4496 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4497 | return; |
| 4498 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4499 | LocationSummary* locations = instruction->GetLocations(); |
| 4500 | Location obj = locations->InAt(0); |
| 4501 | |
| 4502 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
| 4503 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4504 | } |
| 4505 | |
| 4506 | void InstructionCodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4507 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4508 | codegen_->AddSlowPath(slow_path); |
| 4509 | |
| 4510 | LocationSummary* locations = instruction->GetLocations(); |
| 4511 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4512 | |
| 4513 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4514 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4515 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4516 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4517 | } else { |
| 4518 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4519 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4520 | __ jmp(slow_path->GetEntryLabel()); |
| 4521 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4522 | } |
| 4523 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4524 | } |
| 4525 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4526 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4527 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4528 | GenerateImplicitNullCheck(instruction); |
| 4529 | } else { |
| 4530 | GenerateExplicitNullCheck(instruction); |
| 4531 | } |
| 4532 | } |
| 4533 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4534 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4535 | bool object_array_get_with_read_barrier = |
| 4536 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4537 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4538 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4539 | object_array_get_with_read_barrier ? |
| 4540 | LocationSummary::kCallOnSlowPath : |
| 4541 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4542 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4543 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4544 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4545 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4546 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4547 | // The output overlaps for an object array get when read barriers |
| 4548 | // are enabled: we do not want the move to overwrite the array's |
| 4549 | // location, as we need it to emit the read barrier. |
| 4550 | locations->SetOut( |
| 4551 | Location::RequiresRegister(), |
| 4552 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4553 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4554 | // We need a temporary register for the read barrier marking slow |
| 4555 | // path in CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier. |
| 4556 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4557 | locations->AddTemp(Location::RequiresRegister()); |
| 4558 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4559 | } |
| 4560 | |
| 4561 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4562 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4563 | Location obj_loc = locations->InAt(0); |
| 4564 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4565 | Location index = locations->InAt(1); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4566 | Location out_loc = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4567 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4568 | Primitive::Type type = instruction->GetType(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4569 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4570 | case Primitive::kPrimBoolean: { |
| 4571 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4572 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4573 | if (index.IsConstant()) { |
| 4574 | __ movzxb(out, Address(obj, |
| 4575 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4576 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4577 | __ movzxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4578 | } |
| 4579 | break; |
| 4580 | } |
| 4581 | |
| 4582 | case Primitive::kPrimByte: { |
| 4583 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4584 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4585 | if (index.IsConstant()) { |
| 4586 | __ movsxb(out, Address(obj, |
| 4587 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4588 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4589 | __ movsxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4590 | } |
| 4591 | break; |
| 4592 | } |
| 4593 | |
| 4594 | case Primitive::kPrimShort: { |
| 4595 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4596 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4597 | if (index.IsConstant()) { |
| 4598 | __ movsxw(out, Address(obj, |
| 4599 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4600 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4601 | __ movsxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4602 | } |
| 4603 | break; |
| 4604 | } |
| 4605 | |
| 4606 | case Primitive::kPrimChar: { |
| 4607 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4608 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4609 | if (index.IsConstant()) { |
| 4610 | __ movzxw(out, Address(obj, |
| 4611 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4612 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4613 | __ movzxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4614 | } |
| 4615 | break; |
| 4616 | } |
| 4617 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4618 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4619 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4620 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4621 | if (index.IsConstant()) { |
| 4622 | __ movl(out, Address(obj, |
| 4623 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4624 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4625 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4626 | } |
| 4627 | break; |
| 4628 | } |
| 4629 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4630 | case Primitive::kPrimNot: { |
| 4631 | static_assert( |
| 4632 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4633 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 4634 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4635 | // /* HeapReference<Object> */ out = |
| 4636 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4637 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4638 | Location temp = locations->GetTemp(0); |
| 4639 | // Note that a potential implicit null check is handled in this |
| 4640 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 4641 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4642 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4643 | } else { |
| 4644 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| 4645 | if (index.IsConstant()) { |
| 4646 | uint32_t offset = |
| 4647 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4648 | __ movl(out, Address(obj, offset)); |
| 4649 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4650 | // If read barriers are enabled, emit read barriers other than |
| 4651 | // Baker's using a slow path (and also unpoison the loaded |
| 4652 | // reference, if heap poisoning is enabled). |
| 4653 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4654 | } else { |
| 4655 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
| 4656 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4657 | // If read barriers are enabled, emit read barriers other than |
| 4658 | // Baker's using a slow path (and also unpoison the loaded |
| 4659 | // reference, if heap poisoning is enabled). |
| 4660 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4661 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4662 | } |
| 4663 | } |
| 4664 | break; |
| 4665 | } |
| 4666 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4667 | case Primitive::kPrimLong: { |
| 4668 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4669 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4670 | if (index.IsConstant()) { |
| 4671 | __ movq(out, Address(obj, |
| 4672 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4673 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4674 | __ movq(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4675 | } |
| 4676 | break; |
| 4677 | } |
| 4678 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4679 | case Primitive::kPrimFloat: { |
| 4680 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4681 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4682 | if (index.IsConstant()) { |
| 4683 | __ movss(out, Address(obj, |
| 4684 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4685 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4686 | __ movss(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4687 | } |
| 4688 | break; |
| 4689 | } |
| 4690 | |
| 4691 | case Primitive::kPrimDouble: { |
| 4692 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4693 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4694 | if (index.IsConstant()) { |
| 4695 | __ movsd(out, Address(obj, |
| 4696 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4697 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4698 | __ movsd(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4699 | } |
| 4700 | break; |
| 4701 | } |
| 4702 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4703 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4704 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4705 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4706 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4707 | |
| 4708 | if (type == Primitive::kPrimNot) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4709 | // Potential implicit null checks, in the case of reference |
| 4710 | // arrays, are handled in the previous switch statement. |
| 4711 | } else { |
| 4712 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4713 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4714 | } |
| 4715 | |
| 4716 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4717 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4718 | |
| 4719 | bool needs_write_barrier = |
| 4720 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4721 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4722 | bool object_array_set_with_read_barrier = |
| 4723 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4724 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4725 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4726 | instruction, |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4727 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4728 | LocationSummary::kCallOnSlowPath : |
| 4729 | LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4730 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4731 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4732 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4733 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4734 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4735 | } else { |
| 4736 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4737 | } |
| 4738 | |
| 4739 | if (needs_write_barrier) { |
| 4740 | // Temporary registers for the write barrier. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4741 | |
| 4742 | // This first temporary register is possibly used for heap |
| 4743 | // reference poisoning and/or read barrier emission too. |
| 4744 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4745 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4746 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4747 | } |
| 4748 | |
| 4749 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4750 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4751 | Location array_loc = locations->InAt(0); |
| 4752 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4753 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4754 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4755 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4756 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4757 | bool needs_write_barrier = |
| 4758 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4759 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4760 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4761 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4762 | |
| 4763 | switch (value_type) { |
| 4764 | case Primitive::kPrimBoolean: |
| 4765 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4766 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 4767 | Address address = index.IsConstant() |
| 4768 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 4769 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_1, offset); |
| 4770 | if (value.IsRegister()) { |
| 4771 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4772 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4773 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4774 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4775 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4776 | break; |
| 4777 | } |
| 4778 | |
| 4779 | case Primitive::kPrimShort: |
| 4780 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4781 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 4782 | Address address = index.IsConstant() |
| 4783 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 4784 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_2, offset); |
| 4785 | if (value.IsRegister()) { |
| 4786 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4787 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4788 | DCHECK(value.IsConstant()) << value; |
| 4789 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4790 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4791 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4792 | break; |
| 4793 | } |
| 4794 | |
| 4795 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4796 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4797 | Address address = index.IsConstant() |
| 4798 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4799 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4800 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4801 | if (!value.IsRegister()) { |
| 4802 | // Just setting null. |
| 4803 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4804 | DCHECK(value.IsConstant()) << value; |
| 4805 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4806 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4807 | DCHECK(!needs_write_barrier); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4808 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4809 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4810 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4811 | |
| 4812 | DCHECK(needs_write_barrier); |
| 4813 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
| 4814 | NearLabel done, not_null, do_put; |
| 4815 | SlowPathCode* slow_path = nullptr; |
| 4816 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4817 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4818 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86_64(instruction); |
| 4819 | codegen_->AddSlowPath(slow_path); |
| 4820 | if (instruction->GetValueCanBeNull()) { |
| 4821 | __ testl(register_value, register_value); |
| 4822 | __ j(kNotEqual, ¬_null); |
| 4823 | __ movl(address, Immediate(0)); |
| 4824 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4825 | __ jmp(&done); |
| 4826 | __ Bind(¬_null); |
| 4827 | } |
| 4828 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4829 | if (kEmitCompilerReadBarrier) { |
| 4830 | // When read barriers are enabled, the type checking |
| 4831 | // instrumentation requires two read barriers: |
| 4832 | // |
| 4833 | // __ movl(temp2, temp); |
| 4834 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4835 | // __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4836 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4837 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 4838 | // |
| 4839 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 4840 | // __ movl(temp2, Address(register_value, class_offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4841 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4842 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 4843 | // |
| 4844 | // __ cmpl(temp, temp2); |
| 4845 | // |
| 4846 | // However, the second read barrier may trash `temp`, as it |
| 4847 | // is a temporary register, and as such would not be saved |
| 4848 | // along with live registers before calling the runtime (nor |
| 4849 | // restored afterwards). So in this case, we bail out and |
| 4850 | // delegate the work to the array set slow path. |
| 4851 | // |
| 4852 | // TODO: Extend the register allocator to support a new |
| 4853 | // "(locally) live temp" location so as to avoid always |
| 4854 | // going into the slow path when read barriers are enabled. |
| 4855 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4856 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4857 | // /* HeapReference<Class> */ temp = array->klass_ |
| 4858 | __ movl(temp, Address(array, class_offset)); |
| 4859 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4860 | __ MaybeUnpoisonHeapReference(temp); |
| 4861 | |
| 4862 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4863 | __ movl(temp, Address(temp, component_offset)); |
| 4864 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 4865 | // nor the object reference in `register_value->klass`, as |
| 4866 | // we are comparing two poisoned references. |
| 4867 | __ cmpl(temp, Address(register_value, class_offset)); |
| 4868 | |
| 4869 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4870 | __ j(kEqual, &do_put); |
| 4871 | // If heap poisoning is enabled, the `temp` reference has |
| 4872 | // not been unpoisoned yet; unpoison it now. |
| 4873 | __ MaybeUnpoisonHeapReference(temp); |
| 4874 | |
| 4875 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 4876 | __ movl(temp, Address(temp, super_offset)); |
| 4877 | // If heap poisoning is enabled, no need to unpoison |
| 4878 | // `temp`, as we are comparing against null below. |
| 4879 | __ testl(temp, temp); |
| 4880 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4881 | __ Bind(&do_put); |
| 4882 | } else { |
| 4883 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4884 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4885 | } |
| 4886 | } |
| 4887 | |
| 4888 | if (kPoisonHeapReferences) { |
| 4889 | __ movl(temp, register_value); |
| 4890 | __ PoisonHeapReference(temp); |
| 4891 | __ movl(address, temp); |
| 4892 | } else { |
| 4893 | __ movl(address, register_value); |
| 4894 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4895 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4896 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4897 | } |
| 4898 | |
| 4899 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4900 | codegen_->MarkGCCard( |
| 4901 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4902 | __ Bind(&done); |
| 4903 | |
| 4904 | if (slow_path != nullptr) { |
| 4905 | __ Bind(slow_path->GetExitLabel()); |
| 4906 | } |
| 4907 | |
| 4908 | break; |
| 4909 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4910 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4911 | case Primitive::kPrimInt: { |
| 4912 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4913 | Address address = index.IsConstant() |
| 4914 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4915 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
| 4916 | if (value.IsRegister()) { |
| 4917 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 4918 | } else { |
| 4919 | DCHECK(value.IsConstant()) << value; |
| 4920 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4921 | __ movl(address, Immediate(v)); |
| 4922 | } |
| 4923 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4924 | break; |
| 4925 | } |
| 4926 | |
| 4927 | case Primitive::kPrimLong: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4928 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 4929 | Address address = index.IsConstant() |
| 4930 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4931 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
| 4932 | if (value.IsRegister()) { |
| 4933 | __ movq(address, value.AsRegister<CpuRegister>()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4934 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4935 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4936 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4937 | Address address_high = index.IsConstant() |
| 4938 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 4939 | offset + sizeof(int32_t)) |
| 4940 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset + sizeof(int32_t)); |
| 4941 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4942 | } |
| 4943 | break; |
| 4944 | } |
| 4945 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4946 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4947 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4948 | Address address = index.IsConstant() |
| 4949 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4950 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4951 | if (value.IsFpuRegister()) { |
| 4952 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 4953 | } else { |
| 4954 | DCHECK(value.IsConstant()); |
| 4955 | int32_t v = |
| 4956 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4957 | __ movl(address, Immediate(v)); |
| 4958 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4959 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4960 | break; |
| 4961 | } |
| 4962 | |
| 4963 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4964 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4965 | Address address = index.IsConstant() |
| 4966 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4967 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4968 | if (value.IsFpuRegister()) { |
| 4969 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 4970 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4971 | } else { |
| 4972 | int64_t v = |
| 4973 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4974 | Address address_high = index.IsConstant() |
| 4975 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 4976 | offset + sizeof(int32_t)) |
| 4977 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset + sizeof(int32_t)); |
| 4978 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 4979 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4980 | break; |
| 4981 | } |
| 4982 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4983 | case Primitive::kPrimVoid: |
| 4984 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4985 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4986 | } |
| 4987 | } |
| 4988 | |
| 4989 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4990 | LocationSummary* locations = |
| 4991 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4992 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4993 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4994 | } |
| 4995 | |
| 4996 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 4997 | LocationSummary* locations = instruction->GetLocations(); |
| 4998 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4999 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5000 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5001 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5002 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5003 | } |
| 5004 | |
| 5005 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5006 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5007 | ? LocationSummary::kCallOnSlowPath |
| 5008 | : LocationSummary::kNoCall; |
| 5009 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5010 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5011 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5012 | if (instruction->HasUses()) { |
| 5013 | locations->SetOut(Location::SameAsFirstInput()); |
| 5014 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5015 | } |
| 5016 | |
| 5017 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5018 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5019 | Location index_loc = locations->InAt(0); |
| 5020 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5021 | SlowPathCode* slow_path = |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5022 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5023 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5024 | if (length_loc.IsConstant()) { |
| 5025 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5026 | if (index_loc.IsConstant()) { |
| 5027 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5028 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5029 | if (index < 0 || index >= length) { |
| 5030 | codegen_->AddSlowPath(slow_path); |
| 5031 | __ jmp(slow_path->GetEntryLabel()); |
| 5032 | } else { |
| 5033 | // Some optimization after BCE may have generated this, and we should not |
| 5034 | // generate a bounds check if it is a valid range. |
| 5035 | } |
| 5036 | return; |
| 5037 | } |
| 5038 | |
| 5039 | // We have to reverse the jump condition because the length is the constant. |
| 5040 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 5041 | __ cmpl(index_reg, Immediate(length)); |
| 5042 | codegen_->AddSlowPath(slow_path); |
| 5043 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5044 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5045 | CpuRegister length = length_loc.AsRegister<CpuRegister>(); |
| 5046 | if (index_loc.IsConstant()) { |
| 5047 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5048 | __ cmpl(length, Immediate(value)); |
| 5049 | } else { |
| 5050 | __ cmpl(length, index_loc.AsRegister<CpuRegister>()); |
| 5051 | } |
| 5052 | codegen_->AddSlowPath(slow_path); |
| 5053 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5054 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5055 | } |
| 5056 | |
| 5057 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5058 | CpuRegister card, |
| 5059 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5060 | CpuRegister value, |
| 5061 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5062 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5063 | if (value_can_be_null) { |
| 5064 | __ testl(value, value); |
| 5065 | __ j(kEqual, &is_null); |
| 5066 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5067 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), |
| 5068 | /* no_rip */ true)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5069 | __ movq(temp, object); |
| 5070 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5071 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5072 | if (value_can_be_null) { |
| 5073 | __ Bind(&is_null); |
| 5074 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5075 | } |
| 5076 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5077 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5078 | LOG(FATAL) << "Unimplemented"; |
| 5079 | } |
| 5080 | |
| 5081 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5082 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5083 | } |
| 5084 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5085 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5086 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5087 | } |
| 5088 | |
| 5089 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5090 | HBasicBlock* block = instruction->GetBlock(); |
| 5091 | if (block->GetLoopInformation() != nullptr) { |
| 5092 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5093 | // The back edge will generate the suspend check. |
| 5094 | return; |
| 5095 | } |
| 5096 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5097 | // The goto will generate the suspend check. |
| 5098 | return; |
| 5099 | } |
| 5100 | GenerateSuspendCheck(instruction, nullptr); |
| 5101 | } |
| 5102 | |
| 5103 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5104 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5105 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5106 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5107 | if (slow_path == nullptr) { |
| 5108 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 5109 | instruction->SetSlowPath(slow_path); |
| 5110 | codegen_->AddSlowPath(slow_path); |
| 5111 | if (successor != nullptr) { |
| 5112 | DCHECK(successor->IsLoopHeader()); |
| 5113 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5114 | } |
| 5115 | } else { |
| 5116 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5117 | } |
| 5118 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5119 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), |
| 5120 | /* no_rip */ true), |
| 5121 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5122 | if (successor == nullptr) { |
| 5123 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5124 | __ Bind(slow_path->GetReturnLabel()); |
| 5125 | } else { |
| 5126 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5127 | __ jmp(slow_path->GetEntryLabel()); |
| 5128 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5129 | } |
| 5130 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5131 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5132 | return codegen_->GetAssembler(); |
| 5133 | } |
| 5134 | |
| 5135 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5136 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5137 | Location source = move->GetSource(); |
| 5138 | Location destination = move->GetDestination(); |
| 5139 | |
| 5140 | if (source.IsRegister()) { |
| 5141 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5142 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5143 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5144 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5145 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5146 | } else { |
| 5147 | DCHECK(destination.IsDoubleStackSlot()); |
| 5148 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5149 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5150 | } |
| 5151 | } else if (source.IsStackSlot()) { |
| 5152 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5153 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5154 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5155 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5156 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5157 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5158 | } else { |
| 5159 | DCHECK(destination.IsStackSlot()); |
| 5160 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5161 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5162 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5163 | } else if (source.IsDoubleStackSlot()) { |
| 5164 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5165 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5166 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5167 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5168 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5169 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5170 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5171 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5172 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5173 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5174 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5175 | } else if (source.IsConstant()) { |
| 5176 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5177 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5178 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5179 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5180 | if (value == 0) { |
| 5181 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5182 | } else { |
| 5183 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5184 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5185 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5186 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5187 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5188 | } |
| 5189 | } else if (constant->IsLongConstant()) { |
| 5190 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5191 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5192 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5193 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5194 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5195 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5196 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5197 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5198 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5199 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5200 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5201 | codegen_->Load32BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5202 | } else { |
| 5203 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5204 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5205 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5206 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5207 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5208 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5209 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5210 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5211 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5212 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5213 | codegen_->Load64BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5214 | } else { |
| 5215 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5216 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5217 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5218 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5219 | } else if (source.IsFpuRegister()) { |
| 5220 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5221 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5222 | } else if (destination.IsStackSlot()) { |
| 5223 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5224 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5225 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 5226 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5227 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5228 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5229 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5230 | } |
| 5231 | } |
| 5232 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5233 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5234 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5235 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5236 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5237 | } |
| 5238 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5239 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5240 | ScratchRegisterScope ensure_scratch( |
| 5241 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5242 | |
| 5243 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5244 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5245 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5246 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5247 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5248 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5249 | CpuRegister(ensure_scratch.GetRegister())); |
| 5250 | } |
| 5251 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5252 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5253 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5254 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5255 | __ movq(reg, CpuRegister(TMP)); |
| 5256 | } |
| 5257 | |
| 5258 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 5259 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5260 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5261 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5262 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5263 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5264 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5265 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5266 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5267 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5268 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5269 | } |
| 5270 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5271 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5272 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5273 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5274 | __ movd(reg, CpuRegister(TMP)); |
| 5275 | } |
| 5276 | |
| 5277 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5278 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5279 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5280 | __ movd(reg, CpuRegister(TMP)); |
| 5281 | } |
| 5282 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5283 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5284 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5285 | Location source = move->GetSource(); |
| 5286 | Location destination = move->GetDestination(); |
| 5287 | |
| 5288 | if (source.IsRegister() && destination.IsRegister()) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5289 | __ xchgq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5290 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5291 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5292 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5293 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5294 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5295 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5296 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5297 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5298 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5299 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5300 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 5301 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5302 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5303 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5304 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5305 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5306 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5307 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5308 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5309 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5310 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5311 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5312 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5313 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5314 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5315 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5316 | } |
| 5317 | } |
| 5318 | |
| 5319 | |
| 5320 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5321 | __ pushq(CpuRegister(reg)); |
| 5322 | } |
| 5323 | |
| 5324 | |
| 5325 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5326 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5327 | } |
| 5328 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5329 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5330 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5331 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5332 | Immediate(mirror::Class::kStatusInitialized)); |
| 5333 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5334 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5335 | // No need for memory fence, thanks to the x86-64 memory model. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5336 | } |
| 5337 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5338 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5339 | InvokeRuntimeCallingConvention calling_convention; |
| 5340 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5341 | cls, |
| 5342 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5343 | Location::RegisterLocation(RAX), |
| 5344 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5345 | } |
| 5346 | |
| 5347 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5348 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5349 | if (cls->NeedsAccessCheck()) { |
| 5350 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5351 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5352 | cls, |
| 5353 | cls->GetDexPc(), |
| 5354 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5355 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5356 | return; |
| 5357 | } |
| 5358 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5359 | Location out_loc = locations->Out(); |
| 5360 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5361 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5362 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5363 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5364 | DCHECK(!cls->CanCallRuntime()); |
| 5365 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5366 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5367 | GenerateGcRootFieldLoad( |
| 5368 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5369 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5370 | // /* GcRoot<mirror::Class>[] */ out = |
| 5371 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5372 | __ movq(out, Address(current_method, |
| 5373 | ArtMethod::DexCacheResolvedTypesOffset(kX86_64PointerSize).Int32Value())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5374 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5375 | GenerateGcRootFieldLoad(cls, out_loc, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5376 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5377 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5378 | DCHECK(cls->CanCallRuntime()); |
| 5379 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 5380 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5381 | codegen_->AddSlowPath(slow_path); |
| 5382 | if (!cls->IsInDexCache()) { |
| 5383 | __ testl(out, out); |
| 5384 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5385 | } |
| 5386 | if (cls->MustGenerateClinitCheck()) { |
| 5387 | GenerateClassInitializationCheck(slow_path, out); |
| 5388 | } else { |
| 5389 | __ Bind(slow_path->GetExitLabel()); |
| 5390 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5391 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5392 | } |
| 5393 | } |
| 5394 | |
| 5395 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 5396 | LocationSummary* locations = |
| 5397 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5398 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5399 | if (check->HasUses()) { |
| 5400 | locations->SetOut(Location::SameAsFirstInput()); |
| 5401 | } |
| 5402 | } |
| 5403 | |
| 5404 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5405 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5406 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5407 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5408 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5409 | GenerateClassInitializationCheck(slow_path, |
| 5410 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5411 | } |
| 5412 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5413 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5414 | LocationSummary::CallKind call_kind = (!load->IsInDexCache() || kEmitCompilerReadBarrier) |
| 5415 | ? LocationSummary::kCallOnSlowPath |
| 5416 | : LocationSummary::kNoCall; |
| 5417 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5418 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5419 | locations->SetOut(Location::RequiresRegister()); |
| 5420 | } |
| 5421 | |
| 5422 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5423 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5424 | Location out_loc = locations->Out(); |
| 5425 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5426 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5427 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5428 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5429 | GenerateGcRootFieldLoad( |
| 5430 | load, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5431 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
| 5432 | __ movq(out, Address(out, mirror::Class::DexCacheStringsOffset().Uint32Value())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5433 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5434 | GenerateGcRootFieldLoad( |
| 5435 | load, out_loc, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5436 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5437 | if (!load->IsInDexCache()) { |
| 5438 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
| 5439 | codegen_->AddSlowPath(slow_path); |
| 5440 | __ testl(out, out); |
| 5441 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5442 | __ Bind(slow_path->GetExitLabel()); |
| 5443 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5444 | } |
| 5445 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5446 | static Address GetExceptionTlsAddress() { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5447 | return Address::Absolute(Thread::ExceptionOffset<kX86_64WordSize>().Int32Value(), |
| 5448 | /* no_rip */ true); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5449 | } |
| 5450 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5451 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 5452 | LocationSummary* locations = |
| 5453 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5454 | locations->SetOut(Location::RequiresRegister()); |
| 5455 | } |
| 5456 | |
| 5457 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5458 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 5459 | } |
| 5460 | |
| 5461 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 5462 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5463 | } |
| 5464 | |
| 5465 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5466 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5467 | } |
| 5468 | |
| 5469 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 5470 | LocationSummary* locations = |
| 5471 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5472 | InvokeRuntimeCallingConvention calling_convention; |
| 5473 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5474 | } |
| 5475 | |
| 5476 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5477 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 5478 | instruction, |
| 5479 | instruction->GetDexPc(), |
| 5480 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5481 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5482 | } |
| 5483 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5484 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5485 | return kEmitCompilerReadBarrier && |
| 5486 | (kUseBakerReadBarrier || |
| 5487 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5488 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5489 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5490 | } |
| 5491 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5492 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5493 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5494 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5495 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5496 | case TypeCheckKind::kExactCheck: |
| 5497 | case TypeCheckKind::kAbstractClassCheck: |
| 5498 | case TypeCheckKind::kClassHierarchyCheck: |
| 5499 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5500 | call_kind = |
| 5501 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5502 | break; |
| 5503 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5504 | case TypeCheckKind::kUnresolvedCheck: |
| 5505 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5506 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5507 | break; |
| 5508 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5509 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5510 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5511 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5512 | locations->SetInAt(1, Location::Any()); |
| 5513 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 5514 | locations->SetOut(Location::RequiresRegister()); |
| 5515 | // When read barriers are enabled, we need a temporary register for |
| 5516 | // some cases. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5517 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5518 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5519 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5520 | } |
| 5521 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5522 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5523 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5524 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5525 | Location obj_loc = locations->InAt(0); |
| 5526 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5527 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5528 | Location out_loc = locations->Out(); |
| 5529 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5530 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5531 | locations->GetTemp(0) : |
| 5532 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5533 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5534 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5535 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5536 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5537 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5538 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5539 | |
| 5540 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5541 | // Avoid null check if we know obj is not null. |
| 5542 | if (instruction->MustDoNullCheck()) { |
| 5543 | __ testl(obj, obj); |
| 5544 | __ j(kEqual, &zero); |
| 5545 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5546 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5547 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5548 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5549 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5550 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5551 | case TypeCheckKind::kExactCheck: { |
| 5552 | if (cls.IsRegister()) { |
| 5553 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5554 | } else { |
| 5555 | DCHECK(cls.IsStackSlot()) << cls; |
| 5556 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5557 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5558 | if (zero.IsLinked()) { |
| 5559 | // Classes must be equal for the instanceof to succeed. |
| 5560 | __ j(kNotEqual, &zero); |
| 5561 | __ movl(out, Immediate(1)); |
| 5562 | __ jmp(&done); |
| 5563 | } else { |
| 5564 | __ setcc(kEqual, out); |
| 5565 | // setcc only sets the low byte. |
| 5566 | __ andl(out, Immediate(1)); |
| 5567 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5568 | break; |
| 5569 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5570 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5571 | case TypeCheckKind::kAbstractClassCheck: { |
| 5572 | // If the class is abstract, we eagerly fetch the super class of the |
| 5573 | // object to avoid doing a comparison we know will fail. |
| 5574 | NearLabel loop, success; |
| 5575 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5576 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5577 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5578 | __ testl(out, out); |
| 5579 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5580 | __ j(kEqual, &done); |
| 5581 | if (cls.IsRegister()) { |
| 5582 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5583 | } else { |
| 5584 | DCHECK(cls.IsStackSlot()) << cls; |
| 5585 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5586 | } |
| 5587 | __ j(kNotEqual, &loop); |
| 5588 | __ movl(out, Immediate(1)); |
| 5589 | if (zero.IsLinked()) { |
| 5590 | __ jmp(&done); |
| 5591 | } |
| 5592 | break; |
| 5593 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5594 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5595 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5596 | // Walk over the class hierarchy to find a match. |
| 5597 | NearLabel loop, success; |
| 5598 | __ Bind(&loop); |
| 5599 | if (cls.IsRegister()) { |
| 5600 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5601 | } else { |
| 5602 | DCHECK(cls.IsStackSlot()) << cls; |
| 5603 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5604 | } |
| 5605 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5606 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5607 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5608 | __ testl(out, out); |
| 5609 | __ j(kNotEqual, &loop); |
| 5610 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5611 | __ jmp(&done); |
| 5612 | __ Bind(&success); |
| 5613 | __ movl(out, Immediate(1)); |
| 5614 | if (zero.IsLinked()) { |
| 5615 | __ jmp(&done); |
| 5616 | } |
| 5617 | break; |
| 5618 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5619 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5620 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5621 | // Do an exact check. |
| 5622 | NearLabel exact_check; |
| 5623 | if (cls.IsRegister()) { |
| 5624 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5625 | } else { |
| 5626 | DCHECK(cls.IsStackSlot()) << cls; |
| 5627 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5628 | } |
| 5629 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5630 | // 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] | 5631 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5632 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5633 | __ testl(out, out); |
| 5634 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5635 | __ j(kEqual, &done); |
| 5636 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5637 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5638 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5639 | __ movl(out, Immediate(1)); |
| 5640 | __ jmp(&done); |
| 5641 | break; |
| 5642 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5643 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5644 | case TypeCheckKind::kArrayCheck: { |
| 5645 | if (cls.IsRegister()) { |
| 5646 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5647 | } else { |
| 5648 | DCHECK(cls.IsStackSlot()) << cls; |
| 5649 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5650 | } |
| 5651 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5652 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5653 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5654 | codegen_->AddSlowPath(slow_path); |
| 5655 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5656 | __ movl(out, Immediate(1)); |
| 5657 | if (zero.IsLinked()) { |
| 5658 | __ jmp(&done); |
| 5659 | } |
| 5660 | break; |
| 5661 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5662 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5663 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5664 | case TypeCheckKind::kInterfaceCheck: { |
| 5665 | // Note that we indeed only call on slow path, but we always go |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 5666 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5667 | // cases. |
| 5668 | // |
| 5669 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5670 | // entry point without resorting to a type checking slow path |
| 5671 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5672 | // require to assign fixed registers for the inputs of this |
| 5673 | // HInstanceOf instruction (following the runtime calling |
| 5674 | // convention), which might be cluttered by the potential first |
| 5675 | // read barrier emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5676 | // |
| 5677 | // TODO: Introduce a new runtime entry point taking the object |
| 5678 | // to test (instead of its class) as argument, and let it deal |
| 5679 | // with the read barrier issues. This will let us refactor this |
| 5680 | // case of the `switch` code as it was previously (with a direct |
| 5681 | // call to the runtime not using a type checking slow path). |
| 5682 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5683 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5684 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5685 | /* is_fatal */ false); |
| 5686 | codegen_->AddSlowPath(slow_path); |
| 5687 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5688 | if (zero.IsLinked()) { |
| 5689 | __ jmp(&done); |
| 5690 | } |
| 5691 | break; |
| 5692 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5693 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5694 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5695 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5696 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5697 | __ xorl(out, out); |
| 5698 | } |
| 5699 | |
| 5700 | if (done.IsLinked()) { |
| 5701 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5702 | } |
| 5703 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5704 | if (slow_path != nullptr) { |
| 5705 | __ Bind(slow_path->GetExitLabel()); |
| 5706 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5707 | } |
| 5708 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5709 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5710 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5711 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5712 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5713 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5714 | case TypeCheckKind::kExactCheck: |
| 5715 | case TypeCheckKind::kAbstractClassCheck: |
| 5716 | case TypeCheckKind::kClassHierarchyCheck: |
| 5717 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5718 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 5719 | LocationSummary::kCallOnSlowPath : |
| 5720 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5721 | break; |
| 5722 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5723 | case TypeCheckKind::kUnresolvedCheck: |
| 5724 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5725 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5726 | break; |
| 5727 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5728 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5729 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5730 | locations->SetInAt(1, Location::Any()); |
| 5731 | // Note that TypeCheckSlowPathX86_64 uses this "temp" register too. |
| 5732 | locations->AddTemp(Location::RequiresRegister()); |
| 5733 | // When read barriers are enabled, we need an additional temporary |
| 5734 | // register for some cases. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5735 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5736 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5737 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5738 | } |
| 5739 | |
| 5740 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5741 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5742 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5743 | Location obj_loc = locations->InAt(0); |
| 5744 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5745 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5746 | Location temp_loc = locations->GetTemp(0); |
| 5747 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5748 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5749 | locations->GetTemp(1) : |
| 5750 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5751 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5752 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5753 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5754 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5755 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5756 | bool is_type_check_slow_path_fatal = |
| 5757 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 5758 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5759 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5760 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 5761 | !instruction->CanThrowIntoCatchBlock(); |
| 5762 | SlowPathCode* type_check_slow_path = |
| 5763 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5764 | is_type_check_slow_path_fatal); |
| 5765 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5766 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5767 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5768 | case TypeCheckKind::kExactCheck: |
| 5769 | case TypeCheckKind::kArrayCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5770 | NearLabel done; |
| 5771 | // Avoid null check if we know obj is not null. |
| 5772 | if (instruction->MustDoNullCheck()) { |
| 5773 | __ testl(obj, obj); |
| 5774 | __ j(kEqual, &done); |
| 5775 | } |
| 5776 | |
| 5777 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5778 | GenerateReferenceLoadTwoRegisters( |
| 5779 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 5780 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5781 | if (cls.IsRegister()) { |
| 5782 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5783 | } else { |
| 5784 | DCHECK(cls.IsStackSlot()) << cls; |
| 5785 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5786 | } |
| 5787 | // Jump to slow path for throwing the exception or doing a |
| 5788 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5789 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5790 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5791 | break; |
| 5792 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5793 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5794 | case TypeCheckKind::kAbstractClassCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5795 | NearLabel done; |
| 5796 | // Avoid null check if we know obj is not null. |
| 5797 | if (instruction->MustDoNullCheck()) { |
| 5798 | __ testl(obj, obj); |
| 5799 | __ j(kEqual, &done); |
| 5800 | } |
| 5801 | |
| 5802 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5803 | GenerateReferenceLoadTwoRegisters( |
| 5804 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 5805 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5806 | // If the class is abstract, we eagerly fetch the super class of the |
| 5807 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5808 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5809 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5810 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5811 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5812 | |
| 5813 | // If the class reference currently in `temp` is not null, jump |
| 5814 | // to the `compare_classes` label to compare it with the checked |
| 5815 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5816 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5817 | __ j(kNotEqual, &compare_classes); |
| 5818 | // Otherwise, jump to the slow path to throw the exception. |
| 5819 | // |
| 5820 | // But before, move back the object's class into `temp` before |
| 5821 | // going into the slow path, as it has been overwritten in the |
| 5822 | // meantime. |
| 5823 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5824 | GenerateReferenceLoadTwoRegisters( |
| 5825 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5826 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 5827 | |
| 5828 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5829 | if (cls.IsRegister()) { |
| 5830 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5831 | } else { |
| 5832 | DCHECK(cls.IsStackSlot()) << cls; |
| 5833 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5834 | } |
| 5835 | __ j(kNotEqual, &loop); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5836 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5837 | break; |
| 5838 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5839 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5840 | case TypeCheckKind::kClassHierarchyCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5841 | NearLabel done; |
| 5842 | // Avoid null check if we know obj is not null. |
| 5843 | if (instruction->MustDoNullCheck()) { |
| 5844 | __ testl(obj, obj); |
| 5845 | __ j(kEqual, &done); |
| 5846 | } |
| 5847 | |
| 5848 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5849 | GenerateReferenceLoadTwoRegisters( |
| 5850 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 5851 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5852 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5853 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5854 | __ Bind(&loop); |
| 5855 | if (cls.IsRegister()) { |
| 5856 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5857 | } else { |
| 5858 | DCHECK(cls.IsStackSlot()) << cls; |
| 5859 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5860 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5861 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5862 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5863 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5864 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5865 | |
| 5866 | // If the class reference currently in `temp` is not null, jump |
| 5867 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5868 | __ testl(temp, temp); |
| 5869 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5870 | // Otherwise, jump to the slow path to throw the exception. |
| 5871 | // |
| 5872 | // But before, move back the object's class into `temp` before |
| 5873 | // going into the slow path, as it has been overwritten in the |
| 5874 | // meantime. |
| 5875 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5876 | GenerateReferenceLoadTwoRegisters( |
| 5877 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5878 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5879 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5880 | break; |
| 5881 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5882 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5883 | case TypeCheckKind::kArrayObjectCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5884 | // We cannot use a NearLabel here, as its range might be too |
| 5885 | // short in some cases when read barriers are enabled. This has |
| 5886 | // been observed for instance when the code emitted for this |
| 5887 | // case uses high x86-64 registers (R8-R15). |
| 5888 | Label done; |
| 5889 | // Avoid null check if we know obj is not null. |
| 5890 | if (instruction->MustDoNullCheck()) { |
| 5891 | __ testl(obj, obj); |
| 5892 | __ j(kEqual, &done); |
| 5893 | } |
| 5894 | |
| 5895 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5896 | GenerateReferenceLoadTwoRegisters( |
| 5897 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 5898 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5899 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5900 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5901 | if (cls.IsRegister()) { |
| 5902 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5903 | } else { |
| 5904 | DCHECK(cls.IsStackSlot()) << cls; |
| 5905 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5906 | } |
| 5907 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5908 | |
| 5909 | // 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] | 5910 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5911 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5912 | |
| 5913 | // If the component type is not null (i.e. the object is indeed |
| 5914 | // an array), jump to label `check_non_primitive_component_type` |
| 5915 | // to further check that this component type is not a primitive |
| 5916 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5917 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5918 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 5919 | // Otherwise, jump to the slow path to throw the exception. |
| 5920 | // |
| 5921 | // But before, move back the object's class into `temp` before |
| 5922 | // going into the slow path, as it has been overwritten in the |
| 5923 | // meantime. |
| 5924 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5925 | GenerateReferenceLoadTwoRegisters( |
| 5926 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5927 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 5928 | |
| 5929 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5930 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5931 | __ j(kEqual, &done); |
| 5932 | // Same comment as above regarding `temp` and the slow path. |
| 5933 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5934 | GenerateReferenceLoadTwoRegisters( |
| 5935 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5936 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5937 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5938 | break; |
| 5939 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5940 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5941 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5942 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5943 | NearLabel done; |
| 5944 | // Avoid null check if we know obj is not null. |
| 5945 | if (instruction->MustDoNullCheck()) { |
| 5946 | __ testl(obj, obj); |
| 5947 | __ j(kEqual, &done); |
| 5948 | } |
| 5949 | |
| 5950 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5951 | GenerateReferenceLoadTwoRegisters( |
| 5952 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 5953 | |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 5954 | // We always go into the type check slow path for the unresolved |
| 5955 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5956 | // |
| 5957 | // We cannot directly call the CheckCast runtime entry point |
| 5958 | // without resorting to a type checking slow path here (i.e. by |
| 5959 | // calling InvokeRuntime directly), as it would require to |
| 5960 | // assign fixed registers for the inputs of this HInstanceOf |
| 5961 | // instruction (following the runtime calling convention), which |
| 5962 | // might be cluttered by the potential first read barrier |
| 5963 | // emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5964 | // |
| 5965 | // TODO: Introduce a new runtime entry point taking the object |
| 5966 | // to test (instead of its class) as argument, and let it deal |
| 5967 | // with the read barrier issues. This will let us refactor this |
| 5968 | // case of the `switch` code as it was previously (with a direct |
| 5969 | // call to the runtime not using a type checking slow path). |
| 5970 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5971 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5972 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5973 | break; |
| 5974 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5975 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5976 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5977 | } |
| 5978 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5979 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5980 | LocationSummary* locations = |
| 5981 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5982 | InvokeRuntimeCallingConvention calling_convention; |
| 5983 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5984 | } |
| 5985 | |
| 5986 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5987 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 5988 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 5989 | instruction, |
| 5990 | instruction->GetDexPc(), |
| 5991 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5992 | if (instruction->IsEnter()) { |
| 5993 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5994 | } else { |
| 5995 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5996 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5997 | } |
| 5998 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5999 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6000 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6001 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6002 | |
| 6003 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6004 | LocationSummary* locations = |
| 6005 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6006 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6007 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6008 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6009 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6010 | locations->SetOut(Location::SameAsFirstInput()); |
| 6011 | } |
| 6012 | |
| 6013 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 6014 | HandleBitwiseOperation(instruction); |
| 6015 | } |
| 6016 | |
| 6017 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 6018 | HandleBitwiseOperation(instruction); |
| 6019 | } |
| 6020 | |
| 6021 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 6022 | HandleBitwiseOperation(instruction); |
| 6023 | } |
| 6024 | |
| 6025 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6026 | LocationSummary* locations = instruction->GetLocations(); |
| 6027 | Location first = locations->InAt(0); |
| 6028 | Location second = locations->InAt(1); |
| 6029 | DCHECK(first.Equals(locations->Out())); |
| 6030 | |
| 6031 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6032 | if (second.IsRegister()) { |
| 6033 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6034 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6035 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6036 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6037 | } else { |
| 6038 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6039 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6040 | } |
| 6041 | } else if (second.IsConstant()) { |
| 6042 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 6043 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6044 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6045 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6046 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6047 | } else { |
| 6048 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6049 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6050 | } |
| 6051 | } else { |
| 6052 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 6053 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6054 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6055 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6056 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6057 | } else { |
| 6058 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6059 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6060 | } |
| 6061 | } |
| 6062 | } else { |
| 6063 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6064 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 6065 | bool second_is_constant = false; |
| 6066 | int64_t value = 0; |
| 6067 | if (second.IsConstant()) { |
| 6068 | second_is_constant = true; |
| 6069 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6070 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6071 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6072 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6073 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6074 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6075 | if (is_int32_value) { |
| 6076 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6077 | } else { |
| 6078 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6079 | } |
| 6080 | } else if (second.IsDoubleStackSlot()) { |
| 6081 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6082 | } else { |
| 6083 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 6084 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6085 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6086 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6087 | if (is_int32_value) { |
| 6088 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6089 | } else { |
| 6090 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6091 | } |
| 6092 | } else if (second.IsDoubleStackSlot()) { |
| 6093 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6094 | } else { |
| 6095 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6096 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6097 | } else { |
| 6098 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6099 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6100 | if (is_int32_value) { |
| 6101 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6102 | } else { |
| 6103 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6104 | } |
| 6105 | } else if (second.IsDoubleStackSlot()) { |
| 6106 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6107 | } else { |
| 6108 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 6109 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6110 | } |
| 6111 | } |
| 6112 | } |
| 6113 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6114 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6115 | Location out, |
| 6116 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6117 | Location maybe_temp) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6118 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6119 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6120 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6121 | if (kUseBakerReadBarrier) { |
| 6122 | // Load with fast path based Baker's read barrier. |
| 6123 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6124 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6125 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6126 | } else { |
| 6127 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6128 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6129 | // in the following move operation, as we will need it for the |
| 6130 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6131 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6132 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6133 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6134 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6135 | } |
| 6136 | } else { |
| 6137 | // Plain load with no read barrier. |
| 6138 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6139 | __ movl(out_reg, Address(out_reg, offset)); |
| 6140 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6141 | } |
| 6142 | } |
| 6143 | |
| 6144 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6145 | Location out, |
| 6146 | Location obj, |
| 6147 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6148 | Location maybe_temp) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6149 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6150 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
| 6151 | if (kEmitCompilerReadBarrier) { |
| 6152 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6153 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6154 | // Load with fast path based Baker's read barrier. |
| 6155 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6156 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6157 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6158 | } else { |
| 6159 | // Load with slow path based read barrier. |
| 6160 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6161 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6162 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6163 | } |
| 6164 | } else { |
| 6165 | // Plain load with no read barrier. |
| 6166 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6167 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6168 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6169 | } |
| 6170 | } |
| 6171 | |
| 6172 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6173 | Location root, |
| 6174 | CpuRegister obj, |
| 6175 | uint32_t offset) { |
| 6176 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
| 6177 | if (kEmitCompilerReadBarrier) { |
| 6178 | if (kUseBakerReadBarrier) { |
| 6179 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6180 | // Baker's read barrier are used: |
| 6181 | // |
| 6182 | // root = obj.field; |
| 6183 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6184 | // root = ReadBarrier::Mark(root) |
| 6185 | // } |
| 6186 | |
| 6187 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6188 | __ movl(root_reg, Address(obj, offset)); |
| 6189 | static_assert( |
| 6190 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6191 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6192 | "have different sizes."); |
| 6193 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6194 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6195 | "have different sizes."); |
| 6196 | |
| 6197 | // Slow path used to mark the GC root `root`. |
| 6198 | SlowPathCode* slow_path = |
| 6199 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64(instruction, root, root); |
| 6200 | codegen_->AddSlowPath(slow_path); |
| 6201 | |
| 6202 | __ gs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86_64WordSize>().Int32Value(), |
| 6203 | /* no_rip */ true), |
| 6204 | Immediate(0)); |
| 6205 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6206 | __ Bind(slow_path->GetExitLabel()); |
| 6207 | } else { |
| 6208 | // GC root loaded through a slow path for read barriers other |
| 6209 | // than Baker's. |
| 6210 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6211 | __ leaq(root_reg, Address(obj, offset)); |
| 6212 | // /* mirror::Object* */ root = root->Read() |
| 6213 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6214 | } |
| 6215 | } else { |
| 6216 | // Plain GC root load with no read barrier. |
| 6217 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6218 | __ movl(root_reg, Address(obj, offset)); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6219 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6220 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6221 | } |
| 6222 | } |
| 6223 | |
| 6224 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6225 | Location ref, |
| 6226 | CpuRegister obj, |
| 6227 | uint32_t offset, |
| 6228 | Location temp, |
| 6229 | bool needs_null_check) { |
| 6230 | DCHECK(kEmitCompilerReadBarrier); |
| 6231 | DCHECK(kUseBakerReadBarrier); |
| 6232 | |
| 6233 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6234 | Address src(obj, offset); |
| 6235 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6236 | } |
| 6237 | |
| 6238 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6239 | Location ref, |
| 6240 | CpuRegister obj, |
| 6241 | uint32_t data_offset, |
| 6242 | Location index, |
| 6243 | Location temp, |
| 6244 | bool needs_null_check) { |
| 6245 | DCHECK(kEmitCompilerReadBarrier); |
| 6246 | DCHECK(kUseBakerReadBarrier); |
| 6247 | |
| 6248 | // /* HeapReference<Object> */ ref = |
| 6249 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6250 | Address src = index.IsConstant() ? |
| 6251 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 6252 | Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset); |
| 6253 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6254 | } |
| 6255 | |
| 6256 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6257 | Location ref, |
| 6258 | CpuRegister obj, |
| 6259 | const Address& src, |
| 6260 | Location temp, |
| 6261 | bool needs_null_check) { |
| 6262 | DCHECK(kEmitCompilerReadBarrier); |
| 6263 | DCHECK(kUseBakerReadBarrier); |
| 6264 | |
| 6265 | // In slow path based read barriers, the read barrier call is |
| 6266 | // inserted after the original load. However, in fast path based |
| 6267 | // Baker's read barriers, we need to perform the load of |
| 6268 | // mirror::Object::monitor_ *before* the original reference load. |
| 6269 | // This load-load ordering is required by the read barrier. |
| 6270 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6271 | // |
| 6272 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6273 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6274 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6275 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6276 | // if (is_gray) { |
| 6277 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6278 | // } |
| 6279 | // |
| 6280 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6281 | // slightly more complex as: |
| 6282 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6283 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6284 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 6285 | // here, which is a no-op thanks to the x86-64 memory model); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6286 | // - it performs additional checks that we do not do here for |
| 6287 | // performance reasons. |
| 6288 | |
| 6289 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
| 6290 | CpuRegister temp_reg = temp.AsRegister<CpuRegister>(); |
| 6291 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6292 | |
| 6293 | // /* int32_t */ monitor = obj->monitor_ |
| 6294 | __ movl(temp_reg, Address(obj, monitor_offset)); |
| 6295 | if (needs_null_check) { |
| 6296 | MaybeRecordImplicitNullCheck(instruction); |
| 6297 | } |
| 6298 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6299 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6300 | "art::LockWord and int32_t have different sizes."); |
| 6301 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 6302 | __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); |
| 6303 | __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); |
| 6304 | static_assert( |
| 6305 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 6306 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 6307 | |
| 6308 | // Load fence to prevent load-load reordering. |
| 6309 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 6310 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6311 | |
| 6312 | // The actual reference load. |
| 6313 | // /* HeapReference<Object> */ ref = *src |
| 6314 | __ movl(ref_reg, src); |
| 6315 | |
| 6316 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6317 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6318 | |
| 6319 | // Slow path used to mark the object `ref` when it is gray. |
| 6320 | SlowPathCode* slow_path = |
| 6321 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64(instruction, ref, ref); |
| 6322 | AddSlowPath(slow_path); |
| 6323 | |
| 6324 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6325 | // ref = ReadBarrier::Mark(ref); |
| 6326 | __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); |
| 6327 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6328 | __ Bind(slow_path->GetExitLabel()); |
| 6329 | } |
| 6330 | |
| 6331 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6332 | Location out, |
| 6333 | Location ref, |
| 6334 | Location obj, |
| 6335 | uint32_t offset, |
| 6336 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6337 | DCHECK(kEmitCompilerReadBarrier); |
| 6338 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6339 | // Insert a slow path based read barrier *after* the reference load. |
| 6340 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6341 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6342 | // reference will be carried out by the runtime within the slow |
| 6343 | // path. |
| 6344 | // |
| 6345 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6346 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6347 | // not used by the artReadBarrierSlow entry point. |
| 6348 | // |
| 6349 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6350 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6351 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 6352 | AddSlowPath(slow_path); |
| 6353 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6354 | __ jmp(slow_path->GetEntryLabel()); |
| 6355 | __ Bind(slow_path->GetExitLabel()); |
| 6356 | } |
| 6357 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6358 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6359 | Location out, |
| 6360 | Location ref, |
| 6361 | Location obj, |
| 6362 | uint32_t offset, |
| 6363 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6364 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6365 | // Baker's read barriers shall be handled by the fast path |
| 6366 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6367 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6368 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6369 | // by the runtime within the slow path. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6370 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6371 | } else if (kPoisonHeapReferences) { |
| 6372 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 6373 | } |
| 6374 | } |
| 6375 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6376 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6377 | Location out, |
| 6378 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6379 | DCHECK(kEmitCompilerReadBarrier); |
| 6380 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6381 | // Insert a slow path based read barrier *after* the GC root load. |
| 6382 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6383 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6384 | // not need to do anything special for this here. |
| 6385 | SlowPathCode* slow_path = |
| 6386 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
| 6387 | AddSlowPath(slow_path); |
| 6388 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6389 | __ jmp(slow_path->GetEntryLabel()); |
| 6390 | __ Bind(slow_path->GetExitLabel()); |
| 6391 | } |
| 6392 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6393 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6394 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6395 | LOG(FATAL) << "Unreachable"; |
| 6396 | } |
| 6397 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6398 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6399 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6400 | LOG(FATAL) << "Unreachable"; |
| 6401 | } |
| 6402 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6403 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6404 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6405 | LocationSummary* locations = |
| 6406 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6407 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6408 | locations->AddTemp(Location::RequiresRegister()); |
| 6409 | locations->AddTemp(Location::RequiresRegister()); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6410 | } |
| 6411 | |
| 6412 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6413 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6414 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6415 | LocationSummary* locations = switch_instr->GetLocations(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6416 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 6417 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 6418 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6419 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6420 | |
| 6421 | // Should we generate smaller inline compare/jumps? |
| 6422 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6423 | // Figure out the correct compare values and jump conditions. |
| 6424 | // Handle the first compare/branch as a special case because it might |
| 6425 | // jump to the default case. |
| 6426 | DCHECK_GT(num_entries, 2u); |
| 6427 | Condition first_condition; |
| 6428 | uint32_t index; |
| 6429 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6430 | if (lower_bound != 0) { |
| 6431 | first_condition = kLess; |
| 6432 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 6433 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6434 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 6435 | |
| 6436 | index = 1; |
| 6437 | } else { |
| 6438 | // Handle all the compare/jumps below. |
| 6439 | first_condition = kBelow; |
| 6440 | index = 0; |
| 6441 | } |
| 6442 | |
| 6443 | // Handle the rest of the compare/jumps. |
| 6444 | for (; index + 1 < num_entries; index += 2) { |
| 6445 | int32_t compare_to_value = lower_bound + index + 1; |
| 6446 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 6447 | // Jump to successors[index] if value < case_value[index]. |
| 6448 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6449 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6450 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6451 | } |
| 6452 | |
| 6453 | if (index != num_entries) { |
| 6454 | // There are an odd number of entries. Handle the last one. |
| 6455 | DCHECK_EQ(index + 1, num_entries); |
Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 6456 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6457 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 6458 | } |
| 6459 | |
| 6460 | // And the default for any other value. |
| 6461 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6462 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 6463 | } |
| 6464 | return; |
| 6465 | } |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6466 | |
| 6467 | // Remove the bias, if needed. |
| 6468 | Register value_reg_out = value_reg_in.AsRegister(); |
| 6469 | if (lower_bound != 0) { |
| 6470 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 6471 | value_reg_out = temp_reg.AsRegister(); |
| 6472 | } |
| 6473 | CpuRegister value_reg(value_reg_out); |
| 6474 | |
| 6475 | // Is the value in range? |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6476 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6477 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6478 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6479 | // We are in the range of the table. |
| 6480 | // Load the address of the jump table in the constant area. |
| 6481 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6482 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6483 | // Load the (signed) offset from the jump table. |
| 6484 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 6485 | |
| 6486 | // Add the offset to the address of the table base. |
| 6487 | __ addq(temp_reg, base_reg); |
| 6488 | |
| 6489 | // And jump. |
| 6490 | __ jmp(temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6491 | } |
| 6492 | |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6493 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 6494 | if (value == 0) { |
| 6495 | __ xorl(dest, dest); |
| 6496 | } else { |
| 6497 | __ movl(dest, Immediate(value)); |
| 6498 | } |
| 6499 | } |
| 6500 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6501 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 6502 | if (value == 0) { |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6503 | // Clears upper bits too. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6504 | __ xorl(dest, dest); |
| 6505 | } else if (value > 0 && IsInt<32>(value)) { |
| 6506 | // We can use a 32 bit move, as it will zero-extend and is one byte shorter. |
| 6507 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 6508 | } else { |
| 6509 | __ movq(dest, Immediate(value)); |
| 6510 | } |
| 6511 | } |
| 6512 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 6513 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 6514 | if (value == 0) { |
| 6515 | __ xorps(dest, dest); |
| 6516 | } else { |
| 6517 | __ movss(dest, LiteralInt32Address(value)); |
| 6518 | } |
| 6519 | } |
| 6520 | |
| 6521 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 6522 | if (value == 0) { |
| 6523 | __ xorpd(dest, dest); |
| 6524 | } else { |
| 6525 | __ movsd(dest, LiteralInt64Address(value)); |
| 6526 | } |
| 6527 | } |
| 6528 | |
| 6529 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 6530 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 6531 | } |
| 6532 | |
| 6533 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 6534 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 6535 | } |
| 6536 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 6537 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 6538 | if (value == 0) { |
| 6539 | __ testl(dest, dest); |
| 6540 | } else { |
| 6541 | __ cmpl(dest, Immediate(value)); |
| 6542 | } |
| 6543 | } |
| 6544 | |
| 6545 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 6546 | if (IsInt<32>(value)) { |
| 6547 | if (value == 0) { |
| 6548 | __ testq(dest, dest); |
| 6549 | } else { |
| 6550 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 6551 | } |
| 6552 | } else { |
| 6553 | // Value won't fit in an int. |
| 6554 | __ cmpq(dest, LiteralInt64Address(value)); |
| 6555 | } |
| 6556 | } |
| 6557 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 6558 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 6559 | DCHECK(dest.IsDoubleStackSlot()); |
| 6560 | if (IsInt<32>(value)) { |
| 6561 | // Can move directly as an int32 constant. |
| 6562 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 6563 | Immediate(static_cast<int32_t>(value))); |
| 6564 | } else { |
| 6565 | Load64BitValue(CpuRegister(TMP), value); |
| 6566 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 6567 | } |
| 6568 | } |
| 6569 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6570 | /** |
| 6571 | * Class to handle late fixup of offsets into constant area. |
| 6572 | */ |
| 6573 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 6574 | public: |
| 6575 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 6576 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6577 | |
| 6578 | protected: |
| 6579 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6580 | |
| 6581 | CodeGeneratorX86_64* codegen_; |
| 6582 | |
| 6583 | private: |
| 6584 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6585 | // Patch the correct offset for the instruction. We use the address of the |
| 6586 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 6587 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 6588 | int32_t relative_position = constant_offset - pos; |
| 6589 | |
| 6590 | // Patch in the right value. |
| 6591 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 6592 | } |
| 6593 | |
| 6594 | // Location in constant area that the fixup refers to. |
| 6595 | size_t offset_into_constant_area_; |
| 6596 | }; |
| 6597 | |
| 6598 | /** |
| 6599 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 6600 | * constant area. |
| 6601 | */ |
| 6602 | class JumpTableRIPFixup : public RIPFixup { |
| 6603 | public: |
| 6604 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 6605 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 6606 | |
| 6607 | void CreateJumpTable() { |
| 6608 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 6609 | |
| 6610 | // Ensure that the reference to the jump table has the correct offset. |
| 6611 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 6612 | SetOffset(offset_in_constant_table); |
| 6613 | |
| 6614 | // Compute the offset from the start of the function to this jump table. |
| 6615 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 6616 | |
| 6617 | // Populate the jump table with the correct values for the jump table. |
| 6618 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 6619 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 6620 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 6621 | // The value that we want is the target offset - the position of the table. |
| 6622 | for (int32_t i = 0; i < num_entries; i++) { |
| 6623 | HBasicBlock* b = successors[i]; |
| 6624 | Label* l = codegen_->GetLabelOf(b); |
| 6625 | DCHECK(l->IsBound()); |
| 6626 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 6627 | assembler->AppendInt32(offset_to_block); |
| 6628 | } |
| 6629 | } |
| 6630 | |
| 6631 | private: |
| 6632 | const HPackedSwitch* switch_instr_; |
| 6633 | }; |
| 6634 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6635 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 6636 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6637 | X86_64Assembler* assembler = GetAssembler(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6638 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 6639 | // 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] | 6640 | assembler->Align(4, 0); |
| 6641 | constant_area_start_ = assembler->CodeSize(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6642 | |
| 6643 | // Populate any jump tables. |
| 6644 | for (auto jump_table : fixups_to_jump_tables_) { |
| 6645 | jump_table->CreateJumpTable(); |
| 6646 | } |
| 6647 | |
| 6648 | // And now add the constant area to the generated code. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6649 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6650 | } |
| 6651 | |
| 6652 | // And finish up. |
| 6653 | CodeGenerator::Finalize(allocator); |
| 6654 | } |
| 6655 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6656 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 6657 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 6658 | return Address::RIP(fixup); |
| 6659 | } |
| 6660 | |
| 6661 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 6662 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 6663 | return Address::RIP(fixup); |
| 6664 | } |
| 6665 | |
| 6666 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 6667 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 6668 | return Address::RIP(fixup); |
| 6669 | } |
| 6670 | |
| 6671 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 6672 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 6673 | return Address::RIP(fixup); |
| 6674 | } |
| 6675 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6676 | // TODO: trg as memory. |
| 6677 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 6678 | if (!trg.IsValid()) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6679 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6680 | return; |
| 6681 | } |
| 6682 | |
| 6683 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 6684 | |
| 6685 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 6686 | if (trg.Equals(return_loc)) { |
| 6687 | return; |
| 6688 | } |
| 6689 | |
| 6690 | // Let the parallel move resolver take care of all of this. |
| 6691 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6692 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 6693 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6694 | } |
| 6695 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6696 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 6697 | // Create a fixup to be used to create and address the jump table. |
| 6698 | JumpTableRIPFixup* table_fixup = |
| 6699 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 6700 | |
| 6701 | // We have to populate the jump tables. |
| 6702 | fixups_to_jump_tables_.push_back(table_fixup); |
| 6703 | return Address::RIP(table_fixup); |
| 6704 | } |
| 6705 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 6706 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 6707 | const Address& addr_high, |
| 6708 | int64_t v, |
| 6709 | HInstruction* instruction) { |
| 6710 | if (IsInt<32>(v)) { |
| 6711 | int32_t v_32 = v; |
| 6712 | __ movq(addr_low, Immediate(v_32)); |
| 6713 | MaybeRecordImplicitNullCheck(instruction); |
| 6714 | } else { |
| 6715 | // Didn't fit in a register. Do it in pieces. |
| 6716 | int32_t low_v = Low32Bits(v); |
| 6717 | int32_t high_v = High32Bits(v); |
| 6718 | __ movl(addr_low, Immediate(low_v)); |
| 6719 | MaybeRecordImplicitNullCheck(instruction); |
| 6720 | __ movl(addr_high, Immediate(high_v)); |
| 6721 | } |
| 6722 | } |
| 6723 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6724 | #undef __ |
| 6725 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 6726 | } // namespace x86_64 |
| 6727 | } // namespace art |