Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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_mips64.h" |
| 18 | |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 19 | #include "art_method.h" |
| 20 | #include "code_generator_utils.h" |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 21 | #include "compiled_method.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
| 23 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
| 24 | #include "gc/accounting/card_table.h" |
| 25 | #include "intrinsics.h" |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 26 | #include "intrinsics_mips64.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 27 | #include "mirror/array-inl.h" |
| 28 | #include "mirror/class-inl.h" |
| 29 | #include "offsets.h" |
| 30 | #include "thread.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 31 | #include "utils/assembler.h" |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 32 | #include "utils/mips64/assembler_mips64.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 33 | #include "utils/stack_checks.h" |
| 34 | |
| 35 | namespace art { |
| 36 | namespace mips64 { |
| 37 | |
| 38 | static constexpr int kCurrentMethodStackOffset = 0; |
| 39 | static constexpr GpuRegister kMethodRegisterArgument = A0; |
| 40 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 41 | Location Mips64ReturnLocation(Primitive::Type return_type) { |
| 42 | switch (return_type) { |
| 43 | case Primitive::kPrimBoolean: |
| 44 | case Primitive::kPrimByte: |
| 45 | case Primitive::kPrimChar: |
| 46 | case Primitive::kPrimShort: |
| 47 | case Primitive::kPrimInt: |
| 48 | case Primitive::kPrimNot: |
| 49 | case Primitive::kPrimLong: |
| 50 | return Location::RegisterLocation(V0); |
| 51 | |
| 52 | case Primitive::kPrimFloat: |
| 53 | case Primitive::kPrimDouble: |
| 54 | return Location::FpuRegisterLocation(F0); |
| 55 | |
| 56 | case Primitive::kPrimVoid: |
| 57 | return Location(); |
| 58 | } |
| 59 | UNREACHABLE(); |
| 60 | } |
| 61 | |
| 62 | Location InvokeDexCallingConventionVisitorMIPS64::GetReturnLocation(Primitive::Type type) const { |
| 63 | return Mips64ReturnLocation(type); |
| 64 | } |
| 65 | |
| 66 | Location InvokeDexCallingConventionVisitorMIPS64::GetMethodLocation() const { |
| 67 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 68 | } |
| 69 | |
| 70 | Location InvokeDexCallingConventionVisitorMIPS64::GetNextLocation(Primitive::Type type) { |
| 71 | Location next_location; |
| 72 | if (type == Primitive::kPrimVoid) { |
| 73 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 74 | } |
| 75 | |
| 76 | if (Primitive::IsFloatingPointType(type) && |
| 77 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 78 | next_location = Location::FpuRegisterLocation( |
| 79 | calling_convention.GetFpuRegisterAt(float_index_++)); |
| 80 | gp_index_++; |
| 81 | } else if (!Primitive::IsFloatingPointType(type) && |
| 82 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| 83 | next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index_++)); |
| 84 | float_index_++; |
| 85 | } else { |
| 86 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
| 87 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 88 | : Location::StackSlot(stack_offset); |
| 89 | } |
| 90 | |
| 91 | // Space on the stack is reserved for all arguments. |
| 92 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
| 93 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 94 | return next_location; |
| 95 | } |
| 96 | |
| 97 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type type) { |
| 98 | return Mips64ReturnLocation(type); |
| 99 | } |
| 100 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 101 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 102 | #define __ down_cast<CodeGeneratorMIPS64*>(codegen)->GetAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 103 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, x).Int32Value() |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 104 | |
| 105 | class BoundsCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 106 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 107 | explicit BoundsCheckSlowPathMIPS64(HBoundsCheck* instruction) : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 108 | |
| 109 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 110 | LocationSummary* locations = instruction_->GetLocations(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 111 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 112 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 113 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 114 | // Live registers will be restored in the catch block if caught. |
| 115 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 116 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 117 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 118 | // move resolver. |
| 119 | InvokeRuntimeCallingConvention calling_convention; |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 120 | codegen->EmitParallelMoves(locations->InAt(0), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 121 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 122 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 123 | locations->InAt(1), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 124 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 125 | Primitive::kPrimInt); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 126 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 127 | ? kQuickThrowStringBounds |
| 128 | : kQuickThrowArrayBounds; |
| 129 | mips64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 130 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 131 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 132 | } |
| 133 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 134 | bool IsFatal() const OVERRIDE { return true; } |
| 135 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 136 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS64"; } |
| 137 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 138 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 139 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS64); |
| 140 | }; |
| 141 | |
| 142 | class DivZeroCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 143 | public: |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 144 | explicit DivZeroCheckSlowPathMIPS64(HDivZeroCheck* instruction) |
| 145 | : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 146 | |
| 147 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 148 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 149 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 150 | mips64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 151 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 152 | } |
| 153 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 154 | bool IsFatal() const OVERRIDE { return true; } |
| 155 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 156 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS64"; } |
| 157 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 158 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 159 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS64); |
| 160 | }; |
| 161 | |
| 162 | class LoadClassSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 163 | public: |
| 164 | LoadClassSlowPathMIPS64(HLoadClass* cls, |
| 165 | HInstruction* at, |
| 166 | uint32_t dex_pc, |
| 167 | bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 168 | : SlowPathCodeMIPS64(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 169 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 170 | } |
| 171 | |
| 172 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 173 | LocationSummary* locations = instruction_->GetLocations(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 174 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 175 | |
| 176 | __ Bind(GetEntryLabel()); |
| 177 | SaveLiveRegisters(codegen, locations); |
| 178 | |
| 179 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 180 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 181 | __ LoadConst32(calling_convention.GetRegisterAt(0), type_index.index_); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 182 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 183 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 184 | mips64_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 185 | if (do_clinit_) { |
| 186 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 187 | } else { |
| 188 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 189 | } |
| 190 | |
| 191 | // Move the class to the desired location. |
| 192 | Location out = locations->Out(); |
| 193 | if (out.IsValid()) { |
| 194 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 195 | Primitive::Type type = instruction_->GetType(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 196 | mips64_codegen->MoveLocation(out, |
| 197 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 198 | type); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 202 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 203 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 204 | if (cls_ == instruction_ && cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 205 | DCHECK(out.IsValid()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 206 | CodeGeneratorMIPS64::PcRelativePatchInfo* info = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 207 | mips64_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 208 | mips64_codegen->EmitPcRelativeAddressPlaceholderHigh(info, AT); |
| 209 | __ Sw(out.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678); |
| 210 | } |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 211 | __ Bc(GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 214 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS64"; } |
| 215 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 216 | private: |
| 217 | // The class this slow path will load. |
| 218 | HLoadClass* const cls_; |
| 219 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 220 | // The dex PC of `at_`. |
| 221 | const uint32_t dex_pc_; |
| 222 | |
| 223 | // Whether to initialize the class. |
| 224 | const bool do_clinit_; |
| 225 | |
| 226 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS64); |
| 227 | }; |
| 228 | |
| 229 | class LoadStringSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 230 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 231 | explicit LoadStringSlowPathMIPS64(HLoadString* instruction) : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 232 | |
| 233 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 234 | LocationSummary* locations = instruction_->GetLocations(); |
| 235 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 236 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 237 | |
| 238 | __ Bind(GetEntryLabel()); |
| 239 | SaveLiveRegisters(codegen, locations); |
| 240 | |
| 241 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 242 | HLoadString* load = instruction_->AsLoadString(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 243 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 244 | __ LoadConst32(calling_convention.GetRegisterAt(0), string_index.index_); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 245 | mips64_codegen->InvokeRuntime(kQuickResolveString, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 246 | instruction_, |
| 247 | instruction_->GetDexPc(), |
| 248 | this); |
| 249 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 250 | Primitive::Type type = instruction_->GetType(); |
| 251 | mips64_codegen->MoveLocation(locations->Out(), |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 252 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 253 | type); |
| 254 | |
| 255 | RestoreLiveRegisters(codegen, locations); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 256 | |
| 257 | // Store the resolved String to the BSS entry. |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 258 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 259 | CodeGeneratorMIPS64::PcRelativePatchInfo* info = |
| 260 | mips64_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index); |
| 261 | mips64_codegen->EmitPcRelativeAddressPlaceholderHigh(info, AT); |
| 262 | __ Sw(out, AT, /* placeholder */ 0x5678); |
| 263 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 264 | __ Bc(GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 267 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS64"; } |
| 268 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 269 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 270 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS64); |
| 271 | }; |
| 272 | |
| 273 | class NullCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 274 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 275 | explicit NullCheckSlowPathMIPS64(HNullCheck* instr) : SlowPathCodeMIPS64(instr) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 276 | |
| 277 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 278 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 279 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 280 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 281 | // Live registers will be restored in the catch block if caught. |
| 282 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 283 | } |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 284 | mips64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 285 | instruction_, |
| 286 | instruction_->GetDexPc(), |
| 287 | this); |
| 288 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 289 | } |
| 290 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 291 | bool IsFatal() const OVERRIDE { return true; } |
| 292 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 293 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS64"; } |
| 294 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 295 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 296 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS64); |
| 297 | }; |
| 298 | |
| 299 | class SuspendCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 300 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 301 | SuspendCheckSlowPathMIPS64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 302 | : SlowPathCodeMIPS64(instruction), successor_(successor) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 303 | |
| 304 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame^] | 305 | LocationSummary* locations = instruction_->GetLocations(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 306 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 307 | __ Bind(GetEntryLabel()); |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame^] | 308 | SaveLiveRegisters(codegen, locations); // Only saves live vector registers for SIMD. |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 309 | mips64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 310 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame^] | 311 | RestoreLiveRegisters(codegen, locations); // Only restores live vector registers for SIMD. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 312 | if (successor_ == nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 313 | __ Bc(GetReturnLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 314 | } else { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 315 | __ Bc(mips64_codegen->GetLabelOf(successor_)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 319 | Mips64Label* GetReturnLabel() { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 320 | DCHECK(successor_ == nullptr); |
| 321 | return &return_label_; |
| 322 | } |
| 323 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 324 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS64"; } |
| 325 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 326 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 327 | // If not null, the block to branch to after the suspend check. |
| 328 | HBasicBlock* const successor_; |
| 329 | |
| 330 | // If `successor_` is null, the label to branch to after the suspend check. |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 331 | Mips64Label return_label_; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 332 | |
| 333 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS64); |
| 334 | }; |
| 335 | |
| 336 | class TypeCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 337 | public: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 338 | explicit TypeCheckSlowPathMIPS64(HInstruction* instruction, bool is_fatal) |
| 339 | : SlowPathCodeMIPS64(instruction), is_fatal_(is_fatal) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 340 | |
| 341 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 342 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 343 | |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 344 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 345 | DCHECK(instruction_->IsCheckCast() |
| 346 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 347 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 348 | |
| 349 | __ Bind(GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 350 | if (!is_fatal_) { |
| 351 | SaveLiveRegisters(codegen, locations); |
| 352 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 353 | |
| 354 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 355 | // move resolver. |
| 356 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 357 | codegen->EmitParallelMoves(locations->InAt(0), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 358 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 359 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 360 | locations->InAt(1), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 361 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 362 | Primitive::kPrimNot); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 363 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 364 | mips64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 365 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 366 | Primitive::Type ret_type = instruction_->GetType(); |
| 367 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 368 | mips64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 369 | } else { |
| 370 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 371 | mips64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 372 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 375 | if (!is_fatal_) { |
| 376 | RestoreLiveRegisters(codegen, locations); |
| 377 | __ Bc(GetExitLabel()); |
| 378 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 381 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS64"; } |
| 382 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 383 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 384 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 385 | private: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 386 | const bool is_fatal_; |
| 387 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 388 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS64); |
| 389 | }; |
| 390 | |
| 391 | class DeoptimizationSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 392 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 393 | explicit DeoptimizationSlowPathMIPS64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 394 | : SlowPathCodeMIPS64(instruction) {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 395 | |
| 396 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 397 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 398 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 399 | mips64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 400 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 403 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS64"; } |
| 404 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 405 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 406 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS64); |
| 407 | }; |
| 408 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 409 | class ArraySetSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 410 | public: |
| 411 | explicit ArraySetSlowPathMIPS64(HInstruction* instruction) : SlowPathCodeMIPS64(instruction) {} |
| 412 | |
| 413 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 414 | LocationSummary* locations = instruction_->GetLocations(); |
| 415 | __ Bind(GetEntryLabel()); |
| 416 | SaveLiveRegisters(codegen, locations); |
| 417 | |
| 418 | InvokeRuntimeCallingConvention calling_convention; |
| 419 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 420 | parallel_move.AddMove( |
| 421 | locations->InAt(0), |
| 422 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 423 | Primitive::kPrimNot, |
| 424 | nullptr); |
| 425 | parallel_move.AddMove( |
| 426 | locations->InAt(1), |
| 427 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 428 | Primitive::kPrimInt, |
| 429 | nullptr); |
| 430 | parallel_move.AddMove( |
| 431 | locations->InAt(2), |
| 432 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 433 | Primitive::kPrimNot, |
| 434 | nullptr); |
| 435 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 436 | |
| 437 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 438 | mips64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 439 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 440 | RestoreLiveRegisters(codegen, locations); |
| 441 | __ Bc(GetExitLabel()); |
| 442 | } |
| 443 | |
| 444 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathMIPS64"; } |
| 445 | |
| 446 | private: |
| 447 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathMIPS64); |
| 448 | }; |
| 449 | |
| 450 | // Slow path marking an object reference `ref` during a read |
| 451 | // barrier. The field `obj.field` in the object `obj` holding this |
| 452 | // reference does not get updated by this slow path after marking (see |
| 453 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 below for that). |
| 454 | // |
| 455 | // This means that after the execution of this slow path, `ref` will |
| 456 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 457 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 458 | // probably still be a from-space reference (unless it gets updated by |
| 459 | // another thread, or if another thread installed another object |
| 460 | // reference (different from `ref`) in `obj.field`). |
| 461 | // |
| 462 | // If `entrypoint` is a valid location it is assumed to already be |
| 463 | // holding the entrypoint. The case where the entrypoint is passed in |
| 464 | // is for the GcRoot read barrier. |
| 465 | class ReadBarrierMarkSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 466 | public: |
| 467 | ReadBarrierMarkSlowPathMIPS64(HInstruction* instruction, |
| 468 | Location ref, |
| 469 | Location entrypoint = Location::NoLocation()) |
| 470 | : SlowPathCodeMIPS64(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 471 | DCHECK(kEmitCompilerReadBarrier); |
| 472 | } |
| 473 | |
| 474 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathMIPS"; } |
| 475 | |
| 476 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 477 | LocationSummary* locations = instruction_->GetLocations(); |
| 478 | GpuRegister ref_reg = ref_.AsRegister<GpuRegister>(); |
| 479 | DCHECK(locations->CanCall()); |
| 480 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 481 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 482 | instruction_->IsStaticFieldGet() || |
| 483 | instruction_->IsArrayGet() || |
| 484 | instruction_->IsArraySet() || |
| 485 | instruction_->IsLoadClass() || |
| 486 | instruction_->IsLoadString() || |
| 487 | instruction_->IsInstanceOf() || |
| 488 | instruction_->IsCheckCast() || |
| 489 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 490 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 491 | << "Unexpected instruction in read barrier marking slow path: " |
| 492 | << instruction_->DebugName(); |
| 493 | |
| 494 | __ Bind(GetEntryLabel()); |
| 495 | // No need to save live registers; it's taken care of by the |
| 496 | // entrypoint. Also, there is no need to update the stack mask, |
| 497 | // as this runtime call will not trigger a garbage collection. |
| 498 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 499 | DCHECK((V0 <= ref_reg && ref_reg <= T2) || |
| 500 | (S2 <= ref_reg && ref_reg <= S7) || |
| 501 | (ref_reg == S8)) << ref_reg; |
| 502 | // "Compact" slow path, saving two moves. |
| 503 | // |
| 504 | // Instead of using the standard runtime calling convention (input |
| 505 | // and output in A0 and V0 respectively): |
| 506 | // |
| 507 | // A0 <- ref |
| 508 | // V0 <- ReadBarrierMark(A0) |
| 509 | // ref <- V0 |
| 510 | // |
| 511 | // we just use rX (the register containing `ref`) as input and output |
| 512 | // of a dedicated entrypoint: |
| 513 | // |
| 514 | // rX <- ReadBarrierMarkRegX(rX) |
| 515 | // |
| 516 | if (entrypoint_.IsValid()) { |
| 517 | mips64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 518 | DCHECK_EQ(entrypoint_.AsRegister<GpuRegister>(), T9); |
| 519 | __ Jalr(entrypoint_.AsRegister<GpuRegister>()); |
| 520 | __ Nop(); |
| 521 | } else { |
| 522 | int32_t entry_point_offset = |
| 523 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(ref_reg - 1); |
| 524 | // This runtime call does not require a stack map. |
| 525 | mips64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 526 | instruction_, |
| 527 | this); |
| 528 | } |
| 529 | __ Bc(GetExitLabel()); |
| 530 | } |
| 531 | |
| 532 | private: |
| 533 | // The location (register) of the marked object reference. |
| 534 | const Location ref_; |
| 535 | |
| 536 | // The location of the entrypoint if already loaded. |
| 537 | const Location entrypoint_; |
| 538 | |
| 539 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathMIPS64); |
| 540 | }; |
| 541 | |
| 542 | // Slow path marking an object reference `ref` during a read barrier, |
| 543 | // and if needed, atomically updating the field `obj.field` in the |
| 544 | // object `obj` holding this reference after marking (contrary to |
| 545 | // ReadBarrierMarkSlowPathMIPS64 above, which never tries to update |
| 546 | // `obj.field`). |
| 547 | // |
| 548 | // This means that after the execution of this slow path, both `ref` |
| 549 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 550 | // hold the same to-space reference (unless another thread installed |
| 551 | // another object reference (different from `ref`) in `obj.field`). |
| 552 | class ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 553 | public: |
| 554 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS64(HInstruction* instruction, |
| 555 | Location ref, |
| 556 | GpuRegister obj, |
| 557 | Location field_offset, |
| 558 | GpuRegister temp1) |
| 559 | : SlowPathCodeMIPS64(instruction), |
| 560 | ref_(ref), |
| 561 | obj_(obj), |
| 562 | field_offset_(field_offset), |
| 563 | temp1_(temp1) { |
| 564 | DCHECK(kEmitCompilerReadBarrier); |
| 565 | } |
| 566 | |
| 567 | const char* GetDescription() const OVERRIDE { |
| 568 | return "ReadBarrierMarkAndUpdateFieldSlowPathMIPS64"; |
| 569 | } |
| 570 | |
| 571 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 572 | LocationSummary* locations = instruction_->GetLocations(); |
| 573 | GpuRegister ref_reg = ref_.AsRegister<GpuRegister>(); |
| 574 | DCHECK(locations->CanCall()); |
| 575 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 576 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 577 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 578 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 579 | << instruction_->DebugName(); |
| 580 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 581 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 582 | DCHECK(field_offset_.IsRegister()) << field_offset_; |
| 583 | |
| 584 | __ Bind(GetEntryLabel()); |
| 585 | |
| 586 | // Save the old reference. |
| 587 | // Note that we cannot use AT or TMP to save the old reference, as those |
| 588 | // are used by the code that follows, but we need the old reference after |
| 589 | // the call to the ReadBarrierMarkRegX entry point. |
| 590 | DCHECK_NE(temp1_, AT); |
| 591 | DCHECK_NE(temp1_, TMP); |
| 592 | __ Move(temp1_, ref_reg); |
| 593 | |
| 594 | // No need to save live registers; it's taken care of by the |
| 595 | // entrypoint. Also, there is no need to update the stack mask, |
| 596 | // as this runtime call will not trigger a garbage collection. |
| 597 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 598 | DCHECK((V0 <= ref_reg && ref_reg <= T2) || |
| 599 | (S2 <= ref_reg && ref_reg <= S7) || |
| 600 | (ref_reg == S8)) << ref_reg; |
| 601 | // "Compact" slow path, saving two moves. |
| 602 | // |
| 603 | // Instead of using the standard runtime calling convention (input |
| 604 | // and output in A0 and V0 respectively): |
| 605 | // |
| 606 | // A0 <- ref |
| 607 | // V0 <- ReadBarrierMark(A0) |
| 608 | // ref <- V0 |
| 609 | // |
| 610 | // we just use rX (the register containing `ref`) as input and output |
| 611 | // of a dedicated entrypoint: |
| 612 | // |
| 613 | // rX <- ReadBarrierMarkRegX(rX) |
| 614 | // |
| 615 | int32_t entry_point_offset = |
| 616 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(ref_reg - 1); |
| 617 | // This runtime call does not require a stack map. |
| 618 | mips64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 619 | instruction_, |
| 620 | this); |
| 621 | |
| 622 | // If the new reference is different from the old reference, |
| 623 | // update the field in the holder (`*(obj_ + field_offset_)`). |
| 624 | // |
| 625 | // Note that this field could also hold a different object, if |
| 626 | // another thread had concurrently changed it. In that case, the |
| 627 | // the compare-and-set (CAS) loop below would abort, leaving the |
| 628 | // field as-is. |
| 629 | Mips64Label done; |
| 630 | __ Beqc(temp1_, ref_reg, &done); |
| 631 | |
| 632 | // Update the the holder's field atomically. This may fail if |
| 633 | // mutator updates before us, but it's OK. This is achieved |
| 634 | // using a strong compare-and-set (CAS) operation with relaxed |
| 635 | // memory synchronization ordering, where the expected value is |
| 636 | // the old reference and the desired value is the new reference. |
| 637 | |
| 638 | // Convenience aliases. |
| 639 | GpuRegister base = obj_; |
| 640 | GpuRegister offset = field_offset_.AsRegister<GpuRegister>(); |
| 641 | GpuRegister expected = temp1_; |
| 642 | GpuRegister value = ref_reg; |
| 643 | GpuRegister tmp_ptr = TMP; // Pointer to actual memory. |
| 644 | GpuRegister tmp = AT; // Value in memory. |
| 645 | |
| 646 | __ Daddu(tmp_ptr, base, offset); |
| 647 | |
| 648 | if (kPoisonHeapReferences) { |
| 649 | __ PoisonHeapReference(expected); |
| 650 | // Do not poison `value` if it is the same register as |
| 651 | // `expected`, which has just been poisoned. |
| 652 | if (value != expected) { |
| 653 | __ PoisonHeapReference(value); |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | // do { |
| 658 | // tmp = [r_ptr] - expected; |
| 659 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 660 | |
| 661 | Mips64Label loop_head, exit_loop; |
| 662 | __ Bind(&loop_head); |
| 663 | __ Ll(tmp, tmp_ptr); |
| 664 | // The LL instruction sign-extends the 32-bit value, but |
| 665 | // 32-bit references must be zero-extended. Zero-extend `tmp`. |
| 666 | __ Dext(tmp, tmp, 0, 32); |
| 667 | __ Bnec(tmp, expected, &exit_loop); |
| 668 | __ Move(tmp, value); |
| 669 | __ Sc(tmp, tmp_ptr); |
| 670 | __ Beqzc(tmp, &loop_head); |
| 671 | __ Bind(&exit_loop); |
| 672 | |
| 673 | if (kPoisonHeapReferences) { |
| 674 | __ UnpoisonHeapReference(expected); |
| 675 | // Do not unpoison `value` if it is the same register as |
| 676 | // `expected`, which has just been unpoisoned. |
| 677 | if (value != expected) { |
| 678 | __ UnpoisonHeapReference(value); |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | __ Bind(&done); |
| 683 | __ Bc(GetExitLabel()); |
| 684 | } |
| 685 | |
| 686 | private: |
| 687 | // The location (register) of the marked object reference. |
| 688 | const Location ref_; |
| 689 | // The register containing the object holding the marked object reference field. |
| 690 | const GpuRegister obj_; |
| 691 | // The location of the offset of the marked reference field within `obj_`. |
| 692 | Location field_offset_; |
| 693 | |
| 694 | const GpuRegister temp1_; |
| 695 | |
| 696 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathMIPS64); |
| 697 | }; |
| 698 | |
| 699 | // Slow path generating a read barrier for a heap reference. |
| 700 | class ReadBarrierForHeapReferenceSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 701 | public: |
| 702 | ReadBarrierForHeapReferenceSlowPathMIPS64(HInstruction* instruction, |
| 703 | Location out, |
| 704 | Location ref, |
| 705 | Location obj, |
| 706 | uint32_t offset, |
| 707 | Location index) |
| 708 | : SlowPathCodeMIPS64(instruction), |
| 709 | out_(out), |
| 710 | ref_(ref), |
| 711 | obj_(obj), |
| 712 | offset_(offset), |
| 713 | index_(index) { |
| 714 | DCHECK(kEmitCompilerReadBarrier); |
| 715 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 716 | // has been overwritten by (or after) the heap object reference load |
| 717 | // to be instrumented, e.g.: |
| 718 | // |
| 719 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 720 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 721 | // |
| 722 | // In that case, we have lost the information about the original |
| 723 | // object, and the emitted read barrier cannot work properly. |
| 724 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 725 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 726 | } |
| 727 | |
| 728 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 729 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 730 | LocationSummary* locations = instruction_->GetLocations(); |
| 731 | Primitive::Type type = Primitive::kPrimNot; |
| 732 | GpuRegister reg_out = out_.AsRegister<GpuRegister>(); |
| 733 | DCHECK(locations->CanCall()); |
| 734 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 735 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 736 | instruction_->IsStaticFieldGet() || |
| 737 | instruction_->IsArrayGet() || |
| 738 | instruction_->IsInstanceOf() || |
| 739 | instruction_->IsCheckCast() || |
| 740 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 741 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 742 | << instruction_->DebugName(); |
| 743 | |
| 744 | __ Bind(GetEntryLabel()); |
| 745 | SaveLiveRegisters(codegen, locations); |
| 746 | |
| 747 | // We may have to change the index's value, but as `index_` is a |
| 748 | // constant member (like other "inputs" of this slow path), |
| 749 | // introduce a copy of it, `index`. |
| 750 | Location index = index_; |
| 751 | if (index_.IsValid()) { |
| 752 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 753 | if (instruction_->IsArrayGet()) { |
| 754 | // Compute the actual memory offset and store it in `index`. |
| 755 | GpuRegister index_reg = index_.AsRegister<GpuRegister>(); |
| 756 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 757 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 758 | // We are about to change the value of `index_reg` (see the |
| 759 | // calls to art::mips64::Mips64Assembler::Sll and |
| 760 | // art::mips64::MipsAssembler::Addiu32 below), but it has |
| 761 | // not been saved by the previous call to |
| 762 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 763 | // callee-save register -- |
| 764 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 765 | // callee-save registers, as it has been designed with the |
| 766 | // assumption that callee-save registers are supposed to be |
| 767 | // handled by the called function. So, as a callee-save |
| 768 | // register, `index_reg` _would_ eventually be saved onto |
| 769 | // the stack, but it would be too late: we would have |
| 770 | // changed its value earlier. Therefore, we manually save |
| 771 | // it here into another freely available register, |
| 772 | // `free_reg`, chosen of course among the caller-save |
| 773 | // registers (as a callee-save `free_reg` register would |
| 774 | // exhibit the same problem). |
| 775 | // |
| 776 | // Note we could have requested a temporary register from |
| 777 | // the register allocator instead; but we prefer not to, as |
| 778 | // this is a slow path, and we know we can find a |
| 779 | // caller-save register that is available. |
| 780 | GpuRegister free_reg = FindAvailableCallerSaveRegister(codegen); |
| 781 | __ Move(free_reg, index_reg); |
| 782 | index_reg = free_reg; |
| 783 | index = Location::RegisterLocation(index_reg); |
| 784 | } else { |
| 785 | // The initial register stored in `index_` has already been |
| 786 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 787 | // (as it is not a callee-save register), so we can freely |
| 788 | // use it. |
| 789 | } |
| 790 | // Shifting the index value contained in `index_reg` by the scale |
| 791 | // factor (2) cannot overflow in practice, as the runtime is |
| 792 | // unable to allocate object arrays with a size larger than |
| 793 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 794 | __ Sll(index_reg, index_reg, TIMES_4); |
| 795 | static_assert( |
| 796 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 797 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 798 | __ Addiu32(index_reg, index_reg, offset_); |
| 799 | } else { |
| 800 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 801 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 802 | // (as in the case of ArrayGet), as it is actually an offset |
| 803 | // to an object field within an object. |
| 804 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 805 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 806 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 807 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 808 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 809 | DCHECK_EQ(offset_, 0U); |
| 810 | DCHECK(index_.IsRegister()); |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | // We're moving two or three locations to locations that could |
| 815 | // overlap, so we need a parallel move resolver. |
| 816 | InvokeRuntimeCallingConvention calling_convention; |
| 817 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 818 | parallel_move.AddMove(ref_, |
| 819 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 820 | Primitive::kPrimNot, |
| 821 | nullptr); |
| 822 | parallel_move.AddMove(obj_, |
| 823 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 824 | Primitive::kPrimNot, |
| 825 | nullptr); |
| 826 | if (index.IsValid()) { |
| 827 | parallel_move.AddMove(index, |
| 828 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 829 | Primitive::kPrimInt, |
| 830 | nullptr); |
| 831 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 832 | } else { |
| 833 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 834 | __ LoadConst32(calling_convention.GetRegisterAt(2), offset_); |
| 835 | } |
| 836 | mips64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
| 837 | instruction_, |
| 838 | instruction_->GetDexPc(), |
| 839 | this); |
| 840 | CheckEntrypointTypes< |
| 841 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 842 | mips64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 843 | |
| 844 | RestoreLiveRegisters(codegen, locations); |
| 845 | __ Bc(GetExitLabel()); |
| 846 | } |
| 847 | |
| 848 | const char* GetDescription() const OVERRIDE { |
| 849 | return "ReadBarrierForHeapReferenceSlowPathMIPS64"; |
| 850 | } |
| 851 | |
| 852 | private: |
| 853 | GpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 854 | size_t ref = static_cast<int>(ref_.AsRegister<GpuRegister>()); |
| 855 | size_t obj = static_cast<int>(obj_.AsRegister<GpuRegister>()); |
| 856 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 857 | if (i != ref && |
| 858 | i != obj && |
| 859 | !codegen->IsCoreCalleeSaveRegister(i) && |
| 860 | !codegen->IsBlockedCoreRegister(i)) { |
| 861 | return static_cast<GpuRegister>(i); |
| 862 | } |
| 863 | } |
| 864 | // We shall never fail to find a free caller-save register, as |
| 865 | // there are more than two core caller-save registers on MIPS64 |
| 866 | // (meaning it is possible to find one which is different from |
| 867 | // `ref` and `obj`). |
| 868 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 869 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 870 | UNREACHABLE(); |
| 871 | } |
| 872 | |
| 873 | const Location out_; |
| 874 | const Location ref_; |
| 875 | const Location obj_; |
| 876 | const uint32_t offset_; |
| 877 | // An additional location containing an index to an array. |
| 878 | // Only used for HArrayGet and the UnsafeGetObject & |
| 879 | // UnsafeGetObjectVolatile intrinsics. |
| 880 | const Location index_; |
| 881 | |
| 882 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathMIPS64); |
| 883 | }; |
| 884 | |
| 885 | // Slow path generating a read barrier for a GC root. |
| 886 | class ReadBarrierForRootSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 887 | public: |
| 888 | ReadBarrierForRootSlowPathMIPS64(HInstruction* instruction, Location out, Location root) |
| 889 | : SlowPathCodeMIPS64(instruction), out_(out), root_(root) { |
| 890 | DCHECK(kEmitCompilerReadBarrier); |
| 891 | } |
| 892 | |
| 893 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 894 | LocationSummary* locations = instruction_->GetLocations(); |
| 895 | Primitive::Type type = Primitive::kPrimNot; |
| 896 | GpuRegister reg_out = out_.AsRegister<GpuRegister>(); |
| 897 | DCHECK(locations->CanCall()); |
| 898 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 899 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 900 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 901 | << instruction_->DebugName(); |
| 902 | |
| 903 | __ Bind(GetEntryLabel()); |
| 904 | SaveLiveRegisters(codegen, locations); |
| 905 | |
| 906 | InvokeRuntimeCallingConvention calling_convention; |
| 907 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 908 | mips64_codegen->MoveLocation(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 909 | root_, |
| 910 | Primitive::kPrimNot); |
| 911 | mips64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 912 | instruction_, |
| 913 | instruction_->GetDexPc(), |
| 914 | this); |
| 915 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 916 | mips64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 917 | |
| 918 | RestoreLiveRegisters(codegen, locations); |
| 919 | __ Bc(GetExitLabel()); |
| 920 | } |
| 921 | |
| 922 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathMIPS64"; } |
| 923 | |
| 924 | private: |
| 925 | const Location out_; |
| 926 | const Location root_; |
| 927 | |
| 928 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathMIPS64); |
| 929 | }; |
| 930 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 931 | CodeGeneratorMIPS64::CodeGeneratorMIPS64(HGraph* graph, |
| 932 | const Mips64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 933 | const CompilerOptions& compiler_options, |
| 934 | OptimizingCompilerStats* stats) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 935 | : CodeGenerator(graph, |
| 936 | kNumberOfGpuRegisters, |
| 937 | kNumberOfFpuRegisters, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 938 | /* number_of_register_pairs */ 0, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 939 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 940 | arraysize(kCoreCalleeSaves)), |
| 941 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 942 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 943 | compiler_options, |
| 944 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 945 | block_labels_(nullptr), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 946 | location_builder_(graph, this), |
| 947 | instruction_visitor_(graph, this), |
| 948 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 949 | assembler_(graph->GetArena()), |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 950 | isa_features_(isa_features), |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 951 | uint32_literals_(std::less<uint32_t>(), |
| 952 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 953 | uint64_literals_(std::less<uint64_t>(), |
| 954 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 955 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 956 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 957 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 958 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 959 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 960 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 961 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 962 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 963 | jit_string_patches_(StringReferenceValueComparator(), |
| 964 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 965 | jit_class_patches_(TypeReferenceValueComparator(), |
| 966 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 967 | // Save RA (containing the return address) to mimic Quick. |
| 968 | AddAllocatedRegister(Location::RegisterLocation(RA)); |
| 969 | } |
| 970 | |
| 971 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 972 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 973 | #define __ down_cast<Mips64Assembler*>(GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 974 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, x).Int32Value() |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 975 | |
| 976 | void CodeGeneratorMIPS64::Finalize(CodeAllocator* allocator) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 977 | // Ensure that we fix up branches. |
| 978 | __ FinalizeCode(); |
| 979 | |
| 980 | // Adjust native pc offsets in stack maps. |
| 981 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 982 | uint32_t old_position = |
| 983 | stack_map_stream_.GetStackMap(i).native_pc_code_offset.Uint32Value(kMips64); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 984 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 985 | DCHECK_GE(new_position, old_position); |
| 986 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 987 | } |
| 988 | |
| 989 | // Adjust pc offsets for the disassembly information. |
| 990 | if (disasm_info_ != nullptr) { |
| 991 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 992 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 993 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 994 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 995 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 996 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 997 | } |
| 998 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 999 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1000 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1001 | } |
| 1002 | } |
| 1003 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1004 | CodeGenerator::Finalize(allocator); |
| 1005 | } |
| 1006 | |
| 1007 | Mips64Assembler* ParallelMoveResolverMIPS64::GetAssembler() const { |
| 1008 | return codegen_->GetAssembler(); |
| 1009 | } |
| 1010 | |
| 1011 | void ParallelMoveResolverMIPS64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1012 | MoveOperands* move = moves_[index]; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1013 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); |
| 1014 | } |
| 1015 | |
| 1016 | void ParallelMoveResolverMIPS64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1017 | MoveOperands* move = moves_[index]; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1018 | codegen_->SwapLocations(move->GetDestination(), move->GetSource(), move->GetType()); |
| 1019 | } |
| 1020 | |
| 1021 | void ParallelMoveResolverMIPS64::RestoreScratch(int reg) { |
| 1022 | // Pop reg |
| 1023 | __ Ld(GpuRegister(reg), SP, 0); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1024 | __ DecreaseFrameSize(kMips64DoublewordSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | void ParallelMoveResolverMIPS64::SpillScratch(int reg) { |
| 1028 | // Push reg |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1029 | __ IncreaseFrameSize(kMips64DoublewordSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1030 | __ Sd(GpuRegister(reg), SP, 0); |
| 1031 | } |
| 1032 | |
| 1033 | void ParallelMoveResolverMIPS64::Exchange(int index1, int index2, bool double_slot) { |
| 1034 | LoadOperandType load_type = double_slot ? kLoadDoubleword : kLoadWord; |
| 1035 | StoreOperandType store_type = double_slot ? kStoreDoubleword : kStoreWord; |
| 1036 | // Allocate a scratch register other than TMP, if available. |
| 1037 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be |
| 1038 | // automatically unspilled when the scratch scope object is destroyed). |
| 1039 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); |
| 1040 | // If V0 spills onto the stack, SP-relative offsets need to be adjusted. |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1041 | int stack_offset = ensure_scratch.IsSpilled() ? kMips64DoublewordSize : 0; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1042 | __ LoadFromOffset(load_type, |
| 1043 | GpuRegister(ensure_scratch.GetRegister()), |
| 1044 | SP, |
| 1045 | index1 + stack_offset); |
| 1046 | __ LoadFromOffset(load_type, |
| 1047 | TMP, |
| 1048 | SP, |
| 1049 | index2 + stack_offset); |
| 1050 | __ StoreToOffset(store_type, |
| 1051 | GpuRegister(ensure_scratch.GetRegister()), |
| 1052 | SP, |
| 1053 | index2 + stack_offset); |
| 1054 | __ StoreToOffset(store_type, TMP, SP, index1 + stack_offset); |
| 1055 | } |
| 1056 | |
| 1057 | static dwarf::Reg DWARFReg(GpuRegister reg) { |
| 1058 | return dwarf::Reg::Mips64Core(static_cast<int>(reg)); |
| 1059 | } |
| 1060 | |
David Srbecky | ba70200 | 2016-02-01 18:15:29 +0000 | [diff] [blame] | 1061 | static dwarf::Reg DWARFReg(FpuRegister reg) { |
| 1062 | return dwarf::Reg::Mips64Fp(static_cast<int>(reg)); |
| 1063 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1064 | |
| 1065 | void CodeGeneratorMIPS64::GenerateFrameEntry() { |
| 1066 | __ Bind(&frame_entry_label_); |
| 1067 | |
| 1068 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips64) || !IsLeafMethod(); |
| 1069 | |
| 1070 | if (do_overflow_check) { |
| 1071 | __ LoadFromOffset(kLoadWord, |
| 1072 | ZERO, |
| 1073 | SP, |
| 1074 | -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips64))); |
| 1075 | RecordPcInfo(nullptr, 0); |
| 1076 | } |
| 1077 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1078 | if (HasEmptyFrame()) { |
| 1079 | return; |
| 1080 | } |
| 1081 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1082 | // Make sure the frame size isn't unreasonably large. |
| 1083 | if (GetFrameSize() > GetStackOverflowReservedBytes(kMips64)) { |
| 1084 | LOG(FATAL) << "Stack frame larger than " << GetStackOverflowReservedBytes(kMips64) << " bytes"; |
| 1085 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1086 | |
| 1087 | // Spill callee-saved registers. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1088 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1089 | uint32_t ofs = GetFrameSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1090 | __ IncreaseFrameSize(ofs); |
| 1091 | |
| 1092 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1093 | GpuRegister reg = kCoreCalleeSaves[i]; |
| 1094 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1095 | ofs -= kMips64DoublewordSize; |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1096 | __ StoreToOffset(kStoreDoubleword, reg, SP, ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1097 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1102 | FpuRegister reg = kFpuCalleeSaves[i]; |
| 1103 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1104 | ofs -= kMips64DoublewordSize; |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1105 | __ StoreFpuToOffset(kStoreDoubleword, reg, SP, ofs); |
David Srbecky | ba70200 | 2016-02-01 18:15:29 +0000 | [diff] [blame] | 1106 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1107 | } |
| 1108 | } |
| 1109 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1110 | // Save the current method if we need it. Note that we do not |
| 1111 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1112 | // in the SSA graph. |
| 1113 | if (RequiresCurrentMethod()) { |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1114 | __ StoreToOffset(kStoreDoubleword, kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1115 | } |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 1116 | |
| 1117 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1118 | // Initialize should_deoptimize flag to 0. |
| 1119 | __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 1120 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | void CodeGeneratorMIPS64::GenerateFrameExit() { |
| 1124 | __ cfi().RememberState(); |
| 1125 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1126 | if (!HasEmptyFrame()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1127 | // Restore callee-saved registers. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1128 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1129 | // For better instruction scheduling restore RA before other registers. |
| 1130 | uint32_t ofs = GetFrameSize(); |
| 1131 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1132 | GpuRegister reg = kCoreCalleeSaves[i]; |
| 1133 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1134 | ofs -= kMips64DoublewordSize; |
| 1135 | __ LoadFromOffset(kLoadDoubleword, reg, SP, ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1136 | __ cfi().Restore(DWARFReg(reg)); |
| 1137 | } |
| 1138 | } |
| 1139 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1140 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1141 | FpuRegister reg = kFpuCalleeSaves[i]; |
| 1142 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
| 1143 | ofs -= kMips64DoublewordSize; |
| 1144 | __ LoadFpuFromOffset(kLoadDoubleword, reg, SP, ofs); |
| 1145 | __ cfi().Restore(DWARFReg(reg)); |
| 1146 | } |
| 1147 | } |
| 1148 | |
| 1149 | __ DecreaseFrameSize(GetFrameSize()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1152 | __ Jic(RA, 0); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1153 | |
| 1154 | __ cfi().RestoreState(); |
| 1155 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 1156 | } |
| 1157 | |
| 1158 | void CodeGeneratorMIPS64::Bind(HBasicBlock* block) { |
| 1159 | __ Bind(GetLabelOf(block)); |
| 1160 | } |
| 1161 | |
| 1162 | void CodeGeneratorMIPS64::MoveLocation(Location destination, |
| 1163 | Location source, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1164 | Primitive::Type dst_type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1165 | if (source.Equals(destination)) { |
| 1166 | return; |
| 1167 | } |
| 1168 | |
| 1169 | // A valid move can always be inferred from the destination and source |
| 1170 | // locations. When moving from and to a register, the argument type can be |
| 1171 | // used to generate 32bit instead of 64bit moves. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1172 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1173 | DCHECK_EQ(unspecified_type, false); |
| 1174 | |
| 1175 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1176 | if (unspecified_type) { |
| 1177 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1178 | if (source.IsStackSlot() || |
| 1179 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1180 | || src_cst->IsFloatConstant() |
| 1181 | || src_cst->IsNullConstant()))) { |
| 1182 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1183 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1184 | } else { |
| 1185 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1186 | // type is appropriate. Else the source is a register, and since the |
| 1187 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1188 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1189 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1190 | } |
| 1191 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1192 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 1193 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1194 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1195 | // Move to GPR/FPR from stack |
| 1196 | LoadOperandType load_type = source.IsStackSlot() ? kLoadWord : kLoadDoubleword; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1197 | if (Primitive::IsFloatingPointType(dst_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1198 | __ LoadFpuFromOffset(load_type, |
| 1199 | destination.AsFpuRegister<FpuRegister>(), |
| 1200 | SP, |
| 1201 | source.GetStackIndex()); |
| 1202 | } else { |
| 1203 | // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot. |
| 1204 | __ LoadFromOffset(load_type, |
| 1205 | destination.AsRegister<GpuRegister>(), |
| 1206 | SP, |
| 1207 | source.GetStackIndex()); |
| 1208 | } |
| 1209 | } else if (source.IsConstant()) { |
| 1210 | // Move to GPR/FPR from constant |
| 1211 | GpuRegister gpr = AT; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1212 | if (!Primitive::IsFloatingPointType(dst_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1213 | gpr = destination.AsRegister<GpuRegister>(); |
| 1214 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1215 | if (dst_type == Primitive::kPrimInt || dst_type == Primitive::kPrimFloat) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1216 | int32_t value = GetInt32ValueOf(source.GetConstant()->AsConstant()); |
| 1217 | if (Primitive::IsFloatingPointType(dst_type) && value == 0) { |
| 1218 | gpr = ZERO; |
| 1219 | } else { |
| 1220 | __ LoadConst32(gpr, value); |
| 1221 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1222 | } else { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1223 | int64_t value = GetInt64ValueOf(source.GetConstant()->AsConstant()); |
| 1224 | if (Primitive::IsFloatingPointType(dst_type) && value == 0) { |
| 1225 | gpr = ZERO; |
| 1226 | } else { |
| 1227 | __ LoadConst64(gpr, value); |
| 1228 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1229 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1230 | if (dst_type == Primitive::kPrimFloat) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1231 | __ Mtc1(gpr, destination.AsFpuRegister<FpuRegister>()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1232 | } else if (dst_type == Primitive::kPrimDouble) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1233 | __ Dmtc1(gpr, destination.AsFpuRegister<FpuRegister>()); |
| 1234 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1235 | } else if (source.IsRegister()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1236 | if (destination.IsRegister()) { |
| 1237 | // Move to GPR from GPR |
| 1238 | __ Move(destination.AsRegister<GpuRegister>(), source.AsRegister<GpuRegister>()); |
| 1239 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1240 | DCHECK(destination.IsFpuRegister()); |
| 1241 | if (Primitive::Is64BitType(dst_type)) { |
| 1242 | __ Dmtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>()); |
| 1243 | } else { |
| 1244 | __ Mtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>()); |
| 1245 | } |
| 1246 | } |
| 1247 | } else if (source.IsFpuRegister()) { |
| 1248 | if (destination.IsFpuRegister()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1249 | // Move to FPR from FPR |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1250 | if (dst_type == Primitive::kPrimFloat) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1251 | __ MovS(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1252 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1253 | DCHECK_EQ(dst_type, Primitive::kPrimDouble); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1254 | __ MovD(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1255 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1256 | } else { |
| 1257 | DCHECK(destination.IsRegister()); |
| 1258 | if (Primitive::Is64BitType(dst_type)) { |
| 1259 | __ Dmfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1260 | } else { |
| 1261 | __ Mfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1262 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1263 | } |
| 1264 | } |
| 1265 | } else { // The destination is not a register. It must be a stack slot. |
| 1266 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1267 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1268 | if (unspecified_type) { |
| 1269 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1270 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1271 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1272 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1273 | } |
| 1274 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1275 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 1276 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1277 | // Move to stack from GPR/FPR |
| 1278 | StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
| 1279 | if (source.IsRegister()) { |
| 1280 | __ StoreToOffset(store_type, |
| 1281 | source.AsRegister<GpuRegister>(), |
| 1282 | SP, |
| 1283 | destination.GetStackIndex()); |
| 1284 | } else { |
| 1285 | __ StoreFpuToOffset(store_type, |
| 1286 | source.AsFpuRegister<FpuRegister>(), |
| 1287 | SP, |
| 1288 | destination.GetStackIndex()); |
| 1289 | } |
| 1290 | } else if (source.IsConstant()) { |
| 1291 | // Move to stack from constant |
| 1292 | HConstant* src_cst = source.GetConstant(); |
| 1293 | StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1294 | GpuRegister gpr = ZERO; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1295 | if (destination.IsStackSlot()) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1296 | int32_t value = GetInt32ValueOf(src_cst->AsConstant()); |
| 1297 | if (value != 0) { |
| 1298 | gpr = TMP; |
| 1299 | __ LoadConst32(gpr, value); |
| 1300 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1301 | } else { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1302 | DCHECK(destination.IsDoubleStackSlot()); |
| 1303 | int64_t value = GetInt64ValueOf(src_cst->AsConstant()); |
| 1304 | if (value != 0) { |
| 1305 | gpr = TMP; |
| 1306 | __ LoadConst64(gpr, value); |
| 1307 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1308 | } |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1309 | __ StoreToOffset(store_type, gpr, SP, destination.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1310 | } else { |
| 1311 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
| 1312 | DCHECK_EQ(source.IsDoubleStackSlot(), destination.IsDoubleStackSlot()); |
| 1313 | // Move to stack from stack |
| 1314 | if (destination.IsStackSlot()) { |
| 1315 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 1316 | __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex()); |
| 1317 | } else { |
| 1318 | __ LoadFromOffset(kLoadDoubleword, TMP, SP, source.GetStackIndex()); |
| 1319 | __ StoreToOffset(kStoreDoubleword, TMP, SP, destination.GetStackIndex()); |
| 1320 | } |
| 1321 | } |
| 1322 | } |
| 1323 | } |
| 1324 | |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1325 | void CodeGeneratorMIPS64::SwapLocations(Location loc1, Location loc2, Primitive::Type type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1326 | DCHECK(!loc1.IsConstant()); |
| 1327 | DCHECK(!loc2.IsConstant()); |
| 1328 | |
| 1329 | if (loc1.Equals(loc2)) { |
| 1330 | return; |
| 1331 | } |
| 1332 | |
| 1333 | bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot(); |
| 1334 | bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot(); |
| 1335 | bool is_fp_reg1 = loc1.IsFpuRegister(); |
| 1336 | bool is_fp_reg2 = loc2.IsFpuRegister(); |
| 1337 | |
| 1338 | if (loc2.IsRegister() && loc1.IsRegister()) { |
| 1339 | // Swap 2 GPRs |
| 1340 | GpuRegister r1 = loc1.AsRegister<GpuRegister>(); |
| 1341 | GpuRegister r2 = loc2.AsRegister<GpuRegister>(); |
| 1342 | __ Move(TMP, r2); |
| 1343 | __ Move(r2, r1); |
| 1344 | __ Move(r1, TMP); |
| 1345 | } else if (is_fp_reg2 && is_fp_reg1) { |
| 1346 | // Swap 2 FPRs |
| 1347 | FpuRegister r1 = loc1.AsFpuRegister<FpuRegister>(); |
| 1348 | FpuRegister r2 = loc2.AsFpuRegister<FpuRegister>(); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1349 | if (type == Primitive::kPrimFloat) { |
| 1350 | __ MovS(FTMP, r1); |
| 1351 | __ MovS(r1, r2); |
| 1352 | __ MovS(r2, FTMP); |
| 1353 | } else { |
| 1354 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1355 | __ MovD(FTMP, r1); |
| 1356 | __ MovD(r1, r2); |
| 1357 | __ MovD(r2, FTMP); |
| 1358 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1359 | } else if (is_slot1 != is_slot2) { |
| 1360 | // Swap GPR/FPR and stack slot |
| 1361 | Location reg_loc = is_slot1 ? loc2 : loc1; |
| 1362 | Location mem_loc = is_slot1 ? loc1 : loc2; |
| 1363 | LoadOperandType load_type = mem_loc.IsStackSlot() ? kLoadWord : kLoadDoubleword; |
| 1364 | StoreOperandType store_type = mem_loc.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
| 1365 | // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot. |
| 1366 | __ LoadFromOffset(load_type, TMP, SP, mem_loc.GetStackIndex()); |
| 1367 | if (reg_loc.IsFpuRegister()) { |
| 1368 | __ StoreFpuToOffset(store_type, |
| 1369 | reg_loc.AsFpuRegister<FpuRegister>(), |
| 1370 | SP, |
| 1371 | mem_loc.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1372 | if (mem_loc.IsStackSlot()) { |
| 1373 | __ Mtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>()); |
| 1374 | } else { |
| 1375 | DCHECK(mem_loc.IsDoubleStackSlot()); |
| 1376 | __ Dmtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>()); |
| 1377 | } |
| 1378 | } else { |
| 1379 | __ StoreToOffset(store_type, reg_loc.AsRegister<GpuRegister>(), SP, mem_loc.GetStackIndex()); |
| 1380 | __ Move(reg_loc.AsRegister<GpuRegister>(), TMP); |
| 1381 | } |
| 1382 | } else if (is_slot1 && is_slot2) { |
| 1383 | move_resolver_.Exchange(loc1.GetStackIndex(), |
| 1384 | loc2.GetStackIndex(), |
| 1385 | loc1.IsDoubleStackSlot()); |
| 1386 | } else { |
| 1387 | LOG(FATAL) << "Unimplemented swap between locations " << loc1 << " and " << loc2; |
| 1388 | } |
| 1389 | } |
| 1390 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1391 | void CodeGeneratorMIPS64::MoveConstant(Location location, int32_t value) { |
| 1392 | DCHECK(location.IsRegister()); |
| 1393 | __ LoadConst32(location.AsRegister<GpuRegister>(), value); |
| 1394 | } |
| 1395 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1396 | void CodeGeneratorMIPS64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1397 | if (location.IsRegister()) { |
| 1398 | locations->AddTemp(location); |
| 1399 | } else { |
| 1400 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1401 | } |
| 1402 | } |
| 1403 | |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1404 | void CodeGeneratorMIPS64::MarkGCCard(GpuRegister object, |
| 1405 | GpuRegister value, |
| 1406 | bool value_can_be_null) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1407 | Mips64Label done; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1408 | GpuRegister card = AT; |
| 1409 | GpuRegister temp = TMP; |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1410 | if (value_can_be_null) { |
| 1411 | __ Beqzc(value, &done); |
| 1412 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1413 | __ LoadFromOffset(kLoadDoubleword, |
| 1414 | card, |
| 1415 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1416 | Thread::CardTableOffset<kMips64PointerSize>().Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1417 | __ Dsrl(temp, object, gc::accounting::CardTable::kCardShift); |
| 1418 | __ Daddu(temp, card, temp); |
| 1419 | __ Sb(card, temp, 0); |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1420 | if (value_can_be_null) { |
| 1421 | __ Bind(&done); |
| 1422 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1423 | } |
| 1424 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1425 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 1426 | inline void CodeGeneratorMIPS64::EmitPcRelativeLinkerPatches( |
| 1427 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 1428 | ArenaVector<LinkerPatch>* linker_patches) { |
| 1429 | for (const PcRelativePatchInfo& info : infos) { |
| 1430 | const DexFile& dex_file = info.target_dex_file; |
| 1431 | size_t offset_or_index = info.offset_or_index; |
| 1432 | DCHECK(info.pc_rel_label.IsBound()); |
| 1433 | uint32_t pc_rel_offset = __ GetLabelLocation(&info.pc_rel_label); |
| 1434 | linker_patches->push_back(Factory(pc_rel_offset, &dex_file, pc_rel_offset, offset_or_index)); |
| 1435 | } |
| 1436 | } |
| 1437 | |
| 1438 | void CodeGeneratorMIPS64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 1439 | DCHECK(linker_patches->empty()); |
| 1440 | size_t size = |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1441 | pc_relative_dex_cache_patches_.size() + |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1442 | pc_relative_string_patches_.size() + |
| 1443 | pc_relative_type_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1444 | type_bss_entry_patches_.size() + |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1445 | boot_image_string_patches_.size() + |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 1446 | boot_image_type_patches_.size(); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1447 | linker_patches->reserve(size); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1448 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 1449 | linker_patches); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1450 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1451 | DCHECK(pc_relative_type_patches_.empty()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1452 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 1453 | linker_patches); |
| 1454 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1455 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 1456 | linker_patches); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1457 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 1458 | linker_patches); |
| 1459 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1460 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 1461 | linker_patches); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1462 | for (const auto& entry : boot_image_string_patches_) { |
| 1463 | const StringReference& target_string = entry.first; |
| 1464 | Literal* literal = entry.second; |
| 1465 | DCHECK(literal->GetLabel()->IsBound()); |
| 1466 | uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel()); |
| 1467 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 1468 | target_string.dex_file, |
| 1469 | target_string.string_index.index_)); |
| 1470 | } |
| 1471 | for (const auto& entry : boot_image_type_patches_) { |
| 1472 | const TypeReference& target_type = entry.first; |
| 1473 | Literal* literal = entry.second; |
| 1474 | DCHECK(literal->GetLabel()->IsBound()); |
| 1475 | uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel()); |
| 1476 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 1477 | target_type.dex_file, |
| 1478 | target_type.type_index.index_)); |
| 1479 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1480 | DCHECK_EQ(size, linker_patches->size()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeStringPatch( |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1484 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 1485 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1486 | } |
| 1487 | |
| 1488 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeTypePatch( |
| 1489 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 1490 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1491 | } |
| 1492 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1493 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewTypeBssEntryPatch( |
| 1494 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 1495 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 1496 | } |
| 1497 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1498 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeDexCacheArrayPatch( |
| 1499 | const DexFile& dex_file, uint32_t element_offset) { |
| 1500 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 1501 | } |
| 1502 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1503 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativePatch( |
| 1504 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 1505 | patches->emplace_back(dex_file, offset_or_index); |
| 1506 | return &patches->back(); |
| 1507 | } |
| 1508 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1509 | Literal* CodeGeneratorMIPS64::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 1510 | return map->GetOrCreate( |
| 1511 | value, |
| 1512 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
| 1513 | } |
| 1514 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1515 | Literal* CodeGeneratorMIPS64::DeduplicateUint64Literal(uint64_t value) { |
| 1516 | return uint64_literals_.GetOrCreate( |
| 1517 | value, |
| 1518 | [this, value]() { return __ NewLiteral<uint64_t>(value); }); |
| 1519 | } |
| 1520 | |
| 1521 | Literal* CodeGeneratorMIPS64::DeduplicateMethodLiteral(MethodReference target_method, |
| 1522 | MethodToLiteralMap* map) { |
| 1523 | return map->GetOrCreate( |
| 1524 | target_method, |
| 1525 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1526 | } |
| 1527 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1528 | Literal* CodeGeneratorMIPS64::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
| 1529 | dex::StringIndex string_index) { |
| 1530 | return boot_image_string_patches_.GetOrCreate( |
| 1531 | StringReference(&dex_file, string_index), |
| 1532 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1533 | } |
| 1534 | |
| 1535 | Literal* CodeGeneratorMIPS64::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
| 1536 | dex::TypeIndex type_index) { |
| 1537 | return boot_image_type_patches_.GetOrCreate( |
| 1538 | TypeReference(&dex_file, type_index), |
| 1539 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1540 | } |
| 1541 | |
| 1542 | Literal* CodeGeneratorMIPS64::DeduplicateBootImageAddressLiteral(uint64_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 1543 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1544 | } |
| 1545 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1546 | void CodeGeneratorMIPS64::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info, |
| 1547 | GpuRegister out) { |
| 1548 | __ Bind(&info->pc_rel_label); |
| 1549 | // Add the high half of a 32-bit offset to PC. |
| 1550 | __ Auipc(out, /* placeholder */ 0x1234); |
| 1551 | // The immediately following instruction will add the sign-extended low half of the 32-bit |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1552 | // offset to `out` (e.g. ld, jialc, daddiu). |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1553 | } |
| 1554 | |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1555 | Literal* CodeGeneratorMIPS64::DeduplicateJitStringLiteral(const DexFile& dex_file, |
| 1556 | dex::StringIndex string_index, |
| 1557 | Handle<mirror::String> handle) { |
| 1558 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 1559 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
| 1560 | return jit_string_patches_.GetOrCreate( |
| 1561 | StringReference(&dex_file, string_index), |
| 1562 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1563 | } |
| 1564 | |
| 1565 | Literal* CodeGeneratorMIPS64::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 1566 | dex::TypeIndex type_index, |
| 1567 | Handle<mirror::Class> handle) { |
| 1568 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 1569 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
| 1570 | return jit_class_patches_.GetOrCreate( |
| 1571 | TypeReference(&dex_file, type_index), |
| 1572 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1573 | } |
| 1574 | |
| 1575 | void CodeGeneratorMIPS64::PatchJitRootUse(uint8_t* code, |
| 1576 | const uint8_t* roots_data, |
| 1577 | const Literal* literal, |
| 1578 | uint64_t index_in_table) const { |
| 1579 | uint32_t literal_offset = GetAssembler().GetLabelLocation(literal->GetLabel()); |
| 1580 | uintptr_t address = |
| 1581 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 1582 | reinterpret_cast<uint32_t*>(code + literal_offset)[0] = dchecked_integral_cast<uint32_t>(address); |
| 1583 | } |
| 1584 | |
| 1585 | void CodeGeneratorMIPS64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 1586 | for (const auto& entry : jit_string_patches_) { |
| 1587 | const auto& it = jit_string_roots_.find(entry.first); |
| 1588 | DCHECK(it != jit_string_roots_.end()); |
| 1589 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
| 1590 | } |
| 1591 | for (const auto& entry : jit_class_patches_) { |
| 1592 | const auto& it = jit_class_roots_.find(entry.first); |
| 1593 | DCHECK(it != jit_class_roots_.end()); |
| 1594 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
| 1595 | } |
| 1596 | } |
| 1597 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1598 | void CodeGeneratorMIPS64::SetupBlockedRegisters() const { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1599 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1600 | blocked_core_registers_[ZERO] = true; |
| 1601 | blocked_core_registers_[K0] = true; |
| 1602 | blocked_core_registers_[K1] = true; |
| 1603 | blocked_core_registers_[GP] = true; |
| 1604 | blocked_core_registers_[SP] = true; |
| 1605 | blocked_core_registers_[RA] = true; |
| 1606 | |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1607 | // AT, TMP(T8) and TMP2(T3) are used as temporary/scratch |
| 1608 | // registers (similar to how AT is used by MIPS assemblers). |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1609 | blocked_core_registers_[AT] = true; |
| 1610 | blocked_core_registers_[TMP] = true; |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1611 | blocked_core_registers_[TMP2] = true; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1612 | blocked_fpu_registers_[FTMP] = true; |
| 1613 | |
| 1614 | // Reserve suspend and thread registers. |
| 1615 | blocked_core_registers_[S0] = true; |
| 1616 | blocked_core_registers_[TR] = true; |
| 1617 | |
| 1618 | // Reserve T9 for function calls |
| 1619 | blocked_core_registers_[T9] = true; |
| 1620 | |
Goran Jakovljevic | 782be11 | 2016-06-21 12:39:04 +0200 | [diff] [blame] | 1621 | if (GetGraph()->IsDebuggable()) { |
| 1622 | // Stubs do not save callee-save floating point registers. If the graph |
| 1623 | // is debuggable, we need to deal with these registers differently. For |
| 1624 | // now, just block them. |
| 1625 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1626 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1627 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1628 | } |
| 1629 | } |
| 1630 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1631 | size_t CodeGeneratorMIPS64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1632 | __ StoreToOffset(kStoreDoubleword, GpuRegister(reg_id), SP, stack_index); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1633 | return kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | size_t CodeGeneratorMIPS64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1637 | __ LoadFromOffset(kLoadDoubleword, GpuRegister(reg_id), SP, stack_index); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1638 | return kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | size_t CodeGeneratorMIPS64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame^] | 1642 | __ StoreFpuToOffset(GetGraph()->HasSIMD() ? kStoreQuadword : kStoreDoubleword, |
| 1643 | FpuRegister(reg_id), |
| 1644 | SP, |
| 1645 | stack_index); |
| 1646 | return GetFloatingPointSpillSlotSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1647 | } |
| 1648 | |
| 1649 | size_t CodeGeneratorMIPS64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame^] | 1650 | __ LoadFpuFromOffset(GetGraph()->HasSIMD() ? kLoadQuadword : kLoadDoubleword, |
| 1651 | FpuRegister(reg_id), |
| 1652 | SP, |
| 1653 | stack_index); |
| 1654 | return GetFloatingPointSpillSlotSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | void CodeGeneratorMIPS64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 1658 | stream << GpuRegister(reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1659 | } |
| 1660 | |
| 1661 | void CodeGeneratorMIPS64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 1662 | stream << FpuRegister(reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1663 | } |
| 1664 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1665 | void CodeGeneratorMIPS64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1666 | HInstruction* instruction, |
| 1667 | uint32_t dex_pc, |
| 1668 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1669 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1670 | GenerateInvokeRuntime(GetThreadOffset<kMips64PointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 1671 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1672 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1673 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1674 | } |
| 1675 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1676 | void CodeGeneratorMIPS64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1677 | HInstruction* instruction, |
| 1678 | SlowPathCode* slow_path) { |
| 1679 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| 1680 | GenerateInvokeRuntime(entry_point_offset); |
| 1681 | } |
| 1682 | |
| 1683 | void CodeGeneratorMIPS64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
| 1684 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
| 1685 | __ Jalr(T9); |
| 1686 | __ Nop(); |
| 1687 | } |
| 1688 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1689 | void InstructionCodeGeneratorMIPS64::GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path, |
| 1690 | GpuRegister class_reg) { |
| 1691 | __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 1692 | __ LoadConst32(AT, mirror::Class::kStatusInitialized); |
| 1693 | __ Bltc(TMP, AT, slow_path->GetEntryLabel()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1694 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 1695 | __ Sync(0); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1696 | __ Bind(slow_path->GetExitLabel()); |
| 1697 | } |
| 1698 | |
| 1699 | void InstructionCodeGeneratorMIPS64::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1700 | __ Sync(0); // only stype 0 is supported |
| 1701 | } |
| 1702 | |
| 1703 | void InstructionCodeGeneratorMIPS64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1704 | HBasicBlock* successor) { |
| 1705 | SuspendCheckSlowPathMIPS64* slow_path = |
| 1706 | new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS64(instruction, successor); |
| 1707 | codegen_->AddSlowPath(slow_path); |
| 1708 | |
| 1709 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1710 | TMP, |
| 1711 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1712 | Thread::ThreadFlagsOffset<kMips64PointerSize>().Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1713 | if (successor == nullptr) { |
| 1714 | __ Bnezc(TMP, slow_path->GetEntryLabel()); |
| 1715 | __ Bind(slow_path->GetReturnLabel()); |
| 1716 | } else { |
| 1717 | __ Beqzc(TMP, codegen_->GetLabelOf(successor)); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1718 | __ Bc(slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1719 | // slow_path will return to GetLabelOf(successor). |
| 1720 | } |
| 1721 | } |
| 1722 | |
| 1723 | InstructionCodeGeneratorMIPS64::InstructionCodeGeneratorMIPS64(HGraph* graph, |
| 1724 | CodeGeneratorMIPS64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1725 | : InstructionCodeGenerator(graph, codegen), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1726 | assembler_(codegen->GetAssembler()), |
| 1727 | codegen_(codegen) {} |
| 1728 | |
| 1729 | void LocationsBuilderMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1730 | DCHECK_EQ(instruction->InputCount(), 2U); |
| 1731 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1732 | Primitive::Type type = instruction->GetResultType(); |
| 1733 | switch (type) { |
| 1734 | case Primitive::kPrimInt: |
| 1735 | case Primitive::kPrimLong: { |
| 1736 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1737 | HInstruction* right = instruction->InputAt(1); |
| 1738 | bool can_use_imm = false; |
| 1739 | if (right->IsConstant()) { |
| 1740 | int64_t imm = CodeGenerator::GetInt64ValueOf(right->AsConstant()); |
| 1741 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 1742 | can_use_imm = IsUint<16>(imm); |
| 1743 | } else if (instruction->IsAdd()) { |
| 1744 | can_use_imm = IsInt<16>(imm); |
| 1745 | } else { |
| 1746 | DCHECK(instruction->IsSub()); |
| 1747 | can_use_imm = IsInt<16>(-imm); |
| 1748 | } |
| 1749 | } |
| 1750 | if (can_use_imm) |
| 1751 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 1752 | else |
| 1753 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1754 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1755 | } |
| 1756 | break; |
| 1757 | |
| 1758 | case Primitive::kPrimFloat: |
| 1759 | case Primitive::kPrimDouble: |
| 1760 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1761 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1762 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1763 | break; |
| 1764 | |
| 1765 | default: |
| 1766 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 1767 | } |
| 1768 | } |
| 1769 | |
| 1770 | void InstructionCodeGeneratorMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1771 | Primitive::Type type = instruction->GetType(); |
| 1772 | LocationSummary* locations = instruction->GetLocations(); |
| 1773 | |
| 1774 | switch (type) { |
| 1775 | case Primitive::kPrimInt: |
| 1776 | case Primitive::kPrimLong: { |
| 1777 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 1778 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1779 | Location rhs_location = locations->InAt(1); |
| 1780 | |
| 1781 | GpuRegister rhs_reg = ZERO; |
| 1782 | int64_t rhs_imm = 0; |
| 1783 | bool use_imm = rhs_location.IsConstant(); |
| 1784 | if (use_imm) { |
| 1785 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 1786 | } else { |
| 1787 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 1788 | } |
| 1789 | |
| 1790 | if (instruction->IsAnd()) { |
| 1791 | if (use_imm) |
| 1792 | __ Andi(dst, lhs, rhs_imm); |
| 1793 | else |
| 1794 | __ And(dst, lhs, rhs_reg); |
| 1795 | } else if (instruction->IsOr()) { |
| 1796 | if (use_imm) |
| 1797 | __ Ori(dst, lhs, rhs_imm); |
| 1798 | else |
| 1799 | __ Or(dst, lhs, rhs_reg); |
| 1800 | } else if (instruction->IsXor()) { |
| 1801 | if (use_imm) |
| 1802 | __ Xori(dst, lhs, rhs_imm); |
| 1803 | else |
| 1804 | __ Xor(dst, lhs, rhs_reg); |
| 1805 | } else if (instruction->IsAdd()) { |
| 1806 | if (type == Primitive::kPrimInt) { |
| 1807 | if (use_imm) |
| 1808 | __ Addiu(dst, lhs, rhs_imm); |
| 1809 | else |
| 1810 | __ Addu(dst, lhs, rhs_reg); |
| 1811 | } else { |
| 1812 | if (use_imm) |
| 1813 | __ Daddiu(dst, lhs, rhs_imm); |
| 1814 | else |
| 1815 | __ Daddu(dst, lhs, rhs_reg); |
| 1816 | } |
| 1817 | } else { |
| 1818 | DCHECK(instruction->IsSub()); |
| 1819 | if (type == Primitive::kPrimInt) { |
| 1820 | if (use_imm) |
| 1821 | __ Addiu(dst, lhs, -rhs_imm); |
| 1822 | else |
| 1823 | __ Subu(dst, lhs, rhs_reg); |
| 1824 | } else { |
| 1825 | if (use_imm) |
| 1826 | __ Daddiu(dst, lhs, -rhs_imm); |
| 1827 | else |
| 1828 | __ Dsubu(dst, lhs, rhs_reg); |
| 1829 | } |
| 1830 | } |
| 1831 | break; |
| 1832 | } |
| 1833 | case Primitive::kPrimFloat: |
| 1834 | case Primitive::kPrimDouble: { |
| 1835 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 1836 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 1837 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 1838 | if (instruction->IsAdd()) { |
| 1839 | if (type == Primitive::kPrimFloat) |
| 1840 | __ AddS(dst, lhs, rhs); |
| 1841 | else |
| 1842 | __ AddD(dst, lhs, rhs); |
| 1843 | } else if (instruction->IsSub()) { |
| 1844 | if (type == Primitive::kPrimFloat) |
| 1845 | __ SubS(dst, lhs, rhs); |
| 1846 | else |
| 1847 | __ SubD(dst, lhs, rhs); |
| 1848 | } else { |
| 1849 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
| 1850 | } |
| 1851 | break; |
| 1852 | } |
| 1853 | default: |
| 1854 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 1855 | } |
| 1856 | } |
| 1857 | |
| 1858 | void LocationsBuilderMIPS64::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1859 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1860 | |
| 1861 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1862 | Primitive::Type type = instr->GetResultType(); |
| 1863 | switch (type) { |
| 1864 | case Primitive::kPrimInt: |
| 1865 | case Primitive::kPrimLong: { |
| 1866 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1867 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1868 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1869 | break; |
| 1870 | } |
| 1871 | default: |
| 1872 | LOG(FATAL) << "Unexpected shift type " << type; |
| 1873 | } |
| 1874 | } |
| 1875 | |
| 1876 | void InstructionCodeGeneratorMIPS64::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1877 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1878 | LocationSummary* locations = instr->GetLocations(); |
| 1879 | Primitive::Type type = instr->GetType(); |
| 1880 | |
| 1881 | switch (type) { |
| 1882 | case Primitive::kPrimInt: |
| 1883 | case Primitive::kPrimLong: { |
| 1884 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 1885 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1886 | Location rhs_location = locations->InAt(1); |
| 1887 | |
| 1888 | GpuRegister rhs_reg = ZERO; |
| 1889 | int64_t rhs_imm = 0; |
| 1890 | bool use_imm = rhs_location.IsConstant(); |
| 1891 | if (use_imm) { |
| 1892 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 1893 | } else { |
| 1894 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 1895 | } |
| 1896 | |
| 1897 | if (use_imm) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 1898 | uint32_t shift_value = rhs_imm & |
| 1899 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1900 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1901 | if (shift_value == 0) { |
| 1902 | if (dst != lhs) { |
| 1903 | __ Move(dst, lhs); |
| 1904 | } |
| 1905 | } else if (type == Primitive::kPrimInt) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1906 | if (instr->IsShl()) { |
| 1907 | __ Sll(dst, lhs, shift_value); |
| 1908 | } else if (instr->IsShr()) { |
| 1909 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1910 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1911 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1912 | } else { |
| 1913 | __ Rotr(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1914 | } |
| 1915 | } else { |
| 1916 | if (shift_value < 32) { |
| 1917 | if (instr->IsShl()) { |
| 1918 | __ Dsll(dst, lhs, shift_value); |
| 1919 | } else if (instr->IsShr()) { |
| 1920 | __ Dsra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1921 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1922 | __ Dsrl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1923 | } else { |
| 1924 | __ Drotr(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1925 | } |
| 1926 | } else { |
| 1927 | shift_value -= 32; |
| 1928 | if (instr->IsShl()) { |
| 1929 | __ Dsll32(dst, lhs, shift_value); |
| 1930 | } else if (instr->IsShr()) { |
| 1931 | __ Dsra32(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1932 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1933 | __ Dsrl32(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1934 | } else { |
| 1935 | __ Drotr32(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1936 | } |
| 1937 | } |
| 1938 | } |
| 1939 | } else { |
| 1940 | if (type == Primitive::kPrimInt) { |
| 1941 | if (instr->IsShl()) { |
| 1942 | __ Sllv(dst, lhs, rhs_reg); |
| 1943 | } else if (instr->IsShr()) { |
| 1944 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1945 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1946 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1947 | } else { |
| 1948 | __ Rotrv(dst, lhs, rhs_reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1949 | } |
| 1950 | } else { |
| 1951 | if (instr->IsShl()) { |
| 1952 | __ Dsllv(dst, lhs, rhs_reg); |
| 1953 | } else if (instr->IsShr()) { |
| 1954 | __ Dsrav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1955 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1956 | __ Dsrlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1957 | } else { |
| 1958 | __ Drotrv(dst, lhs, rhs_reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1959 | } |
| 1960 | } |
| 1961 | } |
| 1962 | break; |
| 1963 | } |
| 1964 | default: |
| 1965 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 1966 | } |
| 1967 | } |
| 1968 | |
| 1969 | void LocationsBuilderMIPS64::VisitAdd(HAdd* instruction) { |
| 1970 | HandleBinaryOp(instruction); |
| 1971 | } |
| 1972 | |
| 1973 | void InstructionCodeGeneratorMIPS64::VisitAdd(HAdd* instruction) { |
| 1974 | HandleBinaryOp(instruction); |
| 1975 | } |
| 1976 | |
| 1977 | void LocationsBuilderMIPS64::VisitAnd(HAnd* instruction) { |
| 1978 | HandleBinaryOp(instruction); |
| 1979 | } |
| 1980 | |
| 1981 | void InstructionCodeGeneratorMIPS64::VisitAnd(HAnd* instruction) { |
| 1982 | HandleBinaryOp(instruction); |
| 1983 | } |
| 1984 | |
| 1985 | void LocationsBuilderMIPS64::VisitArrayGet(HArrayGet* instruction) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1986 | Primitive::Type type = instruction->GetType(); |
| 1987 | bool object_array_get_with_read_barrier = |
| 1988 | kEmitCompilerReadBarrier && (type == Primitive::kPrimNot); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1989 | LocationSummary* locations = |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1990 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 1991 | object_array_get_with_read_barrier |
| 1992 | ? LocationSummary::kCallOnSlowPath |
| 1993 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1994 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 1995 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 1996 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1997 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1998 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1999 | if (Primitive::IsFloatingPointType(type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2000 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2001 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2002 | // The output overlaps in the case of an object array get with |
| 2003 | // read barriers enabled: we do not want the move to overwrite the |
| 2004 | // array's location, as we need it to emit the read barrier. |
| 2005 | locations->SetOut(Location::RequiresRegister(), |
| 2006 | object_array_get_with_read_barrier |
| 2007 | ? Location::kOutputOverlap |
| 2008 | : Location::kNoOutputOverlap); |
| 2009 | } |
| 2010 | // We need a temporary register for the read barrier marking slow |
| 2011 | // path in CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier. |
| 2012 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 2013 | locations->AddTemp(Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2014 | } |
| 2015 | } |
| 2016 | |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2017 | static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS64* codegen) { |
| 2018 | auto null_checker = [codegen, instruction]() { |
| 2019 | codegen->MaybeRecordImplicitNullCheck(instruction); |
| 2020 | }; |
| 2021 | return null_checker; |
| 2022 | } |
| 2023 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2024 | void InstructionCodeGeneratorMIPS64::VisitArrayGet(HArrayGet* instruction) { |
| 2025 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2026 | Location obj_loc = locations->InAt(0); |
| 2027 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
| 2028 | Location out_loc = locations->Out(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2029 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2030 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2031 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2032 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2033 | Primitive::Type type = instruction->GetType(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2034 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2035 | instruction->IsStringCharAt(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2036 | switch (type) { |
| 2037 | case Primitive::kPrimBoolean: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2038 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2039 | if (index.IsConstant()) { |
| 2040 | size_t offset = |
| 2041 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2042 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2043 | } else { |
| 2044 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2045 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2046 | } |
| 2047 | break; |
| 2048 | } |
| 2049 | |
| 2050 | case Primitive::kPrimByte: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2051 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2052 | if (index.IsConstant()) { |
| 2053 | size_t offset = |
| 2054 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2055 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2056 | } else { |
| 2057 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2058 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2059 | } |
| 2060 | break; |
| 2061 | } |
| 2062 | |
| 2063 | case Primitive::kPrimShort: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2064 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2065 | if (index.IsConstant()) { |
| 2066 | size_t offset = |
| 2067 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2068 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2069 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2070 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_2); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2071 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2072 | } |
| 2073 | break; |
| 2074 | } |
| 2075 | |
| 2076 | case Primitive::kPrimChar: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2077 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2078 | if (maybe_compressed_char_at) { |
| 2079 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2080 | __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2081 | __ Dext(TMP, TMP, 0, 1); |
| 2082 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2083 | "Expecting 0=compressed, 1=uncompressed"); |
| 2084 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2085 | if (index.IsConstant()) { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2086 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 2087 | if (maybe_compressed_char_at) { |
| 2088 | Mips64Label uncompressed_load, done; |
| 2089 | __ Bnezc(TMP, &uncompressed_load); |
| 2090 | __ LoadFromOffset(kLoadUnsignedByte, |
| 2091 | out, |
| 2092 | obj, |
| 2093 | data_offset + (const_index << TIMES_1)); |
| 2094 | __ Bc(&done); |
| 2095 | __ Bind(&uncompressed_load); |
| 2096 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2097 | out, |
| 2098 | obj, |
| 2099 | data_offset + (const_index << TIMES_2)); |
| 2100 | __ Bind(&done); |
| 2101 | } else { |
| 2102 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2103 | out, |
| 2104 | obj, |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2105 | data_offset + (const_index << TIMES_2), |
| 2106 | null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2107 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2108 | } else { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2109 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
| 2110 | if (maybe_compressed_char_at) { |
| 2111 | Mips64Label uncompressed_load, done; |
| 2112 | __ Bnezc(TMP, &uncompressed_load); |
| 2113 | __ Daddu(TMP, obj, index_reg); |
| 2114 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 2115 | __ Bc(&done); |
| 2116 | __ Bind(&uncompressed_load); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2117 | __ Dlsa(TMP, index_reg, obj, TIMES_2); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2118 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 2119 | __ Bind(&done); |
| 2120 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2121 | __ Dlsa(TMP, index_reg, obj, TIMES_2); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2122 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2123 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2124 | } |
| 2125 | break; |
| 2126 | } |
| 2127 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2128 | case Primitive::kPrimInt: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2129 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2130 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2131 | LoadOperandType load_type = (type == Primitive::kPrimNot) ? kLoadUnsignedWord : kLoadWord; |
| 2132 | if (index.IsConstant()) { |
| 2133 | size_t offset = |
| 2134 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2135 | __ LoadFromOffset(load_type, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2136 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2137 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2138 | __ LoadFromOffset(load_type, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2139 | } |
| 2140 | break; |
| 2141 | } |
| 2142 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2143 | case Primitive::kPrimNot: { |
| 2144 | static_assert( |
| 2145 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2146 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2147 | // /* HeapReference<Object> */ out = |
| 2148 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 2149 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2150 | Location temp = locations->GetTemp(0); |
| 2151 | // Note that a potential implicit null check is handled in this |
| 2152 | // CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier call. |
| 2153 | codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction, |
| 2154 | out_loc, |
| 2155 | obj, |
| 2156 | data_offset, |
| 2157 | index, |
| 2158 | temp, |
| 2159 | /* needs_null_check */ true); |
| 2160 | } else { |
| 2161 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 2162 | if (index.IsConstant()) { |
| 2163 | size_t offset = |
| 2164 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2165 | __ LoadFromOffset(kLoadUnsignedWord, out, obj, offset, null_checker); |
| 2166 | // If read barriers are enabled, emit read barriers other than |
| 2167 | // Baker's using a slow path (and also unpoison the loaded |
| 2168 | // reference, if heap poisoning is enabled). |
| 2169 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 2170 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2171 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2172 | __ LoadFromOffset(kLoadUnsignedWord, out, TMP, data_offset, null_checker); |
| 2173 | // If read barriers are enabled, emit read barriers other than |
| 2174 | // Baker's using a slow path (and also unpoison the loaded |
| 2175 | // reference, if heap poisoning is enabled). |
| 2176 | codegen_->MaybeGenerateReadBarrierSlow(instruction, |
| 2177 | out_loc, |
| 2178 | out_loc, |
| 2179 | obj_loc, |
| 2180 | data_offset, |
| 2181 | index); |
| 2182 | } |
| 2183 | } |
| 2184 | break; |
| 2185 | } |
| 2186 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2187 | case Primitive::kPrimLong: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2188 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2189 | if (index.IsConstant()) { |
| 2190 | size_t offset = |
| 2191 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2192 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2193 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2194 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2195 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2196 | } |
| 2197 | break; |
| 2198 | } |
| 2199 | |
| 2200 | case Primitive::kPrimFloat: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2201 | FpuRegister out = out_loc.AsFpuRegister<FpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2202 | if (index.IsConstant()) { |
| 2203 | size_t offset = |
| 2204 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2205 | __ LoadFpuFromOffset(kLoadWord, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2206 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2207 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2208 | __ LoadFpuFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2209 | } |
| 2210 | break; |
| 2211 | } |
| 2212 | |
| 2213 | case Primitive::kPrimDouble: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2214 | FpuRegister out = out_loc.AsFpuRegister<FpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2215 | if (index.IsConstant()) { |
| 2216 | size_t offset = |
| 2217 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2218 | __ LoadFpuFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2219 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2220 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2221 | __ LoadFpuFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2222 | } |
| 2223 | break; |
| 2224 | } |
| 2225 | |
| 2226 | case Primitive::kPrimVoid: |
| 2227 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2228 | UNREACHABLE(); |
| 2229 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | void LocationsBuilderMIPS64::VisitArrayLength(HArrayLength* instruction) { |
| 2233 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2234 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2235 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2236 | } |
| 2237 | |
| 2238 | void InstructionCodeGeneratorMIPS64::VisitArrayLength(HArrayLength* instruction) { |
| 2239 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2240 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2241 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2242 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 2243 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2244 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2245 | // Mask out compression flag from String's array length. |
| 2246 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 2247 | __ Srl(out, out, 1u); |
| 2248 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2249 | } |
| 2250 | |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2251 | Location LocationsBuilderMIPS64::RegisterOrZeroConstant(HInstruction* instruction) { |
| 2252 | return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern()) |
| 2253 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 2254 | : Location::RequiresRegister(); |
| 2255 | } |
| 2256 | |
| 2257 | Location LocationsBuilderMIPS64::FpuRegisterOrConstantForStore(HInstruction* instruction) { |
| 2258 | // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register. |
| 2259 | // We can store a non-zero float or double constant without first loading it into the FPU, |
| 2260 | // but we should only prefer this if the constant has a single use. |
| 2261 | if (instruction->IsConstant() && |
| 2262 | (instruction->AsConstant()->IsZeroBitPattern() || |
| 2263 | instruction->GetUses().HasExactlyOneElement())) { |
| 2264 | return Location::ConstantLocation(instruction->AsConstant()); |
| 2265 | // Otherwise fall through and require an FPU register for the constant. |
| 2266 | } |
| 2267 | return Location::RequiresFpuRegister(); |
| 2268 | } |
| 2269 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2270 | void LocationsBuilderMIPS64::VisitArraySet(HArraySet* instruction) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2271 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2272 | |
| 2273 | bool needs_write_barrier = |
| 2274 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 2275 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 2276 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2277 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2278 | instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2279 | may_need_runtime_call_for_type_check ? |
| 2280 | LocationSummary::kCallOnSlowPath : |
| 2281 | LocationSummary::kNoCall); |
| 2282 | |
| 2283 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2284 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2285 | if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
| 2286 | locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2287 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2288 | locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2))); |
| 2289 | } |
| 2290 | if (needs_write_barrier) { |
| 2291 | // Temporary register for the write barrier. |
| 2292 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2293 | } |
| 2294 | } |
| 2295 | |
| 2296 | void InstructionCodeGeneratorMIPS64::VisitArraySet(HArraySet* instruction) { |
| 2297 | LocationSummary* locations = instruction->GetLocations(); |
| 2298 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2299 | Location index = locations->InAt(1); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2300 | Location value_location = locations->InAt(2); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2301 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2302 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2303 | bool needs_write_barrier = |
| 2304 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2305 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2306 | GpuRegister base_reg = index.IsConstant() ? obj : TMP; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2307 | |
| 2308 | switch (value_type) { |
| 2309 | case Primitive::kPrimBoolean: |
| 2310 | case Primitive::kPrimByte: { |
| 2311 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2312 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2313 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2314 | } else { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2315 | __ Daddu(base_reg, obj, index.AsRegister<GpuRegister>()); |
| 2316 | } |
| 2317 | if (value_location.IsConstant()) { |
| 2318 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2319 | __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker); |
| 2320 | } else { |
| 2321 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2322 | __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2323 | } |
| 2324 | break; |
| 2325 | } |
| 2326 | |
| 2327 | case Primitive::kPrimShort: |
| 2328 | case Primitive::kPrimChar: { |
| 2329 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2330 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2331 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2332 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2333 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_2); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2334 | } |
| 2335 | if (value_location.IsConstant()) { |
| 2336 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2337 | __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker); |
| 2338 | } else { |
| 2339 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2340 | __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2341 | } |
| 2342 | break; |
| 2343 | } |
| 2344 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2345 | case Primitive::kPrimInt: { |
| 2346 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2347 | if (index.IsConstant()) { |
| 2348 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
| 2349 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2350 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2351 | } |
| 2352 | if (value_location.IsConstant()) { |
| 2353 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2354 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2355 | } else { |
| 2356 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2357 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2358 | } |
| 2359 | break; |
| 2360 | } |
| 2361 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2362 | case Primitive::kPrimNot: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2363 | if (value_location.IsConstant()) { |
| 2364 | // Just setting null. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2365 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2366 | if (index.IsConstant()) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2367 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2368 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2369 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2370 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2371 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2372 | DCHECK_EQ(value, 0); |
| 2373 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2374 | DCHECK(!needs_write_barrier); |
| 2375 | DCHECK(!may_need_runtime_call_for_type_check); |
| 2376 | break; |
| 2377 | } |
| 2378 | |
| 2379 | DCHECK(needs_write_barrier); |
| 2380 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2381 | GpuRegister temp1 = locations->GetTemp(0).AsRegister<GpuRegister>(); |
| 2382 | GpuRegister temp2 = TMP; // Doesn't need to survive slow path. |
| 2383 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2384 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2385 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2386 | Mips64Label done; |
| 2387 | SlowPathCodeMIPS64* slow_path = nullptr; |
| 2388 | |
| 2389 | if (may_need_runtime_call_for_type_check) { |
| 2390 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathMIPS64(instruction); |
| 2391 | codegen_->AddSlowPath(slow_path); |
| 2392 | if (instruction->GetValueCanBeNull()) { |
| 2393 | Mips64Label non_zero; |
| 2394 | __ Bnezc(value, &non_zero); |
| 2395 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2396 | if (index.IsConstant()) { |
| 2397 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2398 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2399 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2400 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2401 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2402 | __ Bc(&done); |
| 2403 | __ Bind(&non_zero); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2404 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2405 | |
| 2406 | // Note that when read barriers are enabled, the type checks |
| 2407 | // are performed without read barriers. This is fine, even in |
| 2408 | // the case where a class object is in the from-space after |
| 2409 | // the flip, as a comparison involving such a type would not |
| 2410 | // produce a false positive; it may of course produce a false |
| 2411 | // negative, in which case we would take the ArraySet slow |
| 2412 | // path. |
| 2413 | |
| 2414 | // /* HeapReference<Class> */ temp1 = obj->klass_ |
| 2415 | __ LoadFromOffset(kLoadUnsignedWord, temp1, obj, class_offset, null_checker); |
| 2416 | __ MaybeUnpoisonHeapReference(temp1); |
| 2417 | |
| 2418 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 2419 | __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, component_offset); |
| 2420 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2421 | __ LoadFromOffset(kLoadUnsignedWord, temp2, value, class_offset); |
| 2422 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 2423 | // nor `temp2`, as we are comparing two poisoned references. |
| 2424 | |
| 2425 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2426 | Mips64Label do_put; |
| 2427 | __ Beqc(temp1, temp2, &do_put); |
| 2428 | // If heap poisoning is enabled, the `temp1` reference has |
| 2429 | // not been unpoisoned yet; unpoison it now. |
| 2430 | __ MaybeUnpoisonHeapReference(temp1); |
| 2431 | |
| 2432 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 2433 | __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, super_offset); |
| 2434 | // If heap poisoning is enabled, no need to unpoison |
| 2435 | // `temp1`, as we are comparing against null below. |
| 2436 | __ Bnezc(temp1, slow_path->GetEntryLabel()); |
| 2437 | __ Bind(&do_put); |
| 2438 | } else { |
| 2439 | __ Bnec(temp1, temp2, slow_path->GetEntryLabel()); |
| 2440 | } |
| 2441 | } |
| 2442 | |
| 2443 | GpuRegister source = value; |
| 2444 | if (kPoisonHeapReferences) { |
| 2445 | // Note that in the case where `value` is a null reference, |
| 2446 | // we do not enter this block, as a null reference does not |
| 2447 | // need poisoning. |
| 2448 | __ Move(temp1, value); |
| 2449 | __ PoisonHeapReference(temp1); |
| 2450 | source = temp1; |
| 2451 | } |
| 2452 | |
| 2453 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2454 | if (index.IsConstant()) { |
| 2455 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2456 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2457 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2458 | } |
| 2459 | __ StoreToOffset(kStoreWord, source, base_reg, data_offset); |
| 2460 | |
| 2461 | if (!may_need_runtime_call_for_type_check) { |
| 2462 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2463 | } |
| 2464 | |
| 2465 | codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull()); |
| 2466 | |
| 2467 | if (done.IsLinked()) { |
| 2468 | __ Bind(&done); |
| 2469 | } |
| 2470 | |
| 2471 | if (slow_path != nullptr) { |
| 2472 | __ Bind(slow_path->GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2473 | } |
| 2474 | break; |
| 2475 | } |
| 2476 | |
| 2477 | case Primitive::kPrimLong: { |
| 2478 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2479 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2480 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2481 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2482 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2483 | } |
| 2484 | if (value_location.IsConstant()) { |
| 2485 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2486 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2487 | } else { |
| 2488 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2489 | __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2490 | } |
| 2491 | break; |
| 2492 | } |
| 2493 | |
| 2494 | case Primitive::kPrimFloat: { |
| 2495 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2496 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2497 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2498 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2499 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2500 | } |
| 2501 | if (value_location.IsConstant()) { |
| 2502 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2503 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2504 | } else { |
| 2505 | FpuRegister value = value_location.AsFpuRegister<FpuRegister>(); |
| 2506 | __ StoreFpuToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2507 | } |
| 2508 | break; |
| 2509 | } |
| 2510 | |
| 2511 | case Primitive::kPrimDouble: { |
| 2512 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2513 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2514 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2515 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2516 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2517 | } |
| 2518 | if (value_location.IsConstant()) { |
| 2519 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2520 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2521 | } else { |
| 2522 | FpuRegister value = value_location.AsFpuRegister<FpuRegister>(); |
| 2523 | __ StoreFpuToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2524 | } |
| 2525 | break; |
| 2526 | } |
| 2527 | |
| 2528 | case Primitive::kPrimVoid: |
| 2529 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2530 | UNREACHABLE(); |
| 2531 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2532 | } |
| 2533 | |
| 2534 | void LocationsBuilderMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2535 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2536 | InvokeRuntimeCallingConvention calling_convention; |
| 2537 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2538 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2539 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2540 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2541 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | void InstructionCodeGeneratorMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2545 | LocationSummary* locations = instruction->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2546 | BoundsCheckSlowPathMIPS64* slow_path = |
| 2547 | new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS64(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2548 | codegen_->AddSlowPath(slow_path); |
| 2549 | |
| 2550 | GpuRegister index = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2551 | GpuRegister length = locations->InAt(1).AsRegister<GpuRegister>(); |
| 2552 | |
| 2553 | // length is limited by the maximum positive signed 32-bit integer. |
| 2554 | // Unsigned comparison of length and index checks for index < 0 |
| 2555 | // and for length <= index simultaneously. |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2556 | __ Bgeuc(index, length, slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2557 | } |
| 2558 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2559 | // Temp is used for read barrier. |
| 2560 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 2561 | if (kEmitCompilerReadBarrier && |
| 2562 | (kUseBakerReadBarrier || |
| 2563 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 2564 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 2565 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 2566 | return 1; |
| 2567 | } |
| 2568 | return 0; |
| 2569 | } |
| 2570 | |
| 2571 | // Extra temp is used for read barrier. |
| 2572 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 2573 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 2574 | } |
| 2575 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2576 | void LocationsBuilderMIPS64::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2577 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 2578 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 2579 | |
| 2580 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 2581 | switch (type_check_kind) { |
| 2582 | case TypeCheckKind::kExactCheck: |
| 2583 | case TypeCheckKind::kAbstractClassCheck: |
| 2584 | case TypeCheckKind::kClassHierarchyCheck: |
| 2585 | case TypeCheckKind::kArrayObjectCheck: |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2586 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2587 | ? LocationSummary::kCallOnSlowPath |
| 2588 | : LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
| 2589 | break; |
| 2590 | case TypeCheckKind::kArrayCheck: |
| 2591 | case TypeCheckKind::kUnresolvedCheck: |
| 2592 | case TypeCheckKind::kInterfaceCheck: |
| 2593 | call_kind = LocationSummary::kCallOnSlowPath; |
| 2594 | break; |
| 2595 | } |
| 2596 | |
| 2597 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2598 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2599 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2600 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2601 | } |
| 2602 | |
| 2603 | void InstructionCodeGeneratorMIPS64::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2604 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2605 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2606 | Location obj_loc = locations->InAt(0); |
| 2607 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2608 | GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2609 | Location temp_loc = locations->GetTemp(0); |
| 2610 | GpuRegister temp = temp_loc.AsRegister<GpuRegister>(); |
| 2611 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 2612 | DCHECK_LE(num_temps, 2u); |
| 2613 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2614 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2615 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2616 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2617 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 2618 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 2619 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 2620 | const uint32_t object_array_data_offset = |
| 2621 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| 2622 | Mips64Label done; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2623 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2624 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 2625 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 2626 | // read barriers is done for performance and code size reasons. |
| 2627 | bool is_type_check_slow_path_fatal = false; |
| 2628 | if (!kEmitCompilerReadBarrier) { |
| 2629 | is_type_check_slow_path_fatal = |
| 2630 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 2631 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 2632 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 2633 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 2634 | !instruction->CanThrowIntoCatchBlock(); |
| 2635 | } |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2636 | SlowPathCodeMIPS64* slow_path = |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2637 | new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction, |
| 2638 | is_type_check_slow_path_fatal); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2639 | codegen_->AddSlowPath(slow_path); |
| 2640 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2641 | // Avoid this check if we know `obj` is not null. |
| 2642 | if (instruction->MustDoNullCheck()) { |
| 2643 | __ Beqzc(obj, &done); |
| 2644 | } |
| 2645 | |
| 2646 | switch (type_check_kind) { |
| 2647 | case TypeCheckKind::kExactCheck: |
| 2648 | case TypeCheckKind::kArrayCheck: { |
| 2649 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2650 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2651 | temp_loc, |
| 2652 | obj_loc, |
| 2653 | class_offset, |
| 2654 | maybe_temp2_loc, |
| 2655 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2656 | // Jump to slow path for throwing the exception or doing a |
| 2657 | // more involved array check. |
| 2658 | __ Bnec(temp, cls, slow_path->GetEntryLabel()); |
| 2659 | break; |
| 2660 | } |
| 2661 | |
| 2662 | case TypeCheckKind::kAbstractClassCheck: { |
| 2663 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2664 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2665 | temp_loc, |
| 2666 | obj_loc, |
| 2667 | class_offset, |
| 2668 | maybe_temp2_loc, |
| 2669 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2670 | // If the class is abstract, we eagerly fetch the super class of the |
| 2671 | // object to avoid doing a comparison we know will fail. |
| 2672 | Mips64Label loop; |
| 2673 | __ Bind(&loop); |
| 2674 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2675 | GenerateReferenceLoadOneRegister(instruction, |
| 2676 | temp_loc, |
| 2677 | super_offset, |
| 2678 | maybe_temp2_loc, |
| 2679 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2680 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 2681 | // exception. |
| 2682 | __ Beqzc(temp, slow_path->GetEntryLabel()); |
| 2683 | // Otherwise, compare the classes. |
| 2684 | __ Bnec(temp, cls, &loop); |
| 2685 | break; |
| 2686 | } |
| 2687 | |
| 2688 | case TypeCheckKind::kClassHierarchyCheck: { |
| 2689 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2690 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2691 | temp_loc, |
| 2692 | obj_loc, |
| 2693 | class_offset, |
| 2694 | maybe_temp2_loc, |
| 2695 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2696 | // Walk over the class hierarchy to find a match. |
| 2697 | Mips64Label loop; |
| 2698 | __ Bind(&loop); |
| 2699 | __ Beqc(temp, cls, &done); |
| 2700 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2701 | GenerateReferenceLoadOneRegister(instruction, |
| 2702 | temp_loc, |
| 2703 | super_offset, |
| 2704 | maybe_temp2_loc, |
| 2705 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2706 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 2707 | // exception. Otherwise, jump to the beginning of the loop. |
| 2708 | __ Bnezc(temp, &loop); |
| 2709 | __ Bc(slow_path->GetEntryLabel()); |
| 2710 | break; |
| 2711 | } |
| 2712 | |
| 2713 | case TypeCheckKind::kArrayObjectCheck: { |
| 2714 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2715 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2716 | temp_loc, |
| 2717 | obj_loc, |
| 2718 | class_offset, |
| 2719 | maybe_temp2_loc, |
| 2720 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2721 | // Do an exact check. |
| 2722 | __ Beqc(temp, cls, &done); |
| 2723 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 2724 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2725 | GenerateReferenceLoadOneRegister(instruction, |
| 2726 | temp_loc, |
| 2727 | component_offset, |
| 2728 | maybe_temp2_loc, |
| 2729 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2730 | // If the component type is null, jump to the slow path to throw the exception. |
| 2731 | __ Beqzc(temp, slow_path->GetEntryLabel()); |
| 2732 | // Otherwise, the object is indeed an array, further check that this component |
| 2733 | // type is not a primitive type. |
| 2734 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 2735 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 2736 | __ Bnezc(temp, slow_path->GetEntryLabel()); |
| 2737 | break; |
| 2738 | } |
| 2739 | |
| 2740 | case TypeCheckKind::kUnresolvedCheck: |
| 2741 | // We always go into the type check slow path for the unresolved check case. |
| 2742 | // We cannot directly call the CheckCast runtime entry point |
| 2743 | // without resorting to a type checking slow path here (i.e. by |
| 2744 | // calling InvokeRuntime directly), as it would require to |
| 2745 | // assign fixed registers for the inputs of this HInstanceOf |
| 2746 | // instruction (following the runtime calling convention), which |
| 2747 | // might be cluttered by the potential first read barrier |
| 2748 | // emission at the beginning of this method. |
| 2749 | __ Bc(slow_path->GetEntryLabel()); |
| 2750 | break; |
| 2751 | |
| 2752 | case TypeCheckKind::kInterfaceCheck: { |
| 2753 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 2754 | // positives by doing this. |
| 2755 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2756 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2757 | temp_loc, |
| 2758 | obj_loc, |
| 2759 | class_offset, |
| 2760 | maybe_temp2_loc, |
| 2761 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2762 | // /* HeapReference<Class> */ temp = temp->iftable_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2763 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2764 | temp_loc, |
| 2765 | temp_loc, |
| 2766 | iftable_offset, |
| 2767 | maybe_temp2_loc, |
| 2768 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2769 | // Iftable is never null. |
| 2770 | __ Lw(TMP, temp, array_length_offset); |
| 2771 | // Loop through the iftable and check if any class matches. |
| 2772 | Mips64Label loop; |
| 2773 | __ Bind(&loop); |
| 2774 | __ Beqzc(TMP, slow_path->GetEntryLabel()); |
| 2775 | __ Lwu(AT, temp, object_array_data_offset); |
| 2776 | __ MaybeUnpoisonHeapReference(AT); |
| 2777 | // Go to next interface. |
| 2778 | __ Daddiu(temp, temp, 2 * kHeapReferenceSize); |
| 2779 | __ Addiu(TMP, TMP, -2); |
| 2780 | // Compare the classes and continue the loop if they do not match. |
| 2781 | __ Bnec(AT, cls, &loop); |
| 2782 | break; |
| 2783 | } |
| 2784 | } |
| 2785 | |
| 2786 | __ Bind(&done); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2787 | __ Bind(slow_path->GetExitLabel()); |
| 2788 | } |
| 2789 | |
| 2790 | void LocationsBuilderMIPS64::VisitClinitCheck(HClinitCheck* check) { |
| 2791 | LocationSummary* locations = |
| 2792 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2793 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2794 | if (check->HasUses()) { |
| 2795 | locations->SetOut(Location::SameAsFirstInput()); |
| 2796 | } |
| 2797 | } |
| 2798 | |
| 2799 | void InstructionCodeGeneratorMIPS64::VisitClinitCheck(HClinitCheck* check) { |
| 2800 | // We assume the class is not null. |
| 2801 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64( |
| 2802 | check->GetLoadClass(), |
| 2803 | check, |
| 2804 | check->GetDexPc(), |
| 2805 | true); |
| 2806 | codegen_->AddSlowPath(slow_path); |
| 2807 | GenerateClassInitializationCheck(slow_path, |
| 2808 | check->GetLocations()->InAt(0).AsRegister<GpuRegister>()); |
| 2809 | } |
| 2810 | |
| 2811 | void LocationsBuilderMIPS64::VisitCompare(HCompare* compare) { |
| 2812 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 2813 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2814 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(compare); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2815 | |
| 2816 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2817 | case Primitive::kPrimBoolean: |
| 2818 | case Primitive::kPrimByte: |
| 2819 | case Primitive::kPrimShort: |
| 2820 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2821 | case Primitive::kPrimInt: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2822 | case Primitive::kPrimLong: |
| 2823 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 2824 | locations->SetInAt(1, Location::RegisterOrConstant(compare->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2825 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2826 | break; |
| 2827 | |
| 2828 | case Primitive::kPrimFloat: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2829 | case Primitive::kPrimDouble: |
| 2830 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2831 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2832 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2833 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2834 | |
| 2835 | default: |
| 2836 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2837 | } |
| 2838 | } |
| 2839 | |
| 2840 | void InstructionCodeGeneratorMIPS64::VisitCompare(HCompare* instruction) { |
| 2841 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2842 | GpuRegister res = locations->Out().AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2843 | Primitive::Type in_type = instruction->InputAt(0)->GetType(); |
| 2844 | |
| 2845 | // 0 if: left == right |
| 2846 | // 1 if: left > right |
| 2847 | // -1 if: left < right |
| 2848 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2849 | case Primitive::kPrimBoolean: |
| 2850 | case Primitive::kPrimByte: |
| 2851 | case Primitive::kPrimShort: |
| 2852 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2853 | case Primitive::kPrimInt: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2854 | case Primitive::kPrimLong: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2855 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 2856 | Location rhs_location = locations->InAt(1); |
| 2857 | bool use_imm = rhs_location.IsConstant(); |
| 2858 | GpuRegister rhs = ZERO; |
| 2859 | if (use_imm) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2860 | if (in_type == Primitive::kPrimLong) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2861 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 2862 | if (value != 0) { |
| 2863 | rhs = AT; |
| 2864 | __ LoadConst64(rhs, value); |
| 2865 | } |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2866 | } else { |
| 2867 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 2868 | if (value != 0) { |
| 2869 | rhs = AT; |
| 2870 | __ LoadConst32(rhs, value); |
| 2871 | } |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 2872 | } |
| 2873 | } else { |
| 2874 | rhs = rhs_location.AsRegister<GpuRegister>(); |
| 2875 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2876 | __ Slt(TMP, lhs, rhs); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2877 | __ Slt(res, rhs, lhs); |
| 2878 | __ Subu(res, res, TMP); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2879 | break; |
| 2880 | } |
| 2881 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2882 | case Primitive::kPrimFloat: { |
| 2883 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 2884 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 2885 | Mips64Label done; |
| 2886 | __ CmpEqS(FTMP, lhs, rhs); |
| 2887 | __ LoadConst32(res, 0); |
| 2888 | __ Bc1nez(FTMP, &done); |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 2889 | if (instruction->IsGtBias()) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2890 | __ CmpLtS(FTMP, lhs, rhs); |
| 2891 | __ LoadConst32(res, -1); |
| 2892 | __ Bc1nez(FTMP, &done); |
| 2893 | __ LoadConst32(res, 1); |
| 2894 | } else { |
| 2895 | __ CmpLtS(FTMP, rhs, lhs); |
| 2896 | __ LoadConst32(res, 1); |
| 2897 | __ Bc1nez(FTMP, &done); |
| 2898 | __ LoadConst32(res, -1); |
| 2899 | } |
| 2900 | __ Bind(&done); |
| 2901 | break; |
| 2902 | } |
| 2903 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2904 | case Primitive::kPrimDouble: { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2905 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 2906 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 2907 | Mips64Label done; |
| 2908 | __ CmpEqD(FTMP, lhs, rhs); |
| 2909 | __ LoadConst32(res, 0); |
| 2910 | __ Bc1nez(FTMP, &done); |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 2911 | if (instruction->IsGtBias()) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2912 | __ CmpLtD(FTMP, lhs, rhs); |
| 2913 | __ LoadConst32(res, -1); |
| 2914 | __ Bc1nez(FTMP, &done); |
| 2915 | __ LoadConst32(res, 1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2916 | } else { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2917 | __ CmpLtD(FTMP, rhs, lhs); |
| 2918 | __ LoadConst32(res, 1); |
| 2919 | __ Bc1nez(FTMP, &done); |
| 2920 | __ LoadConst32(res, -1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2921 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2922 | __ Bind(&done); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2923 | break; |
| 2924 | } |
| 2925 | |
| 2926 | default: |
| 2927 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2928 | } |
| 2929 | } |
| 2930 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2931 | void LocationsBuilderMIPS64::HandleCondition(HCondition* instruction) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2932 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2933 | switch (instruction->InputAt(0)->GetType()) { |
| 2934 | default: |
| 2935 | case Primitive::kPrimLong: |
| 2936 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2937 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2938 | break; |
| 2939 | |
| 2940 | case Primitive::kPrimFloat: |
| 2941 | case Primitive::kPrimDouble: |
| 2942 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2943 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2944 | break; |
| 2945 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2946 | if (!instruction->IsEmittedAtUseSite()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2947 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2948 | } |
| 2949 | } |
| 2950 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2951 | void InstructionCodeGeneratorMIPS64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2952 | if (instruction->IsEmittedAtUseSite()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2953 | return; |
| 2954 | } |
| 2955 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2956 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2957 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2958 | switch (type) { |
| 2959 | default: |
| 2960 | // Integer case. |
| 2961 | GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ false, locations); |
| 2962 | return; |
| 2963 | case Primitive::kPrimLong: |
| 2964 | GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ true, locations); |
| 2965 | return; |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2966 | case Primitive::kPrimFloat: |
| 2967 | case Primitive::kPrimDouble: |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 2968 | GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations); |
| 2969 | return; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2970 | } |
| 2971 | } |
| 2972 | |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 2973 | void InstructionCodeGeneratorMIPS64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2974 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2975 | Primitive::Type type = instruction->GetResultType(); |
| 2976 | |
| 2977 | LocationSummary* locations = instruction->GetLocations(); |
| 2978 | Location second = locations->InAt(1); |
| 2979 | DCHECK(second.IsConstant()); |
| 2980 | |
| 2981 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 2982 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2983 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2984 | DCHECK(imm == 1 || imm == -1); |
| 2985 | |
| 2986 | if (instruction->IsRem()) { |
| 2987 | __ Move(out, ZERO); |
| 2988 | } else { |
| 2989 | if (imm == -1) { |
| 2990 | if (type == Primitive::kPrimInt) { |
| 2991 | __ Subu(out, ZERO, dividend); |
| 2992 | } else { |
| 2993 | DCHECK_EQ(type, Primitive::kPrimLong); |
| 2994 | __ Dsubu(out, ZERO, dividend); |
| 2995 | } |
| 2996 | } else if (out != dividend) { |
| 2997 | __ Move(out, dividend); |
| 2998 | } |
| 2999 | } |
| 3000 | } |
| 3001 | |
| 3002 | void InstructionCodeGeneratorMIPS64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3003 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3004 | Primitive::Type type = instruction->GetResultType(); |
| 3005 | |
| 3006 | LocationSummary* locations = instruction->GetLocations(); |
| 3007 | Location second = locations->InAt(1); |
| 3008 | DCHECK(second.IsConstant()); |
| 3009 | |
| 3010 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3011 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3012 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3013 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3014 | int ctz_imm = CTZ(abs_imm); |
| 3015 | |
| 3016 | if (instruction->IsDiv()) { |
| 3017 | if (type == Primitive::kPrimInt) { |
| 3018 | if (ctz_imm == 1) { |
| 3019 | // Fast path for division by +/-2, which is very common. |
| 3020 | __ Srl(TMP, dividend, 31); |
| 3021 | } else { |
| 3022 | __ Sra(TMP, dividend, 31); |
| 3023 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3024 | } |
| 3025 | __ Addu(out, dividend, TMP); |
| 3026 | __ Sra(out, out, ctz_imm); |
| 3027 | if (imm < 0) { |
| 3028 | __ Subu(out, ZERO, out); |
| 3029 | } |
| 3030 | } else { |
| 3031 | DCHECK_EQ(type, Primitive::kPrimLong); |
| 3032 | if (ctz_imm == 1) { |
| 3033 | // Fast path for division by +/-2, which is very common. |
| 3034 | __ Dsrl32(TMP, dividend, 31); |
| 3035 | } else { |
| 3036 | __ Dsra32(TMP, dividend, 31); |
| 3037 | if (ctz_imm > 32) { |
| 3038 | __ Dsrl(TMP, TMP, 64 - ctz_imm); |
| 3039 | } else { |
| 3040 | __ Dsrl32(TMP, TMP, 32 - ctz_imm); |
| 3041 | } |
| 3042 | } |
| 3043 | __ Daddu(out, dividend, TMP); |
| 3044 | if (ctz_imm < 32) { |
| 3045 | __ Dsra(out, out, ctz_imm); |
| 3046 | } else { |
| 3047 | __ Dsra32(out, out, ctz_imm - 32); |
| 3048 | } |
| 3049 | if (imm < 0) { |
| 3050 | __ Dsubu(out, ZERO, out); |
| 3051 | } |
| 3052 | } |
| 3053 | } else { |
| 3054 | if (type == Primitive::kPrimInt) { |
| 3055 | if (ctz_imm == 1) { |
| 3056 | // Fast path for modulo +/-2, which is very common. |
| 3057 | __ Sra(TMP, dividend, 31); |
| 3058 | __ Subu(out, dividend, TMP); |
| 3059 | __ Andi(out, out, 1); |
| 3060 | __ Addu(out, out, TMP); |
| 3061 | } else { |
| 3062 | __ Sra(TMP, dividend, 31); |
| 3063 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3064 | __ Addu(out, dividend, TMP); |
| 3065 | if (IsUint<16>(abs_imm - 1)) { |
| 3066 | __ Andi(out, out, abs_imm - 1); |
| 3067 | } else { |
| 3068 | __ Sll(out, out, 32 - ctz_imm); |
| 3069 | __ Srl(out, out, 32 - ctz_imm); |
| 3070 | } |
| 3071 | __ Subu(out, out, TMP); |
| 3072 | } |
| 3073 | } else { |
| 3074 | DCHECK_EQ(type, Primitive::kPrimLong); |
| 3075 | if (ctz_imm == 1) { |
| 3076 | // Fast path for modulo +/-2, which is very common. |
| 3077 | __ Dsra32(TMP, dividend, 31); |
| 3078 | __ Dsubu(out, dividend, TMP); |
| 3079 | __ Andi(out, out, 1); |
| 3080 | __ Daddu(out, out, TMP); |
| 3081 | } else { |
| 3082 | __ Dsra32(TMP, dividend, 31); |
| 3083 | if (ctz_imm > 32) { |
| 3084 | __ Dsrl(TMP, TMP, 64 - ctz_imm); |
| 3085 | } else { |
| 3086 | __ Dsrl32(TMP, TMP, 32 - ctz_imm); |
| 3087 | } |
| 3088 | __ Daddu(out, dividend, TMP); |
| 3089 | if (IsUint<16>(abs_imm - 1)) { |
| 3090 | __ Andi(out, out, abs_imm - 1); |
| 3091 | } else { |
| 3092 | if (ctz_imm > 32) { |
| 3093 | __ Dsll(out, out, 64 - ctz_imm); |
| 3094 | __ Dsrl(out, out, 64 - ctz_imm); |
| 3095 | } else { |
| 3096 | __ Dsll32(out, out, 32 - ctz_imm); |
| 3097 | __ Dsrl32(out, out, 32 - ctz_imm); |
| 3098 | } |
| 3099 | } |
| 3100 | __ Dsubu(out, out, TMP); |
| 3101 | } |
| 3102 | } |
| 3103 | } |
| 3104 | } |
| 3105 | |
| 3106 | void InstructionCodeGeneratorMIPS64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3107 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3108 | |
| 3109 | LocationSummary* locations = instruction->GetLocations(); |
| 3110 | Location second = locations->InAt(1); |
| 3111 | DCHECK(second.IsConstant()); |
| 3112 | |
| 3113 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3114 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3115 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3116 | |
| 3117 | Primitive::Type type = instruction->GetResultType(); |
| 3118 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong) << type; |
| 3119 | |
| 3120 | int64_t magic; |
| 3121 | int shift; |
| 3122 | CalculateMagicAndShiftForDivRem(imm, |
| 3123 | (type == Primitive::kPrimLong), |
| 3124 | &magic, |
| 3125 | &shift); |
| 3126 | |
| 3127 | if (type == Primitive::kPrimInt) { |
| 3128 | __ LoadConst32(TMP, magic); |
| 3129 | __ MuhR6(TMP, dividend, TMP); |
| 3130 | |
| 3131 | if (imm > 0 && magic < 0) { |
| 3132 | __ Addu(TMP, TMP, dividend); |
| 3133 | } else if (imm < 0 && magic > 0) { |
| 3134 | __ Subu(TMP, TMP, dividend); |
| 3135 | } |
| 3136 | |
| 3137 | if (shift != 0) { |
| 3138 | __ Sra(TMP, TMP, shift); |
| 3139 | } |
| 3140 | |
| 3141 | if (instruction->IsDiv()) { |
| 3142 | __ Sra(out, TMP, 31); |
| 3143 | __ Subu(out, TMP, out); |
| 3144 | } else { |
| 3145 | __ Sra(AT, TMP, 31); |
| 3146 | __ Subu(AT, TMP, AT); |
| 3147 | __ LoadConst32(TMP, imm); |
| 3148 | __ MulR6(TMP, AT, TMP); |
| 3149 | __ Subu(out, dividend, TMP); |
| 3150 | } |
| 3151 | } else { |
| 3152 | __ LoadConst64(TMP, magic); |
| 3153 | __ Dmuh(TMP, dividend, TMP); |
| 3154 | |
| 3155 | if (imm > 0 && magic < 0) { |
| 3156 | __ Daddu(TMP, TMP, dividend); |
| 3157 | } else if (imm < 0 && magic > 0) { |
| 3158 | __ Dsubu(TMP, TMP, dividend); |
| 3159 | } |
| 3160 | |
| 3161 | if (shift >= 32) { |
| 3162 | __ Dsra32(TMP, TMP, shift - 32); |
| 3163 | } else if (shift > 0) { |
| 3164 | __ Dsra(TMP, TMP, shift); |
| 3165 | } |
| 3166 | |
| 3167 | if (instruction->IsDiv()) { |
| 3168 | __ Dsra32(out, TMP, 31); |
| 3169 | __ Dsubu(out, TMP, out); |
| 3170 | } else { |
| 3171 | __ Dsra32(AT, TMP, 31); |
| 3172 | __ Dsubu(AT, TMP, AT); |
| 3173 | __ LoadConst64(TMP, imm); |
| 3174 | __ Dmul(TMP, AT, TMP); |
| 3175 | __ Dsubu(out, dividend, TMP); |
| 3176 | } |
| 3177 | } |
| 3178 | } |
| 3179 | |
| 3180 | void InstructionCodeGeneratorMIPS64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3181 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3182 | Primitive::Type type = instruction->GetResultType(); |
| 3183 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong) << type; |
| 3184 | |
| 3185 | LocationSummary* locations = instruction->GetLocations(); |
| 3186 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3187 | Location second = locations->InAt(1); |
| 3188 | |
| 3189 | if (second.IsConstant()) { |
| 3190 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3191 | if (imm == 0) { |
| 3192 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3193 | } else if (imm == 1 || imm == -1) { |
| 3194 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3195 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3196 | DivRemByPowerOfTwo(instruction); |
| 3197 | } else { |
| 3198 | DCHECK(imm <= -2 || imm >= 2); |
| 3199 | GenerateDivRemWithAnyConstant(instruction); |
| 3200 | } |
| 3201 | } else { |
| 3202 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3203 | GpuRegister divisor = second.AsRegister<GpuRegister>(); |
| 3204 | if (instruction->IsDiv()) { |
| 3205 | if (type == Primitive::kPrimInt) |
| 3206 | __ DivR6(out, dividend, divisor); |
| 3207 | else |
| 3208 | __ Ddiv(out, dividend, divisor); |
| 3209 | } else { |
| 3210 | if (type == Primitive::kPrimInt) |
| 3211 | __ ModR6(out, dividend, divisor); |
| 3212 | else |
| 3213 | __ Dmod(out, dividend, divisor); |
| 3214 | } |
| 3215 | } |
| 3216 | } |
| 3217 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3218 | void LocationsBuilderMIPS64::VisitDiv(HDiv* div) { |
| 3219 | LocationSummary* locations = |
| 3220 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3221 | switch (div->GetResultType()) { |
| 3222 | case Primitive::kPrimInt: |
| 3223 | case Primitive::kPrimLong: |
| 3224 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3225 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3226 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3227 | break; |
| 3228 | |
| 3229 | case Primitive::kPrimFloat: |
| 3230 | case Primitive::kPrimDouble: |
| 3231 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3232 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3233 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3234 | break; |
| 3235 | |
| 3236 | default: |
| 3237 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3238 | } |
| 3239 | } |
| 3240 | |
| 3241 | void InstructionCodeGeneratorMIPS64::VisitDiv(HDiv* instruction) { |
| 3242 | Primitive::Type type = instruction->GetType(); |
| 3243 | LocationSummary* locations = instruction->GetLocations(); |
| 3244 | |
| 3245 | switch (type) { |
| 3246 | case Primitive::kPrimInt: |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3247 | case Primitive::kPrimLong: |
| 3248 | GenerateDivRemIntegral(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3249 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3250 | case Primitive::kPrimFloat: |
| 3251 | case Primitive::kPrimDouble: { |
| 3252 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 3253 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3254 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 3255 | if (type == Primitive::kPrimFloat) |
| 3256 | __ DivS(dst, lhs, rhs); |
| 3257 | else |
| 3258 | __ DivD(dst, lhs, rhs); |
| 3259 | break; |
| 3260 | } |
| 3261 | default: |
| 3262 | LOG(FATAL) << "Unexpected div type " << type; |
| 3263 | } |
| 3264 | } |
| 3265 | |
| 3266 | void LocationsBuilderMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3267 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3268 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3269 | } |
| 3270 | |
| 3271 | void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3272 | SlowPathCodeMIPS64* slow_path = |
| 3273 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS64(instruction); |
| 3274 | codegen_->AddSlowPath(slow_path); |
| 3275 | Location value = instruction->GetLocations()->InAt(0); |
| 3276 | |
| 3277 | Primitive::Type type = instruction->GetType(); |
| 3278 | |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3279 | if (!Primitive::IsIntegralType(type)) { |
| 3280 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3281 | return; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3282 | } |
| 3283 | |
| 3284 | if (value.IsConstant()) { |
| 3285 | int64_t divisor = codegen_->GetInt64ValueOf(value.GetConstant()->AsConstant()); |
| 3286 | if (divisor == 0) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3287 | __ Bc(slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3288 | } else { |
| 3289 | // A division by a non-null constant is valid. We don't need to perform |
| 3290 | // any check, so simply fall through. |
| 3291 | } |
| 3292 | } else { |
| 3293 | __ Beqzc(value.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 3294 | } |
| 3295 | } |
| 3296 | |
| 3297 | void LocationsBuilderMIPS64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3298 | LocationSummary* locations = |
| 3299 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3300 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3301 | } |
| 3302 | |
| 3303 | void InstructionCodeGeneratorMIPS64::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 3304 | // Will be generated at use site. |
| 3305 | } |
| 3306 | |
| 3307 | void LocationsBuilderMIPS64::VisitExit(HExit* exit) { |
| 3308 | exit->SetLocations(nullptr); |
| 3309 | } |
| 3310 | |
| 3311 | void InstructionCodeGeneratorMIPS64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 3312 | } |
| 3313 | |
| 3314 | void LocationsBuilderMIPS64::VisitFloatConstant(HFloatConstant* constant) { |
| 3315 | LocationSummary* locations = |
| 3316 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3317 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3318 | } |
| 3319 | |
| 3320 | void InstructionCodeGeneratorMIPS64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 3321 | // Will be generated at use site. |
| 3322 | } |
| 3323 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3324 | void InstructionCodeGeneratorMIPS64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3325 | DCHECK(!successor->IsExitBlock()); |
| 3326 | HBasicBlock* block = got->GetBlock(); |
| 3327 | HInstruction* previous = got->GetPrevious(); |
| 3328 | HLoopInformation* info = block->GetLoopInformation(); |
| 3329 | |
| 3330 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| 3331 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 3332 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3333 | return; |
| 3334 | } |
| 3335 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3336 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 3337 | } |
| 3338 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3339 | __ Bc(codegen_->GetLabelOf(successor)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3340 | } |
| 3341 | } |
| 3342 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3343 | void LocationsBuilderMIPS64::VisitGoto(HGoto* got) { |
| 3344 | got->SetLocations(nullptr); |
| 3345 | } |
| 3346 | |
| 3347 | void InstructionCodeGeneratorMIPS64::VisitGoto(HGoto* got) { |
| 3348 | HandleGoto(got, got->GetSuccessor()); |
| 3349 | } |
| 3350 | |
| 3351 | void LocationsBuilderMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3352 | try_boundary->SetLocations(nullptr); |
| 3353 | } |
| 3354 | |
| 3355 | void InstructionCodeGeneratorMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3356 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3357 | if (!successor->IsExitBlock()) { |
| 3358 | HandleGoto(try_boundary, successor); |
| 3359 | } |
| 3360 | } |
| 3361 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3362 | void InstructionCodeGeneratorMIPS64::GenerateIntLongCompare(IfCondition cond, |
| 3363 | bool is64bit, |
| 3364 | LocationSummary* locations) { |
| 3365 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3366 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3367 | Location rhs_location = locations->InAt(1); |
| 3368 | GpuRegister rhs_reg = ZERO; |
| 3369 | int64_t rhs_imm = 0; |
| 3370 | bool use_imm = rhs_location.IsConstant(); |
| 3371 | if (use_imm) { |
| 3372 | if (is64bit) { |
| 3373 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3374 | } else { |
| 3375 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3376 | } |
| 3377 | } else { |
| 3378 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3379 | } |
| 3380 | int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1); |
| 3381 | |
| 3382 | switch (cond) { |
| 3383 | case kCondEQ: |
| 3384 | case kCondNE: |
Goran Jakovljevic | db3deee | 2016-12-28 14:33:21 +0100 | [diff] [blame] | 3385 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 3386 | if (rhs_imm == 0) { |
| 3387 | if (cond == kCondEQ) { |
| 3388 | __ Sltiu(dst, lhs, 1); |
| 3389 | } else { |
| 3390 | __ Sltu(dst, ZERO, lhs); |
| 3391 | } |
| 3392 | } else { |
| 3393 | if (is64bit) { |
| 3394 | __ Daddiu(dst, lhs, -rhs_imm); |
| 3395 | } else { |
| 3396 | __ Addiu(dst, lhs, -rhs_imm); |
| 3397 | } |
| 3398 | if (cond == kCondEQ) { |
| 3399 | __ Sltiu(dst, dst, 1); |
| 3400 | } else { |
| 3401 | __ Sltu(dst, ZERO, dst); |
| 3402 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3403 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3404 | } else { |
Goran Jakovljevic | db3deee | 2016-12-28 14:33:21 +0100 | [diff] [blame] | 3405 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 3406 | __ Xori(dst, lhs, rhs_imm); |
| 3407 | } else { |
| 3408 | if (use_imm) { |
| 3409 | rhs_reg = TMP; |
| 3410 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3411 | } |
| 3412 | __ Xor(dst, lhs, rhs_reg); |
| 3413 | } |
| 3414 | if (cond == kCondEQ) { |
| 3415 | __ Sltiu(dst, dst, 1); |
| 3416 | } else { |
| 3417 | __ Sltu(dst, ZERO, dst); |
| 3418 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3419 | } |
| 3420 | break; |
| 3421 | |
| 3422 | case kCondLT: |
| 3423 | case kCondGE: |
| 3424 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3425 | __ Slti(dst, lhs, rhs_imm); |
| 3426 | } else { |
| 3427 | if (use_imm) { |
| 3428 | rhs_reg = TMP; |
| 3429 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3430 | } |
| 3431 | __ Slt(dst, lhs, rhs_reg); |
| 3432 | } |
| 3433 | if (cond == kCondGE) { |
| 3434 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 3435 | // only the slt instruction but no sge. |
| 3436 | __ Xori(dst, dst, 1); |
| 3437 | } |
| 3438 | break; |
| 3439 | |
| 3440 | case kCondLE: |
| 3441 | case kCondGT: |
| 3442 | if (use_imm && IsInt<16>(rhs_imm_plus_one)) { |
| 3443 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3444 | __ Slti(dst, lhs, rhs_imm_plus_one); |
| 3445 | if (cond == kCondGT) { |
| 3446 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 3447 | // only the slti instruction but no sgti. |
| 3448 | __ Xori(dst, dst, 1); |
| 3449 | } |
| 3450 | } else { |
| 3451 | if (use_imm) { |
| 3452 | rhs_reg = TMP; |
| 3453 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3454 | } |
| 3455 | __ Slt(dst, rhs_reg, lhs); |
| 3456 | if (cond == kCondLE) { |
| 3457 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 3458 | // only the slt instruction but no sle. |
| 3459 | __ Xori(dst, dst, 1); |
| 3460 | } |
| 3461 | } |
| 3462 | break; |
| 3463 | |
| 3464 | case kCondB: |
| 3465 | case kCondAE: |
| 3466 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3467 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3468 | // the comparison and thus lets us compare directly with |
| 3469 | // unsigned values in the ranges [0, 0x7fff] and |
| 3470 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3471 | __ Sltiu(dst, lhs, rhs_imm); |
| 3472 | } else { |
| 3473 | if (use_imm) { |
| 3474 | rhs_reg = TMP; |
| 3475 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3476 | } |
| 3477 | __ Sltu(dst, lhs, rhs_reg); |
| 3478 | } |
| 3479 | if (cond == kCondAE) { |
| 3480 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 3481 | // only the sltu instruction but no sgeu. |
| 3482 | __ Xori(dst, dst, 1); |
| 3483 | } |
| 3484 | break; |
| 3485 | |
| 3486 | case kCondBE: |
| 3487 | case kCondA: |
| 3488 | if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) { |
| 3489 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3490 | // Note that this only works if rhs + 1 does not overflow |
| 3491 | // to 0, hence the check above. |
| 3492 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3493 | // the comparison and thus lets us compare directly with |
| 3494 | // unsigned values in the ranges [0, 0x7fff] and |
| 3495 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3496 | __ Sltiu(dst, lhs, rhs_imm_plus_one); |
| 3497 | if (cond == kCondA) { |
| 3498 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 3499 | // only the sltiu instruction but no sgtiu. |
| 3500 | __ Xori(dst, dst, 1); |
| 3501 | } |
| 3502 | } else { |
| 3503 | if (use_imm) { |
| 3504 | rhs_reg = TMP; |
| 3505 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3506 | } |
| 3507 | __ Sltu(dst, rhs_reg, lhs); |
| 3508 | if (cond == kCondBE) { |
| 3509 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 3510 | // only the sltu instruction but no sleu. |
| 3511 | __ Xori(dst, dst, 1); |
| 3512 | } |
| 3513 | } |
| 3514 | break; |
| 3515 | } |
| 3516 | } |
| 3517 | |
| 3518 | void InstructionCodeGeneratorMIPS64::GenerateIntLongCompareAndBranch(IfCondition cond, |
| 3519 | bool is64bit, |
| 3520 | LocationSummary* locations, |
| 3521 | Mips64Label* label) { |
| 3522 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3523 | Location rhs_location = locations->InAt(1); |
| 3524 | GpuRegister rhs_reg = ZERO; |
| 3525 | int64_t rhs_imm = 0; |
| 3526 | bool use_imm = rhs_location.IsConstant(); |
| 3527 | if (use_imm) { |
| 3528 | if (is64bit) { |
| 3529 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3530 | } else { |
| 3531 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3532 | } |
| 3533 | } else { |
| 3534 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3535 | } |
| 3536 | |
| 3537 | if (use_imm && rhs_imm == 0) { |
| 3538 | switch (cond) { |
| 3539 | case kCondEQ: |
| 3540 | case kCondBE: // <= 0 if zero |
| 3541 | __ Beqzc(lhs, label); |
| 3542 | break; |
| 3543 | case kCondNE: |
| 3544 | case kCondA: // > 0 if non-zero |
| 3545 | __ Bnezc(lhs, label); |
| 3546 | break; |
| 3547 | case kCondLT: |
| 3548 | __ Bltzc(lhs, label); |
| 3549 | break; |
| 3550 | case kCondGE: |
| 3551 | __ Bgezc(lhs, label); |
| 3552 | break; |
| 3553 | case kCondLE: |
| 3554 | __ Blezc(lhs, label); |
| 3555 | break; |
| 3556 | case kCondGT: |
| 3557 | __ Bgtzc(lhs, label); |
| 3558 | break; |
| 3559 | case kCondB: // always false |
| 3560 | break; |
| 3561 | case kCondAE: // always true |
| 3562 | __ Bc(label); |
| 3563 | break; |
| 3564 | } |
| 3565 | } else { |
| 3566 | if (use_imm) { |
| 3567 | rhs_reg = TMP; |
| 3568 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3569 | } |
| 3570 | switch (cond) { |
| 3571 | case kCondEQ: |
| 3572 | __ Beqc(lhs, rhs_reg, label); |
| 3573 | break; |
| 3574 | case kCondNE: |
| 3575 | __ Bnec(lhs, rhs_reg, label); |
| 3576 | break; |
| 3577 | case kCondLT: |
| 3578 | __ Bltc(lhs, rhs_reg, label); |
| 3579 | break; |
| 3580 | case kCondGE: |
| 3581 | __ Bgec(lhs, rhs_reg, label); |
| 3582 | break; |
| 3583 | case kCondLE: |
| 3584 | __ Bgec(rhs_reg, lhs, label); |
| 3585 | break; |
| 3586 | case kCondGT: |
| 3587 | __ Bltc(rhs_reg, lhs, label); |
| 3588 | break; |
| 3589 | case kCondB: |
| 3590 | __ Bltuc(lhs, rhs_reg, label); |
| 3591 | break; |
| 3592 | case kCondAE: |
| 3593 | __ Bgeuc(lhs, rhs_reg, label); |
| 3594 | break; |
| 3595 | case kCondBE: |
| 3596 | __ Bgeuc(rhs_reg, lhs, label); |
| 3597 | break; |
| 3598 | case kCondA: |
| 3599 | __ Bltuc(rhs_reg, lhs, label); |
| 3600 | break; |
| 3601 | } |
| 3602 | } |
| 3603 | } |
| 3604 | |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3605 | void InstructionCodeGeneratorMIPS64::GenerateFpCompare(IfCondition cond, |
| 3606 | bool gt_bias, |
| 3607 | Primitive::Type type, |
| 3608 | LocationSummary* locations) { |
| 3609 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3610 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3611 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 3612 | if (type == Primitive::kPrimFloat) { |
| 3613 | switch (cond) { |
| 3614 | case kCondEQ: |
| 3615 | __ CmpEqS(FTMP, lhs, rhs); |
| 3616 | __ Mfc1(dst, FTMP); |
| 3617 | __ Andi(dst, dst, 1); |
| 3618 | break; |
| 3619 | case kCondNE: |
| 3620 | __ CmpEqS(FTMP, lhs, rhs); |
| 3621 | __ Mfc1(dst, FTMP); |
| 3622 | __ Addiu(dst, dst, 1); |
| 3623 | break; |
| 3624 | case kCondLT: |
| 3625 | if (gt_bias) { |
| 3626 | __ CmpLtS(FTMP, lhs, rhs); |
| 3627 | } else { |
| 3628 | __ CmpUltS(FTMP, lhs, rhs); |
| 3629 | } |
| 3630 | __ Mfc1(dst, FTMP); |
| 3631 | __ Andi(dst, dst, 1); |
| 3632 | break; |
| 3633 | case kCondLE: |
| 3634 | if (gt_bias) { |
| 3635 | __ CmpLeS(FTMP, lhs, rhs); |
| 3636 | } else { |
| 3637 | __ CmpUleS(FTMP, lhs, rhs); |
| 3638 | } |
| 3639 | __ Mfc1(dst, FTMP); |
| 3640 | __ Andi(dst, dst, 1); |
| 3641 | break; |
| 3642 | case kCondGT: |
| 3643 | if (gt_bias) { |
| 3644 | __ CmpUltS(FTMP, rhs, lhs); |
| 3645 | } else { |
| 3646 | __ CmpLtS(FTMP, rhs, lhs); |
| 3647 | } |
| 3648 | __ Mfc1(dst, FTMP); |
| 3649 | __ Andi(dst, dst, 1); |
| 3650 | break; |
| 3651 | case kCondGE: |
| 3652 | if (gt_bias) { |
| 3653 | __ CmpUleS(FTMP, rhs, lhs); |
| 3654 | } else { |
| 3655 | __ CmpLeS(FTMP, rhs, lhs); |
| 3656 | } |
| 3657 | __ Mfc1(dst, FTMP); |
| 3658 | __ Andi(dst, dst, 1); |
| 3659 | break; |
| 3660 | default: |
| 3661 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3662 | UNREACHABLE(); |
| 3663 | } |
| 3664 | } else { |
| 3665 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 3666 | switch (cond) { |
| 3667 | case kCondEQ: |
| 3668 | __ CmpEqD(FTMP, lhs, rhs); |
| 3669 | __ Mfc1(dst, FTMP); |
| 3670 | __ Andi(dst, dst, 1); |
| 3671 | break; |
| 3672 | case kCondNE: |
| 3673 | __ CmpEqD(FTMP, lhs, rhs); |
| 3674 | __ Mfc1(dst, FTMP); |
| 3675 | __ Addiu(dst, dst, 1); |
| 3676 | break; |
| 3677 | case kCondLT: |
| 3678 | if (gt_bias) { |
| 3679 | __ CmpLtD(FTMP, lhs, rhs); |
| 3680 | } else { |
| 3681 | __ CmpUltD(FTMP, lhs, rhs); |
| 3682 | } |
| 3683 | __ Mfc1(dst, FTMP); |
| 3684 | __ Andi(dst, dst, 1); |
| 3685 | break; |
| 3686 | case kCondLE: |
| 3687 | if (gt_bias) { |
| 3688 | __ CmpLeD(FTMP, lhs, rhs); |
| 3689 | } else { |
| 3690 | __ CmpUleD(FTMP, lhs, rhs); |
| 3691 | } |
| 3692 | __ Mfc1(dst, FTMP); |
| 3693 | __ Andi(dst, dst, 1); |
| 3694 | break; |
| 3695 | case kCondGT: |
| 3696 | if (gt_bias) { |
| 3697 | __ CmpUltD(FTMP, rhs, lhs); |
| 3698 | } else { |
| 3699 | __ CmpLtD(FTMP, rhs, lhs); |
| 3700 | } |
| 3701 | __ Mfc1(dst, FTMP); |
| 3702 | __ Andi(dst, dst, 1); |
| 3703 | break; |
| 3704 | case kCondGE: |
| 3705 | if (gt_bias) { |
| 3706 | __ CmpUleD(FTMP, rhs, lhs); |
| 3707 | } else { |
| 3708 | __ CmpLeD(FTMP, rhs, lhs); |
| 3709 | } |
| 3710 | __ Mfc1(dst, FTMP); |
| 3711 | __ Andi(dst, dst, 1); |
| 3712 | break; |
| 3713 | default: |
| 3714 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3715 | UNREACHABLE(); |
| 3716 | } |
| 3717 | } |
| 3718 | } |
| 3719 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3720 | void InstructionCodeGeneratorMIPS64::GenerateFpCompareAndBranch(IfCondition cond, |
| 3721 | bool gt_bias, |
| 3722 | Primitive::Type type, |
| 3723 | LocationSummary* locations, |
| 3724 | Mips64Label* label) { |
| 3725 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3726 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 3727 | if (type == Primitive::kPrimFloat) { |
| 3728 | switch (cond) { |
| 3729 | case kCondEQ: |
| 3730 | __ CmpEqS(FTMP, lhs, rhs); |
| 3731 | __ Bc1nez(FTMP, label); |
| 3732 | break; |
| 3733 | case kCondNE: |
| 3734 | __ CmpEqS(FTMP, lhs, rhs); |
| 3735 | __ Bc1eqz(FTMP, label); |
| 3736 | break; |
| 3737 | case kCondLT: |
| 3738 | if (gt_bias) { |
| 3739 | __ CmpLtS(FTMP, lhs, rhs); |
| 3740 | } else { |
| 3741 | __ CmpUltS(FTMP, lhs, rhs); |
| 3742 | } |
| 3743 | __ Bc1nez(FTMP, label); |
| 3744 | break; |
| 3745 | case kCondLE: |
| 3746 | if (gt_bias) { |
| 3747 | __ CmpLeS(FTMP, lhs, rhs); |
| 3748 | } else { |
| 3749 | __ CmpUleS(FTMP, lhs, rhs); |
| 3750 | } |
| 3751 | __ Bc1nez(FTMP, label); |
| 3752 | break; |
| 3753 | case kCondGT: |
| 3754 | if (gt_bias) { |
| 3755 | __ CmpUltS(FTMP, rhs, lhs); |
| 3756 | } else { |
| 3757 | __ CmpLtS(FTMP, rhs, lhs); |
| 3758 | } |
| 3759 | __ Bc1nez(FTMP, label); |
| 3760 | break; |
| 3761 | case kCondGE: |
| 3762 | if (gt_bias) { |
| 3763 | __ CmpUleS(FTMP, rhs, lhs); |
| 3764 | } else { |
| 3765 | __ CmpLeS(FTMP, rhs, lhs); |
| 3766 | } |
| 3767 | __ Bc1nez(FTMP, label); |
| 3768 | break; |
| 3769 | default: |
| 3770 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3771 | } |
| 3772 | } else { |
| 3773 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 3774 | switch (cond) { |
| 3775 | case kCondEQ: |
| 3776 | __ CmpEqD(FTMP, lhs, rhs); |
| 3777 | __ Bc1nez(FTMP, label); |
| 3778 | break; |
| 3779 | case kCondNE: |
| 3780 | __ CmpEqD(FTMP, lhs, rhs); |
| 3781 | __ Bc1eqz(FTMP, label); |
| 3782 | break; |
| 3783 | case kCondLT: |
| 3784 | if (gt_bias) { |
| 3785 | __ CmpLtD(FTMP, lhs, rhs); |
| 3786 | } else { |
| 3787 | __ CmpUltD(FTMP, lhs, rhs); |
| 3788 | } |
| 3789 | __ Bc1nez(FTMP, label); |
| 3790 | break; |
| 3791 | case kCondLE: |
| 3792 | if (gt_bias) { |
| 3793 | __ CmpLeD(FTMP, lhs, rhs); |
| 3794 | } else { |
| 3795 | __ CmpUleD(FTMP, lhs, rhs); |
| 3796 | } |
| 3797 | __ Bc1nez(FTMP, label); |
| 3798 | break; |
| 3799 | case kCondGT: |
| 3800 | if (gt_bias) { |
| 3801 | __ CmpUltD(FTMP, rhs, lhs); |
| 3802 | } else { |
| 3803 | __ CmpLtD(FTMP, rhs, lhs); |
| 3804 | } |
| 3805 | __ Bc1nez(FTMP, label); |
| 3806 | break; |
| 3807 | case kCondGE: |
| 3808 | if (gt_bias) { |
| 3809 | __ CmpUleD(FTMP, rhs, lhs); |
| 3810 | } else { |
| 3811 | __ CmpLeD(FTMP, rhs, lhs); |
| 3812 | } |
| 3813 | __ Bc1nez(FTMP, label); |
| 3814 | break; |
| 3815 | default: |
| 3816 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3817 | } |
| 3818 | } |
| 3819 | } |
| 3820 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3821 | void InstructionCodeGeneratorMIPS64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3822 | size_t condition_input_index, |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3823 | Mips64Label* true_target, |
| 3824 | Mips64Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3825 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3826 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3827 | if (true_target == nullptr && false_target == nullptr) { |
| 3828 | // Nothing to do. The code always falls through. |
| 3829 | return; |
| 3830 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3831 | // Constant condition, statically compared against "true" (integer value 1). |
| 3832 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3833 | if (true_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3834 | __ Bc(true_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3835 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3836 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3837 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3838 | if (false_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3839 | __ Bc(false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3840 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3841 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3842 | return; |
| 3843 | } |
| 3844 | |
| 3845 | // The following code generates these patterns: |
| 3846 | // (1) true_target == nullptr && false_target != nullptr |
| 3847 | // - opposite condition true => branch to false_target |
| 3848 | // (2) true_target != nullptr && false_target == nullptr |
| 3849 | // - condition true => branch to true_target |
| 3850 | // (3) true_target != nullptr && false_target != nullptr |
| 3851 | // - condition true => branch to true_target |
| 3852 | // - branch to false_target |
| 3853 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3854 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3855 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3856 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3857 | if (true_target == nullptr) { |
| 3858 | __ Beqzc(cond_val.AsRegister<GpuRegister>(), false_target); |
| 3859 | } else { |
| 3860 | __ Bnezc(cond_val.AsRegister<GpuRegister>(), true_target); |
| 3861 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3862 | } else { |
| 3863 | // The condition instruction has not been materialized, use its inputs as |
| 3864 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3865 | HCondition* condition = cond->AsCondition(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3866 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 3867 | LocationSummary* locations = cond->GetLocations(); |
| 3868 | IfCondition if_cond = condition->GetCondition(); |
| 3869 | Mips64Label* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3870 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3871 | if (true_target == nullptr) { |
| 3872 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3873 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3874 | } |
| 3875 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3876 | switch (type) { |
| 3877 | default: |
| 3878 | GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ false, locations, branch_target); |
| 3879 | break; |
| 3880 | case Primitive::kPrimLong: |
| 3881 | GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ true, locations, branch_target); |
| 3882 | break; |
| 3883 | case Primitive::kPrimFloat: |
| 3884 | case Primitive::kPrimDouble: |
| 3885 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 3886 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3887 | } |
| 3888 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3889 | |
| 3890 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3891 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3892 | if (true_target != nullptr && false_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3893 | __ Bc(false_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3894 | } |
| 3895 | } |
| 3896 | |
| 3897 | void LocationsBuilderMIPS64::VisitIf(HIf* if_instr) { |
| 3898 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3899 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3900 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3901 | } |
| 3902 | } |
| 3903 | |
| 3904 | void InstructionCodeGeneratorMIPS64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3905 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3906 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3907 | Mips64Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3908 | nullptr : codegen_->GetLabelOf(true_successor); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3909 | Mips64Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3910 | nullptr : codegen_->GetLabelOf(false_successor); |
| 3911 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3912 | } |
| 3913 | |
| 3914 | void LocationsBuilderMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3915 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3916 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3917 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3918 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3919 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3920 | } |
| 3921 | } |
| 3922 | |
| 3923 | void InstructionCodeGeneratorMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3924 | SlowPathCodeMIPS64* slow_path = |
| 3925 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3926 | GenerateTestAndBranch(deoptimize, |
| 3927 | /* condition_input_index */ 0, |
| 3928 | slow_path->GetEntryLabel(), |
| 3929 | /* false_target */ nullptr); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3930 | } |
| 3931 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 3932 | void LocationsBuilderMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3933 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3934 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3935 | locations->SetOut(Location::RequiresRegister()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3936 | } |
| 3937 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 3938 | void InstructionCodeGeneratorMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3939 | __ LoadFromOffset(kLoadWord, |
| 3940 | flag->GetLocations()->Out().AsRegister<GpuRegister>(), |
| 3941 | SP, |
| 3942 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3943 | } |
| 3944 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3945 | void LocationsBuilderMIPS64::VisitSelect(HSelect* select) { |
| 3946 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 3947 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3948 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3949 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3950 | } else { |
| 3951 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3952 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3953 | } |
| 3954 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3955 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3956 | } |
| 3957 | locations->SetOut(Location::SameAsFirstInput()); |
| 3958 | } |
| 3959 | |
| 3960 | void InstructionCodeGeneratorMIPS64::VisitSelect(HSelect* select) { |
| 3961 | LocationSummary* locations = select->GetLocations(); |
| 3962 | Mips64Label false_target; |
| 3963 | GenerateTestAndBranch(select, |
| 3964 | /* condition_input_index */ 2, |
| 3965 | /* true_target */ nullptr, |
| 3966 | &false_target); |
| 3967 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 3968 | __ Bind(&false_target); |
| 3969 | } |
| 3970 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3971 | void LocationsBuilderMIPS64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3972 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3973 | } |
| 3974 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3975 | void InstructionCodeGeneratorMIPS64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3976 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3977 | } |
| 3978 | |
| 3979 | void CodeGeneratorMIPS64::GenerateNop() { |
| 3980 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3981 | } |
| 3982 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3983 | void LocationsBuilderMIPS64::HandleFieldGet(HInstruction* instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3984 | const FieldInfo& field_info) { |
| 3985 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3986 | bool object_field_get_with_read_barrier = |
| 3987 | kEmitCompilerReadBarrier && (field_type == Primitive::kPrimNot); |
| 3988 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 3989 | instruction, |
| 3990 | object_field_get_with_read_barrier |
| 3991 | ? LocationSummary::kCallOnSlowPath |
| 3992 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 3993 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 3994 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 3995 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3996 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3997 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3998 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3999 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4000 | // The output overlaps in the case of an object field get with |
| 4001 | // read barriers enabled: we do not want the move to overwrite the |
| 4002 | // object's location, as we need it to emit the read barrier. |
| 4003 | locations->SetOut(Location::RequiresRegister(), |
| 4004 | object_field_get_with_read_barrier |
| 4005 | ? Location::kOutputOverlap |
| 4006 | : Location::kNoOutputOverlap); |
| 4007 | } |
| 4008 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4009 | // We need a temporary register for the read barrier marking slow |
| 4010 | // path in CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier. |
| 4011 | locations->AddTemp(Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4012 | } |
| 4013 | } |
| 4014 | |
| 4015 | void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction, |
| 4016 | const FieldInfo& field_info) { |
| 4017 | Primitive::Type type = field_info.GetFieldType(); |
| 4018 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4019 | Location obj_loc = locations->InAt(0); |
| 4020 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
| 4021 | Location dst_loc = locations->Out(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4022 | LoadOperandType load_type = kLoadUnsignedByte; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4023 | bool is_volatile = field_info.IsVolatile(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4024 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4025 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
| 4026 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4027 | switch (type) { |
| 4028 | case Primitive::kPrimBoolean: |
| 4029 | load_type = kLoadUnsignedByte; |
| 4030 | break; |
| 4031 | case Primitive::kPrimByte: |
| 4032 | load_type = kLoadSignedByte; |
| 4033 | break; |
| 4034 | case Primitive::kPrimShort: |
| 4035 | load_type = kLoadSignedHalfword; |
| 4036 | break; |
| 4037 | case Primitive::kPrimChar: |
| 4038 | load_type = kLoadUnsignedHalfword; |
| 4039 | break; |
| 4040 | case Primitive::kPrimInt: |
| 4041 | case Primitive::kPrimFloat: |
| 4042 | load_type = kLoadWord; |
| 4043 | break; |
| 4044 | case Primitive::kPrimLong: |
| 4045 | case Primitive::kPrimDouble: |
| 4046 | load_type = kLoadDoubleword; |
| 4047 | break; |
| 4048 | case Primitive::kPrimNot: |
| 4049 | load_type = kLoadUnsignedWord; |
| 4050 | break; |
| 4051 | case Primitive::kPrimVoid: |
| 4052 | LOG(FATAL) << "Unreachable type " << type; |
| 4053 | UNREACHABLE(); |
| 4054 | } |
| 4055 | if (!Primitive::IsFloatingPointType(type)) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4056 | DCHECK(dst_loc.IsRegister()); |
| 4057 | GpuRegister dst = dst_loc.AsRegister<GpuRegister>(); |
| 4058 | if (type == Primitive::kPrimNot) { |
| 4059 | // /* HeapReference<Object> */ dst = *(obj + offset) |
| 4060 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4061 | Location temp_loc = locations->GetTemp(0); |
| 4062 | // Note that a potential implicit null check is handled in this |
| 4063 | // CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier call. |
| 4064 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4065 | dst_loc, |
| 4066 | obj, |
| 4067 | offset, |
| 4068 | temp_loc, |
| 4069 | /* needs_null_check */ true); |
| 4070 | if (is_volatile) { |
| 4071 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4072 | } |
| 4073 | } else { |
| 4074 | __ LoadFromOffset(kLoadUnsignedWord, dst, obj, offset, null_checker); |
| 4075 | if (is_volatile) { |
| 4076 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4077 | } |
| 4078 | // If read barriers are enabled, emit read barriers other than |
| 4079 | // Baker's using a slow path (and also unpoison the loaded |
| 4080 | // reference, if heap poisoning is enabled). |
| 4081 | codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset); |
| 4082 | } |
| 4083 | } else { |
| 4084 | __ LoadFromOffset(load_type, dst, obj, offset, null_checker); |
| 4085 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4086 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4087 | DCHECK(dst_loc.IsFpuRegister()); |
| 4088 | FpuRegister dst = dst_loc.AsFpuRegister<FpuRegister>(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4089 | __ LoadFpuFromOffset(load_type, dst, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4090 | } |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4091 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4092 | // Memory barriers, in the case of references, are handled in the |
| 4093 | // previous switch statement. |
| 4094 | if (is_volatile && (type != Primitive::kPrimNot)) { |
| 4095 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4096 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4097 | } |
| 4098 | |
| 4099 | void LocationsBuilderMIPS64::HandleFieldSet(HInstruction* instruction, |
| 4100 | const FieldInfo& field_info ATTRIBUTE_UNUSED) { |
| 4101 | LocationSummary* locations = |
| 4102 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4103 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4104 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4105 | locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4106 | } else { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4107 | locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4108 | } |
| 4109 | } |
| 4110 | |
| 4111 | void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction, |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4112 | const FieldInfo& field_info, |
| 4113 | bool value_can_be_null) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4114 | Primitive::Type type = field_info.GetFieldType(); |
| 4115 | LocationSummary* locations = instruction->GetLocations(); |
| 4116 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4117 | Location value_location = locations->InAt(1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4118 | StoreOperandType store_type = kStoreByte; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4119 | bool is_volatile = field_info.IsVolatile(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4120 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4121 | bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1)); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4122 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
| 4123 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4124 | switch (type) { |
| 4125 | case Primitive::kPrimBoolean: |
| 4126 | case Primitive::kPrimByte: |
| 4127 | store_type = kStoreByte; |
| 4128 | break; |
| 4129 | case Primitive::kPrimShort: |
| 4130 | case Primitive::kPrimChar: |
| 4131 | store_type = kStoreHalfword; |
| 4132 | break; |
| 4133 | case Primitive::kPrimInt: |
| 4134 | case Primitive::kPrimFloat: |
| 4135 | case Primitive::kPrimNot: |
| 4136 | store_type = kStoreWord; |
| 4137 | break; |
| 4138 | case Primitive::kPrimLong: |
| 4139 | case Primitive::kPrimDouble: |
| 4140 | store_type = kStoreDoubleword; |
| 4141 | break; |
| 4142 | case Primitive::kPrimVoid: |
| 4143 | LOG(FATAL) << "Unreachable type " << type; |
| 4144 | UNREACHABLE(); |
| 4145 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4146 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4147 | if (is_volatile) { |
| 4148 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 4149 | } |
| 4150 | |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4151 | if (value_location.IsConstant()) { |
| 4152 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 4153 | __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker); |
| 4154 | } else { |
| 4155 | if (!Primitive::IsFloatingPointType(type)) { |
| 4156 | DCHECK(value_location.IsRegister()); |
| 4157 | GpuRegister src = value_location.AsRegister<GpuRegister>(); |
| 4158 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4159 | // Note that in the case where `value` is a null reference, |
| 4160 | // we do not enter this block, as a null reference does not |
| 4161 | // need poisoning. |
| 4162 | DCHECK_EQ(type, Primitive::kPrimNot); |
| 4163 | __ PoisonHeapReference(TMP, src); |
| 4164 | __ StoreToOffset(store_type, TMP, obj, offset, null_checker); |
| 4165 | } else { |
| 4166 | __ StoreToOffset(store_type, src, obj, offset, null_checker); |
| 4167 | } |
| 4168 | } else { |
| 4169 | DCHECK(value_location.IsFpuRegister()); |
| 4170 | FpuRegister src = value_location.AsFpuRegister<FpuRegister>(); |
| 4171 | __ StoreFpuToOffset(store_type, src, obj, offset, null_checker); |
| 4172 | } |
| 4173 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4174 | |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4175 | if (needs_write_barrier) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4176 | DCHECK(value_location.IsRegister()); |
| 4177 | GpuRegister src = value_location.AsRegister<GpuRegister>(); |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4178 | codegen_->MarkGCCard(obj, src, value_can_be_null); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4179 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4180 | |
| 4181 | if (is_volatile) { |
| 4182 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 4183 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4184 | } |
| 4185 | |
| 4186 | void LocationsBuilderMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4187 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4188 | } |
| 4189 | |
| 4190 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4191 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4192 | } |
| 4193 | |
| 4194 | void LocationsBuilderMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4195 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4196 | } |
| 4197 | |
| 4198 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4199 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4200 | } |
| 4201 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4202 | void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadOneRegister( |
| 4203 | HInstruction* instruction, |
| 4204 | Location out, |
| 4205 | uint32_t offset, |
| 4206 | Location maybe_temp, |
| 4207 | ReadBarrierOption read_barrier_option) { |
| 4208 | GpuRegister out_reg = out.AsRegister<GpuRegister>(); |
| 4209 | if (read_barrier_option == kWithReadBarrier) { |
| 4210 | CHECK(kEmitCompilerReadBarrier); |
| 4211 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 4212 | if (kUseBakerReadBarrier) { |
| 4213 | // Load with fast path based Baker's read barrier. |
| 4214 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4215 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4216 | out, |
| 4217 | out_reg, |
| 4218 | offset, |
| 4219 | maybe_temp, |
| 4220 | /* needs_null_check */ false); |
| 4221 | } else { |
| 4222 | // Load with slow path based read barrier. |
| 4223 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 4224 | // in the following move operation, as we will need it for the |
| 4225 | // read barrier below. |
| 4226 | __ Move(maybe_temp.AsRegister<GpuRegister>(), out_reg); |
| 4227 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4228 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset); |
| 4229 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 4230 | } |
| 4231 | } else { |
| 4232 | // Plain load with no read barrier. |
| 4233 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4234 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset); |
| 4235 | __ MaybeUnpoisonHeapReference(out_reg); |
| 4236 | } |
| 4237 | } |
| 4238 | |
| 4239 | void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadTwoRegisters( |
| 4240 | HInstruction* instruction, |
| 4241 | Location out, |
| 4242 | Location obj, |
| 4243 | uint32_t offset, |
| 4244 | Location maybe_temp, |
| 4245 | ReadBarrierOption read_barrier_option) { |
| 4246 | GpuRegister out_reg = out.AsRegister<GpuRegister>(); |
| 4247 | GpuRegister obj_reg = obj.AsRegister<GpuRegister>(); |
| 4248 | if (read_barrier_option == kWithReadBarrier) { |
| 4249 | CHECK(kEmitCompilerReadBarrier); |
| 4250 | if (kUseBakerReadBarrier) { |
| 4251 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 4252 | // Load with fast path based Baker's read barrier. |
| 4253 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 4254 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4255 | out, |
| 4256 | obj_reg, |
| 4257 | offset, |
| 4258 | maybe_temp, |
| 4259 | /* needs_null_check */ false); |
| 4260 | } else { |
| 4261 | // Load with slow path based read barrier. |
| 4262 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 4263 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset); |
| 4264 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 4265 | } |
| 4266 | } else { |
| 4267 | // Plain load with no read barrier. |
| 4268 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 4269 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset); |
| 4270 | __ MaybeUnpoisonHeapReference(out_reg); |
| 4271 | } |
| 4272 | } |
| 4273 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4274 | void InstructionCodeGeneratorMIPS64::GenerateGcRootFieldLoad( |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4275 | HInstruction* instruction, |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4276 | Location root, |
| 4277 | GpuRegister obj, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4278 | uint32_t offset, |
| 4279 | ReadBarrierOption read_barrier_option) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4280 | GpuRegister root_reg = root.AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4281 | if (read_barrier_option == kWithReadBarrier) { |
| 4282 | DCHECK(kEmitCompilerReadBarrier); |
| 4283 | if (kUseBakerReadBarrier) { |
| 4284 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 4285 | // Baker's read barrier are used: |
| 4286 | // |
| 4287 | // root = obj.field; |
| 4288 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 4289 | // if (temp != null) { |
| 4290 | // root = temp(root) |
| 4291 | // } |
| 4292 | |
| 4293 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 4294 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset); |
| 4295 | static_assert( |
| 4296 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 4297 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 4298 | "have different sizes."); |
| 4299 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 4300 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 4301 | "have different sizes."); |
| 4302 | |
| 4303 | // Slow path marking the GC root `root`. |
| 4304 | Location temp = Location::RegisterLocation(T9); |
| 4305 | SlowPathCodeMIPS64* slow_path = |
| 4306 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathMIPS64( |
| 4307 | instruction, |
| 4308 | root, |
| 4309 | /*entrypoint*/ temp); |
| 4310 | codegen_->AddSlowPath(slow_path); |
| 4311 | |
| 4312 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 4313 | const int32_t entry_point_offset = |
| 4314 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(root.reg() - 1); |
| 4315 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 4316 | // threads are suspended or running a checkpoint. |
| 4317 | __ LoadFromOffset(kLoadDoubleword, temp.AsRegister<GpuRegister>(), TR, entry_point_offset); |
| 4318 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 4319 | // checking GetIsGcMarking. |
| 4320 | __ Bnezc(temp.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 4321 | __ Bind(slow_path->GetExitLabel()); |
| 4322 | } else { |
| 4323 | // GC root loaded through a slow path for read barriers other |
| 4324 | // than Baker's. |
| 4325 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 4326 | __ Daddiu64(root_reg, obj, static_cast<int32_t>(offset)); |
| 4327 | // /* mirror::Object* */ root = root->Read() |
| 4328 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 4329 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4330 | } else { |
| 4331 | // Plain GC root load with no read barrier. |
| 4332 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 4333 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset); |
| 4334 | // Note that GC roots are not affected by heap poisoning, thus we |
| 4335 | // do not have to unpoison `root_reg` here. |
| 4336 | } |
| 4337 | } |
| 4338 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4339 | void CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 4340 | Location ref, |
| 4341 | GpuRegister obj, |
| 4342 | uint32_t offset, |
| 4343 | Location temp, |
| 4344 | bool needs_null_check) { |
| 4345 | DCHECK(kEmitCompilerReadBarrier); |
| 4346 | DCHECK(kUseBakerReadBarrier); |
| 4347 | |
| 4348 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 4349 | Location no_index = Location::NoLocation(); |
| 4350 | ScaleFactor no_scale_factor = TIMES_1; |
| 4351 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 4352 | ref, |
| 4353 | obj, |
| 4354 | offset, |
| 4355 | no_index, |
| 4356 | no_scale_factor, |
| 4357 | temp, |
| 4358 | needs_null_check); |
| 4359 | } |
| 4360 | |
| 4361 | void CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 4362 | Location ref, |
| 4363 | GpuRegister obj, |
| 4364 | uint32_t data_offset, |
| 4365 | Location index, |
| 4366 | Location temp, |
| 4367 | bool needs_null_check) { |
| 4368 | DCHECK(kEmitCompilerReadBarrier); |
| 4369 | DCHECK(kUseBakerReadBarrier); |
| 4370 | |
| 4371 | static_assert( |
| 4372 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4373 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 4374 | // /* HeapReference<Object> */ ref = |
| 4375 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4376 | ScaleFactor scale_factor = TIMES_4; |
| 4377 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 4378 | ref, |
| 4379 | obj, |
| 4380 | data_offset, |
| 4381 | index, |
| 4382 | scale_factor, |
| 4383 | temp, |
| 4384 | needs_null_check); |
| 4385 | } |
| 4386 | |
| 4387 | void CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 4388 | Location ref, |
| 4389 | GpuRegister obj, |
| 4390 | uint32_t offset, |
| 4391 | Location index, |
| 4392 | ScaleFactor scale_factor, |
| 4393 | Location temp, |
| 4394 | bool needs_null_check, |
| 4395 | bool always_update_field) { |
| 4396 | DCHECK(kEmitCompilerReadBarrier); |
| 4397 | DCHECK(kUseBakerReadBarrier); |
| 4398 | |
| 4399 | // In slow path based read barriers, the read barrier call is |
| 4400 | // inserted after the original load. However, in fast path based |
| 4401 | // Baker's read barriers, we need to perform the load of |
| 4402 | // mirror::Object::monitor_ *before* the original reference load. |
| 4403 | // This load-load ordering is required by the read barrier. |
| 4404 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 4405 | // |
| 4406 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 4407 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 4408 | // HeapReference<Object> ref = *src; // Original reference load. |
| 4409 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 4410 | // if (is_gray) { |
| 4411 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 4412 | // } |
| 4413 | // |
| 4414 | // Note: the original implementation in ReadBarrier::Barrier is |
| 4415 | // slightly more complex as it performs additional checks that we do |
| 4416 | // not do here for performance reasons. |
| 4417 | |
| 4418 | GpuRegister ref_reg = ref.AsRegister<GpuRegister>(); |
| 4419 | GpuRegister temp_reg = temp.AsRegister<GpuRegister>(); |
| 4420 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 4421 | |
| 4422 | // /* int32_t */ monitor = obj->monitor_ |
| 4423 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 4424 | if (needs_null_check) { |
| 4425 | MaybeRecordImplicitNullCheck(instruction); |
| 4426 | } |
| 4427 | // /* LockWord */ lock_word = LockWord(monitor) |
| 4428 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 4429 | "art::LockWord and int32_t have different sizes."); |
| 4430 | |
| 4431 | __ Sync(0); // Barrier to prevent load-load reordering. |
| 4432 | |
| 4433 | // The actual reference load. |
| 4434 | if (index.IsValid()) { |
| 4435 | // Load types involving an "index": ArrayGet, |
| 4436 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 4437 | // intrinsics. |
| 4438 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 4439 | if (index.IsConstant()) { |
| 4440 | size_t computed_offset = |
| 4441 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
| 4442 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, computed_offset); |
| 4443 | } else { |
| 4444 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 4445 | if (scale_factor == TIMES_1) { |
| 4446 | __ Daddu(TMP, index_reg, obj); |
| 4447 | } else { |
| 4448 | __ Dlsa(TMP, index_reg, obj, scale_factor); |
| 4449 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4450 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, offset); |
| 4451 | } |
| 4452 | } else { |
| 4453 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 4454 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, offset); |
| 4455 | } |
| 4456 | |
| 4457 | // Object* ref = ref_addr->AsMirrorPtr() |
| 4458 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 4459 | |
| 4460 | // Slow path marking the object `ref` when it is gray. |
| 4461 | SlowPathCodeMIPS64* slow_path; |
| 4462 | if (always_update_field) { |
| 4463 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 only supports address |
| 4464 | // of the form `obj + field_offset`, where `obj` is a register and |
| 4465 | // `field_offset` is a register. Thus `offset` and `scale_factor` |
| 4466 | // above are expected to be null in this code path. |
| 4467 | DCHECK_EQ(offset, 0u); |
| 4468 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
| 4469 | slow_path = new (GetGraph()->GetArena()) |
| 4470 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS64(instruction, |
| 4471 | ref, |
| 4472 | obj, |
| 4473 | /* field_offset */ index, |
| 4474 | temp_reg); |
| 4475 | } else { |
| 4476 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathMIPS64(instruction, ref); |
| 4477 | } |
| 4478 | AddSlowPath(slow_path); |
| 4479 | |
| 4480 | // if (rb_state == ReadBarrier::GrayState()) |
| 4481 | // ref = ReadBarrier::Mark(ref); |
| 4482 | // Given the numeric representation, it's enough to check the low bit of the |
| 4483 | // rb_state. We do that by shifting the bit into the sign bit (31) and |
| 4484 | // performing a branch on less than zero. |
| 4485 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 4486 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 4487 | static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size"); |
| 4488 | __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift); |
| 4489 | __ Bltzc(temp_reg, slow_path->GetEntryLabel()); |
| 4490 | __ Bind(slow_path->GetExitLabel()); |
| 4491 | } |
| 4492 | |
| 4493 | void CodeGeneratorMIPS64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 4494 | Location out, |
| 4495 | Location ref, |
| 4496 | Location obj, |
| 4497 | uint32_t offset, |
| 4498 | Location index) { |
| 4499 | DCHECK(kEmitCompilerReadBarrier); |
| 4500 | |
| 4501 | // Insert a slow path based read barrier *after* the reference load. |
| 4502 | // |
| 4503 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 4504 | // reference will be carried out by the runtime within the slow |
| 4505 | // path. |
| 4506 | // |
| 4507 | // Note that `ref` currently does not get unpoisoned (when heap |
| 4508 | // poisoning is enabled), which is alright as the `ref` argument is |
| 4509 | // not used by the artReadBarrierSlow entry point. |
| 4510 | // |
| 4511 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 4512 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) |
| 4513 | ReadBarrierForHeapReferenceSlowPathMIPS64(instruction, out, ref, obj, offset, index); |
| 4514 | AddSlowPath(slow_path); |
| 4515 | |
| 4516 | __ Bc(slow_path->GetEntryLabel()); |
| 4517 | __ Bind(slow_path->GetExitLabel()); |
| 4518 | } |
| 4519 | |
| 4520 | void CodeGeneratorMIPS64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 4521 | Location out, |
| 4522 | Location ref, |
| 4523 | Location obj, |
| 4524 | uint32_t offset, |
| 4525 | Location index) { |
| 4526 | if (kEmitCompilerReadBarrier) { |
| 4527 | // Baker's read barriers shall be handled by the fast path |
| 4528 | // (CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier). |
| 4529 | DCHECK(!kUseBakerReadBarrier); |
| 4530 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 4531 | // by the runtime within the slow path. |
| 4532 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| 4533 | } else if (kPoisonHeapReferences) { |
| 4534 | __ UnpoisonHeapReference(out.AsRegister<GpuRegister>()); |
| 4535 | } |
| 4536 | } |
| 4537 | |
| 4538 | void CodeGeneratorMIPS64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 4539 | Location out, |
| 4540 | Location root) { |
| 4541 | DCHECK(kEmitCompilerReadBarrier); |
| 4542 | |
| 4543 | // Insert a slow path based read barrier *after* the GC root load. |
| 4544 | // |
| 4545 | // Note that GC roots are not affected by heap poisoning, so we do |
| 4546 | // not need to do anything special for this here. |
| 4547 | SlowPathCodeMIPS64* slow_path = |
| 4548 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathMIPS64(instruction, out, root); |
| 4549 | AddSlowPath(slow_path); |
| 4550 | |
| 4551 | __ Bc(slow_path->GetEntryLabel()); |
| 4552 | __ Bind(slow_path->GetExitLabel()); |
| 4553 | } |
| 4554 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4555 | void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4556 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4557 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 4558 | bool baker_read_barrier_slow_path = false; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4559 | switch (type_check_kind) { |
| 4560 | case TypeCheckKind::kExactCheck: |
| 4561 | case TypeCheckKind::kAbstractClassCheck: |
| 4562 | case TypeCheckKind::kClassHierarchyCheck: |
| 4563 | case TypeCheckKind::kArrayObjectCheck: |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4564 | call_kind = |
| 4565 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 4566 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4567 | break; |
| 4568 | case TypeCheckKind::kArrayCheck: |
| 4569 | case TypeCheckKind::kUnresolvedCheck: |
| 4570 | case TypeCheckKind::kInterfaceCheck: |
| 4571 | call_kind = LocationSummary::kCallOnSlowPath; |
| 4572 | break; |
| 4573 | } |
| 4574 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4575 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 4576 | if (baker_read_barrier_slow_path) { |
| 4577 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 4578 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4579 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4580 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4581 | // The output does overlap inputs. |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4582 | // Note that TypeCheckSlowPathMIPS64 uses this register too. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4583 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4584 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4585 | } |
| 4586 | |
| 4587 | void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4588 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4589 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4590 | Location obj_loc = locations->InAt(0); |
| 4591 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4592 | GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4593 | Location out_loc = locations->Out(); |
| 4594 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 4595 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 4596 | DCHECK_LE(num_temps, 1u); |
| 4597 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4598 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4599 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4600 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4601 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4602 | Mips64Label done; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4603 | SlowPathCodeMIPS64* slow_path = nullptr; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4604 | |
| 4605 | // Return 0 if `obj` is null. |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4606 | // Avoid this check if we know `obj` is not null. |
| 4607 | if (instruction->MustDoNullCheck()) { |
| 4608 | __ Move(out, ZERO); |
| 4609 | __ Beqzc(obj, &done); |
| 4610 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4611 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4612 | switch (type_check_kind) { |
| 4613 | case TypeCheckKind::kExactCheck: { |
| 4614 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4615 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4616 | out_loc, |
| 4617 | obj_loc, |
| 4618 | class_offset, |
| 4619 | maybe_temp_loc, |
| 4620 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4621 | // Classes must be equal for the instanceof to succeed. |
| 4622 | __ Xor(out, out, cls); |
| 4623 | __ Sltiu(out, out, 1); |
| 4624 | break; |
| 4625 | } |
| 4626 | |
| 4627 | case TypeCheckKind::kAbstractClassCheck: { |
| 4628 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4629 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4630 | out_loc, |
| 4631 | obj_loc, |
| 4632 | class_offset, |
| 4633 | maybe_temp_loc, |
| 4634 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4635 | // If the class is abstract, we eagerly fetch the super class of the |
| 4636 | // object to avoid doing a comparison we know will fail. |
| 4637 | Mips64Label loop; |
| 4638 | __ Bind(&loop); |
| 4639 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4640 | GenerateReferenceLoadOneRegister(instruction, |
| 4641 | out_loc, |
| 4642 | super_offset, |
| 4643 | maybe_temp_loc, |
| 4644 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4645 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4646 | __ Beqzc(out, &done); |
| 4647 | __ Bnec(out, cls, &loop); |
| 4648 | __ LoadConst32(out, 1); |
| 4649 | break; |
| 4650 | } |
| 4651 | |
| 4652 | case TypeCheckKind::kClassHierarchyCheck: { |
| 4653 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4654 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4655 | out_loc, |
| 4656 | obj_loc, |
| 4657 | class_offset, |
| 4658 | maybe_temp_loc, |
| 4659 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4660 | // Walk over the class hierarchy to find a match. |
| 4661 | Mips64Label loop, success; |
| 4662 | __ Bind(&loop); |
| 4663 | __ Beqc(out, cls, &success); |
| 4664 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4665 | GenerateReferenceLoadOneRegister(instruction, |
| 4666 | out_loc, |
| 4667 | super_offset, |
| 4668 | maybe_temp_loc, |
| 4669 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4670 | __ Bnezc(out, &loop); |
| 4671 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4672 | __ Bc(&done); |
| 4673 | __ Bind(&success); |
| 4674 | __ LoadConst32(out, 1); |
| 4675 | break; |
| 4676 | } |
| 4677 | |
| 4678 | case TypeCheckKind::kArrayObjectCheck: { |
| 4679 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4680 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4681 | out_loc, |
| 4682 | obj_loc, |
| 4683 | class_offset, |
| 4684 | maybe_temp_loc, |
| 4685 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4686 | // Do an exact check. |
| 4687 | Mips64Label success; |
| 4688 | __ Beqc(out, cls, &success); |
| 4689 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 4690 | // /* HeapReference<Class> */ out = out->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4691 | GenerateReferenceLoadOneRegister(instruction, |
| 4692 | out_loc, |
| 4693 | component_offset, |
| 4694 | maybe_temp_loc, |
| 4695 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4696 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4697 | __ Beqzc(out, &done); |
| 4698 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 4699 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4700 | __ Sltiu(out, out, 1); |
| 4701 | __ Bc(&done); |
| 4702 | __ Bind(&success); |
| 4703 | __ LoadConst32(out, 1); |
| 4704 | break; |
| 4705 | } |
| 4706 | |
| 4707 | case TypeCheckKind::kArrayCheck: { |
| 4708 | // No read barrier since the slow path will retry upon failure. |
| 4709 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4710 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4711 | out_loc, |
| 4712 | obj_loc, |
| 4713 | class_offset, |
| 4714 | maybe_temp_loc, |
| 4715 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4716 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4717 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction, |
| 4718 | /* is_fatal */ false); |
| 4719 | codegen_->AddSlowPath(slow_path); |
| 4720 | __ Bnec(out, cls, slow_path->GetEntryLabel()); |
| 4721 | __ LoadConst32(out, 1); |
| 4722 | break; |
| 4723 | } |
| 4724 | |
| 4725 | case TypeCheckKind::kUnresolvedCheck: |
| 4726 | case TypeCheckKind::kInterfaceCheck: { |
| 4727 | // Note that we indeed only call on slow path, but we always go |
| 4728 | // into the slow path for the unresolved and interface check |
| 4729 | // cases. |
| 4730 | // |
| 4731 | // We cannot directly call the InstanceofNonTrivial runtime |
| 4732 | // entry point without resorting to a type checking slow path |
| 4733 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 4734 | // require to assign fixed registers for the inputs of this |
| 4735 | // HInstanceOf instruction (following the runtime calling |
| 4736 | // convention), which might be cluttered by the potential first |
| 4737 | // read barrier emission at the beginning of this method. |
| 4738 | // |
| 4739 | // TODO: Introduce a new runtime entry point taking the object |
| 4740 | // to test (instead of its class) as argument, and let it deal |
| 4741 | // with the read barrier issues. This will let us refactor this |
| 4742 | // case of the `switch` code as it was previously (with a direct |
| 4743 | // call to the runtime not using a type checking slow path). |
| 4744 | // This should also be beneficial for the other cases above. |
| 4745 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4746 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction, |
| 4747 | /* is_fatal */ false); |
| 4748 | codegen_->AddSlowPath(slow_path); |
| 4749 | __ Bc(slow_path->GetEntryLabel()); |
| 4750 | break; |
| 4751 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4752 | } |
| 4753 | |
| 4754 | __ Bind(&done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4755 | |
| 4756 | if (slow_path != nullptr) { |
| 4757 | __ Bind(slow_path->GetExitLabel()); |
| 4758 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4759 | } |
| 4760 | |
| 4761 | void LocationsBuilderMIPS64::VisitIntConstant(HIntConstant* constant) { |
| 4762 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4763 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4764 | } |
| 4765 | |
| 4766 | void InstructionCodeGeneratorMIPS64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 4767 | // Will be generated at use site. |
| 4768 | } |
| 4769 | |
| 4770 | void LocationsBuilderMIPS64::VisitNullConstant(HNullConstant* constant) { |
| 4771 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4772 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4773 | } |
| 4774 | |
| 4775 | void InstructionCodeGeneratorMIPS64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 4776 | // Will be generated at use site. |
| 4777 | } |
| 4778 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4779 | void LocationsBuilderMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4780 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4781 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4782 | // the method_idx. |
| 4783 | HandleInvoke(invoke); |
| 4784 | } |
| 4785 | |
| 4786 | void InstructionCodeGeneratorMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4787 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 4788 | } |
| 4789 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4790 | void LocationsBuilderMIPS64::HandleInvoke(HInvoke* invoke) { |
| 4791 | InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor; |
| 4792 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 4793 | } |
| 4794 | |
| 4795 | void LocationsBuilderMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4796 | HandleInvoke(invoke); |
| 4797 | // The register T0 is required to be used for the hidden argument in |
| 4798 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
| 4799 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0)); |
| 4800 | } |
| 4801 | |
| 4802 | void InstructionCodeGeneratorMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4803 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 4804 | GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4805 | Location receiver = invoke->GetLocations()->InAt(0); |
| 4806 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4807 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4808 | |
| 4809 | // Set the hidden argument. |
| 4810 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<GpuRegister>(), |
| 4811 | invoke->GetDexMethodIndex()); |
| 4812 | |
| 4813 | // temp = object->GetClass(); |
| 4814 | if (receiver.IsStackSlot()) { |
| 4815 | __ LoadFromOffset(kLoadUnsignedWord, temp, SP, receiver.GetStackIndex()); |
| 4816 | __ LoadFromOffset(kLoadUnsignedWord, temp, temp, class_offset); |
| 4817 | } else { |
| 4818 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset); |
| 4819 | } |
| 4820 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4821 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4822 | // emit a read barrier for the previous class reference load. |
| 4823 | // However this is not required in practice, as this is an |
| 4824 | // intermediate/temporary reference and because the current |
| 4825 | // concurrent copying collector keeps the from-space memory |
| 4826 | // intact/accessible until the end of the marking phase (the |
| 4827 | // concurrent copying collector may not in the future). |
| 4828 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4829 | __ LoadFromOffset(kLoadDoubleword, temp, temp, |
| 4830 | mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value()); |
| 4831 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4832 | invoke->GetImtIndex(), kMips64PointerSize)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4833 | // temp = temp->GetImtEntryAt(method_offset); |
| 4834 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); |
| 4835 | // T9 = temp->GetEntryPoint(); |
| 4836 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); |
| 4837 | // T9(); |
| 4838 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4839 | __ Nop(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4840 | DCHECK(!codegen_->IsLeafMethod()); |
| 4841 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4842 | } |
| 4843 | |
| 4844 | void LocationsBuilderMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 4845 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); |
| 4846 | if (intrinsic.TryDispatch(invoke)) { |
| 4847 | return; |
| 4848 | } |
| 4849 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4850 | HandleInvoke(invoke); |
| 4851 | } |
| 4852 | |
| 4853 | void LocationsBuilderMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4854 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4855 | // art::PrepareForRegisterAllocation. |
| 4856 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4857 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 4858 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); |
| 4859 | if (intrinsic.TryDispatch(invoke)) { |
| 4860 | return; |
| 4861 | } |
| 4862 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4863 | HandleInvoke(invoke); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4864 | } |
| 4865 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4866 | void LocationsBuilderMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4867 | HandleInvoke(invoke); |
| 4868 | } |
| 4869 | |
| 4870 | void InstructionCodeGeneratorMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4871 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 4872 | } |
| 4873 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 4874 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS64* codegen) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4875 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 4876 | IntrinsicCodeGeneratorMIPS64 intrinsic(codegen); |
| 4877 | intrinsic.Dispatch(invoke); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4878 | return true; |
| 4879 | } |
| 4880 | return false; |
| 4881 | } |
| 4882 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4883 | HLoadString::LoadKind CodeGeneratorMIPS64::GetSupportedLoadStringKind( |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4884 | HLoadString::LoadKind desired_string_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4885 | bool fallback_load = false; |
| 4886 | switch (desired_string_load_kind) { |
| 4887 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 4888 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 4889 | break; |
| 4890 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 4891 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 4892 | break; |
| 4893 | case HLoadString::LoadKind::kBootImageAddress: |
| 4894 | break; |
| 4895 | case HLoadString::LoadKind::kBssEntry: |
| 4896 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4897 | break; |
| 4898 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 4899 | break; |
| 4900 | case HLoadString::LoadKind::kJitTableAddress: |
| 4901 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4902 | break; |
| 4903 | } |
| 4904 | if (fallback_load) { |
| 4905 | desired_string_load_kind = HLoadString::LoadKind::kDexCacheViaMethod; |
| 4906 | } |
| 4907 | return desired_string_load_kind; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4908 | } |
| 4909 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4910 | HLoadClass::LoadKind CodeGeneratorMIPS64::GetSupportedLoadClassKind( |
| 4911 | HLoadClass::LoadKind desired_class_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4912 | bool fallback_load = false; |
| 4913 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4914 | case HLoadClass::LoadKind::kInvalid: |
| 4915 | LOG(FATAL) << "UNREACHABLE"; |
| 4916 | UNREACHABLE(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4917 | case HLoadClass::LoadKind::kReferrersClass: |
| 4918 | break; |
| 4919 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 4920 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 4921 | break; |
| 4922 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 4923 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 4924 | break; |
| 4925 | case HLoadClass::LoadKind::kBootImageAddress: |
| 4926 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4927 | case HLoadClass::LoadKind::kBssEntry: |
| 4928 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4929 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4930 | case HLoadClass::LoadKind::kJitTableAddress: |
| 4931 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4932 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4933 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 4934 | break; |
| 4935 | } |
| 4936 | if (fallback_load) { |
| 4937 | desired_class_load_kind = HLoadClass::LoadKind::kDexCacheViaMethod; |
| 4938 | } |
| 4939 | return desired_class_load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4940 | } |
| 4941 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4942 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4943 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4944 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 4945 | // On MIPS64 we support all dispatch types. |
| 4946 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4947 | } |
| 4948 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4949 | void CodeGeneratorMIPS64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4950 | // All registers are assumed to be correctly set up per the calling convention. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4951 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 4952 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 4953 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
| 4954 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 4955 | switch (method_load_kind) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4956 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4957 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4958 | uint32_t offset = |
| 4959 | GetThreadOffset<kMips64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4960 | __ LoadFromOffset(kLoadDoubleword, |
| 4961 | temp.AsRegister<GpuRegister>(), |
| 4962 | TR, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4963 | offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4964 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4965 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4966 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4967 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4968 | break; |
| 4969 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 4970 | __ LoadLiteral(temp.AsRegister<GpuRegister>(), |
| 4971 | kLoadDoubleword, |
| 4972 | DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4973 | break; |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 4974 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4975 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 4976 | CodeGeneratorMIPS64::PcRelativePatchInfo* info = |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 4977 | NewPcRelativeDexCacheArrayPatch(invoke->GetDexFileForPcRelativeDexCache(), offset); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 4978 | EmitPcRelativeAddressPlaceholderHigh(info, AT); |
| 4979 | __ Ld(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678); |
| 4980 | break; |
| 4981 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4982 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4983 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4984 | GpuRegister reg = temp.AsRegister<GpuRegister>(); |
| 4985 | GpuRegister method_reg; |
| 4986 | if (current_method.IsRegister()) { |
| 4987 | method_reg = current_method.AsRegister<GpuRegister>(); |
| 4988 | } else { |
| 4989 | // TODO: use the appropriate DCHECK() here if possible. |
| 4990 | // DCHECK(invoke->GetLocations()->Intrinsified()); |
| 4991 | DCHECK(!current_method.IsValid()); |
| 4992 | method_reg = reg; |
| 4993 | __ Ld(reg, SP, kCurrentMethodStackOffset); |
| 4994 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4995 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4996 | // temp = temp->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4997 | __ LoadFromOffset(kLoadDoubleword, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4998 | reg, |
| 4999 | method_reg, |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 5000 | ArtMethod::DexCacheResolvedMethodsOffset(kMips64PointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 5001 | // temp = temp[index_in_cache]; |
| 5002 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 5003 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5004 | __ LoadFromOffset(kLoadDoubleword, |
| 5005 | reg, |
| 5006 | reg, |
| 5007 | CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 5008 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5009 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5010 | } |
| 5011 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5012 | switch (code_ptr_location) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5013 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 5014 | __ Balc(&frame_entry_label_); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5015 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5016 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 5017 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
| 5018 | __ LoadFromOffset(kLoadDoubleword, |
| 5019 | T9, |
| 5020 | callee_method.AsRegister<GpuRegister>(), |
| 5021 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5022 | kMips64PointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5023 | // T9() |
| 5024 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 5025 | __ Nop(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5026 | break; |
| 5027 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5028 | DCHECK(!IsLeafMethod()); |
| 5029 | } |
| 5030 | |
| 5031 | void InstructionCodeGeneratorMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5032 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5033 | // art::PrepareForRegisterAllocation. |
| 5034 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5035 | |
| 5036 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 5037 | return; |
| 5038 | } |
| 5039 | |
| 5040 | LocationSummary* locations = invoke->GetLocations(); |
| 5041 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 5042 | locations->HasTemps() |
| 5043 | ? locations->GetTemp(0) |
| 5044 | : Location::NoLocation()); |
| 5045 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 5046 | } |
| 5047 | |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 5048 | void CodeGeneratorMIPS64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5049 | // Use the calling convention instead of the location of the receiver, as |
| 5050 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 5051 | // slow path, the arguments have been moved to the right place, so here we are |
| 5052 | // guaranteed that the receiver is the first register of the calling convention. |
| 5053 | InvokeDexCallingConvention calling_convention; |
| 5054 | GpuRegister receiver = calling_convention.GetRegisterAt(0); |
| 5055 | |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 5056 | GpuRegister temp = temp_location.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5057 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 5058 | invoke->GetVTableIndex(), kMips64PointerSize).SizeValue(); |
| 5059 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5060 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5061 | |
| 5062 | // temp = object->GetClass(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5063 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver, class_offset); |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 5064 | MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5065 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 5066 | // emit a read barrier for the previous class reference load. |
| 5067 | // However this is not required in practice, as this is an |
| 5068 | // intermediate/temporary reference and because the current |
| 5069 | // concurrent copying collector keeps the from-space memory |
| 5070 | // intact/accessible until the end of the marking phase (the |
| 5071 | // concurrent copying collector may not in the future). |
| 5072 | __ MaybeUnpoisonHeapReference(temp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5073 | // temp = temp->GetMethodAt(method_offset); |
| 5074 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); |
| 5075 | // T9 = temp->GetEntryPoint(); |
| 5076 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); |
| 5077 | // T9(); |
| 5078 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 5079 | __ Nop(); |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 5080 | } |
| 5081 | |
| 5082 | void InstructionCodeGeneratorMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 5083 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 5084 | return; |
| 5085 | } |
| 5086 | |
| 5087 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5088 | DCHECK(!codegen_->IsLeafMethod()); |
| 5089 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 5090 | } |
| 5091 | |
| 5092 | void LocationsBuilderMIPS64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5093 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5094 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5095 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5096 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 5097 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(cls, loc, loc); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5098 | return; |
| 5099 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5100 | DCHECK(!cls->NeedsAccessCheck()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5101 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5102 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5103 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5104 | ? LocationSummary::kCallOnSlowPath |
| 5105 | : LocationSummary::kNoCall; |
| 5106 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5107 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| 5108 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5109 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5110 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5111 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5112 | } |
| 5113 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5114 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 5115 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5116 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 5117 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5118 | InvokeRuntimeCallingConvention calling_convention; |
| 5119 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5120 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5121 | } else { |
| 5122 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5123 | } |
| 5124 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5125 | } |
| 5126 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5127 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5128 | // move. |
| 5129 | void InstructionCodeGeneratorMIPS64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5130 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5131 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 5132 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5133 | return; |
| 5134 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5135 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5136 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5137 | LocationSummary* locations = cls->GetLocations(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5138 | Location out_loc = locations->Out(); |
| 5139 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 5140 | GpuRegister current_method_reg = ZERO; |
| 5141 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 5142 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 5143 | current_method_reg = locations->InAt(0).AsRegister<GpuRegister>(); |
| 5144 | } |
| 5145 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5146 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5147 | ? kWithoutReadBarrier |
| 5148 | : kCompilerReadBarrierOption; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5149 | bool generate_null_check = false; |
| 5150 | switch (load_kind) { |
| 5151 | case HLoadClass::LoadKind::kReferrersClass: |
| 5152 | DCHECK(!cls->CanCallRuntime()); |
| 5153 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5154 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5155 | GenerateGcRootFieldLoad(cls, |
| 5156 | out_loc, |
| 5157 | current_method_reg, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5158 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 5159 | read_barrier_option); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5160 | break; |
| 5161 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5162 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5163 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5164 | __ LoadLiteral(out, |
| 5165 | kLoadUnsignedWord, |
| 5166 | codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 5167 | cls->GetTypeIndex())); |
| 5168 | break; |
| 5169 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5170 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5171 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5172 | CodeGeneratorMIPS64::PcRelativePatchInfo* info = |
| 5173 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 5174 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info, AT); |
| 5175 | __ Daddiu(out, AT, /* placeholder */ 0x5678); |
| 5176 | break; |
| 5177 | } |
| 5178 | case HLoadClass::LoadKind::kBootImageAddress: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5179 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5180 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5181 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 5182 | DCHECK_NE(address, 0u); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5183 | __ LoadLiteral(out, |
| 5184 | kLoadUnsignedWord, |
| 5185 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5186 | break; |
| 5187 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5188 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5189 | CodeGeneratorMIPS64::PcRelativePatchInfo* info = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5190 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5191 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info, out); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5192 | GenerateGcRootFieldLoad(cls, out_loc, out, /* placeholder */ 0x5678, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5193 | generate_null_check = true; |
| 5194 | break; |
| 5195 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 5196 | case HLoadClass::LoadKind::kJitTableAddress: |
| 5197 | __ LoadLiteral(out, |
| 5198 | kLoadUnsignedWord, |
| 5199 | codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 5200 | cls->GetTypeIndex(), |
| 5201 | cls->GetClass())); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5202 | GenerateGcRootFieldLoad(cls, out_loc, out, 0, read_barrier_option); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5203 | break; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5204 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5205 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5206 | LOG(FATAL) << "UNREACHABLE"; |
| 5207 | UNREACHABLE(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5208 | } |
| 5209 | |
| 5210 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5211 | DCHECK(cls->CanCallRuntime()); |
| 5212 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64( |
| 5213 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5214 | codegen_->AddSlowPath(slow_path); |
| 5215 | if (generate_null_check) { |
| 5216 | __ Beqzc(out, slow_path->GetEntryLabel()); |
| 5217 | } |
| 5218 | if (cls->MustGenerateClinitCheck()) { |
| 5219 | GenerateClassInitializationCheck(slow_path, out); |
| 5220 | } else { |
| 5221 | __ Bind(slow_path->GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5222 | } |
| 5223 | } |
| 5224 | } |
| 5225 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5226 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5227 | return Thread::ExceptionOffset<kMips64PointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5228 | } |
| 5229 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5230 | void LocationsBuilderMIPS64::VisitLoadException(HLoadException* load) { |
| 5231 | LocationSummary* locations = |
| 5232 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5233 | locations->SetOut(Location::RequiresRegister()); |
| 5234 | } |
| 5235 | |
| 5236 | void InstructionCodeGeneratorMIPS64::VisitLoadException(HLoadException* load) { |
| 5237 | GpuRegister out = load->GetLocations()->Out().AsRegister<GpuRegister>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5238 | __ LoadFromOffset(kLoadUnsignedWord, out, TR, GetExceptionTlsOffset()); |
| 5239 | } |
| 5240 | |
| 5241 | void LocationsBuilderMIPS64::VisitClearException(HClearException* clear) { |
| 5242 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5243 | } |
| 5244 | |
| 5245 | void InstructionCodeGeneratorMIPS64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5246 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5247 | } |
| 5248 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5249 | void LocationsBuilderMIPS64::VisitLoadString(HLoadString* load) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5250 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 5251 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5252 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5253 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 5254 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5255 | locations->SetOut(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5256 | } else { |
| 5257 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5258 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 5259 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5260 | // Rely on the pResolveString and marking to save everything we need. |
| 5261 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5262 | InvokeRuntimeCallingConvention calling_convention; |
| 5263 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5264 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5265 | } else { |
| 5266 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5267 | } |
| 5268 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5269 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5270 | } |
| 5271 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5272 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5273 | // move. |
| 5274 | void InstructionCodeGeneratorMIPS64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5275 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 5276 | LocationSummary* locations = load->GetLocations(); |
| 5277 | Location out_loc = locations->Out(); |
| 5278 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 5279 | |
| 5280 | switch (load_kind) { |
| 5281 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5282 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5283 | __ LoadLiteral(out, |
| 5284 | kLoadUnsignedWord, |
| 5285 | codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 5286 | load->GetStringIndex())); |
| 5287 | return; // No dex cache slow path. |
| 5288 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 5289 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| 5290 | CodeGeneratorMIPS64::PcRelativePatchInfo* info = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5291 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5292 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info, AT); |
| 5293 | __ Daddiu(out, AT, /* placeholder */ 0x5678); |
| 5294 | return; // No dex cache slow path. |
| 5295 | } |
| 5296 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5297 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5298 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5299 | DCHECK_NE(address, 0u); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5300 | __ LoadLiteral(out, |
| 5301 | kLoadUnsignedWord, |
| 5302 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5303 | return; // No dex cache slow path. |
| 5304 | } |
| 5305 | case HLoadString::LoadKind::kBssEntry: { |
| 5306 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 5307 | CodeGeneratorMIPS64::PcRelativePatchInfo* info = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5308 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5309 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info, out); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5310 | GenerateGcRootFieldLoad(load, |
| 5311 | out_loc, |
| 5312 | out, |
| 5313 | /* placeholder */ 0x5678, |
| 5314 | kCompilerReadBarrierOption); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5315 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS64(load); |
| 5316 | codegen_->AddSlowPath(slow_path); |
| 5317 | __ Beqzc(out, slow_path->GetEntryLabel()); |
| 5318 | __ Bind(slow_path->GetExitLabel()); |
| 5319 | return; |
| 5320 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 5321 | case HLoadString::LoadKind::kJitTableAddress: |
| 5322 | __ LoadLiteral(out, |
| 5323 | kLoadUnsignedWord, |
| 5324 | codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
| 5325 | load->GetStringIndex(), |
| 5326 | load->GetString())); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5327 | GenerateGcRootFieldLoad(load, out_loc, out, 0, kCompilerReadBarrierOption); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 5328 | return; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5329 | default: |
| 5330 | break; |
| 5331 | } |
| 5332 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5333 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5334 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 5335 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5336 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5337 | __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
| 5338 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5339 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5340 | } |
| 5341 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5342 | void LocationsBuilderMIPS64::VisitLongConstant(HLongConstant* constant) { |
| 5343 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5344 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5345 | } |
| 5346 | |
| 5347 | void InstructionCodeGeneratorMIPS64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 5348 | // Will be generated at use site. |
| 5349 | } |
| 5350 | |
| 5351 | void LocationsBuilderMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5352 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5353 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5354 | InvokeRuntimeCallingConvention calling_convention; |
| 5355 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5356 | } |
| 5357 | |
| 5358 | void InstructionCodeGeneratorMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 5359 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5360 | instruction, |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 5361 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5362 | if (instruction->IsEnter()) { |
| 5363 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5364 | } else { |
| 5365 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5366 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5367 | } |
| 5368 | |
| 5369 | void LocationsBuilderMIPS64::VisitMul(HMul* mul) { |
| 5370 | LocationSummary* locations = |
| 5371 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 5372 | switch (mul->GetResultType()) { |
| 5373 | case Primitive::kPrimInt: |
| 5374 | case Primitive::kPrimLong: |
| 5375 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5376 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5377 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5378 | break; |
| 5379 | |
| 5380 | case Primitive::kPrimFloat: |
| 5381 | case Primitive::kPrimDouble: |
| 5382 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5383 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5384 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5385 | break; |
| 5386 | |
| 5387 | default: |
| 5388 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5389 | } |
| 5390 | } |
| 5391 | |
| 5392 | void InstructionCodeGeneratorMIPS64::VisitMul(HMul* instruction) { |
| 5393 | Primitive::Type type = instruction->GetType(); |
| 5394 | LocationSummary* locations = instruction->GetLocations(); |
| 5395 | |
| 5396 | switch (type) { |
| 5397 | case Primitive::kPrimInt: |
| 5398 | case Primitive::kPrimLong: { |
| 5399 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 5400 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 5401 | GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>(); |
| 5402 | if (type == Primitive::kPrimInt) |
| 5403 | __ MulR6(dst, lhs, rhs); |
| 5404 | else |
| 5405 | __ Dmul(dst, lhs, rhs); |
| 5406 | break; |
| 5407 | } |
| 5408 | case Primitive::kPrimFloat: |
| 5409 | case Primitive::kPrimDouble: { |
| 5410 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 5411 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 5412 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 5413 | if (type == Primitive::kPrimFloat) |
| 5414 | __ MulS(dst, lhs, rhs); |
| 5415 | else |
| 5416 | __ MulD(dst, lhs, rhs); |
| 5417 | break; |
| 5418 | } |
| 5419 | default: |
| 5420 | LOG(FATAL) << "Unexpected mul type " << type; |
| 5421 | } |
| 5422 | } |
| 5423 | |
| 5424 | void LocationsBuilderMIPS64::VisitNeg(HNeg* neg) { |
| 5425 | LocationSummary* locations = |
| 5426 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 5427 | switch (neg->GetResultType()) { |
| 5428 | case Primitive::kPrimInt: |
| 5429 | case Primitive::kPrimLong: |
| 5430 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5431 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5432 | break; |
| 5433 | |
| 5434 | case Primitive::kPrimFloat: |
| 5435 | case Primitive::kPrimDouble: |
| 5436 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5437 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5438 | break; |
| 5439 | |
| 5440 | default: |
| 5441 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5442 | } |
| 5443 | } |
| 5444 | |
| 5445 | void InstructionCodeGeneratorMIPS64::VisitNeg(HNeg* instruction) { |
| 5446 | Primitive::Type type = instruction->GetType(); |
| 5447 | LocationSummary* locations = instruction->GetLocations(); |
| 5448 | |
| 5449 | switch (type) { |
| 5450 | case Primitive::kPrimInt: |
| 5451 | case Primitive::kPrimLong: { |
| 5452 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 5453 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 5454 | if (type == Primitive::kPrimInt) |
| 5455 | __ Subu(dst, ZERO, src); |
| 5456 | else |
| 5457 | __ Dsubu(dst, ZERO, src); |
| 5458 | break; |
| 5459 | } |
| 5460 | case Primitive::kPrimFloat: |
| 5461 | case Primitive::kPrimDouble: { |
| 5462 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 5463 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 5464 | if (type == Primitive::kPrimFloat) |
| 5465 | __ NegS(dst, src); |
| 5466 | else |
| 5467 | __ NegD(dst, src); |
| 5468 | break; |
| 5469 | } |
| 5470 | default: |
| 5471 | LOG(FATAL) << "Unexpected neg type " << type; |
| 5472 | } |
| 5473 | } |
| 5474 | |
| 5475 | void LocationsBuilderMIPS64::VisitNewArray(HNewArray* instruction) { |
| 5476 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5477 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5478 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5479 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5480 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5481 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5482 | } |
| 5483 | |
| 5484 | void InstructionCodeGeneratorMIPS64::VisitNewArray(HNewArray* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5485 | // Note: if heap poisoning is enabled, the entry point takes care |
| 5486 | // of poisoning the reference. |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5487 | codegen_->InvokeRuntime(kQuickAllocArrayResolved, instruction, instruction->GetDexPc()); |
| 5488 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5489 | } |
| 5490 | |
| 5491 | void LocationsBuilderMIPS64::VisitNewInstance(HNewInstance* instruction) { |
| 5492 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5493 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5494 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5495 | if (instruction->IsStringAlloc()) { |
| 5496 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 5497 | } else { |
| 5498 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5499 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5500 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 5501 | } |
| 5502 | |
| 5503 | void InstructionCodeGeneratorMIPS64::VisitNewInstance(HNewInstance* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5504 | // Note: if heap poisoning is enabled, the entry point takes care |
| 5505 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5506 | if (instruction->IsStringAlloc()) { |
| 5507 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5508 | GpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<GpuRegister>(); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 5509 | MemberOffset code_offset = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5510 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5511 | __ LoadFromOffset(kLoadDoubleword, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 5512 | __ LoadFromOffset(kLoadDoubleword, T9, temp, code_offset.Int32Value()); |
| 5513 | __ Jalr(T9); |
| 5514 | __ Nop(); |
| 5515 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5516 | } else { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 5517 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 5518 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5519 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5520 | } |
| 5521 | |
| 5522 | void LocationsBuilderMIPS64::VisitNot(HNot* instruction) { |
| 5523 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5524 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5525 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5526 | } |
| 5527 | |
| 5528 | void InstructionCodeGeneratorMIPS64::VisitNot(HNot* instruction) { |
| 5529 | Primitive::Type type = instruction->GetType(); |
| 5530 | LocationSummary* locations = instruction->GetLocations(); |
| 5531 | |
| 5532 | switch (type) { |
| 5533 | case Primitive::kPrimInt: |
| 5534 | case Primitive::kPrimLong: { |
| 5535 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 5536 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 5537 | __ Nor(dst, src, ZERO); |
| 5538 | break; |
| 5539 | } |
| 5540 | |
| 5541 | default: |
| 5542 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5543 | } |
| 5544 | } |
| 5545 | |
| 5546 | void LocationsBuilderMIPS64::VisitBooleanNot(HBooleanNot* instruction) { |
| 5547 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5548 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5549 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5550 | } |
| 5551 | |
| 5552 | void InstructionCodeGeneratorMIPS64::VisitBooleanNot(HBooleanNot* instruction) { |
| 5553 | LocationSummary* locations = instruction->GetLocations(); |
| 5554 | __ Xori(locations->Out().AsRegister<GpuRegister>(), |
| 5555 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 5556 | 1); |
| 5557 | } |
| 5558 | |
| 5559 | void LocationsBuilderMIPS64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5560 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5561 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5562 | } |
| 5563 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5564 | void CodeGeneratorMIPS64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5565 | if (CanMoveNullCheckToUser(instruction)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5566 | return; |
| 5567 | } |
| 5568 | Location obj = instruction->GetLocations()->InAt(0); |
| 5569 | |
| 5570 | __ Lw(ZERO, obj.AsRegister<GpuRegister>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5571 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5572 | } |
| 5573 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5574 | void CodeGeneratorMIPS64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5575 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5576 | AddSlowPath(slow_path); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5577 | |
| 5578 | Location obj = instruction->GetLocations()->InAt(0); |
| 5579 | |
| 5580 | __ Beqzc(obj.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 5581 | } |
| 5582 | |
| 5583 | void InstructionCodeGeneratorMIPS64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5584 | codegen_->GenerateNullCheck(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5585 | } |
| 5586 | |
| 5587 | void LocationsBuilderMIPS64::VisitOr(HOr* instruction) { |
| 5588 | HandleBinaryOp(instruction); |
| 5589 | } |
| 5590 | |
| 5591 | void InstructionCodeGeneratorMIPS64::VisitOr(HOr* instruction) { |
| 5592 | HandleBinaryOp(instruction); |
| 5593 | } |
| 5594 | |
| 5595 | void LocationsBuilderMIPS64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5596 | LOG(FATAL) << "Unreachable"; |
| 5597 | } |
| 5598 | |
| 5599 | void InstructionCodeGeneratorMIPS64::VisitParallelMove(HParallelMove* instruction) { |
| 5600 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5601 | } |
| 5602 | |
| 5603 | void LocationsBuilderMIPS64::VisitParameterValue(HParameterValue* instruction) { |
| 5604 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5605 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5606 | if (location.IsStackSlot()) { |
| 5607 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5608 | } else if (location.IsDoubleStackSlot()) { |
| 5609 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5610 | } |
| 5611 | locations->SetOut(location); |
| 5612 | } |
| 5613 | |
| 5614 | void InstructionCodeGeneratorMIPS64::VisitParameterValue(HParameterValue* instruction |
| 5615 | ATTRIBUTE_UNUSED) { |
| 5616 | // Nothing to do, the parameter is already at its location. |
| 5617 | } |
| 5618 | |
| 5619 | void LocationsBuilderMIPS64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5620 | LocationSummary* locations = |
| 5621 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5622 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 5623 | } |
| 5624 | |
| 5625 | void InstructionCodeGeneratorMIPS64::VisitCurrentMethod(HCurrentMethod* instruction |
| 5626 | ATTRIBUTE_UNUSED) { |
| 5627 | // Nothing to do, the method is already at its location. |
| 5628 | } |
| 5629 | |
| 5630 | void LocationsBuilderMIPS64::VisitPhi(HPhi* instruction) { |
| 5631 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5632 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5633 | locations->SetInAt(i, Location::Any()); |
| 5634 | } |
| 5635 | locations->SetOut(Location::Any()); |
| 5636 | } |
| 5637 | |
| 5638 | void InstructionCodeGeneratorMIPS64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 5639 | LOG(FATAL) << "Unreachable"; |
| 5640 | } |
| 5641 | |
| 5642 | void LocationsBuilderMIPS64::VisitRem(HRem* rem) { |
| 5643 | Primitive::Type type = rem->GetResultType(); |
| 5644 | LocationSummary::CallKind call_kind = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5645 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 5646 | : LocationSummary::kNoCall; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5647 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 5648 | |
| 5649 | switch (type) { |
| 5650 | case Primitive::kPrimInt: |
| 5651 | case Primitive::kPrimLong: |
| 5652 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 5653 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5654 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5655 | break; |
| 5656 | |
| 5657 | case Primitive::kPrimFloat: |
| 5658 | case Primitive::kPrimDouble: { |
| 5659 | InvokeRuntimeCallingConvention calling_convention; |
| 5660 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 5661 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 5662 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5663 | break; |
| 5664 | } |
| 5665 | |
| 5666 | default: |
| 5667 | LOG(FATAL) << "Unexpected rem type " << type; |
| 5668 | } |
| 5669 | } |
| 5670 | |
| 5671 | void InstructionCodeGeneratorMIPS64::VisitRem(HRem* instruction) { |
| 5672 | Primitive::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5673 | |
| 5674 | switch (type) { |
| 5675 | case Primitive::kPrimInt: |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 5676 | case Primitive::kPrimLong: |
| 5677 | GenerateDivRemIntegral(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5678 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5679 | |
| 5680 | case Primitive::kPrimFloat: |
| 5681 | case Primitive::kPrimDouble: { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 5682 | QuickEntrypointEnum entrypoint = (type == Primitive::kPrimFloat) ? kQuickFmodf : kQuickFmod; |
| 5683 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5684 | if (type == Primitive::kPrimFloat) { |
| 5685 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 5686 | } else { |
| 5687 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 5688 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5689 | break; |
| 5690 | } |
| 5691 | default: |
| 5692 | LOG(FATAL) << "Unexpected rem type " << type; |
| 5693 | } |
| 5694 | } |
| 5695 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5696 | void LocationsBuilderMIPS64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 5697 | constructor_fence->SetLocations(nullptr); |
| 5698 | } |
| 5699 | |
| 5700 | void InstructionCodeGeneratorMIPS64::VisitConstructorFence( |
| 5701 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 5702 | GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 5703 | } |
| 5704 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5705 | void LocationsBuilderMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5706 | memory_barrier->SetLocations(nullptr); |
| 5707 | } |
| 5708 | |
| 5709 | void InstructionCodeGeneratorMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5710 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 5711 | } |
| 5712 | |
| 5713 | void LocationsBuilderMIPS64::VisitReturn(HReturn* ret) { |
| 5714 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret); |
| 5715 | Primitive::Type return_type = ret->InputAt(0)->GetType(); |
| 5716 | locations->SetInAt(0, Mips64ReturnLocation(return_type)); |
| 5717 | } |
| 5718 | |
| 5719 | void InstructionCodeGeneratorMIPS64::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 5720 | codegen_->GenerateFrameExit(); |
| 5721 | } |
| 5722 | |
| 5723 | void LocationsBuilderMIPS64::VisitReturnVoid(HReturnVoid* ret) { |
| 5724 | ret->SetLocations(nullptr); |
| 5725 | } |
| 5726 | |
| 5727 | void InstructionCodeGeneratorMIPS64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 5728 | codegen_->GenerateFrameExit(); |
| 5729 | } |
| 5730 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 5731 | void LocationsBuilderMIPS64::VisitRor(HRor* ror) { |
| 5732 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5733 | } |
| 5734 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 5735 | void InstructionCodeGeneratorMIPS64::VisitRor(HRor* ror) { |
| 5736 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5737 | } |
| 5738 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5739 | void LocationsBuilderMIPS64::VisitShl(HShl* shl) { |
| 5740 | HandleShift(shl); |
| 5741 | } |
| 5742 | |
| 5743 | void InstructionCodeGeneratorMIPS64::VisitShl(HShl* shl) { |
| 5744 | HandleShift(shl); |
| 5745 | } |
| 5746 | |
| 5747 | void LocationsBuilderMIPS64::VisitShr(HShr* shr) { |
| 5748 | HandleShift(shr); |
| 5749 | } |
| 5750 | |
| 5751 | void InstructionCodeGeneratorMIPS64::VisitShr(HShr* shr) { |
| 5752 | HandleShift(shr); |
| 5753 | } |
| 5754 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5755 | void LocationsBuilderMIPS64::VisitSub(HSub* instruction) { |
| 5756 | HandleBinaryOp(instruction); |
| 5757 | } |
| 5758 | |
| 5759 | void InstructionCodeGeneratorMIPS64::VisitSub(HSub* instruction) { |
| 5760 | HandleBinaryOp(instruction); |
| 5761 | } |
| 5762 | |
| 5763 | void LocationsBuilderMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5764 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5765 | } |
| 5766 | |
| 5767 | void InstructionCodeGeneratorMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5768 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5769 | } |
| 5770 | |
| 5771 | void LocationsBuilderMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5772 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5773 | } |
| 5774 | |
| 5775 | void InstructionCodeGeneratorMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 5776 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5777 | } |
| 5778 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5779 | void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldGet( |
| 5780 | HUnresolvedInstanceFieldGet* instruction) { |
| 5781 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 5782 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5783 | instruction, instruction->GetFieldType(), calling_convention); |
| 5784 | } |
| 5785 | |
| 5786 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldGet( |
| 5787 | HUnresolvedInstanceFieldGet* instruction) { |
| 5788 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 5789 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5790 | instruction->GetFieldType(), |
| 5791 | instruction->GetFieldIndex(), |
| 5792 | instruction->GetDexPc(), |
| 5793 | calling_convention); |
| 5794 | } |
| 5795 | |
| 5796 | void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldSet( |
| 5797 | HUnresolvedInstanceFieldSet* instruction) { |
| 5798 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 5799 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5800 | instruction, instruction->GetFieldType(), calling_convention); |
| 5801 | } |
| 5802 | |
| 5803 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldSet( |
| 5804 | HUnresolvedInstanceFieldSet* instruction) { |
| 5805 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 5806 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5807 | instruction->GetFieldType(), |
| 5808 | instruction->GetFieldIndex(), |
| 5809 | instruction->GetDexPc(), |
| 5810 | calling_convention); |
| 5811 | } |
| 5812 | |
| 5813 | void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldGet( |
| 5814 | HUnresolvedStaticFieldGet* instruction) { |
| 5815 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 5816 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5817 | instruction, instruction->GetFieldType(), calling_convention); |
| 5818 | } |
| 5819 | |
| 5820 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldGet( |
| 5821 | HUnresolvedStaticFieldGet* instruction) { |
| 5822 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 5823 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5824 | instruction->GetFieldType(), |
| 5825 | instruction->GetFieldIndex(), |
| 5826 | instruction->GetDexPc(), |
| 5827 | calling_convention); |
| 5828 | } |
| 5829 | |
| 5830 | void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldSet( |
| 5831 | HUnresolvedStaticFieldSet* instruction) { |
| 5832 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 5833 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5834 | instruction, instruction->GetFieldType(), calling_convention); |
| 5835 | } |
| 5836 | |
| 5837 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldSet( |
| 5838 | HUnresolvedStaticFieldSet* instruction) { |
| 5839 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 5840 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5841 | instruction->GetFieldType(), |
| 5842 | instruction->GetFieldIndex(), |
| 5843 | instruction->GetDexPc(), |
| 5844 | calling_convention); |
| 5845 | } |
| 5846 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5847 | void LocationsBuilderMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5848 | LocationSummary* locations = |
| 5849 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame^] | 5850 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5851 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5852 | // registers in full width (since the runtime only saves/restores lower part). |
| 5853 | locations->SetCustomSlowPathCallerSaves( |
| 5854 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5855 | } |
| 5856 | |
| 5857 | void InstructionCodeGeneratorMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5858 | HBasicBlock* block = instruction->GetBlock(); |
| 5859 | if (block->GetLoopInformation() != nullptr) { |
| 5860 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5861 | // The back edge will generate the suspend check. |
| 5862 | return; |
| 5863 | } |
| 5864 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5865 | // The goto will generate the suspend check. |
| 5866 | return; |
| 5867 | } |
| 5868 | GenerateSuspendCheck(instruction, nullptr); |
| 5869 | } |
| 5870 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5871 | void LocationsBuilderMIPS64::VisitThrow(HThrow* instruction) { |
| 5872 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5873 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5874 | InvokeRuntimeCallingConvention calling_convention; |
| 5875 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5876 | } |
| 5877 | |
| 5878 | void InstructionCodeGeneratorMIPS64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 5879 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5880 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 5881 | } |
| 5882 | |
| 5883 | void LocationsBuilderMIPS64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5884 | Primitive::Type input_type = conversion->GetInputType(); |
| 5885 | Primitive::Type result_type = conversion->GetResultType(); |
| 5886 | DCHECK_NE(input_type, result_type); |
| 5887 | |
| 5888 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 5889 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 5890 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 5891 | } |
| 5892 | |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 5893 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion); |
| 5894 | |
| 5895 | if (Primitive::IsFloatingPointType(input_type)) { |
| 5896 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5897 | } else { |
| 5898 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5899 | } |
| 5900 | |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 5901 | if (Primitive::IsFloatingPointType(result_type)) { |
| 5902 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5903 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 5904 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5905 | } |
| 5906 | } |
| 5907 | |
| 5908 | void InstructionCodeGeneratorMIPS64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5909 | LocationSummary* locations = conversion->GetLocations(); |
| 5910 | Primitive::Type result_type = conversion->GetResultType(); |
| 5911 | Primitive::Type input_type = conversion->GetInputType(); |
| 5912 | |
| 5913 | DCHECK_NE(input_type, result_type); |
| 5914 | |
| 5915 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
| 5916 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 5917 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 5918 | |
| 5919 | switch (result_type) { |
| 5920 | case Primitive::kPrimChar: |
| 5921 | __ Andi(dst, src, 0xFFFF); |
| 5922 | break; |
| 5923 | case Primitive::kPrimByte: |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 5924 | if (input_type == Primitive::kPrimLong) { |
| 5925 | // Type conversion from long to types narrower than int is a result of code |
| 5926 | // transformations. To avoid unpredictable results for SEB and SEH, we first |
| 5927 | // need to sign-extend the low 32-bit value into bits 32 through 63. |
| 5928 | __ Sll(dst, src, 0); |
| 5929 | __ Seb(dst, dst); |
| 5930 | } else { |
| 5931 | __ Seb(dst, src); |
| 5932 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5933 | break; |
| 5934 | case Primitive::kPrimShort: |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 5935 | if (input_type == Primitive::kPrimLong) { |
| 5936 | // Type conversion from long to types narrower than int is a result of code |
| 5937 | // transformations. To avoid unpredictable results for SEB and SEH, we first |
| 5938 | // need to sign-extend the low 32-bit value into bits 32 through 63. |
| 5939 | __ Sll(dst, src, 0); |
| 5940 | __ Seh(dst, dst); |
| 5941 | } else { |
| 5942 | __ Seh(dst, src); |
| 5943 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5944 | break; |
| 5945 | case Primitive::kPrimInt: |
| 5946 | case Primitive::kPrimLong: |
Goran Jakovljevic | 992bdb9 | 2016-12-28 16:21:48 +0100 | [diff] [blame] | 5947 | // Sign-extend 32-bit int into bits 32 through 63 for int-to-long and long-to-int |
| 5948 | // conversions, except when the input and output registers are the same and we are not |
| 5949 | // converting longs to shorter types. In these cases, do nothing. |
| 5950 | if ((input_type == Primitive::kPrimLong) || (dst != src)) { |
| 5951 | __ Sll(dst, src, 0); |
| 5952 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5953 | break; |
| 5954 | |
| 5955 | default: |
| 5956 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 5957 | << " to " << result_type; |
| 5958 | } |
| 5959 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 5960 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 5961 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 5962 | if (input_type == Primitive::kPrimLong) { |
| 5963 | __ Dmtc1(src, FTMP); |
| 5964 | if (result_type == Primitive::kPrimFloat) { |
| 5965 | __ Cvtsl(dst, FTMP); |
| 5966 | } else { |
| 5967 | __ Cvtdl(dst, FTMP); |
| 5968 | } |
| 5969 | } else { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5970 | __ Mtc1(src, FTMP); |
| 5971 | if (result_type == Primitive::kPrimFloat) { |
| 5972 | __ Cvtsw(dst, FTMP); |
| 5973 | } else { |
| 5974 | __ Cvtdw(dst, FTMP); |
| 5975 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5976 | } |
| 5977 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
| 5978 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 5979 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 5980 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 5981 | Mips64Label truncate; |
| 5982 | Mips64Label done; |
| 5983 | |
| 5984 | // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive |
| 5985 | // value when the input is either a NaN or is outside of the range of the output type |
| 5986 | // after the truncation. IOW, the three special cases (NaN, too small, too big) produce |
| 5987 | // the same result. |
| 5988 | // |
| 5989 | // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum |
| 5990 | // value of the output type if the input is outside of the range after the truncation or |
| 5991 | // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct |
| 5992 | // results. This matches the desired float/double-to-int/long conversion exactly. |
| 5993 | // |
| 5994 | // So, NAN2008 affects handling of negative values and NaNs by the truncate instruction. |
| 5995 | // |
| 5996 | // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate |
| 5997 | // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6, |
| 5998 | // even though it must be NAN2008=1 on R6. |
| 5999 | // |
| 6000 | // The code takes care of the different behaviors by first comparing the input to the |
| 6001 | // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int). |
| 6002 | // If the input is greater than or equal to the minimum, it procedes to the truncate |
| 6003 | // instruction, which will handle such an input the same way irrespective of NAN2008. |
| 6004 | // Otherwise the input is compared to itself to determine whether it is a NaN or not |
| 6005 | // in order to return either zero or the minimum value. |
| 6006 | // |
| 6007 | // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the |
| 6008 | // truncate instruction for MIPS64R6. |
| 6009 | if (input_type == Primitive::kPrimFloat) { |
| 6010 | uint32_t min_val = (result_type == Primitive::kPrimLong) |
| 6011 | ? bit_cast<uint32_t, float>(std::numeric_limits<int64_t>::min()) |
| 6012 | : bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min()); |
| 6013 | __ LoadConst32(TMP, min_val); |
| 6014 | __ Mtc1(TMP, FTMP); |
| 6015 | __ CmpLeS(FTMP, FTMP, src); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6016 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6017 | uint64_t min_val = (result_type == Primitive::kPrimLong) |
| 6018 | ? bit_cast<uint64_t, double>(std::numeric_limits<int64_t>::min()) |
| 6019 | : bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min()); |
| 6020 | __ LoadConst64(TMP, min_val); |
| 6021 | __ Dmtc1(TMP, FTMP); |
| 6022 | __ CmpLeD(FTMP, FTMP, src); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6023 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6024 | |
| 6025 | __ Bc1nez(FTMP, &truncate); |
| 6026 | |
| 6027 | if (input_type == Primitive::kPrimFloat) { |
| 6028 | __ CmpEqS(FTMP, src, src); |
| 6029 | } else { |
| 6030 | __ CmpEqD(FTMP, src, src); |
| 6031 | } |
| 6032 | if (result_type == Primitive::kPrimLong) { |
| 6033 | __ LoadConst64(dst, std::numeric_limits<int64_t>::min()); |
| 6034 | } else { |
| 6035 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); |
| 6036 | } |
| 6037 | __ Mfc1(TMP, FTMP); |
| 6038 | __ And(dst, dst, TMP); |
| 6039 | |
| 6040 | __ Bc(&done); |
| 6041 | |
| 6042 | __ Bind(&truncate); |
| 6043 | |
| 6044 | if (result_type == Primitive::kPrimLong) { |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6045 | if (input_type == Primitive::kPrimFloat) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6046 | __ TruncLS(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6047 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6048 | __ TruncLD(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6049 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6050 | __ Dmfc1(dst, FTMP); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6051 | } else { |
| 6052 | if (input_type == Primitive::kPrimFloat) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6053 | __ TruncWS(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6054 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6055 | __ TruncWD(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6056 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6057 | __ Mfc1(dst, FTMP); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6058 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6059 | |
| 6060 | __ Bind(&done); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6061 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 6062 | Primitive::IsFloatingPointType(input_type)) { |
| 6063 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 6064 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 6065 | if (result_type == Primitive::kPrimFloat) { |
| 6066 | __ Cvtsd(dst, src); |
| 6067 | } else { |
| 6068 | __ Cvtds(dst, src); |
| 6069 | } |
| 6070 | } else { |
| 6071 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 6072 | << " to " << result_type; |
| 6073 | } |
| 6074 | } |
| 6075 | |
| 6076 | void LocationsBuilderMIPS64::VisitUShr(HUShr* ushr) { |
| 6077 | HandleShift(ushr); |
| 6078 | } |
| 6079 | |
| 6080 | void InstructionCodeGeneratorMIPS64::VisitUShr(HUShr* ushr) { |
| 6081 | HandleShift(ushr); |
| 6082 | } |
| 6083 | |
| 6084 | void LocationsBuilderMIPS64::VisitXor(HXor* instruction) { |
| 6085 | HandleBinaryOp(instruction); |
| 6086 | } |
| 6087 | |
| 6088 | void InstructionCodeGeneratorMIPS64::VisitXor(HXor* instruction) { |
| 6089 | HandleBinaryOp(instruction); |
| 6090 | } |
| 6091 | |
| 6092 | void LocationsBuilderMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 6093 | // Nothing to do, this should be removed during prepare for register allocator. |
| 6094 | LOG(FATAL) << "Unreachable"; |
| 6095 | } |
| 6096 | |
| 6097 | void InstructionCodeGeneratorMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 6098 | // Nothing to do, this should be removed during prepare for register allocator. |
| 6099 | LOG(FATAL) << "Unreachable"; |
| 6100 | } |
| 6101 | |
| 6102 | void LocationsBuilderMIPS64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6103 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6104 | } |
| 6105 | |
| 6106 | void InstructionCodeGeneratorMIPS64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6107 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6108 | } |
| 6109 | |
| 6110 | void LocationsBuilderMIPS64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6111 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6112 | } |
| 6113 | |
| 6114 | void InstructionCodeGeneratorMIPS64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6115 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6116 | } |
| 6117 | |
| 6118 | void LocationsBuilderMIPS64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6119 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6120 | } |
| 6121 | |
| 6122 | void InstructionCodeGeneratorMIPS64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6123 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6124 | } |
| 6125 | |
| 6126 | void LocationsBuilderMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6127 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6128 | } |
| 6129 | |
| 6130 | void InstructionCodeGeneratorMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6131 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6132 | } |
| 6133 | |
| 6134 | void LocationsBuilderMIPS64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6135 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6136 | } |
| 6137 | |
| 6138 | void InstructionCodeGeneratorMIPS64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6139 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6140 | } |
| 6141 | |
| 6142 | void LocationsBuilderMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6143 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6144 | } |
| 6145 | |
| 6146 | void InstructionCodeGeneratorMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6147 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6148 | } |
| 6149 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6150 | void LocationsBuilderMIPS64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6151 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6152 | } |
| 6153 | |
| 6154 | void InstructionCodeGeneratorMIPS64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6155 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6156 | } |
| 6157 | |
| 6158 | void LocationsBuilderMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6159 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6160 | } |
| 6161 | |
| 6162 | void InstructionCodeGeneratorMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6163 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6164 | } |
| 6165 | |
| 6166 | void LocationsBuilderMIPS64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6167 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6168 | } |
| 6169 | |
| 6170 | void InstructionCodeGeneratorMIPS64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6171 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6172 | } |
| 6173 | |
| 6174 | void LocationsBuilderMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6175 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6176 | } |
| 6177 | |
| 6178 | void InstructionCodeGeneratorMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6179 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6180 | } |
| 6181 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6182 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6183 | void LocationsBuilderMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6184 | LocationSummary* locations = |
| 6185 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6186 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6187 | } |
| 6188 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 6189 | void InstructionCodeGeneratorMIPS64::GenPackedSwitchWithCompares(GpuRegister value_reg, |
| 6190 | int32_t lower_bound, |
| 6191 | uint32_t num_entries, |
| 6192 | HBasicBlock* switch_block, |
| 6193 | HBasicBlock* default_block) { |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6194 | // Create a set of compare/jumps. |
| 6195 | GpuRegister temp_reg = TMP; |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 6196 | __ Addiu32(temp_reg, value_reg, -lower_bound); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6197 | // Jump to default if index is negative |
| 6198 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 6199 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 6200 | __ Bltzc(temp_reg, codegen_->GetLabelOf(default_block)); |
| 6201 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 6202 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6203 | // Jump to successors[0] if value == lower_bound. |
| 6204 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 6205 | int32_t last_index = 0; |
| 6206 | for (; num_entries - last_index > 2; last_index += 2) { |
| 6207 | __ Addiu(temp_reg, temp_reg, -2); |
| 6208 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 6209 | __ Bltzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 6210 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 6211 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 6212 | } |
| 6213 | if (num_entries - last_index == 2) { |
| 6214 | // The last missing case_value. |
| 6215 | __ Addiu(temp_reg, temp_reg, -1); |
| 6216 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6217 | } |
| 6218 | |
| 6219 | // And the default for any other value. |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 6220 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 6221 | __ Bc(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6222 | } |
| 6223 | } |
| 6224 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 6225 | void InstructionCodeGeneratorMIPS64::GenTableBasedPackedSwitch(GpuRegister value_reg, |
| 6226 | int32_t lower_bound, |
| 6227 | uint32_t num_entries, |
| 6228 | HBasicBlock* switch_block, |
| 6229 | HBasicBlock* default_block) { |
| 6230 | // Create a jump table. |
| 6231 | std::vector<Mips64Label*> labels(num_entries); |
| 6232 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 6233 | for (uint32_t i = 0; i < num_entries; i++) { |
| 6234 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 6235 | } |
| 6236 | JumpTable* table = __ CreateJumpTable(std::move(labels)); |
| 6237 | |
| 6238 | // Is the value in range? |
| 6239 | __ Addiu32(TMP, value_reg, -lower_bound); |
| 6240 | __ LoadConst32(AT, num_entries); |
| 6241 | __ Bgeuc(TMP, AT, codegen_->GetLabelOf(default_block)); |
| 6242 | |
| 6243 | // We are in the range of the table. |
| 6244 | // Load the target address from the jump table, indexing by the value. |
| 6245 | __ LoadLabelAddress(AT, table->GetLabel()); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 6246 | __ Dlsa(TMP, TMP, AT, 2); |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 6247 | __ Lw(TMP, TMP, 0); |
| 6248 | // Compute the absolute target address by adding the table start address |
| 6249 | // (the table contains offsets to targets relative to its start). |
| 6250 | __ Daddu(TMP, TMP, AT); |
| 6251 | // And jump. |
| 6252 | __ Jr(TMP); |
| 6253 | __ Nop(); |
| 6254 | } |
| 6255 | |
| 6256 | void InstructionCodeGeneratorMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6257 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 6258 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 6259 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6260 | GpuRegister value_reg = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6261 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 6262 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6263 | |
| 6264 | if (num_entries > kPackedSwitchJumpTableThreshold) { |
| 6265 | GenTableBasedPackedSwitch(value_reg, |
| 6266 | lower_bound, |
| 6267 | num_entries, |
| 6268 | switch_block, |
| 6269 | default_block); |
| 6270 | } else { |
| 6271 | GenPackedSwitchWithCompares(value_reg, |
| 6272 | lower_bound, |
| 6273 | num_entries, |
| 6274 | switch_block, |
| 6275 | default_block); |
| 6276 | } |
| 6277 | } |
| 6278 | |
Chris Larsen | c9905a6 | 2017-03-13 17:06:18 -0700 | [diff] [blame] | 6279 | void LocationsBuilderMIPS64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6280 | LocationSummary* locations = |
| 6281 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6282 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6283 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6284 | } |
| 6285 | |
Chris Larsen | c9905a6 | 2017-03-13 17:06:18 -0700 | [diff] [blame] | 6286 | void InstructionCodeGeneratorMIPS64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6287 | LocationSummary* locations = instruction->GetLocations(); |
| 6288 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 6289 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 6290 | instruction->GetIndex(), kMips64PointerSize).SizeValue(); |
| 6291 | __ LoadFromOffset(kLoadDoubleword, |
| 6292 | locations->Out().AsRegister<GpuRegister>(), |
| 6293 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 6294 | method_offset); |
| 6295 | } else { |
| 6296 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 6297 | instruction->GetIndex(), kMips64PointerSize)); |
| 6298 | __ LoadFromOffset(kLoadDoubleword, |
| 6299 | locations->Out().AsRegister<GpuRegister>(), |
| 6300 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 6301 | mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value()); |
| 6302 | __ LoadFromOffset(kLoadDoubleword, |
| 6303 | locations->Out().AsRegister<GpuRegister>(), |
| 6304 | locations->Out().AsRegister<GpuRegister>(), |
| 6305 | method_offset); |
| 6306 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6307 | } |
| 6308 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6309 | } // namespace mips64 |
| 6310 | } // namespace art |