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