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()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 399 | LocationSummary* locations = instruction_->GetLocations(); |
| 400 | SaveLiveRegisters(codegen, locations); |
| 401 | InvokeRuntimeCallingConvention calling_convention; |
| 402 | __ LoadConst32(calling_convention.GetRegisterAt(0), |
| 403 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 404 | mips64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 405 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 406 | } |
| 407 | |
Roland Levillain | 4664889 | 2015-06-19 16:07:18 +0100 | [diff] [blame] | 408 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS64"; } |
| 409 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 410 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 411 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS64); |
| 412 | }; |
| 413 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 414 | class ArraySetSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 415 | public: |
| 416 | explicit ArraySetSlowPathMIPS64(HInstruction* instruction) : SlowPathCodeMIPS64(instruction) {} |
| 417 | |
| 418 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 419 | LocationSummary* locations = instruction_->GetLocations(); |
| 420 | __ Bind(GetEntryLabel()); |
| 421 | SaveLiveRegisters(codegen, locations); |
| 422 | |
| 423 | InvokeRuntimeCallingConvention calling_convention; |
| 424 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 425 | parallel_move.AddMove( |
| 426 | locations->InAt(0), |
| 427 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 428 | Primitive::kPrimNot, |
| 429 | nullptr); |
| 430 | parallel_move.AddMove( |
| 431 | locations->InAt(1), |
| 432 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 433 | Primitive::kPrimInt, |
| 434 | nullptr); |
| 435 | parallel_move.AddMove( |
| 436 | locations->InAt(2), |
| 437 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 438 | Primitive::kPrimNot, |
| 439 | nullptr); |
| 440 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 441 | |
| 442 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 443 | mips64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 444 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 445 | RestoreLiveRegisters(codegen, locations); |
| 446 | __ Bc(GetExitLabel()); |
| 447 | } |
| 448 | |
| 449 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathMIPS64"; } |
| 450 | |
| 451 | private: |
| 452 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathMIPS64); |
| 453 | }; |
| 454 | |
| 455 | // Slow path marking an object reference `ref` during a read |
| 456 | // barrier. The field `obj.field` in the object `obj` holding this |
| 457 | // reference does not get updated by this slow path after marking (see |
| 458 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 below for that). |
| 459 | // |
| 460 | // This means that after the execution of this slow path, `ref` will |
| 461 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 462 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 463 | // probably still be a from-space reference (unless it gets updated by |
| 464 | // another thread, or if another thread installed another object |
| 465 | // reference (different from `ref`) in `obj.field`). |
| 466 | // |
| 467 | // If `entrypoint` is a valid location it is assumed to already be |
| 468 | // holding the entrypoint. The case where the entrypoint is passed in |
| 469 | // is for the GcRoot read barrier. |
| 470 | class ReadBarrierMarkSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 471 | public: |
| 472 | ReadBarrierMarkSlowPathMIPS64(HInstruction* instruction, |
| 473 | Location ref, |
| 474 | Location entrypoint = Location::NoLocation()) |
| 475 | : SlowPathCodeMIPS64(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 476 | DCHECK(kEmitCompilerReadBarrier); |
| 477 | } |
| 478 | |
| 479 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathMIPS"; } |
| 480 | |
| 481 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 482 | LocationSummary* locations = instruction_->GetLocations(); |
| 483 | GpuRegister ref_reg = ref_.AsRegister<GpuRegister>(); |
| 484 | DCHECK(locations->CanCall()); |
| 485 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 486 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 487 | instruction_->IsStaticFieldGet() || |
| 488 | instruction_->IsArrayGet() || |
| 489 | instruction_->IsArraySet() || |
| 490 | instruction_->IsLoadClass() || |
| 491 | instruction_->IsLoadString() || |
| 492 | instruction_->IsInstanceOf() || |
| 493 | instruction_->IsCheckCast() || |
| 494 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 495 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 496 | << "Unexpected instruction in read barrier marking slow path: " |
| 497 | << instruction_->DebugName(); |
| 498 | |
| 499 | __ Bind(GetEntryLabel()); |
| 500 | // No need to save live registers; it's taken care of by the |
| 501 | // entrypoint. Also, there is no need to update the stack mask, |
| 502 | // as this runtime call will not trigger a garbage collection. |
| 503 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 504 | DCHECK((V0 <= ref_reg && ref_reg <= T2) || |
| 505 | (S2 <= ref_reg && ref_reg <= S7) || |
| 506 | (ref_reg == S8)) << ref_reg; |
| 507 | // "Compact" slow path, saving two moves. |
| 508 | // |
| 509 | // Instead of using the standard runtime calling convention (input |
| 510 | // and output in A0 and V0 respectively): |
| 511 | // |
| 512 | // A0 <- ref |
| 513 | // V0 <- ReadBarrierMark(A0) |
| 514 | // ref <- V0 |
| 515 | // |
| 516 | // we just use rX (the register containing `ref`) as input and output |
| 517 | // of a dedicated entrypoint: |
| 518 | // |
| 519 | // rX <- ReadBarrierMarkRegX(rX) |
| 520 | // |
| 521 | if (entrypoint_.IsValid()) { |
| 522 | mips64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 523 | DCHECK_EQ(entrypoint_.AsRegister<GpuRegister>(), T9); |
| 524 | __ Jalr(entrypoint_.AsRegister<GpuRegister>()); |
| 525 | __ Nop(); |
| 526 | } else { |
| 527 | int32_t entry_point_offset = |
| 528 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(ref_reg - 1); |
| 529 | // This runtime call does not require a stack map. |
| 530 | mips64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 531 | instruction_, |
| 532 | this); |
| 533 | } |
| 534 | __ Bc(GetExitLabel()); |
| 535 | } |
| 536 | |
| 537 | private: |
| 538 | // The location (register) of the marked object reference. |
| 539 | const Location ref_; |
| 540 | |
| 541 | // The location of the entrypoint if already loaded. |
| 542 | const Location entrypoint_; |
| 543 | |
| 544 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathMIPS64); |
| 545 | }; |
| 546 | |
| 547 | // Slow path marking an object reference `ref` during a read barrier, |
| 548 | // and if needed, atomically updating the field `obj.field` in the |
| 549 | // object `obj` holding this reference after marking (contrary to |
| 550 | // ReadBarrierMarkSlowPathMIPS64 above, which never tries to update |
| 551 | // `obj.field`). |
| 552 | // |
| 553 | // This means that after the execution of this slow path, both `ref` |
| 554 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 555 | // hold the same to-space reference (unless another thread installed |
| 556 | // another object reference (different from `ref`) in `obj.field`). |
| 557 | class ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 558 | public: |
| 559 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS64(HInstruction* instruction, |
| 560 | Location ref, |
| 561 | GpuRegister obj, |
| 562 | Location field_offset, |
| 563 | GpuRegister temp1) |
| 564 | : SlowPathCodeMIPS64(instruction), |
| 565 | ref_(ref), |
| 566 | obj_(obj), |
| 567 | field_offset_(field_offset), |
| 568 | temp1_(temp1) { |
| 569 | DCHECK(kEmitCompilerReadBarrier); |
| 570 | } |
| 571 | |
| 572 | const char* GetDescription() const OVERRIDE { |
| 573 | return "ReadBarrierMarkAndUpdateFieldSlowPathMIPS64"; |
| 574 | } |
| 575 | |
| 576 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 577 | LocationSummary* locations = instruction_->GetLocations(); |
| 578 | GpuRegister ref_reg = ref_.AsRegister<GpuRegister>(); |
| 579 | DCHECK(locations->CanCall()); |
| 580 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 581 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 582 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 583 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 584 | << instruction_->DebugName(); |
| 585 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 586 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 587 | DCHECK(field_offset_.IsRegister()) << field_offset_; |
| 588 | |
| 589 | __ Bind(GetEntryLabel()); |
| 590 | |
| 591 | // Save the old reference. |
| 592 | // Note that we cannot use AT or TMP to save the old reference, as those |
| 593 | // are used by the code that follows, but we need the old reference after |
| 594 | // the call to the ReadBarrierMarkRegX entry point. |
| 595 | DCHECK_NE(temp1_, AT); |
| 596 | DCHECK_NE(temp1_, TMP); |
| 597 | __ Move(temp1_, ref_reg); |
| 598 | |
| 599 | // No need to save live registers; it's taken care of by the |
| 600 | // entrypoint. Also, there is no need to update the stack mask, |
| 601 | // as this runtime call will not trigger a garbage collection. |
| 602 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 603 | DCHECK((V0 <= ref_reg && ref_reg <= T2) || |
| 604 | (S2 <= ref_reg && ref_reg <= S7) || |
| 605 | (ref_reg == S8)) << ref_reg; |
| 606 | // "Compact" slow path, saving two moves. |
| 607 | // |
| 608 | // Instead of using the standard runtime calling convention (input |
| 609 | // and output in A0 and V0 respectively): |
| 610 | // |
| 611 | // A0 <- ref |
| 612 | // V0 <- ReadBarrierMark(A0) |
| 613 | // ref <- V0 |
| 614 | // |
| 615 | // we just use rX (the register containing `ref`) as input and output |
| 616 | // of a dedicated entrypoint: |
| 617 | // |
| 618 | // rX <- ReadBarrierMarkRegX(rX) |
| 619 | // |
| 620 | int32_t entry_point_offset = |
| 621 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(ref_reg - 1); |
| 622 | // This runtime call does not require a stack map. |
| 623 | mips64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 624 | instruction_, |
| 625 | this); |
| 626 | |
| 627 | // If the new reference is different from the old reference, |
| 628 | // update the field in the holder (`*(obj_ + field_offset_)`). |
| 629 | // |
| 630 | // Note that this field could also hold a different object, if |
| 631 | // another thread had concurrently changed it. In that case, the |
| 632 | // the compare-and-set (CAS) loop below would abort, leaving the |
| 633 | // field as-is. |
| 634 | Mips64Label done; |
| 635 | __ Beqc(temp1_, ref_reg, &done); |
| 636 | |
| 637 | // Update the the holder's field atomically. This may fail if |
| 638 | // mutator updates before us, but it's OK. This is achieved |
| 639 | // using a strong compare-and-set (CAS) operation with relaxed |
| 640 | // memory synchronization ordering, where the expected value is |
| 641 | // the old reference and the desired value is the new reference. |
| 642 | |
| 643 | // Convenience aliases. |
| 644 | GpuRegister base = obj_; |
| 645 | GpuRegister offset = field_offset_.AsRegister<GpuRegister>(); |
| 646 | GpuRegister expected = temp1_; |
| 647 | GpuRegister value = ref_reg; |
| 648 | GpuRegister tmp_ptr = TMP; // Pointer to actual memory. |
| 649 | GpuRegister tmp = AT; // Value in memory. |
| 650 | |
| 651 | __ Daddu(tmp_ptr, base, offset); |
| 652 | |
| 653 | if (kPoisonHeapReferences) { |
| 654 | __ PoisonHeapReference(expected); |
| 655 | // Do not poison `value` if it is the same register as |
| 656 | // `expected`, which has just been poisoned. |
| 657 | if (value != expected) { |
| 658 | __ PoisonHeapReference(value); |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | // do { |
| 663 | // tmp = [r_ptr] - expected; |
| 664 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 665 | |
| 666 | Mips64Label loop_head, exit_loop; |
| 667 | __ Bind(&loop_head); |
| 668 | __ Ll(tmp, tmp_ptr); |
| 669 | // The LL instruction sign-extends the 32-bit value, but |
| 670 | // 32-bit references must be zero-extended. Zero-extend `tmp`. |
| 671 | __ Dext(tmp, tmp, 0, 32); |
| 672 | __ Bnec(tmp, expected, &exit_loop); |
| 673 | __ Move(tmp, value); |
| 674 | __ Sc(tmp, tmp_ptr); |
| 675 | __ Beqzc(tmp, &loop_head); |
| 676 | __ Bind(&exit_loop); |
| 677 | |
| 678 | if (kPoisonHeapReferences) { |
| 679 | __ UnpoisonHeapReference(expected); |
| 680 | // Do not unpoison `value` if it is the same register as |
| 681 | // `expected`, which has just been unpoisoned. |
| 682 | if (value != expected) { |
| 683 | __ UnpoisonHeapReference(value); |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | __ Bind(&done); |
| 688 | __ Bc(GetExitLabel()); |
| 689 | } |
| 690 | |
| 691 | private: |
| 692 | // The location (register) of the marked object reference. |
| 693 | const Location ref_; |
| 694 | // The register containing the object holding the marked object reference field. |
| 695 | const GpuRegister obj_; |
| 696 | // The location of the offset of the marked reference field within `obj_`. |
| 697 | Location field_offset_; |
| 698 | |
| 699 | const GpuRegister temp1_; |
| 700 | |
| 701 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathMIPS64); |
| 702 | }; |
| 703 | |
| 704 | // Slow path generating a read barrier for a heap reference. |
| 705 | class ReadBarrierForHeapReferenceSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 706 | public: |
| 707 | ReadBarrierForHeapReferenceSlowPathMIPS64(HInstruction* instruction, |
| 708 | Location out, |
| 709 | Location ref, |
| 710 | Location obj, |
| 711 | uint32_t offset, |
| 712 | Location index) |
| 713 | : SlowPathCodeMIPS64(instruction), |
| 714 | out_(out), |
| 715 | ref_(ref), |
| 716 | obj_(obj), |
| 717 | offset_(offset), |
| 718 | index_(index) { |
| 719 | DCHECK(kEmitCompilerReadBarrier); |
| 720 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 721 | // has been overwritten by (or after) the heap object reference load |
| 722 | // to be instrumented, e.g.: |
| 723 | // |
| 724 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 725 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 726 | // |
| 727 | // In that case, we have lost the information about the original |
| 728 | // object, and the emitted read barrier cannot work properly. |
| 729 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 730 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 731 | } |
| 732 | |
| 733 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 734 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 735 | LocationSummary* locations = instruction_->GetLocations(); |
| 736 | Primitive::Type type = Primitive::kPrimNot; |
| 737 | GpuRegister reg_out = out_.AsRegister<GpuRegister>(); |
| 738 | DCHECK(locations->CanCall()); |
| 739 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 740 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 741 | instruction_->IsStaticFieldGet() || |
| 742 | instruction_->IsArrayGet() || |
| 743 | instruction_->IsInstanceOf() || |
| 744 | instruction_->IsCheckCast() || |
| 745 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 746 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 747 | << instruction_->DebugName(); |
| 748 | |
| 749 | __ Bind(GetEntryLabel()); |
| 750 | SaveLiveRegisters(codegen, locations); |
| 751 | |
| 752 | // We may have to change the index's value, but as `index_` is a |
| 753 | // constant member (like other "inputs" of this slow path), |
| 754 | // introduce a copy of it, `index`. |
| 755 | Location index = index_; |
| 756 | if (index_.IsValid()) { |
| 757 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 758 | if (instruction_->IsArrayGet()) { |
| 759 | // Compute the actual memory offset and store it in `index`. |
| 760 | GpuRegister index_reg = index_.AsRegister<GpuRegister>(); |
| 761 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 762 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 763 | // We are about to change the value of `index_reg` (see the |
| 764 | // calls to art::mips64::Mips64Assembler::Sll and |
| 765 | // art::mips64::MipsAssembler::Addiu32 below), but it has |
| 766 | // not been saved by the previous call to |
| 767 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 768 | // callee-save register -- |
| 769 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 770 | // callee-save registers, as it has been designed with the |
| 771 | // assumption that callee-save registers are supposed to be |
| 772 | // handled by the called function. So, as a callee-save |
| 773 | // register, `index_reg` _would_ eventually be saved onto |
| 774 | // the stack, but it would be too late: we would have |
| 775 | // changed its value earlier. Therefore, we manually save |
| 776 | // it here into another freely available register, |
| 777 | // `free_reg`, chosen of course among the caller-save |
| 778 | // registers (as a callee-save `free_reg` register would |
| 779 | // exhibit the same problem). |
| 780 | // |
| 781 | // Note we could have requested a temporary register from |
| 782 | // the register allocator instead; but we prefer not to, as |
| 783 | // this is a slow path, and we know we can find a |
| 784 | // caller-save register that is available. |
| 785 | GpuRegister free_reg = FindAvailableCallerSaveRegister(codegen); |
| 786 | __ Move(free_reg, index_reg); |
| 787 | index_reg = free_reg; |
| 788 | index = Location::RegisterLocation(index_reg); |
| 789 | } else { |
| 790 | // The initial register stored in `index_` has already been |
| 791 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 792 | // (as it is not a callee-save register), so we can freely |
| 793 | // use it. |
| 794 | } |
| 795 | // Shifting the index value contained in `index_reg` by the scale |
| 796 | // factor (2) cannot overflow in practice, as the runtime is |
| 797 | // unable to allocate object arrays with a size larger than |
| 798 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 799 | __ Sll(index_reg, index_reg, TIMES_4); |
| 800 | static_assert( |
| 801 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 802 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 803 | __ Addiu32(index_reg, index_reg, offset_); |
| 804 | } else { |
| 805 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 806 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 807 | // (as in the case of ArrayGet), as it is actually an offset |
| 808 | // to an object field within an object. |
| 809 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 810 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 811 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 812 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 813 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 814 | DCHECK_EQ(offset_, 0U); |
| 815 | DCHECK(index_.IsRegister()); |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | // We're moving two or three locations to locations that could |
| 820 | // overlap, so we need a parallel move resolver. |
| 821 | InvokeRuntimeCallingConvention calling_convention; |
| 822 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 823 | parallel_move.AddMove(ref_, |
| 824 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 825 | Primitive::kPrimNot, |
| 826 | nullptr); |
| 827 | parallel_move.AddMove(obj_, |
| 828 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 829 | Primitive::kPrimNot, |
| 830 | nullptr); |
| 831 | if (index.IsValid()) { |
| 832 | parallel_move.AddMove(index, |
| 833 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 834 | Primitive::kPrimInt, |
| 835 | nullptr); |
| 836 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 837 | } else { |
| 838 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 839 | __ LoadConst32(calling_convention.GetRegisterAt(2), offset_); |
| 840 | } |
| 841 | mips64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
| 842 | instruction_, |
| 843 | instruction_->GetDexPc(), |
| 844 | this); |
| 845 | CheckEntrypointTypes< |
| 846 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 847 | mips64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 848 | |
| 849 | RestoreLiveRegisters(codegen, locations); |
| 850 | __ Bc(GetExitLabel()); |
| 851 | } |
| 852 | |
| 853 | const char* GetDescription() const OVERRIDE { |
| 854 | return "ReadBarrierForHeapReferenceSlowPathMIPS64"; |
| 855 | } |
| 856 | |
| 857 | private: |
| 858 | GpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 859 | size_t ref = static_cast<int>(ref_.AsRegister<GpuRegister>()); |
| 860 | size_t obj = static_cast<int>(obj_.AsRegister<GpuRegister>()); |
| 861 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 862 | if (i != ref && |
| 863 | i != obj && |
| 864 | !codegen->IsCoreCalleeSaveRegister(i) && |
| 865 | !codegen->IsBlockedCoreRegister(i)) { |
| 866 | return static_cast<GpuRegister>(i); |
| 867 | } |
| 868 | } |
| 869 | // We shall never fail to find a free caller-save register, as |
| 870 | // there are more than two core caller-save registers on MIPS64 |
| 871 | // (meaning it is possible to find one which is different from |
| 872 | // `ref` and `obj`). |
| 873 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 874 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 875 | UNREACHABLE(); |
| 876 | } |
| 877 | |
| 878 | const Location out_; |
| 879 | const Location ref_; |
| 880 | const Location obj_; |
| 881 | const uint32_t offset_; |
| 882 | // An additional location containing an index to an array. |
| 883 | // Only used for HArrayGet and the UnsafeGetObject & |
| 884 | // UnsafeGetObjectVolatile intrinsics. |
| 885 | const Location index_; |
| 886 | |
| 887 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathMIPS64); |
| 888 | }; |
| 889 | |
| 890 | // Slow path generating a read barrier for a GC root. |
| 891 | class ReadBarrierForRootSlowPathMIPS64 : public SlowPathCodeMIPS64 { |
| 892 | public: |
| 893 | ReadBarrierForRootSlowPathMIPS64(HInstruction* instruction, Location out, Location root) |
| 894 | : SlowPathCodeMIPS64(instruction), out_(out), root_(root) { |
| 895 | DCHECK(kEmitCompilerReadBarrier); |
| 896 | } |
| 897 | |
| 898 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 899 | LocationSummary* locations = instruction_->GetLocations(); |
| 900 | Primitive::Type type = Primitive::kPrimNot; |
| 901 | GpuRegister reg_out = out_.AsRegister<GpuRegister>(); |
| 902 | DCHECK(locations->CanCall()); |
| 903 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 904 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 905 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 906 | << instruction_->DebugName(); |
| 907 | |
| 908 | __ Bind(GetEntryLabel()); |
| 909 | SaveLiveRegisters(codegen, locations); |
| 910 | |
| 911 | InvokeRuntimeCallingConvention calling_convention; |
| 912 | CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); |
| 913 | mips64_codegen->MoveLocation(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 914 | root_, |
| 915 | Primitive::kPrimNot); |
| 916 | mips64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 917 | instruction_, |
| 918 | instruction_->GetDexPc(), |
| 919 | this); |
| 920 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 921 | mips64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 922 | |
| 923 | RestoreLiveRegisters(codegen, locations); |
| 924 | __ Bc(GetExitLabel()); |
| 925 | } |
| 926 | |
| 927 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathMIPS64"; } |
| 928 | |
| 929 | private: |
| 930 | const Location out_; |
| 931 | const Location root_; |
| 932 | |
| 933 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathMIPS64); |
| 934 | }; |
| 935 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 936 | CodeGeneratorMIPS64::CodeGeneratorMIPS64(HGraph* graph, |
| 937 | const Mips64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 938 | const CompilerOptions& compiler_options, |
| 939 | OptimizingCompilerStats* stats) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 940 | : CodeGenerator(graph, |
| 941 | kNumberOfGpuRegisters, |
| 942 | kNumberOfFpuRegisters, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 943 | /* number_of_register_pairs */ 0, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 944 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 945 | arraysize(kCoreCalleeSaves)), |
| 946 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 947 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 948 | compiler_options, |
| 949 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 950 | block_labels_(nullptr), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 951 | location_builder_(graph, this), |
| 952 | instruction_visitor_(graph, this), |
| 953 | move_resolver_(graph->GetArena(), this), |
Goran Jakovljevic | 19680d3 | 2017-05-11 10:38:36 +0200 | [diff] [blame] | 954 | assembler_(graph->GetArena(), &isa_features), |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 955 | isa_features_(isa_features), |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 956 | uint32_literals_(std::less<uint32_t>(), |
| 957 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 958 | uint64_literals_(std::less<uint64_t>(), |
| 959 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 960 | pc_relative_method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 961 | method_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 962 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 963 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 964 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 965 | jit_string_patches_(StringReferenceValueComparator(), |
| 966 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 967 | jit_class_patches_(TypeReferenceValueComparator(), |
| 968 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 969 | // Save RA (containing the return address) to mimic Quick. |
| 970 | AddAllocatedRegister(Location::RegisterLocation(RA)); |
| 971 | } |
| 972 | |
| 973 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 974 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 975 | #define __ down_cast<Mips64Assembler*>(GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 976 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, x).Int32Value() |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 977 | |
| 978 | void CodeGeneratorMIPS64::Finalize(CodeAllocator* allocator) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 979 | // Ensure that we fix up branches. |
| 980 | __ FinalizeCode(); |
| 981 | |
| 982 | // Adjust native pc offsets in stack maps. |
| 983 | 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] | 984 | uint32_t old_position = |
| 985 | stack_map_stream_.GetStackMap(i).native_pc_code_offset.Uint32Value(kMips64); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 986 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 987 | DCHECK_GE(new_position, old_position); |
| 988 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 989 | } |
| 990 | |
| 991 | // Adjust pc offsets for the disassembly information. |
| 992 | if (disasm_info_ != nullptr) { |
| 993 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 994 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 995 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 996 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 997 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 998 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 999 | } |
| 1000 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1001 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1002 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1003 | } |
| 1004 | } |
| 1005 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1006 | CodeGenerator::Finalize(allocator); |
| 1007 | } |
| 1008 | |
| 1009 | Mips64Assembler* ParallelMoveResolverMIPS64::GetAssembler() const { |
| 1010 | return codegen_->GetAssembler(); |
| 1011 | } |
| 1012 | |
| 1013 | void ParallelMoveResolverMIPS64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1014 | MoveOperands* move = moves_[index]; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1015 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); |
| 1016 | } |
| 1017 | |
| 1018 | void ParallelMoveResolverMIPS64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1019 | MoveOperands* move = moves_[index]; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1020 | codegen_->SwapLocations(move->GetDestination(), move->GetSource(), move->GetType()); |
| 1021 | } |
| 1022 | |
| 1023 | void ParallelMoveResolverMIPS64::RestoreScratch(int reg) { |
| 1024 | // Pop reg |
| 1025 | __ Ld(GpuRegister(reg), SP, 0); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1026 | __ DecreaseFrameSize(kMips64DoublewordSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | void ParallelMoveResolverMIPS64::SpillScratch(int reg) { |
| 1030 | // Push reg |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1031 | __ IncreaseFrameSize(kMips64DoublewordSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1032 | __ Sd(GpuRegister(reg), SP, 0); |
| 1033 | } |
| 1034 | |
| 1035 | void ParallelMoveResolverMIPS64::Exchange(int index1, int index2, bool double_slot) { |
| 1036 | LoadOperandType load_type = double_slot ? kLoadDoubleword : kLoadWord; |
| 1037 | StoreOperandType store_type = double_slot ? kStoreDoubleword : kStoreWord; |
| 1038 | // Allocate a scratch register other than TMP, if available. |
| 1039 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be |
| 1040 | // automatically unspilled when the scratch scope object is destroyed). |
| 1041 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); |
| 1042 | // 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] | 1043 | int stack_offset = ensure_scratch.IsSpilled() ? kMips64DoublewordSize : 0; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1044 | __ LoadFromOffset(load_type, |
| 1045 | GpuRegister(ensure_scratch.GetRegister()), |
| 1046 | SP, |
| 1047 | index1 + stack_offset); |
| 1048 | __ LoadFromOffset(load_type, |
| 1049 | TMP, |
| 1050 | SP, |
| 1051 | index2 + stack_offset); |
| 1052 | __ StoreToOffset(store_type, |
| 1053 | GpuRegister(ensure_scratch.GetRegister()), |
| 1054 | SP, |
| 1055 | index2 + stack_offset); |
| 1056 | __ StoreToOffset(store_type, TMP, SP, index1 + stack_offset); |
| 1057 | } |
| 1058 | |
| 1059 | static dwarf::Reg DWARFReg(GpuRegister reg) { |
| 1060 | return dwarf::Reg::Mips64Core(static_cast<int>(reg)); |
| 1061 | } |
| 1062 | |
David Srbecky | ba70200 | 2016-02-01 18:15:29 +0000 | [diff] [blame] | 1063 | static dwarf::Reg DWARFReg(FpuRegister reg) { |
| 1064 | return dwarf::Reg::Mips64Fp(static_cast<int>(reg)); |
| 1065 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1066 | |
| 1067 | void CodeGeneratorMIPS64::GenerateFrameEntry() { |
| 1068 | __ Bind(&frame_entry_label_); |
| 1069 | |
| 1070 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips64) || !IsLeafMethod(); |
| 1071 | |
| 1072 | if (do_overflow_check) { |
| 1073 | __ LoadFromOffset(kLoadWord, |
| 1074 | ZERO, |
| 1075 | SP, |
| 1076 | -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips64))); |
| 1077 | RecordPcInfo(nullptr, 0); |
| 1078 | } |
| 1079 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1080 | if (HasEmptyFrame()) { |
| 1081 | return; |
| 1082 | } |
| 1083 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1084 | // Make sure the frame size isn't unreasonably large. |
| 1085 | if (GetFrameSize() > GetStackOverflowReservedBytes(kMips64)) { |
| 1086 | LOG(FATAL) << "Stack frame larger than " << GetStackOverflowReservedBytes(kMips64) << " bytes"; |
| 1087 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1088 | |
| 1089 | // Spill callee-saved registers. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1090 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1091 | uint32_t ofs = GetFrameSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1092 | __ IncreaseFrameSize(ofs); |
| 1093 | |
| 1094 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1095 | GpuRegister reg = kCoreCalleeSaves[i]; |
| 1096 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1097 | ofs -= kMips64DoublewordSize; |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1098 | __ StoreToOffset(kStoreDoubleword, reg, SP, ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1099 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1104 | FpuRegister reg = kFpuCalleeSaves[i]; |
| 1105 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1106 | ofs -= kMips64DoublewordSize; |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1107 | __ StoreFpuToOffset(kStoreDoubleword, reg, SP, ofs); |
David Srbecky | ba70200 | 2016-02-01 18:15:29 +0000 | [diff] [blame] | 1108 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1109 | } |
| 1110 | } |
| 1111 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1112 | // Save the current method if we need it. Note that we do not |
| 1113 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1114 | // in the SSA graph. |
| 1115 | if (RequiresCurrentMethod()) { |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1116 | __ StoreToOffset(kStoreDoubleword, kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1117 | } |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 1118 | |
| 1119 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1120 | // Initialize should_deoptimize flag to 0. |
| 1121 | __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 1122 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | void CodeGeneratorMIPS64::GenerateFrameExit() { |
| 1126 | __ cfi().RememberState(); |
| 1127 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1128 | if (!HasEmptyFrame()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1129 | // Restore callee-saved registers. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1130 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1131 | // For better instruction scheduling restore RA before other registers. |
| 1132 | uint32_t ofs = GetFrameSize(); |
| 1133 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1134 | GpuRegister reg = kCoreCalleeSaves[i]; |
| 1135 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1136 | ofs -= kMips64DoublewordSize; |
| 1137 | __ LoadFromOffset(kLoadDoubleword, reg, SP, ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1138 | __ cfi().Restore(DWARFReg(reg)); |
| 1139 | } |
| 1140 | } |
| 1141 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1142 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1143 | FpuRegister reg = kFpuCalleeSaves[i]; |
| 1144 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
| 1145 | ofs -= kMips64DoublewordSize; |
| 1146 | __ LoadFpuFromOffset(kLoadDoubleword, reg, SP, ofs); |
| 1147 | __ cfi().Restore(DWARFReg(reg)); |
| 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | __ DecreaseFrameSize(GetFrameSize()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1152 | } |
| 1153 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1154 | __ Jic(RA, 0); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1155 | |
| 1156 | __ cfi().RestoreState(); |
| 1157 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 1158 | } |
| 1159 | |
| 1160 | void CodeGeneratorMIPS64::Bind(HBasicBlock* block) { |
| 1161 | __ Bind(GetLabelOf(block)); |
| 1162 | } |
| 1163 | |
| 1164 | void CodeGeneratorMIPS64::MoveLocation(Location destination, |
| 1165 | Location source, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1166 | Primitive::Type dst_type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1167 | if (source.Equals(destination)) { |
| 1168 | return; |
| 1169 | } |
| 1170 | |
| 1171 | // A valid move can always be inferred from the destination and source |
| 1172 | // locations. When moving from and to a register, the argument type can be |
| 1173 | // used to generate 32bit instead of 64bit moves. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1174 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1175 | DCHECK_EQ(unspecified_type, false); |
| 1176 | |
| 1177 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1178 | if (unspecified_type) { |
| 1179 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1180 | if (source.IsStackSlot() || |
| 1181 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1182 | || src_cst->IsFloatConstant() |
| 1183 | || src_cst->IsNullConstant()))) { |
| 1184 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1185 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1186 | } else { |
| 1187 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1188 | // type is appropriate. Else the source is a register, and since the |
| 1189 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1190 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1191 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1192 | } |
| 1193 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1194 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 1195 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1196 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1197 | // Move to GPR/FPR from stack |
| 1198 | LoadOperandType load_type = source.IsStackSlot() ? kLoadWord : kLoadDoubleword; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1199 | if (Primitive::IsFloatingPointType(dst_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1200 | __ LoadFpuFromOffset(load_type, |
| 1201 | destination.AsFpuRegister<FpuRegister>(), |
| 1202 | SP, |
| 1203 | source.GetStackIndex()); |
| 1204 | } else { |
| 1205 | // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot. |
| 1206 | __ LoadFromOffset(load_type, |
| 1207 | destination.AsRegister<GpuRegister>(), |
| 1208 | SP, |
| 1209 | source.GetStackIndex()); |
| 1210 | } |
| 1211 | } else if (source.IsConstant()) { |
| 1212 | // Move to GPR/FPR from constant |
| 1213 | GpuRegister gpr = AT; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1214 | if (!Primitive::IsFloatingPointType(dst_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1215 | gpr = destination.AsRegister<GpuRegister>(); |
| 1216 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1217 | if (dst_type == Primitive::kPrimInt || dst_type == Primitive::kPrimFloat) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1218 | int32_t value = GetInt32ValueOf(source.GetConstant()->AsConstant()); |
| 1219 | if (Primitive::IsFloatingPointType(dst_type) && value == 0) { |
| 1220 | gpr = ZERO; |
| 1221 | } else { |
| 1222 | __ LoadConst32(gpr, value); |
| 1223 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1224 | } else { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1225 | int64_t value = GetInt64ValueOf(source.GetConstant()->AsConstant()); |
| 1226 | if (Primitive::IsFloatingPointType(dst_type) && value == 0) { |
| 1227 | gpr = ZERO; |
| 1228 | } else { |
| 1229 | __ LoadConst64(gpr, value); |
| 1230 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1231 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1232 | if (dst_type == Primitive::kPrimFloat) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1233 | __ Mtc1(gpr, destination.AsFpuRegister<FpuRegister>()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1234 | } else if (dst_type == Primitive::kPrimDouble) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1235 | __ Dmtc1(gpr, destination.AsFpuRegister<FpuRegister>()); |
| 1236 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1237 | } else if (source.IsRegister()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1238 | if (destination.IsRegister()) { |
| 1239 | // Move to GPR from GPR |
| 1240 | __ Move(destination.AsRegister<GpuRegister>(), source.AsRegister<GpuRegister>()); |
| 1241 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1242 | DCHECK(destination.IsFpuRegister()); |
| 1243 | if (Primitive::Is64BitType(dst_type)) { |
| 1244 | __ Dmtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>()); |
| 1245 | } else { |
| 1246 | __ Mtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>()); |
| 1247 | } |
| 1248 | } |
| 1249 | } else if (source.IsFpuRegister()) { |
| 1250 | if (destination.IsFpuRegister()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1251 | // Move to FPR from FPR |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1252 | if (dst_type == Primitive::kPrimFloat) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1253 | __ MovS(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1254 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1255 | DCHECK_EQ(dst_type, Primitive::kPrimDouble); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1256 | __ MovD(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1257 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1258 | } else { |
| 1259 | DCHECK(destination.IsRegister()); |
| 1260 | if (Primitive::Is64BitType(dst_type)) { |
| 1261 | __ Dmfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1262 | } else { |
| 1263 | __ Mfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1264 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1265 | } |
| 1266 | } |
| 1267 | } else { // The destination is not a register. It must be a stack slot. |
| 1268 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1269 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1270 | if (unspecified_type) { |
| 1271 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1272 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1273 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1274 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1275 | } |
| 1276 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1277 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 1278 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1279 | // Move to stack from GPR/FPR |
| 1280 | StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
| 1281 | if (source.IsRegister()) { |
| 1282 | __ StoreToOffset(store_type, |
| 1283 | source.AsRegister<GpuRegister>(), |
| 1284 | SP, |
| 1285 | destination.GetStackIndex()); |
| 1286 | } else { |
| 1287 | __ StoreFpuToOffset(store_type, |
| 1288 | source.AsFpuRegister<FpuRegister>(), |
| 1289 | SP, |
| 1290 | destination.GetStackIndex()); |
| 1291 | } |
| 1292 | } else if (source.IsConstant()) { |
| 1293 | // Move to stack from constant |
| 1294 | HConstant* src_cst = source.GetConstant(); |
| 1295 | StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1296 | GpuRegister gpr = ZERO; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1297 | if (destination.IsStackSlot()) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1298 | int32_t value = GetInt32ValueOf(src_cst->AsConstant()); |
| 1299 | if (value != 0) { |
| 1300 | gpr = TMP; |
| 1301 | __ LoadConst32(gpr, value); |
| 1302 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1303 | } else { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1304 | DCHECK(destination.IsDoubleStackSlot()); |
| 1305 | int64_t value = GetInt64ValueOf(src_cst->AsConstant()); |
| 1306 | if (value != 0) { |
| 1307 | gpr = TMP; |
| 1308 | __ LoadConst64(gpr, value); |
| 1309 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1310 | } |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1311 | __ StoreToOffset(store_type, gpr, SP, destination.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1312 | } else { |
| 1313 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
| 1314 | DCHECK_EQ(source.IsDoubleStackSlot(), destination.IsDoubleStackSlot()); |
| 1315 | // Move to stack from stack |
| 1316 | if (destination.IsStackSlot()) { |
| 1317 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 1318 | __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex()); |
| 1319 | } else { |
| 1320 | __ LoadFromOffset(kLoadDoubleword, TMP, SP, source.GetStackIndex()); |
| 1321 | __ StoreToOffset(kStoreDoubleword, TMP, SP, destination.GetStackIndex()); |
| 1322 | } |
| 1323 | } |
| 1324 | } |
| 1325 | } |
| 1326 | |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1327 | void CodeGeneratorMIPS64::SwapLocations(Location loc1, Location loc2, Primitive::Type type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1328 | DCHECK(!loc1.IsConstant()); |
| 1329 | DCHECK(!loc2.IsConstant()); |
| 1330 | |
| 1331 | if (loc1.Equals(loc2)) { |
| 1332 | return; |
| 1333 | } |
| 1334 | |
| 1335 | bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot(); |
| 1336 | bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot(); |
| 1337 | bool is_fp_reg1 = loc1.IsFpuRegister(); |
| 1338 | bool is_fp_reg2 = loc2.IsFpuRegister(); |
| 1339 | |
| 1340 | if (loc2.IsRegister() && loc1.IsRegister()) { |
| 1341 | // Swap 2 GPRs |
| 1342 | GpuRegister r1 = loc1.AsRegister<GpuRegister>(); |
| 1343 | GpuRegister r2 = loc2.AsRegister<GpuRegister>(); |
| 1344 | __ Move(TMP, r2); |
| 1345 | __ Move(r2, r1); |
| 1346 | __ Move(r1, TMP); |
| 1347 | } else if (is_fp_reg2 && is_fp_reg1) { |
| 1348 | // Swap 2 FPRs |
| 1349 | FpuRegister r1 = loc1.AsFpuRegister<FpuRegister>(); |
| 1350 | FpuRegister r2 = loc2.AsFpuRegister<FpuRegister>(); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1351 | if (type == Primitive::kPrimFloat) { |
| 1352 | __ MovS(FTMP, r1); |
| 1353 | __ MovS(r1, r2); |
| 1354 | __ MovS(r2, FTMP); |
| 1355 | } else { |
| 1356 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1357 | __ MovD(FTMP, r1); |
| 1358 | __ MovD(r1, r2); |
| 1359 | __ MovD(r2, FTMP); |
| 1360 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1361 | } else if (is_slot1 != is_slot2) { |
| 1362 | // Swap GPR/FPR and stack slot |
| 1363 | Location reg_loc = is_slot1 ? loc2 : loc1; |
| 1364 | Location mem_loc = is_slot1 ? loc1 : loc2; |
| 1365 | LoadOperandType load_type = mem_loc.IsStackSlot() ? kLoadWord : kLoadDoubleword; |
| 1366 | StoreOperandType store_type = mem_loc.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
| 1367 | // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot. |
| 1368 | __ LoadFromOffset(load_type, TMP, SP, mem_loc.GetStackIndex()); |
| 1369 | if (reg_loc.IsFpuRegister()) { |
| 1370 | __ StoreFpuToOffset(store_type, |
| 1371 | reg_loc.AsFpuRegister<FpuRegister>(), |
| 1372 | SP, |
| 1373 | mem_loc.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1374 | if (mem_loc.IsStackSlot()) { |
| 1375 | __ Mtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>()); |
| 1376 | } else { |
| 1377 | DCHECK(mem_loc.IsDoubleStackSlot()); |
| 1378 | __ Dmtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>()); |
| 1379 | } |
| 1380 | } else { |
| 1381 | __ StoreToOffset(store_type, reg_loc.AsRegister<GpuRegister>(), SP, mem_loc.GetStackIndex()); |
| 1382 | __ Move(reg_loc.AsRegister<GpuRegister>(), TMP); |
| 1383 | } |
| 1384 | } else if (is_slot1 && is_slot2) { |
| 1385 | move_resolver_.Exchange(loc1.GetStackIndex(), |
| 1386 | loc2.GetStackIndex(), |
| 1387 | loc1.IsDoubleStackSlot()); |
| 1388 | } else { |
| 1389 | LOG(FATAL) << "Unimplemented swap between locations " << loc1 << " and " << loc2; |
| 1390 | } |
| 1391 | } |
| 1392 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1393 | void CodeGeneratorMIPS64::MoveConstant(Location location, int32_t value) { |
| 1394 | DCHECK(location.IsRegister()); |
| 1395 | __ LoadConst32(location.AsRegister<GpuRegister>(), value); |
| 1396 | } |
| 1397 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1398 | void CodeGeneratorMIPS64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1399 | if (location.IsRegister()) { |
| 1400 | locations->AddTemp(location); |
| 1401 | } else { |
| 1402 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1403 | } |
| 1404 | } |
| 1405 | |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1406 | void CodeGeneratorMIPS64::MarkGCCard(GpuRegister object, |
| 1407 | GpuRegister value, |
| 1408 | bool value_can_be_null) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1409 | Mips64Label done; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1410 | GpuRegister card = AT; |
| 1411 | GpuRegister temp = TMP; |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1412 | if (value_can_be_null) { |
| 1413 | __ Beqzc(value, &done); |
| 1414 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1415 | __ LoadFromOffset(kLoadDoubleword, |
| 1416 | card, |
| 1417 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1418 | Thread::CardTableOffset<kMips64PointerSize>().Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1419 | __ Dsrl(temp, object, gc::accounting::CardTable::kCardShift); |
| 1420 | __ Daddu(temp, card, temp); |
| 1421 | __ Sb(card, temp, 0); |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1422 | if (value_can_be_null) { |
| 1423 | __ Bind(&done); |
| 1424 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1425 | } |
| 1426 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1427 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 1428 | inline void CodeGeneratorMIPS64::EmitPcRelativeLinkerPatches( |
| 1429 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 1430 | ArenaVector<LinkerPatch>* linker_patches) { |
| 1431 | for (const PcRelativePatchInfo& info : infos) { |
| 1432 | const DexFile& dex_file = info.target_dex_file; |
| 1433 | size_t offset_or_index = info.offset_or_index; |
| 1434 | DCHECK(info.pc_rel_label.IsBound()); |
| 1435 | uint32_t pc_rel_offset = __ GetLabelLocation(&info.pc_rel_label); |
| 1436 | linker_patches->push_back(Factory(pc_rel_offset, &dex_file, pc_rel_offset, offset_or_index)); |
| 1437 | } |
| 1438 | } |
| 1439 | |
| 1440 | void CodeGeneratorMIPS64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 1441 | DCHECK(linker_patches->empty()); |
| 1442 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1443 | pc_relative_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1444 | method_bss_entry_patches_.size() + |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1445 | pc_relative_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1446 | type_bss_entry_patches_.size() + |
| 1447 | pc_relative_string_patches_.size(); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1448 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1449 | if (GetCompilerOptions().IsBootImage()) { |
| 1450 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeMethodPatch>(pc_relative_method_patches_, |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1451 | linker_patches); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1452 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 1453 | linker_patches); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1454 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 1455 | linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1456 | } else { |
| 1457 | DCHECK(pc_relative_method_patches_.empty()); |
| 1458 | DCHECK(pc_relative_type_patches_.empty()); |
| 1459 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 1460 | linker_patches); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1461 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1462 | EmitPcRelativeLinkerPatches<LinkerPatch::MethodBssEntryPatch>(method_bss_entry_patches_, |
| 1463 | linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1464 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 1465 | linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1466 | DCHECK_EQ(size, linker_patches->size()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1467 | } |
| 1468 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1469 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeMethodPatch( |
| 1470 | MethodReference target_method) { |
| 1471 | return NewPcRelativePatch(*target_method.dex_file, |
| 1472 | target_method.dex_method_index, |
| 1473 | &pc_relative_method_patches_); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1474 | } |
| 1475 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1476 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewMethodBssEntryPatch( |
| 1477 | MethodReference target_method) { |
| 1478 | return NewPcRelativePatch(*target_method.dex_file, |
| 1479 | target_method.dex_method_index, |
| 1480 | &method_bss_entry_patches_); |
| 1481 | } |
| 1482 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1483 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeTypePatch( |
| 1484 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 1485 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1486 | } |
| 1487 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1488 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewTypeBssEntryPatch( |
| 1489 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 1490 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 1491 | } |
| 1492 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1493 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeStringPatch( |
| 1494 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 1495 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
| 1496 | } |
| 1497 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1498 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativePatch( |
| 1499 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 1500 | patches->emplace_back(dex_file, offset_or_index); |
| 1501 | return &patches->back(); |
| 1502 | } |
| 1503 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1504 | Literal* CodeGeneratorMIPS64::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 1505 | return map->GetOrCreate( |
| 1506 | value, |
| 1507 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
| 1508 | } |
| 1509 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1510 | Literal* CodeGeneratorMIPS64::DeduplicateUint64Literal(uint64_t value) { |
| 1511 | return uint64_literals_.GetOrCreate( |
| 1512 | value, |
| 1513 | [this, value]() { return __ NewLiteral<uint64_t>(value); }); |
| 1514 | } |
| 1515 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1516 | Literal* CodeGeneratorMIPS64::DeduplicateBootImageAddressLiteral(uint64_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 1517 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1518 | } |
| 1519 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1520 | void CodeGeneratorMIPS64::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info, |
| 1521 | GpuRegister out) { |
| 1522 | __ Bind(&info->pc_rel_label); |
| 1523 | // Add the high half of a 32-bit offset to PC. |
| 1524 | __ Auipc(out, /* placeholder */ 0x1234); |
| 1525 | // 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] | 1526 | // offset to `out` (e.g. ld, jialc, daddiu). |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1527 | } |
| 1528 | |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1529 | Literal* CodeGeneratorMIPS64::DeduplicateJitStringLiteral(const DexFile& dex_file, |
| 1530 | dex::StringIndex string_index, |
| 1531 | Handle<mirror::String> handle) { |
| 1532 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 1533 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
| 1534 | return jit_string_patches_.GetOrCreate( |
| 1535 | StringReference(&dex_file, string_index), |
| 1536 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1537 | } |
| 1538 | |
| 1539 | Literal* CodeGeneratorMIPS64::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 1540 | dex::TypeIndex type_index, |
| 1541 | Handle<mirror::Class> handle) { |
| 1542 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 1543 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
| 1544 | return jit_class_patches_.GetOrCreate( |
| 1545 | TypeReference(&dex_file, type_index), |
| 1546 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1547 | } |
| 1548 | |
| 1549 | void CodeGeneratorMIPS64::PatchJitRootUse(uint8_t* code, |
| 1550 | const uint8_t* roots_data, |
| 1551 | const Literal* literal, |
| 1552 | uint64_t index_in_table) const { |
| 1553 | uint32_t literal_offset = GetAssembler().GetLabelLocation(literal->GetLabel()); |
| 1554 | uintptr_t address = |
| 1555 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 1556 | reinterpret_cast<uint32_t*>(code + literal_offset)[0] = dchecked_integral_cast<uint32_t>(address); |
| 1557 | } |
| 1558 | |
| 1559 | void CodeGeneratorMIPS64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 1560 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1561 | const StringReference& string_reference = entry.first; |
| 1562 | Literal* table_entry_literal = entry.second; |
| 1563 | const auto it = jit_string_roots_.find(string_reference); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1564 | DCHECK(it != jit_string_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1565 | uint64_t index_in_table = it->second; |
| 1566 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1567 | } |
| 1568 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1569 | const TypeReference& type_reference = entry.first; |
| 1570 | Literal* table_entry_literal = entry.second; |
| 1571 | const auto it = jit_class_roots_.find(type_reference); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1572 | DCHECK(it != jit_class_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1573 | uint64_t index_in_table = it->second; |
| 1574 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1575 | } |
| 1576 | } |
| 1577 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1578 | void CodeGeneratorMIPS64::SetupBlockedRegisters() const { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1579 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1580 | blocked_core_registers_[ZERO] = true; |
| 1581 | blocked_core_registers_[K0] = true; |
| 1582 | blocked_core_registers_[K1] = true; |
| 1583 | blocked_core_registers_[GP] = true; |
| 1584 | blocked_core_registers_[SP] = true; |
| 1585 | blocked_core_registers_[RA] = true; |
| 1586 | |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1587 | // AT, TMP(T8) and TMP2(T3) are used as temporary/scratch |
| 1588 | // registers (similar to how AT is used by MIPS assemblers). |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1589 | blocked_core_registers_[AT] = true; |
| 1590 | blocked_core_registers_[TMP] = true; |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1591 | blocked_core_registers_[TMP2] = true; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1592 | blocked_fpu_registers_[FTMP] = true; |
| 1593 | |
| 1594 | // Reserve suspend and thread registers. |
| 1595 | blocked_core_registers_[S0] = true; |
| 1596 | blocked_core_registers_[TR] = true; |
| 1597 | |
| 1598 | // Reserve T9 for function calls |
| 1599 | blocked_core_registers_[T9] = true; |
| 1600 | |
Goran Jakovljevic | 782be11 | 2016-06-21 12:39:04 +0200 | [diff] [blame] | 1601 | if (GetGraph()->IsDebuggable()) { |
| 1602 | // Stubs do not save callee-save floating point registers. If the graph |
| 1603 | // is debuggable, we need to deal with these registers differently. For |
| 1604 | // now, just block them. |
| 1605 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1606 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1607 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1608 | } |
| 1609 | } |
| 1610 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1611 | size_t CodeGeneratorMIPS64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1612 | __ StoreToOffset(kStoreDoubleword, GpuRegister(reg_id), SP, stack_index); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1613 | return kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | size_t CodeGeneratorMIPS64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1617 | __ LoadFromOffset(kLoadDoubleword, GpuRegister(reg_id), SP, stack_index); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1618 | return kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | size_t CodeGeneratorMIPS64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1622 | __ StoreFpuToOffset(GetGraph()->HasSIMD() ? kStoreQuadword : kStoreDoubleword, |
| 1623 | FpuRegister(reg_id), |
| 1624 | SP, |
| 1625 | stack_index); |
| 1626 | return GetFloatingPointSpillSlotSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | size_t CodeGeneratorMIPS64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1630 | __ LoadFpuFromOffset(GetGraph()->HasSIMD() ? kLoadQuadword : kLoadDoubleword, |
| 1631 | FpuRegister(reg_id), |
| 1632 | SP, |
| 1633 | stack_index); |
| 1634 | return GetFloatingPointSpillSlotSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1635 | } |
| 1636 | |
| 1637 | void CodeGeneratorMIPS64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 1638 | stream << GpuRegister(reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | void CodeGeneratorMIPS64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 1642 | stream << FpuRegister(reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1643 | } |
| 1644 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1645 | void CodeGeneratorMIPS64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1646 | HInstruction* instruction, |
| 1647 | uint32_t dex_pc, |
| 1648 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1649 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1650 | GenerateInvokeRuntime(GetThreadOffset<kMips64PointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 1651 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1652 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1653 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1654 | } |
| 1655 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1656 | void CodeGeneratorMIPS64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1657 | HInstruction* instruction, |
| 1658 | SlowPathCode* slow_path) { |
| 1659 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| 1660 | GenerateInvokeRuntime(entry_point_offset); |
| 1661 | } |
| 1662 | |
| 1663 | void CodeGeneratorMIPS64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
| 1664 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
| 1665 | __ Jalr(T9); |
| 1666 | __ Nop(); |
| 1667 | } |
| 1668 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1669 | void InstructionCodeGeneratorMIPS64::GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path, |
| 1670 | GpuRegister class_reg) { |
| 1671 | __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 1672 | __ LoadConst32(AT, mirror::Class::kStatusInitialized); |
| 1673 | __ Bltc(TMP, AT, slow_path->GetEntryLabel()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1674 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 1675 | __ Sync(0); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1676 | __ Bind(slow_path->GetExitLabel()); |
| 1677 | } |
| 1678 | |
| 1679 | void InstructionCodeGeneratorMIPS64::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1680 | __ Sync(0); // only stype 0 is supported |
| 1681 | } |
| 1682 | |
| 1683 | void InstructionCodeGeneratorMIPS64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1684 | HBasicBlock* successor) { |
| 1685 | SuspendCheckSlowPathMIPS64* slow_path = |
| 1686 | new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS64(instruction, successor); |
| 1687 | codegen_->AddSlowPath(slow_path); |
| 1688 | |
| 1689 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1690 | TMP, |
| 1691 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1692 | Thread::ThreadFlagsOffset<kMips64PointerSize>().Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1693 | if (successor == nullptr) { |
| 1694 | __ Bnezc(TMP, slow_path->GetEntryLabel()); |
| 1695 | __ Bind(slow_path->GetReturnLabel()); |
| 1696 | } else { |
| 1697 | __ Beqzc(TMP, codegen_->GetLabelOf(successor)); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1698 | __ Bc(slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1699 | // slow_path will return to GetLabelOf(successor). |
| 1700 | } |
| 1701 | } |
| 1702 | |
| 1703 | InstructionCodeGeneratorMIPS64::InstructionCodeGeneratorMIPS64(HGraph* graph, |
| 1704 | CodeGeneratorMIPS64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1705 | : InstructionCodeGenerator(graph, codegen), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1706 | assembler_(codegen->GetAssembler()), |
| 1707 | codegen_(codegen) {} |
| 1708 | |
| 1709 | void LocationsBuilderMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1710 | DCHECK_EQ(instruction->InputCount(), 2U); |
| 1711 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1712 | Primitive::Type type = instruction->GetResultType(); |
| 1713 | switch (type) { |
| 1714 | case Primitive::kPrimInt: |
| 1715 | case Primitive::kPrimLong: { |
| 1716 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1717 | HInstruction* right = instruction->InputAt(1); |
| 1718 | bool can_use_imm = false; |
| 1719 | if (right->IsConstant()) { |
| 1720 | int64_t imm = CodeGenerator::GetInt64ValueOf(right->AsConstant()); |
| 1721 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 1722 | can_use_imm = IsUint<16>(imm); |
| 1723 | } else if (instruction->IsAdd()) { |
| 1724 | can_use_imm = IsInt<16>(imm); |
| 1725 | } else { |
| 1726 | DCHECK(instruction->IsSub()); |
| 1727 | can_use_imm = IsInt<16>(-imm); |
| 1728 | } |
| 1729 | } |
| 1730 | if (can_use_imm) |
| 1731 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 1732 | else |
| 1733 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1734 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1735 | } |
| 1736 | break; |
| 1737 | |
| 1738 | case Primitive::kPrimFloat: |
| 1739 | case Primitive::kPrimDouble: |
| 1740 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1741 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1742 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1743 | break; |
| 1744 | |
| 1745 | default: |
| 1746 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 1747 | } |
| 1748 | } |
| 1749 | |
| 1750 | void InstructionCodeGeneratorMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1751 | Primitive::Type type = instruction->GetType(); |
| 1752 | LocationSummary* locations = instruction->GetLocations(); |
| 1753 | |
| 1754 | switch (type) { |
| 1755 | case Primitive::kPrimInt: |
| 1756 | case Primitive::kPrimLong: { |
| 1757 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 1758 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1759 | Location rhs_location = locations->InAt(1); |
| 1760 | |
| 1761 | GpuRegister rhs_reg = ZERO; |
| 1762 | int64_t rhs_imm = 0; |
| 1763 | bool use_imm = rhs_location.IsConstant(); |
| 1764 | if (use_imm) { |
| 1765 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 1766 | } else { |
| 1767 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 1768 | } |
| 1769 | |
| 1770 | if (instruction->IsAnd()) { |
| 1771 | if (use_imm) |
| 1772 | __ Andi(dst, lhs, rhs_imm); |
| 1773 | else |
| 1774 | __ And(dst, lhs, rhs_reg); |
| 1775 | } else if (instruction->IsOr()) { |
| 1776 | if (use_imm) |
| 1777 | __ Ori(dst, lhs, rhs_imm); |
| 1778 | else |
| 1779 | __ Or(dst, lhs, rhs_reg); |
| 1780 | } else if (instruction->IsXor()) { |
| 1781 | if (use_imm) |
| 1782 | __ Xori(dst, lhs, rhs_imm); |
| 1783 | else |
| 1784 | __ Xor(dst, lhs, rhs_reg); |
| 1785 | } else if (instruction->IsAdd()) { |
| 1786 | if (type == Primitive::kPrimInt) { |
| 1787 | if (use_imm) |
| 1788 | __ Addiu(dst, lhs, rhs_imm); |
| 1789 | else |
| 1790 | __ Addu(dst, lhs, rhs_reg); |
| 1791 | } else { |
| 1792 | if (use_imm) |
| 1793 | __ Daddiu(dst, lhs, rhs_imm); |
| 1794 | else |
| 1795 | __ Daddu(dst, lhs, rhs_reg); |
| 1796 | } |
| 1797 | } else { |
| 1798 | DCHECK(instruction->IsSub()); |
| 1799 | if (type == Primitive::kPrimInt) { |
| 1800 | if (use_imm) |
| 1801 | __ Addiu(dst, lhs, -rhs_imm); |
| 1802 | else |
| 1803 | __ Subu(dst, lhs, rhs_reg); |
| 1804 | } else { |
| 1805 | if (use_imm) |
| 1806 | __ Daddiu(dst, lhs, -rhs_imm); |
| 1807 | else |
| 1808 | __ Dsubu(dst, lhs, rhs_reg); |
| 1809 | } |
| 1810 | } |
| 1811 | break; |
| 1812 | } |
| 1813 | case Primitive::kPrimFloat: |
| 1814 | case Primitive::kPrimDouble: { |
| 1815 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 1816 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 1817 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 1818 | if (instruction->IsAdd()) { |
| 1819 | if (type == Primitive::kPrimFloat) |
| 1820 | __ AddS(dst, lhs, rhs); |
| 1821 | else |
| 1822 | __ AddD(dst, lhs, rhs); |
| 1823 | } else if (instruction->IsSub()) { |
| 1824 | if (type == Primitive::kPrimFloat) |
| 1825 | __ SubS(dst, lhs, rhs); |
| 1826 | else |
| 1827 | __ SubD(dst, lhs, rhs); |
| 1828 | } else { |
| 1829 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
| 1830 | } |
| 1831 | break; |
| 1832 | } |
| 1833 | default: |
| 1834 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 1835 | } |
| 1836 | } |
| 1837 | |
| 1838 | void LocationsBuilderMIPS64::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1839 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1840 | |
| 1841 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1842 | Primitive::Type type = instr->GetResultType(); |
| 1843 | switch (type) { |
| 1844 | case Primitive::kPrimInt: |
| 1845 | case Primitive::kPrimLong: { |
| 1846 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1847 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1848 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1849 | break; |
| 1850 | } |
| 1851 | default: |
| 1852 | LOG(FATAL) << "Unexpected shift type " << type; |
| 1853 | } |
| 1854 | } |
| 1855 | |
| 1856 | void InstructionCodeGeneratorMIPS64::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1857 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1858 | LocationSummary* locations = instr->GetLocations(); |
| 1859 | Primitive::Type type = instr->GetType(); |
| 1860 | |
| 1861 | switch (type) { |
| 1862 | case Primitive::kPrimInt: |
| 1863 | case Primitive::kPrimLong: { |
| 1864 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 1865 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1866 | Location rhs_location = locations->InAt(1); |
| 1867 | |
| 1868 | GpuRegister rhs_reg = ZERO; |
| 1869 | int64_t rhs_imm = 0; |
| 1870 | bool use_imm = rhs_location.IsConstant(); |
| 1871 | if (use_imm) { |
| 1872 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 1873 | } else { |
| 1874 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 1875 | } |
| 1876 | |
| 1877 | if (use_imm) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 1878 | uint32_t shift_value = rhs_imm & |
| 1879 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1880 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1881 | if (shift_value == 0) { |
| 1882 | if (dst != lhs) { |
| 1883 | __ Move(dst, lhs); |
| 1884 | } |
| 1885 | } else if (type == Primitive::kPrimInt) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1886 | if (instr->IsShl()) { |
| 1887 | __ Sll(dst, lhs, shift_value); |
| 1888 | } else if (instr->IsShr()) { |
| 1889 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1890 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1891 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1892 | } else { |
| 1893 | __ Rotr(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1894 | } |
| 1895 | } else { |
| 1896 | if (shift_value < 32) { |
| 1897 | if (instr->IsShl()) { |
| 1898 | __ Dsll(dst, lhs, shift_value); |
| 1899 | } else if (instr->IsShr()) { |
| 1900 | __ Dsra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1901 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1902 | __ Dsrl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1903 | } else { |
| 1904 | __ Drotr(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1905 | } |
| 1906 | } else { |
| 1907 | shift_value -= 32; |
| 1908 | if (instr->IsShl()) { |
| 1909 | __ Dsll32(dst, lhs, shift_value); |
| 1910 | } else if (instr->IsShr()) { |
| 1911 | __ Dsra32(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1912 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1913 | __ Dsrl32(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1914 | } else { |
| 1915 | __ Drotr32(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1916 | } |
| 1917 | } |
| 1918 | } |
| 1919 | } else { |
| 1920 | if (type == Primitive::kPrimInt) { |
| 1921 | if (instr->IsShl()) { |
| 1922 | __ Sllv(dst, lhs, rhs_reg); |
| 1923 | } else if (instr->IsShr()) { |
| 1924 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1925 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1926 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1927 | } else { |
| 1928 | __ Rotrv(dst, lhs, rhs_reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1929 | } |
| 1930 | } else { |
| 1931 | if (instr->IsShl()) { |
| 1932 | __ Dsllv(dst, lhs, rhs_reg); |
| 1933 | } else if (instr->IsShr()) { |
| 1934 | __ Dsrav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1935 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1936 | __ Dsrlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1937 | } else { |
| 1938 | __ Drotrv(dst, lhs, rhs_reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1939 | } |
| 1940 | } |
| 1941 | } |
| 1942 | break; |
| 1943 | } |
| 1944 | default: |
| 1945 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 1946 | } |
| 1947 | } |
| 1948 | |
| 1949 | void LocationsBuilderMIPS64::VisitAdd(HAdd* instruction) { |
| 1950 | HandleBinaryOp(instruction); |
| 1951 | } |
| 1952 | |
| 1953 | void InstructionCodeGeneratorMIPS64::VisitAdd(HAdd* instruction) { |
| 1954 | HandleBinaryOp(instruction); |
| 1955 | } |
| 1956 | |
| 1957 | void LocationsBuilderMIPS64::VisitAnd(HAnd* instruction) { |
| 1958 | HandleBinaryOp(instruction); |
| 1959 | } |
| 1960 | |
| 1961 | void InstructionCodeGeneratorMIPS64::VisitAnd(HAnd* instruction) { |
| 1962 | HandleBinaryOp(instruction); |
| 1963 | } |
| 1964 | |
| 1965 | void LocationsBuilderMIPS64::VisitArrayGet(HArrayGet* instruction) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1966 | Primitive::Type type = instruction->GetType(); |
| 1967 | bool object_array_get_with_read_barrier = |
| 1968 | kEmitCompilerReadBarrier && (type == Primitive::kPrimNot); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1969 | LocationSummary* locations = |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1970 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 1971 | object_array_get_with_read_barrier |
| 1972 | ? LocationSummary::kCallOnSlowPath |
| 1973 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1974 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 1975 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 1976 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1977 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1978 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1979 | if (Primitive::IsFloatingPointType(type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1980 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1981 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1982 | // The output overlaps in the case of an object array get with |
| 1983 | // read barriers enabled: we do not want the move to overwrite the |
| 1984 | // array's location, as we need it to emit the read barrier. |
| 1985 | locations->SetOut(Location::RequiresRegister(), |
| 1986 | object_array_get_with_read_barrier |
| 1987 | ? Location::kOutputOverlap |
| 1988 | : Location::kNoOutputOverlap); |
| 1989 | } |
| 1990 | // We need a temporary register for the read barrier marking slow |
| 1991 | // path in CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier. |
| 1992 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 1993 | locations->AddTemp(Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1994 | } |
| 1995 | } |
| 1996 | |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 1997 | static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS64* codegen) { |
| 1998 | auto null_checker = [codegen, instruction]() { |
| 1999 | codegen->MaybeRecordImplicitNullCheck(instruction); |
| 2000 | }; |
| 2001 | return null_checker; |
| 2002 | } |
| 2003 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2004 | void InstructionCodeGeneratorMIPS64::VisitArrayGet(HArrayGet* instruction) { |
| 2005 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2006 | Location obj_loc = locations->InAt(0); |
| 2007 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
| 2008 | Location out_loc = locations->Out(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2009 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2010 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2011 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2012 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2013 | Primitive::Type type = instruction->GetType(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2014 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2015 | instruction->IsStringCharAt(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2016 | switch (type) { |
| 2017 | case Primitive::kPrimBoolean: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2018 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2019 | if (index.IsConstant()) { |
| 2020 | size_t offset = |
| 2021 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2022 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2023 | } else { |
| 2024 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2025 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2026 | } |
| 2027 | break; |
| 2028 | } |
| 2029 | |
| 2030 | case Primitive::kPrimByte: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2031 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2032 | if (index.IsConstant()) { |
| 2033 | size_t offset = |
| 2034 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2035 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2036 | } else { |
| 2037 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2038 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2039 | } |
| 2040 | break; |
| 2041 | } |
| 2042 | |
| 2043 | case Primitive::kPrimShort: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2044 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2045 | if (index.IsConstant()) { |
| 2046 | size_t offset = |
| 2047 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2048 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2049 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2050 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_2); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2051 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2052 | } |
| 2053 | break; |
| 2054 | } |
| 2055 | |
| 2056 | case Primitive::kPrimChar: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2057 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2058 | if (maybe_compressed_char_at) { |
| 2059 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2060 | __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2061 | __ Dext(TMP, TMP, 0, 1); |
| 2062 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2063 | "Expecting 0=compressed, 1=uncompressed"); |
| 2064 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2065 | if (index.IsConstant()) { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2066 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 2067 | if (maybe_compressed_char_at) { |
| 2068 | Mips64Label uncompressed_load, done; |
| 2069 | __ Bnezc(TMP, &uncompressed_load); |
| 2070 | __ LoadFromOffset(kLoadUnsignedByte, |
| 2071 | out, |
| 2072 | obj, |
| 2073 | data_offset + (const_index << TIMES_1)); |
| 2074 | __ Bc(&done); |
| 2075 | __ Bind(&uncompressed_load); |
| 2076 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2077 | out, |
| 2078 | obj, |
| 2079 | data_offset + (const_index << TIMES_2)); |
| 2080 | __ Bind(&done); |
| 2081 | } else { |
| 2082 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2083 | out, |
| 2084 | obj, |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2085 | data_offset + (const_index << TIMES_2), |
| 2086 | null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2087 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2088 | } else { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2089 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
| 2090 | if (maybe_compressed_char_at) { |
| 2091 | Mips64Label uncompressed_load, done; |
| 2092 | __ Bnezc(TMP, &uncompressed_load); |
| 2093 | __ Daddu(TMP, obj, index_reg); |
| 2094 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 2095 | __ Bc(&done); |
| 2096 | __ Bind(&uncompressed_load); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2097 | __ Dlsa(TMP, index_reg, obj, TIMES_2); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2098 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 2099 | __ Bind(&done); |
| 2100 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2101 | __ Dlsa(TMP, index_reg, obj, TIMES_2); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2102 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2103 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2104 | } |
| 2105 | break; |
| 2106 | } |
| 2107 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2108 | case Primitive::kPrimInt: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2109 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2110 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2111 | LoadOperandType load_type = (type == Primitive::kPrimNot) ? kLoadUnsignedWord : kLoadWord; |
| 2112 | if (index.IsConstant()) { |
| 2113 | size_t offset = |
| 2114 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2115 | __ LoadFromOffset(load_type, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2116 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2117 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2118 | __ LoadFromOffset(load_type, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2119 | } |
| 2120 | break; |
| 2121 | } |
| 2122 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2123 | case Primitive::kPrimNot: { |
| 2124 | static_assert( |
| 2125 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2126 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2127 | // /* HeapReference<Object> */ out = |
| 2128 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 2129 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2130 | Location temp = locations->GetTemp(0); |
| 2131 | // Note that a potential implicit null check is handled in this |
| 2132 | // CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier call. |
| 2133 | codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction, |
| 2134 | out_loc, |
| 2135 | obj, |
| 2136 | data_offset, |
| 2137 | index, |
| 2138 | temp, |
| 2139 | /* needs_null_check */ true); |
| 2140 | } else { |
| 2141 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 2142 | if (index.IsConstant()) { |
| 2143 | size_t offset = |
| 2144 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2145 | __ LoadFromOffset(kLoadUnsignedWord, out, obj, offset, null_checker); |
| 2146 | // If read barriers are enabled, emit read barriers other than |
| 2147 | // Baker's using a slow path (and also unpoison the loaded |
| 2148 | // reference, if heap poisoning is enabled). |
| 2149 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 2150 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2151 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2152 | __ LoadFromOffset(kLoadUnsignedWord, out, TMP, data_offset, null_checker); |
| 2153 | // If read barriers are enabled, emit read barriers other than |
| 2154 | // Baker's using a slow path (and also unpoison the loaded |
| 2155 | // reference, if heap poisoning is enabled). |
| 2156 | codegen_->MaybeGenerateReadBarrierSlow(instruction, |
| 2157 | out_loc, |
| 2158 | out_loc, |
| 2159 | obj_loc, |
| 2160 | data_offset, |
| 2161 | index); |
| 2162 | } |
| 2163 | } |
| 2164 | break; |
| 2165 | } |
| 2166 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2167 | case Primitive::kPrimLong: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2168 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2169 | if (index.IsConstant()) { |
| 2170 | size_t offset = |
| 2171 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2172 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2173 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2174 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2175 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2176 | } |
| 2177 | break; |
| 2178 | } |
| 2179 | |
| 2180 | case Primitive::kPrimFloat: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2181 | FpuRegister out = out_loc.AsFpuRegister<FpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2182 | if (index.IsConstant()) { |
| 2183 | size_t offset = |
| 2184 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2185 | __ LoadFpuFromOffset(kLoadWord, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2186 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2187 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2188 | __ LoadFpuFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2189 | } |
| 2190 | break; |
| 2191 | } |
| 2192 | |
| 2193 | case Primitive::kPrimDouble: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2194 | FpuRegister out = out_loc.AsFpuRegister<FpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2195 | if (index.IsConstant()) { |
| 2196 | size_t offset = |
| 2197 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2198 | __ LoadFpuFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2199 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2200 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2201 | __ LoadFpuFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2202 | } |
| 2203 | break; |
| 2204 | } |
| 2205 | |
| 2206 | case Primitive::kPrimVoid: |
| 2207 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2208 | UNREACHABLE(); |
| 2209 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2210 | } |
| 2211 | |
| 2212 | void LocationsBuilderMIPS64::VisitArrayLength(HArrayLength* instruction) { |
| 2213 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2214 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2215 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2216 | } |
| 2217 | |
| 2218 | void InstructionCodeGeneratorMIPS64::VisitArrayLength(HArrayLength* instruction) { |
| 2219 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2220 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2221 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2222 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 2223 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2224 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2225 | // Mask out compression flag from String's array length. |
| 2226 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 2227 | __ Srl(out, out, 1u); |
| 2228 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2229 | } |
| 2230 | |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2231 | Location LocationsBuilderMIPS64::RegisterOrZeroConstant(HInstruction* instruction) { |
| 2232 | return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern()) |
| 2233 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 2234 | : Location::RequiresRegister(); |
| 2235 | } |
| 2236 | |
| 2237 | Location LocationsBuilderMIPS64::FpuRegisterOrConstantForStore(HInstruction* instruction) { |
| 2238 | // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register. |
| 2239 | // We can store a non-zero float or double constant without first loading it into the FPU, |
| 2240 | // but we should only prefer this if the constant has a single use. |
| 2241 | if (instruction->IsConstant() && |
| 2242 | (instruction->AsConstant()->IsZeroBitPattern() || |
| 2243 | instruction->GetUses().HasExactlyOneElement())) { |
| 2244 | return Location::ConstantLocation(instruction->AsConstant()); |
| 2245 | // Otherwise fall through and require an FPU register for the constant. |
| 2246 | } |
| 2247 | return Location::RequiresFpuRegister(); |
| 2248 | } |
| 2249 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2250 | void LocationsBuilderMIPS64::VisitArraySet(HArraySet* instruction) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2251 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2252 | |
| 2253 | bool needs_write_barrier = |
| 2254 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 2255 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 2256 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2257 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2258 | instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2259 | may_need_runtime_call_for_type_check ? |
| 2260 | LocationSummary::kCallOnSlowPath : |
| 2261 | LocationSummary::kNoCall); |
| 2262 | |
| 2263 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2264 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2265 | if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
| 2266 | locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2267 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2268 | locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2))); |
| 2269 | } |
| 2270 | if (needs_write_barrier) { |
| 2271 | // Temporary register for the write barrier. |
| 2272 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2273 | } |
| 2274 | } |
| 2275 | |
| 2276 | void InstructionCodeGeneratorMIPS64::VisitArraySet(HArraySet* instruction) { |
| 2277 | LocationSummary* locations = instruction->GetLocations(); |
| 2278 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2279 | Location index = locations->InAt(1); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2280 | Location value_location = locations->InAt(2); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2281 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2282 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2283 | bool needs_write_barrier = |
| 2284 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2285 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2286 | GpuRegister base_reg = index.IsConstant() ? obj : TMP; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2287 | |
| 2288 | switch (value_type) { |
| 2289 | case Primitive::kPrimBoolean: |
| 2290 | case Primitive::kPrimByte: { |
| 2291 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2292 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2293 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2294 | } else { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2295 | __ Daddu(base_reg, obj, index.AsRegister<GpuRegister>()); |
| 2296 | } |
| 2297 | if (value_location.IsConstant()) { |
| 2298 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2299 | __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker); |
| 2300 | } else { |
| 2301 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2302 | __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2303 | } |
| 2304 | break; |
| 2305 | } |
| 2306 | |
| 2307 | case Primitive::kPrimShort: |
| 2308 | case Primitive::kPrimChar: { |
| 2309 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2310 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2311 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2312 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2313 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_2); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2314 | } |
| 2315 | if (value_location.IsConstant()) { |
| 2316 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2317 | __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker); |
| 2318 | } else { |
| 2319 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2320 | __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2321 | } |
| 2322 | break; |
| 2323 | } |
| 2324 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2325 | case Primitive::kPrimInt: { |
| 2326 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2327 | if (index.IsConstant()) { |
| 2328 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
| 2329 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2330 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2331 | } |
| 2332 | if (value_location.IsConstant()) { |
| 2333 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2334 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2335 | } else { |
| 2336 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2337 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2338 | } |
| 2339 | break; |
| 2340 | } |
| 2341 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2342 | case Primitive::kPrimNot: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2343 | if (value_location.IsConstant()) { |
| 2344 | // Just setting null. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2345 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2346 | if (index.IsConstant()) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2347 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2348 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2349 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2350 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2351 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2352 | DCHECK_EQ(value, 0); |
| 2353 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2354 | DCHECK(!needs_write_barrier); |
| 2355 | DCHECK(!may_need_runtime_call_for_type_check); |
| 2356 | break; |
| 2357 | } |
| 2358 | |
| 2359 | DCHECK(needs_write_barrier); |
| 2360 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2361 | GpuRegister temp1 = locations->GetTemp(0).AsRegister<GpuRegister>(); |
| 2362 | GpuRegister temp2 = TMP; // Doesn't need to survive slow path. |
| 2363 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2364 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2365 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2366 | Mips64Label done; |
| 2367 | SlowPathCodeMIPS64* slow_path = nullptr; |
| 2368 | |
| 2369 | if (may_need_runtime_call_for_type_check) { |
| 2370 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathMIPS64(instruction); |
| 2371 | codegen_->AddSlowPath(slow_path); |
| 2372 | if (instruction->GetValueCanBeNull()) { |
| 2373 | Mips64Label non_zero; |
| 2374 | __ Bnezc(value, &non_zero); |
| 2375 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2376 | if (index.IsConstant()) { |
| 2377 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2378 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2379 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2380 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2381 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2382 | __ Bc(&done); |
| 2383 | __ Bind(&non_zero); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2384 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2385 | |
| 2386 | // Note that when read barriers are enabled, the type checks |
| 2387 | // are performed without read barriers. This is fine, even in |
| 2388 | // the case where a class object is in the from-space after |
| 2389 | // the flip, as a comparison involving such a type would not |
| 2390 | // produce a false positive; it may of course produce a false |
| 2391 | // negative, in which case we would take the ArraySet slow |
| 2392 | // path. |
| 2393 | |
| 2394 | // /* HeapReference<Class> */ temp1 = obj->klass_ |
| 2395 | __ LoadFromOffset(kLoadUnsignedWord, temp1, obj, class_offset, null_checker); |
| 2396 | __ MaybeUnpoisonHeapReference(temp1); |
| 2397 | |
| 2398 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 2399 | __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, component_offset); |
| 2400 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2401 | __ LoadFromOffset(kLoadUnsignedWord, temp2, value, class_offset); |
| 2402 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 2403 | // nor `temp2`, as we are comparing two poisoned references. |
| 2404 | |
| 2405 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2406 | Mips64Label do_put; |
| 2407 | __ Beqc(temp1, temp2, &do_put); |
| 2408 | // If heap poisoning is enabled, the `temp1` reference has |
| 2409 | // not been unpoisoned yet; unpoison it now. |
| 2410 | __ MaybeUnpoisonHeapReference(temp1); |
| 2411 | |
| 2412 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 2413 | __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, super_offset); |
| 2414 | // If heap poisoning is enabled, no need to unpoison |
| 2415 | // `temp1`, as we are comparing against null below. |
| 2416 | __ Bnezc(temp1, slow_path->GetEntryLabel()); |
| 2417 | __ Bind(&do_put); |
| 2418 | } else { |
| 2419 | __ Bnec(temp1, temp2, slow_path->GetEntryLabel()); |
| 2420 | } |
| 2421 | } |
| 2422 | |
| 2423 | GpuRegister source = value; |
| 2424 | if (kPoisonHeapReferences) { |
| 2425 | // Note that in the case where `value` is a null reference, |
| 2426 | // we do not enter this block, as a null reference does not |
| 2427 | // need poisoning. |
| 2428 | __ Move(temp1, value); |
| 2429 | __ PoisonHeapReference(temp1); |
| 2430 | source = temp1; |
| 2431 | } |
| 2432 | |
| 2433 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2434 | if (index.IsConstant()) { |
| 2435 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2436 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2437 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2438 | } |
| 2439 | __ StoreToOffset(kStoreWord, source, base_reg, data_offset); |
| 2440 | |
| 2441 | if (!may_need_runtime_call_for_type_check) { |
| 2442 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2443 | } |
| 2444 | |
| 2445 | codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull()); |
| 2446 | |
| 2447 | if (done.IsLinked()) { |
| 2448 | __ Bind(&done); |
| 2449 | } |
| 2450 | |
| 2451 | if (slow_path != nullptr) { |
| 2452 | __ Bind(slow_path->GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2453 | } |
| 2454 | break; |
| 2455 | } |
| 2456 | |
| 2457 | case Primitive::kPrimLong: { |
| 2458 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2459 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2460 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2461 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2462 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2463 | } |
| 2464 | if (value_location.IsConstant()) { |
| 2465 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2466 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2467 | } else { |
| 2468 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2469 | __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2470 | } |
| 2471 | break; |
| 2472 | } |
| 2473 | |
| 2474 | case Primitive::kPrimFloat: { |
| 2475 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2476 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2477 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2478 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2479 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2480 | } |
| 2481 | if (value_location.IsConstant()) { |
| 2482 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2483 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2484 | } else { |
| 2485 | FpuRegister value = value_location.AsFpuRegister<FpuRegister>(); |
| 2486 | __ StoreFpuToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2487 | } |
| 2488 | break; |
| 2489 | } |
| 2490 | |
| 2491 | case Primitive::kPrimDouble: { |
| 2492 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2493 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2494 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2495 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2496 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2497 | } |
| 2498 | if (value_location.IsConstant()) { |
| 2499 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2500 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2501 | } else { |
| 2502 | FpuRegister value = value_location.AsFpuRegister<FpuRegister>(); |
| 2503 | __ StoreFpuToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2504 | } |
| 2505 | break; |
| 2506 | } |
| 2507 | |
| 2508 | case Primitive::kPrimVoid: |
| 2509 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2510 | UNREACHABLE(); |
| 2511 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2512 | } |
| 2513 | |
| 2514 | void LocationsBuilderMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2515 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2516 | InvokeRuntimeCallingConvention calling_convention; |
| 2517 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2518 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2519 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2520 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2521 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2522 | } |
| 2523 | |
| 2524 | void InstructionCodeGeneratorMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2525 | LocationSummary* locations = instruction->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2526 | BoundsCheckSlowPathMIPS64* slow_path = |
| 2527 | new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS64(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2528 | codegen_->AddSlowPath(slow_path); |
| 2529 | |
| 2530 | GpuRegister index = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2531 | GpuRegister length = locations->InAt(1).AsRegister<GpuRegister>(); |
| 2532 | |
| 2533 | // length is limited by the maximum positive signed 32-bit integer. |
| 2534 | // Unsigned comparison of length and index checks for index < 0 |
| 2535 | // and for length <= index simultaneously. |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2536 | __ Bgeuc(index, length, slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2537 | } |
| 2538 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2539 | // Temp is used for read barrier. |
| 2540 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 2541 | if (kEmitCompilerReadBarrier && |
| 2542 | (kUseBakerReadBarrier || |
| 2543 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 2544 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 2545 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 2546 | return 1; |
| 2547 | } |
| 2548 | return 0; |
| 2549 | } |
| 2550 | |
| 2551 | // Extra temp is used for read barrier. |
| 2552 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 2553 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 2554 | } |
| 2555 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2556 | void LocationsBuilderMIPS64::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2557 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 2558 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 2559 | |
| 2560 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 2561 | switch (type_check_kind) { |
| 2562 | case TypeCheckKind::kExactCheck: |
| 2563 | case TypeCheckKind::kAbstractClassCheck: |
| 2564 | case TypeCheckKind::kClassHierarchyCheck: |
| 2565 | case TypeCheckKind::kArrayObjectCheck: |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2566 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2567 | ? LocationSummary::kCallOnSlowPath |
| 2568 | : LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
| 2569 | break; |
| 2570 | case TypeCheckKind::kArrayCheck: |
| 2571 | case TypeCheckKind::kUnresolvedCheck: |
| 2572 | case TypeCheckKind::kInterfaceCheck: |
| 2573 | call_kind = LocationSummary::kCallOnSlowPath; |
| 2574 | break; |
| 2575 | } |
| 2576 | |
| 2577 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2578 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2579 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2580 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2581 | } |
| 2582 | |
| 2583 | void InstructionCodeGeneratorMIPS64::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2584 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2585 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2586 | Location obj_loc = locations->InAt(0); |
| 2587 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2588 | GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2589 | Location temp_loc = locations->GetTemp(0); |
| 2590 | GpuRegister temp = temp_loc.AsRegister<GpuRegister>(); |
| 2591 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 2592 | DCHECK_LE(num_temps, 2u); |
| 2593 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2594 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2595 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2596 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2597 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 2598 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 2599 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 2600 | const uint32_t object_array_data_offset = |
| 2601 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| 2602 | Mips64Label done; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2603 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2604 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 2605 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 2606 | // read barriers is done for performance and code size reasons. |
| 2607 | bool is_type_check_slow_path_fatal = false; |
| 2608 | if (!kEmitCompilerReadBarrier) { |
| 2609 | is_type_check_slow_path_fatal = |
| 2610 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 2611 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 2612 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 2613 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 2614 | !instruction->CanThrowIntoCatchBlock(); |
| 2615 | } |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2616 | SlowPathCodeMIPS64* slow_path = |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2617 | new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction, |
| 2618 | is_type_check_slow_path_fatal); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2619 | codegen_->AddSlowPath(slow_path); |
| 2620 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2621 | // Avoid this check if we know `obj` is not null. |
| 2622 | if (instruction->MustDoNullCheck()) { |
| 2623 | __ Beqzc(obj, &done); |
| 2624 | } |
| 2625 | |
| 2626 | switch (type_check_kind) { |
| 2627 | case TypeCheckKind::kExactCheck: |
| 2628 | case TypeCheckKind::kArrayCheck: { |
| 2629 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2630 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2631 | temp_loc, |
| 2632 | obj_loc, |
| 2633 | class_offset, |
| 2634 | maybe_temp2_loc, |
| 2635 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2636 | // Jump to slow path for throwing the exception or doing a |
| 2637 | // more involved array check. |
| 2638 | __ Bnec(temp, cls, slow_path->GetEntryLabel()); |
| 2639 | break; |
| 2640 | } |
| 2641 | |
| 2642 | case TypeCheckKind::kAbstractClassCheck: { |
| 2643 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2644 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2645 | temp_loc, |
| 2646 | obj_loc, |
| 2647 | class_offset, |
| 2648 | maybe_temp2_loc, |
| 2649 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2650 | // If the class is abstract, we eagerly fetch the super class of the |
| 2651 | // object to avoid doing a comparison we know will fail. |
| 2652 | Mips64Label loop; |
| 2653 | __ Bind(&loop); |
| 2654 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2655 | GenerateReferenceLoadOneRegister(instruction, |
| 2656 | temp_loc, |
| 2657 | super_offset, |
| 2658 | maybe_temp2_loc, |
| 2659 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2660 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 2661 | // exception. |
| 2662 | __ Beqzc(temp, slow_path->GetEntryLabel()); |
| 2663 | // Otherwise, compare the classes. |
| 2664 | __ Bnec(temp, cls, &loop); |
| 2665 | break; |
| 2666 | } |
| 2667 | |
| 2668 | case TypeCheckKind::kClassHierarchyCheck: { |
| 2669 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2670 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2671 | temp_loc, |
| 2672 | obj_loc, |
| 2673 | class_offset, |
| 2674 | maybe_temp2_loc, |
| 2675 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2676 | // Walk over the class hierarchy to find a match. |
| 2677 | Mips64Label loop; |
| 2678 | __ Bind(&loop); |
| 2679 | __ Beqc(temp, cls, &done); |
| 2680 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2681 | GenerateReferenceLoadOneRegister(instruction, |
| 2682 | temp_loc, |
| 2683 | super_offset, |
| 2684 | maybe_temp2_loc, |
| 2685 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2686 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 2687 | // exception. Otherwise, jump to the beginning of the loop. |
| 2688 | __ Bnezc(temp, &loop); |
| 2689 | __ Bc(slow_path->GetEntryLabel()); |
| 2690 | break; |
| 2691 | } |
| 2692 | |
| 2693 | case TypeCheckKind::kArrayObjectCheck: { |
| 2694 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2695 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2696 | temp_loc, |
| 2697 | obj_loc, |
| 2698 | class_offset, |
| 2699 | maybe_temp2_loc, |
| 2700 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2701 | // Do an exact check. |
| 2702 | __ Beqc(temp, cls, &done); |
| 2703 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 2704 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2705 | GenerateReferenceLoadOneRegister(instruction, |
| 2706 | temp_loc, |
| 2707 | component_offset, |
| 2708 | maybe_temp2_loc, |
| 2709 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2710 | // If the component type is null, jump to the slow path to throw the exception. |
| 2711 | __ Beqzc(temp, slow_path->GetEntryLabel()); |
| 2712 | // Otherwise, the object is indeed an array, further check that this component |
| 2713 | // type is not a primitive type. |
| 2714 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 2715 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 2716 | __ Bnezc(temp, slow_path->GetEntryLabel()); |
| 2717 | break; |
| 2718 | } |
| 2719 | |
| 2720 | case TypeCheckKind::kUnresolvedCheck: |
| 2721 | // We always go into the type check slow path for the unresolved check case. |
| 2722 | // We cannot directly call the CheckCast runtime entry point |
| 2723 | // without resorting to a type checking slow path here (i.e. by |
| 2724 | // calling InvokeRuntime directly), as it would require to |
| 2725 | // assign fixed registers for the inputs of this HInstanceOf |
| 2726 | // instruction (following the runtime calling convention), which |
| 2727 | // might be cluttered by the potential first read barrier |
| 2728 | // emission at the beginning of this method. |
| 2729 | __ Bc(slow_path->GetEntryLabel()); |
| 2730 | break; |
| 2731 | |
| 2732 | case TypeCheckKind::kInterfaceCheck: { |
| 2733 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 2734 | // positives by doing this. |
| 2735 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2736 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2737 | temp_loc, |
| 2738 | obj_loc, |
| 2739 | class_offset, |
| 2740 | maybe_temp2_loc, |
| 2741 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2742 | // /* HeapReference<Class> */ temp = temp->iftable_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2743 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2744 | temp_loc, |
| 2745 | temp_loc, |
| 2746 | iftable_offset, |
| 2747 | maybe_temp2_loc, |
| 2748 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2749 | // Iftable is never null. |
| 2750 | __ Lw(TMP, temp, array_length_offset); |
| 2751 | // Loop through the iftable and check if any class matches. |
| 2752 | Mips64Label loop; |
| 2753 | __ Bind(&loop); |
| 2754 | __ Beqzc(TMP, slow_path->GetEntryLabel()); |
| 2755 | __ Lwu(AT, temp, object_array_data_offset); |
| 2756 | __ MaybeUnpoisonHeapReference(AT); |
| 2757 | // Go to next interface. |
| 2758 | __ Daddiu(temp, temp, 2 * kHeapReferenceSize); |
| 2759 | __ Addiu(TMP, TMP, -2); |
| 2760 | // Compare the classes and continue the loop if they do not match. |
| 2761 | __ Bnec(AT, cls, &loop); |
| 2762 | break; |
| 2763 | } |
| 2764 | } |
| 2765 | |
| 2766 | __ Bind(&done); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2767 | __ Bind(slow_path->GetExitLabel()); |
| 2768 | } |
| 2769 | |
| 2770 | void LocationsBuilderMIPS64::VisitClinitCheck(HClinitCheck* check) { |
| 2771 | LocationSummary* locations = |
| 2772 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2773 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2774 | if (check->HasUses()) { |
| 2775 | locations->SetOut(Location::SameAsFirstInput()); |
| 2776 | } |
| 2777 | } |
| 2778 | |
| 2779 | void InstructionCodeGeneratorMIPS64::VisitClinitCheck(HClinitCheck* check) { |
| 2780 | // We assume the class is not null. |
| 2781 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64( |
| 2782 | check->GetLoadClass(), |
| 2783 | check, |
| 2784 | check->GetDexPc(), |
| 2785 | true); |
| 2786 | codegen_->AddSlowPath(slow_path); |
| 2787 | GenerateClassInitializationCheck(slow_path, |
| 2788 | check->GetLocations()->InAt(0).AsRegister<GpuRegister>()); |
| 2789 | } |
| 2790 | |
| 2791 | void LocationsBuilderMIPS64::VisitCompare(HCompare* compare) { |
| 2792 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 2793 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2794 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(compare); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2795 | |
| 2796 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2797 | case Primitive::kPrimBoolean: |
| 2798 | case Primitive::kPrimByte: |
| 2799 | case Primitive::kPrimShort: |
| 2800 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2801 | case Primitive::kPrimInt: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2802 | case Primitive::kPrimLong: |
| 2803 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 2804 | locations->SetInAt(1, Location::RegisterOrConstant(compare->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2805 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2806 | break; |
| 2807 | |
| 2808 | case Primitive::kPrimFloat: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2809 | case Primitive::kPrimDouble: |
| 2810 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2811 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2812 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2813 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2814 | |
| 2815 | default: |
| 2816 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2817 | } |
| 2818 | } |
| 2819 | |
| 2820 | void InstructionCodeGeneratorMIPS64::VisitCompare(HCompare* instruction) { |
| 2821 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2822 | GpuRegister res = locations->Out().AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2823 | Primitive::Type in_type = instruction->InputAt(0)->GetType(); |
| 2824 | |
| 2825 | // 0 if: left == right |
| 2826 | // 1 if: left > right |
| 2827 | // -1 if: left < right |
| 2828 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2829 | case Primitive::kPrimBoolean: |
| 2830 | case Primitive::kPrimByte: |
| 2831 | case Primitive::kPrimShort: |
| 2832 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2833 | case Primitive::kPrimInt: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2834 | case Primitive::kPrimLong: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2835 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 2836 | Location rhs_location = locations->InAt(1); |
| 2837 | bool use_imm = rhs_location.IsConstant(); |
| 2838 | GpuRegister rhs = ZERO; |
| 2839 | if (use_imm) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2840 | if (in_type == Primitive::kPrimLong) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2841 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 2842 | if (value != 0) { |
| 2843 | rhs = AT; |
| 2844 | __ LoadConst64(rhs, value); |
| 2845 | } |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2846 | } else { |
| 2847 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 2848 | if (value != 0) { |
| 2849 | rhs = AT; |
| 2850 | __ LoadConst32(rhs, value); |
| 2851 | } |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 2852 | } |
| 2853 | } else { |
| 2854 | rhs = rhs_location.AsRegister<GpuRegister>(); |
| 2855 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2856 | __ Slt(TMP, lhs, rhs); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2857 | __ Slt(res, rhs, lhs); |
| 2858 | __ Subu(res, res, TMP); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2859 | break; |
| 2860 | } |
| 2861 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2862 | case Primitive::kPrimFloat: { |
| 2863 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 2864 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 2865 | Mips64Label done; |
| 2866 | __ CmpEqS(FTMP, lhs, rhs); |
| 2867 | __ LoadConst32(res, 0); |
| 2868 | __ Bc1nez(FTMP, &done); |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 2869 | if (instruction->IsGtBias()) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2870 | __ CmpLtS(FTMP, lhs, rhs); |
| 2871 | __ LoadConst32(res, -1); |
| 2872 | __ Bc1nez(FTMP, &done); |
| 2873 | __ LoadConst32(res, 1); |
| 2874 | } else { |
| 2875 | __ CmpLtS(FTMP, rhs, lhs); |
| 2876 | __ LoadConst32(res, 1); |
| 2877 | __ Bc1nez(FTMP, &done); |
| 2878 | __ LoadConst32(res, -1); |
| 2879 | } |
| 2880 | __ Bind(&done); |
| 2881 | break; |
| 2882 | } |
| 2883 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2884 | case Primitive::kPrimDouble: { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2885 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 2886 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 2887 | Mips64Label done; |
| 2888 | __ CmpEqD(FTMP, lhs, rhs); |
| 2889 | __ LoadConst32(res, 0); |
| 2890 | __ Bc1nez(FTMP, &done); |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 2891 | if (instruction->IsGtBias()) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2892 | __ CmpLtD(FTMP, lhs, rhs); |
| 2893 | __ LoadConst32(res, -1); |
| 2894 | __ Bc1nez(FTMP, &done); |
| 2895 | __ LoadConst32(res, 1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2896 | } else { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2897 | __ CmpLtD(FTMP, rhs, lhs); |
| 2898 | __ LoadConst32(res, 1); |
| 2899 | __ Bc1nez(FTMP, &done); |
| 2900 | __ LoadConst32(res, -1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2901 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2902 | __ Bind(&done); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2903 | break; |
| 2904 | } |
| 2905 | |
| 2906 | default: |
| 2907 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2908 | } |
| 2909 | } |
| 2910 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2911 | void LocationsBuilderMIPS64::HandleCondition(HCondition* instruction) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2912 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2913 | switch (instruction->InputAt(0)->GetType()) { |
| 2914 | default: |
| 2915 | case Primitive::kPrimLong: |
| 2916 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2917 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2918 | break; |
| 2919 | |
| 2920 | case Primitive::kPrimFloat: |
| 2921 | case Primitive::kPrimDouble: |
| 2922 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2923 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2924 | break; |
| 2925 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2926 | if (!instruction->IsEmittedAtUseSite()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2927 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2928 | } |
| 2929 | } |
| 2930 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2931 | void InstructionCodeGeneratorMIPS64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2932 | if (instruction->IsEmittedAtUseSite()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2933 | return; |
| 2934 | } |
| 2935 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2936 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2937 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2938 | switch (type) { |
| 2939 | default: |
| 2940 | // Integer case. |
| 2941 | GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ false, locations); |
| 2942 | return; |
| 2943 | case Primitive::kPrimLong: |
| 2944 | GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ true, locations); |
| 2945 | return; |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2946 | case Primitive::kPrimFloat: |
| 2947 | case Primitive::kPrimDouble: |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 2948 | GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations); |
| 2949 | return; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2950 | } |
| 2951 | } |
| 2952 | |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 2953 | void InstructionCodeGeneratorMIPS64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2954 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2955 | Primitive::Type type = instruction->GetResultType(); |
| 2956 | |
| 2957 | LocationSummary* locations = instruction->GetLocations(); |
| 2958 | Location second = locations->InAt(1); |
| 2959 | DCHECK(second.IsConstant()); |
| 2960 | |
| 2961 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 2962 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2963 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2964 | DCHECK(imm == 1 || imm == -1); |
| 2965 | |
| 2966 | if (instruction->IsRem()) { |
| 2967 | __ Move(out, ZERO); |
| 2968 | } else { |
| 2969 | if (imm == -1) { |
| 2970 | if (type == Primitive::kPrimInt) { |
| 2971 | __ Subu(out, ZERO, dividend); |
| 2972 | } else { |
| 2973 | DCHECK_EQ(type, Primitive::kPrimLong); |
| 2974 | __ Dsubu(out, ZERO, dividend); |
| 2975 | } |
| 2976 | } else if (out != dividend) { |
| 2977 | __ Move(out, dividend); |
| 2978 | } |
| 2979 | } |
| 2980 | } |
| 2981 | |
| 2982 | void InstructionCodeGeneratorMIPS64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2983 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2984 | Primitive::Type type = instruction->GetResultType(); |
| 2985 | |
| 2986 | LocationSummary* locations = instruction->GetLocations(); |
| 2987 | Location second = locations->InAt(1); |
| 2988 | DCHECK(second.IsConstant()); |
| 2989 | |
| 2990 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 2991 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2992 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2993 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 2994 | int ctz_imm = CTZ(abs_imm); |
| 2995 | |
| 2996 | if (instruction->IsDiv()) { |
| 2997 | if (type == Primitive::kPrimInt) { |
| 2998 | if (ctz_imm == 1) { |
| 2999 | // Fast path for division by +/-2, which is very common. |
| 3000 | __ Srl(TMP, dividend, 31); |
| 3001 | } else { |
| 3002 | __ Sra(TMP, dividend, 31); |
| 3003 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3004 | } |
| 3005 | __ Addu(out, dividend, TMP); |
| 3006 | __ Sra(out, out, ctz_imm); |
| 3007 | if (imm < 0) { |
| 3008 | __ Subu(out, ZERO, out); |
| 3009 | } |
| 3010 | } else { |
| 3011 | DCHECK_EQ(type, Primitive::kPrimLong); |
| 3012 | if (ctz_imm == 1) { |
| 3013 | // Fast path for division by +/-2, which is very common. |
| 3014 | __ Dsrl32(TMP, dividend, 31); |
| 3015 | } else { |
| 3016 | __ Dsra32(TMP, dividend, 31); |
| 3017 | if (ctz_imm > 32) { |
| 3018 | __ Dsrl(TMP, TMP, 64 - ctz_imm); |
| 3019 | } else { |
| 3020 | __ Dsrl32(TMP, TMP, 32 - ctz_imm); |
| 3021 | } |
| 3022 | } |
| 3023 | __ Daddu(out, dividend, TMP); |
| 3024 | if (ctz_imm < 32) { |
| 3025 | __ Dsra(out, out, ctz_imm); |
| 3026 | } else { |
| 3027 | __ Dsra32(out, out, ctz_imm - 32); |
| 3028 | } |
| 3029 | if (imm < 0) { |
| 3030 | __ Dsubu(out, ZERO, out); |
| 3031 | } |
| 3032 | } |
| 3033 | } else { |
| 3034 | if (type == Primitive::kPrimInt) { |
| 3035 | if (ctz_imm == 1) { |
| 3036 | // Fast path for modulo +/-2, which is very common. |
| 3037 | __ Sra(TMP, dividend, 31); |
| 3038 | __ Subu(out, dividend, TMP); |
| 3039 | __ Andi(out, out, 1); |
| 3040 | __ Addu(out, out, TMP); |
| 3041 | } else { |
| 3042 | __ Sra(TMP, dividend, 31); |
| 3043 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3044 | __ Addu(out, dividend, TMP); |
| 3045 | if (IsUint<16>(abs_imm - 1)) { |
| 3046 | __ Andi(out, out, abs_imm - 1); |
| 3047 | } else { |
| 3048 | __ Sll(out, out, 32 - ctz_imm); |
| 3049 | __ Srl(out, out, 32 - ctz_imm); |
| 3050 | } |
| 3051 | __ Subu(out, out, TMP); |
| 3052 | } |
| 3053 | } else { |
| 3054 | DCHECK_EQ(type, Primitive::kPrimLong); |
| 3055 | if (ctz_imm == 1) { |
| 3056 | // Fast path for modulo +/-2, which is very common. |
| 3057 | __ Dsra32(TMP, dividend, 31); |
| 3058 | __ Dsubu(out, dividend, TMP); |
| 3059 | __ Andi(out, out, 1); |
| 3060 | __ Daddu(out, out, TMP); |
| 3061 | } else { |
| 3062 | __ Dsra32(TMP, dividend, 31); |
| 3063 | if (ctz_imm > 32) { |
| 3064 | __ Dsrl(TMP, TMP, 64 - ctz_imm); |
| 3065 | } else { |
| 3066 | __ Dsrl32(TMP, TMP, 32 - ctz_imm); |
| 3067 | } |
| 3068 | __ Daddu(out, dividend, TMP); |
| 3069 | if (IsUint<16>(abs_imm - 1)) { |
| 3070 | __ Andi(out, out, abs_imm - 1); |
| 3071 | } else { |
| 3072 | if (ctz_imm > 32) { |
| 3073 | __ Dsll(out, out, 64 - ctz_imm); |
| 3074 | __ Dsrl(out, out, 64 - ctz_imm); |
| 3075 | } else { |
| 3076 | __ Dsll32(out, out, 32 - ctz_imm); |
| 3077 | __ Dsrl32(out, out, 32 - ctz_imm); |
| 3078 | } |
| 3079 | } |
| 3080 | __ Dsubu(out, out, TMP); |
| 3081 | } |
| 3082 | } |
| 3083 | } |
| 3084 | } |
| 3085 | |
| 3086 | void InstructionCodeGeneratorMIPS64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3087 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3088 | |
| 3089 | LocationSummary* locations = instruction->GetLocations(); |
| 3090 | Location second = locations->InAt(1); |
| 3091 | DCHECK(second.IsConstant()); |
| 3092 | |
| 3093 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3094 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3095 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3096 | |
| 3097 | Primitive::Type type = instruction->GetResultType(); |
| 3098 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong) << type; |
| 3099 | |
| 3100 | int64_t magic; |
| 3101 | int shift; |
| 3102 | CalculateMagicAndShiftForDivRem(imm, |
| 3103 | (type == Primitive::kPrimLong), |
| 3104 | &magic, |
| 3105 | &shift); |
| 3106 | |
| 3107 | if (type == Primitive::kPrimInt) { |
| 3108 | __ LoadConst32(TMP, magic); |
| 3109 | __ MuhR6(TMP, dividend, TMP); |
| 3110 | |
| 3111 | if (imm > 0 && magic < 0) { |
| 3112 | __ Addu(TMP, TMP, dividend); |
| 3113 | } else if (imm < 0 && magic > 0) { |
| 3114 | __ Subu(TMP, TMP, dividend); |
| 3115 | } |
| 3116 | |
| 3117 | if (shift != 0) { |
| 3118 | __ Sra(TMP, TMP, shift); |
| 3119 | } |
| 3120 | |
| 3121 | if (instruction->IsDiv()) { |
| 3122 | __ Sra(out, TMP, 31); |
| 3123 | __ Subu(out, TMP, out); |
| 3124 | } else { |
| 3125 | __ Sra(AT, TMP, 31); |
| 3126 | __ Subu(AT, TMP, AT); |
| 3127 | __ LoadConst32(TMP, imm); |
| 3128 | __ MulR6(TMP, AT, TMP); |
| 3129 | __ Subu(out, dividend, TMP); |
| 3130 | } |
| 3131 | } else { |
| 3132 | __ LoadConst64(TMP, magic); |
| 3133 | __ Dmuh(TMP, dividend, TMP); |
| 3134 | |
| 3135 | if (imm > 0 && magic < 0) { |
| 3136 | __ Daddu(TMP, TMP, dividend); |
| 3137 | } else if (imm < 0 && magic > 0) { |
| 3138 | __ Dsubu(TMP, TMP, dividend); |
| 3139 | } |
| 3140 | |
| 3141 | if (shift >= 32) { |
| 3142 | __ Dsra32(TMP, TMP, shift - 32); |
| 3143 | } else if (shift > 0) { |
| 3144 | __ Dsra(TMP, TMP, shift); |
| 3145 | } |
| 3146 | |
| 3147 | if (instruction->IsDiv()) { |
| 3148 | __ Dsra32(out, TMP, 31); |
| 3149 | __ Dsubu(out, TMP, out); |
| 3150 | } else { |
| 3151 | __ Dsra32(AT, TMP, 31); |
| 3152 | __ Dsubu(AT, TMP, AT); |
| 3153 | __ LoadConst64(TMP, imm); |
| 3154 | __ Dmul(TMP, AT, TMP); |
| 3155 | __ Dsubu(out, dividend, TMP); |
| 3156 | } |
| 3157 | } |
| 3158 | } |
| 3159 | |
| 3160 | void InstructionCodeGeneratorMIPS64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3161 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3162 | Primitive::Type type = instruction->GetResultType(); |
| 3163 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong) << type; |
| 3164 | |
| 3165 | LocationSummary* locations = instruction->GetLocations(); |
| 3166 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3167 | Location second = locations->InAt(1); |
| 3168 | |
| 3169 | if (second.IsConstant()) { |
| 3170 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3171 | if (imm == 0) { |
| 3172 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3173 | } else if (imm == 1 || imm == -1) { |
| 3174 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3175 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3176 | DivRemByPowerOfTwo(instruction); |
| 3177 | } else { |
| 3178 | DCHECK(imm <= -2 || imm >= 2); |
| 3179 | GenerateDivRemWithAnyConstant(instruction); |
| 3180 | } |
| 3181 | } else { |
| 3182 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3183 | GpuRegister divisor = second.AsRegister<GpuRegister>(); |
| 3184 | if (instruction->IsDiv()) { |
| 3185 | if (type == Primitive::kPrimInt) |
| 3186 | __ DivR6(out, dividend, divisor); |
| 3187 | else |
| 3188 | __ Ddiv(out, dividend, divisor); |
| 3189 | } else { |
| 3190 | if (type == Primitive::kPrimInt) |
| 3191 | __ ModR6(out, dividend, divisor); |
| 3192 | else |
| 3193 | __ Dmod(out, dividend, divisor); |
| 3194 | } |
| 3195 | } |
| 3196 | } |
| 3197 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3198 | void LocationsBuilderMIPS64::VisitDiv(HDiv* div) { |
| 3199 | LocationSummary* locations = |
| 3200 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3201 | switch (div->GetResultType()) { |
| 3202 | case Primitive::kPrimInt: |
| 3203 | case Primitive::kPrimLong: |
| 3204 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3205 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3206 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3207 | break; |
| 3208 | |
| 3209 | case Primitive::kPrimFloat: |
| 3210 | case Primitive::kPrimDouble: |
| 3211 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3212 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3213 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3214 | break; |
| 3215 | |
| 3216 | default: |
| 3217 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3218 | } |
| 3219 | } |
| 3220 | |
| 3221 | void InstructionCodeGeneratorMIPS64::VisitDiv(HDiv* instruction) { |
| 3222 | Primitive::Type type = instruction->GetType(); |
| 3223 | LocationSummary* locations = instruction->GetLocations(); |
| 3224 | |
| 3225 | switch (type) { |
| 3226 | case Primitive::kPrimInt: |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3227 | case Primitive::kPrimLong: |
| 3228 | GenerateDivRemIntegral(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3229 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3230 | case Primitive::kPrimFloat: |
| 3231 | case Primitive::kPrimDouble: { |
| 3232 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 3233 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3234 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 3235 | if (type == Primitive::kPrimFloat) |
| 3236 | __ DivS(dst, lhs, rhs); |
| 3237 | else |
| 3238 | __ DivD(dst, lhs, rhs); |
| 3239 | break; |
| 3240 | } |
| 3241 | default: |
| 3242 | LOG(FATAL) << "Unexpected div type " << type; |
| 3243 | } |
| 3244 | } |
| 3245 | |
| 3246 | void LocationsBuilderMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3247 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3248 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3249 | } |
| 3250 | |
| 3251 | void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3252 | SlowPathCodeMIPS64* slow_path = |
| 3253 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS64(instruction); |
| 3254 | codegen_->AddSlowPath(slow_path); |
| 3255 | Location value = instruction->GetLocations()->InAt(0); |
| 3256 | |
| 3257 | Primitive::Type type = instruction->GetType(); |
| 3258 | |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3259 | if (!Primitive::IsIntegralType(type)) { |
| 3260 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3261 | return; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3262 | } |
| 3263 | |
| 3264 | if (value.IsConstant()) { |
| 3265 | int64_t divisor = codegen_->GetInt64ValueOf(value.GetConstant()->AsConstant()); |
| 3266 | if (divisor == 0) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3267 | __ Bc(slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3268 | } else { |
| 3269 | // A division by a non-null constant is valid. We don't need to perform |
| 3270 | // any check, so simply fall through. |
| 3271 | } |
| 3272 | } else { |
| 3273 | __ Beqzc(value.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 3274 | } |
| 3275 | } |
| 3276 | |
| 3277 | void LocationsBuilderMIPS64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3278 | LocationSummary* locations = |
| 3279 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3280 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3281 | } |
| 3282 | |
| 3283 | void InstructionCodeGeneratorMIPS64::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 3284 | // Will be generated at use site. |
| 3285 | } |
| 3286 | |
| 3287 | void LocationsBuilderMIPS64::VisitExit(HExit* exit) { |
| 3288 | exit->SetLocations(nullptr); |
| 3289 | } |
| 3290 | |
| 3291 | void InstructionCodeGeneratorMIPS64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 3292 | } |
| 3293 | |
| 3294 | void LocationsBuilderMIPS64::VisitFloatConstant(HFloatConstant* constant) { |
| 3295 | LocationSummary* locations = |
| 3296 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3297 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3298 | } |
| 3299 | |
| 3300 | void InstructionCodeGeneratorMIPS64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 3301 | // Will be generated at use site. |
| 3302 | } |
| 3303 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3304 | void InstructionCodeGeneratorMIPS64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3305 | DCHECK(!successor->IsExitBlock()); |
| 3306 | HBasicBlock* block = got->GetBlock(); |
| 3307 | HInstruction* previous = got->GetPrevious(); |
| 3308 | HLoopInformation* info = block->GetLoopInformation(); |
| 3309 | |
| 3310 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| 3311 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 3312 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3313 | return; |
| 3314 | } |
| 3315 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3316 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 3317 | } |
| 3318 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3319 | __ Bc(codegen_->GetLabelOf(successor)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3320 | } |
| 3321 | } |
| 3322 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3323 | void LocationsBuilderMIPS64::VisitGoto(HGoto* got) { |
| 3324 | got->SetLocations(nullptr); |
| 3325 | } |
| 3326 | |
| 3327 | void InstructionCodeGeneratorMIPS64::VisitGoto(HGoto* got) { |
| 3328 | HandleGoto(got, got->GetSuccessor()); |
| 3329 | } |
| 3330 | |
| 3331 | void LocationsBuilderMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3332 | try_boundary->SetLocations(nullptr); |
| 3333 | } |
| 3334 | |
| 3335 | void InstructionCodeGeneratorMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3336 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3337 | if (!successor->IsExitBlock()) { |
| 3338 | HandleGoto(try_boundary, successor); |
| 3339 | } |
| 3340 | } |
| 3341 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3342 | void InstructionCodeGeneratorMIPS64::GenerateIntLongCompare(IfCondition cond, |
| 3343 | bool is64bit, |
| 3344 | LocationSummary* locations) { |
| 3345 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3346 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3347 | Location rhs_location = locations->InAt(1); |
| 3348 | GpuRegister rhs_reg = ZERO; |
| 3349 | int64_t rhs_imm = 0; |
| 3350 | bool use_imm = rhs_location.IsConstant(); |
| 3351 | if (use_imm) { |
| 3352 | if (is64bit) { |
| 3353 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3354 | } else { |
| 3355 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3356 | } |
| 3357 | } else { |
| 3358 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3359 | } |
| 3360 | int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1); |
| 3361 | |
| 3362 | switch (cond) { |
| 3363 | case kCondEQ: |
| 3364 | case kCondNE: |
Goran Jakovljevic | db3deee | 2016-12-28 14:33:21 +0100 | [diff] [blame] | 3365 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 3366 | if (rhs_imm == 0) { |
| 3367 | if (cond == kCondEQ) { |
| 3368 | __ Sltiu(dst, lhs, 1); |
| 3369 | } else { |
| 3370 | __ Sltu(dst, ZERO, lhs); |
| 3371 | } |
| 3372 | } else { |
| 3373 | if (is64bit) { |
| 3374 | __ Daddiu(dst, lhs, -rhs_imm); |
| 3375 | } else { |
| 3376 | __ Addiu(dst, lhs, -rhs_imm); |
| 3377 | } |
| 3378 | if (cond == kCondEQ) { |
| 3379 | __ Sltiu(dst, dst, 1); |
| 3380 | } else { |
| 3381 | __ Sltu(dst, ZERO, dst); |
| 3382 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3383 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3384 | } else { |
Goran Jakovljevic | db3deee | 2016-12-28 14:33:21 +0100 | [diff] [blame] | 3385 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 3386 | __ Xori(dst, lhs, rhs_imm); |
| 3387 | } else { |
| 3388 | if (use_imm) { |
| 3389 | rhs_reg = TMP; |
| 3390 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3391 | } |
| 3392 | __ Xor(dst, lhs, rhs_reg); |
| 3393 | } |
| 3394 | if (cond == kCondEQ) { |
| 3395 | __ Sltiu(dst, dst, 1); |
| 3396 | } else { |
| 3397 | __ Sltu(dst, ZERO, dst); |
| 3398 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3399 | } |
| 3400 | break; |
| 3401 | |
| 3402 | case kCondLT: |
| 3403 | case kCondGE: |
| 3404 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3405 | __ Slti(dst, lhs, rhs_imm); |
| 3406 | } else { |
| 3407 | if (use_imm) { |
| 3408 | rhs_reg = TMP; |
| 3409 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3410 | } |
| 3411 | __ Slt(dst, lhs, rhs_reg); |
| 3412 | } |
| 3413 | if (cond == kCondGE) { |
| 3414 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 3415 | // only the slt instruction but no sge. |
| 3416 | __ Xori(dst, dst, 1); |
| 3417 | } |
| 3418 | break; |
| 3419 | |
| 3420 | case kCondLE: |
| 3421 | case kCondGT: |
| 3422 | if (use_imm && IsInt<16>(rhs_imm_plus_one)) { |
| 3423 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3424 | __ Slti(dst, lhs, rhs_imm_plus_one); |
| 3425 | if (cond == kCondGT) { |
| 3426 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 3427 | // only the slti instruction but no sgti. |
| 3428 | __ Xori(dst, dst, 1); |
| 3429 | } |
| 3430 | } else { |
| 3431 | if (use_imm) { |
| 3432 | rhs_reg = TMP; |
| 3433 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3434 | } |
| 3435 | __ Slt(dst, rhs_reg, lhs); |
| 3436 | if (cond == kCondLE) { |
| 3437 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 3438 | // only the slt instruction but no sle. |
| 3439 | __ Xori(dst, dst, 1); |
| 3440 | } |
| 3441 | } |
| 3442 | break; |
| 3443 | |
| 3444 | case kCondB: |
| 3445 | case kCondAE: |
| 3446 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3447 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3448 | // the comparison and thus lets us compare directly with |
| 3449 | // unsigned values in the ranges [0, 0x7fff] and |
| 3450 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3451 | __ Sltiu(dst, lhs, rhs_imm); |
| 3452 | } else { |
| 3453 | if (use_imm) { |
| 3454 | rhs_reg = TMP; |
| 3455 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3456 | } |
| 3457 | __ Sltu(dst, lhs, rhs_reg); |
| 3458 | } |
| 3459 | if (cond == kCondAE) { |
| 3460 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 3461 | // only the sltu instruction but no sgeu. |
| 3462 | __ Xori(dst, dst, 1); |
| 3463 | } |
| 3464 | break; |
| 3465 | |
| 3466 | case kCondBE: |
| 3467 | case kCondA: |
| 3468 | if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) { |
| 3469 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3470 | // Note that this only works if rhs + 1 does not overflow |
| 3471 | // to 0, hence the check above. |
| 3472 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3473 | // the comparison and thus lets us compare directly with |
| 3474 | // unsigned values in the ranges [0, 0x7fff] and |
| 3475 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3476 | __ Sltiu(dst, lhs, rhs_imm_plus_one); |
| 3477 | if (cond == kCondA) { |
| 3478 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 3479 | // only the sltiu instruction but no sgtiu. |
| 3480 | __ Xori(dst, dst, 1); |
| 3481 | } |
| 3482 | } else { |
| 3483 | if (use_imm) { |
| 3484 | rhs_reg = TMP; |
| 3485 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3486 | } |
| 3487 | __ Sltu(dst, rhs_reg, lhs); |
| 3488 | if (cond == kCondBE) { |
| 3489 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 3490 | // only the sltu instruction but no sleu. |
| 3491 | __ Xori(dst, dst, 1); |
| 3492 | } |
| 3493 | } |
| 3494 | break; |
| 3495 | } |
| 3496 | } |
| 3497 | |
| 3498 | void InstructionCodeGeneratorMIPS64::GenerateIntLongCompareAndBranch(IfCondition cond, |
| 3499 | bool is64bit, |
| 3500 | LocationSummary* locations, |
| 3501 | Mips64Label* label) { |
| 3502 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3503 | Location rhs_location = locations->InAt(1); |
| 3504 | GpuRegister rhs_reg = ZERO; |
| 3505 | int64_t rhs_imm = 0; |
| 3506 | bool use_imm = rhs_location.IsConstant(); |
| 3507 | if (use_imm) { |
| 3508 | if (is64bit) { |
| 3509 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3510 | } else { |
| 3511 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3512 | } |
| 3513 | } else { |
| 3514 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3515 | } |
| 3516 | |
| 3517 | if (use_imm && rhs_imm == 0) { |
| 3518 | switch (cond) { |
| 3519 | case kCondEQ: |
| 3520 | case kCondBE: // <= 0 if zero |
| 3521 | __ Beqzc(lhs, label); |
| 3522 | break; |
| 3523 | case kCondNE: |
| 3524 | case kCondA: // > 0 if non-zero |
| 3525 | __ Bnezc(lhs, label); |
| 3526 | break; |
| 3527 | case kCondLT: |
| 3528 | __ Bltzc(lhs, label); |
| 3529 | break; |
| 3530 | case kCondGE: |
| 3531 | __ Bgezc(lhs, label); |
| 3532 | break; |
| 3533 | case kCondLE: |
| 3534 | __ Blezc(lhs, label); |
| 3535 | break; |
| 3536 | case kCondGT: |
| 3537 | __ Bgtzc(lhs, label); |
| 3538 | break; |
| 3539 | case kCondB: // always false |
| 3540 | break; |
| 3541 | case kCondAE: // always true |
| 3542 | __ Bc(label); |
| 3543 | break; |
| 3544 | } |
| 3545 | } else { |
| 3546 | if (use_imm) { |
| 3547 | rhs_reg = TMP; |
| 3548 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3549 | } |
| 3550 | switch (cond) { |
| 3551 | case kCondEQ: |
| 3552 | __ Beqc(lhs, rhs_reg, label); |
| 3553 | break; |
| 3554 | case kCondNE: |
| 3555 | __ Bnec(lhs, rhs_reg, label); |
| 3556 | break; |
| 3557 | case kCondLT: |
| 3558 | __ Bltc(lhs, rhs_reg, label); |
| 3559 | break; |
| 3560 | case kCondGE: |
| 3561 | __ Bgec(lhs, rhs_reg, label); |
| 3562 | break; |
| 3563 | case kCondLE: |
| 3564 | __ Bgec(rhs_reg, lhs, label); |
| 3565 | break; |
| 3566 | case kCondGT: |
| 3567 | __ Bltc(rhs_reg, lhs, label); |
| 3568 | break; |
| 3569 | case kCondB: |
| 3570 | __ Bltuc(lhs, rhs_reg, label); |
| 3571 | break; |
| 3572 | case kCondAE: |
| 3573 | __ Bgeuc(lhs, rhs_reg, label); |
| 3574 | break; |
| 3575 | case kCondBE: |
| 3576 | __ Bgeuc(rhs_reg, lhs, label); |
| 3577 | break; |
| 3578 | case kCondA: |
| 3579 | __ Bltuc(rhs_reg, lhs, label); |
| 3580 | break; |
| 3581 | } |
| 3582 | } |
| 3583 | } |
| 3584 | |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3585 | void InstructionCodeGeneratorMIPS64::GenerateFpCompare(IfCondition cond, |
| 3586 | bool gt_bias, |
| 3587 | Primitive::Type type, |
| 3588 | LocationSummary* locations) { |
| 3589 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3590 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3591 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 3592 | if (type == Primitive::kPrimFloat) { |
| 3593 | switch (cond) { |
| 3594 | case kCondEQ: |
| 3595 | __ CmpEqS(FTMP, lhs, rhs); |
| 3596 | __ Mfc1(dst, FTMP); |
| 3597 | __ Andi(dst, dst, 1); |
| 3598 | break; |
| 3599 | case kCondNE: |
| 3600 | __ CmpEqS(FTMP, lhs, rhs); |
| 3601 | __ Mfc1(dst, FTMP); |
| 3602 | __ Addiu(dst, dst, 1); |
| 3603 | break; |
| 3604 | case kCondLT: |
| 3605 | if (gt_bias) { |
| 3606 | __ CmpLtS(FTMP, lhs, rhs); |
| 3607 | } else { |
| 3608 | __ CmpUltS(FTMP, lhs, rhs); |
| 3609 | } |
| 3610 | __ Mfc1(dst, FTMP); |
| 3611 | __ Andi(dst, dst, 1); |
| 3612 | break; |
| 3613 | case kCondLE: |
| 3614 | if (gt_bias) { |
| 3615 | __ CmpLeS(FTMP, lhs, rhs); |
| 3616 | } else { |
| 3617 | __ CmpUleS(FTMP, lhs, rhs); |
| 3618 | } |
| 3619 | __ Mfc1(dst, FTMP); |
| 3620 | __ Andi(dst, dst, 1); |
| 3621 | break; |
| 3622 | case kCondGT: |
| 3623 | if (gt_bias) { |
| 3624 | __ CmpUltS(FTMP, rhs, lhs); |
| 3625 | } else { |
| 3626 | __ CmpLtS(FTMP, rhs, lhs); |
| 3627 | } |
| 3628 | __ Mfc1(dst, FTMP); |
| 3629 | __ Andi(dst, dst, 1); |
| 3630 | break; |
| 3631 | case kCondGE: |
| 3632 | if (gt_bias) { |
| 3633 | __ CmpUleS(FTMP, rhs, lhs); |
| 3634 | } else { |
| 3635 | __ CmpLeS(FTMP, rhs, lhs); |
| 3636 | } |
| 3637 | __ Mfc1(dst, FTMP); |
| 3638 | __ Andi(dst, dst, 1); |
| 3639 | break; |
| 3640 | default: |
| 3641 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3642 | UNREACHABLE(); |
| 3643 | } |
| 3644 | } else { |
| 3645 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 3646 | switch (cond) { |
| 3647 | case kCondEQ: |
| 3648 | __ CmpEqD(FTMP, lhs, rhs); |
| 3649 | __ Mfc1(dst, FTMP); |
| 3650 | __ Andi(dst, dst, 1); |
| 3651 | break; |
| 3652 | case kCondNE: |
| 3653 | __ CmpEqD(FTMP, lhs, rhs); |
| 3654 | __ Mfc1(dst, FTMP); |
| 3655 | __ Addiu(dst, dst, 1); |
| 3656 | break; |
| 3657 | case kCondLT: |
| 3658 | if (gt_bias) { |
| 3659 | __ CmpLtD(FTMP, lhs, rhs); |
| 3660 | } else { |
| 3661 | __ CmpUltD(FTMP, lhs, rhs); |
| 3662 | } |
| 3663 | __ Mfc1(dst, FTMP); |
| 3664 | __ Andi(dst, dst, 1); |
| 3665 | break; |
| 3666 | case kCondLE: |
| 3667 | if (gt_bias) { |
| 3668 | __ CmpLeD(FTMP, lhs, rhs); |
| 3669 | } else { |
| 3670 | __ CmpUleD(FTMP, lhs, rhs); |
| 3671 | } |
| 3672 | __ Mfc1(dst, FTMP); |
| 3673 | __ Andi(dst, dst, 1); |
| 3674 | break; |
| 3675 | case kCondGT: |
| 3676 | if (gt_bias) { |
| 3677 | __ CmpUltD(FTMP, rhs, lhs); |
| 3678 | } else { |
| 3679 | __ CmpLtD(FTMP, rhs, lhs); |
| 3680 | } |
| 3681 | __ Mfc1(dst, FTMP); |
| 3682 | __ Andi(dst, dst, 1); |
| 3683 | break; |
| 3684 | case kCondGE: |
| 3685 | if (gt_bias) { |
| 3686 | __ CmpUleD(FTMP, rhs, lhs); |
| 3687 | } else { |
| 3688 | __ CmpLeD(FTMP, rhs, lhs); |
| 3689 | } |
| 3690 | __ Mfc1(dst, FTMP); |
| 3691 | __ Andi(dst, dst, 1); |
| 3692 | break; |
| 3693 | default: |
| 3694 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3695 | UNREACHABLE(); |
| 3696 | } |
| 3697 | } |
| 3698 | } |
| 3699 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3700 | void InstructionCodeGeneratorMIPS64::GenerateFpCompareAndBranch(IfCondition cond, |
| 3701 | bool gt_bias, |
| 3702 | Primitive::Type type, |
| 3703 | LocationSummary* locations, |
| 3704 | Mips64Label* label) { |
| 3705 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3706 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 3707 | if (type == Primitive::kPrimFloat) { |
| 3708 | switch (cond) { |
| 3709 | case kCondEQ: |
| 3710 | __ CmpEqS(FTMP, lhs, rhs); |
| 3711 | __ Bc1nez(FTMP, label); |
| 3712 | break; |
| 3713 | case kCondNE: |
| 3714 | __ CmpEqS(FTMP, lhs, rhs); |
| 3715 | __ Bc1eqz(FTMP, label); |
| 3716 | break; |
| 3717 | case kCondLT: |
| 3718 | if (gt_bias) { |
| 3719 | __ CmpLtS(FTMP, lhs, rhs); |
| 3720 | } else { |
| 3721 | __ CmpUltS(FTMP, lhs, rhs); |
| 3722 | } |
| 3723 | __ Bc1nez(FTMP, label); |
| 3724 | break; |
| 3725 | case kCondLE: |
| 3726 | if (gt_bias) { |
| 3727 | __ CmpLeS(FTMP, lhs, rhs); |
| 3728 | } else { |
| 3729 | __ CmpUleS(FTMP, lhs, rhs); |
| 3730 | } |
| 3731 | __ Bc1nez(FTMP, label); |
| 3732 | break; |
| 3733 | case kCondGT: |
| 3734 | if (gt_bias) { |
| 3735 | __ CmpUltS(FTMP, rhs, lhs); |
| 3736 | } else { |
| 3737 | __ CmpLtS(FTMP, rhs, lhs); |
| 3738 | } |
| 3739 | __ Bc1nez(FTMP, label); |
| 3740 | break; |
| 3741 | case kCondGE: |
| 3742 | if (gt_bias) { |
| 3743 | __ CmpUleS(FTMP, rhs, lhs); |
| 3744 | } else { |
| 3745 | __ CmpLeS(FTMP, rhs, lhs); |
| 3746 | } |
| 3747 | __ Bc1nez(FTMP, label); |
| 3748 | break; |
| 3749 | default: |
| 3750 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3751 | } |
| 3752 | } else { |
| 3753 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 3754 | switch (cond) { |
| 3755 | case kCondEQ: |
| 3756 | __ CmpEqD(FTMP, lhs, rhs); |
| 3757 | __ Bc1nez(FTMP, label); |
| 3758 | break; |
| 3759 | case kCondNE: |
| 3760 | __ CmpEqD(FTMP, lhs, rhs); |
| 3761 | __ Bc1eqz(FTMP, label); |
| 3762 | break; |
| 3763 | case kCondLT: |
| 3764 | if (gt_bias) { |
| 3765 | __ CmpLtD(FTMP, lhs, rhs); |
| 3766 | } else { |
| 3767 | __ CmpUltD(FTMP, lhs, rhs); |
| 3768 | } |
| 3769 | __ Bc1nez(FTMP, label); |
| 3770 | break; |
| 3771 | case kCondLE: |
| 3772 | if (gt_bias) { |
| 3773 | __ CmpLeD(FTMP, lhs, rhs); |
| 3774 | } else { |
| 3775 | __ CmpUleD(FTMP, lhs, rhs); |
| 3776 | } |
| 3777 | __ Bc1nez(FTMP, label); |
| 3778 | break; |
| 3779 | case kCondGT: |
| 3780 | if (gt_bias) { |
| 3781 | __ CmpUltD(FTMP, rhs, lhs); |
| 3782 | } else { |
| 3783 | __ CmpLtD(FTMP, rhs, lhs); |
| 3784 | } |
| 3785 | __ Bc1nez(FTMP, label); |
| 3786 | break; |
| 3787 | case kCondGE: |
| 3788 | if (gt_bias) { |
| 3789 | __ CmpUleD(FTMP, rhs, lhs); |
| 3790 | } else { |
| 3791 | __ CmpLeD(FTMP, rhs, lhs); |
| 3792 | } |
| 3793 | __ Bc1nez(FTMP, label); |
| 3794 | break; |
| 3795 | default: |
| 3796 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3797 | } |
| 3798 | } |
| 3799 | } |
| 3800 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3801 | void InstructionCodeGeneratorMIPS64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3802 | size_t condition_input_index, |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3803 | Mips64Label* true_target, |
| 3804 | Mips64Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3805 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3806 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3807 | if (true_target == nullptr && false_target == nullptr) { |
| 3808 | // Nothing to do. The code always falls through. |
| 3809 | return; |
| 3810 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3811 | // Constant condition, statically compared against "true" (integer value 1). |
| 3812 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3813 | if (true_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3814 | __ Bc(true_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3815 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3816 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3817 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3818 | if (false_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3819 | __ Bc(false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3820 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3821 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3822 | return; |
| 3823 | } |
| 3824 | |
| 3825 | // The following code generates these patterns: |
| 3826 | // (1) true_target == nullptr && false_target != nullptr |
| 3827 | // - opposite condition true => branch to false_target |
| 3828 | // (2) true_target != nullptr && false_target == nullptr |
| 3829 | // - condition true => branch to true_target |
| 3830 | // (3) true_target != nullptr && false_target != nullptr |
| 3831 | // - condition true => branch to true_target |
| 3832 | // - branch to false_target |
| 3833 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3834 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3835 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3836 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3837 | if (true_target == nullptr) { |
| 3838 | __ Beqzc(cond_val.AsRegister<GpuRegister>(), false_target); |
| 3839 | } else { |
| 3840 | __ Bnezc(cond_val.AsRegister<GpuRegister>(), true_target); |
| 3841 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3842 | } else { |
| 3843 | // The condition instruction has not been materialized, use its inputs as |
| 3844 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3845 | HCondition* condition = cond->AsCondition(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3846 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 3847 | LocationSummary* locations = cond->GetLocations(); |
| 3848 | IfCondition if_cond = condition->GetCondition(); |
| 3849 | Mips64Label* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3850 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3851 | if (true_target == nullptr) { |
| 3852 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3853 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3854 | } |
| 3855 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3856 | switch (type) { |
| 3857 | default: |
| 3858 | GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ false, locations, branch_target); |
| 3859 | break; |
| 3860 | case Primitive::kPrimLong: |
| 3861 | GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ true, locations, branch_target); |
| 3862 | break; |
| 3863 | case Primitive::kPrimFloat: |
| 3864 | case Primitive::kPrimDouble: |
| 3865 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 3866 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3867 | } |
| 3868 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3869 | |
| 3870 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3871 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3872 | if (true_target != nullptr && false_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3873 | __ Bc(false_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3874 | } |
| 3875 | } |
| 3876 | |
| 3877 | void LocationsBuilderMIPS64::VisitIf(HIf* if_instr) { |
| 3878 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3879 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3880 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3881 | } |
| 3882 | } |
| 3883 | |
| 3884 | void InstructionCodeGeneratorMIPS64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3885 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3886 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3887 | Mips64Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3888 | nullptr : codegen_->GetLabelOf(true_successor); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3889 | Mips64Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3890 | nullptr : codegen_->GetLabelOf(false_successor); |
| 3891 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3892 | } |
| 3893 | |
| 3894 | void LocationsBuilderMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3895 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3896 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3897 | InvokeRuntimeCallingConvention calling_convention; |
| 3898 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3899 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3900 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3901 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3902 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3903 | } |
| 3904 | } |
| 3905 | |
| 3906 | void InstructionCodeGeneratorMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3907 | SlowPathCodeMIPS64* slow_path = |
| 3908 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3909 | GenerateTestAndBranch(deoptimize, |
| 3910 | /* condition_input_index */ 0, |
| 3911 | slow_path->GetEntryLabel(), |
| 3912 | /* false_target */ nullptr); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3913 | } |
| 3914 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 3915 | void LocationsBuilderMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3916 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3917 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3918 | locations->SetOut(Location::RequiresRegister()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3919 | } |
| 3920 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 3921 | void InstructionCodeGeneratorMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3922 | __ LoadFromOffset(kLoadWord, |
| 3923 | flag->GetLocations()->Out().AsRegister<GpuRegister>(), |
| 3924 | SP, |
| 3925 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3926 | } |
| 3927 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3928 | void LocationsBuilderMIPS64::VisitSelect(HSelect* select) { |
| 3929 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 3930 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3931 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3932 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3933 | } else { |
| 3934 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3935 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3936 | } |
| 3937 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3938 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3939 | } |
| 3940 | locations->SetOut(Location::SameAsFirstInput()); |
| 3941 | } |
| 3942 | |
| 3943 | void InstructionCodeGeneratorMIPS64::VisitSelect(HSelect* select) { |
| 3944 | LocationSummary* locations = select->GetLocations(); |
| 3945 | Mips64Label false_target; |
| 3946 | GenerateTestAndBranch(select, |
| 3947 | /* condition_input_index */ 2, |
| 3948 | /* true_target */ nullptr, |
| 3949 | &false_target); |
| 3950 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 3951 | __ Bind(&false_target); |
| 3952 | } |
| 3953 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3954 | void LocationsBuilderMIPS64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3955 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3956 | } |
| 3957 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3958 | void InstructionCodeGeneratorMIPS64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3959 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3960 | } |
| 3961 | |
| 3962 | void CodeGeneratorMIPS64::GenerateNop() { |
| 3963 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3964 | } |
| 3965 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3966 | void LocationsBuilderMIPS64::HandleFieldGet(HInstruction* instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3967 | const FieldInfo& field_info) { |
| 3968 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3969 | bool object_field_get_with_read_barrier = |
| 3970 | kEmitCompilerReadBarrier && (field_type == Primitive::kPrimNot); |
| 3971 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 3972 | instruction, |
| 3973 | object_field_get_with_read_barrier |
| 3974 | ? LocationSummary::kCallOnSlowPath |
| 3975 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 3976 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 3977 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 3978 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3979 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3980 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3981 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3982 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3983 | // The output overlaps in the case of an object field get with |
| 3984 | // read barriers enabled: we do not want the move to overwrite the |
| 3985 | // object's location, as we need it to emit the read barrier. |
| 3986 | locations->SetOut(Location::RequiresRegister(), |
| 3987 | object_field_get_with_read_barrier |
| 3988 | ? Location::kOutputOverlap |
| 3989 | : Location::kNoOutputOverlap); |
| 3990 | } |
| 3991 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 3992 | // We need a temporary register for the read barrier marking slow |
| 3993 | // path in CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier. |
| 3994 | locations->AddTemp(Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3995 | } |
| 3996 | } |
| 3997 | |
| 3998 | void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction, |
| 3999 | const FieldInfo& field_info) { |
| 4000 | Primitive::Type type = field_info.GetFieldType(); |
| 4001 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4002 | Location obj_loc = locations->InAt(0); |
| 4003 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
| 4004 | Location dst_loc = locations->Out(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4005 | LoadOperandType load_type = kLoadUnsignedByte; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4006 | bool is_volatile = field_info.IsVolatile(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4007 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4008 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
| 4009 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4010 | switch (type) { |
| 4011 | case Primitive::kPrimBoolean: |
| 4012 | load_type = kLoadUnsignedByte; |
| 4013 | break; |
| 4014 | case Primitive::kPrimByte: |
| 4015 | load_type = kLoadSignedByte; |
| 4016 | break; |
| 4017 | case Primitive::kPrimShort: |
| 4018 | load_type = kLoadSignedHalfword; |
| 4019 | break; |
| 4020 | case Primitive::kPrimChar: |
| 4021 | load_type = kLoadUnsignedHalfword; |
| 4022 | break; |
| 4023 | case Primitive::kPrimInt: |
| 4024 | case Primitive::kPrimFloat: |
| 4025 | load_type = kLoadWord; |
| 4026 | break; |
| 4027 | case Primitive::kPrimLong: |
| 4028 | case Primitive::kPrimDouble: |
| 4029 | load_type = kLoadDoubleword; |
| 4030 | break; |
| 4031 | case Primitive::kPrimNot: |
| 4032 | load_type = kLoadUnsignedWord; |
| 4033 | break; |
| 4034 | case Primitive::kPrimVoid: |
| 4035 | LOG(FATAL) << "Unreachable type " << type; |
| 4036 | UNREACHABLE(); |
| 4037 | } |
| 4038 | if (!Primitive::IsFloatingPointType(type)) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4039 | DCHECK(dst_loc.IsRegister()); |
| 4040 | GpuRegister dst = dst_loc.AsRegister<GpuRegister>(); |
| 4041 | if (type == Primitive::kPrimNot) { |
| 4042 | // /* HeapReference<Object> */ dst = *(obj + offset) |
| 4043 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4044 | Location temp_loc = locations->GetTemp(0); |
| 4045 | // Note that a potential implicit null check is handled in this |
| 4046 | // CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier call. |
| 4047 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4048 | dst_loc, |
| 4049 | obj, |
| 4050 | offset, |
| 4051 | temp_loc, |
| 4052 | /* needs_null_check */ true); |
| 4053 | if (is_volatile) { |
| 4054 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4055 | } |
| 4056 | } else { |
| 4057 | __ LoadFromOffset(kLoadUnsignedWord, dst, obj, offset, null_checker); |
| 4058 | if (is_volatile) { |
| 4059 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4060 | } |
| 4061 | // If read barriers are enabled, emit read barriers other than |
| 4062 | // Baker's using a slow path (and also unpoison the loaded |
| 4063 | // reference, if heap poisoning is enabled). |
| 4064 | codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset); |
| 4065 | } |
| 4066 | } else { |
| 4067 | __ LoadFromOffset(load_type, dst, obj, offset, null_checker); |
| 4068 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4069 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4070 | DCHECK(dst_loc.IsFpuRegister()); |
| 4071 | FpuRegister dst = dst_loc.AsFpuRegister<FpuRegister>(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4072 | __ LoadFpuFromOffset(load_type, dst, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4073 | } |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4074 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4075 | // Memory barriers, in the case of references, are handled in the |
| 4076 | // previous switch statement. |
| 4077 | if (is_volatile && (type != Primitive::kPrimNot)) { |
| 4078 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4079 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4080 | } |
| 4081 | |
| 4082 | void LocationsBuilderMIPS64::HandleFieldSet(HInstruction* instruction, |
| 4083 | const FieldInfo& field_info ATTRIBUTE_UNUSED) { |
| 4084 | LocationSummary* locations = |
| 4085 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4086 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4087 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4088 | locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4089 | } else { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4090 | locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4091 | } |
| 4092 | } |
| 4093 | |
| 4094 | void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction, |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4095 | const FieldInfo& field_info, |
| 4096 | bool value_can_be_null) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4097 | Primitive::Type type = field_info.GetFieldType(); |
| 4098 | LocationSummary* locations = instruction->GetLocations(); |
| 4099 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4100 | Location value_location = locations->InAt(1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4101 | StoreOperandType store_type = kStoreByte; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4102 | bool is_volatile = field_info.IsVolatile(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4103 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4104 | bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1)); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4105 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
| 4106 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4107 | switch (type) { |
| 4108 | case Primitive::kPrimBoolean: |
| 4109 | case Primitive::kPrimByte: |
| 4110 | store_type = kStoreByte; |
| 4111 | break; |
| 4112 | case Primitive::kPrimShort: |
| 4113 | case Primitive::kPrimChar: |
| 4114 | store_type = kStoreHalfword; |
| 4115 | break; |
| 4116 | case Primitive::kPrimInt: |
| 4117 | case Primitive::kPrimFloat: |
| 4118 | case Primitive::kPrimNot: |
| 4119 | store_type = kStoreWord; |
| 4120 | break; |
| 4121 | case Primitive::kPrimLong: |
| 4122 | case Primitive::kPrimDouble: |
| 4123 | store_type = kStoreDoubleword; |
| 4124 | break; |
| 4125 | case Primitive::kPrimVoid: |
| 4126 | LOG(FATAL) << "Unreachable type " << type; |
| 4127 | UNREACHABLE(); |
| 4128 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4129 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4130 | if (is_volatile) { |
| 4131 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 4132 | } |
| 4133 | |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4134 | if (value_location.IsConstant()) { |
| 4135 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 4136 | __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker); |
| 4137 | } else { |
| 4138 | if (!Primitive::IsFloatingPointType(type)) { |
| 4139 | DCHECK(value_location.IsRegister()); |
| 4140 | GpuRegister src = value_location.AsRegister<GpuRegister>(); |
| 4141 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4142 | // Note that in the case where `value` is a null reference, |
| 4143 | // we do not enter this block, as a null reference does not |
| 4144 | // need poisoning. |
| 4145 | DCHECK_EQ(type, Primitive::kPrimNot); |
| 4146 | __ PoisonHeapReference(TMP, src); |
| 4147 | __ StoreToOffset(store_type, TMP, obj, offset, null_checker); |
| 4148 | } else { |
| 4149 | __ StoreToOffset(store_type, src, obj, offset, null_checker); |
| 4150 | } |
| 4151 | } else { |
| 4152 | DCHECK(value_location.IsFpuRegister()); |
| 4153 | FpuRegister src = value_location.AsFpuRegister<FpuRegister>(); |
| 4154 | __ StoreFpuToOffset(store_type, src, obj, offset, null_checker); |
| 4155 | } |
| 4156 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4157 | |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4158 | if (needs_write_barrier) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4159 | DCHECK(value_location.IsRegister()); |
| 4160 | GpuRegister src = value_location.AsRegister<GpuRegister>(); |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4161 | codegen_->MarkGCCard(obj, src, value_can_be_null); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4162 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4163 | |
| 4164 | if (is_volatile) { |
| 4165 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 4166 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4167 | } |
| 4168 | |
| 4169 | void LocationsBuilderMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4170 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4171 | } |
| 4172 | |
| 4173 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4174 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4175 | } |
| 4176 | |
| 4177 | void LocationsBuilderMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4178 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4179 | } |
| 4180 | |
| 4181 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4182 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4183 | } |
| 4184 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4185 | void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadOneRegister( |
| 4186 | HInstruction* instruction, |
| 4187 | Location out, |
| 4188 | uint32_t offset, |
| 4189 | Location maybe_temp, |
| 4190 | ReadBarrierOption read_barrier_option) { |
| 4191 | GpuRegister out_reg = out.AsRegister<GpuRegister>(); |
| 4192 | if (read_barrier_option == kWithReadBarrier) { |
| 4193 | CHECK(kEmitCompilerReadBarrier); |
| 4194 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 4195 | if (kUseBakerReadBarrier) { |
| 4196 | // Load with fast path based Baker's read barrier. |
| 4197 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4198 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4199 | out, |
| 4200 | out_reg, |
| 4201 | offset, |
| 4202 | maybe_temp, |
| 4203 | /* needs_null_check */ false); |
| 4204 | } else { |
| 4205 | // Load with slow path based read barrier. |
| 4206 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 4207 | // in the following move operation, as we will need it for the |
| 4208 | // read barrier below. |
| 4209 | __ Move(maybe_temp.AsRegister<GpuRegister>(), out_reg); |
| 4210 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4211 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset); |
| 4212 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 4213 | } |
| 4214 | } else { |
| 4215 | // Plain load with no read barrier. |
| 4216 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4217 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset); |
| 4218 | __ MaybeUnpoisonHeapReference(out_reg); |
| 4219 | } |
| 4220 | } |
| 4221 | |
| 4222 | void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadTwoRegisters( |
| 4223 | HInstruction* instruction, |
| 4224 | Location out, |
| 4225 | Location obj, |
| 4226 | uint32_t offset, |
| 4227 | Location maybe_temp, |
| 4228 | ReadBarrierOption read_barrier_option) { |
| 4229 | GpuRegister out_reg = out.AsRegister<GpuRegister>(); |
| 4230 | GpuRegister obj_reg = obj.AsRegister<GpuRegister>(); |
| 4231 | if (read_barrier_option == kWithReadBarrier) { |
| 4232 | CHECK(kEmitCompilerReadBarrier); |
| 4233 | if (kUseBakerReadBarrier) { |
| 4234 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 4235 | // Load with fast path based Baker's read barrier. |
| 4236 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 4237 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4238 | out, |
| 4239 | obj_reg, |
| 4240 | offset, |
| 4241 | maybe_temp, |
| 4242 | /* needs_null_check */ false); |
| 4243 | } else { |
| 4244 | // Load with slow path based read barrier. |
| 4245 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 4246 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset); |
| 4247 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 4248 | } |
| 4249 | } else { |
| 4250 | // Plain load with no read barrier. |
| 4251 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 4252 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset); |
| 4253 | __ MaybeUnpoisonHeapReference(out_reg); |
| 4254 | } |
| 4255 | } |
| 4256 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4257 | void InstructionCodeGeneratorMIPS64::GenerateGcRootFieldLoad( |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4258 | HInstruction* instruction, |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4259 | Location root, |
| 4260 | GpuRegister obj, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4261 | uint32_t offset, |
| 4262 | ReadBarrierOption read_barrier_option) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4263 | GpuRegister root_reg = root.AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4264 | if (read_barrier_option == kWithReadBarrier) { |
| 4265 | DCHECK(kEmitCompilerReadBarrier); |
| 4266 | if (kUseBakerReadBarrier) { |
| 4267 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 4268 | // Baker's read barrier are used: |
| 4269 | // |
| 4270 | // root = obj.field; |
| 4271 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 4272 | // if (temp != null) { |
| 4273 | // root = temp(root) |
| 4274 | // } |
| 4275 | |
| 4276 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 4277 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset); |
| 4278 | static_assert( |
| 4279 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 4280 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 4281 | "have different sizes."); |
| 4282 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 4283 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 4284 | "have different sizes."); |
| 4285 | |
| 4286 | // Slow path marking the GC root `root`. |
| 4287 | Location temp = Location::RegisterLocation(T9); |
| 4288 | SlowPathCodeMIPS64* slow_path = |
| 4289 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathMIPS64( |
| 4290 | instruction, |
| 4291 | root, |
| 4292 | /*entrypoint*/ temp); |
| 4293 | codegen_->AddSlowPath(slow_path); |
| 4294 | |
| 4295 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 4296 | const int32_t entry_point_offset = |
| 4297 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(root.reg() - 1); |
| 4298 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 4299 | // threads are suspended or running a checkpoint. |
| 4300 | __ LoadFromOffset(kLoadDoubleword, temp.AsRegister<GpuRegister>(), TR, entry_point_offset); |
| 4301 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 4302 | // checking GetIsGcMarking. |
| 4303 | __ Bnezc(temp.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 4304 | __ Bind(slow_path->GetExitLabel()); |
| 4305 | } else { |
| 4306 | // GC root loaded through a slow path for read barriers other |
| 4307 | // than Baker's. |
| 4308 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 4309 | __ Daddiu64(root_reg, obj, static_cast<int32_t>(offset)); |
| 4310 | // /* mirror::Object* */ root = root->Read() |
| 4311 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 4312 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4313 | } else { |
| 4314 | // Plain GC root load with no read barrier. |
| 4315 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 4316 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset); |
| 4317 | // Note that GC roots are not affected by heap poisoning, thus we |
| 4318 | // do not have to unpoison `root_reg` here. |
| 4319 | } |
| 4320 | } |
| 4321 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4322 | void CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 4323 | Location ref, |
| 4324 | GpuRegister obj, |
| 4325 | uint32_t offset, |
| 4326 | Location temp, |
| 4327 | bool needs_null_check) { |
| 4328 | DCHECK(kEmitCompilerReadBarrier); |
| 4329 | DCHECK(kUseBakerReadBarrier); |
| 4330 | |
| 4331 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 4332 | Location no_index = Location::NoLocation(); |
| 4333 | ScaleFactor no_scale_factor = TIMES_1; |
| 4334 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 4335 | ref, |
| 4336 | obj, |
| 4337 | offset, |
| 4338 | no_index, |
| 4339 | no_scale_factor, |
| 4340 | temp, |
| 4341 | needs_null_check); |
| 4342 | } |
| 4343 | |
| 4344 | void CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 4345 | Location ref, |
| 4346 | GpuRegister obj, |
| 4347 | uint32_t data_offset, |
| 4348 | Location index, |
| 4349 | Location temp, |
| 4350 | bool needs_null_check) { |
| 4351 | DCHECK(kEmitCompilerReadBarrier); |
| 4352 | DCHECK(kUseBakerReadBarrier); |
| 4353 | |
| 4354 | static_assert( |
| 4355 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4356 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 4357 | // /* HeapReference<Object> */ ref = |
| 4358 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4359 | ScaleFactor scale_factor = TIMES_4; |
| 4360 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 4361 | ref, |
| 4362 | obj, |
| 4363 | data_offset, |
| 4364 | index, |
| 4365 | scale_factor, |
| 4366 | temp, |
| 4367 | needs_null_check); |
| 4368 | } |
| 4369 | |
| 4370 | void CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 4371 | Location ref, |
| 4372 | GpuRegister obj, |
| 4373 | uint32_t offset, |
| 4374 | Location index, |
| 4375 | ScaleFactor scale_factor, |
| 4376 | Location temp, |
| 4377 | bool needs_null_check, |
| 4378 | bool always_update_field) { |
| 4379 | DCHECK(kEmitCompilerReadBarrier); |
| 4380 | DCHECK(kUseBakerReadBarrier); |
| 4381 | |
| 4382 | // In slow path based read barriers, the read barrier call is |
| 4383 | // inserted after the original load. However, in fast path based |
| 4384 | // Baker's read barriers, we need to perform the load of |
| 4385 | // mirror::Object::monitor_ *before* the original reference load. |
| 4386 | // This load-load ordering is required by the read barrier. |
| 4387 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 4388 | // |
| 4389 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 4390 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 4391 | // HeapReference<Object> ref = *src; // Original reference load. |
| 4392 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 4393 | // if (is_gray) { |
| 4394 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 4395 | // } |
| 4396 | // |
| 4397 | // Note: the original implementation in ReadBarrier::Barrier is |
| 4398 | // slightly more complex as it performs additional checks that we do |
| 4399 | // not do here for performance reasons. |
| 4400 | |
| 4401 | GpuRegister ref_reg = ref.AsRegister<GpuRegister>(); |
| 4402 | GpuRegister temp_reg = temp.AsRegister<GpuRegister>(); |
| 4403 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 4404 | |
| 4405 | // /* int32_t */ monitor = obj->monitor_ |
| 4406 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 4407 | if (needs_null_check) { |
| 4408 | MaybeRecordImplicitNullCheck(instruction); |
| 4409 | } |
| 4410 | // /* LockWord */ lock_word = LockWord(monitor) |
| 4411 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 4412 | "art::LockWord and int32_t have different sizes."); |
| 4413 | |
| 4414 | __ Sync(0); // Barrier to prevent load-load reordering. |
| 4415 | |
| 4416 | // The actual reference load. |
| 4417 | if (index.IsValid()) { |
| 4418 | // Load types involving an "index": ArrayGet, |
| 4419 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 4420 | // intrinsics. |
| 4421 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 4422 | if (index.IsConstant()) { |
| 4423 | size_t computed_offset = |
| 4424 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
| 4425 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, computed_offset); |
| 4426 | } else { |
| 4427 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 4428 | if (scale_factor == TIMES_1) { |
| 4429 | __ Daddu(TMP, index_reg, obj); |
| 4430 | } else { |
| 4431 | __ Dlsa(TMP, index_reg, obj, scale_factor); |
| 4432 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4433 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, offset); |
| 4434 | } |
| 4435 | } else { |
| 4436 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 4437 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, offset); |
| 4438 | } |
| 4439 | |
| 4440 | // Object* ref = ref_addr->AsMirrorPtr() |
| 4441 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 4442 | |
| 4443 | // Slow path marking the object `ref` when it is gray. |
| 4444 | SlowPathCodeMIPS64* slow_path; |
| 4445 | if (always_update_field) { |
| 4446 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 only supports address |
| 4447 | // of the form `obj + field_offset`, where `obj` is a register and |
| 4448 | // `field_offset` is a register. Thus `offset` and `scale_factor` |
| 4449 | // above are expected to be null in this code path. |
| 4450 | DCHECK_EQ(offset, 0u); |
| 4451 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
| 4452 | slow_path = new (GetGraph()->GetArena()) |
| 4453 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS64(instruction, |
| 4454 | ref, |
| 4455 | obj, |
| 4456 | /* field_offset */ index, |
| 4457 | temp_reg); |
| 4458 | } else { |
| 4459 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathMIPS64(instruction, ref); |
| 4460 | } |
| 4461 | AddSlowPath(slow_path); |
| 4462 | |
| 4463 | // if (rb_state == ReadBarrier::GrayState()) |
| 4464 | // ref = ReadBarrier::Mark(ref); |
| 4465 | // Given the numeric representation, it's enough to check the low bit of the |
| 4466 | // rb_state. We do that by shifting the bit into the sign bit (31) and |
| 4467 | // performing a branch on less than zero. |
| 4468 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 4469 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 4470 | static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size"); |
| 4471 | __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift); |
| 4472 | __ Bltzc(temp_reg, slow_path->GetEntryLabel()); |
| 4473 | __ Bind(slow_path->GetExitLabel()); |
| 4474 | } |
| 4475 | |
| 4476 | void CodeGeneratorMIPS64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 4477 | Location out, |
| 4478 | Location ref, |
| 4479 | Location obj, |
| 4480 | uint32_t offset, |
| 4481 | Location index) { |
| 4482 | DCHECK(kEmitCompilerReadBarrier); |
| 4483 | |
| 4484 | // Insert a slow path based read barrier *after* the reference load. |
| 4485 | // |
| 4486 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 4487 | // reference will be carried out by the runtime within the slow |
| 4488 | // path. |
| 4489 | // |
| 4490 | // Note that `ref` currently does not get unpoisoned (when heap |
| 4491 | // poisoning is enabled), which is alright as the `ref` argument is |
| 4492 | // not used by the artReadBarrierSlow entry point. |
| 4493 | // |
| 4494 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 4495 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) |
| 4496 | ReadBarrierForHeapReferenceSlowPathMIPS64(instruction, out, ref, obj, offset, index); |
| 4497 | AddSlowPath(slow_path); |
| 4498 | |
| 4499 | __ Bc(slow_path->GetEntryLabel()); |
| 4500 | __ Bind(slow_path->GetExitLabel()); |
| 4501 | } |
| 4502 | |
| 4503 | void CodeGeneratorMIPS64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 4504 | Location out, |
| 4505 | Location ref, |
| 4506 | Location obj, |
| 4507 | uint32_t offset, |
| 4508 | Location index) { |
| 4509 | if (kEmitCompilerReadBarrier) { |
| 4510 | // Baker's read barriers shall be handled by the fast path |
| 4511 | // (CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier). |
| 4512 | DCHECK(!kUseBakerReadBarrier); |
| 4513 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 4514 | // by the runtime within the slow path. |
| 4515 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| 4516 | } else if (kPoisonHeapReferences) { |
| 4517 | __ UnpoisonHeapReference(out.AsRegister<GpuRegister>()); |
| 4518 | } |
| 4519 | } |
| 4520 | |
| 4521 | void CodeGeneratorMIPS64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 4522 | Location out, |
| 4523 | Location root) { |
| 4524 | DCHECK(kEmitCompilerReadBarrier); |
| 4525 | |
| 4526 | // Insert a slow path based read barrier *after* the GC root load. |
| 4527 | // |
| 4528 | // Note that GC roots are not affected by heap poisoning, so we do |
| 4529 | // not need to do anything special for this here. |
| 4530 | SlowPathCodeMIPS64* slow_path = |
| 4531 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathMIPS64(instruction, out, root); |
| 4532 | AddSlowPath(slow_path); |
| 4533 | |
| 4534 | __ Bc(slow_path->GetEntryLabel()); |
| 4535 | __ Bind(slow_path->GetExitLabel()); |
| 4536 | } |
| 4537 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4538 | void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4539 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4540 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 4541 | bool baker_read_barrier_slow_path = false; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4542 | switch (type_check_kind) { |
| 4543 | case TypeCheckKind::kExactCheck: |
| 4544 | case TypeCheckKind::kAbstractClassCheck: |
| 4545 | case TypeCheckKind::kClassHierarchyCheck: |
| 4546 | case TypeCheckKind::kArrayObjectCheck: |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4547 | call_kind = |
| 4548 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 4549 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4550 | break; |
| 4551 | case TypeCheckKind::kArrayCheck: |
| 4552 | case TypeCheckKind::kUnresolvedCheck: |
| 4553 | case TypeCheckKind::kInterfaceCheck: |
| 4554 | call_kind = LocationSummary::kCallOnSlowPath; |
| 4555 | break; |
| 4556 | } |
| 4557 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4558 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 4559 | if (baker_read_barrier_slow_path) { |
| 4560 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 4561 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4562 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4563 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4564 | // The output does overlap inputs. |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4565 | // Note that TypeCheckSlowPathMIPS64 uses this register too. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4566 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4567 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4568 | } |
| 4569 | |
| 4570 | void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4571 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4572 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4573 | Location obj_loc = locations->InAt(0); |
| 4574 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4575 | GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4576 | Location out_loc = locations->Out(); |
| 4577 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 4578 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 4579 | DCHECK_LE(num_temps, 1u); |
| 4580 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4581 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4582 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4583 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4584 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4585 | Mips64Label done; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4586 | SlowPathCodeMIPS64* slow_path = nullptr; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4587 | |
| 4588 | // Return 0 if `obj` is null. |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4589 | // Avoid this check if we know `obj` is not null. |
| 4590 | if (instruction->MustDoNullCheck()) { |
| 4591 | __ Move(out, ZERO); |
| 4592 | __ Beqzc(obj, &done); |
| 4593 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4594 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4595 | switch (type_check_kind) { |
| 4596 | case TypeCheckKind::kExactCheck: { |
| 4597 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4598 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4599 | out_loc, |
| 4600 | obj_loc, |
| 4601 | class_offset, |
| 4602 | maybe_temp_loc, |
| 4603 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4604 | // Classes must be equal for the instanceof to succeed. |
| 4605 | __ Xor(out, out, cls); |
| 4606 | __ Sltiu(out, out, 1); |
| 4607 | break; |
| 4608 | } |
| 4609 | |
| 4610 | case TypeCheckKind::kAbstractClassCheck: { |
| 4611 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4612 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4613 | out_loc, |
| 4614 | obj_loc, |
| 4615 | class_offset, |
| 4616 | maybe_temp_loc, |
| 4617 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4618 | // If the class is abstract, we eagerly fetch the super class of the |
| 4619 | // object to avoid doing a comparison we know will fail. |
| 4620 | Mips64Label loop; |
| 4621 | __ Bind(&loop); |
| 4622 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4623 | GenerateReferenceLoadOneRegister(instruction, |
| 4624 | out_loc, |
| 4625 | super_offset, |
| 4626 | maybe_temp_loc, |
| 4627 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4628 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4629 | __ Beqzc(out, &done); |
| 4630 | __ Bnec(out, cls, &loop); |
| 4631 | __ LoadConst32(out, 1); |
| 4632 | break; |
| 4633 | } |
| 4634 | |
| 4635 | case TypeCheckKind::kClassHierarchyCheck: { |
| 4636 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4637 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4638 | out_loc, |
| 4639 | obj_loc, |
| 4640 | class_offset, |
| 4641 | maybe_temp_loc, |
| 4642 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4643 | // Walk over the class hierarchy to find a match. |
| 4644 | Mips64Label loop, success; |
| 4645 | __ Bind(&loop); |
| 4646 | __ Beqc(out, cls, &success); |
| 4647 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4648 | GenerateReferenceLoadOneRegister(instruction, |
| 4649 | out_loc, |
| 4650 | super_offset, |
| 4651 | maybe_temp_loc, |
| 4652 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4653 | __ Bnezc(out, &loop); |
| 4654 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4655 | __ Bc(&done); |
| 4656 | __ Bind(&success); |
| 4657 | __ LoadConst32(out, 1); |
| 4658 | break; |
| 4659 | } |
| 4660 | |
| 4661 | case TypeCheckKind::kArrayObjectCheck: { |
| 4662 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4663 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4664 | out_loc, |
| 4665 | obj_loc, |
| 4666 | class_offset, |
| 4667 | maybe_temp_loc, |
| 4668 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4669 | // Do an exact check. |
| 4670 | Mips64Label success; |
| 4671 | __ Beqc(out, cls, &success); |
| 4672 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 4673 | // /* HeapReference<Class> */ out = out->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4674 | GenerateReferenceLoadOneRegister(instruction, |
| 4675 | out_loc, |
| 4676 | component_offset, |
| 4677 | maybe_temp_loc, |
| 4678 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4679 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4680 | __ Beqzc(out, &done); |
| 4681 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 4682 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4683 | __ Sltiu(out, out, 1); |
| 4684 | __ Bc(&done); |
| 4685 | __ Bind(&success); |
| 4686 | __ LoadConst32(out, 1); |
| 4687 | break; |
| 4688 | } |
| 4689 | |
| 4690 | case TypeCheckKind::kArrayCheck: { |
| 4691 | // No read barrier since the slow path will retry upon failure. |
| 4692 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4693 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4694 | out_loc, |
| 4695 | obj_loc, |
| 4696 | class_offset, |
| 4697 | maybe_temp_loc, |
| 4698 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4699 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4700 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction, |
| 4701 | /* is_fatal */ false); |
| 4702 | codegen_->AddSlowPath(slow_path); |
| 4703 | __ Bnec(out, cls, slow_path->GetEntryLabel()); |
| 4704 | __ LoadConst32(out, 1); |
| 4705 | break; |
| 4706 | } |
| 4707 | |
| 4708 | case TypeCheckKind::kUnresolvedCheck: |
| 4709 | case TypeCheckKind::kInterfaceCheck: { |
| 4710 | // Note that we indeed only call on slow path, but we always go |
| 4711 | // into the slow path for the unresolved and interface check |
| 4712 | // cases. |
| 4713 | // |
| 4714 | // We cannot directly call the InstanceofNonTrivial runtime |
| 4715 | // entry point without resorting to a type checking slow path |
| 4716 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 4717 | // require to assign fixed registers for the inputs of this |
| 4718 | // HInstanceOf instruction (following the runtime calling |
| 4719 | // convention), which might be cluttered by the potential first |
| 4720 | // read barrier emission at the beginning of this method. |
| 4721 | // |
| 4722 | // TODO: Introduce a new runtime entry point taking the object |
| 4723 | // to test (instead of its class) as argument, and let it deal |
| 4724 | // with the read barrier issues. This will let us refactor this |
| 4725 | // case of the `switch` code as it was previously (with a direct |
| 4726 | // call to the runtime not using a type checking slow path). |
| 4727 | // This should also be beneficial for the other cases above. |
| 4728 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4729 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction, |
| 4730 | /* is_fatal */ false); |
| 4731 | codegen_->AddSlowPath(slow_path); |
| 4732 | __ Bc(slow_path->GetEntryLabel()); |
| 4733 | break; |
| 4734 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4735 | } |
| 4736 | |
| 4737 | __ Bind(&done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4738 | |
| 4739 | if (slow_path != nullptr) { |
| 4740 | __ Bind(slow_path->GetExitLabel()); |
| 4741 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4742 | } |
| 4743 | |
| 4744 | void LocationsBuilderMIPS64::VisitIntConstant(HIntConstant* constant) { |
| 4745 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4746 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4747 | } |
| 4748 | |
| 4749 | void InstructionCodeGeneratorMIPS64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 4750 | // Will be generated at use site. |
| 4751 | } |
| 4752 | |
| 4753 | void LocationsBuilderMIPS64::VisitNullConstant(HNullConstant* constant) { |
| 4754 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4755 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4756 | } |
| 4757 | |
| 4758 | void InstructionCodeGeneratorMIPS64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 4759 | // Will be generated at use site. |
| 4760 | } |
| 4761 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4762 | void LocationsBuilderMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4763 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4764 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4765 | // the method_idx. |
| 4766 | HandleInvoke(invoke); |
| 4767 | } |
| 4768 | |
| 4769 | void InstructionCodeGeneratorMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4770 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 4771 | } |
| 4772 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4773 | void LocationsBuilderMIPS64::HandleInvoke(HInvoke* invoke) { |
| 4774 | InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor; |
| 4775 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 4776 | } |
| 4777 | |
| 4778 | void LocationsBuilderMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4779 | HandleInvoke(invoke); |
| 4780 | // The register T0 is required to be used for the hidden argument in |
| 4781 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
| 4782 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0)); |
| 4783 | } |
| 4784 | |
| 4785 | void InstructionCodeGeneratorMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4786 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 4787 | GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4788 | Location receiver = invoke->GetLocations()->InAt(0); |
| 4789 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4790 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4791 | |
| 4792 | // Set the hidden argument. |
| 4793 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<GpuRegister>(), |
| 4794 | invoke->GetDexMethodIndex()); |
| 4795 | |
| 4796 | // temp = object->GetClass(); |
| 4797 | if (receiver.IsStackSlot()) { |
| 4798 | __ LoadFromOffset(kLoadUnsignedWord, temp, SP, receiver.GetStackIndex()); |
| 4799 | __ LoadFromOffset(kLoadUnsignedWord, temp, temp, class_offset); |
| 4800 | } else { |
| 4801 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset); |
| 4802 | } |
| 4803 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4804 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4805 | // emit a read barrier for the previous class reference load. |
| 4806 | // However this is not required in practice, as this is an |
| 4807 | // intermediate/temporary reference and because the current |
| 4808 | // concurrent copying collector keeps the from-space memory |
| 4809 | // intact/accessible until the end of the marking phase (the |
| 4810 | // concurrent copying collector may not in the future). |
| 4811 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4812 | __ LoadFromOffset(kLoadDoubleword, temp, temp, |
| 4813 | mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value()); |
| 4814 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4815 | invoke->GetImtIndex(), kMips64PointerSize)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4816 | // temp = temp->GetImtEntryAt(method_offset); |
| 4817 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); |
| 4818 | // T9 = temp->GetEntryPoint(); |
| 4819 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); |
| 4820 | // T9(); |
| 4821 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4822 | __ Nop(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4823 | DCHECK(!codegen_->IsLeafMethod()); |
| 4824 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4825 | } |
| 4826 | |
| 4827 | void LocationsBuilderMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 4828 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); |
| 4829 | if (intrinsic.TryDispatch(invoke)) { |
| 4830 | return; |
| 4831 | } |
| 4832 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4833 | HandleInvoke(invoke); |
| 4834 | } |
| 4835 | |
| 4836 | void LocationsBuilderMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4837 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4838 | // art::PrepareForRegisterAllocation. |
| 4839 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4840 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 4841 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); |
| 4842 | if (intrinsic.TryDispatch(invoke)) { |
| 4843 | return; |
| 4844 | } |
| 4845 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4846 | HandleInvoke(invoke); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4847 | } |
| 4848 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4849 | void LocationsBuilderMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4850 | HandleInvoke(invoke); |
| 4851 | } |
| 4852 | |
| 4853 | void InstructionCodeGeneratorMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4854 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 4855 | } |
| 4856 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 4857 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS64* codegen) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4858 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 4859 | IntrinsicCodeGeneratorMIPS64 intrinsic(codegen); |
| 4860 | intrinsic.Dispatch(invoke); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4861 | return true; |
| 4862 | } |
| 4863 | return false; |
| 4864 | } |
| 4865 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4866 | HLoadString::LoadKind CodeGeneratorMIPS64::GetSupportedLoadStringKind( |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4867 | HLoadString::LoadKind desired_string_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4868 | bool fallback_load = false; |
| 4869 | switch (desired_string_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4870 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4871 | case HLoadString::LoadKind::kBssEntry: |
| 4872 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4873 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4874 | case HLoadString::LoadKind::kJitTableAddress: |
| 4875 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4876 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4877 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4878 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4879 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4880 | } |
| 4881 | if (fallback_load) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4882 | desired_string_load_kind = HLoadString::LoadKind::kRuntimeCall; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4883 | } |
| 4884 | return desired_string_load_kind; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4885 | } |
| 4886 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4887 | HLoadClass::LoadKind CodeGeneratorMIPS64::GetSupportedLoadClassKind( |
| 4888 | HLoadClass::LoadKind desired_class_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4889 | bool fallback_load = false; |
| 4890 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4891 | case HLoadClass::LoadKind::kInvalid: |
| 4892 | LOG(FATAL) << "UNREACHABLE"; |
| 4893 | UNREACHABLE(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4894 | case HLoadClass::LoadKind::kReferrersClass: |
| 4895 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4896 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4897 | case HLoadClass::LoadKind::kBssEntry: |
| 4898 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4899 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4900 | case HLoadClass::LoadKind::kJitTableAddress: |
| 4901 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4902 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4903 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4904 | case HLoadClass::LoadKind::kRuntimeCall: |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4905 | break; |
| 4906 | } |
| 4907 | if (fallback_load) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4908 | desired_class_load_kind = HLoadClass::LoadKind::kRuntimeCall; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4909 | } |
| 4910 | return desired_class_load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4911 | } |
| 4912 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4913 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4914 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4915 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 4916 | // On MIPS64 we support all dispatch types. |
| 4917 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4918 | } |
| 4919 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4920 | void CodeGeneratorMIPS64::GenerateStaticOrDirectCall( |
| 4921 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4922 | // 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] | 4923 | 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] | 4924 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 4925 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
| 4926 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 4927 | switch (method_load_kind) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4928 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4929 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4930 | uint32_t offset = |
| 4931 | GetThreadOffset<kMips64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4932 | __ LoadFromOffset(kLoadDoubleword, |
| 4933 | temp.AsRegister<GpuRegister>(), |
| 4934 | TR, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4935 | offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4936 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4937 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4938 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4939 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4940 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4941 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4942 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4943 | CodeGeneratorMIPS64::PcRelativePatchInfo* info = |
| 4944 | NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
| 4945 | EmitPcRelativeAddressPlaceholderHigh(info, AT); |
| 4946 | __ Daddiu(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678); |
| 4947 | break; |
| 4948 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4949 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 4950 | __ LoadLiteral(temp.AsRegister<GpuRegister>(), |
| 4951 | kLoadDoubleword, |
| 4952 | DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4953 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4954 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
| 4955 | PcRelativePatchInfo* info = NewMethodBssEntryPatch( |
| 4956 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex())); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 4957 | EmitPcRelativeAddressPlaceholderHigh(info, AT); |
| 4958 | __ Ld(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678); |
| 4959 | break; |
| 4960 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4961 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4962 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4963 | return; // No code pointer retrieval; the runtime performs the call directly. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4964 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4965 | } |
| 4966 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 4967 | switch (code_ptr_location) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4968 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 4969 | __ Balc(&frame_entry_label_); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4970 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4971 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4972 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
| 4973 | __ LoadFromOffset(kLoadDoubleword, |
| 4974 | T9, |
| 4975 | callee_method.AsRegister<GpuRegister>(), |
| 4976 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4977 | kMips64PointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4978 | // T9() |
| 4979 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4980 | __ Nop(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4981 | break; |
| 4982 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4983 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4984 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4985 | DCHECK(!IsLeafMethod()); |
| 4986 | } |
| 4987 | |
| 4988 | void InstructionCodeGeneratorMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4989 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4990 | // art::PrepareForRegisterAllocation. |
| 4991 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4992 | |
| 4993 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4994 | return; |
| 4995 | } |
| 4996 | |
| 4997 | LocationSummary* locations = invoke->GetLocations(); |
| 4998 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 4999 | locations->HasTemps() |
| 5000 | ? locations->GetTemp(0) |
| 5001 | : Location::NoLocation()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5002 | } |
| 5003 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5004 | void CodeGeneratorMIPS64::GenerateVirtualCall( |
| 5005 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5006 | // Use the calling convention instead of the location of the receiver, as |
| 5007 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 5008 | // slow path, the arguments have been moved to the right place, so here we are |
| 5009 | // guaranteed that the receiver is the first register of the calling convention. |
| 5010 | InvokeDexCallingConvention calling_convention; |
| 5011 | GpuRegister receiver = calling_convention.GetRegisterAt(0); |
| 5012 | |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 5013 | GpuRegister temp = temp_location.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5014 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 5015 | invoke->GetVTableIndex(), kMips64PointerSize).SizeValue(); |
| 5016 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5017 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5018 | |
| 5019 | // temp = object->GetClass(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5020 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver, class_offset); |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 5021 | MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5022 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 5023 | // emit a read barrier for the previous class reference load. |
| 5024 | // However this is not required in practice, as this is an |
| 5025 | // intermediate/temporary reference and because the current |
| 5026 | // concurrent copying collector keeps the from-space memory |
| 5027 | // intact/accessible until the end of the marking phase (the |
| 5028 | // concurrent copying collector may not in the future). |
| 5029 | __ MaybeUnpoisonHeapReference(temp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5030 | // temp = temp->GetMethodAt(method_offset); |
| 5031 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); |
| 5032 | // T9 = temp->GetEntryPoint(); |
| 5033 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); |
| 5034 | // T9(); |
| 5035 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 5036 | __ Nop(); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5037 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 5038 | } |
| 5039 | |
| 5040 | void InstructionCodeGeneratorMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 5041 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 5042 | return; |
| 5043 | } |
| 5044 | |
| 5045 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5046 | DCHECK(!codegen_->IsLeafMethod()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5047 | } |
| 5048 | |
| 5049 | void LocationsBuilderMIPS64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5050 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5051 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5052 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5053 | Location loc = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 5054 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary(cls, loc, loc); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5055 | return; |
| 5056 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5057 | DCHECK(!cls->NeedsAccessCheck()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5058 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5059 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5060 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5061 | ? LocationSummary::kCallOnSlowPath |
| 5062 | : LocationSummary::kNoCall; |
| 5063 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5064 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| 5065 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5066 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5067 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5068 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5069 | } |
| 5070 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5071 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 5072 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5073 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 5074 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5075 | InvokeRuntimeCallingConvention calling_convention; |
| 5076 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5077 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5078 | } else { |
| 5079 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5080 | } |
| 5081 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5082 | } |
| 5083 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5084 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5085 | // move. |
| 5086 | void InstructionCodeGeneratorMIPS64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5087 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5088 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5089 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5090 | return; |
| 5091 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5092 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5093 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5094 | LocationSummary* locations = cls->GetLocations(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5095 | Location out_loc = locations->Out(); |
| 5096 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 5097 | GpuRegister current_method_reg = ZERO; |
| 5098 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5099 | load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5100 | current_method_reg = locations->InAt(0).AsRegister<GpuRegister>(); |
| 5101 | } |
| 5102 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5103 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5104 | ? kWithoutReadBarrier |
| 5105 | : kCompilerReadBarrierOption; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5106 | bool generate_null_check = false; |
| 5107 | switch (load_kind) { |
| 5108 | case HLoadClass::LoadKind::kReferrersClass: |
| 5109 | DCHECK(!cls->CanCallRuntime()); |
| 5110 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5111 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5112 | GenerateGcRootFieldLoad(cls, |
| 5113 | out_loc, |
| 5114 | current_method_reg, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5115 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 5116 | read_barrier_option); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5117 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5118 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5119 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5120 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5121 | CodeGeneratorMIPS64::PcRelativePatchInfo* info = |
| 5122 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 5123 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info, AT); |
| 5124 | __ Daddiu(out, AT, /* placeholder */ 0x5678); |
| 5125 | break; |
| 5126 | } |
| 5127 | case HLoadClass::LoadKind::kBootImageAddress: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5128 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5129 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5130 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 5131 | DCHECK_NE(address, 0u); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5132 | __ LoadLiteral(out, |
| 5133 | kLoadUnsignedWord, |
| 5134 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5135 | break; |
| 5136 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5137 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5138 | CodeGeneratorMIPS64::PcRelativePatchInfo* info = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5139 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5140 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info, out); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5141 | GenerateGcRootFieldLoad(cls, out_loc, out, /* placeholder */ 0x5678, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5142 | generate_null_check = true; |
| 5143 | break; |
| 5144 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 5145 | case HLoadClass::LoadKind::kJitTableAddress: |
| 5146 | __ LoadLiteral(out, |
| 5147 | kLoadUnsignedWord, |
| 5148 | codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 5149 | cls->GetTypeIndex(), |
| 5150 | cls->GetClass())); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5151 | GenerateGcRootFieldLoad(cls, out_loc, out, 0, read_barrier_option); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5152 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5153 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5154 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5155 | LOG(FATAL) << "UNREACHABLE"; |
| 5156 | UNREACHABLE(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5157 | } |
| 5158 | |
| 5159 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5160 | DCHECK(cls->CanCallRuntime()); |
| 5161 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64( |
| 5162 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5163 | codegen_->AddSlowPath(slow_path); |
| 5164 | if (generate_null_check) { |
| 5165 | __ Beqzc(out, slow_path->GetEntryLabel()); |
| 5166 | } |
| 5167 | if (cls->MustGenerateClinitCheck()) { |
| 5168 | GenerateClassInitializationCheck(slow_path, out); |
| 5169 | } else { |
| 5170 | __ Bind(slow_path->GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5171 | } |
| 5172 | } |
| 5173 | } |
| 5174 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5175 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5176 | return Thread::ExceptionOffset<kMips64PointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5177 | } |
| 5178 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5179 | void LocationsBuilderMIPS64::VisitLoadException(HLoadException* load) { |
| 5180 | LocationSummary* locations = |
| 5181 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5182 | locations->SetOut(Location::RequiresRegister()); |
| 5183 | } |
| 5184 | |
| 5185 | void InstructionCodeGeneratorMIPS64::VisitLoadException(HLoadException* load) { |
| 5186 | GpuRegister out = load->GetLocations()->Out().AsRegister<GpuRegister>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5187 | __ LoadFromOffset(kLoadUnsignedWord, out, TR, GetExceptionTlsOffset()); |
| 5188 | } |
| 5189 | |
| 5190 | void LocationsBuilderMIPS64::VisitClearException(HClearException* clear) { |
| 5191 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5192 | } |
| 5193 | |
| 5194 | void InstructionCodeGeneratorMIPS64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5195 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5196 | } |
| 5197 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5198 | void LocationsBuilderMIPS64::VisitLoadString(HLoadString* load) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5199 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 5200 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5201 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5202 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5203 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5204 | locations->SetOut(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5205 | } else { |
| 5206 | locations->SetOut(Location::RequiresRegister()); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5207 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 5208 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5209 | // Rely on the pResolveString and marking to save everything we need. |
| 5210 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5211 | InvokeRuntimeCallingConvention calling_convention; |
| 5212 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5213 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5214 | } else { |
| 5215 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5216 | } |
| 5217 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5218 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5219 | } |
| 5220 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5221 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5222 | // move. |
| 5223 | void InstructionCodeGeneratorMIPS64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5224 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 5225 | LocationSummary* locations = load->GetLocations(); |
| 5226 | Location out_loc = locations->Out(); |
| 5227 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 5228 | |
| 5229 | switch (load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5230 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 5231 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| 5232 | CodeGeneratorMIPS64::PcRelativePatchInfo* info = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5233 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5234 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info, AT); |
| 5235 | __ Daddiu(out, AT, /* placeholder */ 0x5678); |
| 5236 | return; // No dex cache slow path. |
| 5237 | } |
| 5238 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5239 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5240 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5241 | DCHECK_NE(address, 0u); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5242 | __ LoadLiteral(out, |
| 5243 | kLoadUnsignedWord, |
| 5244 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5245 | return; // No dex cache slow path. |
| 5246 | } |
| 5247 | case HLoadString::LoadKind::kBssEntry: { |
| 5248 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 5249 | CodeGeneratorMIPS64::PcRelativePatchInfo* info = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5250 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5251 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info, out); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5252 | GenerateGcRootFieldLoad(load, |
| 5253 | out_loc, |
| 5254 | out, |
| 5255 | /* placeholder */ 0x5678, |
| 5256 | kCompilerReadBarrierOption); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5257 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS64(load); |
| 5258 | codegen_->AddSlowPath(slow_path); |
| 5259 | __ Beqzc(out, slow_path->GetEntryLabel()); |
| 5260 | __ Bind(slow_path->GetExitLabel()); |
| 5261 | return; |
| 5262 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 5263 | case HLoadString::LoadKind::kJitTableAddress: |
| 5264 | __ LoadLiteral(out, |
| 5265 | kLoadUnsignedWord, |
| 5266 | codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
| 5267 | load->GetStringIndex(), |
| 5268 | load->GetString())); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5269 | GenerateGcRootFieldLoad(load, out_loc, out, 0, kCompilerReadBarrierOption); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 5270 | return; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5271 | default: |
| 5272 | break; |
| 5273 | } |
| 5274 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5275 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5276 | DCHECK(load_kind == HLoadString::LoadKind::kRuntimeCall); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5277 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 5278 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5279 | __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
| 5280 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5281 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5282 | } |
| 5283 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5284 | void LocationsBuilderMIPS64::VisitLongConstant(HLongConstant* constant) { |
| 5285 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5286 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5287 | } |
| 5288 | |
| 5289 | void InstructionCodeGeneratorMIPS64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 5290 | // Will be generated at use site. |
| 5291 | } |
| 5292 | |
| 5293 | void LocationsBuilderMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5294 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5295 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5296 | InvokeRuntimeCallingConvention calling_convention; |
| 5297 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5298 | } |
| 5299 | |
| 5300 | void InstructionCodeGeneratorMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 5301 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5302 | instruction, |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 5303 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5304 | if (instruction->IsEnter()) { |
| 5305 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5306 | } else { |
| 5307 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5308 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5309 | } |
| 5310 | |
| 5311 | void LocationsBuilderMIPS64::VisitMul(HMul* mul) { |
| 5312 | LocationSummary* locations = |
| 5313 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 5314 | switch (mul->GetResultType()) { |
| 5315 | case Primitive::kPrimInt: |
| 5316 | case Primitive::kPrimLong: |
| 5317 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5318 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5319 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5320 | break; |
| 5321 | |
| 5322 | case Primitive::kPrimFloat: |
| 5323 | case Primitive::kPrimDouble: |
| 5324 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5325 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5326 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5327 | break; |
| 5328 | |
| 5329 | default: |
| 5330 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5331 | } |
| 5332 | } |
| 5333 | |
| 5334 | void InstructionCodeGeneratorMIPS64::VisitMul(HMul* instruction) { |
| 5335 | Primitive::Type type = instruction->GetType(); |
| 5336 | LocationSummary* locations = instruction->GetLocations(); |
| 5337 | |
| 5338 | switch (type) { |
| 5339 | case Primitive::kPrimInt: |
| 5340 | case Primitive::kPrimLong: { |
| 5341 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 5342 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 5343 | GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>(); |
| 5344 | if (type == Primitive::kPrimInt) |
| 5345 | __ MulR6(dst, lhs, rhs); |
| 5346 | else |
| 5347 | __ Dmul(dst, lhs, rhs); |
| 5348 | break; |
| 5349 | } |
| 5350 | case Primitive::kPrimFloat: |
| 5351 | case Primitive::kPrimDouble: { |
| 5352 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 5353 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 5354 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 5355 | if (type == Primitive::kPrimFloat) |
| 5356 | __ MulS(dst, lhs, rhs); |
| 5357 | else |
| 5358 | __ MulD(dst, lhs, rhs); |
| 5359 | break; |
| 5360 | } |
| 5361 | default: |
| 5362 | LOG(FATAL) << "Unexpected mul type " << type; |
| 5363 | } |
| 5364 | } |
| 5365 | |
| 5366 | void LocationsBuilderMIPS64::VisitNeg(HNeg* neg) { |
| 5367 | LocationSummary* locations = |
| 5368 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 5369 | switch (neg->GetResultType()) { |
| 5370 | case Primitive::kPrimInt: |
| 5371 | case Primitive::kPrimLong: |
| 5372 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5373 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5374 | break; |
| 5375 | |
| 5376 | case Primitive::kPrimFloat: |
| 5377 | case Primitive::kPrimDouble: |
| 5378 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5379 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5380 | break; |
| 5381 | |
| 5382 | default: |
| 5383 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5384 | } |
| 5385 | } |
| 5386 | |
| 5387 | void InstructionCodeGeneratorMIPS64::VisitNeg(HNeg* instruction) { |
| 5388 | Primitive::Type type = instruction->GetType(); |
| 5389 | LocationSummary* locations = instruction->GetLocations(); |
| 5390 | |
| 5391 | switch (type) { |
| 5392 | case Primitive::kPrimInt: |
| 5393 | case Primitive::kPrimLong: { |
| 5394 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 5395 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 5396 | if (type == Primitive::kPrimInt) |
| 5397 | __ Subu(dst, ZERO, src); |
| 5398 | else |
| 5399 | __ Dsubu(dst, ZERO, src); |
| 5400 | break; |
| 5401 | } |
| 5402 | case Primitive::kPrimFloat: |
| 5403 | case Primitive::kPrimDouble: { |
| 5404 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 5405 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 5406 | if (type == Primitive::kPrimFloat) |
| 5407 | __ NegS(dst, src); |
| 5408 | else |
| 5409 | __ NegD(dst, src); |
| 5410 | break; |
| 5411 | } |
| 5412 | default: |
| 5413 | LOG(FATAL) << "Unexpected neg type " << type; |
| 5414 | } |
| 5415 | } |
| 5416 | |
| 5417 | void LocationsBuilderMIPS64::VisitNewArray(HNewArray* instruction) { |
| 5418 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5419 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5420 | InvokeRuntimeCallingConvention calling_convention; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5421 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5422 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5423 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5424 | } |
| 5425 | |
| 5426 | void InstructionCodeGeneratorMIPS64::VisitNewArray(HNewArray* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5427 | // Note: if heap poisoning is enabled, the entry point takes care |
| 5428 | // of poisoning the reference. |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5429 | codegen_->InvokeRuntime(kQuickAllocArrayResolved, instruction, instruction->GetDexPc()); |
| 5430 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5431 | } |
| 5432 | |
| 5433 | void LocationsBuilderMIPS64::VisitNewInstance(HNewInstance* instruction) { |
| 5434 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5435 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5436 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5437 | if (instruction->IsStringAlloc()) { |
| 5438 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 5439 | } else { |
| 5440 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5441 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5442 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 5443 | } |
| 5444 | |
| 5445 | void InstructionCodeGeneratorMIPS64::VisitNewInstance(HNewInstance* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5446 | // Note: if heap poisoning is enabled, the entry point takes care |
| 5447 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5448 | if (instruction->IsStringAlloc()) { |
| 5449 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5450 | GpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<GpuRegister>(); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 5451 | MemberOffset code_offset = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5452 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5453 | __ LoadFromOffset(kLoadDoubleword, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 5454 | __ LoadFromOffset(kLoadDoubleword, T9, temp, code_offset.Int32Value()); |
| 5455 | __ Jalr(T9); |
| 5456 | __ Nop(); |
| 5457 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5458 | } else { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 5459 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 5460 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5461 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5462 | } |
| 5463 | |
| 5464 | void LocationsBuilderMIPS64::VisitNot(HNot* instruction) { |
| 5465 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5466 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5467 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5468 | } |
| 5469 | |
| 5470 | void InstructionCodeGeneratorMIPS64::VisitNot(HNot* instruction) { |
| 5471 | Primitive::Type type = instruction->GetType(); |
| 5472 | LocationSummary* locations = instruction->GetLocations(); |
| 5473 | |
| 5474 | switch (type) { |
| 5475 | case Primitive::kPrimInt: |
| 5476 | case Primitive::kPrimLong: { |
| 5477 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 5478 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 5479 | __ Nor(dst, src, ZERO); |
| 5480 | break; |
| 5481 | } |
| 5482 | |
| 5483 | default: |
| 5484 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5485 | } |
| 5486 | } |
| 5487 | |
| 5488 | void LocationsBuilderMIPS64::VisitBooleanNot(HBooleanNot* instruction) { |
| 5489 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5490 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5491 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5492 | } |
| 5493 | |
| 5494 | void InstructionCodeGeneratorMIPS64::VisitBooleanNot(HBooleanNot* instruction) { |
| 5495 | LocationSummary* locations = instruction->GetLocations(); |
| 5496 | __ Xori(locations->Out().AsRegister<GpuRegister>(), |
| 5497 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 5498 | 1); |
| 5499 | } |
| 5500 | |
| 5501 | void LocationsBuilderMIPS64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5502 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5503 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5504 | } |
| 5505 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5506 | void CodeGeneratorMIPS64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5507 | if (CanMoveNullCheckToUser(instruction)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5508 | return; |
| 5509 | } |
| 5510 | Location obj = instruction->GetLocations()->InAt(0); |
| 5511 | |
| 5512 | __ Lw(ZERO, obj.AsRegister<GpuRegister>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5513 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5514 | } |
| 5515 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5516 | void CodeGeneratorMIPS64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5517 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5518 | AddSlowPath(slow_path); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5519 | |
| 5520 | Location obj = instruction->GetLocations()->InAt(0); |
| 5521 | |
| 5522 | __ Beqzc(obj.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 5523 | } |
| 5524 | |
| 5525 | void InstructionCodeGeneratorMIPS64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5526 | codegen_->GenerateNullCheck(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5527 | } |
| 5528 | |
| 5529 | void LocationsBuilderMIPS64::VisitOr(HOr* instruction) { |
| 5530 | HandleBinaryOp(instruction); |
| 5531 | } |
| 5532 | |
| 5533 | void InstructionCodeGeneratorMIPS64::VisitOr(HOr* instruction) { |
| 5534 | HandleBinaryOp(instruction); |
| 5535 | } |
| 5536 | |
| 5537 | void LocationsBuilderMIPS64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5538 | LOG(FATAL) << "Unreachable"; |
| 5539 | } |
| 5540 | |
| 5541 | void InstructionCodeGeneratorMIPS64::VisitParallelMove(HParallelMove* instruction) { |
| 5542 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5543 | } |
| 5544 | |
| 5545 | void LocationsBuilderMIPS64::VisitParameterValue(HParameterValue* instruction) { |
| 5546 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5547 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5548 | if (location.IsStackSlot()) { |
| 5549 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5550 | } else if (location.IsDoubleStackSlot()) { |
| 5551 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5552 | } |
| 5553 | locations->SetOut(location); |
| 5554 | } |
| 5555 | |
| 5556 | void InstructionCodeGeneratorMIPS64::VisitParameterValue(HParameterValue* instruction |
| 5557 | ATTRIBUTE_UNUSED) { |
| 5558 | // Nothing to do, the parameter is already at its location. |
| 5559 | } |
| 5560 | |
| 5561 | void LocationsBuilderMIPS64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5562 | LocationSummary* locations = |
| 5563 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5564 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 5565 | } |
| 5566 | |
| 5567 | void InstructionCodeGeneratorMIPS64::VisitCurrentMethod(HCurrentMethod* instruction |
| 5568 | ATTRIBUTE_UNUSED) { |
| 5569 | // Nothing to do, the method is already at its location. |
| 5570 | } |
| 5571 | |
| 5572 | void LocationsBuilderMIPS64::VisitPhi(HPhi* instruction) { |
| 5573 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5574 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5575 | locations->SetInAt(i, Location::Any()); |
| 5576 | } |
| 5577 | locations->SetOut(Location::Any()); |
| 5578 | } |
| 5579 | |
| 5580 | void InstructionCodeGeneratorMIPS64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 5581 | LOG(FATAL) << "Unreachable"; |
| 5582 | } |
| 5583 | |
| 5584 | void LocationsBuilderMIPS64::VisitRem(HRem* rem) { |
| 5585 | Primitive::Type type = rem->GetResultType(); |
| 5586 | LocationSummary::CallKind call_kind = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5587 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 5588 | : LocationSummary::kNoCall; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5589 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 5590 | |
| 5591 | switch (type) { |
| 5592 | case Primitive::kPrimInt: |
| 5593 | case Primitive::kPrimLong: |
| 5594 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 5595 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5596 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5597 | break; |
| 5598 | |
| 5599 | case Primitive::kPrimFloat: |
| 5600 | case Primitive::kPrimDouble: { |
| 5601 | InvokeRuntimeCallingConvention calling_convention; |
| 5602 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 5603 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 5604 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5605 | break; |
| 5606 | } |
| 5607 | |
| 5608 | default: |
| 5609 | LOG(FATAL) << "Unexpected rem type " << type; |
| 5610 | } |
| 5611 | } |
| 5612 | |
| 5613 | void InstructionCodeGeneratorMIPS64::VisitRem(HRem* instruction) { |
| 5614 | Primitive::Type type = instruction->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5615 | |
| 5616 | switch (type) { |
| 5617 | case Primitive::kPrimInt: |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 5618 | case Primitive::kPrimLong: |
| 5619 | GenerateDivRemIntegral(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5620 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5621 | |
| 5622 | case Primitive::kPrimFloat: |
| 5623 | case Primitive::kPrimDouble: { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 5624 | QuickEntrypointEnum entrypoint = (type == Primitive::kPrimFloat) ? kQuickFmodf : kQuickFmod; |
| 5625 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5626 | if (type == Primitive::kPrimFloat) { |
| 5627 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 5628 | } else { |
| 5629 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 5630 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5631 | break; |
| 5632 | } |
| 5633 | default: |
| 5634 | LOG(FATAL) << "Unexpected rem type " << type; |
| 5635 | } |
| 5636 | } |
| 5637 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5638 | void LocationsBuilderMIPS64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 5639 | constructor_fence->SetLocations(nullptr); |
| 5640 | } |
| 5641 | |
| 5642 | void InstructionCodeGeneratorMIPS64::VisitConstructorFence( |
| 5643 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 5644 | GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 5645 | } |
| 5646 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5647 | void LocationsBuilderMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5648 | memory_barrier->SetLocations(nullptr); |
| 5649 | } |
| 5650 | |
| 5651 | void InstructionCodeGeneratorMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5652 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 5653 | } |
| 5654 | |
| 5655 | void LocationsBuilderMIPS64::VisitReturn(HReturn* ret) { |
| 5656 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret); |
| 5657 | Primitive::Type return_type = ret->InputAt(0)->GetType(); |
| 5658 | locations->SetInAt(0, Mips64ReturnLocation(return_type)); |
| 5659 | } |
| 5660 | |
| 5661 | void InstructionCodeGeneratorMIPS64::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 5662 | codegen_->GenerateFrameExit(); |
| 5663 | } |
| 5664 | |
| 5665 | void LocationsBuilderMIPS64::VisitReturnVoid(HReturnVoid* ret) { |
| 5666 | ret->SetLocations(nullptr); |
| 5667 | } |
| 5668 | |
| 5669 | void InstructionCodeGeneratorMIPS64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 5670 | codegen_->GenerateFrameExit(); |
| 5671 | } |
| 5672 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 5673 | void LocationsBuilderMIPS64::VisitRor(HRor* ror) { |
| 5674 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5675 | } |
| 5676 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 5677 | void InstructionCodeGeneratorMIPS64::VisitRor(HRor* ror) { |
| 5678 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5679 | } |
| 5680 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5681 | void LocationsBuilderMIPS64::VisitShl(HShl* shl) { |
| 5682 | HandleShift(shl); |
| 5683 | } |
| 5684 | |
| 5685 | void InstructionCodeGeneratorMIPS64::VisitShl(HShl* shl) { |
| 5686 | HandleShift(shl); |
| 5687 | } |
| 5688 | |
| 5689 | void LocationsBuilderMIPS64::VisitShr(HShr* shr) { |
| 5690 | HandleShift(shr); |
| 5691 | } |
| 5692 | |
| 5693 | void InstructionCodeGeneratorMIPS64::VisitShr(HShr* shr) { |
| 5694 | HandleShift(shr); |
| 5695 | } |
| 5696 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5697 | void LocationsBuilderMIPS64::VisitSub(HSub* instruction) { |
| 5698 | HandleBinaryOp(instruction); |
| 5699 | } |
| 5700 | |
| 5701 | void InstructionCodeGeneratorMIPS64::VisitSub(HSub* instruction) { |
| 5702 | HandleBinaryOp(instruction); |
| 5703 | } |
| 5704 | |
| 5705 | void LocationsBuilderMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5706 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5707 | } |
| 5708 | |
| 5709 | void InstructionCodeGeneratorMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5710 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5711 | } |
| 5712 | |
| 5713 | void LocationsBuilderMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5714 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5715 | } |
| 5716 | |
| 5717 | void InstructionCodeGeneratorMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 5718 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5719 | } |
| 5720 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5721 | void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldGet( |
| 5722 | HUnresolvedInstanceFieldGet* instruction) { |
| 5723 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 5724 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5725 | instruction, instruction->GetFieldType(), calling_convention); |
| 5726 | } |
| 5727 | |
| 5728 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldGet( |
| 5729 | HUnresolvedInstanceFieldGet* instruction) { |
| 5730 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 5731 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5732 | instruction->GetFieldType(), |
| 5733 | instruction->GetFieldIndex(), |
| 5734 | instruction->GetDexPc(), |
| 5735 | calling_convention); |
| 5736 | } |
| 5737 | |
| 5738 | void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldSet( |
| 5739 | HUnresolvedInstanceFieldSet* instruction) { |
| 5740 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 5741 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5742 | instruction, instruction->GetFieldType(), calling_convention); |
| 5743 | } |
| 5744 | |
| 5745 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldSet( |
| 5746 | HUnresolvedInstanceFieldSet* instruction) { |
| 5747 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 5748 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5749 | instruction->GetFieldType(), |
| 5750 | instruction->GetFieldIndex(), |
| 5751 | instruction->GetDexPc(), |
| 5752 | calling_convention); |
| 5753 | } |
| 5754 | |
| 5755 | void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldGet( |
| 5756 | HUnresolvedStaticFieldGet* instruction) { |
| 5757 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 5758 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5759 | instruction, instruction->GetFieldType(), calling_convention); |
| 5760 | } |
| 5761 | |
| 5762 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldGet( |
| 5763 | HUnresolvedStaticFieldGet* instruction) { |
| 5764 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 5765 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5766 | instruction->GetFieldType(), |
| 5767 | instruction->GetFieldIndex(), |
| 5768 | instruction->GetDexPc(), |
| 5769 | calling_convention); |
| 5770 | } |
| 5771 | |
| 5772 | void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldSet( |
| 5773 | HUnresolvedStaticFieldSet* instruction) { |
| 5774 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 5775 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5776 | instruction, instruction->GetFieldType(), calling_convention); |
| 5777 | } |
| 5778 | |
| 5779 | void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldSet( |
| 5780 | HUnresolvedStaticFieldSet* instruction) { |
| 5781 | FieldAccessCallingConventionMIPS64 calling_convention; |
| 5782 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5783 | instruction->GetFieldType(), |
| 5784 | instruction->GetFieldIndex(), |
| 5785 | instruction->GetDexPc(), |
| 5786 | calling_convention); |
| 5787 | } |
| 5788 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5789 | void LocationsBuilderMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5790 | LocationSummary* locations = |
| 5791 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 5792 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5793 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5794 | // registers in full width (since the runtime only saves/restores lower part). |
| 5795 | locations->SetCustomSlowPathCallerSaves( |
| 5796 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5797 | } |
| 5798 | |
| 5799 | void InstructionCodeGeneratorMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5800 | HBasicBlock* block = instruction->GetBlock(); |
| 5801 | if (block->GetLoopInformation() != nullptr) { |
| 5802 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5803 | // The back edge will generate the suspend check. |
| 5804 | return; |
| 5805 | } |
| 5806 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5807 | // The goto will generate the suspend check. |
| 5808 | return; |
| 5809 | } |
| 5810 | GenerateSuspendCheck(instruction, nullptr); |
| 5811 | } |
| 5812 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5813 | void LocationsBuilderMIPS64::VisitThrow(HThrow* instruction) { |
| 5814 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5815 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5816 | InvokeRuntimeCallingConvention calling_convention; |
| 5817 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5818 | } |
| 5819 | |
| 5820 | void InstructionCodeGeneratorMIPS64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 5821 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5822 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 5823 | } |
| 5824 | |
| 5825 | void LocationsBuilderMIPS64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5826 | Primitive::Type input_type = conversion->GetInputType(); |
| 5827 | Primitive::Type result_type = conversion->GetResultType(); |
| 5828 | DCHECK_NE(input_type, result_type); |
| 5829 | |
| 5830 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 5831 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 5832 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 5833 | } |
| 5834 | |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 5835 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion); |
| 5836 | |
| 5837 | if (Primitive::IsFloatingPointType(input_type)) { |
| 5838 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5839 | } else { |
| 5840 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5841 | } |
| 5842 | |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 5843 | if (Primitive::IsFloatingPointType(result_type)) { |
| 5844 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5845 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 5846 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5847 | } |
| 5848 | } |
| 5849 | |
| 5850 | void InstructionCodeGeneratorMIPS64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5851 | LocationSummary* locations = conversion->GetLocations(); |
| 5852 | Primitive::Type result_type = conversion->GetResultType(); |
| 5853 | Primitive::Type input_type = conversion->GetInputType(); |
| 5854 | |
| 5855 | DCHECK_NE(input_type, result_type); |
| 5856 | |
| 5857 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
| 5858 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 5859 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 5860 | |
| 5861 | switch (result_type) { |
| 5862 | case Primitive::kPrimChar: |
| 5863 | __ Andi(dst, src, 0xFFFF); |
| 5864 | break; |
| 5865 | case Primitive::kPrimByte: |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 5866 | if (input_type == Primitive::kPrimLong) { |
| 5867 | // Type conversion from long to types narrower than int is a result of code |
| 5868 | // transformations. To avoid unpredictable results for SEB and SEH, we first |
| 5869 | // need to sign-extend the low 32-bit value into bits 32 through 63. |
| 5870 | __ Sll(dst, src, 0); |
| 5871 | __ Seb(dst, dst); |
| 5872 | } else { |
| 5873 | __ Seb(dst, src); |
| 5874 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5875 | break; |
| 5876 | case Primitive::kPrimShort: |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 5877 | if (input_type == Primitive::kPrimLong) { |
| 5878 | // Type conversion from long to types narrower than int is a result of code |
| 5879 | // transformations. To avoid unpredictable results for SEB and SEH, we first |
| 5880 | // need to sign-extend the low 32-bit value into bits 32 through 63. |
| 5881 | __ Sll(dst, src, 0); |
| 5882 | __ Seh(dst, dst); |
| 5883 | } else { |
| 5884 | __ Seh(dst, src); |
| 5885 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5886 | break; |
| 5887 | case Primitive::kPrimInt: |
| 5888 | case Primitive::kPrimLong: |
Goran Jakovljevic | 992bdb9 | 2016-12-28 16:21:48 +0100 | [diff] [blame] | 5889 | // Sign-extend 32-bit int into bits 32 through 63 for int-to-long and long-to-int |
| 5890 | // conversions, except when the input and output registers are the same and we are not |
| 5891 | // converting longs to shorter types. In these cases, do nothing. |
| 5892 | if ((input_type == Primitive::kPrimLong) || (dst != src)) { |
| 5893 | __ Sll(dst, src, 0); |
| 5894 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5895 | break; |
| 5896 | |
| 5897 | default: |
| 5898 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 5899 | << " to " << result_type; |
| 5900 | } |
| 5901 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 5902 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 5903 | GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>(); |
| 5904 | if (input_type == Primitive::kPrimLong) { |
| 5905 | __ Dmtc1(src, FTMP); |
| 5906 | if (result_type == Primitive::kPrimFloat) { |
| 5907 | __ Cvtsl(dst, FTMP); |
| 5908 | } else { |
| 5909 | __ Cvtdl(dst, FTMP); |
| 5910 | } |
| 5911 | } else { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5912 | __ Mtc1(src, FTMP); |
| 5913 | if (result_type == Primitive::kPrimFloat) { |
| 5914 | __ Cvtsw(dst, FTMP); |
| 5915 | } else { |
| 5916 | __ Cvtdw(dst, FTMP); |
| 5917 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5918 | } |
| 5919 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
| 5920 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 5921 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 5922 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 5923 | |
| 5924 | if (result_type == Primitive::kPrimLong) { |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5925 | if (input_type == Primitive::kPrimFloat) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 5926 | __ TruncLS(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5927 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 5928 | __ TruncLD(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5929 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 5930 | __ Dmfc1(dst, FTMP); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5931 | } else { |
| 5932 | if (input_type == Primitive::kPrimFloat) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 5933 | __ TruncWS(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5934 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 5935 | __ TruncWD(FTMP, src); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5936 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 5937 | __ Mfc1(dst, FTMP); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5938 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5939 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 5940 | Primitive::IsFloatingPointType(input_type)) { |
| 5941 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 5942 | FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 5943 | if (result_type == Primitive::kPrimFloat) { |
| 5944 | __ Cvtsd(dst, src); |
| 5945 | } else { |
| 5946 | __ Cvtds(dst, src); |
| 5947 | } |
| 5948 | } else { |
| 5949 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 5950 | << " to " << result_type; |
| 5951 | } |
| 5952 | } |
| 5953 | |
| 5954 | void LocationsBuilderMIPS64::VisitUShr(HUShr* ushr) { |
| 5955 | HandleShift(ushr); |
| 5956 | } |
| 5957 | |
| 5958 | void InstructionCodeGeneratorMIPS64::VisitUShr(HUShr* ushr) { |
| 5959 | HandleShift(ushr); |
| 5960 | } |
| 5961 | |
| 5962 | void LocationsBuilderMIPS64::VisitXor(HXor* instruction) { |
| 5963 | HandleBinaryOp(instruction); |
| 5964 | } |
| 5965 | |
| 5966 | void InstructionCodeGeneratorMIPS64::VisitXor(HXor* instruction) { |
| 5967 | HandleBinaryOp(instruction); |
| 5968 | } |
| 5969 | |
| 5970 | void LocationsBuilderMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 5971 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5972 | LOG(FATAL) << "Unreachable"; |
| 5973 | } |
| 5974 | |
| 5975 | void InstructionCodeGeneratorMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 5976 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5977 | LOG(FATAL) << "Unreachable"; |
| 5978 | } |
| 5979 | |
| 5980 | void LocationsBuilderMIPS64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5981 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5982 | } |
| 5983 | |
| 5984 | void InstructionCodeGeneratorMIPS64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5985 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5986 | } |
| 5987 | |
| 5988 | void LocationsBuilderMIPS64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5989 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5990 | } |
| 5991 | |
| 5992 | void InstructionCodeGeneratorMIPS64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5993 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5994 | } |
| 5995 | |
| 5996 | void LocationsBuilderMIPS64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5997 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5998 | } |
| 5999 | |
| 6000 | void InstructionCodeGeneratorMIPS64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6001 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6002 | } |
| 6003 | |
| 6004 | void LocationsBuilderMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6005 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6006 | } |
| 6007 | |
| 6008 | void InstructionCodeGeneratorMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6009 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6010 | } |
| 6011 | |
| 6012 | void LocationsBuilderMIPS64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6013 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6014 | } |
| 6015 | |
| 6016 | void InstructionCodeGeneratorMIPS64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6017 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6018 | } |
| 6019 | |
| 6020 | void LocationsBuilderMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6021 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6022 | } |
| 6023 | |
| 6024 | void InstructionCodeGeneratorMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6025 | HandleCondition(comp); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6026 | } |
| 6027 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6028 | void LocationsBuilderMIPS64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6029 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6030 | } |
| 6031 | |
| 6032 | void InstructionCodeGeneratorMIPS64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6033 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6034 | } |
| 6035 | |
| 6036 | void LocationsBuilderMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6037 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6038 | } |
| 6039 | |
| 6040 | void InstructionCodeGeneratorMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6041 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6042 | } |
| 6043 | |
| 6044 | void LocationsBuilderMIPS64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6045 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6046 | } |
| 6047 | |
| 6048 | void InstructionCodeGeneratorMIPS64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6049 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6050 | } |
| 6051 | |
| 6052 | void LocationsBuilderMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6053 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6054 | } |
| 6055 | |
| 6056 | void InstructionCodeGeneratorMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6057 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 6058 | } |
| 6059 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6060 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6061 | void LocationsBuilderMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6062 | LocationSummary* locations = |
| 6063 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6064 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6065 | } |
| 6066 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 6067 | void InstructionCodeGeneratorMIPS64::GenPackedSwitchWithCompares(GpuRegister value_reg, |
| 6068 | int32_t lower_bound, |
| 6069 | uint32_t num_entries, |
| 6070 | HBasicBlock* switch_block, |
| 6071 | HBasicBlock* default_block) { |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6072 | // Create a set of compare/jumps. |
| 6073 | GpuRegister temp_reg = TMP; |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 6074 | __ Addiu32(temp_reg, value_reg, -lower_bound); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6075 | // Jump to default if index is negative |
| 6076 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 6077 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 6078 | __ Bltzc(temp_reg, codegen_->GetLabelOf(default_block)); |
| 6079 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 6080 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6081 | // Jump to successors[0] if value == lower_bound. |
| 6082 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 6083 | int32_t last_index = 0; |
| 6084 | for (; num_entries - last_index > 2; last_index += 2) { |
| 6085 | __ Addiu(temp_reg, temp_reg, -2); |
| 6086 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 6087 | __ Bltzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 6088 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 6089 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 6090 | } |
| 6091 | if (num_entries - last_index == 2) { |
| 6092 | // The last missing case_value. |
| 6093 | __ Addiu(temp_reg, temp_reg, -1); |
| 6094 | __ Beqzc(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6095 | } |
| 6096 | |
| 6097 | // And the default for any other value. |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 6098 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 6099 | __ Bc(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6100 | } |
| 6101 | } |
| 6102 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 6103 | void InstructionCodeGeneratorMIPS64::GenTableBasedPackedSwitch(GpuRegister value_reg, |
| 6104 | int32_t lower_bound, |
| 6105 | uint32_t num_entries, |
| 6106 | HBasicBlock* switch_block, |
| 6107 | HBasicBlock* default_block) { |
| 6108 | // Create a jump table. |
| 6109 | std::vector<Mips64Label*> labels(num_entries); |
| 6110 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 6111 | for (uint32_t i = 0; i < num_entries; i++) { |
| 6112 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 6113 | } |
| 6114 | JumpTable* table = __ CreateJumpTable(std::move(labels)); |
| 6115 | |
| 6116 | // Is the value in range? |
| 6117 | __ Addiu32(TMP, value_reg, -lower_bound); |
| 6118 | __ LoadConst32(AT, num_entries); |
| 6119 | __ Bgeuc(TMP, AT, codegen_->GetLabelOf(default_block)); |
| 6120 | |
| 6121 | // We are in the range of the table. |
| 6122 | // Load the target address from the jump table, indexing by the value. |
| 6123 | __ LoadLabelAddress(AT, table->GetLabel()); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 6124 | __ Dlsa(TMP, TMP, AT, 2); |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 6125 | __ Lw(TMP, TMP, 0); |
| 6126 | // Compute the absolute target address by adding the table start address |
| 6127 | // (the table contains offsets to targets relative to its start). |
| 6128 | __ Daddu(TMP, TMP, AT); |
| 6129 | // And jump. |
| 6130 | __ Jr(TMP); |
| 6131 | __ Nop(); |
| 6132 | } |
| 6133 | |
| 6134 | void InstructionCodeGeneratorMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6135 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 6136 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 6137 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6138 | GpuRegister value_reg = locations->InAt(0).AsRegister<GpuRegister>(); |
| 6139 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 6140 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6141 | |
| 6142 | if (num_entries > kPackedSwitchJumpTableThreshold) { |
| 6143 | GenTableBasedPackedSwitch(value_reg, |
| 6144 | lower_bound, |
| 6145 | num_entries, |
| 6146 | switch_block, |
| 6147 | default_block); |
| 6148 | } else { |
| 6149 | GenPackedSwitchWithCompares(value_reg, |
| 6150 | lower_bound, |
| 6151 | num_entries, |
| 6152 | switch_block, |
| 6153 | default_block); |
| 6154 | } |
| 6155 | } |
| 6156 | |
Chris Larsen | c9905a6 | 2017-03-13 17:06:18 -0700 | [diff] [blame] | 6157 | void LocationsBuilderMIPS64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6158 | LocationSummary* locations = |
| 6159 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6160 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6161 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6162 | } |
| 6163 | |
Chris Larsen | c9905a6 | 2017-03-13 17:06:18 -0700 | [diff] [blame] | 6164 | void InstructionCodeGeneratorMIPS64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6165 | LocationSummary* locations = instruction->GetLocations(); |
| 6166 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 6167 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 6168 | instruction->GetIndex(), kMips64PointerSize).SizeValue(); |
| 6169 | __ LoadFromOffset(kLoadDoubleword, |
| 6170 | locations->Out().AsRegister<GpuRegister>(), |
| 6171 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 6172 | method_offset); |
| 6173 | } else { |
| 6174 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 6175 | instruction->GetIndex(), kMips64PointerSize)); |
| 6176 | __ LoadFromOffset(kLoadDoubleword, |
| 6177 | locations->Out().AsRegister<GpuRegister>(), |
| 6178 | locations->InAt(0).AsRegister<GpuRegister>(), |
| 6179 | mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value()); |
| 6180 | __ LoadFromOffset(kLoadDoubleword, |
| 6181 | locations->Out().AsRegister<GpuRegister>(), |
| 6182 | locations->Out().AsRegister<GpuRegister>(), |
| 6183 | method_offset); |
| 6184 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6185 | } |
| 6186 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6187 | } // namespace mips64 |
| 6188 | } // namespace art |