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