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