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