Alexandre Rames | 5319def | 2014-10-23 10:03: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_arm64.h" |
| 18 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 19 | #include "arch/arm64/instruction_set_features_arm64.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 20 | #include "code_generator_utils.h" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 21 | #include "common_arm64.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 25 | #include "intrinsics.h" |
| 26 | #include "intrinsics_arm64.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 27 | #include "mirror/array-inl.h" |
| 28 | #include "mirror/art_method.h" |
| 29 | #include "mirror/class.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 30 | #include "offsets.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 31 | #include "thread.h" |
| 32 | #include "utils/arm64/assembler_arm64.h" |
| 33 | #include "utils/assembler.h" |
| 34 | #include "utils/stack_checks.h" |
| 35 | |
| 36 | |
| 37 | using namespace vixl; // NOLINT(build/namespaces) |
| 38 | |
| 39 | #ifdef __ |
| 40 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 41 | #endif |
| 42 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 43 | namespace art { |
| 44 | |
| 45 | namespace arm64 { |
| 46 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 47 | using helpers::CPURegisterFrom; |
| 48 | using helpers::DRegisterFrom; |
| 49 | using helpers::FPRegisterFrom; |
| 50 | using helpers::HeapOperand; |
| 51 | using helpers::HeapOperandFrom; |
| 52 | using helpers::InputCPURegisterAt; |
| 53 | using helpers::InputFPRegisterAt; |
| 54 | using helpers::InputRegisterAt; |
| 55 | using helpers::InputOperandAt; |
| 56 | using helpers::Int64ConstantFrom; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 57 | using helpers::LocationFrom; |
| 58 | using helpers::OperandFromMemOperand; |
| 59 | using helpers::OutputCPURegister; |
| 60 | using helpers::OutputFPRegister; |
| 61 | using helpers::OutputRegister; |
| 62 | using helpers::RegisterFrom; |
| 63 | using helpers::StackOperandFrom; |
| 64 | using helpers::VIXLRegCodeFromART; |
| 65 | using helpers::WRegisterFrom; |
| 66 | using helpers::XRegisterFrom; |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 67 | using helpers::ARM64EncodableConstantOrRegister; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 68 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 69 | static constexpr size_t kHeapRefSize = sizeof(mirror::HeapReference<mirror::Object>); |
| 70 | static constexpr int kCurrentMethodStackOffset = 0; |
| 71 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 72 | inline Condition ARM64Condition(IfCondition cond) { |
| 73 | switch (cond) { |
| 74 | case kCondEQ: return eq; |
| 75 | case kCondNE: return ne; |
| 76 | case kCondLT: return lt; |
| 77 | case kCondLE: return le; |
| 78 | case kCondGT: return gt; |
| 79 | case kCondGE: return ge; |
| 80 | default: |
| 81 | LOG(FATAL) << "Unknown if condition"; |
| 82 | } |
| 83 | return nv; // Unreachable. |
| 84 | } |
| 85 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 86 | Location ARM64ReturnLocation(Primitive::Type return_type) { |
| 87 | DCHECK_NE(return_type, Primitive::kPrimVoid); |
| 88 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 89 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 90 | // but we use the exact registers for clarity. |
| 91 | if (return_type == Primitive::kPrimFloat) { |
| 92 | return LocationFrom(s0); |
| 93 | } else if (return_type == Primitive::kPrimDouble) { |
| 94 | return LocationFrom(d0); |
| 95 | } else if (return_type == Primitive::kPrimLong) { |
| 96 | return LocationFrom(x0); |
| 97 | } else { |
| 98 | return LocationFrom(w0); |
| 99 | } |
| 100 | } |
| 101 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 102 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 103 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 104 | } |
| 105 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 106 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> |
| 107 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 108 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 109 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 110 | public: |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 111 | BoundsCheckSlowPathARM64(HBoundsCheck* instruction, |
| 112 | Location index_location, |
| 113 | Location length_location) |
| 114 | : instruction_(instruction), |
| 115 | index_location_(index_location), |
| 116 | length_location_(length_location) {} |
| 117 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 118 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 119 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 120 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 121 | __ Bind(GetEntryLabel()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 122 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 123 | // move resolver. |
| 124 | InvokeRuntimeCallingConvention calling_convention; |
| 125 | codegen->EmitParallelMoves( |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 126 | index_location_, LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt, |
| 127 | length_location_, LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 128 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 129 | QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 130 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | private: |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 134 | HBoundsCheck* const instruction_; |
| 135 | const Location index_location_; |
| 136 | const Location length_location_; |
| 137 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 138 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 139 | }; |
| 140 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 141 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 142 | public: |
| 143 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 144 | |
| 145 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 146 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 147 | __ Bind(GetEntryLabel()); |
| 148 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 149 | QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 150 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | private: |
| 154 | HDivZeroCheck* const instruction_; |
| 155 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 156 | }; |
| 157 | |
| 158 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 159 | public: |
| 160 | LoadClassSlowPathARM64(HLoadClass* cls, |
| 161 | HInstruction* at, |
| 162 | uint32_t dex_pc, |
| 163 | bool do_clinit) |
| 164 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 165 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 166 | } |
| 167 | |
| 168 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 169 | LocationSummary* locations = at_->GetLocations(); |
| 170 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 171 | |
| 172 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 173 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 174 | |
| 175 | InvokeRuntimeCallingConvention calling_convention; |
| 176 | __ Mov(calling_convention.GetRegisterAt(0).W(), cls_->GetTypeIndex()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 177 | int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 178 | : QUICK_ENTRY_POINT(pInitializeType); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 179 | arm64_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 180 | if (do_clinit_) { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 181 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 182 | } else { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 183 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 184 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 185 | |
| 186 | // Move the class to the desired location. |
| 187 | Location out = locations->Out(); |
| 188 | if (out.IsValid()) { |
| 189 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 190 | Primitive::Type type = at_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 191 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 194 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 195 | __ B(GetExitLabel()); |
| 196 | } |
| 197 | |
| 198 | private: |
| 199 | // The class this slow path will load. |
| 200 | HLoadClass* const cls_; |
| 201 | |
| 202 | // The instruction where this slow path is happening. |
| 203 | // (Might be the load class or an initialization check). |
| 204 | HInstruction* const at_; |
| 205 | |
| 206 | // The dex PC of `at_`. |
| 207 | const uint32_t dex_pc_; |
| 208 | |
| 209 | // Whether to initialize the class. |
| 210 | const bool do_clinit_; |
| 211 | |
| 212 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 213 | }; |
| 214 | |
| 215 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 216 | public: |
| 217 | explicit LoadStringSlowPathARM64(HLoadString* instruction) : instruction_(instruction) {} |
| 218 | |
| 219 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 220 | LocationSummary* locations = instruction_->GetLocations(); |
| 221 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 222 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 223 | |
| 224 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 225 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 226 | |
| 227 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 228 | __ Mov(calling_convention.GetRegisterAt(0).W(), instruction_->GetStringIndex()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 229 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 230 | QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 231 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 232 | Primitive::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 233 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 234 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 235 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 236 | __ B(GetExitLabel()); |
| 237 | } |
| 238 | |
| 239 | private: |
| 240 | HLoadString* const instruction_; |
| 241 | |
| 242 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 243 | }; |
| 244 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 245 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 246 | public: |
| 247 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : instruction_(instr) {} |
| 248 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 249 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 250 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 251 | __ Bind(GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 252 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 253 | QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 254 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | private: |
| 258 | HNullCheck* const instruction_; |
| 259 | |
| 260 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 261 | }; |
| 262 | |
| 263 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 264 | public: |
| 265 | explicit SuspendCheckSlowPathARM64(HSuspendCheck* instruction, |
| 266 | HBasicBlock* successor) |
| 267 | : instruction_(instruction), successor_(successor) {} |
| 268 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 269 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 270 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 271 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 272 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 273 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 274 | QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 275 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 276 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 277 | if (successor_ == nullptr) { |
| 278 | __ B(GetReturnLabel()); |
| 279 | } else { |
| 280 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 281 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | vixl::Label* GetReturnLabel() { |
| 285 | DCHECK(successor_ == nullptr); |
| 286 | return &return_label_; |
| 287 | } |
| 288 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 289 | HBasicBlock* GetSuccessor() const { |
| 290 | return successor_; |
| 291 | } |
| 292 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 293 | private: |
| 294 | HSuspendCheck* const instruction_; |
| 295 | // If not null, the block to branch to after the suspend check. |
| 296 | HBasicBlock* const successor_; |
| 297 | |
| 298 | // If `successor_` is null, the label to branch to after the suspend check. |
| 299 | vixl::Label return_label_; |
| 300 | |
| 301 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 302 | }; |
| 303 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 304 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 305 | public: |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 306 | TypeCheckSlowPathARM64(HInstruction* instruction, |
| 307 | Location class_to_check, |
| 308 | Location object_class, |
| 309 | uint32_t dex_pc) |
| 310 | : instruction_(instruction), |
| 311 | class_to_check_(class_to_check), |
| 312 | object_class_(object_class), |
| 313 | dex_pc_(dex_pc) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 314 | |
| 315 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 316 | LocationSummary* locations = instruction_->GetLocations(); |
| 317 | DCHECK(instruction_->IsCheckCast() |
| 318 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 319 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 320 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 321 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 322 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 323 | |
| 324 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 325 | // move resolver. |
| 326 | InvokeRuntimeCallingConvention calling_convention; |
| 327 | codegen->EmitParallelMoves( |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 328 | class_to_check_, LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimNot, |
| 329 | object_class_, LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimNot); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 330 | |
| 331 | if (instruction_->IsInstanceOf()) { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 332 | arm64_codegen->InvokeRuntime( |
| 333 | QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_, this); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 334 | Primitive::Type ret_type = instruction_->GetType(); |
| 335 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 336 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 337 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, uint32_t, |
| 338 | const mirror::Class*, const mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 339 | } else { |
| 340 | DCHECK(instruction_->IsCheckCast()); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 341 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 342 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 345 | RestoreLiveRegisters(codegen, locations); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 346 | __ B(GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | private: |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 350 | HInstruction* const instruction_; |
| 351 | const Location class_to_check_; |
| 352 | const Location object_class_; |
| 353 | uint32_t dex_pc_; |
| 354 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 355 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 356 | }; |
| 357 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 358 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 359 | public: |
| 360 | explicit DeoptimizationSlowPathARM64(HInstruction* instruction) |
| 361 | : instruction_(instruction) {} |
| 362 | |
| 363 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 364 | __ Bind(GetEntryLabel()); |
| 365 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 366 | DCHECK(instruction_->IsDeoptimize()); |
| 367 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); |
| 368 | uint32_t dex_pc = deoptimize->GetDexPc(); |
| 369 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 370 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this); |
| 371 | } |
| 372 | |
| 373 | private: |
| 374 | HInstruction* const instruction_; |
| 375 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 376 | }; |
| 377 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 378 | #undef __ |
| 379 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 380 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 381 | Location next_location; |
| 382 | if (type == Primitive::kPrimVoid) { |
| 383 | LOG(FATAL) << "Unreachable type " << type; |
| 384 | } |
| 385 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 386 | if (Primitive::IsFloatingPointType(type) && |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 387 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 388 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 389 | } else if (!Primitive::IsFloatingPointType(type) && |
| 390 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 391 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 392 | } else { |
| 393 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 394 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 395 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 396 | } |
| 397 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 398 | // Space on the stack is reserved for all arguments. |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 399 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 400 | return next_location; |
| 401 | } |
| 402 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 403 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 404 | const Arm64InstructionSetFeatures& isa_features, |
| 405 | const CompilerOptions& compiler_options) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 406 | : CodeGenerator(graph, |
| 407 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 408 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 409 | kNumberOfAllocatableRegisterPairs, |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 410 | callee_saved_core_registers.list(), |
| 411 | callee_saved_fp_registers.list(), |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 412 | compiler_options), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 413 | block_labels_(nullptr), |
| 414 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 415 | instruction_visitor_(graph, this), |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 416 | move_resolver_(graph->GetArena(), this), |
| 417 | isa_features_(isa_features) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 418 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 419 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 420 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 421 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 422 | #undef __ |
| 423 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 424 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 425 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
| 426 | // Ensure we emit the literal pool. |
| 427 | __ FinalizeCode(); |
| 428 | CodeGenerator::Finalize(allocator); |
| 429 | } |
| 430 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 431 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 432 | // Note: There are 6 kinds of moves: |
| 433 | // 1. constant -> GPR/FPR (non-cycle) |
| 434 | // 2. constant -> stack (non-cycle) |
| 435 | // 3. GPR/FPR -> GPR/FPR |
| 436 | // 4. GPR/FPR -> stack |
| 437 | // 5. stack -> GPR/FPR |
| 438 | // 6. stack -> stack (non-cycle) |
| 439 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 440 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 441 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 442 | // dependency. |
| 443 | vixl_temps_.Open(GetVIXLAssembler()); |
| 444 | } |
| 445 | |
| 446 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 447 | vixl_temps_.Close(); |
| 448 | } |
| 449 | |
| 450 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
| 451 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister || |
| 452 | kind == Location::kStackSlot || kind == Location::kDoubleStackSlot); |
| 453 | kind = (kind == Location::kFpuRegister) ? Location::kFpuRegister : Location::kRegister; |
| 454 | Location scratch = GetScratchLocation(kind); |
| 455 | if (!scratch.Equals(Location::NoLocation())) { |
| 456 | return scratch; |
| 457 | } |
| 458 | // Allocate from VIXL temp registers. |
| 459 | if (kind == Location::kRegister) { |
| 460 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 461 | } else { |
| 462 | DCHECK(kind == Location::kFpuRegister); |
| 463 | scratch = LocationFrom(vixl_temps_.AcquireD()); |
| 464 | } |
| 465 | AddScratchLocation(scratch); |
| 466 | return scratch; |
| 467 | } |
| 468 | |
| 469 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 470 | if (loc.IsRegister()) { |
| 471 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 472 | } else { |
| 473 | DCHECK(loc.IsFpuRegister()); |
| 474 | vixl_temps_.Release(DRegisterFrom(loc)); |
| 475 | } |
| 476 | RemoveScratchLocation(loc); |
| 477 | } |
| 478 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 479 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
| 480 | MoveOperands* move = moves_.Get(index); |
| 481 | codegen_->MoveLocation(move->GetDestination(), move->GetSource()); |
| 482 | } |
| 483 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 484 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 485 | MacroAssembler* masm = GetVIXLAssembler(); |
| 486 | BlockPoolsScope block_pools(masm); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 487 | __ Bind(&frame_entry_label_); |
| 488 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 489 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod(); |
| 490 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 491 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 492 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 493 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 494 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 495 | __ Ldr(wzr, MemOperand(temp, 0)); |
| 496 | RecordPcInfo(nullptr, 0); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 497 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 498 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 499 | if (!HasEmptyFrame()) { |
| 500 | int frame_size = GetFrameSize(); |
| 501 | // Stack layout: |
| 502 | // sp[frame_size - 8] : lr. |
| 503 | // ... : other preserved core registers. |
| 504 | // ... : other preserved fp registers. |
| 505 | // ... : reserved frame space. |
| 506 | // sp[0] : current method. |
| 507 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 508 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 509 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 510 | frame_size - GetCoreSpillSize()); |
| 511 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 512 | frame_size - FrameEntrySpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 513 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | void CodeGeneratorARM64::GenerateFrameExit() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 517 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 518 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 519 | if (!HasEmptyFrame()) { |
| 520 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 521 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 522 | frame_size - FrameEntrySpillSize()); |
| 523 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 524 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 525 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 526 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 527 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 528 | __ Ret(); |
| 529 | GetAssembler()->cfi().RestoreState(); |
| 530 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 534 | __ Bind(GetLabelOf(block)); |
| 535 | } |
| 536 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 537 | void CodeGeneratorARM64::Move(HInstruction* instruction, |
| 538 | Location location, |
| 539 | HInstruction* move_for) { |
| 540 | LocationSummary* locations = instruction->GetLocations(); |
| 541 | if (locations != nullptr && locations->Out().Equals(location)) { |
| 542 | return; |
| 543 | } |
| 544 | |
| 545 | Primitive::Type type = instruction->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 546 | DCHECK_NE(type, Primitive::kPrimVoid); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 547 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 548 | if (instruction->IsIntConstant() |
| 549 | || instruction->IsLongConstant() |
| 550 | || instruction->IsNullConstant()) { |
| 551 | int64_t value = GetInt64ValueOf(instruction->AsConstant()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 552 | if (location.IsRegister()) { |
| 553 | Register dst = RegisterFrom(location, type); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 554 | DCHECK(((instruction->IsIntConstant() || instruction->IsNullConstant()) && dst.Is32Bits()) || |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 555 | (instruction->IsLongConstant() && dst.Is64Bits())); |
| 556 | __ Mov(dst, value); |
| 557 | } else { |
| 558 | DCHECK(location.IsStackSlot() || location.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 559 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 560 | Register temp = (instruction->IsIntConstant() || instruction->IsNullConstant()) |
| 561 | ? temps.AcquireW() |
| 562 | : temps.AcquireX(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 563 | __ Mov(temp, value); |
| 564 | __ Str(temp, StackOperandFrom(location)); |
| 565 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 566 | } else if (instruction->IsTemporary()) { |
| 567 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 568 | MoveLocation(location, temp_location, type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 569 | } else if (instruction->IsLoadLocal()) { |
| 570 | uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 571 | if (Primitive::Is64BitType(type)) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 572 | MoveLocation(location, Location::DoubleStackSlot(stack_slot), type); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 573 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 574 | MoveLocation(location, Location::StackSlot(stack_slot), type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | } else { |
| 578 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 579 | MoveLocation(location, locations->Out(), type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 580 | } |
| 581 | } |
| 582 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 583 | Location CodeGeneratorARM64::GetStackLocation(HLoadLocal* load) const { |
| 584 | Primitive::Type type = load->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 585 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 586 | switch (type) { |
| 587 | case Primitive::kPrimNot: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 588 | case Primitive::kPrimInt: |
| 589 | case Primitive::kPrimFloat: |
| 590 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
| 591 | |
| 592 | case Primitive::kPrimLong: |
| 593 | case Primitive::kPrimDouble: |
| 594 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
| 595 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 596 | case Primitive::kPrimBoolean: |
| 597 | case Primitive::kPrimByte: |
| 598 | case Primitive::kPrimChar: |
| 599 | case Primitive::kPrimShort: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 600 | case Primitive::kPrimVoid: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 601 | LOG(FATAL) << "Unexpected type " << type; |
| 602 | } |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 603 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 604 | LOG(FATAL) << "Unreachable"; |
| 605 | return Location::NoLocation(); |
| 606 | } |
| 607 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame^] | 608 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 609 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 610 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 611 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 612 | vixl::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame^] | 613 | if (value_can_be_null) { |
| 614 | __ Cbz(value, &done); |
| 615 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 616 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64WordSize>().Int32Value())); |
| 617 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 618 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame^] | 619 | if (value_can_be_null) { |
| 620 | __ Bind(&done); |
| 621 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 622 | } |
| 623 | |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 624 | void CodeGeneratorARM64::SetupBlockedRegisters(bool is_baseline) const { |
| 625 | // Blocked core registers: |
| 626 | // lr : Runtime reserved. |
| 627 | // tr : Runtime reserved. |
| 628 | // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it. |
| 629 | // ip1 : VIXL core temp. |
| 630 | // ip0 : VIXL core temp. |
| 631 | // |
| 632 | // Blocked fp registers: |
| 633 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 634 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 635 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 636 | while (!reserved_core_registers.IsEmpty()) { |
| 637 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().code()] = true; |
| 638 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 639 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 640 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 641 | while (!reserved_fp_registers.IsEmpty()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 642 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().code()] = true; |
| 643 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 644 | |
| 645 | if (is_baseline) { |
| 646 | CPURegList reserved_core_baseline_registers = callee_saved_core_registers; |
| 647 | while (!reserved_core_baseline_registers.IsEmpty()) { |
| 648 | blocked_core_registers_[reserved_core_baseline_registers.PopLowestIndex().code()] = true; |
| 649 | } |
| 650 | |
| 651 | CPURegList reserved_fp_baseline_registers = callee_saved_fp_registers; |
| 652 | while (!reserved_fp_baseline_registers.IsEmpty()) { |
| 653 | blocked_fpu_registers_[reserved_fp_baseline_registers.PopLowestIndex().code()] = true; |
| 654 | } |
| 655 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | Location CodeGeneratorARM64::AllocateFreeRegister(Primitive::Type type) const { |
| 659 | if (type == Primitive::kPrimVoid) { |
| 660 | LOG(FATAL) << "Unreachable type " << type; |
| 661 | } |
| 662 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 663 | if (Primitive::IsFloatingPointType(type)) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 664 | ssize_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfAllocatableFPRegisters); |
| 665 | DCHECK_NE(reg, -1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 666 | return Location::FpuRegisterLocation(reg); |
| 667 | } else { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 668 | ssize_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfAllocatableRegisters); |
| 669 | DCHECK_NE(reg, -1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 670 | return Location::RegisterLocation(reg); |
| 671 | } |
| 672 | } |
| 673 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 674 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 675 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 676 | __ Str(reg, MemOperand(sp, stack_index)); |
| 677 | return kArm64WordSize; |
| 678 | } |
| 679 | |
| 680 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 681 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 682 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 683 | return kArm64WordSize; |
| 684 | } |
| 685 | |
| 686 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 687 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 688 | __ Str(reg, MemOperand(sp, stack_index)); |
| 689 | return kArm64WordSize; |
| 690 | } |
| 691 | |
| 692 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 693 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 694 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 695 | return kArm64WordSize; |
| 696 | } |
| 697 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 698 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 699 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 703 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 704 | } |
| 705 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 706 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 707 | if (constant->IsIntConstant()) { |
| 708 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 709 | } else if (constant->IsLongConstant()) { |
| 710 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 711 | } else if (constant->IsNullConstant()) { |
| 712 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 713 | } else if (constant->IsFloatConstant()) { |
| 714 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 715 | } else { |
| 716 | DCHECK(constant->IsDoubleConstant()); |
| 717 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 718 | } |
| 719 | } |
| 720 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 721 | |
| 722 | static bool CoherentConstantAndType(Location constant, Primitive::Type type) { |
| 723 | DCHECK(constant.IsConstant()); |
| 724 | HConstant* cst = constant.GetConstant(); |
| 725 | return (cst->IsIntConstant() && type == Primitive::kPrimInt) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 726 | // Null is mapped to a core W register, which we associate with kPrimInt. |
| 727 | (cst->IsNullConstant() && type == Primitive::kPrimInt) || |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 728 | (cst->IsLongConstant() && type == Primitive::kPrimLong) || |
| 729 | (cst->IsFloatConstant() && type == Primitive::kPrimFloat) || |
| 730 | (cst->IsDoubleConstant() && type == Primitive::kPrimDouble); |
| 731 | } |
| 732 | |
| 733 | void CodeGeneratorARM64::MoveLocation(Location destination, Location source, Primitive::Type type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 734 | if (source.Equals(destination)) { |
| 735 | return; |
| 736 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 737 | |
| 738 | // A valid move can always be inferred from the destination and source |
| 739 | // locations. When moving from and to a register, the argument type can be |
| 740 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 741 | // checks the coherency of the locations and the type. |
| 742 | bool unspecified_type = (type == Primitive::kPrimVoid); |
| 743 | |
| 744 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 745 | if (unspecified_type) { |
| 746 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 747 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 748 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 749 | || src_cst->IsFloatConstant() |
| 750 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 751 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
| 752 | type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 753 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 754 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 755 | // type is appropriate. Else the source is a register, and since the |
| 756 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 757 | // move. |
| 758 | type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 759 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 760 | } |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 761 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(type)) || |
| 762 | (destination.IsRegister() && !Primitive::IsFloatingPointType(type))); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 763 | CPURegister dst = CPURegisterFrom(destination, type); |
| 764 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 765 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 766 | __ Ldr(dst, StackOperandFrom(source)); |
| 767 | } else if (source.IsConstant()) { |
| 768 | DCHECK(CoherentConstantAndType(source, type)); |
| 769 | MoveConstant(dst, source.GetConstant()); |
| 770 | } else { |
| 771 | if (destination.IsRegister()) { |
| 772 | __ Mov(Register(dst), RegisterFrom(source, type)); |
| 773 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 774 | DCHECK(destination.IsFpuRegister()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 775 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, type)); |
| 776 | } |
| 777 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 778 | } else { // The destination is not a register. It must be a stack slot. |
| 779 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 780 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 781 | if (unspecified_type) { |
| 782 | if (source.IsRegister()) { |
| 783 | type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
| 784 | } else { |
| 785 | type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
| 786 | } |
| 787 | } |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 788 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(type)) && |
| 789 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(type))); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 790 | __ Str(CPURegisterFrom(source, type), StackOperandFrom(destination)); |
| 791 | } else if (source.IsConstant()) { |
| 792 | DCHECK(unspecified_type || CoherentConstantAndType(source, type)); |
| 793 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 794 | HConstant* src_cst = source.GetConstant(); |
| 795 | CPURegister temp; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 796 | if (src_cst->IsIntConstant() || src_cst->IsNullConstant()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 797 | temp = temps.AcquireW(); |
| 798 | } else if (src_cst->IsLongConstant()) { |
| 799 | temp = temps.AcquireX(); |
| 800 | } else if (src_cst->IsFloatConstant()) { |
| 801 | temp = temps.AcquireS(); |
| 802 | } else { |
| 803 | DCHECK(src_cst->IsDoubleConstant()); |
| 804 | temp = temps.AcquireD(); |
| 805 | } |
| 806 | MoveConstant(temp, src_cst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 807 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 808 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 809 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 810 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 811 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 812 | // There is generally less pressure on FP registers. |
| 813 | FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 814 | __ Ldr(temp, StackOperandFrom(source)); |
| 815 | __ Str(temp, StackOperandFrom(destination)); |
| 816 | } |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | void CodeGeneratorARM64::Load(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 821 | CPURegister dst, |
| 822 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 823 | switch (type) { |
| 824 | case Primitive::kPrimBoolean: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 825 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 826 | break; |
| 827 | case Primitive::kPrimByte: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 828 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 829 | break; |
| 830 | case Primitive::kPrimShort: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 831 | __ Ldrsh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 832 | break; |
| 833 | case Primitive::kPrimChar: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 834 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 835 | break; |
| 836 | case Primitive::kPrimInt: |
| 837 | case Primitive::kPrimNot: |
| 838 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 839 | case Primitive::kPrimFloat: |
| 840 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 841 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 842 | __ Ldr(dst, src); |
| 843 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 844 | case Primitive::kPrimVoid: |
| 845 | LOG(FATAL) << "Unreachable type " << type; |
| 846 | } |
| 847 | } |
| 848 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 849 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 850 | CPURegister dst, |
| 851 | const MemOperand& src) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 852 | MacroAssembler* masm = GetVIXLAssembler(); |
| 853 | BlockPoolsScope block_pools(masm); |
| 854 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 855 | Register temp_base = temps.AcquireX(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 856 | Primitive::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 857 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 858 | DCHECK(!src.IsPreIndex()); |
| 859 | DCHECK(!src.IsPostIndex()); |
| 860 | |
| 861 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 862 | __ Add(temp_base, src.base(), OperandFromMemOperand(src)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 863 | MemOperand base = MemOperand(temp_base); |
| 864 | switch (type) { |
| 865 | case Primitive::kPrimBoolean: |
| 866 | __ Ldarb(Register(dst), base); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 867 | MaybeRecordImplicitNullCheck(instruction); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 868 | break; |
| 869 | case Primitive::kPrimByte: |
| 870 | __ Ldarb(Register(dst), base); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 871 | MaybeRecordImplicitNullCheck(instruction); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 872 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 873 | break; |
| 874 | case Primitive::kPrimChar: |
| 875 | __ Ldarh(Register(dst), base); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 876 | MaybeRecordImplicitNullCheck(instruction); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 877 | break; |
| 878 | case Primitive::kPrimShort: |
| 879 | __ Ldarh(Register(dst), base); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 880 | MaybeRecordImplicitNullCheck(instruction); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 881 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 882 | break; |
| 883 | case Primitive::kPrimInt: |
| 884 | case Primitive::kPrimNot: |
| 885 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 886 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 887 | __ Ldar(Register(dst), base); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 888 | MaybeRecordImplicitNullCheck(instruction); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 889 | break; |
| 890 | case Primitive::kPrimFloat: |
| 891 | case Primitive::kPrimDouble: { |
| 892 | DCHECK(dst.IsFPRegister()); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 893 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 894 | |
| 895 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 896 | __ Ldar(temp, base); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 897 | MaybeRecordImplicitNullCheck(instruction); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 898 | __ Fmov(FPRegister(dst), temp); |
| 899 | break; |
| 900 | } |
| 901 | case Primitive::kPrimVoid: |
| 902 | LOG(FATAL) << "Unreachable type " << type; |
| 903 | } |
| 904 | } |
| 905 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 906 | void CodeGeneratorARM64::Store(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 907 | CPURegister src, |
| 908 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 909 | switch (type) { |
| 910 | case Primitive::kPrimBoolean: |
| 911 | case Primitive::kPrimByte: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 912 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 913 | break; |
| 914 | case Primitive::kPrimChar: |
| 915 | case Primitive::kPrimShort: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 916 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 917 | break; |
| 918 | case Primitive::kPrimInt: |
| 919 | case Primitive::kPrimNot: |
| 920 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 921 | case Primitive::kPrimFloat: |
| 922 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 923 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 924 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 925 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 926 | case Primitive::kPrimVoid: |
| 927 | LOG(FATAL) << "Unreachable type " << type; |
| 928 | } |
| 929 | } |
| 930 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 931 | void CodeGeneratorARM64::StoreRelease(Primitive::Type type, |
| 932 | CPURegister src, |
| 933 | const MemOperand& dst) { |
| 934 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 935 | Register temp_base = temps.AcquireX(); |
| 936 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 937 | DCHECK(!dst.IsPreIndex()); |
| 938 | DCHECK(!dst.IsPostIndex()); |
| 939 | |
| 940 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 941 | Operand op = OperandFromMemOperand(dst); |
| 942 | __ Add(temp_base, dst.base(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 943 | MemOperand base = MemOperand(temp_base); |
| 944 | switch (type) { |
| 945 | case Primitive::kPrimBoolean: |
| 946 | case Primitive::kPrimByte: |
| 947 | __ Stlrb(Register(src), base); |
| 948 | break; |
| 949 | case Primitive::kPrimChar: |
| 950 | case Primitive::kPrimShort: |
| 951 | __ Stlrh(Register(src), base); |
| 952 | break; |
| 953 | case Primitive::kPrimInt: |
| 954 | case Primitive::kPrimNot: |
| 955 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 956 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 957 | __ Stlr(Register(src), base); |
| 958 | break; |
| 959 | case Primitive::kPrimFloat: |
| 960 | case Primitive::kPrimDouble: { |
| 961 | DCHECK(src.IsFPRegister()); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 962 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 963 | |
| 964 | Register temp = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 965 | __ Fmov(temp, FPRegister(src)); |
| 966 | __ Stlr(temp, base); |
| 967 | break; |
| 968 | } |
| 969 | case Primitive::kPrimVoid: |
| 970 | LOG(FATAL) << "Unreachable type " << type; |
| 971 | } |
| 972 | } |
| 973 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 974 | void CodeGeneratorARM64::LoadCurrentMethod(vixl::Register current_method) { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 975 | DCHECK(RequiresCurrentMethod()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 976 | DCHECK(current_method.IsW()); |
| 977 | __ Ldr(current_method, MemOperand(sp, kCurrentMethodStackOffset)); |
| 978 | } |
| 979 | |
| 980 | void CodeGeneratorARM64::InvokeRuntime(int32_t entry_point_offset, |
| 981 | HInstruction* instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 982 | uint32_t dex_pc, |
| 983 | SlowPathCode* slow_path) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 984 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 985 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 986 | __ Blr(lr); |
Roland Levillain | 896e32d | 2015-05-05 18:07:10 +0100 | [diff] [blame] | 987 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 988 | DCHECK(instruction->IsSuspendCheck() |
| 989 | || instruction->IsBoundsCheck() |
| 990 | || instruction->IsNullCheck() |
| 991 | || instruction->IsDivZeroCheck() |
| 992 | || !IsLeafMethod()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
| 996 | vixl::Register class_reg) { |
| 997 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 998 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 999 | size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1000 | bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1001 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1002 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1003 | if (use_acquire_release) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1004 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| 1005 | __ Add(temp, class_reg, status_offset); |
| 1006 | __ Ldar(temp, HeapOperand(temp)); |
| 1007 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 1008 | __ B(lt, slow_path->GetEntryLabel()); |
| 1009 | } else { |
| 1010 | __ Ldr(temp, HeapOperand(class_reg, status_offset)); |
| 1011 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 1012 | __ B(lt, slow_path->GetEntryLabel()); |
| 1013 | __ Dmb(InnerShareable, BarrierReads); |
| 1014 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1015 | __ Bind(slow_path->GetExitLabel()); |
| 1016 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1017 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1018 | void InstructionCodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 1019 | BarrierType type = BarrierAll; |
| 1020 | |
| 1021 | switch (kind) { |
| 1022 | case MemBarrierKind::kAnyAny: |
| 1023 | case MemBarrierKind::kAnyStore: { |
| 1024 | type = BarrierAll; |
| 1025 | break; |
| 1026 | } |
| 1027 | case MemBarrierKind::kLoadAny: { |
| 1028 | type = BarrierReads; |
| 1029 | break; |
| 1030 | } |
| 1031 | case MemBarrierKind::kStoreStore: { |
| 1032 | type = BarrierWrites; |
| 1033 | break; |
| 1034 | } |
| 1035 | default: |
| 1036 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 1037 | } |
| 1038 | __ Dmb(InnerShareable, type); |
| 1039 | } |
| 1040 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1041 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1042 | HBasicBlock* successor) { |
| 1043 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1044 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 1045 | if (slow_path == nullptr) { |
| 1046 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor); |
| 1047 | instruction->SetSlowPath(slow_path); |
| 1048 | codegen_->AddSlowPath(slow_path); |
| 1049 | if (successor != nullptr) { |
| 1050 | DCHECK(successor->IsLoopHeader()); |
| 1051 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 1052 | } |
| 1053 | } else { |
| 1054 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1055 | } |
| 1056 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1057 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 1058 | Register temp = temps.AcquireW(); |
| 1059 | |
| 1060 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64WordSize>().SizeValue())); |
| 1061 | if (successor == nullptr) { |
| 1062 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 1063 | __ Bind(slow_path->GetReturnLabel()); |
| 1064 | } else { |
| 1065 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 1066 | __ B(slow_path->GetEntryLabel()); |
| 1067 | // slow_path will return to GetLabelOf(successor). |
| 1068 | } |
| 1069 | } |
| 1070 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1071 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 1072 | CodeGeneratorARM64* codegen) |
| 1073 | : HGraphVisitor(graph), |
| 1074 | assembler_(codegen->GetAssembler()), |
| 1075 | codegen_(codegen) {} |
| 1076 | |
| 1077 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \ |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1078 | /* No unimplemented IR. */ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1079 | |
| 1080 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode |
| 1081 | |
| 1082 | enum UnimplementedInstructionBreakCode { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1083 | // Using a base helps identify when we hit such breakpoints. |
| 1084 | UnimplementedInstructionBreakCodeBaseCode = 0x900, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1085 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), |
| 1086 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) |
| 1087 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION |
| 1088 | }; |
| 1089 | |
| 1090 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \ |
| 1091 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr) { \ |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1092 | UNUSED(instr); \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1093 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \ |
| 1094 | } \ |
| 1095 | void LocationsBuilderARM64::Visit##name(H##name* instr) { \ |
| 1096 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ |
| 1097 | locations->SetOut(Location::Any()); \ |
| 1098 | } |
| 1099 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) |
| 1100 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS |
| 1101 | |
| 1102 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1103 | #undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1104 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1105 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1106 | DCHECK_EQ(instr->InputCount(), 2U); |
| 1107 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1108 | Primitive::Type type = instr->GetResultType(); |
| 1109 | switch (type) { |
| 1110 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1111 | case Primitive::kPrimLong: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1112 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1113 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1114 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1115 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1116 | |
| 1117 | case Primitive::kPrimFloat: |
| 1118 | case Primitive::kPrimDouble: |
| 1119 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1120 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1121 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1122 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1123 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1124 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1125 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1126 | } |
| 1127 | } |
| 1128 | |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1129 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction) { |
| 1130 | LocationSummary* locations = |
| 1131 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1132 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1133 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 1134 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1135 | } else { |
| 1136 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 1141 | const FieldInfo& field_info) { |
| 1142 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1143 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1144 | |
| 1145 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
| 1146 | bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease(); |
| 1147 | |
| 1148 | if (field_info.IsVolatile()) { |
| 1149 | if (use_acquire_release) { |
| 1150 | // NB: LoadAcquire will record the pc info if needed. |
| 1151 | codegen_->LoadAcquire(instruction, OutputCPURegister(instruction), field); |
| 1152 | } else { |
| 1153 | codegen_->Load(field_info.GetFieldType(), OutputCPURegister(instruction), field); |
| 1154 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1155 | // For IRIW sequential consistency kLoadAny is not sufficient. |
| 1156 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 1157 | } |
| 1158 | } else { |
| 1159 | codegen_->Load(field_info.GetFieldType(), OutputCPURegister(instruction), field); |
| 1160 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 1165 | LocationSummary* locations = |
| 1166 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1167 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1168 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| 1169 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1170 | } else { |
| 1171 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame^] | 1176 | const FieldInfo& field_info, |
| 1177 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1178 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1179 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1180 | |
| 1181 | Register obj = InputRegisterAt(instruction, 0); |
| 1182 | CPURegister value = InputCPURegisterAt(instruction, 1); |
| 1183 | Offset offset = field_info.GetFieldOffset(); |
| 1184 | Primitive::Type field_type = field_info.GetFieldType(); |
| 1185 | bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease(); |
| 1186 | |
| 1187 | if (field_info.IsVolatile()) { |
| 1188 | if (use_acquire_release) { |
| 1189 | codegen_->StoreRelease(field_type, value, HeapOperand(obj, offset)); |
| 1190 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1191 | } else { |
| 1192 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 1193 | codegen_->Store(field_type, value, HeapOperand(obj, offset)); |
| 1194 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1195 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 1196 | } |
| 1197 | } else { |
| 1198 | codegen_->Store(field_type, value, HeapOperand(obj, offset)); |
| 1199 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1200 | } |
| 1201 | |
| 1202 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame^] | 1203 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1204 | } |
| 1205 | } |
| 1206 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1207 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1208 | Primitive::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1209 | |
| 1210 | switch (type) { |
| 1211 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1212 | case Primitive::kPrimLong: { |
| 1213 | Register dst = OutputRegister(instr); |
| 1214 | Register lhs = InputRegisterAt(instr, 0); |
| 1215 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1216 | if (instr->IsAdd()) { |
| 1217 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1218 | } else if (instr->IsAnd()) { |
| 1219 | __ And(dst, lhs, rhs); |
| 1220 | } else if (instr->IsOr()) { |
| 1221 | __ Orr(dst, lhs, rhs); |
| 1222 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1223 | __ Sub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1224 | } else { |
| 1225 | DCHECK(instr->IsXor()); |
| 1226 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1227 | } |
| 1228 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1229 | } |
| 1230 | case Primitive::kPrimFloat: |
| 1231 | case Primitive::kPrimDouble: { |
| 1232 | FPRegister dst = OutputFPRegister(instr); |
| 1233 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 1234 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 1235 | if (instr->IsAdd()) { |
| 1236 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1237 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1238 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1239 | } else { |
| 1240 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1241 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1242 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1243 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1244 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1245 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1246 | } |
| 1247 | } |
| 1248 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1249 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 1250 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 1251 | |
| 1252 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1253 | Primitive::Type type = instr->GetResultType(); |
| 1254 | switch (type) { |
| 1255 | case Primitive::kPrimInt: |
| 1256 | case Primitive::kPrimLong: { |
| 1257 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1258 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 1259 | locations->SetOut(Location::RequiresRegister()); |
| 1260 | break; |
| 1261 | } |
| 1262 | default: |
| 1263 | LOG(FATAL) << "Unexpected shift type " << type; |
| 1264 | } |
| 1265 | } |
| 1266 | |
| 1267 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 1268 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 1269 | |
| 1270 | Primitive::Type type = instr->GetType(); |
| 1271 | switch (type) { |
| 1272 | case Primitive::kPrimInt: |
| 1273 | case Primitive::kPrimLong: { |
| 1274 | Register dst = OutputRegister(instr); |
| 1275 | Register lhs = InputRegisterAt(instr, 0); |
| 1276 | Operand rhs = InputOperandAt(instr, 1); |
| 1277 | if (rhs.IsImmediate()) { |
| 1278 | uint32_t shift_value = (type == Primitive::kPrimInt) |
| 1279 | ? static_cast<uint32_t>(rhs.immediate() & kMaxIntShiftValue) |
| 1280 | : static_cast<uint32_t>(rhs.immediate() & kMaxLongShiftValue); |
| 1281 | if (instr->IsShl()) { |
| 1282 | __ Lsl(dst, lhs, shift_value); |
| 1283 | } else if (instr->IsShr()) { |
| 1284 | __ Asr(dst, lhs, shift_value); |
| 1285 | } else { |
| 1286 | __ Lsr(dst, lhs, shift_value); |
| 1287 | } |
| 1288 | } else { |
| 1289 | Register rhs_reg = dst.IsX() ? rhs.reg().X() : rhs.reg().W(); |
| 1290 | |
| 1291 | if (instr->IsShl()) { |
| 1292 | __ Lsl(dst, lhs, rhs_reg); |
| 1293 | } else if (instr->IsShr()) { |
| 1294 | __ Asr(dst, lhs, rhs_reg); |
| 1295 | } else { |
| 1296 | __ Lsr(dst, lhs, rhs_reg); |
| 1297 | } |
| 1298 | } |
| 1299 | break; |
| 1300 | } |
| 1301 | default: |
| 1302 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 1303 | } |
| 1304 | } |
| 1305 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1306 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1307 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1311 | HandleBinaryOp(instruction); |
| 1312 | } |
| 1313 | |
| 1314 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 1315 | HandleBinaryOp(instruction); |
| 1316 | } |
| 1317 | |
| 1318 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 1319 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1320 | } |
| 1321 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1322 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
| 1323 | LocationSummary* locations = |
| 1324 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1325 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1326 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 1327 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 1328 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1329 | } else { |
| 1330 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1331 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
| 1335 | LocationSummary* locations = instruction->GetLocations(); |
| 1336 | Primitive::Type type = instruction->GetType(); |
| 1337 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1338 | Location index = locations->InAt(1); |
| 1339 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(type)).Uint32Value(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1340 | MemOperand source = HeapOperand(obj); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1341 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1342 | UseScratchRegisterScope temps(masm); |
| 1343 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1344 | |
| 1345 | if (index.IsConstant()) { |
| 1346 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1347 | source = HeapOperand(obj, offset); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1348 | } else { |
| 1349 | Register temp = temps.AcquireSameSizeAs(obj); |
| 1350 | Register index_reg = RegisterFrom(index, Primitive::kPrimInt); |
| 1351 | __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(type))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1352 | source = HeapOperand(temp, offset); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1355 | codegen_->Load(type, OutputCPURegister(instruction), source); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1356 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1357 | } |
| 1358 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1359 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| 1360 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1361 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1362 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1366 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1367 | __ Ldr(OutputRegister(instruction), |
| 1368 | HeapOperand(InputRegisterAt(instruction, 0), mirror::Array::LengthOffset())); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1369 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1370 | } |
| 1371 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1372 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 1373 | if (instruction->NeedsTypeCheck()) { |
| 1374 | LocationSummary* locations = |
| 1375 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1376 | InvokeRuntimeCallingConvention calling_convention; |
| 1377 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 1378 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 1379 | locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2))); |
| 1380 | } else { |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 1381 | LocationSummary* locations = |
| 1382 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1383 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1384 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 1385 | if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
| 1386 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 1387 | } else { |
| 1388 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1389 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1390 | } |
| 1391 | } |
| 1392 | |
| 1393 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| 1394 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 1395 | LocationSummary* locations = instruction->GetLocations(); |
| 1396 | bool needs_runtime_call = locations->WillCall(); |
| 1397 | |
| 1398 | if (needs_runtime_call) { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1399 | codegen_->InvokeRuntime( |
| 1400 | QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc(), nullptr); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 1401 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1402 | } else { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1403 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1404 | CPURegister value = InputCPURegisterAt(instruction, 2); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1405 | Location index = locations->InAt(1); |
| 1406 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1407 | MemOperand destination = HeapOperand(obj); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1408 | MacroAssembler* masm = GetVIXLAssembler(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1409 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 1410 | { |
| 1411 | // We use a block to end the scratch scope before the write barrier, thus |
| 1412 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 1413 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1414 | |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 1415 | if (index.IsConstant()) { |
| 1416 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
| 1417 | destination = HeapOperand(obj, offset); |
| 1418 | } else { |
| 1419 | Register temp = temps.AcquireSameSizeAs(obj); |
| 1420 | Register index_reg = InputRegisterAt(instruction, 1); |
| 1421 | __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(value_type))); |
| 1422 | destination = HeapOperand(temp, offset); |
| 1423 | } |
| 1424 | |
| 1425 | codegen_->Store(value_type, value, destination); |
| 1426 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1427 | } |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 1428 | if (CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue())) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame^] | 1429 | codegen_->MarkGCCard(obj, value.W(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 1430 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1431 | } |
| 1432 | } |
| 1433 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1434 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 1435 | LocationSummary* locations = |
| 1436 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1437 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 1438 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1439 | if (instruction->HasUses()) { |
| 1440 | locations->SetOut(Location::SameAsFirstInput()); |
| 1441 | } |
| 1442 | } |
| 1443 | |
| 1444 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1445 | LocationSummary* locations = instruction->GetLocations(); |
| 1446 | BoundsCheckSlowPathARM64* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64( |
| 1447 | instruction, locations->InAt(0), locations->InAt(1)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1448 | codegen_->AddSlowPath(slow_path); |
| 1449 | |
| 1450 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 1451 | __ B(slow_path->GetEntryLabel(), hs); |
| 1452 | } |
| 1453 | |
| 1454 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| 1455 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 1456 | instruction, LocationSummary::kCallOnSlowPath); |
| 1457 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1458 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1459 | locations->AddTemp(Location::RequiresRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1463 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1464 | Register obj = InputRegisterAt(instruction, 0);; |
| 1465 | Register cls = InputRegisterAt(instruction, 1);; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1466 | Register obj_cls = WRegisterFrom(instruction->GetLocations()->GetTemp(0)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1467 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1468 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64( |
| 1469 | instruction, locations->InAt(1), LocationFrom(obj_cls), instruction->GetDexPc()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1470 | codegen_->AddSlowPath(slow_path); |
| 1471 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 1472 | // Avoid null check if we know obj is not null. |
| 1473 | if (instruction->MustDoNullCheck()) { |
| 1474 | __ Cbz(obj, slow_path->GetExitLabel()); |
| 1475 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1476 | // Compare the class of `obj` with `cls`. |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1477 | __ Ldr(obj_cls, HeapOperand(obj, mirror::Object::ClassOffset())); |
| 1478 | __ Cmp(obj_cls, cls); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1479 | __ B(ne, slow_path->GetEntryLabel()); |
| 1480 | __ Bind(slow_path->GetExitLabel()); |
| 1481 | } |
| 1482 | |
| 1483 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 1484 | LocationSummary* locations = |
| 1485 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 1486 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1487 | if (check->HasUses()) { |
| 1488 | locations->SetOut(Location::SameAsFirstInput()); |
| 1489 | } |
| 1490 | } |
| 1491 | |
| 1492 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 1493 | // We assume the class is not null. |
| 1494 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 1495 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 1496 | codegen_->AddSlowPath(slow_path); |
| 1497 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 1498 | } |
| 1499 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1500 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1501 | LocationSummary* locations = |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1502 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 1503 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1504 | switch (in_type) { |
| 1505 | case Primitive::kPrimLong: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1506 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1507 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1508 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1509 | break; |
| 1510 | } |
| 1511 | case Primitive::kPrimFloat: |
| 1512 | case Primitive::kPrimDouble: { |
| 1513 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Alexandre Rames | 9341546 | 2015-02-17 15:08:20 +0000 | [diff] [blame] | 1514 | HInstruction* right = compare->InputAt(1); |
| 1515 | if ((right->IsFloatConstant() && (right->AsFloatConstant()->GetValue() == 0.0f)) || |
| 1516 | (right->IsDoubleConstant() && (right->AsDoubleConstant()->GetValue() == 0.0))) { |
| 1517 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 1518 | } else { |
| 1519 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1520 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1521 | locations->SetOut(Location::RequiresRegister()); |
| 1522 | break; |
| 1523 | } |
| 1524 | default: |
| 1525 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 1526 | } |
| 1527 | } |
| 1528 | |
| 1529 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| 1530 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 1531 | |
| 1532 | // 0 if: left == right |
| 1533 | // 1 if: left > right |
| 1534 | // -1 if: left < right |
| 1535 | switch (in_type) { |
| 1536 | case Primitive::kPrimLong: { |
| 1537 | Register result = OutputRegister(compare); |
| 1538 | Register left = InputRegisterAt(compare, 0); |
| 1539 | Operand right = InputOperandAt(compare, 1); |
| 1540 | |
| 1541 | __ Cmp(left, right); |
| 1542 | __ Cset(result, ne); |
| 1543 | __ Cneg(result, result, lt); |
| 1544 | break; |
| 1545 | } |
| 1546 | case Primitive::kPrimFloat: |
| 1547 | case Primitive::kPrimDouble: { |
| 1548 | Register result = OutputRegister(compare); |
| 1549 | FPRegister left = InputFPRegisterAt(compare, 0); |
Alexandre Rames | 9341546 | 2015-02-17 15:08:20 +0000 | [diff] [blame] | 1550 | if (compare->GetLocations()->InAt(1).IsConstant()) { |
| 1551 | if (kIsDebugBuild) { |
| 1552 | HInstruction* right = compare->GetLocations()->InAt(1).GetConstant(); |
| 1553 | DCHECK((right->IsFloatConstant() && (right->AsFloatConstant()->GetValue() == 0.0f)) || |
| 1554 | (right->IsDoubleConstant() && (right->AsDoubleConstant()->GetValue() == 0.0))); |
| 1555 | } |
| 1556 | // 0.0 is the only immediate that can be encoded directly in a FCMP instruction. |
| 1557 | __ Fcmp(left, 0.0); |
| 1558 | } else { |
| 1559 | __ Fcmp(left, InputFPRegisterAt(compare, 1)); |
| 1560 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1561 | if (compare->IsGtBias()) { |
| 1562 | __ Cset(result, ne); |
| 1563 | } else { |
| 1564 | __ Csetm(result, ne); |
| 1565 | } |
| 1566 | __ Cneg(result, result, compare->IsGtBias() ? mi : gt); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1567 | break; |
| 1568 | } |
| 1569 | default: |
| 1570 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 1571 | } |
| 1572 | } |
| 1573 | |
| 1574 | void LocationsBuilderARM64::VisitCondition(HCondition* instruction) { |
| 1575 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1576 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1577 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1578 | if (instruction->NeedsMaterialization()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1579 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1580 | } |
| 1581 | } |
| 1582 | |
| 1583 | void InstructionCodeGeneratorARM64::VisitCondition(HCondition* instruction) { |
| 1584 | if (!instruction->NeedsMaterialization()) { |
| 1585 | return; |
| 1586 | } |
| 1587 | |
| 1588 | LocationSummary* locations = instruction->GetLocations(); |
| 1589 | Register lhs = InputRegisterAt(instruction, 0); |
| 1590 | Operand rhs = InputOperandAt(instruction, 1); |
| 1591 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
| 1592 | Condition cond = ARM64Condition(instruction->GetCondition()); |
| 1593 | |
| 1594 | __ Cmp(lhs, rhs); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1595 | __ Cset(res, cond); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 1599 | M(Equal) \ |
| 1600 | M(NotEqual) \ |
| 1601 | M(LessThan) \ |
| 1602 | M(LessThanOrEqual) \ |
| 1603 | M(GreaterThan) \ |
| 1604 | M(GreaterThanOrEqual) |
| 1605 | #define DEFINE_CONDITION_VISITORS(Name) \ |
| 1606 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); } \ |
| 1607 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); } |
| 1608 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1609 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1610 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 1611 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 1612 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 1613 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 1614 | |
| 1615 | LocationSummary* locations = instruction->GetLocations(); |
| 1616 | Location second = locations->InAt(1); |
| 1617 | DCHECK(second.IsConstant()); |
| 1618 | |
| 1619 | Register out = OutputRegister(instruction); |
| 1620 | Register dividend = InputRegisterAt(instruction, 0); |
| 1621 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 1622 | DCHECK(imm == 1 || imm == -1); |
| 1623 | |
| 1624 | if (instruction->IsRem()) { |
| 1625 | __ Mov(out, 0); |
| 1626 | } else { |
| 1627 | if (imm == 1) { |
| 1628 | __ Mov(out, dividend); |
| 1629 | } else { |
| 1630 | __ Neg(out, dividend); |
| 1631 | } |
| 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 1636 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 1637 | |
| 1638 | LocationSummary* locations = instruction->GetLocations(); |
| 1639 | Location second = locations->InAt(1); |
| 1640 | DCHECK(second.IsConstant()); |
| 1641 | |
| 1642 | Register out = OutputRegister(instruction); |
| 1643 | Register dividend = InputRegisterAt(instruction, 0); |
| 1644 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 1645 | int64_t abs_imm = std::abs(imm); |
| 1646 | DCHECK(IsPowerOfTwo(abs_imm)); |
| 1647 | int ctz_imm = CTZ(abs_imm); |
| 1648 | |
| 1649 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1650 | Register temp = temps.AcquireSameSizeAs(out); |
| 1651 | |
| 1652 | if (instruction->IsDiv()) { |
| 1653 | __ Add(temp, dividend, abs_imm - 1); |
| 1654 | __ Cmp(dividend, 0); |
| 1655 | __ Csel(out, temp, dividend, lt); |
| 1656 | if (imm > 0) { |
| 1657 | __ Asr(out, out, ctz_imm); |
| 1658 | } else { |
| 1659 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 1660 | } |
| 1661 | } else { |
| 1662 | int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64; |
| 1663 | __ Asr(temp, dividend, bits - 1); |
| 1664 | __ Lsr(temp, temp, bits - ctz_imm); |
| 1665 | __ Add(out, dividend, temp); |
| 1666 | __ And(out, out, abs_imm - 1); |
| 1667 | __ Sub(out, out, temp); |
| 1668 | } |
| 1669 | } |
| 1670 | |
| 1671 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 1672 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 1673 | |
| 1674 | LocationSummary* locations = instruction->GetLocations(); |
| 1675 | Location second = locations->InAt(1); |
| 1676 | DCHECK(second.IsConstant()); |
| 1677 | |
| 1678 | Register out = OutputRegister(instruction); |
| 1679 | Register dividend = InputRegisterAt(instruction, 0); |
| 1680 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 1681 | |
| 1682 | Primitive::Type type = instruction->GetResultType(); |
| 1683 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 1684 | |
| 1685 | int64_t magic; |
| 1686 | int shift; |
| 1687 | CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift); |
| 1688 | |
| 1689 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1690 | Register temp = temps.AcquireSameSizeAs(out); |
| 1691 | |
| 1692 | // temp = get_high(dividend * magic) |
| 1693 | __ Mov(temp, magic); |
| 1694 | if (type == Primitive::kPrimLong) { |
| 1695 | __ Smulh(temp, dividend, temp); |
| 1696 | } else { |
| 1697 | __ Smull(temp.X(), dividend, temp); |
| 1698 | __ Lsr(temp.X(), temp.X(), 32); |
| 1699 | } |
| 1700 | |
| 1701 | if (imm > 0 && magic < 0) { |
| 1702 | __ Add(temp, temp, dividend); |
| 1703 | } else if (imm < 0 && magic > 0) { |
| 1704 | __ Sub(temp, temp, dividend); |
| 1705 | } |
| 1706 | |
| 1707 | if (shift != 0) { |
| 1708 | __ Asr(temp, temp, shift); |
| 1709 | } |
| 1710 | |
| 1711 | if (instruction->IsDiv()) { |
| 1712 | __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 1713 | } else { |
| 1714 | __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 1715 | // TODO: Strength reduction for msub. |
| 1716 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 1717 | __ Mov(temp_imm, imm); |
| 1718 | __ Msub(out, temp, temp_imm, dividend); |
| 1719 | } |
| 1720 | } |
| 1721 | |
| 1722 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 1723 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 1724 | Primitive::Type type = instruction->GetResultType(); |
| 1725 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 1726 | |
| 1727 | LocationSummary* locations = instruction->GetLocations(); |
| 1728 | Register out = OutputRegister(instruction); |
| 1729 | Location second = locations->InAt(1); |
| 1730 | |
| 1731 | if (second.IsConstant()) { |
| 1732 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 1733 | |
| 1734 | if (imm == 0) { |
| 1735 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 1736 | } else if (imm == 1 || imm == -1) { |
| 1737 | DivRemOneOrMinusOne(instruction); |
| 1738 | } else if (IsPowerOfTwo(std::abs(imm))) { |
| 1739 | DivRemByPowerOfTwo(instruction); |
| 1740 | } else { |
| 1741 | DCHECK(imm <= -2 || imm >= 2); |
| 1742 | GenerateDivRemWithAnyConstant(instruction); |
| 1743 | } |
| 1744 | } else { |
| 1745 | Register dividend = InputRegisterAt(instruction, 0); |
| 1746 | Register divisor = InputRegisterAt(instruction, 1); |
| 1747 | if (instruction->IsDiv()) { |
| 1748 | __ Sdiv(out, dividend, divisor); |
| 1749 | } else { |
| 1750 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1751 | Register temp = temps.AcquireSameSizeAs(out); |
| 1752 | __ Sdiv(temp, dividend, divisor); |
| 1753 | __ Msub(out, temp, divisor, dividend); |
| 1754 | } |
| 1755 | } |
| 1756 | } |
| 1757 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1758 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 1759 | LocationSummary* locations = |
| 1760 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 1761 | switch (div->GetResultType()) { |
| 1762 | case Primitive::kPrimInt: |
| 1763 | case Primitive::kPrimLong: |
| 1764 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 1765 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1766 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1767 | break; |
| 1768 | |
| 1769 | case Primitive::kPrimFloat: |
| 1770 | case Primitive::kPrimDouble: |
| 1771 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1772 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1773 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1774 | break; |
| 1775 | |
| 1776 | default: |
| 1777 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 1778 | } |
| 1779 | } |
| 1780 | |
| 1781 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| 1782 | Primitive::Type type = div->GetResultType(); |
| 1783 | switch (type) { |
| 1784 | case Primitive::kPrimInt: |
| 1785 | case Primitive::kPrimLong: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 1786 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1787 | break; |
| 1788 | |
| 1789 | case Primitive::kPrimFloat: |
| 1790 | case Primitive::kPrimDouble: |
| 1791 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 1792 | break; |
| 1793 | |
| 1794 | default: |
| 1795 | LOG(FATAL) << "Unexpected div type " << type; |
| 1796 | } |
| 1797 | } |
| 1798 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1799 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 1800 | LocationSummary* locations = |
| 1801 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1802 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 1803 | if (instruction->HasUses()) { |
| 1804 | locations->SetOut(Location::SameAsFirstInput()); |
| 1805 | } |
| 1806 | } |
| 1807 | |
| 1808 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 1809 | SlowPathCodeARM64* slow_path = |
| 1810 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction); |
| 1811 | codegen_->AddSlowPath(slow_path); |
| 1812 | Location value = instruction->GetLocations()->InAt(0); |
| 1813 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1814 | Primitive::Type type = instruction->GetType(); |
| 1815 | |
| 1816 | if ((type != Primitive::kPrimInt) && (type != Primitive::kPrimLong)) { |
| 1817 | LOG(FATAL) << "Unexpected type " << type << "for DivZeroCheck."; |
| 1818 | return; |
| 1819 | } |
| 1820 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1821 | if (value.IsConstant()) { |
| 1822 | int64_t divisor = Int64ConstantFrom(value); |
| 1823 | if (divisor == 0) { |
| 1824 | __ B(slow_path->GetEntryLabel()); |
| 1825 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1826 | // A division by a non-null constant is valid. We don't need to perform |
| 1827 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1828 | } |
| 1829 | } else { |
| 1830 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 1831 | } |
| 1832 | } |
| 1833 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1834 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1835 | LocationSummary* locations = |
| 1836 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1837 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1838 | } |
| 1839 | |
| 1840 | void InstructionCodeGeneratorARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1841 | UNUSED(constant); |
| 1842 | // Will be generated at use site. |
| 1843 | } |
| 1844 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1845 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 1846 | exit->SetLocations(nullptr); |
| 1847 | } |
| 1848 | |
| 1849 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1850 | UNUSED(exit); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1851 | } |
| 1852 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1853 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 1854 | LocationSummary* locations = |
| 1855 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1856 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1857 | } |
| 1858 | |
| 1859 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 1860 | UNUSED(constant); |
| 1861 | // Will be generated at use site. |
| 1862 | } |
| 1863 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1864 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 1865 | got->SetLocations(nullptr); |
| 1866 | } |
| 1867 | |
| 1868 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 1869 | HBasicBlock* successor = got->GetSuccessor(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1870 | DCHECK(!successor->IsExitBlock()); |
| 1871 | HBasicBlock* block = got->GetBlock(); |
| 1872 | HInstruction* previous = got->GetPrevious(); |
| 1873 | HLoopInformation* info = block->GetLoopInformation(); |
| 1874 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1875 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1876 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 1877 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1878 | return; |
| 1879 | } |
| 1880 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1881 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1882 | } |
| 1883 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1884 | __ B(codegen_->GetLabelOf(successor)); |
| 1885 | } |
| 1886 | } |
| 1887 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1888 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
| 1889 | vixl::Label* true_target, |
| 1890 | vixl::Label* false_target, |
| 1891 | vixl::Label* always_true_target) { |
| 1892 | HInstruction* cond = instruction->InputAt(0); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1893 | HCondition* condition = cond->AsCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1894 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1895 | if (cond->IsIntConstant()) { |
| 1896 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 1897 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1898 | if (always_true_target != nullptr) { |
| 1899 | __ B(always_true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1900 | } |
| 1901 | return; |
| 1902 | } else { |
| 1903 | DCHECK_EQ(cond_value, 0); |
| 1904 | } |
| 1905 | } else if (!cond->IsCondition() || condition->NeedsMaterialization()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1906 | // The condition instruction has been materialized, compare the output to 0. |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1907 | Location cond_val = instruction->GetLocations()->InAt(0); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1908 | DCHECK(cond_val.IsRegister()); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1909 | __ Cbnz(InputRegisterAt(instruction, 0), true_target); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1910 | } else { |
| 1911 | // The condition instruction has not been materialized, use its inputs as |
| 1912 | // the comparison and its condition as the branch condition. |
| 1913 | Register lhs = InputRegisterAt(condition, 0); |
| 1914 | Operand rhs = InputOperandAt(condition, 1); |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 1915 | Condition arm64_cond = ARM64Condition(condition->GetCondition()); |
Alexandre Rames | 4388dcc | 2015-02-03 10:28:33 +0000 | [diff] [blame] | 1916 | if ((arm64_cond != gt && arm64_cond != le) && rhs.IsImmediate() && (rhs.immediate() == 0)) { |
| 1917 | switch (arm64_cond) { |
| 1918 | case eq: |
| 1919 | __ Cbz(lhs, true_target); |
| 1920 | break; |
| 1921 | case ne: |
| 1922 | __ Cbnz(lhs, true_target); |
| 1923 | break; |
| 1924 | case lt: |
| 1925 | // Test the sign bit and branch accordingly. |
| 1926 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target); |
| 1927 | break; |
| 1928 | case ge: |
| 1929 | // Test the sign bit and branch accordingly. |
| 1930 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target); |
| 1931 | break; |
| 1932 | default: |
| 1933 | // Without the `static_cast` the compiler throws an error for |
| 1934 | // `-Werror=sign-promo`. |
| 1935 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1936 | } |
| 1937 | } else { |
| 1938 | __ Cmp(lhs, rhs); |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 1939 | __ B(arm64_cond, true_target); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1940 | } |
| 1941 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1942 | if (false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1943 | __ B(false_target); |
| 1944 | } |
| 1945 | } |
| 1946 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1947 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| 1948 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1949 | HInstruction* cond = if_instr->InputAt(0); |
| 1950 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1951 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1952 | } |
| 1953 | } |
| 1954 | |
| 1955 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
| 1956 | vixl::Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1957 | vixl::Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1958 | vixl::Label* always_true_target = true_target; |
| 1959 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1960 | if_instr->IfTrueSuccessor())) { |
| 1961 | always_true_target = nullptr; |
| 1962 | } |
| 1963 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1964 | if_instr->IfFalseSuccessor())) { |
| 1965 | false_target = nullptr; |
| 1966 | } |
| 1967 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 1968 | } |
| 1969 | |
| 1970 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1971 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1972 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1973 | HInstruction* cond = deoptimize->InputAt(0); |
| 1974 | DCHECK(cond->IsCondition()); |
| 1975 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 1976 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1977 | } |
| 1978 | } |
| 1979 | |
| 1980 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1981 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) |
| 1982 | DeoptimizationSlowPathARM64(deoptimize); |
| 1983 | codegen_->AddSlowPath(slow_path); |
| 1984 | vixl::Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 1985 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 1986 | } |
| 1987 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1988 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1989 | HandleFieldGet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1993 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1994 | } |
| 1995 | |
| 1996 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1997 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame^] | 2001 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2002 | } |
| 2003 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2004 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
| 2005 | LocationSummary::CallKind call_kind = |
| 2006 | instruction->IsClassFinal() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath; |
| 2007 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 2008 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2009 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2010 | // The output does overlap inputs. |
| 2011 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2012 | } |
| 2013 | |
| 2014 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
| 2015 | LocationSummary* locations = instruction->GetLocations(); |
| 2016 | Register obj = InputRegisterAt(instruction, 0);; |
| 2017 | Register cls = InputRegisterAt(instruction, 1);; |
| 2018 | Register out = OutputRegister(instruction); |
| 2019 | |
| 2020 | vixl::Label done; |
| 2021 | |
| 2022 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 2023 | // Avoid null check if we know `obj` is not null. |
| 2024 | if (instruction->MustDoNullCheck()) { |
| 2025 | __ Mov(out, 0); |
| 2026 | __ Cbz(obj, &done); |
| 2027 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2028 | |
| 2029 | // Compare the class of `obj` with `cls`. |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2030 | __ Ldr(out, HeapOperand(obj, mirror::Object::ClassOffset())); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2031 | __ Cmp(out, cls); |
| 2032 | if (instruction->IsClassFinal()) { |
| 2033 | // Classes must be equal for the instanceof to succeed. |
| 2034 | __ Cset(out, eq); |
| 2035 | } else { |
| 2036 | // If the classes are not equal, we go into a slow path. |
| 2037 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 2038 | SlowPathCodeARM64* slow_path = |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2039 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM64( |
| 2040 | instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2041 | codegen_->AddSlowPath(slow_path); |
| 2042 | __ B(ne, slow_path->GetEntryLabel()); |
| 2043 | __ Mov(out, 1); |
| 2044 | __ Bind(slow_path->GetExitLabel()); |
| 2045 | } |
| 2046 | |
| 2047 | __ Bind(&done); |
| 2048 | } |
| 2049 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2050 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| 2051 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 2052 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2053 | } |
| 2054 | |
| 2055 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant) { |
| 2056 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2057 | UNUSED(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2058 | } |
| 2059 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2060 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| 2061 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 2062 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2063 | } |
| 2064 | |
| 2065 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant) { |
| 2066 | // Will be generated at use site. |
| 2067 | UNUSED(constant); |
| 2068 | } |
| 2069 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2070 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
| 2071 | LocationSummary* locations = |
| 2072 | new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall); |
| 2073 | locations->AddTemp(LocationFrom(x0)); |
| 2074 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2075 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 2076 | for (size_t i = 0; i < invoke->GetNumberOfArguments(); i++) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2077 | HInstruction* input = invoke->InputAt(i); |
| 2078 | locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); |
| 2079 | } |
| 2080 | |
| 2081 | Primitive::Type return_type = invoke->GetType(); |
| 2082 | if (return_type != Primitive::kPrimVoid) { |
| 2083 | locations->SetOut(calling_convention_visitor.GetReturnLocation(return_type)); |
| 2084 | } |
| 2085 | } |
| 2086 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2087 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2088 | HandleInvoke(invoke); |
| 2089 | } |
| 2090 | |
| 2091 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2092 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 2093 | Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0)); |
| 2094 | uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() + |
| 2095 | (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry); |
| 2096 | Location receiver = invoke->GetLocations()->InAt(0); |
| 2097 | Offset class_offset = mirror::Object::ClassOffset(); |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 2098 | Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2099 | |
| 2100 | // The register ip1 is required to be used for the hidden argument in |
| 2101 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2102 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2103 | UseScratchRegisterScope scratch_scope(masm); |
| 2104 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2105 | scratch_scope.Exclude(ip1); |
| 2106 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 2107 | |
| 2108 | // temp = object->GetClass(); |
| 2109 | if (receiver.IsStackSlot()) { |
| 2110 | __ Ldr(temp, StackOperandFrom(receiver)); |
| 2111 | __ Ldr(temp, HeapOperand(temp, class_offset)); |
| 2112 | } else { |
| 2113 | __ Ldr(temp, HeapOperandFrom(receiver, class_offset)); |
| 2114 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2115 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2116 | // temp = temp->GetImtEntryAt(method_offset); |
| 2117 | __ Ldr(temp, HeapOperand(temp, method_offset)); |
| 2118 | // lr = temp->GetEntryPoint(); |
| 2119 | __ Ldr(lr, HeapOperand(temp, entry_point)); |
| 2120 | // lr(); |
| 2121 | __ Blr(lr); |
| 2122 | DCHECK(!codegen_->IsLeafMethod()); |
| 2123 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2124 | } |
| 2125 | |
| 2126 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2127 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
| 2128 | if (intrinsic.TryDispatch(invoke)) { |
| 2129 | return; |
| 2130 | } |
| 2131 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2132 | HandleInvoke(invoke); |
| 2133 | } |
| 2134 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2135 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 2136 | // When we do not run baseline, explicit clinit checks triggered by static |
| 2137 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 2138 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2139 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2140 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
| 2141 | if (intrinsic.TryDispatch(invoke)) { |
| 2142 | return; |
| 2143 | } |
| 2144 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2145 | HandleInvoke(invoke); |
| 2146 | } |
| 2147 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2148 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 2149 | if (invoke->GetLocations()->Intrinsified()) { |
| 2150 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 2151 | intrinsic.Dispatch(invoke); |
| 2152 | return true; |
| 2153 | } |
| 2154 | return false; |
| 2155 | } |
| 2156 | |
| 2157 | void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) { |
| 2158 | // Make sure that ArtMethod* is passed in kArtMethodRegister as per the calling convention. |
| 2159 | DCHECK(temp.Is(kArtMethodRegister)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2160 | size_t index_in_cache = mirror::Array::DataOffset(kHeapRefSize).SizeValue() + |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2161 | invoke->GetDexMethodIndex() * kHeapRefSize; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2162 | |
| 2163 | // TODO: Implement all kinds of calls: |
| 2164 | // 1) boot -> boot |
| 2165 | // 2) app -> boot |
| 2166 | // 3) app -> app |
| 2167 | // |
| 2168 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 2169 | |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 2170 | if (invoke->IsStringInit()) { |
| 2171 | // temp = thread->string_init_entrypoint |
| 2172 | __ Ldr(temp, HeapOperand(tr, invoke->GetStringInitOffset())); |
| 2173 | // LR = temp->entry_point_from_quick_compiled_code_; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2174 | __ Ldr(lr, HeapOperand(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 2175 | kArm64WordSize))); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 2176 | // lr() |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2177 | __ Blr(lr); |
| 2178 | } else { |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 2179 | // temp = method; |
| 2180 | LoadCurrentMethod(temp); |
| 2181 | if (!invoke->IsRecursive()) { |
| 2182 | // temp = temp->dex_cache_resolved_methods_; |
| 2183 | __ Ldr(temp, HeapOperand(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset())); |
| 2184 | // temp = temp[index_in_cache]; |
| 2185 | __ Ldr(temp, HeapOperand(temp, index_in_cache)); |
| 2186 | // lr = temp->entry_point_from_quick_compiled_code_; |
| 2187 | __ Ldr(lr, HeapOperand(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 2188 | kArm64WordSize))); |
| 2189 | // lr(); |
| 2190 | __ Blr(lr); |
| 2191 | } else { |
| 2192 | __ Bl(&frame_entry_label_); |
| 2193 | } |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2194 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2195 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2196 | DCHECK(!IsLeafMethod()); |
| 2197 | } |
| 2198 | |
| 2199 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 2200 | // When we do not run baseline, explicit clinit checks triggered by static |
| 2201 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 2202 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2203 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2204 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2205 | return; |
| 2206 | } |
| 2207 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2208 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2209 | Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0)); |
| 2210 | codegen_->GenerateStaticOrDirectCall(invoke, temp); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2211 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2212 | } |
| 2213 | |
| 2214 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2215 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2216 | return; |
| 2217 | } |
| 2218 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2219 | LocationSummary* locations = invoke->GetLocations(); |
| 2220 | Location receiver = locations->InAt(0); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2221 | Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2222 | size_t method_offset = mirror::Class::EmbeddedVTableOffset().SizeValue() + |
| 2223 | invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry); |
| 2224 | Offset class_offset = mirror::Object::ClassOffset(); |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 2225 | Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2226 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2227 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 2228 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2229 | // temp = object->GetClass(); |
| 2230 | if (receiver.IsStackSlot()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2231 | __ Ldr(temp, MemOperand(sp, receiver.GetStackIndex())); |
| 2232 | __ Ldr(temp, HeapOperand(temp, class_offset)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2233 | } else { |
| 2234 | DCHECK(receiver.IsRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2235 | __ Ldr(temp, HeapOperandFrom(receiver, class_offset)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2236 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2237 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2238 | // temp = temp->GetMethodAt(method_offset); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2239 | __ Ldr(temp, HeapOperand(temp, method_offset)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2240 | // lr = temp->GetEntryPoint(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2241 | __ Ldr(lr, HeapOperand(temp, entry_point.SizeValue())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2242 | // lr(); |
| 2243 | __ Blr(lr); |
| 2244 | DCHECK(!codegen_->IsLeafMethod()); |
| 2245 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2246 | } |
| 2247 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2248 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
| 2249 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() ? LocationSummary::kCallOnSlowPath |
| 2250 | : LocationSummary::kNoCall; |
| 2251 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
| 2252 | locations->SetOut(Location::RequiresRegister()); |
| 2253 | } |
| 2254 | |
| 2255 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) { |
| 2256 | Register out = OutputRegister(cls); |
| 2257 | if (cls->IsReferrersClass()) { |
| 2258 | DCHECK(!cls->CanCallRuntime()); |
| 2259 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 2260 | codegen_->LoadCurrentMethod(out); |
| 2261 | __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DeclaringClassOffset())); |
| 2262 | } else { |
| 2263 | DCHECK(cls->CanCallRuntime()); |
| 2264 | codegen_->LoadCurrentMethod(out); |
| 2265 | __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DexCacheResolvedTypesOffset())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2266 | __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2267 | |
| 2268 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 2269 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 2270 | codegen_->AddSlowPath(slow_path); |
| 2271 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 2272 | if (cls->MustGenerateClinitCheck()) { |
| 2273 | GenerateClassInitializationCheck(slow_path, out); |
| 2274 | } else { |
| 2275 | __ Bind(slow_path->GetExitLabel()); |
| 2276 | } |
| 2277 | } |
| 2278 | } |
| 2279 | |
| 2280 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 2281 | LocationSummary* locations = |
| 2282 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 2283 | locations->SetOut(Location::RequiresRegister()); |
| 2284 | } |
| 2285 | |
| 2286 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
| 2287 | MemOperand exception = MemOperand(tr, Thread::ExceptionOffset<kArm64WordSize>().Int32Value()); |
| 2288 | __ Ldr(OutputRegister(instruction), exception); |
| 2289 | __ Str(wzr, exception); |
| 2290 | } |
| 2291 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2292 | void LocationsBuilderARM64::VisitLoadLocal(HLoadLocal* load) { |
| 2293 | load->SetLocations(nullptr); |
| 2294 | } |
| 2295 | |
| 2296 | void InstructionCodeGeneratorARM64::VisitLoadLocal(HLoadLocal* load) { |
| 2297 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2298 | UNUSED(load); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2299 | } |
| 2300 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2301 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
| 2302 | LocationSummary* locations = |
| 2303 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
| 2304 | locations->SetOut(Location::RequiresRegister()); |
| 2305 | } |
| 2306 | |
| 2307 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) { |
| 2308 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load); |
| 2309 | codegen_->AddSlowPath(slow_path); |
| 2310 | |
| 2311 | Register out = OutputRegister(load); |
| 2312 | codegen_->LoadCurrentMethod(out); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 2313 | __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DeclaringClassOffset())); |
| 2314 | __ Ldr(out, HeapOperand(out, mirror::Class::DexCacheStringsOffset())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2315 | __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2316 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 2317 | __ Bind(slow_path->GetExitLabel()); |
| 2318 | } |
| 2319 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2320 | void LocationsBuilderARM64::VisitLocal(HLocal* local) { |
| 2321 | local->SetLocations(nullptr); |
| 2322 | } |
| 2323 | |
| 2324 | void InstructionCodeGeneratorARM64::VisitLocal(HLocal* local) { |
| 2325 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 2326 | } |
| 2327 | |
| 2328 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| 2329 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 2330 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2331 | } |
| 2332 | |
| 2333 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant) { |
| 2334 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2335 | UNUSED(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2336 | } |
| 2337 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2338 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 2339 | LocationSummary* locations = |
| 2340 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2341 | InvokeRuntimeCallingConvention calling_convention; |
| 2342 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 2343 | } |
| 2344 | |
| 2345 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 2346 | codegen_->InvokeRuntime(instruction->IsEnter() |
| 2347 | ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), |
| 2348 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2349 | instruction->GetDexPc(), |
| 2350 | nullptr); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2351 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2352 | } |
| 2353 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 2354 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 2355 | LocationSummary* locations = |
| 2356 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2357 | switch (mul->GetResultType()) { |
| 2358 | case Primitive::kPrimInt: |
| 2359 | case Primitive::kPrimLong: |
| 2360 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2361 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2362 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 2363 | break; |
| 2364 | |
| 2365 | case Primitive::kPrimFloat: |
| 2366 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2367 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2368 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2369 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 2370 | break; |
| 2371 | |
| 2372 | default: |
| 2373 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 2374 | } |
| 2375 | } |
| 2376 | |
| 2377 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 2378 | switch (mul->GetResultType()) { |
| 2379 | case Primitive::kPrimInt: |
| 2380 | case Primitive::kPrimLong: |
| 2381 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 2382 | break; |
| 2383 | |
| 2384 | case Primitive::kPrimFloat: |
| 2385 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2386 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 2387 | break; |
| 2388 | |
| 2389 | default: |
| 2390 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 2391 | } |
| 2392 | } |
| 2393 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2394 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 2395 | LocationSummary* locations = |
| 2396 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2397 | switch (neg->GetResultType()) { |
| 2398 | case Primitive::kPrimInt: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2399 | case Primitive::kPrimLong: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2400 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2401 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2402 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2403 | |
| 2404 | case Primitive::kPrimFloat: |
| 2405 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2406 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2407 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2408 | break; |
| 2409 | |
| 2410 | default: |
| 2411 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2412 | } |
| 2413 | } |
| 2414 | |
| 2415 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 2416 | switch (neg->GetResultType()) { |
| 2417 | case Primitive::kPrimInt: |
| 2418 | case Primitive::kPrimLong: |
| 2419 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 2420 | break; |
| 2421 | |
| 2422 | case Primitive::kPrimFloat: |
| 2423 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2424 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2425 | break; |
| 2426 | |
| 2427 | default: |
| 2428 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2429 | } |
| 2430 | } |
| 2431 | |
| 2432 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| 2433 | LocationSummary* locations = |
| 2434 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2435 | InvokeRuntimeCallingConvention calling_convention; |
| 2436 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2437 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(2))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2438 | locations->SetOut(LocationFrom(x0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2439 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 2440 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, |
| 2441 | void*, uint32_t, int32_t, mirror::ArtMethod*>(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2442 | } |
| 2443 | |
| 2444 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
| 2445 | LocationSummary* locations = instruction->GetLocations(); |
| 2446 | InvokeRuntimeCallingConvention calling_convention; |
| 2447 | Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt); |
| 2448 | DCHECK(type_index.Is(w0)); |
| 2449 | Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2450 | DCHECK(current_method.Is(w2)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2451 | codegen_->LoadCurrentMethod(current_method); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2452 | __ Mov(type_index, instruction->GetTypeIndex()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2453 | codegen_->InvokeRuntime( |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2454 | GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(), |
| 2455 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2456 | instruction->GetDexPc(), |
| 2457 | nullptr); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2458 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, |
| 2459 | void*, uint32_t, int32_t, mirror::ArtMethod*>(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2460 | } |
| 2461 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2462 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| 2463 | LocationSummary* locations = |
| 2464 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2465 | InvokeRuntimeCallingConvention calling_convention; |
| 2466 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 2467 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(1))); |
| 2468 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2469 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, mirror::ArtMethod*>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2470 | } |
| 2471 | |
| 2472 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
| 2473 | LocationSummary* locations = instruction->GetLocations(); |
| 2474 | Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt); |
| 2475 | DCHECK(type_index.Is(w0)); |
| 2476 | Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot); |
| 2477 | DCHECK(current_method.Is(w1)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2478 | codegen_->LoadCurrentMethod(current_method); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2479 | __ Mov(type_index, instruction->GetTypeIndex()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2480 | codegen_->InvokeRuntime( |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2481 | GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(), |
| 2482 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2483 | instruction->GetDexPc(), |
| 2484 | nullptr); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2485 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, mirror::ArtMethod*>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2486 | } |
| 2487 | |
| 2488 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| 2489 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 2490 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2491 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2492 | } |
| 2493 | |
| 2494 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 2495 | switch (instruction->GetResultType()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2496 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2497 | case Primitive::kPrimLong: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 2498 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2499 | break; |
| 2500 | |
| 2501 | default: |
| 2502 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 2503 | } |
| 2504 | } |
| 2505 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 2506 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| 2507 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2508 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2509 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2510 | } |
| 2511 | |
| 2512 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 2513 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::Operand(1)); |
| 2514 | } |
| 2515 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2516 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
| 2517 | LocationSummary* locations = |
| 2518 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2519 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2520 | if (instruction->HasUses()) { |
| 2521 | locations->SetOut(Location::SameAsFirstInput()); |
| 2522 | } |
| 2523 | } |
| 2524 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2525 | void InstructionCodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2526 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 2527 | return; |
| 2528 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2529 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2530 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 2531 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2532 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 2533 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 2534 | } |
| 2535 | |
| 2536 | void InstructionCodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2537 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction); |
| 2538 | codegen_->AddSlowPath(slow_path); |
| 2539 | |
| 2540 | LocationSummary* locations = instruction->GetLocations(); |
| 2541 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2542 | |
| 2543 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2544 | } |
| 2545 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2546 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
| 2547 | if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) { |
| 2548 | GenerateImplicitNullCheck(instruction); |
| 2549 | } else { |
| 2550 | GenerateExplicitNullCheck(instruction); |
| 2551 | } |
| 2552 | } |
| 2553 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2554 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 2555 | HandleBinaryOp(instruction); |
| 2556 | } |
| 2557 | |
| 2558 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 2559 | HandleBinaryOp(instruction); |
| 2560 | } |
| 2561 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2562 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 2563 | LOG(FATAL) << "Unreachable"; |
| 2564 | } |
| 2565 | |
| 2566 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
| 2567 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 2568 | } |
| 2569 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2570 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| 2571 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2572 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 2573 | if (location.IsStackSlot()) { |
| 2574 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 2575 | } else if (location.IsDoubleStackSlot()) { |
| 2576 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 2577 | } |
| 2578 | locations->SetOut(location); |
| 2579 | } |
| 2580 | |
| 2581 | void InstructionCodeGeneratorARM64::VisitParameterValue(HParameterValue* instruction) { |
| 2582 | // Nothing to do, the parameter is already at its location. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2583 | UNUSED(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2584 | } |
| 2585 | |
| 2586 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| 2587 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2588 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 2589 | locations->SetInAt(i, Location::Any()); |
| 2590 | } |
| 2591 | locations->SetOut(Location::Any()); |
| 2592 | } |
| 2593 | |
| 2594 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2595 | UNUSED(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2596 | LOG(FATAL) << "Unreachable"; |
| 2597 | } |
| 2598 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2599 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2600 | Primitive::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2601 | LocationSummary::CallKind call_kind = |
| 2602 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2603 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 2604 | |
| 2605 | switch (type) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2606 | case Primitive::kPrimInt: |
| 2607 | case Primitive::kPrimLong: |
| 2608 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2609 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2610 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2611 | break; |
| 2612 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2613 | case Primitive::kPrimFloat: |
| 2614 | case Primitive::kPrimDouble: { |
| 2615 | InvokeRuntimeCallingConvention calling_convention; |
| 2616 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 2617 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 2618 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 2619 | |
| 2620 | break; |
| 2621 | } |
| 2622 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2623 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2624 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2625 | } |
| 2626 | } |
| 2627 | |
| 2628 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
| 2629 | Primitive::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2630 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2631 | switch (type) { |
| 2632 | case Primitive::kPrimInt: |
| 2633 | case Primitive::kPrimLong: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2634 | GenerateDivRemIntegral(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2635 | break; |
| 2636 | } |
| 2637 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2638 | case Primitive::kPrimFloat: |
| 2639 | case Primitive::kPrimDouble: { |
| 2640 | int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf) |
| 2641 | : QUICK_ENTRY_POINT(pFmod); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2642 | codegen_->InvokeRuntime(entry_offset, rem, rem->GetDexPc(), nullptr); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2643 | break; |
| 2644 | } |
| 2645 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2646 | default: |
| 2647 | LOG(FATAL) << "Unexpected rem type " << type; |
| 2648 | } |
| 2649 | } |
| 2650 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2651 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2652 | memory_barrier->SetLocations(nullptr); |
| 2653 | } |
| 2654 | |
| 2655 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2656 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 2657 | } |
| 2658 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2659 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| 2660 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2661 | Primitive::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2662 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2663 | } |
| 2664 | |
| 2665 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2666 | UNUSED(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2667 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2668 | } |
| 2669 | |
| 2670 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 2671 | instruction->SetLocations(nullptr); |
| 2672 | } |
| 2673 | |
| 2674 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2675 | UNUSED(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2676 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2677 | } |
| 2678 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2679 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 2680 | HandleShift(shl); |
| 2681 | } |
| 2682 | |
| 2683 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 2684 | HandleShift(shl); |
| 2685 | } |
| 2686 | |
| 2687 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 2688 | HandleShift(shr); |
| 2689 | } |
| 2690 | |
| 2691 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 2692 | HandleShift(shr); |
| 2693 | } |
| 2694 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2695 | void LocationsBuilderARM64::VisitStoreLocal(HStoreLocal* store) { |
| 2696 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store); |
| 2697 | Primitive::Type field_type = store->InputAt(1)->GetType(); |
| 2698 | switch (field_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2699 | case Primitive::kPrimNot: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2700 | case Primitive::kPrimBoolean: |
| 2701 | case Primitive::kPrimByte: |
| 2702 | case Primitive::kPrimChar: |
| 2703 | case Primitive::kPrimShort: |
| 2704 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2705 | case Primitive::kPrimFloat: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2706 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 2707 | break; |
| 2708 | |
| 2709 | case Primitive::kPrimLong: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2710 | case Primitive::kPrimDouble: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2711 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 2712 | break; |
| 2713 | |
| 2714 | default: |
| 2715 | LOG(FATAL) << "Unimplemented local type " << field_type; |
| 2716 | } |
| 2717 | } |
| 2718 | |
| 2719 | void InstructionCodeGeneratorARM64::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2720 | UNUSED(store); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2721 | } |
| 2722 | |
| 2723 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2724 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2725 | } |
| 2726 | |
| 2727 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2728 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2729 | } |
| 2730 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2731 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2732 | HandleFieldGet(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2736 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2737 | } |
| 2738 | |
| 2739 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2740 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2741 | } |
| 2742 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2743 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame^] | 2744 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2745 | } |
| 2746 | |
| 2747 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 2748 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 2749 | } |
| 2750 | |
| 2751 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2752 | HBasicBlock* block = instruction->GetBlock(); |
| 2753 | if (block->GetLoopInformation() != nullptr) { |
| 2754 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 2755 | // The back edge will generate the suspend check. |
| 2756 | return; |
| 2757 | } |
| 2758 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 2759 | // The goto will generate the suspend check. |
| 2760 | return; |
| 2761 | } |
| 2762 | GenerateSuspendCheck(instruction, nullptr); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2763 | } |
| 2764 | |
| 2765 | void LocationsBuilderARM64::VisitTemporary(HTemporary* temp) { |
| 2766 | temp->SetLocations(nullptr); |
| 2767 | } |
| 2768 | |
| 2769 | void InstructionCodeGeneratorARM64::VisitTemporary(HTemporary* temp) { |
| 2770 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2771 | UNUSED(temp); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2772 | } |
| 2773 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2774 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| 2775 | LocationSummary* locations = |
| 2776 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2777 | InvokeRuntimeCallingConvention calling_convention; |
| 2778 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 2779 | } |
| 2780 | |
| 2781 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
| 2782 | codegen_->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2783 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2784 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2785 | } |
| 2786 | |
| 2787 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2788 | LocationSummary* locations = |
| 2789 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 2790 | Primitive::Type input_type = conversion->GetInputType(); |
| 2791 | Primitive::Type result_type = conversion->GetResultType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2792 | DCHECK_NE(input_type, result_type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2793 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 2794 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 2795 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 2796 | } |
| 2797 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2798 | if (Primitive::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2799 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2800 | } else { |
| 2801 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2802 | } |
| 2803 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2804 | if (Primitive::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2805 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2806 | } else { |
| 2807 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2808 | } |
| 2809 | } |
| 2810 | |
| 2811 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2812 | Primitive::Type result_type = conversion->GetResultType(); |
| 2813 | Primitive::Type input_type = conversion->GetInputType(); |
| 2814 | |
| 2815 | DCHECK_NE(input_type, result_type); |
| 2816 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2817 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2818 | int result_size = Primitive::ComponentSize(result_type); |
| 2819 | int input_size = Primitive::ComponentSize(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2820 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2821 | Register output = OutputRegister(conversion); |
| 2822 | Register source = InputRegisterAt(conversion, 0); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2823 | if ((result_type == Primitive::kPrimChar) && (input_size < result_size)) { |
| 2824 | __ Ubfx(output, source, 0, result_size * kBitsPerByte); |
| 2825 | } else if ((result_type == Primitive::kPrimChar) || |
| 2826 | ((input_type == Primitive::kPrimChar) && (result_size > input_size))) { |
| 2827 | __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2828 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2829 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2830 | } |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2831 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2832 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2833 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2834 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
| 2835 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2836 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 2837 | Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2838 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 2839 | } else { |
| 2840 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 2841 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2842 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2843 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2844 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2845 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 2846 | HandleShift(ushr); |
| 2847 | } |
| 2848 | |
| 2849 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 2850 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2851 | } |
| 2852 | |
| 2853 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 2854 | HandleBinaryOp(instruction); |
| 2855 | } |
| 2856 | |
| 2857 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 2858 | HandleBinaryOp(instruction); |
| 2859 | } |
| 2860 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 2861 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction) { |
| 2862 | // Nothing to do, this should be removed during prepare for register allocator. |
| 2863 | UNUSED(instruction); |
| 2864 | LOG(FATAL) << "Unreachable"; |
| 2865 | } |
| 2866 | |
| 2867 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction) { |
| 2868 | // Nothing to do, this should be removed during prepare for register allocator. |
| 2869 | UNUSED(instruction); |
| 2870 | LOG(FATAL) << "Unreachable"; |
| 2871 | } |
| 2872 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2873 | #undef __ |
| 2874 | #undef QUICK_ENTRY_POINT |
| 2875 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2876 | } // namespace arm64 |
| 2877 | } // namespace art |