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