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 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 37 | namespace x86_64 { |
| 38 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 39 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 40 | static constexpr Register kMethodRegisterArgument = RDI; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 41 | |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 42 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 43 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 44 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 45 | static constexpr int kC2ConditionMask = 0x400; |
| 46 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 47 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 48 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 49 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 50 | class NullCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 51 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 52 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 53 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 54 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 55 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 56 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 57 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 58 | // Live registers will be restored in the catch block if caught. |
| 59 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 60 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 61 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 62 | instruction_, |
| 63 | instruction_->GetDexPc(), |
| 64 | this); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 65 | } |
| 66 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 67 | bool IsFatal() const OVERRIDE { return true; } |
| 68 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 69 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86_64"; } |
| 70 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 71 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 72 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 73 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 74 | }; |
| 75 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 76 | class DivZeroCheckSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 77 | public: |
| 78 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 79 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 80 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 81 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 82 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 83 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 84 | // Live registers will be restored in the catch block if caught. |
| 85 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 86 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 87 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 88 | instruction_, |
| 89 | instruction_->GetDexPc(), |
| 90 | this); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 93 | bool IsFatal() const OVERRIDE { return true; } |
| 94 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 95 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86_64"; } |
| 96 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 97 | private: |
| 98 | HDivZeroCheck* const instruction_; |
| 99 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 100 | }; |
| 101 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 102 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 104 | DivRemMinusOneSlowPathX86_64(Register reg, Primitive::Type type, bool is_div) |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 105 | : cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 106 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 107 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 108 | __ Bind(GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 109 | if (type_ == Primitive::kPrimInt) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 110 | if (is_div_) { |
| 111 | __ negl(cpu_reg_); |
| 112 | } else { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 113 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 116 | } else { |
| 117 | DCHECK_EQ(Primitive::kPrimLong, type_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 118 | if (is_div_) { |
| 119 | __ negq(cpu_reg_); |
| 120 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 121 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 122 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 123 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 124 | __ jmp(GetExitLabel()); |
| 125 | } |
| 126 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 127 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86_64"; } |
| 128 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 129 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 130 | const CpuRegister cpu_reg_; |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 131 | const Primitive::Type type_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 132 | const bool is_div_; |
| 133 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 136 | class SuspendCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 137 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 138 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 139 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 140 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 141 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 142 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 143 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 144 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 145 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 146 | instruction_, |
| 147 | instruction_->GetDexPc(), |
| 148 | this); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 149 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 150 | if (successor_ == nullptr) { |
| 151 | __ jmp(GetReturnLabel()); |
| 152 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 153 | __ jmp(x64_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 154 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 157 | Label* GetReturnLabel() { |
| 158 | DCHECK(successor_ == nullptr); |
| 159 | return &return_label_; |
| 160 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 161 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 162 | HBasicBlock* GetSuccessor() const { |
| 163 | return successor_; |
| 164 | } |
| 165 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 166 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 167 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 168 | private: |
| 169 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 170 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 171 | Label return_label_; |
| 172 | |
| 173 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 174 | }; |
| 175 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 176 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 177 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 178 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
| 179 | : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 180 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 181 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 182 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 183 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 184 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 185 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 186 | // Live registers will be restored in the catch block if caught. |
| 187 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 188 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 189 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 190 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 191 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 192 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 193 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 194 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 195 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 196 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 197 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 198 | Primitive::kPrimInt); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 199 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 200 | instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 201 | } |
| 202 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 203 | bool IsFatal() const OVERRIDE { return true; } |
| 204 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 205 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 206 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 207 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 208 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 209 | |
| 210 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 211 | }; |
| 212 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 213 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 214 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 215 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 216 | HInstruction* at, |
| 217 | uint32_t dex_pc, |
| 218 | bool do_clinit) |
| 219 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 220 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 221 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 222 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 223 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 224 | LocationSummary* locations = at_->GetLocations(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 225 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 226 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 227 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 228 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 229 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 230 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 231 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 232 | x64_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 233 | : QUICK_ENTRY_POINT(pInitializeType), |
| 234 | at_, dex_pc_, this); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 235 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 236 | Location out = locations->Out(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 237 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 238 | if (out.IsValid()) { |
| 239 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 240 | x64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 241 | } |
| 242 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 243 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 244 | __ jmp(GetExitLabel()); |
| 245 | } |
| 246 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 247 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 248 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 249 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 250 | // The class this slow path will load. |
| 251 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 252 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 253 | // The instruction where this slow path is happening. |
| 254 | // (Might be the load class or an initialization check). |
| 255 | HInstruction* const at_; |
| 256 | |
| 257 | // The dex PC of `at_`. |
| 258 | const uint32_t dex_pc_; |
| 259 | |
| 260 | // Whether to initialize the class. |
| 261 | const bool do_clinit_; |
| 262 | |
| 263 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 264 | }; |
| 265 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 266 | class LoadStringSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 267 | public: |
| 268 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : instruction_(instruction) {} |
| 269 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 270 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 271 | LocationSummary* locations = instruction_->GetLocations(); |
| 272 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 273 | |
| 274 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 275 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 276 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 277 | |
| 278 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 279 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 280 | Immediate(instruction_->GetStringIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 281 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 282 | instruction_, |
| 283 | instruction_->GetDexPc(), |
| 284 | this); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 285 | x64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 286 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 287 | __ jmp(GetExitLabel()); |
| 288 | } |
| 289 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 290 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86_64"; } |
| 291 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 292 | private: |
| 293 | HLoadString* const instruction_; |
| 294 | |
| 295 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 296 | }; |
| 297 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 298 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 299 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 300 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
| 301 | : instruction_(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 302 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 303 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 304 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 305 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 306 | : locations->Out(); |
| 307 | uint32_t dex_pc = instruction_->GetDexPc(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 308 | DCHECK(instruction_->IsCheckCast() |
| 309 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 310 | |
| 311 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 312 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 313 | |
| 314 | if (instruction_->IsCheckCast()) { |
| 315 | // The codegen for the instruction overwrites `temp`, so put it back in place. |
| 316 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 317 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 318 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 319 | __ movl(temp, Address(obj, class_offset)); |
| 320 | __ MaybeUnpoisonHeapReference(temp); |
| 321 | } |
| 322 | |
| 323 | if (!is_fatal_) { |
| 324 | SaveLiveRegisters(codegen, locations); |
| 325 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 326 | |
| 327 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 328 | // move resolver. |
| 329 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 330 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 331 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 332 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 333 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 334 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 335 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 336 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 337 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 338 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 339 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 340 | instruction_, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 341 | dex_pc, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 342 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 343 | } else { |
| 344 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 345 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 346 | instruction_, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 347 | dex_pc, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 348 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 349 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 350 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 351 | if (!is_fatal_) { |
| 352 | if (instruction_->IsInstanceOf()) { |
| 353 | x64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| 354 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 355 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 356 | RestoreLiveRegisters(codegen, locations); |
| 357 | __ jmp(GetExitLabel()); |
| 358 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 361 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 362 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 363 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 364 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 365 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 366 | HInstruction* const instruction_; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 367 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 368 | |
| 369 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 370 | }; |
| 371 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 372 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 373 | public: |
| 374 | explicit DeoptimizationSlowPathX86_64(HInstruction* instruction) |
| 375 | : instruction_(instruction) {} |
| 376 | |
| 377 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 378 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 379 | __ Bind(GetEntryLabel()); |
| 380 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 381 | DCHECK(instruction_->IsDeoptimize()); |
| 382 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 383 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 384 | deoptimize, |
| 385 | deoptimize->GetDexPc(), |
| 386 | this); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 389 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 390 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 391 | private: |
| 392 | HInstruction* const instruction_; |
| 393 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 394 | }; |
| 395 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 396 | class ArraySetSlowPathX86_64 : public SlowPathCode { |
| 397 | public: |
| 398 | explicit ArraySetSlowPathX86_64(HInstruction* instruction) : instruction_(instruction) {} |
| 399 | |
| 400 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 401 | LocationSummary* locations = instruction_->GetLocations(); |
| 402 | __ Bind(GetEntryLabel()); |
| 403 | SaveLiveRegisters(codegen, locations); |
| 404 | |
| 405 | InvokeRuntimeCallingConvention calling_convention; |
| 406 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 407 | parallel_move.AddMove( |
| 408 | locations->InAt(0), |
| 409 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 410 | Primitive::kPrimNot, |
| 411 | nullptr); |
| 412 | parallel_move.AddMove( |
| 413 | locations->InAt(1), |
| 414 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 415 | Primitive::kPrimInt, |
| 416 | nullptr); |
| 417 | parallel_move.AddMove( |
| 418 | locations->InAt(2), |
| 419 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 420 | Primitive::kPrimNot, |
| 421 | nullptr); |
| 422 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 423 | |
| 424 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 425 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 426 | instruction_, |
| 427 | instruction_->GetDexPc(), |
| 428 | this); |
| 429 | RestoreLiveRegisters(codegen, locations); |
| 430 | __ jmp(GetExitLabel()); |
| 431 | } |
| 432 | |
| 433 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86_64"; } |
| 434 | |
| 435 | private: |
| 436 | HInstruction* const instruction_; |
| 437 | |
| 438 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 439 | }; |
| 440 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 441 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 442 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 443 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 444 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 445 | switch (cond) { |
| 446 | case kCondEQ: return kEqual; |
| 447 | case kCondNE: return kNotEqual; |
| 448 | case kCondLT: return kLess; |
| 449 | case kCondLE: return kLessEqual; |
| 450 | case kCondGT: return kGreater; |
| 451 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 452 | case kCondB: return kBelow; |
| 453 | case kCondBE: return kBelowEqual; |
| 454 | case kCondA: return kAbove; |
| 455 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 456 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 457 | LOG(FATAL) << "Unreachable"; |
| 458 | UNREACHABLE(); |
| 459 | } |
| 460 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 461 | // Maps FP condition to x86_64 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 462 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 463 | switch (cond) { |
| 464 | case kCondEQ: return kEqual; |
| 465 | case kCondNE: return kNotEqual; |
| 466 | case kCondLT: return kBelow; |
| 467 | case kCondLE: return kBelowEqual; |
| 468 | case kCondGT: return kAbove; |
| 469 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 470 | default: break; // should not happen |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 471 | }; |
| 472 | LOG(FATAL) << "Unreachable"; |
| 473 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 474 | } |
| 475 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 476 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86_64::GetSupportedInvokeStaticOrDirectDispatch( |
| 477 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 478 | MethodReference target_method ATTRIBUTE_UNUSED) { |
| 479 | switch (desired_dispatch_info.code_ptr_location) { |
| 480 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 481 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 482 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 483 | return HInvokeStaticOrDirect::DispatchInfo { |
| 484 | desired_dispatch_info.method_load_kind, |
| 485 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 486 | desired_dispatch_info.method_load_data, |
| 487 | 0u |
| 488 | }; |
| 489 | default: |
| 490 | return desired_dispatch_info; |
| 491 | } |
| 492 | } |
| 493 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 494 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 495 | Location temp) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 496 | // All registers are assumed to be correctly set up. |
| 497 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 498 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 499 | switch (invoke->GetMethodLoadKind()) { |
| 500 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 501 | // temp = thread->string_init_entrypoint |
| 502 | __ gs()->movl(temp.AsRegister<CpuRegister>(), |
| 503 | Address::Absolute(invoke->GetStringInitOffset(), true)); |
| 504 | break; |
| 505 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 506 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 507 | break; |
| 508 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 509 | __ movq(temp.AsRegister<CpuRegister>(), Immediate(invoke->GetMethodAddress())); |
| 510 | break; |
| 511 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 512 | __ movl(temp.AsRegister<CpuRegister>(), Immediate(0)); // Placeholder. |
| 513 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 514 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 515 | break; |
| 516 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
| 517 | pc_rel_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 518 | invoke->GetDexCacheArrayOffset()); |
| 519 | __ movq(temp.AsRegister<CpuRegister>(), |
| 520 | Address::Absolute(kDummy32BitOffset, false /* no_rip */)); |
| 521 | // Bind the label at the end of the "movl" insn. |
| 522 | __ Bind(&pc_rel_dex_cache_patches_.back().label); |
| 523 | break; |
| 524 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 525 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 526 | Register method_reg; |
| 527 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
| 528 | if (current_method.IsRegister()) { |
| 529 | method_reg = current_method.AsRegister<Register>(); |
| 530 | } else { |
| 531 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 532 | DCHECK(!current_method.IsValid()); |
| 533 | method_reg = reg.AsRegister(); |
| 534 | __ movq(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 535 | } |
| 536 | // temp = temp->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 537 | __ movq(reg, |
| 538 | Address(CpuRegister(method_reg), |
| 539 | ArtMethod::DexCacheResolvedMethodsOffset(kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 540 | // temp = temp[index_in_cache] |
| 541 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 542 | __ movq(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 543 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 544 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | switch (invoke->GetCodePtrLocation()) { |
| 548 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 549 | __ call(&frame_entry_label_); |
| 550 | break; |
| 551 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 552 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 553 | Label* label = &relative_call_patches_.back().label; |
| 554 | __ call(label); // Bind to the patch label, override at link time. |
| 555 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 556 | break; |
| 557 | } |
| 558 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 559 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 560 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 561 | LOG(FATAL) << "Unsupported"; |
| 562 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 563 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 564 | // (callee_method + offset_of_quick_compiled_code)() |
| 565 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 566 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 567 | kX86_64WordSize).SizeValue())); |
| 568 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 569 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 570 | |
| 571 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 572 | } |
| 573 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 574 | void CodeGeneratorX86_64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 575 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 576 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 577 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
| 578 | LocationSummary* locations = invoke->GetLocations(); |
| 579 | Location receiver = locations->InAt(0); |
| 580 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 581 | // temp = object->GetClass(); |
| 582 | DCHECK(receiver.IsRegister()); |
| 583 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
| 584 | MaybeRecordImplicitNullCheck(invoke); |
| 585 | __ MaybeUnpoisonHeapReference(temp); |
| 586 | // temp = temp->GetMethodAt(method_offset); |
| 587 | __ movq(temp, Address(temp, method_offset)); |
| 588 | // call temp->GetEntryPoint(); |
| 589 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 590 | kX86_64WordSize).SizeValue())); |
| 591 | } |
| 592 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 593 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 594 | DCHECK(linker_patches->empty()); |
| 595 | size_t size = |
| 596 | method_patches_.size() + relative_call_patches_.size() + pc_rel_dex_cache_patches_.size(); |
| 597 | linker_patches->reserve(size); |
| 598 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
| 599 | // The label points to the end of the "movl" instruction but the literal offset for method |
| 600 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 601 | uint32_t literal_offset = info.label.Position() - 4; |
| 602 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 603 | info.target_method.dex_file, |
| 604 | info.target_method.dex_method_index)); |
| 605 | } |
| 606 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 607 | // The label points to the end of the "call" instruction but the literal offset for method |
| 608 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 609 | uint32_t literal_offset = info.label.Position() - 4; |
| 610 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 611 | info.target_method.dex_file, |
| 612 | info.target_method.dex_method_index)); |
| 613 | } |
| 614 | for (const PcRelativeDexCacheAccessInfo& info : pc_rel_dex_cache_patches_) { |
| 615 | // The label points to the end of the "mov" instruction but the literal offset for method |
| 616 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 617 | uint32_t literal_offset = info.label.Position() - 4; |
| 618 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 619 | &info.target_dex_file, |
| 620 | info.label.Position(), |
| 621 | info.element_offset)); |
| 622 | } |
| 623 | } |
| 624 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 625 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 626 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 630 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 631 | } |
| 632 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 633 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 634 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 635 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 636 | } |
| 637 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 638 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 639 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 640 | return kX86_64WordSize; |
| 641 | } |
| 642 | |
| 643 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 644 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 645 | return kX86_64WordSize; |
| 646 | } |
| 647 | |
| 648 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 649 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 650 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 651 | } |
| 652 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 653 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 654 | HInstruction* instruction, |
| 655 | uint32_t dex_pc, |
| 656 | SlowPathCode* slow_path) { |
| 657 | InvokeRuntime(GetThreadOffset<kX86_64WordSize>(entrypoint).Int32Value(), |
| 658 | instruction, |
| 659 | dex_pc, |
| 660 | slow_path); |
| 661 | } |
| 662 | |
| 663 | void CodeGeneratorX86_64::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 664 | HInstruction* instruction, |
| 665 | uint32_t dex_pc, |
| 666 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 667 | ValidateInvokeRuntime(instruction, slow_path); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 668 | __ gs()->call(Address::Absolute(entry_point_offset, true)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 669 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 670 | } |
| 671 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 672 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 673 | // Use a fake return address register to mimic Quick. |
| 674 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 675 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
| 676 | const X86_64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 677 | const CompilerOptions& compiler_options, |
| 678 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 679 | : CodeGenerator(graph, |
| 680 | kNumberOfCpuRegisters, |
| 681 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 682 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 683 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 684 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 685 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 686 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 687 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 688 | compiler_options, |
| 689 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 690 | block_labels_(nullptr), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 691 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 692 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 693 | move_resolver_(graph->GetArena(), this), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 694 | isa_features_(isa_features), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 695 | constant_area_start_(0), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 696 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 697 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 698 | pc_rel_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 699 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 700 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 701 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 702 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 703 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 704 | CodeGeneratorX86_64* codegen) |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 705 | : HGraphVisitor(graph), |
| 706 | assembler_(codegen->GetAssembler()), |
| 707 | codegen_(codegen) {} |
| 708 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 709 | Location CodeGeneratorX86_64::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 710 | switch (type) { |
| 711 | case Primitive::kPrimLong: |
| 712 | case Primitive::kPrimByte: |
| 713 | case Primitive::kPrimBoolean: |
| 714 | case Primitive::kPrimChar: |
| 715 | case Primitive::kPrimShort: |
| 716 | case Primitive::kPrimInt: |
| 717 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 718 | size_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 719 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 723 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 724 | size_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfFloatRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 725 | return Location::FpuRegisterLocation(reg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 726 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 727 | |
| 728 | case Primitive::kPrimVoid: |
| 729 | LOG(FATAL) << "Unreachable type " << type; |
| 730 | } |
| 731 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 732 | return Location(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 733 | } |
| 734 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 735 | void CodeGeneratorX86_64::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 736 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 737 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 738 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 739 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 740 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 741 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 742 | if (is_baseline) { |
| 743 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 744 | blocked_core_registers_[kCoreCalleeSaves[i]] = true; |
| 745 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 746 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 747 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 748 | } |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 749 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 750 | } |
| 751 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 752 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 753 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 754 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 755 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 756 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 757 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 758 | } |
| 759 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 760 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 761 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 762 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 763 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 764 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 765 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 766 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 767 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 768 | __ testq(CpuRegister(RAX), Address( |
| 769 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 770 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 771 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 772 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 773 | if (HasEmptyFrame()) { |
| 774 | return; |
| 775 | } |
| 776 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 777 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 778 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 779 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 780 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 781 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 782 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 783 | } |
| 784 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 785 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 786 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 787 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 788 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 789 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 790 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 791 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 792 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 793 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 794 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 795 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 796 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 797 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 798 | } |
| 799 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 800 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 801 | CpuRegister(kMethodRegisterArgument)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 805 | __ cfi().RememberState(); |
| 806 | if (!HasEmptyFrame()) { |
| 807 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 808 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 809 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 810 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 811 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 812 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 813 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 818 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 819 | __ cfi().AdjustCFAOffset(-adjust); |
| 820 | |
| 821 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 822 | Register reg = kCoreCalleeSaves[i]; |
| 823 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 824 | __ popq(CpuRegister(reg)); |
| 825 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 826 | __ cfi().Restore(DWARFReg(reg)); |
| 827 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 828 | } |
| 829 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 830 | __ ret(); |
| 831 | __ cfi().RestoreState(); |
| 832 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 833 | } |
| 834 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 835 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 836 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 837 | } |
| 838 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 839 | Location CodeGeneratorX86_64::GetStackLocation(HLoadLocal* load) const { |
| 840 | switch (load->GetType()) { |
| 841 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 842 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 843 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 844 | |
| 845 | case Primitive::kPrimInt: |
| 846 | case Primitive::kPrimNot: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 847 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 848 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 849 | |
| 850 | case Primitive::kPrimBoolean: |
| 851 | case Primitive::kPrimByte: |
| 852 | case Primitive::kPrimChar: |
| 853 | case Primitive::kPrimShort: |
| 854 | case Primitive::kPrimVoid: |
| 855 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 856 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 860 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 864 | if (source.Equals(destination)) { |
| 865 | return; |
| 866 | } |
| 867 | if (destination.IsRegister()) { |
| 868 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 869 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 870 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 871 | __ movd(destination.AsRegister<CpuRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 872 | } else if (source.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 873 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 874 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 875 | } else { |
| 876 | DCHECK(source.IsDoubleStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 877 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 878 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 879 | } |
| 880 | } else if (destination.IsFpuRegister()) { |
| 881 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 882 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 883 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 884 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 885 | } else if (source.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 886 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 887 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 888 | } else { |
| 889 | DCHECK(source.IsDoubleStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 890 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 891 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 892 | } |
| 893 | } else if (destination.IsStackSlot()) { |
| 894 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 895 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 896 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 897 | } else if (source.IsFpuRegister()) { |
| 898 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 899 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 900 | } else if (source.IsConstant()) { |
| 901 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 902 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 903 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 904 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 905 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 906 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 907 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 908 | } |
| 909 | } else { |
| 910 | DCHECK(destination.IsDoubleStackSlot()); |
| 911 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 912 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 913 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 914 | } else if (source.IsFpuRegister()) { |
| 915 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 916 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 917 | } else if (source.IsConstant()) { |
| 918 | HConstant* constant = source.GetConstant(); |
Zheng Xu | 12bca97 | 2015-03-30 19:35:50 +0800 | [diff] [blame] | 919 | int64_t value; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 920 | if (constant->IsDoubleConstant()) { |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 921 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 922 | } else { |
| 923 | DCHECK(constant->IsLongConstant()); |
| 924 | value = constant->AsLongConstant()->GetValue(); |
| 925 | } |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 926 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 927 | } else { |
| 928 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 929 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 930 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 931 | } |
| 932 | } |
| 933 | } |
| 934 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 935 | void CodeGeneratorX86_64::Move(HInstruction* instruction, |
| 936 | Location location, |
| 937 | HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 938 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 939 | if (instruction->IsCurrentMethod()) { |
Mathieu Chartier | e3b034a | 2015-05-31 14:29:23 -0700 | [diff] [blame] | 940 | Move(location, Location::DoubleStackSlot(kCurrentMethodStackOffset)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 941 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 942 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 943 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 944 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 945 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 946 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 947 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 948 | __ movl(location.AsRegister<CpuRegister>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 949 | } else if (location.IsStackSlot()) { |
| 950 | __ movl(Address(CpuRegister(RSP), location.GetStackIndex()), imm); |
| 951 | } else { |
| 952 | DCHECK(location.IsConstant()); |
| 953 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 954 | } |
| 955 | } else if (const_to_move->IsLongConstant()) { |
| 956 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 957 | if (location.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 958 | Load64BitValue(location.AsRegister<CpuRegister>(), value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 959 | } else if (location.IsDoubleStackSlot()) { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 960 | Store64BitValueToStack(location, value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 961 | } else { |
| 962 | DCHECK(location.IsConstant()); |
| 963 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 964 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 965 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 966 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 967 | switch (instruction->GetType()) { |
| 968 | case Primitive::kPrimBoolean: |
| 969 | case Primitive::kPrimByte: |
| 970 | case Primitive::kPrimChar: |
| 971 | case Primitive::kPrimShort: |
| 972 | case Primitive::kPrimInt: |
| 973 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 974 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 975 | Move(location, Location::StackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
| 976 | break; |
| 977 | |
| 978 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 979 | case Primitive::kPrimDouble: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 980 | Move(location, |
| 981 | Location::DoubleStackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 982 | break; |
| 983 | |
| 984 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 985 | LOG(FATAL) << "Unexpected local type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 986 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 987 | } else if (instruction->IsTemporary()) { |
| 988 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
| 989 | Move(location, temp_location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 990 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 991 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 992 | switch (instruction->GetType()) { |
| 993 | case Primitive::kPrimBoolean: |
| 994 | case Primitive::kPrimByte: |
| 995 | case Primitive::kPrimChar: |
| 996 | case Primitive::kPrimShort: |
| 997 | case Primitive::kPrimInt: |
| 998 | case Primitive::kPrimNot: |
| 999 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1000 | case Primitive::kPrimFloat: |
| 1001 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1002 | Move(location, locations->Out()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1003 | break; |
| 1004 | |
| 1005 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1006 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1007 | } |
| 1008 | } |
| 1009 | } |
| 1010 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1011 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1012 | DCHECK(location.IsRegister()); |
| 1013 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1014 | } |
| 1015 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1016 | void CodeGeneratorX86_64::MoveLocation( |
| 1017 | Location dst, Location src, Primitive::Type dst_type ATTRIBUTE_UNUSED) { |
| 1018 | Move(dst, src); |
| 1019 | } |
| 1020 | |
| 1021 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1022 | if (location.IsRegister()) { |
| 1023 | locations->AddTemp(location); |
| 1024 | } else { |
| 1025 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1026 | } |
| 1027 | } |
| 1028 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1029 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1030 | DCHECK(!successor->IsExitBlock()); |
| 1031 | |
| 1032 | HBasicBlock* block = got->GetBlock(); |
| 1033 | HInstruction* previous = got->GetPrevious(); |
| 1034 | |
| 1035 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1036 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1037 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1038 | return; |
| 1039 | } |
| 1040 | |
| 1041 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1042 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1043 | } |
| 1044 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1045 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1046 | } |
| 1047 | } |
| 1048 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1049 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1050 | got->SetLocations(nullptr); |
| 1051 | } |
| 1052 | |
| 1053 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1054 | HandleGoto(got, got->GetSuccessor()); |
| 1055 | } |
| 1056 | |
| 1057 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1058 | try_boundary->SetLocations(nullptr); |
| 1059 | } |
| 1060 | |
| 1061 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1062 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1063 | if (!successor->IsExitBlock()) { |
| 1064 | HandleGoto(try_boundary, successor); |
| 1065 | } |
| 1066 | } |
| 1067 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1068 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1069 | exit->SetLocations(nullptr); |
| 1070 | } |
| 1071 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1072 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1073 | } |
| 1074 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1075 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
| 1076 | Label* true_label, |
| 1077 | Label* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1078 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1079 | __ j(kUnordered, true_label); |
| 1080 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1081 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1082 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1083 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HIf* if_instr, |
| 1087 | HCondition* condition, |
| 1088 | Label* true_target, |
| 1089 | Label* false_target, |
| 1090 | Label* always_true_target) { |
| 1091 | LocationSummary* locations = condition->GetLocations(); |
| 1092 | Location left = locations->InAt(0); |
| 1093 | Location right = locations->InAt(1); |
| 1094 | |
| 1095 | // We don't want true_target as a nullptr. |
| 1096 | if (true_target == nullptr) { |
| 1097 | true_target = always_true_target; |
| 1098 | } |
| 1099 | bool falls_through = (false_target == nullptr); |
| 1100 | |
| 1101 | // FP compares don't like null false_targets. |
| 1102 | if (false_target == nullptr) { |
| 1103 | false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1104 | } |
| 1105 | |
| 1106 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1107 | switch (type) { |
| 1108 | case Primitive::kPrimLong: { |
| 1109 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1110 | if (right.IsConstant()) { |
| 1111 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1112 | if (IsInt<32>(value)) { |
| 1113 | if (value == 0) { |
| 1114 | __ testq(left_reg, left_reg); |
| 1115 | } else { |
| 1116 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 1117 | } |
| 1118 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1119 | // Value won't fit in a 32-bit integer. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1120 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
| 1121 | } |
| 1122 | } else if (right.IsDoubleStackSlot()) { |
| 1123 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1124 | } else { |
| 1125 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1126 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1127 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1128 | break; |
| 1129 | } |
| 1130 | case Primitive::kPrimFloat: { |
| 1131 | if (right.IsFpuRegister()) { |
| 1132 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1133 | } else if (right.IsConstant()) { |
| 1134 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1135 | codegen_->LiteralFloatAddress( |
| 1136 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1137 | } else { |
| 1138 | DCHECK(right.IsStackSlot()); |
| 1139 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1140 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1141 | } |
| 1142 | GenerateFPJumps(condition, true_target, false_target); |
| 1143 | break; |
| 1144 | } |
| 1145 | case Primitive::kPrimDouble: { |
| 1146 | if (right.IsFpuRegister()) { |
| 1147 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1148 | } else if (right.IsConstant()) { |
| 1149 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1150 | codegen_->LiteralDoubleAddress( |
| 1151 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1152 | } else { |
| 1153 | DCHECK(right.IsDoubleStackSlot()); |
| 1154 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1155 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1156 | } |
| 1157 | GenerateFPJumps(condition, true_target, false_target); |
| 1158 | break; |
| 1159 | } |
| 1160 | default: |
| 1161 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1162 | } |
| 1163 | |
| 1164 | if (!falls_through) { |
| 1165 | __ jmp(false_target); |
| 1166 | } |
| 1167 | } |
| 1168 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1169 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
| 1170 | Label* true_target, |
| 1171 | Label* false_target, |
| 1172 | Label* always_true_target) { |
| 1173 | HInstruction* cond = instruction->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1174 | if (cond->IsIntConstant()) { |
| 1175 | // Constant condition, statically compared against 1. |
| 1176 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 1177 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1178 | if (always_true_target != nullptr) { |
| 1179 | __ jmp(always_true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1180 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1181 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1182 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1183 | DCHECK_EQ(cond_value, 0); |
| 1184 | } |
| 1185 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame^] | 1186 | HCondition* condition = cond->AsCondition(); |
| 1187 | bool is_materialized = condition == nullptr || condition->NeedsMaterialization(); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1188 | // Moves do not affect the eflags register, so if the condition is |
| 1189 | // evaluated just before the if, we don't need to evaluate it |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1190 | // again. We can't use the eflags on FP conditions if they are |
| 1191 | // materialized due to the complex branching. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame^] | 1192 | Primitive::Type type = (condition != nullptr) |
| 1193 | ? cond->InputAt(0)->GetType() |
| 1194 | : Primitive::kPrimInt; |
| 1195 | bool eflags_set = condition != nullptr |
| 1196 | && condition->IsBeforeWhenDisregardMoves(instruction) |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1197 | && !Primitive::IsFloatingPointType(type); |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame^] | 1198 | // Can we optimize the jump if we know that the next block is the true case? |
| 1199 | bool can_jump_to_false = CanReverseCondition(always_true_target, false_target, condition); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1200 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1201 | if (is_materialized) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1202 | if (!eflags_set) { |
| 1203 | // Materialized condition, compare against 0. |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1204 | Location lhs = instruction->GetLocations()->InAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1205 | if (lhs.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 1206 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1207 | } else { |
| 1208 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), |
| 1209 | Immediate(0)); |
| 1210 | } |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame^] | 1211 | if (can_jump_to_false) { |
| 1212 | __ j(kEqual, false_target); |
| 1213 | return; |
| 1214 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1215 | __ j(kNotEqual, true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1216 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame^] | 1217 | if (can_jump_to_false) { |
| 1218 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1219 | return; |
| 1220 | } |
| 1221 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1222 | } |
| 1223 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1224 | // Condition has not been materialized, use its inputs as the |
| 1225 | // comparison and its condition as the branch condition. |
| 1226 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1227 | // Is this a long or FP comparison that has been folded into the HCondition? |
| 1228 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1229 | // Generate the comparison directly. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame^] | 1230 | GenerateCompareTestAndBranch(instruction->AsIf(), condition, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1231 | true_target, false_target, always_true_target); |
| 1232 | return; |
| 1233 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1234 | |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1235 | Location lhs = cond->GetLocations()->InAt(0); |
| 1236 | Location rhs = cond->GetLocations()->InAt(1); |
| 1237 | if (rhs.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1238 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1239 | } else if (rhs.IsConstant()) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1240 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 1241 | if (constant == 0) { |
| 1242 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1243 | } else { |
| 1244 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
| 1245 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1246 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1247 | __ cmpl(lhs.AsRegister<CpuRegister>(), |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1248 | Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1249 | } |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame^] | 1250 | |
| 1251 | if (can_jump_to_false) { |
| 1252 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1253 | return; |
| 1254 | } |
| 1255 | |
| 1256 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1257 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1258 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1259 | if (false_target != nullptr) { |
| 1260 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1261 | } |
| 1262 | } |
| 1263 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1264 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
| 1265 | LocationSummary* locations = |
| 1266 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
| 1267 | HInstruction* cond = if_instr->InputAt(0); |
| 1268 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1269 | locations->SetInAt(0, Location::Any()); |
| 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
| 1274 | Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1275 | Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1276 | Label* always_true_target = true_target; |
| 1277 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1278 | if_instr->IfTrueSuccessor())) { |
| 1279 | always_true_target = nullptr; |
| 1280 | } |
| 1281 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1282 | if_instr->IfFalseSuccessor())) { |
| 1283 | false_target = nullptr; |
| 1284 | } |
| 1285 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 1286 | } |
| 1287 | |
| 1288 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1289 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1290 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1291 | HInstruction* cond = deoptimize->InputAt(0); |
Aart Bik | bb245d1 | 2015-10-19 11:05:03 -0700 | [diff] [blame] | 1292 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1293 | locations->SetInAt(0, Location::Any()); |
| 1294 | } |
| 1295 | } |
| 1296 | |
| 1297 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 1298 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1299 | DeoptimizationSlowPathX86_64(deoptimize); |
| 1300 | codegen_->AddSlowPath(slow_path); |
| 1301 | Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 1302 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 1303 | } |
| 1304 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1305 | void LocationsBuilderX86_64::VisitLocal(HLocal* local) { |
| 1306 | local->SetLocations(nullptr); |
| 1307 | } |
| 1308 | |
| 1309 | void InstructionCodeGeneratorX86_64::VisitLocal(HLocal* local) { |
| 1310 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 1311 | } |
| 1312 | |
| 1313 | void LocationsBuilderX86_64::VisitLoadLocal(HLoadLocal* local) { |
| 1314 | local->SetLocations(nullptr); |
| 1315 | } |
| 1316 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1317 | void InstructionCodeGeneratorX86_64::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1318 | // Nothing to do, this is driven by the code generator. |
| 1319 | } |
| 1320 | |
| 1321 | void LocationsBuilderX86_64::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1322 | LocationSummary* locations = |
| 1323 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1324 | switch (store->InputAt(1)->GetType()) { |
| 1325 | case Primitive::kPrimBoolean: |
| 1326 | case Primitive::kPrimByte: |
| 1327 | case Primitive::kPrimChar: |
| 1328 | case Primitive::kPrimShort: |
| 1329 | case Primitive::kPrimInt: |
| 1330 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1331 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1332 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1333 | break; |
| 1334 | |
| 1335 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1336 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1337 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1338 | break; |
| 1339 | |
| 1340 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1341 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1342 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1343 | } |
| 1344 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1345 | void InstructionCodeGeneratorX86_64::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1346 | } |
| 1347 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1348 | void LocationsBuilderX86_64::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1349 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1350 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1351 | // Handle the long/FP comparisons made in instruction simplification. |
| 1352 | switch (cond->InputAt(0)->GetType()) { |
| 1353 | case Primitive::kPrimLong: |
| 1354 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1355 | locations->SetInAt(1, Location::Any()); |
| 1356 | break; |
| 1357 | case Primitive::kPrimFloat: |
| 1358 | case Primitive::kPrimDouble: |
| 1359 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1360 | locations->SetInAt(1, Location::Any()); |
| 1361 | break; |
| 1362 | default: |
| 1363 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1364 | locations->SetInAt(1, Location::Any()); |
| 1365 | break; |
| 1366 | } |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1367 | if (cond->NeedsMaterialization()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1368 | locations->SetOut(Location::RequiresRegister()); |
| 1369 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1370 | } |
| 1371 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1372 | void InstructionCodeGeneratorX86_64::VisitCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1373 | if (!cond->NeedsMaterialization()) { |
| 1374 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1375 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1376 | |
| 1377 | LocationSummary* locations = cond->GetLocations(); |
| 1378 | Location lhs = locations->InAt(0); |
| 1379 | Location rhs = locations->InAt(1); |
| 1380 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
| 1381 | Label true_label, false_label; |
| 1382 | |
| 1383 | switch (cond->InputAt(0)->GetType()) { |
| 1384 | default: |
| 1385 | // Integer case. |
| 1386 | |
| 1387 | // Clear output register: setcc only sets the low byte. |
| 1388 | __ xorl(reg, reg); |
| 1389 | |
| 1390 | if (rhs.IsRegister()) { |
| 1391 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1392 | } else if (rhs.IsConstant()) { |
| 1393 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1394 | if (constant == 0) { |
| 1395 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1396 | } else { |
| 1397 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
| 1398 | } |
| 1399 | } else { |
| 1400 | __ cmpl(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1401 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1402 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1403 | return; |
| 1404 | case Primitive::kPrimLong: |
| 1405 | // Clear output register: setcc only sets the low byte. |
| 1406 | __ xorl(reg, reg); |
| 1407 | |
| 1408 | if (rhs.IsRegister()) { |
| 1409 | __ cmpq(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1410 | } else if (rhs.IsConstant()) { |
| 1411 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 1412 | if (IsInt<32>(value)) { |
| 1413 | if (value == 0) { |
| 1414 | __ testq(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1415 | } else { |
| 1416 | __ cmpq(lhs.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 1417 | } |
| 1418 | } else { |
| 1419 | // Value won't fit in an int. |
| 1420 | __ cmpq(lhs.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 1421 | } |
| 1422 | } else { |
| 1423 | __ cmpq(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1424 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1425 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1426 | return; |
| 1427 | case Primitive::kPrimFloat: { |
| 1428 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1429 | if (rhs.IsConstant()) { |
| 1430 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1431 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1432 | } else if (rhs.IsStackSlot()) { |
| 1433 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1434 | } else { |
| 1435 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1436 | } |
| 1437 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1438 | break; |
| 1439 | } |
| 1440 | case Primitive::kPrimDouble: { |
| 1441 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1442 | if (rhs.IsConstant()) { |
| 1443 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1444 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1445 | } else if (rhs.IsDoubleStackSlot()) { |
| 1446 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1447 | } else { |
| 1448 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1449 | } |
| 1450 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1451 | break; |
| 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1456 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1457 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1458 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1459 | __ Bind(&false_label); |
| 1460 | __ xorl(reg, reg); |
| 1461 | __ jmp(&done_label); |
| 1462 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1463 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1464 | __ Bind(&true_label); |
| 1465 | __ movl(reg, Immediate(1)); |
| 1466 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
| 1470 | VisitCondition(comp); |
| 1471 | } |
| 1472 | |
| 1473 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
| 1474 | VisitCondition(comp); |
| 1475 | } |
| 1476 | |
| 1477 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
| 1478 | VisitCondition(comp); |
| 1479 | } |
| 1480 | |
| 1481 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
| 1482 | VisitCondition(comp); |
| 1483 | } |
| 1484 | |
| 1485 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
| 1486 | VisitCondition(comp); |
| 1487 | } |
| 1488 | |
| 1489 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
| 1490 | VisitCondition(comp); |
| 1491 | } |
| 1492 | |
| 1493 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1494 | VisitCondition(comp); |
| 1495 | } |
| 1496 | |
| 1497 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1498 | VisitCondition(comp); |
| 1499 | } |
| 1500 | |
| 1501 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 1502 | VisitCondition(comp); |
| 1503 | } |
| 1504 | |
| 1505 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 1506 | VisitCondition(comp); |
| 1507 | } |
| 1508 | |
| 1509 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1510 | VisitCondition(comp); |
| 1511 | } |
| 1512 | |
| 1513 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1514 | VisitCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1515 | } |
| 1516 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1517 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
| 1518 | VisitCondition(comp); |
| 1519 | } |
| 1520 | |
| 1521 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
| 1522 | VisitCondition(comp); |
| 1523 | } |
| 1524 | |
| 1525 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 1526 | VisitCondition(comp); |
| 1527 | } |
| 1528 | |
| 1529 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 1530 | VisitCondition(comp); |
| 1531 | } |
| 1532 | |
| 1533 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
| 1534 | VisitCondition(comp); |
| 1535 | } |
| 1536 | |
| 1537 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
| 1538 | VisitCondition(comp); |
| 1539 | } |
| 1540 | |
| 1541 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 1542 | VisitCondition(comp); |
| 1543 | } |
| 1544 | |
| 1545 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 1546 | VisitCondition(comp); |
| 1547 | } |
| 1548 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1549 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1550 | LocationSummary* locations = |
| 1551 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1552 | switch (compare->InputAt(0)->GetType()) { |
| 1553 | case Primitive::kPrimLong: { |
| 1554 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1555 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1556 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1557 | break; |
| 1558 | } |
| 1559 | case Primitive::kPrimFloat: |
| 1560 | case Primitive::kPrimDouble: { |
| 1561 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1562 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1563 | locations->SetOut(Location::RequiresRegister()); |
| 1564 | break; |
| 1565 | } |
| 1566 | default: |
| 1567 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 1568 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1572 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1573 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1574 | Location left = locations->InAt(0); |
| 1575 | Location right = locations->InAt(1); |
| 1576 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1577 | NearLabel less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1578 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 1579 | switch (type) { |
| 1580 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1581 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1582 | if (right.IsConstant()) { |
| 1583 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1584 | if (IsInt<32>(value)) { |
| 1585 | if (value == 0) { |
| 1586 | __ testq(left_reg, left_reg); |
| 1587 | } else { |
| 1588 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 1589 | } |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1590 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1591 | // Value won't fit in an int. |
| 1592 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1593 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1594 | } else if (right.IsDoubleStackSlot()) { |
| 1595 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1596 | } else { |
| 1597 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1598 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1599 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1600 | } |
| 1601 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1602 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1603 | if (right.IsConstant()) { |
| 1604 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 1605 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 1606 | } else if (right.IsStackSlot()) { |
| 1607 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1608 | } else { |
| 1609 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1610 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1611 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 1612 | break; |
| 1613 | } |
| 1614 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1615 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1616 | if (right.IsConstant()) { |
| 1617 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1618 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 1619 | } else if (right.IsDoubleStackSlot()) { |
| 1620 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1621 | } else { |
| 1622 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1623 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1624 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 1625 | break; |
| 1626 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1627 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1628 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1629 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1630 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1631 | __ j(kEqual, &done); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1632 | __ j(type == Primitive::kPrimLong ? kLess : kBelow, &less); // ucomis{s,d} sets CF (kBelow) |
Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1633 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1634 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1635 | __ movl(out, Immediate(1)); |
| 1636 | __ jmp(&done); |
| 1637 | |
| 1638 | __ Bind(&less); |
| 1639 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1640 | |
| 1641 | __ Bind(&done); |
| 1642 | } |
| 1643 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1644 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1645 | LocationSummary* locations = |
| 1646 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1647 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1648 | } |
| 1649 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1650 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1651 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1652 | } |
| 1653 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1654 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1655 | LocationSummary* locations = |
| 1656 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1657 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1658 | } |
| 1659 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1660 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1661 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1662 | } |
| 1663 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1664 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1665 | LocationSummary* locations = |
| 1666 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1667 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1668 | } |
| 1669 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1670 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1671 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1672 | } |
| 1673 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1674 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1675 | LocationSummary* locations = |
| 1676 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1677 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1678 | } |
| 1679 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1680 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1681 | // Will be generated at use site. |
| 1682 | } |
| 1683 | |
| 1684 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1685 | LocationSummary* locations = |
| 1686 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1687 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1688 | } |
| 1689 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1690 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 1691 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1692 | // Will be generated at use site. |
| 1693 | } |
| 1694 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1695 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1696 | memory_barrier->SetLocations(nullptr); |
| 1697 | } |
| 1698 | |
| 1699 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1700 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1701 | } |
| 1702 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1703 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 1704 | ret->SetLocations(nullptr); |
| 1705 | } |
| 1706 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1707 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1708 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1712 | LocationSummary* locations = |
| 1713 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1714 | switch (ret->InputAt(0)->GetType()) { |
| 1715 | case Primitive::kPrimBoolean: |
| 1716 | case Primitive::kPrimByte: |
| 1717 | case Primitive::kPrimChar: |
| 1718 | case Primitive::kPrimShort: |
| 1719 | case Primitive::kPrimInt: |
| 1720 | case Primitive::kPrimNot: |
| 1721 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1722 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1723 | break; |
| 1724 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1725 | case Primitive::kPrimFloat: |
| 1726 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1727 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1728 | break; |
| 1729 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1730 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1731 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1732 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 1736 | if (kIsDebugBuild) { |
| 1737 | switch (ret->InputAt(0)->GetType()) { |
| 1738 | case Primitive::kPrimBoolean: |
| 1739 | case Primitive::kPrimByte: |
| 1740 | case Primitive::kPrimChar: |
| 1741 | case Primitive::kPrimShort: |
| 1742 | case Primitive::kPrimInt: |
| 1743 | case Primitive::kPrimNot: |
| 1744 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1745 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1746 | break; |
| 1747 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1748 | case Primitive::kPrimFloat: |
| 1749 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1750 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1751 | XMM0); |
| 1752 | break; |
| 1753 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1754 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1755 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1756 | } |
| 1757 | } |
| 1758 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1759 | } |
| 1760 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1761 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 1762 | switch (type) { |
| 1763 | case Primitive::kPrimBoolean: |
| 1764 | case Primitive::kPrimByte: |
| 1765 | case Primitive::kPrimChar: |
| 1766 | case Primitive::kPrimShort: |
| 1767 | case Primitive::kPrimInt: |
| 1768 | case Primitive::kPrimNot: |
| 1769 | case Primitive::kPrimLong: |
| 1770 | return Location::RegisterLocation(RAX); |
| 1771 | |
| 1772 | case Primitive::kPrimVoid: |
| 1773 | return Location::NoLocation(); |
| 1774 | |
| 1775 | case Primitive::kPrimDouble: |
| 1776 | case Primitive::kPrimFloat: |
| 1777 | return Location::FpuRegisterLocation(XMM0); |
| 1778 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1779 | |
| 1780 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 1784 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1785 | } |
| 1786 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1787 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1788 | switch (type) { |
| 1789 | case Primitive::kPrimBoolean: |
| 1790 | case Primitive::kPrimByte: |
| 1791 | case Primitive::kPrimChar: |
| 1792 | case Primitive::kPrimShort: |
| 1793 | case Primitive::kPrimInt: |
| 1794 | case Primitive::kPrimNot: { |
| 1795 | uint32_t index = gp_index_++; |
| 1796 | stack_index_++; |
| 1797 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1798 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1799 | } else { |
| 1800 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1801 | } |
| 1802 | } |
| 1803 | |
| 1804 | case Primitive::kPrimLong: { |
| 1805 | uint32_t index = gp_index_; |
| 1806 | stack_index_ += 2; |
| 1807 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 1808 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1809 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1810 | } else { |
| 1811 | gp_index_ += 2; |
| 1812 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1813 | } |
| 1814 | } |
| 1815 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1816 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1817 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1818 | stack_index_++; |
| 1819 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1820 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1821 | } else { |
| 1822 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1823 | } |
| 1824 | } |
| 1825 | |
| 1826 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1827 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1828 | stack_index_ += 2; |
| 1829 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1830 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1831 | } else { |
| 1832 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1833 | } |
| 1834 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1835 | |
| 1836 | case Primitive::kPrimVoid: |
| 1837 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1838 | break; |
| 1839 | } |
| 1840 | return Location(); |
| 1841 | } |
| 1842 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1843 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1844 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1845 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1846 | // the method_idx. |
| 1847 | HandleInvoke(invoke); |
| 1848 | } |
| 1849 | |
| 1850 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1851 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1852 | } |
| 1853 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1854 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1855 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1856 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1857 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1858 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1859 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1860 | if (intrinsic.TryDispatch(invoke)) { |
| 1861 | return; |
| 1862 | } |
| 1863 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1864 | HandleInvoke(invoke); |
| 1865 | } |
| 1866 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1867 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 1868 | if (invoke->GetLocations()->Intrinsified()) { |
| 1869 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 1870 | intrinsic.Dispatch(invoke); |
| 1871 | return true; |
| 1872 | } |
| 1873 | return false; |
| 1874 | } |
| 1875 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1876 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1877 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1878 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1879 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1880 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1881 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1882 | return; |
| 1883 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1884 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1885 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1886 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1887 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 1888 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1889 | } |
| 1890 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1891 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1892 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1893 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1894 | } |
| 1895 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1896 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1897 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1898 | if (intrinsic.TryDispatch(invoke)) { |
| 1899 | return; |
| 1900 | } |
| 1901 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1902 | HandleInvoke(invoke); |
| 1903 | } |
| 1904 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1905 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1906 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1907 | return; |
| 1908 | } |
| 1909 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1910 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1911 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1912 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1913 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1914 | } |
| 1915 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1916 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1917 | HandleInvoke(invoke); |
| 1918 | // Add the hidden argument. |
| 1919 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 1920 | } |
| 1921 | |
| 1922 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1923 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1924 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1925 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1926 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1927 | LocationSummary* locations = invoke->GetLocations(); |
| 1928 | Location receiver = locations->InAt(0); |
| 1929 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 1930 | |
| 1931 | // Set the hidden argument. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 1932 | CpuRegister hidden_reg = invoke->GetLocations()->GetTemp(1).AsRegister<CpuRegister>(); |
| 1933 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1934 | |
| 1935 | // temp = object->GetClass(); |
| 1936 | if (receiver.IsStackSlot()) { |
| 1937 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
| 1938 | __ movl(temp, Address(temp, class_offset)); |
| 1939 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1940 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1941 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1942 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1943 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1944 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1945 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1946 | // call temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1947 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1948 | kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1949 | |
| 1950 | DCHECK(!codegen_->IsLeafMethod()); |
| 1951 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1952 | } |
| 1953 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1954 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 1955 | LocationSummary* locations = |
| 1956 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1957 | switch (neg->GetResultType()) { |
| 1958 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1959 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1960 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1961 | locations->SetOut(Location::SameAsFirstInput()); |
| 1962 | break; |
| 1963 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1964 | case Primitive::kPrimFloat: |
| 1965 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1966 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1967 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1968 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1969 | break; |
| 1970 | |
| 1971 | default: |
| 1972 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1973 | } |
| 1974 | } |
| 1975 | |
| 1976 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 1977 | LocationSummary* locations = neg->GetLocations(); |
| 1978 | Location out = locations->Out(); |
| 1979 | Location in = locations->InAt(0); |
| 1980 | switch (neg->GetResultType()) { |
| 1981 | case Primitive::kPrimInt: |
| 1982 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1983 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1984 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1985 | break; |
| 1986 | |
| 1987 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1988 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1989 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1990 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1991 | break; |
| 1992 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1993 | case Primitive::kPrimFloat: { |
| 1994 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1995 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1996 | // Implement float negation with an exclusive or with value |
| 1997 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 1998 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1999 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2000 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2001 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2002 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2003 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2004 | case Primitive::kPrimDouble: { |
| 2005 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2006 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2007 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2008 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2009 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2010 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2011 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2012 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2013 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2014 | |
| 2015 | default: |
| 2016 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2017 | } |
| 2018 | } |
| 2019 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2020 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2021 | LocationSummary* locations = |
| 2022 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 2023 | Primitive::Type result_type = conversion->GetResultType(); |
| 2024 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2025 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2026 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2027 | // The Java language does not allow treating boolean as an integral type but |
| 2028 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2029 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2030 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2031 | case Primitive::kPrimByte: |
| 2032 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2033 | case Primitive::kPrimBoolean: |
| 2034 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2035 | case Primitive::kPrimShort: |
| 2036 | case Primitive::kPrimInt: |
| 2037 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2038 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2039 | locations->SetInAt(0, Location::Any()); |
| 2040 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2041 | break; |
| 2042 | |
| 2043 | default: |
| 2044 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2045 | << " to " << result_type; |
| 2046 | } |
| 2047 | break; |
| 2048 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2049 | case Primitive::kPrimShort: |
| 2050 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2051 | case Primitive::kPrimBoolean: |
| 2052 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2053 | case Primitive::kPrimByte: |
| 2054 | case Primitive::kPrimInt: |
| 2055 | case Primitive::kPrimChar: |
| 2056 | // Processing a Dex `int-to-short' instruction. |
| 2057 | locations->SetInAt(0, Location::Any()); |
| 2058 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2059 | break; |
| 2060 | |
| 2061 | default: |
| 2062 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2063 | << " to " << result_type; |
| 2064 | } |
| 2065 | break; |
| 2066 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2067 | case Primitive::kPrimInt: |
| 2068 | switch (input_type) { |
| 2069 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2070 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2071 | locations->SetInAt(0, Location::Any()); |
| 2072 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2073 | break; |
| 2074 | |
| 2075 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2076 | // Processing a Dex `float-to-int' instruction. |
| 2077 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2078 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2079 | break; |
| 2080 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2081 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2082 | // Processing a Dex `double-to-int' instruction. |
| 2083 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2084 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2085 | break; |
| 2086 | |
| 2087 | default: |
| 2088 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2089 | << " to " << result_type; |
| 2090 | } |
| 2091 | break; |
| 2092 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2093 | case Primitive::kPrimLong: |
| 2094 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2095 | case Primitive::kPrimBoolean: |
| 2096 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2097 | case Primitive::kPrimByte: |
| 2098 | case Primitive::kPrimShort: |
| 2099 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2100 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2101 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2102 | // TODO: We would benefit from a (to-be-implemented) |
| 2103 | // Location::RegisterOrStackSlot requirement for this input. |
| 2104 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2105 | locations->SetOut(Location::RequiresRegister()); |
| 2106 | break; |
| 2107 | |
| 2108 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2109 | // Processing a Dex `float-to-long' instruction. |
| 2110 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2111 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2112 | break; |
| 2113 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2114 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2115 | // Processing a Dex `double-to-long' instruction. |
| 2116 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2117 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2118 | break; |
| 2119 | |
| 2120 | default: |
| 2121 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2122 | << " to " << result_type; |
| 2123 | } |
| 2124 | break; |
| 2125 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2126 | case Primitive::kPrimChar: |
| 2127 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2128 | case Primitive::kPrimBoolean: |
| 2129 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2130 | case Primitive::kPrimByte: |
| 2131 | case Primitive::kPrimShort: |
| 2132 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2133 | // Processing a Dex `int-to-char' instruction. |
| 2134 | locations->SetInAt(0, Location::Any()); |
| 2135 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2136 | break; |
| 2137 | |
| 2138 | default: |
| 2139 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2140 | << " to " << result_type; |
| 2141 | } |
| 2142 | break; |
| 2143 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2144 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2145 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2146 | case Primitive::kPrimBoolean: |
| 2147 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2148 | case Primitive::kPrimByte: |
| 2149 | case Primitive::kPrimShort: |
| 2150 | case Primitive::kPrimInt: |
| 2151 | case Primitive::kPrimChar: |
| 2152 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2153 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2154 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2155 | break; |
| 2156 | |
| 2157 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2158 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2159 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2160 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2161 | break; |
| 2162 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2163 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2164 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2165 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2166 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2167 | break; |
| 2168 | |
| 2169 | default: |
| 2170 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2171 | << " to " << result_type; |
| 2172 | }; |
| 2173 | break; |
| 2174 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2175 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2176 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2177 | case Primitive::kPrimBoolean: |
| 2178 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2179 | case Primitive::kPrimByte: |
| 2180 | case Primitive::kPrimShort: |
| 2181 | case Primitive::kPrimInt: |
| 2182 | case Primitive::kPrimChar: |
| 2183 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2184 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2185 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2186 | break; |
| 2187 | |
| 2188 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2189 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2190 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2191 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2192 | break; |
| 2193 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2194 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2195 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2196 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2197 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2198 | break; |
| 2199 | |
| 2200 | default: |
| 2201 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2202 | << " to " << result_type; |
| 2203 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2204 | break; |
| 2205 | |
| 2206 | default: |
| 2207 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2208 | << " to " << result_type; |
| 2209 | } |
| 2210 | } |
| 2211 | |
| 2212 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2213 | LocationSummary* locations = conversion->GetLocations(); |
| 2214 | Location out = locations->Out(); |
| 2215 | Location in = locations->InAt(0); |
| 2216 | Primitive::Type result_type = conversion->GetResultType(); |
| 2217 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2218 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2219 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2220 | case Primitive::kPrimByte: |
| 2221 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2222 | case Primitive::kPrimBoolean: |
| 2223 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2224 | case Primitive::kPrimShort: |
| 2225 | case Primitive::kPrimInt: |
| 2226 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2227 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2228 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2229 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2230 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2231 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2232 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2233 | } else { |
| 2234 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2235 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2236 | Immediate(static_cast<int8_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2237 | } |
| 2238 | break; |
| 2239 | |
| 2240 | default: |
| 2241 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2242 | << " to " << result_type; |
| 2243 | } |
| 2244 | break; |
| 2245 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2246 | case Primitive::kPrimShort: |
| 2247 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2248 | case Primitive::kPrimBoolean: |
| 2249 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2250 | case Primitive::kPrimByte: |
| 2251 | case Primitive::kPrimInt: |
| 2252 | case Primitive::kPrimChar: |
| 2253 | // Processing a Dex `int-to-short' instruction. |
| 2254 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2255 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2256 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2257 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2258 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2259 | } else { |
| 2260 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2261 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2262 | Immediate(static_cast<int16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2263 | } |
| 2264 | break; |
| 2265 | |
| 2266 | default: |
| 2267 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2268 | << " to " << result_type; |
| 2269 | } |
| 2270 | break; |
| 2271 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2272 | case Primitive::kPrimInt: |
| 2273 | switch (input_type) { |
| 2274 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2275 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2276 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2277 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2278 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2279 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2280 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2281 | } else { |
| 2282 | DCHECK(in.IsConstant()); |
| 2283 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2284 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2285 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2286 | } |
| 2287 | break; |
| 2288 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2289 | case Primitive::kPrimFloat: { |
| 2290 | // Processing a Dex `float-to-int' instruction. |
| 2291 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2292 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2293 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2294 | |
| 2295 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2296 | // if input >= (float)INT_MAX goto done |
| 2297 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2298 | __ j(kAboveEqual, &done); |
| 2299 | // if input == NaN goto nan |
| 2300 | __ j(kUnordered, &nan); |
| 2301 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2302 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2303 | __ jmp(&done); |
| 2304 | __ Bind(&nan); |
| 2305 | // output = 0 |
| 2306 | __ xorl(output, output); |
| 2307 | __ Bind(&done); |
| 2308 | break; |
| 2309 | } |
| 2310 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2311 | case Primitive::kPrimDouble: { |
| 2312 | // Processing a Dex `double-to-int' instruction. |
| 2313 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2314 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2315 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2316 | |
| 2317 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2318 | // if input >= (double)INT_MAX goto done |
| 2319 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2320 | __ j(kAboveEqual, &done); |
| 2321 | // if input == NaN goto nan |
| 2322 | __ j(kUnordered, &nan); |
| 2323 | // output = double-to-int-truncate(input) |
| 2324 | __ cvttsd2si(output, input); |
| 2325 | __ jmp(&done); |
| 2326 | __ Bind(&nan); |
| 2327 | // output = 0 |
| 2328 | __ xorl(output, output); |
| 2329 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2330 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2331 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2332 | |
| 2333 | default: |
| 2334 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2335 | << " to " << result_type; |
| 2336 | } |
| 2337 | break; |
| 2338 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2339 | case Primitive::kPrimLong: |
| 2340 | switch (input_type) { |
| 2341 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2342 | case Primitive::kPrimBoolean: |
| 2343 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2344 | case Primitive::kPrimByte: |
| 2345 | case Primitive::kPrimShort: |
| 2346 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2347 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2348 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2349 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2350 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2351 | break; |
| 2352 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2353 | case Primitive::kPrimFloat: { |
| 2354 | // Processing a Dex `float-to-long' instruction. |
| 2355 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2356 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2357 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2358 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2359 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2360 | // if input >= (float)LONG_MAX goto done |
| 2361 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2362 | __ j(kAboveEqual, &done); |
| 2363 | // if input == NaN goto nan |
| 2364 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2365 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2366 | __ cvttss2si(output, input, true); |
| 2367 | __ jmp(&done); |
| 2368 | __ Bind(&nan); |
| 2369 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2370 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2371 | __ Bind(&done); |
| 2372 | break; |
| 2373 | } |
| 2374 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2375 | case Primitive::kPrimDouble: { |
| 2376 | // Processing a Dex `double-to-long' instruction. |
| 2377 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2378 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2379 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2380 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2381 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2382 | // if input >= (double)LONG_MAX goto done |
| 2383 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2384 | __ j(kAboveEqual, &done); |
| 2385 | // if input == NaN goto nan |
| 2386 | __ j(kUnordered, &nan); |
| 2387 | // output = double-to-long-truncate(input) |
| 2388 | __ cvttsd2si(output, input, true); |
| 2389 | __ jmp(&done); |
| 2390 | __ Bind(&nan); |
| 2391 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2392 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2393 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2394 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2395 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2396 | |
| 2397 | default: |
| 2398 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2399 | << " to " << result_type; |
| 2400 | } |
| 2401 | break; |
| 2402 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2403 | case Primitive::kPrimChar: |
| 2404 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2405 | case Primitive::kPrimBoolean: |
| 2406 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2407 | case Primitive::kPrimByte: |
| 2408 | case Primitive::kPrimShort: |
| 2409 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2410 | // Processing a Dex `int-to-char' instruction. |
| 2411 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2412 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2413 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2414 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2415 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2416 | } else { |
| 2417 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2418 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2419 | Immediate(static_cast<uint16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2420 | } |
| 2421 | break; |
| 2422 | |
| 2423 | default: |
| 2424 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2425 | << " to " << result_type; |
| 2426 | } |
| 2427 | break; |
| 2428 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2429 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2430 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2431 | case Primitive::kPrimBoolean: |
| 2432 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2433 | case Primitive::kPrimByte: |
| 2434 | case Primitive::kPrimShort: |
| 2435 | case Primitive::kPrimInt: |
| 2436 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2437 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2438 | if (in.IsRegister()) { |
| 2439 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2440 | } else if (in.IsConstant()) { |
| 2441 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2442 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2443 | if (v == 0) { |
| 2444 | __ xorps(dest, dest); |
| 2445 | } else { |
| 2446 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2447 | } |
| 2448 | } else { |
| 2449 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2450 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2451 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2452 | break; |
| 2453 | |
| 2454 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2455 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2456 | if (in.IsRegister()) { |
| 2457 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2458 | } else if (in.IsConstant()) { |
| 2459 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2460 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2461 | if (v == 0) { |
| 2462 | __ xorps(dest, dest); |
| 2463 | } else { |
| 2464 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2465 | } |
| 2466 | } else { |
| 2467 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2468 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2469 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2470 | break; |
| 2471 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2472 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2473 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2474 | if (in.IsFpuRegister()) { |
| 2475 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2476 | } else if (in.IsConstant()) { |
| 2477 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2478 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2479 | if (bit_cast<int64_t, double>(v) == 0) { |
| 2480 | __ xorps(dest, dest); |
| 2481 | } else { |
| 2482 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2483 | } |
| 2484 | } else { |
| 2485 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2486 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2487 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2488 | break; |
| 2489 | |
| 2490 | default: |
| 2491 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2492 | << " to " << result_type; |
| 2493 | }; |
| 2494 | break; |
| 2495 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2496 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2497 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2498 | case Primitive::kPrimBoolean: |
| 2499 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2500 | case Primitive::kPrimByte: |
| 2501 | case Primitive::kPrimShort: |
| 2502 | case Primitive::kPrimInt: |
| 2503 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2504 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2505 | if (in.IsRegister()) { |
| 2506 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2507 | } else if (in.IsConstant()) { |
| 2508 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2509 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2510 | if (v == 0) { |
| 2511 | __ xorpd(dest, dest); |
| 2512 | } else { |
| 2513 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2514 | } |
| 2515 | } else { |
| 2516 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2517 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2518 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2519 | break; |
| 2520 | |
| 2521 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2522 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2523 | if (in.IsRegister()) { |
| 2524 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2525 | } else if (in.IsConstant()) { |
| 2526 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2527 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2528 | if (v == 0) { |
| 2529 | __ xorpd(dest, dest); |
| 2530 | } else { |
| 2531 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2532 | } |
| 2533 | } else { |
| 2534 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2535 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2536 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2537 | break; |
| 2538 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2539 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2540 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2541 | if (in.IsFpuRegister()) { |
| 2542 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2543 | } else if (in.IsConstant()) { |
| 2544 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 2545 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2546 | if (bit_cast<int32_t, float>(v) == 0) { |
| 2547 | __ xorpd(dest, dest); |
| 2548 | } else { |
| 2549 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2550 | } |
| 2551 | } else { |
| 2552 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 2553 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2554 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2555 | break; |
| 2556 | |
| 2557 | default: |
| 2558 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2559 | << " to " << result_type; |
| 2560 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2561 | break; |
| 2562 | |
| 2563 | default: |
| 2564 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2565 | << " to " << result_type; |
| 2566 | } |
| 2567 | } |
| 2568 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2569 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2570 | LocationSummary* locations = |
| 2571 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2572 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2573 | case Primitive::kPrimInt: { |
| 2574 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2575 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2576 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2577 | break; |
| 2578 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2579 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2580 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2581 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2582 | // We can use a leaq or addq if the constant can fit in an immediate. |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2583 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2584 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2585 | break; |
| 2586 | } |
| 2587 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2588 | case Primitive::kPrimDouble: |
| 2589 | case Primitive::kPrimFloat: { |
| 2590 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2591 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2592 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2593 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2594 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2595 | |
| 2596 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2597 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2598 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2599 | } |
| 2600 | |
| 2601 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 2602 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2603 | Location first = locations->InAt(0); |
| 2604 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2605 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2606 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2607 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2608 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2609 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2610 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2611 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2612 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2613 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2614 | } else { |
| 2615 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2616 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2617 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2618 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2619 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2620 | __ addl(out.AsRegister<CpuRegister>(), |
| 2621 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 2622 | } else { |
| 2623 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2624 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 2625 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2626 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2627 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2628 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2629 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2630 | break; |
| 2631 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2632 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2633 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2634 | if (second.IsRegister()) { |
| 2635 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2636 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2637 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2638 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2639 | } else { |
| 2640 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2641 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2642 | } |
| 2643 | } else { |
| 2644 | DCHECK(second.IsConstant()); |
| 2645 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2646 | int32_t int32_value = Low32Bits(value); |
| 2647 | DCHECK_EQ(int32_value, value); |
| 2648 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2649 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 2650 | } else { |
| 2651 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2652 | first.AsRegister<CpuRegister>(), int32_value)); |
| 2653 | } |
| 2654 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2655 | break; |
| 2656 | } |
| 2657 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2658 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2659 | if (second.IsFpuRegister()) { |
| 2660 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2661 | } else if (second.IsConstant()) { |
| 2662 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2663 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2664 | } else { |
| 2665 | DCHECK(second.IsStackSlot()); |
| 2666 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2667 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2668 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2669 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2670 | } |
| 2671 | |
| 2672 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2673 | if (second.IsFpuRegister()) { |
| 2674 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2675 | } else if (second.IsConstant()) { |
| 2676 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2677 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2678 | } else { |
| 2679 | DCHECK(second.IsDoubleStackSlot()); |
| 2680 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2681 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2682 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2683 | break; |
| 2684 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2685 | |
| 2686 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2687 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2688 | } |
| 2689 | } |
| 2690 | |
| 2691 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2692 | LocationSummary* locations = |
| 2693 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2694 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2695 | case Primitive::kPrimInt: { |
| 2696 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2697 | locations->SetInAt(1, Location::Any()); |
| 2698 | locations->SetOut(Location::SameAsFirstInput()); |
| 2699 | break; |
| 2700 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2701 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2702 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2703 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2704 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2705 | break; |
| 2706 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2707 | case Primitive::kPrimFloat: |
| 2708 | case Primitive::kPrimDouble: { |
| 2709 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2710 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2711 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2712 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2713 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2714 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2715 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2716 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2717 | } |
| 2718 | |
| 2719 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 2720 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2721 | Location first = locations->InAt(0); |
| 2722 | Location second = locations->InAt(1); |
| 2723 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2724 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2725 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2726 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2727 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2728 | } else if (second.IsConstant()) { |
| 2729 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2730 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2731 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2732 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2733 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2734 | break; |
| 2735 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2736 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2737 | if (second.IsConstant()) { |
| 2738 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2739 | DCHECK(IsInt<32>(value)); |
| 2740 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 2741 | } else { |
| 2742 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 2743 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2744 | break; |
| 2745 | } |
| 2746 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2747 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2748 | if (second.IsFpuRegister()) { |
| 2749 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2750 | } else if (second.IsConstant()) { |
| 2751 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2752 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2753 | } else { |
| 2754 | DCHECK(second.IsStackSlot()); |
| 2755 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2756 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2757 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2758 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2762 | if (second.IsFpuRegister()) { |
| 2763 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2764 | } else if (second.IsConstant()) { |
| 2765 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2766 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2767 | } else { |
| 2768 | DCHECK(second.IsDoubleStackSlot()); |
| 2769 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2770 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2771 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2772 | break; |
| 2773 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2774 | |
| 2775 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2776 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2777 | } |
| 2778 | } |
| 2779 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2780 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 2781 | LocationSummary* locations = |
| 2782 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2783 | switch (mul->GetResultType()) { |
| 2784 | case Primitive::kPrimInt: { |
| 2785 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2786 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2787 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2788 | // Can use 3 operand multiply. |
| 2789 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2790 | } else { |
| 2791 | locations->SetOut(Location::SameAsFirstInput()); |
| 2792 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2793 | break; |
| 2794 | } |
| 2795 | case Primitive::kPrimLong: { |
| 2796 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2797 | locations->SetInAt(1, Location::Any()); |
| 2798 | if (mul->InputAt(1)->IsLongConstant() && |
| 2799 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2800 | // Can use 3 operand multiply. |
| 2801 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2802 | } else { |
| 2803 | locations->SetOut(Location::SameAsFirstInput()); |
| 2804 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2805 | break; |
| 2806 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2807 | case Primitive::kPrimFloat: |
| 2808 | case Primitive::kPrimDouble: { |
| 2809 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2810 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2811 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2812 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2813 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2814 | |
| 2815 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2816 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2817 | } |
| 2818 | } |
| 2819 | |
| 2820 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 2821 | LocationSummary* locations = mul->GetLocations(); |
| 2822 | Location first = locations->InAt(0); |
| 2823 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2824 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2825 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2826 | case Primitive::kPrimInt: |
| 2827 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2828 | // problems where the output may not be the same as the first operand. |
| 2829 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2830 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2831 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 2832 | } else if (second.IsRegister()) { |
| 2833 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2834 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2835 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2836 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2837 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2838 | __ imull(first.AsRegister<CpuRegister>(), |
| 2839 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2840 | } |
| 2841 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2842 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2843 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2844 | // problems where the output may not be the same as the first operand. |
| 2845 | if (mul->InputAt(1)->IsLongConstant()) { |
| 2846 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 2847 | if (IsInt<32>(value)) { |
| 2848 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 2849 | Immediate(static_cast<int32_t>(value))); |
| 2850 | } else { |
| 2851 | // Have to use the constant area. |
| 2852 | DCHECK(first.Equals(out)); |
| 2853 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 2854 | } |
| 2855 | } else if (second.IsRegister()) { |
| 2856 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2857 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2858 | } else { |
| 2859 | DCHECK(second.IsDoubleStackSlot()); |
| 2860 | DCHECK(first.Equals(out)); |
| 2861 | __ imulq(first.AsRegister<CpuRegister>(), |
| 2862 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2863 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2864 | break; |
| 2865 | } |
| 2866 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2867 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2868 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2869 | if (second.IsFpuRegister()) { |
| 2870 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2871 | } else if (second.IsConstant()) { |
| 2872 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2873 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2874 | } else { |
| 2875 | DCHECK(second.IsStackSlot()); |
| 2876 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2877 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2878 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2879 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2880 | } |
| 2881 | |
| 2882 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2883 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2884 | if (second.IsFpuRegister()) { |
| 2885 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2886 | } else if (second.IsConstant()) { |
| 2887 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2888 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2889 | } else { |
| 2890 | DCHECK(second.IsDoubleStackSlot()); |
| 2891 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2892 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2893 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2894 | break; |
| 2895 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2896 | |
| 2897 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2898 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2899 | } |
| 2900 | } |
| 2901 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2902 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 2903 | uint32_t stack_adjustment, bool is_float) { |
| 2904 | if (source.IsStackSlot()) { |
| 2905 | DCHECK(is_float); |
| 2906 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 2907 | } else if (source.IsDoubleStackSlot()) { |
| 2908 | DCHECK(!is_float); |
| 2909 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 2910 | } else { |
| 2911 | // Write the value to the temporary location on the stack and load to FP stack. |
| 2912 | if (is_float) { |
| 2913 | Location stack_temp = Location::StackSlot(temp_offset); |
| 2914 | codegen_->Move(stack_temp, source); |
| 2915 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 2916 | } else { |
| 2917 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 2918 | codegen_->Move(stack_temp, source); |
| 2919 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 2920 | } |
| 2921 | } |
| 2922 | } |
| 2923 | |
| 2924 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 2925 | Primitive::Type type = rem->GetResultType(); |
| 2926 | bool is_float = type == Primitive::kPrimFloat; |
| 2927 | size_t elem_size = Primitive::ComponentSize(type); |
| 2928 | LocationSummary* locations = rem->GetLocations(); |
| 2929 | Location first = locations->InAt(0); |
| 2930 | Location second = locations->InAt(1); |
| 2931 | Location out = locations->Out(); |
| 2932 | |
| 2933 | // Create stack space for 2 elements. |
| 2934 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2935 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 2936 | |
| 2937 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 2938 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 2939 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 2940 | |
| 2941 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2942 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2943 | __ Bind(&retry); |
| 2944 | __ fprem(); |
| 2945 | |
| 2946 | // Move FP status to AX. |
| 2947 | __ fstsw(); |
| 2948 | |
| 2949 | // And see if the argument reduction is complete. This is signaled by the |
| 2950 | // C2 FPU flag bit set to 0. |
| 2951 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 2952 | __ j(kNotEqual, &retry); |
| 2953 | |
| 2954 | // We have settled on the final value. Retrieve it into an XMM register. |
| 2955 | // Store FP top of stack to real stack. |
| 2956 | if (is_float) { |
| 2957 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 2958 | } else { |
| 2959 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 2960 | } |
| 2961 | |
| 2962 | // Pop the 2 items from the FP stack. |
| 2963 | __ fucompp(); |
| 2964 | |
| 2965 | // Load the value from the stack into an XMM register. |
| 2966 | DCHECK(out.IsFpuRegister()) << out; |
| 2967 | if (is_float) { |
| 2968 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 2969 | } else { |
| 2970 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 2971 | } |
| 2972 | |
| 2973 | // And remove the temporary stack space we allocated. |
| 2974 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 2975 | } |
| 2976 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2977 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2978 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2979 | |
| 2980 | LocationSummary* locations = instruction->GetLocations(); |
| 2981 | Location second = locations->InAt(1); |
| 2982 | DCHECK(second.IsConstant()); |
| 2983 | |
| 2984 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 2985 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2986 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2987 | |
| 2988 | DCHECK(imm == 1 || imm == -1); |
| 2989 | |
| 2990 | switch (instruction->GetResultType()) { |
| 2991 | case Primitive::kPrimInt: { |
| 2992 | if (instruction->IsRem()) { |
| 2993 | __ xorl(output_register, output_register); |
| 2994 | } else { |
| 2995 | __ movl(output_register, input_register); |
| 2996 | if (imm == -1) { |
| 2997 | __ negl(output_register); |
| 2998 | } |
| 2999 | } |
| 3000 | break; |
| 3001 | } |
| 3002 | |
| 3003 | case Primitive::kPrimLong: { |
| 3004 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3005 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3006 | } else { |
| 3007 | __ movq(output_register, input_register); |
| 3008 | if (imm == -1) { |
| 3009 | __ negq(output_register); |
| 3010 | } |
| 3011 | } |
| 3012 | break; |
| 3013 | } |
| 3014 | |
| 3015 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3016 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3017 | } |
| 3018 | } |
| 3019 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3020 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3021 | LocationSummary* locations = instruction->GetLocations(); |
| 3022 | Location second = locations->InAt(1); |
| 3023 | |
| 3024 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3025 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3026 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3027 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3028 | |
| 3029 | DCHECK(IsPowerOfTwo(std::abs(imm))); |
| 3030 | |
| 3031 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3032 | |
| 3033 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3034 | __ leal(tmp, Address(numerator, std::abs(imm) - 1)); |
| 3035 | __ testl(numerator, numerator); |
| 3036 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3037 | int shift = CTZ(imm); |
| 3038 | __ sarl(tmp, Immediate(shift)); |
| 3039 | |
| 3040 | if (imm < 0) { |
| 3041 | __ negl(tmp); |
| 3042 | } |
| 3043 | |
| 3044 | __ movl(output_register, tmp); |
| 3045 | } else { |
| 3046 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3047 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3048 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3049 | codegen_->Load64BitValue(rdx, std::abs(imm) - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3050 | __ addq(rdx, numerator); |
| 3051 | __ testq(numerator, numerator); |
| 3052 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3053 | int shift = CTZ(imm); |
| 3054 | __ sarq(rdx, Immediate(shift)); |
| 3055 | |
| 3056 | if (imm < 0) { |
| 3057 | __ negq(rdx); |
| 3058 | } |
| 3059 | |
| 3060 | __ movq(output_register, rdx); |
| 3061 | } |
| 3062 | } |
| 3063 | |
| 3064 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3065 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3066 | |
| 3067 | LocationSummary* locations = instruction->GetLocations(); |
| 3068 | Location second = locations->InAt(1); |
| 3069 | |
| 3070 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3071 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3072 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3073 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3074 | : locations->Out().AsRegister<CpuRegister>(); |
| 3075 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3076 | |
| 3077 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3078 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3079 | if (instruction->IsDiv()) { |
| 3080 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3081 | } else { |
| 3082 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3083 | } |
| 3084 | |
| 3085 | int64_t magic; |
| 3086 | int shift; |
| 3087 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3088 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3089 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3090 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3091 | |
| 3092 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3093 | |
| 3094 | __ movl(numerator, eax); |
| 3095 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3096 | NearLabel no_div; |
| 3097 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3098 | __ testl(eax, eax); |
| 3099 | __ j(kNotEqual, &no_div); |
| 3100 | |
| 3101 | __ xorl(out, out); |
| 3102 | __ jmp(&end); |
| 3103 | |
| 3104 | __ Bind(&no_div); |
| 3105 | |
| 3106 | __ movl(eax, Immediate(magic)); |
| 3107 | __ imull(numerator); |
| 3108 | |
| 3109 | if (imm > 0 && magic < 0) { |
| 3110 | __ addl(edx, numerator); |
| 3111 | } else if (imm < 0 && magic > 0) { |
| 3112 | __ subl(edx, numerator); |
| 3113 | } |
| 3114 | |
| 3115 | if (shift != 0) { |
| 3116 | __ sarl(edx, Immediate(shift)); |
| 3117 | } |
| 3118 | |
| 3119 | __ movl(eax, edx); |
| 3120 | __ shrl(edx, Immediate(31)); |
| 3121 | __ addl(edx, eax); |
| 3122 | |
| 3123 | if (instruction->IsRem()) { |
| 3124 | __ movl(eax, numerator); |
| 3125 | __ imull(edx, Immediate(imm)); |
| 3126 | __ subl(eax, edx); |
| 3127 | __ movl(edx, eax); |
| 3128 | } else { |
| 3129 | __ movl(eax, edx); |
| 3130 | } |
| 3131 | __ Bind(&end); |
| 3132 | } else { |
| 3133 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3134 | |
| 3135 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3136 | |
| 3137 | CpuRegister rax = eax; |
| 3138 | CpuRegister rdx = edx; |
| 3139 | |
| 3140 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3141 | |
| 3142 | // Save the numerator. |
| 3143 | __ movq(numerator, rax); |
| 3144 | |
| 3145 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3146 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3147 | |
| 3148 | // RDX:RAX = magic * numerator |
| 3149 | __ imulq(numerator); |
| 3150 | |
| 3151 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3152 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3153 | __ addq(rdx, numerator); |
| 3154 | } else if (imm < 0 && magic > 0) { |
| 3155 | // RDX -= numerator |
| 3156 | __ subq(rdx, numerator); |
| 3157 | } |
| 3158 | |
| 3159 | // Shift if needed. |
| 3160 | if (shift != 0) { |
| 3161 | __ sarq(rdx, Immediate(shift)); |
| 3162 | } |
| 3163 | |
| 3164 | // RDX += 1 if RDX < 0 |
| 3165 | __ movq(rax, rdx); |
| 3166 | __ shrq(rdx, Immediate(63)); |
| 3167 | __ addq(rdx, rax); |
| 3168 | |
| 3169 | if (instruction->IsRem()) { |
| 3170 | __ movq(rax, numerator); |
| 3171 | |
| 3172 | if (IsInt<32>(imm)) { |
| 3173 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3174 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3175 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3176 | } |
| 3177 | |
| 3178 | __ subq(rax, rdx); |
| 3179 | __ movq(rdx, rax); |
| 3180 | } else { |
| 3181 | __ movq(rax, rdx); |
| 3182 | } |
| 3183 | } |
| 3184 | } |
| 3185 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3186 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3187 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3188 | Primitive::Type type = instruction->GetResultType(); |
| 3189 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3190 | |
| 3191 | bool is_div = instruction->IsDiv(); |
| 3192 | LocationSummary* locations = instruction->GetLocations(); |
| 3193 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3194 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3195 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3196 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3197 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3198 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3199 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3200 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3201 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3202 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3203 | if (imm == 0) { |
| 3204 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3205 | } else if (imm == 1 || imm == -1) { |
| 3206 | DivRemOneOrMinusOne(instruction); |
| 3207 | } else if (instruction->IsDiv() && IsPowerOfTwo(std::abs(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3208 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3209 | } else { |
| 3210 | DCHECK(imm <= -2 || imm >= 2); |
| 3211 | GenerateDivRemWithAnyConstant(instruction); |
| 3212 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3213 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3214 | SlowPathCode* slow_path = |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3215 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
| 3216 | out.AsRegister(), type, is_div); |
| 3217 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3218 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3219 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3220 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3221 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3222 | // so it's safe to just use negl instead of more complex comparisons. |
| 3223 | if (type == Primitive::kPrimInt) { |
| 3224 | __ cmpl(second_reg, Immediate(-1)); |
| 3225 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3226 | // edx:eax <- sign-extended of eax |
| 3227 | __ cdq(); |
| 3228 | // eax = quotient, edx = remainder |
| 3229 | __ idivl(second_reg); |
| 3230 | } else { |
| 3231 | __ cmpq(second_reg, Immediate(-1)); |
| 3232 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3233 | // rdx:rax <- sign-extended of rax |
| 3234 | __ cqo(); |
| 3235 | // rax = quotient, rdx = remainder |
| 3236 | __ idivq(second_reg); |
| 3237 | } |
| 3238 | __ Bind(slow_path->GetExitLabel()); |
| 3239 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3240 | } |
| 3241 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3242 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3243 | LocationSummary* locations = |
| 3244 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3245 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3246 | case Primitive::kPrimInt: |
| 3247 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3248 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3249 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3250 | locations->SetOut(Location::SameAsFirstInput()); |
| 3251 | // Intel uses edx:eax as the dividend. |
| 3252 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3253 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3254 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3255 | // output and request another temp. |
| 3256 | if (div->InputAt(1)->IsConstant()) { |
| 3257 | locations->AddTemp(Location::RequiresRegister()); |
| 3258 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3259 | break; |
| 3260 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3261 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3262 | case Primitive::kPrimFloat: |
| 3263 | case Primitive::kPrimDouble: { |
| 3264 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3265 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3266 | locations->SetOut(Location::SameAsFirstInput()); |
| 3267 | break; |
| 3268 | } |
| 3269 | |
| 3270 | default: |
| 3271 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3272 | } |
| 3273 | } |
| 3274 | |
| 3275 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3276 | LocationSummary* locations = div->GetLocations(); |
| 3277 | Location first = locations->InAt(0); |
| 3278 | Location second = locations->InAt(1); |
| 3279 | DCHECK(first.Equals(locations->Out())); |
| 3280 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3281 | Primitive::Type type = div->GetResultType(); |
| 3282 | switch (type) { |
| 3283 | case Primitive::kPrimInt: |
| 3284 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3285 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3286 | break; |
| 3287 | } |
| 3288 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3289 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3290 | if (second.IsFpuRegister()) { |
| 3291 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3292 | } else if (second.IsConstant()) { |
| 3293 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3294 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 3295 | } else { |
| 3296 | DCHECK(second.IsStackSlot()); |
| 3297 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3298 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3299 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3300 | break; |
| 3301 | } |
| 3302 | |
| 3303 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3304 | if (second.IsFpuRegister()) { |
| 3305 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3306 | } else if (second.IsConstant()) { |
| 3307 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3308 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 3309 | } else { |
| 3310 | DCHECK(second.IsDoubleStackSlot()); |
| 3311 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3312 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3313 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3314 | break; |
| 3315 | } |
| 3316 | |
| 3317 | default: |
| 3318 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3319 | } |
| 3320 | } |
| 3321 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3322 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3323 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3324 | LocationSummary* locations = |
| 3325 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3326 | |
| 3327 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3328 | case Primitive::kPrimInt: |
| 3329 | case Primitive::kPrimLong: { |
| 3330 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3331 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3332 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3333 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3334 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3335 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3336 | // output and request another temp. |
| 3337 | if (rem->InputAt(1)->IsConstant()) { |
| 3338 | locations->AddTemp(Location::RequiresRegister()); |
| 3339 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3340 | break; |
| 3341 | } |
| 3342 | |
| 3343 | case Primitive::kPrimFloat: |
| 3344 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3345 | locations->SetInAt(0, Location::Any()); |
| 3346 | locations->SetInAt(1, Location::Any()); |
| 3347 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3348 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3349 | break; |
| 3350 | } |
| 3351 | |
| 3352 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3353 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3354 | } |
| 3355 | } |
| 3356 | |
| 3357 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3358 | Primitive::Type type = rem->GetResultType(); |
| 3359 | switch (type) { |
| 3360 | case Primitive::kPrimInt: |
| 3361 | case Primitive::kPrimLong: { |
| 3362 | GenerateDivRemIntegral(rem); |
| 3363 | break; |
| 3364 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3365 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3366 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3367 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3368 | break; |
| 3369 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3370 | default: |
| 3371 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3372 | } |
| 3373 | } |
| 3374 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3375 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3376 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3377 | ? LocationSummary::kCallOnSlowPath |
| 3378 | : LocationSummary::kNoCall; |
| 3379 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3380 | locations->SetInAt(0, Location::Any()); |
| 3381 | if (instruction->HasUses()) { |
| 3382 | locations->SetOut(Location::SameAsFirstInput()); |
| 3383 | } |
| 3384 | } |
| 3385 | |
| 3386 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3387 | SlowPathCode* slow_path = |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3388 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3389 | codegen_->AddSlowPath(slow_path); |
| 3390 | |
| 3391 | LocationSummary* locations = instruction->GetLocations(); |
| 3392 | Location value = locations->InAt(0); |
| 3393 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3394 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3395 | case Primitive::kPrimByte: |
| 3396 | case Primitive::kPrimChar: |
| 3397 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3398 | case Primitive::kPrimInt: { |
| 3399 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3400 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3401 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3402 | } else if (value.IsStackSlot()) { |
| 3403 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3404 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3405 | } else { |
| 3406 | DCHECK(value.IsConstant()) << value; |
| 3407 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3408 | __ jmp(slow_path->GetEntryLabel()); |
| 3409 | } |
| 3410 | } |
| 3411 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3412 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3413 | case Primitive::kPrimLong: { |
| 3414 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3415 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3416 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3417 | } else if (value.IsDoubleStackSlot()) { |
| 3418 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3419 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3420 | } else { |
| 3421 | DCHECK(value.IsConstant()) << value; |
| 3422 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3423 | __ jmp(slow_path->GetEntryLabel()); |
| 3424 | } |
| 3425 | } |
| 3426 | break; |
| 3427 | } |
| 3428 | default: |
| 3429 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3430 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3431 | } |
| 3432 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3433 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3434 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3435 | |
| 3436 | LocationSummary* locations = |
| 3437 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3438 | |
| 3439 | switch (op->GetResultType()) { |
| 3440 | case Primitive::kPrimInt: |
| 3441 | case Primitive::kPrimLong: { |
| 3442 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3443 | // The shift count needs to be in CL. |
| 3444 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3445 | locations->SetOut(Location::SameAsFirstInput()); |
| 3446 | break; |
| 3447 | } |
| 3448 | default: |
| 3449 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3450 | } |
| 3451 | } |
| 3452 | |
| 3453 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3454 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3455 | |
| 3456 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3457 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3458 | Location second = locations->InAt(1); |
| 3459 | |
| 3460 | switch (op->GetResultType()) { |
| 3461 | case Primitive::kPrimInt: { |
| 3462 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3463 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3464 | if (op->IsShl()) { |
| 3465 | __ shll(first_reg, second_reg); |
| 3466 | } else if (op->IsShr()) { |
| 3467 | __ sarl(first_reg, second_reg); |
| 3468 | } else { |
| 3469 | __ shrl(first_reg, second_reg); |
| 3470 | } |
| 3471 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3472 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3473 | if (op->IsShl()) { |
| 3474 | __ shll(first_reg, imm); |
| 3475 | } else if (op->IsShr()) { |
| 3476 | __ sarl(first_reg, imm); |
| 3477 | } else { |
| 3478 | __ shrl(first_reg, imm); |
| 3479 | } |
| 3480 | } |
| 3481 | break; |
| 3482 | } |
| 3483 | case Primitive::kPrimLong: { |
| 3484 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3485 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3486 | if (op->IsShl()) { |
| 3487 | __ shlq(first_reg, second_reg); |
| 3488 | } else if (op->IsShr()) { |
| 3489 | __ sarq(first_reg, second_reg); |
| 3490 | } else { |
| 3491 | __ shrq(first_reg, second_reg); |
| 3492 | } |
| 3493 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3494 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3495 | if (op->IsShl()) { |
| 3496 | __ shlq(first_reg, imm); |
| 3497 | } else if (op->IsShr()) { |
| 3498 | __ sarq(first_reg, imm); |
| 3499 | } else { |
| 3500 | __ shrq(first_reg, imm); |
| 3501 | } |
| 3502 | } |
| 3503 | break; |
| 3504 | } |
| 3505 | default: |
| 3506 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3507 | } |
| 3508 | } |
| 3509 | |
| 3510 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 3511 | HandleShift(shl); |
| 3512 | } |
| 3513 | |
| 3514 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 3515 | HandleShift(shl); |
| 3516 | } |
| 3517 | |
| 3518 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 3519 | HandleShift(shr); |
| 3520 | } |
| 3521 | |
| 3522 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 3523 | HandleShift(shr); |
| 3524 | } |
| 3525 | |
| 3526 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 3527 | HandleShift(ushr); |
| 3528 | } |
| 3529 | |
| 3530 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 3531 | HandleShift(ushr); |
| 3532 | } |
| 3533 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3534 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3535 | LocationSummary* locations = |
| 3536 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3537 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3538 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3539 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3540 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3541 | } |
| 3542 | |
| 3543 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
| 3544 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3545 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3546 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3547 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3548 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3549 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3550 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3551 | instruction, |
| 3552 | instruction->GetDexPc(), |
| 3553 | nullptr); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3554 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3555 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3556 | } |
| 3557 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3558 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 3559 | LocationSummary* locations = |
| 3560 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3561 | InvokeRuntimeCallingConvention calling_convention; |
| 3562 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3563 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3564 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3565 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3566 | } |
| 3567 | |
| 3568 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 3569 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3570 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3571 | instruction->GetTypeIndex()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3572 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3573 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3574 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3575 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3576 | instruction, |
| 3577 | instruction->GetDexPc(), |
| 3578 | nullptr); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3579 | |
| 3580 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3581 | } |
| 3582 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3583 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3584 | LocationSummary* locations = |
| 3585 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3586 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3587 | if (location.IsStackSlot()) { |
| 3588 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3589 | } else if (location.IsDoubleStackSlot()) { |
| 3590 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3591 | } |
| 3592 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3593 | } |
| 3594 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3595 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 3596 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3597 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3598 | } |
| 3599 | |
| 3600 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3601 | LocationSummary* locations = |
| 3602 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3603 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3604 | } |
| 3605 | |
| 3606 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 3607 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3608 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3609 | } |
| 3610 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3611 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3612 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3613 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3614 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3615 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3616 | } |
| 3617 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3618 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 3619 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3620 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3621 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3622 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3623 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3624 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3625 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3626 | break; |
| 3627 | |
| 3628 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3629 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3630 | break; |
| 3631 | |
| 3632 | default: |
| 3633 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3634 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3635 | } |
| 3636 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3637 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3638 | LocationSummary* locations = |
| 3639 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3640 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3641 | locations->SetOut(Location::SameAsFirstInput()); |
| 3642 | } |
| 3643 | |
| 3644 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3645 | LocationSummary* locations = bool_not->GetLocations(); |
| 3646 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3647 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 3648 | Location out = locations->Out(); |
| 3649 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 3650 | } |
| 3651 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3652 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3653 | LocationSummary* locations = |
| 3654 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3655 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3656 | locations->SetInAt(i, Location::Any()); |
| 3657 | } |
| 3658 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3659 | } |
| 3660 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3661 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3662 | LOG(FATAL) << "Unimplemented"; |
| 3663 | } |
| 3664 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3665 | void InstructionCodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3666 | /* |
| 3667 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 3668 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 3669 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 3670 | */ |
| 3671 | switch (kind) { |
| 3672 | case MemBarrierKind::kAnyAny: { |
| 3673 | __ mfence(); |
| 3674 | break; |
| 3675 | } |
| 3676 | case MemBarrierKind::kAnyStore: |
| 3677 | case MemBarrierKind::kLoadAny: |
| 3678 | case MemBarrierKind::kStoreStore: { |
| 3679 | // nop |
| 3680 | break; |
| 3681 | } |
| 3682 | default: |
| 3683 | LOG(FATAL) << "Unexpected memory barier " << kind; |
| 3684 | } |
| 3685 | } |
| 3686 | |
| 3687 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 3688 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 3689 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3690 | LocationSummary* locations = |
| 3691 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3692 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3693 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3694 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3695 | } else { |
| 3696 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3697 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3698 | } |
| 3699 | |
| 3700 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 3701 | const FieldInfo& field_info) { |
| 3702 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 3703 | |
| 3704 | LocationSummary* locations = instruction->GetLocations(); |
| 3705 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3706 | Location out = locations->Out(); |
| 3707 | bool is_volatile = field_info.IsVolatile(); |
| 3708 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3709 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3710 | |
| 3711 | switch (field_type) { |
| 3712 | case Primitive::kPrimBoolean: { |
| 3713 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3714 | break; |
| 3715 | } |
| 3716 | |
| 3717 | case Primitive::kPrimByte: { |
| 3718 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3719 | break; |
| 3720 | } |
| 3721 | |
| 3722 | case Primitive::kPrimShort: { |
| 3723 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3724 | break; |
| 3725 | } |
| 3726 | |
| 3727 | case Primitive::kPrimChar: { |
| 3728 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3729 | break; |
| 3730 | } |
| 3731 | |
| 3732 | case Primitive::kPrimInt: |
| 3733 | case Primitive::kPrimNot: { |
| 3734 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3735 | break; |
| 3736 | } |
| 3737 | |
| 3738 | case Primitive::kPrimLong: { |
| 3739 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3740 | break; |
| 3741 | } |
| 3742 | |
| 3743 | case Primitive::kPrimFloat: { |
| 3744 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 3745 | break; |
| 3746 | } |
| 3747 | |
| 3748 | case Primitive::kPrimDouble: { |
| 3749 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 3750 | break; |
| 3751 | } |
| 3752 | |
| 3753 | case Primitive::kPrimVoid: |
| 3754 | LOG(FATAL) << "Unreachable type " << field_type; |
| 3755 | UNREACHABLE(); |
| 3756 | } |
| 3757 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3758 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3759 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3760 | if (is_volatile) { |
| 3761 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3762 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3763 | |
| 3764 | if (field_type == Primitive::kPrimNot) { |
| 3765 | __ MaybeUnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 3766 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 3770 | const FieldInfo& field_info) { |
| 3771 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3772 | |
| 3773 | LocationSummary* locations = |
| 3774 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3775 | Primitive::Type field_type = field_info.GetFieldType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3776 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3777 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3778 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3779 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3780 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| 3781 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3782 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3783 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3784 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3785 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3786 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3787 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3788 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3789 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 3790 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3791 | locations->AddTemp(Location::RequiresRegister()); |
| 3792 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3793 | } |
| 3794 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3795 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3796 | const FieldInfo& field_info, |
| 3797 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3798 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3799 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3800 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3801 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3802 | Location value = locations->InAt(1); |
| 3803 | bool is_volatile = field_info.IsVolatile(); |
| 3804 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3805 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3806 | |
| 3807 | if (is_volatile) { |
| 3808 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3809 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3810 | |
| 3811 | switch (field_type) { |
| 3812 | case Primitive::kPrimBoolean: |
| 3813 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3814 | if (value.IsConstant()) { |
| 3815 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 3816 | __ movb(Address(base, offset), Immediate(v)); |
| 3817 | } else { |
| 3818 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3819 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3820 | break; |
| 3821 | } |
| 3822 | |
| 3823 | case Primitive::kPrimShort: |
| 3824 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3825 | if (value.IsConstant()) { |
| 3826 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 3827 | __ movw(Address(base, offset), Immediate(v)); |
| 3828 | } else { |
| 3829 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3830 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3831 | break; |
| 3832 | } |
| 3833 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3834 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3835 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3836 | if (value.IsConstant()) { |
| 3837 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3838 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 3839 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 3840 | // Note: if heap poisoning is enabled, no need to poison |
| 3841 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 3842 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3843 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3844 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 3845 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3846 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 3847 | __ PoisonHeapReference(temp); |
| 3848 | __ movl(Address(base, offset), temp); |
| 3849 | } else { |
| 3850 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3851 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3852 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3853 | break; |
| 3854 | } |
| 3855 | |
| 3856 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3857 | if (value.IsConstant()) { |
| 3858 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 3859 | DCHECK(IsInt<32>(v)); |
| 3860 | int32_t v_32 = v; |
| 3861 | __ movq(Address(base, offset), Immediate(v_32)); |
| 3862 | } else { |
| 3863 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3864 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3865 | break; |
| 3866 | } |
| 3867 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3868 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3869 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3870 | break; |
| 3871 | } |
| 3872 | |
| 3873 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3874 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3875 | break; |
| 3876 | } |
| 3877 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3878 | case Primitive::kPrimVoid: |
| 3879 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3880 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3881 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3882 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3883 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3884 | |
| 3885 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 3886 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3887 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3888 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3889 | } |
| 3890 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3891 | if (is_volatile) { |
| 3892 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 3893 | } |
| 3894 | } |
| 3895 | |
| 3896 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 3897 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3898 | } |
| 3899 | |
| 3900 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3901 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3902 | } |
| 3903 | |
| 3904 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3905 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3906 | } |
| 3907 | |
| 3908 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3909 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3910 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3911 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3912 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3913 | HandleFieldGet(instruction); |
| 3914 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3915 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3916 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3917 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3918 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3919 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3920 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3921 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3922 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3923 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3924 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3925 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3926 | } |
| 3927 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 3928 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 3929 | HUnresolvedInstanceFieldGet* instruction) { |
| 3930 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3931 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3932 | instruction, instruction->GetFieldType(), calling_convention); |
| 3933 | } |
| 3934 | |
| 3935 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 3936 | HUnresolvedInstanceFieldGet* instruction) { |
| 3937 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3938 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3939 | instruction->GetFieldType(), |
| 3940 | instruction->GetFieldIndex(), |
| 3941 | instruction->GetDexPc(), |
| 3942 | calling_convention); |
| 3943 | } |
| 3944 | |
| 3945 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 3946 | HUnresolvedInstanceFieldSet* instruction) { |
| 3947 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3948 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3949 | instruction, instruction->GetFieldType(), calling_convention); |
| 3950 | } |
| 3951 | |
| 3952 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 3953 | HUnresolvedInstanceFieldSet* instruction) { |
| 3954 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3955 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3956 | instruction->GetFieldType(), |
| 3957 | instruction->GetFieldIndex(), |
| 3958 | instruction->GetDexPc(), |
| 3959 | calling_convention); |
| 3960 | } |
| 3961 | |
| 3962 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 3963 | HUnresolvedStaticFieldGet* instruction) { |
| 3964 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3965 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3966 | instruction, instruction->GetFieldType(), calling_convention); |
| 3967 | } |
| 3968 | |
| 3969 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 3970 | HUnresolvedStaticFieldGet* instruction) { |
| 3971 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3972 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3973 | instruction->GetFieldType(), |
| 3974 | instruction->GetFieldIndex(), |
| 3975 | instruction->GetDexPc(), |
| 3976 | calling_convention); |
| 3977 | } |
| 3978 | |
| 3979 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 3980 | HUnresolvedStaticFieldSet* instruction) { |
| 3981 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3982 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3983 | instruction, instruction->GetFieldType(), calling_convention); |
| 3984 | } |
| 3985 | |
| 3986 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 3987 | HUnresolvedStaticFieldSet* instruction) { |
| 3988 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3989 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3990 | instruction->GetFieldType(), |
| 3991 | instruction->GetFieldIndex(), |
| 3992 | instruction->GetDexPc(), |
| 3993 | calling_convention); |
| 3994 | } |
| 3995 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3996 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3997 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3998 | ? LocationSummary::kCallOnSlowPath |
| 3999 | : LocationSummary::kNoCall; |
| 4000 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4001 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4002 | ? Location::RequiresRegister() |
| 4003 | : Location::Any(); |
| 4004 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4005 | if (instruction->HasUses()) { |
| 4006 | locations->SetOut(Location::SameAsFirstInput()); |
| 4007 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4008 | } |
| 4009 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4010 | void InstructionCodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4011 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4012 | return; |
| 4013 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4014 | LocationSummary* locations = instruction->GetLocations(); |
| 4015 | Location obj = locations->InAt(0); |
| 4016 | |
| 4017 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
| 4018 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4019 | } |
| 4020 | |
| 4021 | void InstructionCodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4022 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4023 | codegen_->AddSlowPath(slow_path); |
| 4024 | |
| 4025 | LocationSummary* locations = instruction->GetLocations(); |
| 4026 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4027 | |
| 4028 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4029 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4030 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4031 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4032 | } else { |
| 4033 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4034 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4035 | __ jmp(slow_path->GetEntryLabel()); |
| 4036 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4037 | } |
| 4038 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4039 | } |
| 4040 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4041 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4042 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4043 | GenerateImplicitNullCheck(instruction); |
| 4044 | } else { |
| 4045 | GenerateExplicitNullCheck(instruction); |
| 4046 | } |
| 4047 | } |
| 4048 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4049 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4050 | LocationSummary* locations = |
| 4051 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4052 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4053 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4054 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4055 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4056 | } else { |
| 4057 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4058 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4059 | } |
| 4060 | |
| 4061 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4062 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4063 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4064 | Location index = locations->InAt(1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4065 | Primitive::Type type = instruction->GetType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4066 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4067 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4068 | case Primitive::kPrimBoolean: { |
| 4069 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4070 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4071 | if (index.IsConstant()) { |
| 4072 | __ movzxb(out, Address(obj, |
| 4073 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4074 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4075 | __ movzxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4076 | } |
| 4077 | break; |
| 4078 | } |
| 4079 | |
| 4080 | case Primitive::kPrimByte: { |
| 4081 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4082 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4083 | if (index.IsConstant()) { |
| 4084 | __ movsxb(out, Address(obj, |
| 4085 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4086 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4087 | __ movsxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4088 | } |
| 4089 | break; |
| 4090 | } |
| 4091 | |
| 4092 | case Primitive::kPrimShort: { |
| 4093 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4094 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4095 | if (index.IsConstant()) { |
| 4096 | __ movsxw(out, Address(obj, |
| 4097 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4098 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4099 | __ movsxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4100 | } |
| 4101 | break; |
| 4102 | } |
| 4103 | |
| 4104 | case Primitive::kPrimChar: { |
| 4105 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4106 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4107 | if (index.IsConstant()) { |
| 4108 | __ movzxw(out, Address(obj, |
| 4109 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4110 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4111 | __ movzxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4112 | } |
| 4113 | break; |
| 4114 | } |
| 4115 | |
| 4116 | case Primitive::kPrimInt: |
| 4117 | case Primitive::kPrimNot: { |
Roland Levillain | 33d6903 | 2015-06-18 18:20:59 +0100 | [diff] [blame] | 4118 | static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4119 | "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4120 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4121 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4122 | if (index.IsConstant()) { |
| 4123 | __ movl(out, Address(obj, |
| 4124 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4125 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4126 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4127 | } |
| 4128 | break; |
| 4129 | } |
| 4130 | |
| 4131 | case Primitive::kPrimLong: { |
| 4132 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4133 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4134 | if (index.IsConstant()) { |
| 4135 | __ movq(out, Address(obj, |
| 4136 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4137 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4138 | __ movq(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4139 | } |
| 4140 | break; |
| 4141 | } |
| 4142 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4143 | case Primitive::kPrimFloat: { |
| 4144 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4145 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4146 | if (index.IsConstant()) { |
| 4147 | __ movss(out, Address(obj, |
| 4148 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4149 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4150 | __ movss(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4151 | } |
| 4152 | break; |
| 4153 | } |
| 4154 | |
| 4155 | case Primitive::kPrimDouble: { |
| 4156 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4157 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4158 | if (index.IsConstant()) { |
| 4159 | __ movsd(out, Address(obj, |
| 4160 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4161 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4162 | __ movsd(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4163 | } |
| 4164 | break; |
| 4165 | } |
| 4166 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4167 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4168 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4169 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4170 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4171 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4172 | |
| 4173 | if (type == Primitive::kPrimNot) { |
| 4174 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4175 | __ MaybeUnpoisonHeapReference(out); |
| 4176 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4177 | } |
| 4178 | |
| 4179 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4180 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4181 | |
| 4182 | bool needs_write_barrier = |
| 4183 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4184 | bool may_need_runtime_call = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4185 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4186 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4187 | instruction, |
| 4188 | may_need_runtime_call ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4189 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4190 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4191 | locations->SetInAt( |
| 4192 | 1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4193 | locations->SetInAt(2, Location::RequiresRegister()); |
| 4194 | if (value_type == Primitive::kPrimLong) { |
| 4195 | locations->SetInAt(2, Location::RegisterOrInt32LongConstant(instruction->InputAt(2))); |
| 4196 | } else if (value_type == Primitive::kPrimFloat || value_type == Primitive::kPrimDouble) { |
| 4197 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 4198 | } else { |
| 4199 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4200 | } |
| 4201 | |
| 4202 | if (needs_write_barrier) { |
| 4203 | // Temporary registers for the write barrier. |
| 4204 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 4205 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4206 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4207 | } |
| 4208 | |
| 4209 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4210 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4211 | CpuRegister array = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4212 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4213 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4214 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4215 | bool may_need_runtime_call = locations->CanCall(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4216 | bool needs_write_barrier = |
| 4217 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4218 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4219 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4220 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4221 | |
| 4222 | switch (value_type) { |
| 4223 | case Primitive::kPrimBoolean: |
| 4224 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4225 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 4226 | Address address = index.IsConstant() |
| 4227 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 4228 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_1, offset); |
| 4229 | if (value.IsRegister()) { |
| 4230 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4231 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4232 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4233 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4234 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4235 | break; |
| 4236 | } |
| 4237 | |
| 4238 | case Primitive::kPrimShort: |
| 4239 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4240 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 4241 | Address address = index.IsConstant() |
| 4242 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 4243 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_2, offset); |
| 4244 | if (value.IsRegister()) { |
| 4245 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4246 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4247 | DCHECK(value.IsConstant()) << value; |
| 4248 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4249 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4250 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4251 | break; |
| 4252 | } |
| 4253 | |
| 4254 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4255 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4256 | Address address = index.IsConstant() |
| 4257 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4258 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
| 4259 | if (!value.IsRegister()) { |
| 4260 | // Just setting null. |
| 4261 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4262 | DCHECK(value.IsConstant()) << value; |
| 4263 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4264 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4265 | DCHECK(!needs_write_barrier); |
| 4266 | DCHECK(!may_need_runtime_call); |
| 4267 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4268 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4269 | |
| 4270 | DCHECK(needs_write_barrier); |
| 4271 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
| 4272 | NearLabel done, not_null, do_put; |
| 4273 | SlowPathCode* slow_path = nullptr; |
| 4274 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4275 | if (may_need_runtime_call) { |
| 4276 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86_64(instruction); |
| 4277 | codegen_->AddSlowPath(slow_path); |
| 4278 | if (instruction->GetValueCanBeNull()) { |
| 4279 | __ testl(register_value, register_value); |
| 4280 | __ j(kNotEqual, ¬_null); |
| 4281 | __ movl(address, Immediate(0)); |
| 4282 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4283 | __ jmp(&done); |
| 4284 | __ Bind(¬_null); |
| 4285 | } |
| 4286 | |
| 4287 | __ movl(temp, Address(array, class_offset)); |
| 4288 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4289 | __ MaybeUnpoisonHeapReference(temp); |
| 4290 | __ movl(temp, Address(temp, component_offset)); |
| 4291 | // No need to poison/unpoison, we're comparing two poisoned references. |
| 4292 | __ cmpl(temp, Address(register_value, class_offset)); |
| 4293 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4294 | __ j(kEqual, &do_put); |
| 4295 | __ MaybeUnpoisonHeapReference(temp); |
| 4296 | __ movl(temp, Address(temp, super_offset)); |
| 4297 | // No need to unpoison the result, we're comparing against null. |
| 4298 | __ testl(temp, temp); |
| 4299 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4300 | __ Bind(&do_put); |
| 4301 | } else { |
| 4302 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4303 | } |
| 4304 | } |
| 4305 | |
| 4306 | if (kPoisonHeapReferences) { |
| 4307 | __ movl(temp, register_value); |
| 4308 | __ PoisonHeapReference(temp); |
| 4309 | __ movl(address, temp); |
| 4310 | } else { |
| 4311 | __ movl(address, register_value); |
| 4312 | } |
| 4313 | if (!may_need_runtime_call) { |
| 4314 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4315 | } |
| 4316 | |
| 4317 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4318 | codegen_->MarkGCCard( |
| 4319 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4320 | __ Bind(&done); |
| 4321 | |
| 4322 | if (slow_path != nullptr) { |
| 4323 | __ Bind(slow_path->GetExitLabel()); |
| 4324 | } |
| 4325 | |
| 4326 | break; |
| 4327 | } |
| 4328 | case Primitive::kPrimInt: { |
| 4329 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4330 | Address address = index.IsConstant() |
| 4331 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4332 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
| 4333 | if (value.IsRegister()) { |
| 4334 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 4335 | } else { |
| 4336 | DCHECK(value.IsConstant()) << value; |
| 4337 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4338 | __ movl(address, Immediate(v)); |
| 4339 | } |
| 4340 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4341 | break; |
| 4342 | } |
| 4343 | |
| 4344 | case Primitive::kPrimLong: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4345 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 4346 | Address address = index.IsConstant() |
| 4347 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4348 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
| 4349 | if (value.IsRegister()) { |
| 4350 | __ movq(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4351 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4352 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 4353 | DCHECK(IsInt<32>(v)); |
| 4354 | int32_t v_32 = v; |
| 4355 | __ movq(address, Immediate(v_32)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4356 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4357 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4358 | break; |
| 4359 | } |
| 4360 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4361 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4362 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4363 | Address address = index.IsConstant() |
| 4364 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4365 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
| 4366 | DCHECK(value.IsFpuRegister()); |
| 4367 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4368 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4369 | break; |
| 4370 | } |
| 4371 | |
| 4372 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4373 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4374 | Address address = index.IsConstant() |
| 4375 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4376 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
| 4377 | DCHECK(value.IsFpuRegister()); |
| 4378 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4379 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4380 | break; |
| 4381 | } |
| 4382 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4383 | case Primitive::kPrimVoid: |
| 4384 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4385 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4386 | } |
| 4387 | } |
| 4388 | |
| 4389 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4390 | LocationSummary* locations = |
| 4391 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4392 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4393 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4394 | } |
| 4395 | |
| 4396 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 4397 | LocationSummary* locations = instruction->GetLocations(); |
| 4398 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4399 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4400 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4401 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4402 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4403 | } |
| 4404 | |
| 4405 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4406 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4407 | ? LocationSummary::kCallOnSlowPath |
| 4408 | : LocationSummary::kNoCall; |
| 4409 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4410 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4411 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4412 | if (instruction->HasUses()) { |
| 4413 | locations->SetOut(Location::SameAsFirstInput()); |
| 4414 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4415 | } |
| 4416 | |
| 4417 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4418 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4419 | Location index_loc = locations->InAt(0); |
| 4420 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4421 | SlowPathCode* slow_path = |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4422 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4423 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4424 | if (length_loc.IsConstant()) { |
| 4425 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4426 | if (index_loc.IsConstant()) { |
| 4427 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4428 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4429 | if (index < 0 || index >= length) { |
| 4430 | codegen_->AddSlowPath(slow_path); |
| 4431 | __ jmp(slow_path->GetEntryLabel()); |
| 4432 | } else { |
| 4433 | // Some optimization after BCE may have generated this, and we should not |
| 4434 | // generate a bounds check if it is a valid range. |
| 4435 | } |
| 4436 | return; |
| 4437 | } |
| 4438 | |
| 4439 | // We have to reverse the jump condition because the length is the constant. |
| 4440 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 4441 | __ cmpl(index_reg, Immediate(length)); |
| 4442 | codegen_->AddSlowPath(slow_path); |
| 4443 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4444 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4445 | CpuRegister length = length_loc.AsRegister<CpuRegister>(); |
| 4446 | if (index_loc.IsConstant()) { |
| 4447 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4448 | __ cmpl(length, Immediate(value)); |
| 4449 | } else { |
| 4450 | __ cmpl(length, index_loc.AsRegister<CpuRegister>()); |
| 4451 | } |
| 4452 | codegen_->AddSlowPath(slow_path); |
| 4453 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4454 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4455 | } |
| 4456 | |
| 4457 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 4458 | CpuRegister card, |
| 4459 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4460 | CpuRegister value, |
| 4461 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4462 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4463 | if (value_can_be_null) { |
| 4464 | __ testl(value, value); |
| 4465 | __ j(kEqual, &is_null); |
| 4466 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4467 | __ gs()->movq(card, Address::Absolute( |
| 4468 | Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), true)); |
| 4469 | __ movq(temp, object); |
| 4470 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4471 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4472 | if (value_can_be_null) { |
| 4473 | __ Bind(&is_null); |
| 4474 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4475 | } |
| 4476 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4477 | void LocationsBuilderX86_64::VisitTemporary(HTemporary* temp) { |
| 4478 | temp->SetLocations(nullptr); |
| 4479 | } |
| 4480 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4481 | void InstructionCodeGeneratorX86_64::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4482 | // Nothing to do, this is driven by the code generator. |
| 4483 | } |
| 4484 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4485 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4486 | LOG(FATAL) << "Unimplemented"; |
| 4487 | } |
| 4488 | |
| 4489 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4490 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4491 | } |
| 4492 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4493 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4494 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4495 | } |
| 4496 | |
| 4497 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4498 | HBasicBlock* block = instruction->GetBlock(); |
| 4499 | if (block->GetLoopInformation() != nullptr) { |
| 4500 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4501 | // The back edge will generate the suspend check. |
| 4502 | return; |
| 4503 | } |
| 4504 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4505 | // The goto will generate the suspend check. |
| 4506 | return; |
| 4507 | } |
| 4508 | GenerateSuspendCheck(instruction, nullptr); |
| 4509 | } |
| 4510 | |
| 4511 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4512 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4513 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4514 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 4515 | if (slow_path == nullptr) { |
| 4516 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 4517 | instruction->SetSlowPath(slow_path); |
| 4518 | codegen_->AddSlowPath(slow_path); |
| 4519 | if (successor != nullptr) { |
| 4520 | DCHECK(successor->IsLoopHeader()); |
| 4521 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4522 | } |
| 4523 | } else { |
| 4524 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4525 | } |
| 4526 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4527 | __ gs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4528 | Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), true), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4529 | if (successor == nullptr) { |
| 4530 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4531 | __ Bind(slow_path->GetReturnLabel()); |
| 4532 | } else { |
| 4533 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 4534 | __ jmp(slow_path->GetEntryLabel()); |
| 4535 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4536 | } |
| 4537 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4538 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 4539 | return codegen_->GetAssembler(); |
| 4540 | } |
| 4541 | |
| 4542 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4543 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4544 | Location source = move->GetSource(); |
| 4545 | Location destination = move->GetDestination(); |
| 4546 | |
| 4547 | if (source.IsRegister()) { |
| 4548 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4549 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4550 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4551 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4552 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4553 | } else { |
| 4554 | DCHECK(destination.IsDoubleStackSlot()); |
| 4555 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4556 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4557 | } |
| 4558 | } else if (source.IsStackSlot()) { |
| 4559 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4560 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4561 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4562 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4563 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4564 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4565 | } else { |
| 4566 | DCHECK(destination.IsStackSlot()); |
| 4567 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 4568 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4569 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4570 | } else if (source.IsDoubleStackSlot()) { |
| 4571 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4572 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4573 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4574 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4575 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 4576 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4577 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 4578 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4579 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 4580 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4581 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4582 | } else if (source.IsConstant()) { |
| 4583 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4584 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 4585 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4586 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4587 | if (value == 0) { |
| 4588 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 4589 | } else { |
| 4590 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 4591 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4592 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4593 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4594 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4595 | } |
| 4596 | } else if (constant->IsLongConstant()) { |
| 4597 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 4598 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4599 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4600 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4601 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 4602 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4603 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4604 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4605 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4606 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4607 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4608 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4609 | if (value == 0) { |
| 4610 | // easy FP 0.0. |
| 4611 | __ xorps(dest, dest); |
| 4612 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4613 | __ movss(dest, codegen_->LiteralFloatAddress(fp_value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4614 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4615 | } else { |
| 4616 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4617 | Immediate imm(value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4618 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 4619 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4620 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4621 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4622 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4623 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4624 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4625 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4626 | if (value == 0) { |
| 4627 | __ xorpd(dest, dest); |
| 4628 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4629 | __ movsd(dest, codegen_->LiteralDoubleAddress(fp_value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4630 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4631 | } else { |
| 4632 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 4633 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4634 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4635 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4636 | } else if (source.IsFpuRegister()) { |
| 4637 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4638 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4639 | } else if (destination.IsStackSlot()) { |
| 4640 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4641 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4642 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 4643 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4644 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4645 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4646 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4647 | } |
| 4648 | } |
| 4649 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4650 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4651 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4652 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 4653 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4654 | } |
| 4655 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4656 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4657 | ScratchRegisterScope ensure_scratch( |
| 4658 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 4659 | |
| 4660 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 4661 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 4662 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 4663 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 4664 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 4665 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 4666 | CpuRegister(ensure_scratch.GetRegister())); |
| 4667 | } |
| 4668 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4669 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 4670 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4671 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 4672 | __ movq(reg, CpuRegister(TMP)); |
| 4673 | } |
| 4674 | |
| 4675 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 4676 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4677 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4678 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4679 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 4680 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 4681 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 4682 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 4683 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 4684 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 4685 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4686 | } |
| 4687 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4688 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 4689 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4690 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 4691 | __ movd(reg, CpuRegister(TMP)); |
| 4692 | } |
| 4693 | |
| 4694 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 4695 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4696 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 4697 | __ movd(reg, CpuRegister(TMP)); |
| 4698 | } |
| 4699 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4700 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4701 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4702 | Location source = move->GetSource(); |
| 4703 | Location destination = move->GetDestination(); |
| 4704 | |
| 4705 | if (source.IsRegister() && destination.IsRegister()) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4706 | __ xchgq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4707 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4708 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4709 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4710 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4711 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4712 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 4713 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4714 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4715 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4716 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4717 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 4718 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4719 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4720 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 4721 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 4722 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4723 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4724 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4725 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4726 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4727 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4728 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4729 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4730 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4731 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4732 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4733 | } |
| 4734 | } |
| 4735 | |
| 4736 | |
| 4737 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 4738 | __ pushq(CpuRegister(reg)); |
| 4739 | } |
| 4740 | |
| 4741 | |
| 4742 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 4743 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4744 | } |
| 4745 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4746 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4747 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4748 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 4749 | Immediate(mirror::Class::kStatusInitialized)); |
| 4750 | __ j(kLess, slow_path->GetEntryLabel()); |
| 4751 | __ Bind(slow_path->GetExitLabel()); |
| 4752 | // No need for memory fence, thanks to the X86_64 memory model. |
| 4753 | } |
| 4754 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4755 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4756 | InvokeRuntimeCallingConvention calling_convention; |
| 4757 | CodeGenerator::CreateLoadClassLocationSummary( |
| 4758 | cls, |
| 4759 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 4760 | Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4761 | } |
| 4762 | |
| 4763 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4764 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4765 | if (cls->NeedsAccessCheck()) { |
| 4766 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 4767 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 4768 | cls, |
| 4769 | cls->GetDexPc(), |
| 4770 | nullptr); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4771 | return; |
| 4772 | } |
| 4773 | |
| 4774 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4775 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4776 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4777 | DCHECK(!cls->CanCallRuntime()); |
| 4778 | DCHECK(!cls->MustGenerateClinitCheck()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4779 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4780 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4781 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4782 | __ movq(out, Address( |
| 4783 | current_method, ArtMethod::DexCacheResolvedTypesOffset(kX86_64PointerSize).Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4784 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4785 | // TODO: We will need a read barrier here. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4786 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4787 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4788 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4789 | codegen_->AddSlowPath(slow_path); |
| 4790 | __ testl(out, out); |
| 4791 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4792 | if (cls->MustGenerateClinitCheck()) { |
| 4793 | GenerateClassInitializationCheck(slow_path, out); |
| 4794 | } else { |
| 4795 | __ Bind(slow_path->GetExitLabel()); |
| 4796 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4797 | } |
| 4798 | } |
| 4799 | |
| 4800 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 4801 | LocationSummary* locations = |
| 4802 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 4803 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4804 | if (check->HasUses()) { |
| 4805 | locations->SetOut(Location::SameAsFirstInput()); |
| 4806 | } |
| 4807 | } |
| 4808 | |
| 4809 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4810 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4811 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4812 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4813 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4814 | GenerateClassInitializationCheck(slow_path, |
| 4815 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4816 | } |
| 4817 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4818 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
| 4819 | LocationSummary* locations = |
| 4820 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4821 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4822 | locations->SetOut(Location::RequiresRegister()); |
| 4823 | } |
| 4824 | |
| 4825 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4826 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4827 | codegen_->AddSlowPath(slow_path); |
| 4828 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4829 | LocationSummary* locations = load->GetLocations(); |
| 4830 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4831 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4832 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4833 | __ movq(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4834 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4835 | // TODO: We will need a read barrier here. |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4836 | __ testl(out, out); |
| 4837 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4838 | __ Bind(slow_path->GetExitLabel()); |
| 4839 | } |
| 4840 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4841 | static Address GetExceptionTlsAddress() { |
| 4842 | return Address::Absolute(Thread::ExceptionOffset<kX86_64WordSize>().Int32Value(), true); |
| 4843 | } |
| 4844 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4845 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 4846 | LocationSummary* locations = |
| 4847 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4848 | locations->SetOut(Location::RequiresRegister()); |
| 4849 | } |
| 4850 | |
| 4851 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4852 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 4853 | } |
| 4854 | |
| 4855 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 4856 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4857 | } |
| 4858 | |
| 4859 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4860 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4861 | } |
| 4862 | |
| 4863 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 4864 | LocationSummary* locations = |
| 4865 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4866 | InvokeRuntimeCallingConvention calling_convention; |
| 4867 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4868 | } |
| 4869 | |
| 4870 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4871 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 4872 | instruction, |
| 4873 | instruction->GetDexPc(), |
| 4874 | nullptr); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4875 | } |
| 4876 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4877 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4878 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4879 | switch (instruction->GetTypeCheckKind()) { |
| 4880 | case TypeCheckKind::kExactCheck: |
| 4881 | case TypeCheckKind::kAbstractClassCheck: |
| 4882 | case TypeCheckKind::kClassHierarchyCheck: |
| 4883 | case TypeCheckKind::kArrayObjectCheck: |
| 4884 | call_kind = LocationSummary::kNoCall; |
| 4885 | break; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4886 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4887 | case TypeCheckKind::kInterfaceCheck: |
| 4888 | call_kind = LocationSummary::kCall; |
| 4889 | break; |
| 4890 | case TypeCheckKind::kArrayCheck: |
| 4891 | call_kind = LocationSummary::kCallOnSlowPath; |
| 4892 | break; |
| 4893 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4894 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4895 | if (call_kind != LocationSummary::kCall) { |
| 4896 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4897 | locations->SetInAt(1, Location::Any()); |
| 4898 | // Note that TypeCheckSlowPathX86_64 uses this register too. |
| 4899 | locations->SetOut(Location::RequiresRegister()); |
| 4900 | } else { |
| 4901 | InvokeRuntimeCallingConvention calling_convention; |
| 4902 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4903 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4904 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 4905 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4906 | } |
| 4907 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4908 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4909 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4910 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4911 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4912 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4913 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4914 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4915 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4916 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4917 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4918 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4919 | |
| 4920 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4921 | // Avoid null check if we know obj is not null. |
| 4922 | if (instruction->MustDoNullCheck()) { |
| 4923 | __ testl(obj, obj); |
| 4924 | __ j(kEqual, &zero); |
| 4925 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4926 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4927 | // In case of an interface/unresolved check, we put the object class into the object register. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4928 | // This is safe, as the register is caller-save, and the object must be in another |
| 4929 | // register if it survives the runtime call. |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4930 | CpuRegister target = (instruction->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) || |
| 4931 | (instruction->GetTypeCheckKind() == TypeCheckKind::kUnresolvedCheck) |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4932 | ? obj |
| 4933 | : out; |
| 4934 | __ movl(target, Address(obj, class_offset)); |
| 4935 | __ MaybeUnpoisonHeapReference(target); |
| 4936 | |
| 4937 | switch (instruction->GetTypeCheckKind()) { |
| 4938 | case TypeCheckKind::kExactCheck: { |
| 4939 | if (cls.IsRegister()) { |
| 4940 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 4941 | } else { |
| 4942 | DCHECK(cls.IsStackSlot()) << cls; |
| 4943 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4944 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4945 | if (zero.IsLinked()) { |
| 4946 | // Classes must be equal for the instanceof to succeed. |
| 4947 | __ j(kNotEqual, &zero); |
| 4948 | __ movl(out, Immediate(1)); |
| 4949 | __ jmp(&done); |
| 4950 | } else { |
| 4951 | __ setcc(kEqual, out); |
| 4952 | // setcc only sets the low byte. |
| 4953 | __ andl(out, Immediate(1)); |
| 4954 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4955 | break; |
| 4956 | } |
| 4957 | case TypeCheckKind::kAbstractClassCheck: { |
| 4958 | // If the class is abstract, we eagerly fetch the super class of the |
| 4959 | // object to avoid doing a comparison we know will fail. |
| 4960 | NearLabel loop, success; |
| 4961 | __ Bind(&loop); |
| 4962 | __ movl(out, Address(out, super_offset)); |
| 4963 | __ MaybeUnpoisonHeapReference(out); |
| 4964 | __ testl(out, out); |
| 4965 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4966 | __ j(kEqual, &done); |
| 4967 | if (cls.IsRegister()) { |
| 4968 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 4969 | } else { |
| 4970 | DCHECK(cls.IsStackSlot()) << cls; |
| 4971 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4972 | } |
| 4973 | __ j(kNotEqual, &loop); |
| 4974 | __ movl(out, Immediate(1)); |
| 4975 | if (zero.IsLinked()) { |
| 4976 | __ jmp(&done); |
| 4977 | } |
| 4978 | break; |
| 4979 | } |
| 4980 | case TypeCheckKind::kClassHierarchyCheck: { |
| 4981 | // Walk over the class hierarchy to find a match. |
| 4982 | NearLabel loop, success; |
| 4983 | __ Bind(&loop); |
| 4984 | if (cls.IsRegister()) { |
| 4985 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 4986 | } else { |
| 4987 | DCHECK(cls.IsStackSlot()) << cls; |
| 4988 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4989 | } |
| 4990 | __ j(kEqual, &success); |
| 4991 | __ movl(out, Address(out, super_offset)); |
| 4992 | __ MaybeUnpoisonHeapReference(out); |
| 4993 | __ testl(out, out); |
| 4994 | __ j(kNotEqual, &loop); |
| 4995 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4996 | __ jmp(&done); |
| 4997 | __ Bind(&success); |
| 4998 | __ movl(out, Immediate(1)); |
| 4999 | if (zero.IsLinked()) { |
| 5000 | __ jmp(&done); |
| 5001 | } |
| 5002 | break; |
| 5003 | } |
| 5004 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5005 | // Do an exact check. |
| 5006 | NearLabel exact_check; |
| 5007 | if (cls.IsRegister()) { |
| 5008 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5009 | } else { |
| 5010 | DCHECK(cls.IsStackSlot()) << cls; |
| 5011 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5012 | } |
| 5013 | __ j(kEqual, &exact_check); |
| 5014 | // Otherwise, we need to check that the object's class is a non primitive array. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5015 | __ movl(out, Address(out, component_offset)); |
| 5016 | __ MaybeUnpoisonHeapReference(out); |
| 5017 | __ testl(out, out); |
| 5018 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5019 | __ j(kEqual, &done); |
| 5020 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5021 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5022 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5023 | __ movl(out, Immediate(1)); |
| 5024 | __ jmp(&done); |
| 5025 | break; |
| 5026 | } |
| 5027 | case TypeCheckKind::kArrayCheck: { |
| 5028 | if (cls.IsRegister()) { |
| 5029 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5030 | } else { |
| 5031 | DCHECK(cls.IsStackSlot()) << cls; |
| 5032 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5033 | } |
| 5034 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5035 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64( |
| 5036 | instruction, /* is_fatal */ false); |
| 5037 | codegen_->AddSlowPath(slow_path); |
| 5038 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5039 | __ movl(out, Immediate(1)); |
| 5040 | if (zero.IsLinked()) { |
| 5041 | __ jmp(&done); |
| 5042 | } |
| 5043 | break; |
| 5044 | } |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5045 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5046 | case TypeCheckKind::kInterfaceCheck: |
| 5047 | default: { |
| 5048 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 5049 | instruction, |
| 5050 | instruction->GetDexPc(), |
| 5051 | nullptr); |
| 5052 | if (zero.IsLinked()) { |
| 5053 | __ jmp(&done); |
| 5054 | } |
| 5055 | break; |
| 5056 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5057 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5058 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5059 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5060 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5061 | __ xorl(out, out); |
| 5062 | } |
| 5063 | |
| 5064 | if (done.IsLinked()) { |
| 5065 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5066 | } |
| 5067 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5068 | if (slow_path != nullptr) { |
| 5069 | __ Bind(slow_path->GetExitLabel()); |
| 5070 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5071 | } |
| 5072 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5073 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5074 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5075 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 5076 | |
| 5077 | switch (instruction->GetTypeCheckKind()) { |
| 5078 | case TypeCheckKind::kExactCheck: |
| 5079 | case TypeCheckKind::kAbstractClassCheck: |
| 5080 | case TypeCheckKind::kClassHierarchyCheck: |
| 5081 | case TypeCheckKind::kArrayObjectCheck: |
| 5082 | call_kind = throws_into_catch |
| 5083 | ? LocationSummary::kCallOnSlowPath |
| 5084 | : LocationSummary::kNoCall; |
| 5085 | break; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5086 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5087 | case TypeCheckKind::kInterfaceCheck: |
| 5088 | call_kind = LocationSummary::kCall; |
| 5089 | break; |
| 5090 | case TypeCheckKind::kArrayCheck: |
| 5091 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5092 | break; |
| 5093 | } |
| 5094 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5095 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5096 | instruction, call_kind); |
| 5097 | if (call_kind != LocationSummary::kCall) { |
| 5098 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5099 | locations->SetInAt(1, Location::Any()); |
| 5100 | // Note that TypeCheckSlowPathX86_64 uses this register too. |
| 5101 | locations->AddTemp(Location::RequiresRegister()); |
| 5102 | } else { |
| 5103 | InvokeRuntimeCallingConvention calling_convention; |
| 5104 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5105 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5106 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5107 | } |
| 5108 | |
| 5109 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 5110 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5111 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5112 | Location cls = locations->InAt(1); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5113 | CpuRegister temp = locations->WillCall() |
| 5114 | ? CpuRegister(kNoRegister) |
| 5115 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 5116 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5117 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5118 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5119 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5120 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 5121 | SlowPathCode* slow_path = nullptr; |
| 5122 | |
| 5123 | if (!locations->WillCall()) { |
| 5124 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64( |
| 5125 | instruction, !locations->CanCall()); |
| 5126 | codegen_->AddSlowPath(slow_path); |
| 5127 | } |
| 5128 | |
| 5129 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5130 | // Avoid null check if we know obj is not null. |
| 5131 | if (instruction->MustDoNullCheck()) { |
| 5132 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5133 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5134 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5135 | |
| 5136 | if (locations->WillCall()) { |
| 5137 | __ movl(obj, Address(obj, class_offset)); |
| 5138 | __ MaybeUnpoisonHeapReference(obj); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5139 | } else { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5140 | __ movl(temp, Address(obj, class_offset)); |
| 5141 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5142 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5143 | |
| 5144 | switch (instruction->GetTypeCheckKind()) { |
| 5145 | case TypeCheckKind::kExactCheck: |
| 5146 | case TypeCheckKind::kArrayCheck: { |
| 5147 | if (cls.IsRegister()) { |
| 5148 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5149 | } else { |
| 5150 | DCHECK(cls.IsStackSlot()) << cls; |
| 5151 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5152 | } |
| 5153 | // Jump to slow path for throwing the exception or doing a |
| 5154 | // more involved array check. |
| 5155 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5156 | break; |
| 5157 | } |
| 5158 | case TypeCheckKind::kAbstractClassCheck: { |
| 5159 | // If the class is abstract, we eagerly fetch the super class of the |
| 5160 | // object to avoid doing a comparison we know will fail. |
| 5161 | NearLabel loop; |
| 5162 | __ Bind(&loop); |
| 5163 | __ movl(temp, Address(temp, super_offset)); |
| 5164 | __ MaybeUnpoisonHeapReference(temp); |
| 5165 | __ testl(temp, temp); |
| 5166 | // Jump to the slow path to throw the exception. |
| 5167 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5168 | if (cls.IsRegister()) { |
| 5169 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5170 | } else { |
| 5171 | DCHECK(cls.IsStackSlot()) << cls; |
| 5172 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5173 | } |
| 5174 | __ j(kNotEqual, &loop); |
| 5175 | break; |
| 5176 | } |
| 5177 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5178 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5179 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5180 | __ Bind(&loop); |
| 5181 | if (cls.IsRegister()) { |
| 5182 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5183 | } else { |
| 5184 | DCHECK(cls.IsStackSlot()) << cls; |
| 5185 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5186 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5187 | __ j(kEqual, &done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5188 | __ movl(temp, Address(temp, super_offset)); |
| 5189 | __ MaybeUnpoisonHeapReference(temp); |
| 5190 | __ testl(temp, temp); |
| 5191 | __ j(kNotEqual, &loop); |
| 5192 | // Jump to the slow path to throw the exception. |
| 5193 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5194 | break; |
| 5195 | } |
| 5196 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5197 | // Do an exact check. |
| 5198 | if (cls.IsRegister()) { |
| 5199 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5200 | } else { |
| 5201 | DCHECK(cls.IsStackSlot()) << cls; |
| 5202 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5203 | } |
| 5204 | __ j(kEqual, &done); |
| 5205 | // Otherwise, we need to check that the object's class is a non primitive array. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5206 | __ movl(temp, Address(temp, component_offset)); |
| 5207 | __ MaybeUnpoisonHeapReference(temp); |
| 5208 | __ testl(temp, temp); |
| 5209 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5210 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5211 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5212 | break; |
| 5213 | } |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5214 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5215 | case TypeCheckKind::kInterfaceCheck: |
| 5216 | default: |
| 5217 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 5218 | instruction, |
| 5219 | instruction->GetDexPc(), |
| 5220 | nullptr); |
| 5221 | break; |
| 5222 | } |
| 5223 | __ Bind(&done); |
| 5224 | |
| 5225 | if (slow_path != nullptr) { |
| 5226 | __ Bind(slow_path->GetExitLabel()); |
| 5227 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5228 | } |
| 5229 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5230 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5231 | LocationSummary* locations = |
| 5232 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5233 | InvokeRuntimeCallingConvention calling_convention; |
| 5234 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5235 | } |
| 5236 | |
| 5237 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5238 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 5239 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 5240 | instruction, |
| 5241 | instruction->GetDexPc(), |
| 5242 | nullptr); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5243 | } |
| 5244 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5245 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 5246 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 5247 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 5248 | |
| 5249 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5250 | LocationSummary* locations = |
| 5251 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5252 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 5253 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 5254 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5255 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5256 | locations->SetOut(Location::SameAsFirstInput()); |
| 5257 | } |
| 5258 | |
| 5259 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 5260 | HandleBitwiseOperation(instruction); |
| 5261 | } |
| 5262 | |
| 5263 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 5264 | HandleBitwiseOperation(instruction); |
| 5265 | } |
| 5266 | |
| 5267 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 5268 | HandleBitwiseOperation(instruction); |
| 5269 | } |
| 5270 | |
| 5271 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5272 | LocationSummary* locations = instruction->GetLocations(); |
| 5273 | Location first = locations->InAt(0); |
| 5274 | Location second = locations->InAt(1); |
| 5275 | DCHECK(first.Equals(locations->Out())); |
| 5276 | |
| 5277 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 5278 | if (second.IsRegister()) { |
| 5279 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5280 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5281 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5282 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5283 | } else { |
| 5284 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5285 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5286 | } |
| 5287 | } else if (second.IsConstant()) { |
| 5288 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 5289 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5290 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5291 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5292 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5293 | } else { |
| 5294 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5295 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5296 | } |
| 5297 | } else { |
| 5298 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 5299 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5300 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5301 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5302 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5303 | } else { |
| 5304 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5305 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5306 | } |
| 5307 | } |
| 5308 | } else { |
| 5309 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5310 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 5311 | bool second_is_constant = false; |
| 5312 | int64_t value = 0; |
| 5313 | if (second.IsConstant()) { |
| 5314 | second_is_constant = true; |
| 5315 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5316 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5317 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5318 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5319 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5320 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5321 | if (is_int32_value) { |
| 5322 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 5323 | } else { |
| 5324 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 5325 | } |
| 5326 | } else if (second.IsDoubleStackSlot()) { |
| 5327 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5328 | } else { |
| 5329 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 5330 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5331 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5332 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5333 | if (is_int32_value) { |
| 5334 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 5335 | } else { |
| 5336 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 5337 | } |
| 5338 | } else if (second.IsDoubleStackSlot()) { |
| 5339 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5340 | } else { |
| 5341 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 5342 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5343 | } else { |
| 5344 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5345 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5346 | if (is_int32_value) { |
| 5347 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 5348 | } else { |
| 5349 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 5350 | } |
| 5351 | } else if (second.IsDoubleStackSlot()) { |
| 5352 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5353 | } else { |
| 5354 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 5355 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5356 | } |
| 5357 | } |
| 5358 | } |
| 5359 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5360 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5361 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5362 | LOG(FATAL) << "Unreachable"; |
| 5363 | } |
| 5364 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5365 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5366 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5367 | LOG(FATAL) << "Unreachable"; |
| 5368 | } |
| 5369 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5370 | void LocationsBuilderX86_64::VisitFakeString(HFakeString* instruction) { |
| 5371 | DCHECK(codegen_->IsBaseline()); |
| 5372 | LocationSummary* locations = |
| 5373 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5374 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 5375 | } |
| 5376 | |
| 5377 | void InstructionCodeGeneratorX86_64::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 5378 | DCHECK(codegen_->IsBaseline()); |
| 5379 | // Will be generated at use site. |
| 5380 | } |
| 5381 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5382 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5383 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5384 | LocationSummary* locations = |
| 5385 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 5386 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 5387 | locations->AddTemp(Location::RequiresRegister()); |
| 5388 | locations->AddTemp(Location::RequiresRegister()); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5389 | } |
| 5390 | |
| 5391 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5392 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 5393 | int32_t num_entries = switch_instr->GetNumEntries(); |
| 5394 | LocationSummary* locations = switch_instr->GetLocations(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 5395 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5396 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 5397 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 5398 | |
| 5399 | // Remove the bias, if needed. |
| 5400 | Register value_reg_out = value_reg_in.AsRegister(); |
| 5401 | if (lower_bound != 0) { |
| 5402 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 5403 | value_reg_out = temp_reg.AsRegister(); |
| 5404 | } |
| 5405 | CpuRegister value_reg(value_reg_out); |
| 5406 | |
| 5407 | // Is the value in range? |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5408 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 5409 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 5410 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5411 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 5412 | // We are in the range of the table. |
| 5413 | // Load the address of the jump table in the constant area. |
| 5414 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5415 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 5416 | // Load the (signed) offset from the jump table. |
| 5417 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 5418 | |
| 5419 | // Add the offset to the address of the table base. |
| 5420 | __ addq(temp_reg, base_reg); |
| 5421 | |
| 5422 | // And jump. |
| 5423 | __ jmp(temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5424 | } |
| 5425 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5426 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 5427 | if (value == 0) { |
| 5428 | __ xorl(dest, dest); |
| 5429 | } else if (value > 0 && IsInt<32>(value)) { |
| 5430 | // We can use a 32 bit move, as it will zero-extend and is one byte shorter. |
| 5431 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 5432 | } else { |
| 5433 | __ movq(dest, Immediate(value)); |
| 5434 | } |
| 5435 | } |
| 5436 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5437 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 5438 | DCHECK(dest.IsDoubleStackSlot()); |
| 5439 | if (IsInt<32>(value)) { |
| 5440 | // Can move directly as an int32 constant. |
| 5441 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 5442 | Immediate(static_cast<int32_t>(value))); |
| 5443 | } else { |
| 5444 | Load64BitValue(CpuRegister(TMP), value); |
| 5445 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 5446 | } |
| 5447 | } |
| 5448 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 5449 | /** |
| 5450 | * Class to handle late fixup of offsets into constant area. |
| 5451 | */ |
| 5452 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 5453 | public: |
| 5454 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 5455 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 5456 | |
| 5457 | protected: |
| 5458 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 5459 | |
| 5460 | CodeGeneratorX86_64* codegen_; |
| 5461 | |
| 5462 | private: |
| 5463 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 5464 | // Patch the correct offset for the instruction. We use the address of the |
| 5465 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 5466 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 5467 | int32_t relative_position = constant_offset - pos; |
| 5468 | |
| 5469 | // Patch in the right value. |
| 5470 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 5471 | } |
| 5472 | |
| 5473 | // Location in constant area that the fixup refers to. |
| 5474 | size_t offset_into_constant_area_; |
| 5475 | }; |
| 5476 | |
| 5477 | /** |
| 5478 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 5479 | * constant area. |
| 5480 | */ |
| 5481 | class JumpTableRIPFixup : public RIPFixup { |
| 5482 | public: |
| 5483 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 5484 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 5485 | |
| 5486 | void CreateJumpTable() { |
| 5487 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 5488 | |
| 5489 | // Ensure that the reference to the jump table has the correct offset. |
| 5490 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 5491 | SetOffset(offset_in_constant_table); |
| 5492 | |
| 5493 | // Compute the offset from the start of the function to this jump table. |
| 5494 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 5495 | |
| 5496 | // Populate the jump table with the correct values for the jump table. |
| 5497 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 5498 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 5499 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 5500 | // The value that we want is the target offset - the position of the table. |
| 5501 | for (int32_t i = 0; i < num_entries; i++) { |
| 5502 | HBasicBlock* b = successors[i]; |
| 5503 | Label* l = codegen_->GetLabelOf(b); |
| 5504 | DCHECK(l->IsBound()); |
| 5505 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 5506 | assembler->AppendInt32(offset_to_block); |
| 5507 | } |
| 5508 | } |
| 5509 | |
| 5510 | private: |
| 5511 | const HPackedSwitch* switch_instr_; |
| 5512 | }; |
| 5513 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 5514 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 5515 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 5516 | X86_64Assembler* assembler = GetAssembler(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 5517 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 5518 | // 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] | 5519 | assembler->Align(4, 0); |
| 5520 | constant_area_start_ = assembler->CodeSize(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 5521 | |
| 5522 | // Populate any jump tables. |
| 5523 | for (auto jump_table : fixups_to_jump_tables_) { |
| 5524 | jump_table->CreateJumpTable(); |
| 5525 | } |
| 5526 | |
| 5527 | // And now add the constant area to the generated code. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 5528 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 5529 | } |
| 5530 | |
| 5531 | // And finish up. |
| 5532 | CodeGenerator::Finalize(allocator); |
| 5533 | } |
| 5534 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 5535 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 5536 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 5537 | return Address::RIP(fixup); |
| 5538 | } |
| 5539 | |
| 5540 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 5541 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 5542 | return Address::RIP(fixup); |
| 5543 | } |
| 5544 | |
| 5545 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 5546 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 5547 | return Address::RIP(fixup); |
| 5548 | } |
| 5549 | |
| 5550 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 5551 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 5552 | return Address::RIP(fixup); |
| 5553 | } |
| 5554 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5555 | // TODO: trg as memory. |
| 5556 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 5557 | if (!trg.IsValid()) { |
| 5558 | DCHECK(type == Primitive::kPrimVoid); |
| 5559 | return; |
| 5560 | } |
| 5561 | |
| 5562 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 5563 | |
| 5564 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 5565 | if (trg.Equals(return_loc)) { |
| 5566 | return; |
| 5567 | } |
| 5568 | |
| 5569 | // Let the parallel move resolver take care of all of this. |
| 5570 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 5571 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 5572 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 5573 | } |
| 5574 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 5575 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 5576 | // Create a fixup to be used to create and address the jump table. |
| 5577 | JumpTableRIPFixup* table_fixup = |
| 5578 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 5579 | |
| 5580 | // We have to populate the jump tables. |
| 5581 | fixups_to_jump_tables_.push_back(table_fixup); |
| 5582 | return Address::RIP(table_fixup); |
| 5583 | } |
| 5584 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5585 | #undef __ |
| 5586 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5587 | } // namespace x86_64 |
| 5588 | } // namespace art |