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