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), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 954 | assembler_(graph->GetArena()), |
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)), |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 960 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 961 | pc_relative_string_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)), |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 964 | jit_string_patches_(StringReferenceValueComparator(), |
| 965 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 966 | jit_class_patches_(TypeReferenceValueComparator(), |
| 967 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 968 | // Save RA (containing the return address) to mimic Quick. |
| 969 | AddAllocatedRegister(Location::RegisterLocation(RA)); |
| 970 | } |
| 971 | |
| 972 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 973 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 974 | #define __ down_cast<Mips64Assembler*>(GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 975 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, x).Int32Value() |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 976 | |
| 977 | void CodeGeneratorMIPS64::Finalize(CodeAllocator* allocator) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 978 | // Ensure that we fix up branches. |
| 979 | __ FinalizeCode(); |
| 980 | |
| 981 | // Adjust native pc offsets in stack maps. |
| 982 | 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] | 983 | uint32_t old_position = |
| 984 | stack_map_stream_.GetStackMap(i).native_pc_code_offset.Uint32Value(kMips64); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 985 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 986 | DCHECK_GE(new_position, old_position); |
| 987 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 988 | } |
| 989 | |
| 990 | // Adjust pc offsets for the disassembly information. |
| 991 | if (disasm_info_ != nullptr) { |
| 992 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 993 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 994 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 995 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 996 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 997 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 998 | } |
| 999 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1000 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1001 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1002 | } |
| 1003 | } |
| 1004 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1005 | CodeGenerator::Finalize(allocator); |
| 1006 | } |
| 1007 | |
| 1008 | Mips64Assembler* ParallelMoveResolverMIPS64::GetAssembler() const { |
| 1009 | return codegen_->GetAssembler(); |
| 1010 | } |
| 1011 | |
| 1012 | void ParallelMoveResolverMIPS64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1013 | MoveOperands* move = moves_[index]; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1014 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); |
| 1015 | } |
| 1016 | |
| 1017 | void ParallelMoveResolverMIPS64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1018 | MoveOperands* move = moves_[index]; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1019 | codegen_->SwapLocations(move->GetDestination(), move->GetSource(), move->GetType()); |
| 1020 | } |
| 1021 | |
| 1022 | void ParallelMoveResolverMIPS64::RestoreScratch(int reg) { |
| 1023 | // Pop reg |
| 1024 | __ Ld(GpuRegister(reg), SP, 0); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1025 | __ DecreaseFrameSize(kMips64DoublewordSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | void ParallelMoveResolverMIPS64::SpillScratch(int reg) { |
| 1029 | // Push reg |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1030 | __ IncreaseFrameSize(kMips64DoublewordSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1031 | __ Sd(GpuRegister(reg), SP, 0); |
| 1032 | } |
| 1033 | |
| 1034 | void ParallelMoveResolverMIPS64::Exchange(int index1, int index2, bool double_slot) { |
| 1035 | LoadOperandType load_type = double_slot ? kLoadDoubleword : kLoadWord; |
| 1036 | StoreOperandType store_type = double_slot ? kStoreDoubleword : kStoreWord; |
| 1037 | // Allocate a scratch register other than TMP, if available. |
| 1038 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be |
| 1039 | // automatically unspilled when the scratch scope object is destroyed). |
| 1040 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); |
| 1041 | // 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] | 1042 | int stack_offset = ensure_scratch.IsSpilled() ? kMips64DoublewordSize : 0; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1043 | __ LoadFromOffset(load_type, |
| 1044 | GpuRegister(ensure_scratch.GetRegister()), |
| 1045 | SP, |
| 1046 | index1 + stack_offset); |
| 1047 | __ LoadFromOffset(load_type, |
| 1048 | TMP, |
| 1049 | SP, |
| 1050 | index2 + stack_offset); |
| 1051 | __ StoreToOffset(store_type, |
| 1052 | GpuRegister(ensure_scratch.GetRegister()), |
| 1053 | SP, |
| 1054 | index2 + stack_offset); |
| 1055 | __ StoreToOffset(store_type, TMP, SP, index1 + stack_offset); |
| 1056 | } |
| 1057 | |
| 1058 | static dwarf::Reg DWARFReg(GpuRegister reg) { |
| 1059 | return dwarf::Reg::Mips64Core(static_cast<int>(reg)); |
| 1060 | } |
| 1061 | |
David Srbecky | ba70200 | 2016-02-01 18:15:29 +0000 | [diff] [blame] | 1062 | static dwarf::Reg DWARFReg(FpuRegister reg) { |
| 1063 | return dwarf::Reg::Mips64Fp(static_cast<int>(reg)); |
| 1064 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1065 | |
| 1066 | void CodeGeneratorMIPS64::GenerateFrameEntry() { |
| 1067 | __ Bind(&frame_entry_label_); |
| 1068 | |
| 1069 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips64) || !IsLeafMethod(); |
| 1070 | |
| 1071 | if (do_overflow_check) { |
| 1072 | __ LoadFromOffset(kLoadWord, |
| 1073 | ZERO, |
| 1074 | SP, |
| 1075 | -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips64))); |
| 1076 | RecordPcInfo(nullptr, 0); |
| 1077 | } |
| 1078 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1079 | if (HasEmptyFrame()) { |
| 1080 | return; |
| 1081 | } |
| 1082 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1083 | // Make sure the frame size isn't unreasonably large. |
| 1084 | if (GetFrameSize() > GetStackOverflowReservedBytes(kMips64)) { |
| 1085 | LOG(FATAL) << "Stack frame larger than " << GetStackOverflowReservedBytes(kMips64) << " bytes"; |
| 1086 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1087 | |
| 1088 | // Spill callee-saved registers. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1089 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1090 | uint32_t ofs = GetFrameSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1091 | __ IncreaseFrameSize(ofs); |
| 1092 | |
| 1093 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1094 | GpuRegister reg = kCoreCalleeSaves[i]; |
| 1095 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1096 | ofs -= kMips64DoublewordSize; |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1097 | __ StoreToOffset(kStoreDoubleword, reg, SP, ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1098 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1103 | FpuRegister reg = kFpuCalleeSaves[i]; |
| 1104 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1105 | ofs -= kMips64DoublewordSize; |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1106 | __ StoreFpuToOffset(kStoreDoubleword, reg, SP, ofs); |
David Srbecky | ba70200 | 2016-02-01 18:15:29 +0000 | [diff] [blame] | 1107 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1108 | } |
| 1109 | } |
| 1110 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1111 | // Save the current method if we need it. Note that we do not |
| 1112 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1113 | // in the SSA graph. |
| 1114 | if (RequiresCurrentMethod()) { |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1115 | __ StoreToOffset(kStoreDoubleword, kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1116 | } |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 1117 | |
| 1118 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1119 | // Initialize should_deoptimize flag to 0. |
| 1120 | __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 1121 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | void CodeGeneratorMIPS64::GenerateFrameExit() { |
| 1125 | __ cfi().RememberState(); |
| 1126 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1127 | if (!HasEmptyFrame()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1128 | // Restore callee-saved registers. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1129 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1130 | // For better instruction scheduling restore RA before other registers. |
| 1131 | uint32_t ofs = GetFrameSize(); |
| 1132 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1133 | GpuRegister reg = kCoreCalleeSaves[i]; |
| 1134 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1135 | ofs -= kMips64DoublewordSize; |
| 1136 | __ LoadFromOffset(kLoadDoubleword, reg, SP, ofs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1137 | __ cfi().Restore(DWARFReg(reg)); |
| 1138 | } |
| 1139 | } |
| 1140 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1141 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1142 | FpuRegister reg = kFpuCalleeSaves[i]; |
| 1143 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
| 1144 | ofs -= kMips64DoublewordSize; |
| 1145 | __ LoadFpuFromOffset(kLoadDoubleword, reg, SP, ofs); |
| 1146 | __ cfi().Restore(DWARFReg(reg)); |
| 1147 | } |
| 1148 | } |
| 1149 | |
| 1150 | __ DecreaseFrameSize(GetFrameSize()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1151 | } |
| 1152 | |
Alexey Frunze | e104d6e | 2017-03-21 20:16:05 -0700 | [diff] [blame] | 1153 | __ Jic(RA, 0); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1154 | |
| 1155 | __ cfi().RestoreState(); |
| 1156 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 1157 | } |
| 1158 | |
| 1159 | void CodeGeneratorMIPS64::Bind(HBasicBlock* block) { |
| 1160 | __ Bind(GetLabelOf(block)); |
| 1161 | } |
| 1162 | |
| 1163 | void CodeGeneratorMIPS64::MoveLocation(Location destination, |
| 1164 | Location source, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1165 | Primitive::Type dst_type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1166 | if (source.Equals(destination)) { |
| 1167 | return; |
| 1168 | } |
| 1169 | |
| 1170 | // A valid move can always be inferred from the destination and source |
| 1171 | // locations. When moving from and to a register, the argument type can be |
| 1172 | // used to generate 32bit instead of 64bit moves. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1173 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1174 | DCHECK_EQ(unspecified_type, false); |
| 1175 | |
| 1176 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1177 | if (unspecified_type) { |
| 1178 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1179 | if (source.IsStackSlot() || |
| 1180 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1181 | || src_cst->IsFloatConstant() |
| 1182 | || src_cst->IsNullConstant()))) { |
| 1183 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1184 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1185 | } else { |
| 1186 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1187 | // type is appropriate. Else the source is a register, and since the |
| 1188 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1189 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1190 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1191 | } |
| 1192 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1193 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 1194 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1195 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1196 | // Move to GPR/FPR from stack |
| 1197 | LoadOperandType load_type = source.IsStackSlot() ? kLoadWord : kLoadDoubleword; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1198 | if (Primitive::IsFloatingPointType(dst_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1199 | __ LoadFpuFromOffset(load_type, |
| 1200 | destination.AsFpuRegister<FpuRegister>(), |
| 1201 | SP, |
| 1202 | source.GetStackIndex()); |
| 1203 | } else { |
| 1204 | // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot. |
| 1205 | __ LoadFromOffset(load_type, |
| 1206 | destination.AsRegister<GpuRegister>(), |
| 1207 | SP, |
| 1208 | source.GetStackIndex()); |
| 1209 | } |
| 1210 | } else if (source.IsConstant()) { |
| 1211 | // Move to GPR/FPR from constant |
| 1212 | GpuRegister gpr = AT; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1213 | if (!Primitive::IsFloatingPointType(dst_type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1214 | gpr = destination.AsRegister<GpuRegister>(); |
| 1215 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1216 | if (dst_type == Primitive::kPrimInt || dst_type == Primitive::kPrimFloat) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1217 | int32_t value = GetInt32ValueOf(source.GetConstant()->AsConstant()); |
| 1218 | if (Primitive::IsFloatingPointType(dst_type) && value == 0) { |
| 1219 | gpr = ZERO; |
| 1220 | } else { |
| 1221 | __ LoadConst32(gpr, value); |
| 1222 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1223 | } else { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1224 | int64_t value = GetInt64ValueOf(source.GetConstant()->AsConstant()); |
| 1225 | if (Primitive::IsFloatingPointType(dst_type) && value == 0) { |
| 1226 | gpr = ZERO; |
| 1227 | } else { |
| 1228 | __ LoadConst64(gpr, value); |
| 1229 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1230 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1231 | if (dst_type == Primitive::kPrimFloat) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1232 | __ Mtc1(gpr, destination.AsFpuRegister<FpuRegister>()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1233 | } else if (dst_type == Primitive::kPrimDouble) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1234 | __ Dmtc1(gpr, destination.AsFpuRegister<FpuRegister>()); |
| 1235 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1236 | } else if (source.IsRegister()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1237 | if (destination.IsRegister()) { |
| 1238 | // Move to GPR from GPR |
| 1239 | __ Move(destination.AsRegister<GpuRegister>(), source.AsRegister<GpuRegister>()); |
| 1240 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1241 | DCHECK(destination.IsFpuRegister()); |
| 1242 | if (Primitive::Is64BitType(dst_type)) { |
| 1243 | __ Dmtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>()); |
| 1244 | } else { |
| 1245 | __ Mtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>()); |
| 1246 | } |
| 1247 | } |
| 1248 | } else if (source.IsFpuRegister()) { |
| 1249 | if (destination.IsFpuRegister()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1250 | // Move to FPR from FPR |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1251 | if (dst_type == Primitive::kPrimFloat) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1252 | __ MovS(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1253 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1254 | DCHECK_EQ(dst_type, Primitive::kPrimDouble); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1255 | __ MovD(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1256 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1257 | } else { |
| 1258 | DCHECK(destination.IsRegister()); |
| 1259 | if (Primitive::Is64BitType(dst_type)) { |
| 1260 | __ Dmfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1261 | } else { |
| 1262 | __ Mfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>()); |
| 1263 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1264 | } |
| 1265 | } |
| 1266 | } else { // The destination is not a register. It must be a stack slot. |
| 1267 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1268 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1269 | if (unspecified_type) { |
| 1270 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1271 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1272 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1273 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1274 | } |
| 1275 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1276 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 1277 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1278 | // Move to stack from GPR/FPR |
| 1279 | StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
| 1280 | if (source.IsRegister()) { |
| 1281 | __ StoreToOffset(store_type, |
| 1282 | source.AsRegister<GpuRegister>(), |
| 1283 | SP, |
| 1284 | destination.GetStackIndex()); |
| 1285 | } else { |
| 1286 | __ StoreFpuToOffset(store_type, |
| 1287 | source.AsFpuRegister<FpuRegister>(), |
| 1288 | SP, |
| 1289 | destination.GetStackIndex()); |
| 1290 | } |
| 1291 | } else if (source.IsConstant()) { |
| 1292 | // Move to stack from constant |
| 1293 | HConstant* src_cst = source.GetConstant(); |
| 1294 | StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1295 | GpuRegister gpr = ZERO; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1296 | if (destination.IsStackSlot()) { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1297 | int32_t value = GetInt32ValueOf(src_cst->AsConstant()); |
| 1298 | if (value != 0) { |
| 1299 | gpr = TMP; |
| 1300 | __ LoadConst32(gpr, value); |
| 1301 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1302 | } else { |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1303 | DCHECK(destination.IsDoubleStackSlot()); |
| 1304 | int64_t value = GetInt64ValueOf(src_cst->AsConstant()); |
| 1305 | if (value != 0) { |
| 1306 | gpr = TMP; |
| 1307 | __ LoadConst64(gpr, value); |
| 1308 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1309 | } |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1310 | __ StoreToOffset(store_type, gpr, SP, destination.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1311 | } else { |
| 1312 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
| 1313 | DCHECK_EQ(source.IsDoubleStackSlot(), destination.IsDoubleStackSlot()); |
| 1314 | // Move to stack from stack |
| 1315 | if (destination.IsStackSlot()) { |
| 1316 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 1317 | __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex()); |
| 1318 | } else { |
| 1319 | __ LoadFromOffset(kLoadDoubleword, TMP, SP, source.GetStackIndex()); |
| 1320 | __ StoreToOffset(kStoreDoubleword, TMP, SP, destination.GetStackIndex()); |
| 1321 | } |
| 1322 | } |
| 1323 | } |
| 1324 | } |
| 1325 | |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1326 | void CodeGeneratorMIPS64::SwapLocations(Location loc1, Location loc2, Primitive::Type type) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1327 | DCHECK(!loc1.IsConstant()); |
| 1328 | DCHECK(!loc2.IsConstant()); |
| 1329 | |
| 1330 | if (loc1.Equals(loc2)) { |
| 1331 | return; |
| 1332 | } |
| 1333 | |
| 1334 | bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot(); |
| 1335 | bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot(); |
| 1336 | bool is_fp_reg1 = loc1.IsFpuRegister(); |
| 1337 | bool is_fp_reg2 = loc2.IsFpuRegister(); |
| 1338 | |
| 1339 | if (loc2.IsRegister() && loc1.IsRegister()) { |
| 1340 | // Swap 2 GPRs |
| 1341 | GpuRegister r1 = loc1.AsRegister<GpuRegister>(); |
| 1342 | GpuRegister r2 = loc2.AsRegister<GpuRegister>(); |
| 1343 | __ Move(TMP, r2); |
| 1344 | __ Move(r2, r1); |
| 1345 | __ Move(r1, TMP); |
| 1346 | } else if (is_fp_reg2 && is_fp_reg1) { |
| 1347 | // Swap 2 FPRs |
| 1348 | FpuRegister r1 = loc1.AsFpuRegister<FpuRegister>(); |
| 1349 | FpuRegister r2 = loc2.AsFpuRegister<FpuRegister>(); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1350 | if (type == Primitive::kPrimFloat) { |
| 1351 | __ MovS(FTMP, r1); |
| 1352 | __ MovS(r1, r2); |
| 1353 | __ MovS(r2, FTMP); |
| 1354 | } else { |
| 1355 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1356 | __ MovD(FTMP, r1); |
| 1357 | __ MovD(r1, r2); |
| 1358 | __ MovD(r2, FTMP); |
| 1359 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1360 | } else if (is_slot1 != is_slot2) { |
| 1361 | // Swap GPR/FPR and stack slot |
| 1362 | Location reg_loc = is_slot1 ? loc2 : loc1; |
| 1363 | Location mem_loc = is_slot1 ? loc1 : loc2; |
| 1364 | LoadOperandType load_type = mem_loc.IsStackSlot() ? kLoadWord : kLoadDoubleword; |
| 1365 | StoreOperandType store_type = mem_loc.IsStackSlot() ? kStoreWord : kStoreDoubleword; |
| 1366 | // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot. |
| 1367 | __ LoadFromOffset(load_type, TMP, SP, mem_loc.GetStackIndex()); |
| 1368 | if (reg_loc.IsFpuRegister()) { |
| 1369 | __ StoreFpuToOffset(store_type, |
| 1370 | reg_loc.AsFpuRegister<FpuRegister>(), |
| 1371 | SP, |
| 1372 | mem_loc.GetStackIndex()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1373 | if (mem_loc.IsStackSlot()) { |
| 1374 | __ Mtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>()); |
| 1375 | } else { |
| 1376 | DCHECK(mem_loc.IsDoubleStackSlot()); |
| 1377 | __ Dmtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>()); |
| 1378 | } |
| 1379 | } else { |
| 1380 | __ StoreToOffset(store_type, reg_loc.AsRegister<GpuRegister>(), SP, mem_loc.GetStackIndex()); |
| 1381 | __ Move(reg_loc.AsRegister<GpuRegister>(), TMP); |
| 1382 | } |
| 1383 | } else if (is_slot1 && is_slot2) { |
| 1384 | move_resolver_.Exchange(loc1.GetStackIndex(), |
| 1385 | loc2.GetStackIndex(), |
| 1386 | loc1.IsDoubleStackSlot()); |
| 1387 | } else { |
| 1388 | LOG(FATAL) << "Unimplemented swap between locations " << loc1 << " and " << loc2; |
| 1389 | } |
| 1390 | } |
| 1391 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1392 | void CodeGeneratorMIPS64::MoveConstant(Location location, int32_t value) { |
| 1393 | DCHECK(location.IsRegister()); |
| 1394 | __ LoadConst32(location.AsRegister<GpuRegister>(), value); |
| 1395 | } |
| 1396 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1397 | void CodeGeneratorMIPS64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1398 | if (location.IsRegister()) { |
| 1399 | locations->AddTemp(location); |
| 1400 | } else { |
| 1401 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1402 | } |
| 1403 | } |
| 1404 | |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1405 | void CodeGeneratorMIPS64::MarkGCCard(GpuRegister object, |
| 1406 | GpuRegister value, |
| 1407 | bool value_can_be_null) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1408 | Mips64Label done; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1409 | GpuRegister card = AT; |
| 1410 | GpuRegister temp = TMP; |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1411 | if (value_can_be_null) { |
| 1412 | __ Beqzc(value, &done); |
| 1413 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1414 | __ LoadFromOffset(kLoadDoubleword, |
| 1415 | card, |
| 1416 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1417 | Thread::CardTableOffset<kMips64PointerSize>().Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1418 | __ Dsrl(temp, object, gc::accounting::CardTable::kCardShift); |
| 1419 | __ Daddu(temp, card, temp); |
| 1420 | __ Sb(card, temp, 0); |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 1421 | if (value_can_be_null) { |
| 1422 | __ Bind(&done); |
| 1423 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1424 | } |
| 1425 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1426 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 1427 | inline void CodeGeneratorMIPS64::EmitPcRelativeLinkerPatches( |
| 1428 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 1429 | ArenaVector<LinkerPatch>* linker_patches) { |
| 1430 | for (const PcRelativePatchInfo& info : infos) { |
| 1431 | const DexFile& dex_file = info.target_dex_file; |
| 1432 | size_t offset_or_index = info.offset_or_index; |
| 1433 | DCHECK(info.pc_rel_label.IsBound()); |
| 1434 | uint32_t pc_rel_offset = __ GetLabelLocation(&info.pc_rel_label); |
| 1435 | linker_patches->push_back(Factory(pc_rel_offset, &dex_file, pc_rel_offset, offset_or_index)); |
| 1436 | } |
| 1437 | } |
| 1438 | |
| 1439 | void CodeGeneratorMIPS64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 1440 | DCHECK(linker_patches->empty()); |
| 1441 | size_t size = |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1442 | pc_relative_dex_cache_patches_.size() + |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1443 | pc_relative_string_patches_.size() + |
| 1444 | pc_relative_type_patches_.size() + |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 1445 | type_bss_entry_patches_.size(); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1446 | linker_patches->reserve(size); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1447 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 1448 | linker_patches); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1449 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1450 | DCHECK(pc_relative_type_patches_.empty()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1451 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 1452 | linker_patches); |
| 1453 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1454 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 1455 | linker_patches); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1456 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 1457 | linker_patches); |
| 1458 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1459 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 1460 | linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1461 | DCHECK_EQ(size, linker_patches->size()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeStringPatch( |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1465 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 1466 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeTypePatch( |
| 1470 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 1471 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1472 | } |
| 1473 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1474 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewTypeBssEntryPatch( |
| 1475 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 1476 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 1477 | } |
| 1478 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1479 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativeDexCacheArrayPatch( |
| 1480 | const DexFile& dex_file, uint32_t element_offset) { |
| 1481 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 1482 | } |
| 1483 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1484 | CodeGeneratorMIPS64::PcRelativePatchInfo* CodeGeneratorMIPS64::NewPcRelativePatch( |
| 1485 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 1486 | patches->emplace_back(dex_file, offset_or_index); |
| 1487 | return &patches->back(); |
| 1488 | } |
| 1489 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1490 | Literal* CodeGeneratorMIPS64::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 1491 | return map->GetOrCreate( |
| 1492 | value, |
| 1493 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
| 1494 | } |
| 1495 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1496 | Literal* CodeGeneratorMIPS64::DeduplicateUint64Literal(uint64_t value) { |
| 1497 | return uint64_literals_.GetOrCreate( |
| 1498 | value, |
| 1499 | [this, value]() { return __ NewLiteral<uint64_t>(value); }); |
| 1500 | } |
| 1501 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1502 | Literal* CodeGeneratorMIPS64::DeduplicateBootImageAddressLiteral(uint64_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 1503 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 1504 | } |
| 1505 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1506 | void CodeGeneratorMIPS64::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info, |
| 1507 | GpuRegister out) { |
| 1508 | __ Bind(&info->pc_rel_label); |
| 1509 | // Add the high half of a 32-bit offset to PC. |
| 1510 | __ Auipc(out, /* placeholder */ 0x1234); |
| 1511 | // 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] | 1512 | // offset to `out` (e.g. ld, jialc, daddiu). |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1513 | } |
| 1514 | |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1515 | Literal* CodeGeneratorMIPS64::DeduplicateJitStringLiteral(const DexFile& dex_file, |
| 1516 | dex::StringIndex string_index, |
| 1517 | Handle<mirror::String> handle) { |
| 1518 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 1519 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
| 1520 | return jit_string_patches_.GetOrCreate( |
| 1521 | StringReference(&dex_file, string_index), |
| 1522 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1523 | } |
| 1524 | |
| 1525 | Literal* CodeGeneratorMIPS64::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 1526 | dex::TypeIndex type_index, |
| 1527 | Handle<mirror::Class> handle) { |
| 1528 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 1529 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
| 1530 | return jit_class_patches_.GetOrCreate( |
| 1531 | TypeReference(&dex_file, type_index), |
| 1532 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1533 | } |
| 1534 | |
| 1535 | void CodeGeneratorMIPS64::PatchJitRootUse(uint8_t* code, |
| 1536 | const uint8_t* roots_data, |
| 1537 | const Literal* literal, |
| 1538 | uint64_t index_in_table) const { |
| 1539 | uint32_t literal_offset = GetAssembler().GetLabelLocation(literal->GetLabel()); |
| 1540 | uintptr_t address = |
| 1541 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 1542 | reinterpret_cast<uint32_t*>(code + literal_offset)[0] = dchecked_integral_cast<uint32_t>(address); |
| 1543 | } |
| 1544 | |
| 1545 | void CodeGeneratorMIPS64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 1546 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1547 | const StringReference& string_reference = entry.first; |
| 1548 | Literal* table_entry_literal = entry.second; |
| 1549 | const auto it = jit_string_roots_.find(string_reference); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1550 | DCHECK(it != jit_string_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1551 | uint64_t index_in_table = it->second; |
| 1552 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1553 | } |
| 1554 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1555 | const TypeReference& type_reference = entry.first; |
| 1556 | Literal* table_entry_literal = entry.second; |
| 1557 | const auto it = jit_class_roots_.find(type_reference); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1558 | DCHECK(it != jit_class_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 1559 | uint64_t index_in_table = it->second; |
| 1560 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1561 | } |
| 1562 | } |
| 1563 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1564 | void CodeGeneratorMIPS64::SetupBlockedRegisters() const { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1565 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1566 | blocked_core_registers_[ZERO] = true; |
| 1567 | blocked_core_registers_[K0] = true; |
| 1568 | blocked_core_registers_[K1] = true; |
| 1569 | blocked_core_registers_[GP] = true; |
| 1570 | blocked_core_registers_[SP] = true; |
| 1571 | blocked_core_registers_[RA] = true; |
| 1572 | |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1573 | // AT, TMP(T8) and TMP2(T3) are used as temporary/scratch |
| 1574 | // registers (similar to how AT is used by MIPS assemblers). |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1575 | blocked_core_registers_[AT] = true; |
| 1576 | blocked_core_registers_[TMP] = true; |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1577 | blocked_core_registers_[TMP2] = true; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1578 | blocked_fpu_registers_[FTMP] = true; |
| 1579 | |
| 1580 | // Reserve suspend and thread registers. |
| 1581 | blocked_core_registers_[S0] = true; |
| 1582 | blocked_core_registers_[TR] = true; |
| 1583 | |
| 1584 | // Reserve T9 for function calls |
| 1585 | blocked_core_registers_[T9] = true; |
| 1586 | |
Goran Jakovljevic | 782be11 | 2016-06-21 12:39:04 +0200 | [diff] [blame] | 1587 | if (GetGraph()->IsDebuggable()) { |
| 1588 | // Stubs do not save callee-save floating point registers. If the graph |
| 1589 | // is debuggable, we need to deal with these registers differently. For |
| 1590 | // now, just block them. |
| 1591 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1592 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1593 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1594 | } |
| 1595 | } |
| 1596 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1597 | size_t CodeGeneratorMIPS64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1598 | __ StoreToOffset(kStoreDoubleword, GpuRegister(reg_id), SP, stack_index); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1599 | return kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | size_t CodeGeneratorMIPS64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1603 | __ LoadFromOffset(kLoadDoubleword, GpuRegister(reg_id), SP, stack_index); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 1604 | return kMips64DoublewordSize; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1605 | } |
| 1606 | |
| 1607 | size_t CodeGeneratorMIPS64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1608 | __ StoreFpuToOffset(GetGraph()->HasSIMD() ? kStoreQuadword : kStoreDoubleword, |
| 1609 | FpuRegister(reg_id), |
| 1610 | SP, |
| 1611 | stack_index); |
| 1612 | return GetFloatingPointSpillSlotSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1613 | } |
| 1614 | |
| 1615 | size_t CodeGeneratorMIPS64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1616 | __ LoadFpuFromOffset(GetGraph()->HasSIMD() ? kLoadQuadword : kLoadDoubleword, |
| 1617 | FpuRegister(reg_id), |
| 1618 | SP, |
| 1619 | stack_index); |
| 1620 | return GetFloatingPointSpillSlotSize(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | void CodeGeneratorMIPS64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 1624 | stream << GpuRegister(reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1625 | } |
| 1626 | |
| 1627 | void CodeGeneratorMIPS64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | 9f0dece | 2015-09-21 18:20:26 +0100 | [diff] [blame] | 1628 | stream << FpuRegister(reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1629 | } |
| 1630 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1631 | void CodeGeneratorMIPS64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1632 | HInstruction* instruction, |
| 1633 | uint32_t dex_pc, |
| 1634 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1635 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1636 | GenerateInvokeRuntime(GetThreadOffset<kMips64PointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 1637 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1638 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1639 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1640 | } |
| 1641 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1642 | void CodeGeneratorMIPS64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1643 | HInstruction* instruction, |
| 1644 | SlowPathCode* slow_path) { |
| 1645 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| 1646 | GenerateInvokeRuntime(entry_point_offset); |
| 1647 | } |
| 1648 | |
| 1649 | void CodeGeneratorMIPS64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
| 1650 | __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset); |
| 1651 | __ Jalr(T9); |
| 1652 | __ Nop(); |
| 1653 | } |
| 1654 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1655 | void InstructionCodeGeneratorMIPS64::GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path, |
| 1656 | GpuRegister class_reg) { |
| 1657 | __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 1658 | __ LoadConst32(AT, mirror::Class::kStatusInitialized); |
| 1659 | __ Bltc(TMP, AT, slow_path->GetEntryLabel()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1660 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 1661 | __ Sync(0); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1662 | __ Bind(slow_path->GetExitLabel()); |
| 1663 | } |
| 1664 | |
| 1665 | void InstructionCodeGeneratorMIPS64::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1666 | __ Sync(0); // only stype 0 is supported |
| 1667 | } |
| 1668 | |
| 1669 | void InstructionCodeGeneratorMIPS64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1670 | HBasicBlock* successor) { |
| 1671 | SuspendCheckSlowPathMIPS64* slow_path = |
| 1672 | new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS64(instruction, successor); |
| 1673 | codegen_->AddSlowPath(slow_path); |
| 1674 | |
| 1675 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1676 | TMP, |
| 1677 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1678 | Thread::ThreadFlagsOffset<kMips64PointerSize>().Int32Value()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1679 | if (successor == nullptr) { |
| 1680 | __ Bnezc(TMP, slow_path->GetEntryLabel()); |
| 1681 | __ Bind(slow_path->GetReturnLabel()); |
| 1682 | } else { |
| 1683 | __ Beqzc(TMP, codegen_->GetLabelOf(successor)); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1684 | __ Bc(slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1685 | // slow_path will return to GetLabelOf(successor). |
| 1686 | } |
| 1687 | } |
| 1688 | |
| 1689 | InstructionCodeGeneratorMIPS64::InstructionCodeGeneratorMIPS64(HGraph* graph, |
| 1690 | CodeGeneratorMIPS64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1691 | : InstructionCodeGenerator(graph, codegen), |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1692 | assembler_(codegen->GetAssembler()), |
| 1693 | codegen_(codegen) {} |
| 1694 | |
| 1695 | void LocationsBuilderMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1696 | DCHECK_EQ(instruction->InputCount(), 2U); |
| 1697 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1698 | Primitive::Type type = instruction->GetResultType(); |
| 1699 | switch (type) { |
| 1700 | case Primitive::kPrimInt: |
| 1701 | case Primitive::kPrimLong: { |
| 1702 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1703 | HInstruction* right = instruction->InputAt(1); |
| 1704 | bool can_use_imm = false; |
| 1705 | if (right->IsConstant()) { |
| 1706 | int64_t imm = CodeGenerator::GetInt64ValueOf(right->AsConstant()); |
| 1707 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 1708 | can_use_imm = IsUint<16>(imm); |
| 1709 | } else if (instruction->IsAdd()) { |
| 1710 | can_use_imm = IsInt<16>(imm); |
| 1711 | } else { |
| 1712 | DCHECK(instruction->IsSub()); |
| 1713 | can_use_imm = IsInt<16>(-imm); |
| 1714 | } |
| 1715 | } |
| 1716 | if (can_use_imm) |
| 1717 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 1718 | else |
| 1719 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1720 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1721 | } |
| 1722 | break; |
| 1723 | |
| 1724 | case Primitive::kPrimFloat: |
| 1725 | case Primitive::kPrimDouble: |
| 1726 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1727 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1728 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1729 | break; |
| 1730 | |
| 1731 | default: |
| 1732 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 1733 | } |
| 1734 | } |
| 1735 | |
| 1736 | void InstructionCodeGeneratorMIPS64::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1737 | Primitive::Type type = instruction->GetType(); |
| 1738 | LocationSummary* locations = instruction->GetLocations(); |
| 1739 | |
| 1740 | switch (type) { |
| 1741 | case Primitive::kPrimInt: |
| 1742 | case Primitive::kPrimLong: { |
| 1743 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 1744 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1745 | Location rhs_location = locations->InAt(1); |
| 1746 | |
| 1747 | GpuRegister rhs_reg = ZERO; |
| 1748 | int64_t rhs_imm = 0; |
| 1749 | bool use_imm = rhs_location.IsConstant(); |
| 1750 | if (use_imm) { |
| 1751 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 1752 | } else { |
| 1753 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 1754 | } |
| 1755 | |
| 1756 | if (instruction->IsAnd()) { |
| 1757 | if (use_imm) |
| 1758 | __ Andi(dst, lhs, rhs_imm); |
| 1759 | else |
| 1760 | __ And(dst, lhs, rhs_reg); |
| 1761 | } else if (instruction->IsOr()) { |
| 1762 | if (use_imm) |
| 1763 | __ Ori(dst, lhs, rhs_imm); |
| 1764 | else |
| 1765 | __ Or(dst, lhs, rhs_reg); |
| 1766 | } else if (instruction->IsXor()) { |
| 1767 | if (use_imm) |
| 1768 | __ Xori(dst, lhs, rhs_imm); |
| 1769 | else |
| 1770 | __ Xor(dst, lhs, rhs_reg); |
| 1771 | } else if (instruction->IsAdd()) { |
| 1772 | if (type == Primitive::kPrimInt) { |
| 1773 | if (use_imm) |
| 1774 | __ Addiu(dst, lhs, rhs_imm); |
| 1775 | else |
| 1776 | __ Addu(dst, lhs, rhs_reg); |
| 1777 | } else { |
| 1778 | if (use_imm) |
| 1779 | __ Daddiu(dst, lhs, rhs_imm); |
| 1780 | else |
| 1781 | __ Daddu(dst, lhs, rhs_reg); |
| 1782 | } |
| 1783 | } else { |
| 1784 | DCHECK(instruction->IsSub()); |
| 1785 | if (type == Primitive::kPrimInt) { |
| 1786 | if (use_imm) |
| 1787 | __ Addiu(dst, lhs, -rhs_imm); |
| 1788 | else |
| 1789 | __ Subu(dst, lhs, rhs_reg); |
| 1790 | } else { |
| 1791 | if (use_imm) |
| 1792 | __ Daddiu(dst, lhs, -rhs_imm); |
| 1793 | else |
| 1794 | __ Dsubu(dst, lhs, rhs_reg); |
| 1795 | } |
| 1796 | } |
| 1797 | break; |
| 1798 | } |
| 1799 | case Primitive::kPrimFloat: |
| 1800 | case Primitive::kPrimDouble: { |
| 1801 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 1802 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 1803 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 1804 | if (instruction->IsAdd()) { |
| 1805 | if (type == Primitive::kPrimFloat) |
| 1806 | __ AddS(dst, lhs, rhs); |
| 1807 | else |
| 1808 | __ AddD(dst, lhs, rhs); |
| 1809 | } else if (instruction->IsSub()) { |
| 1810 | if (type == Primitive::kPrimFloat) |
| 1811 | __ SubS(dst, lhs, rhs); |
| 1812 | else |
| 1813 | __ SubD(dst, lhs, rhs); |
| 1814 | } else { |
| 1815 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
| 1816 | } |
| 1817 | break; |
| 1818 | } |
| 1819 | default: |
| 1820 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 1821 | } |
| 1822 | } |
| 1823 | |
| 1824 | void LocationsBuilderMIPS64::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1825 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1826 | |
| 1827 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1828 | Primitive::Type type = instr->GetResultType(); |
| 1829 | switch (type) { |
| 1830 | case Primitive::kPrimInt: |
| 1831 | case Primitive::kPrimLong: { |
| 1832 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1833 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 1834 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1835 | break; |
| 1836 | } |
| 1837 | default: |
| 1838 | LOG(FATAL) << "Unexpected shift type " << type; |
| 1839 | } |
| 1840 | } |
| 1841 | |
| 1842 | void InstructionCodeGeneratorMIPS64::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1843 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1844 | LocationSummary* locations = instr->GetLocations(); |
| 1845 | Primitive::Type type = instr->GetType(); |
| 1846 | |
| 1847 | switch (type) { |
| 1848 | case Primitive::kPrimInt: |
| 1849 | case Primitive::kPrimLong: { |
| 1850 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 1851 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 1852 | Location rhs_location = locations->InAt(1); |
| 1853 | |
| 1854 | GpuRegister rhs_reg = ZERO; |
| 1855 | int64_t rhs_imm = 0; |
| 1856 | bool use_imm = rhs_location.IsConstant(); |
| 1857 | if (use_imm) { |
| 1858 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 1859 | } else { |
| 1860 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 1861 | } |
| 1862 | |
| 1863 | if (use_imm) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 1864 | uint32_t shift_value = rhs_imm & |
| 1865 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1866 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1867 | if (shift_value == 0) { |
| 1868 | if (dst != lhs) { |
| 1869 | __ Move(dst, lhs); |
| 1870 | } |
| 1871 | } else if (type == Primitive::kPrimInt) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1872 | if (instr->IsShl()) { |
| 1873 | __ Sll(dst, lhs, shift_value); |
| 1874 | } else if (instr->IsShr()) { |
| 1875 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1876 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1877 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1878 | } else { |
| 1879 | __ Rotr(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1880 | } |
| 1881 | } else { |
| 1882 | if (shift_value < 32) { |
| 1883 | if (instr->IsShl()) { |
| 1884 | __ Dsll(dst, lhs, shift_value); |
| 1885 | } else if (instr->IsShr()) { |
| 1886 | __ Dsra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1887 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1888 | __ Dsrl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1889 | } else { |
| 1890 | __ Drotr(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1891 | } |
| 1892 | } else { |
| 1893 | shift_value -= 32; |
| 1894 | if (instr->IsShl()) { |
| 1895 | __ Dsll32(dst, lhs, shift_value); |
| 1896 | } else if (instr->IsShr()) { |
| 1897 | __ Dsra32(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1898 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1899 | __ Dsrl32(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1900 | } else { |
| 1901 | __ Drotr32(dst, lhs, shift_value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1902 | } |
| 1903 | } |
| 1904 | } |
| 1905 | } else { |
| 1906 | if (type == Primitive::kPrimInt) { |
| 1907 | if (instr->IsShl()) { |
| 1908 | __ Sllv(dst, lhs, rhs_reg); |
| 1909 | } else if (instr->IsShr()) { |
| 1910 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1911 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1912 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1913 | } else { |
| 1914 | __ Rotrv(dst, lhs, rhs_reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1915 | } |
| 1916 | } else { |
| 1917 | if (instr->IsShl()) { |
| 1918 | __ Dsllv(dst, lhs, rhs_reg); |
| 1919 | } else if (instr->IsShr()) { |
| 1920 | __ Dsrav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1921 | } else if (instr->IsUShr()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1922 | __ Dsrlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1923 | } else { |
| 1924 | __ Drotrv(dst, lhs, rhs_reg); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1925 | } |
| 1926 | } |
| 1927 | } |
| 1928 | break; |
| 1929 | } |
| 1930 | default: |
| 1931 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 1932 | } |
| 1933 | } |
| 1934 | |
| 1935 | void LocationsBuilderMIPS64::VisitAdd(HAdd* instruction) { |
| 1936 | HandleBinaryOp(instruction); |
| 1937 | } |
| 1938 | |
| 1939 | void InstructionCodeGeneratorMIPS64::VisitAdd(HAdd* instruction) { |
| 1940 | HandleBinaryOp(instruction); |
| 1941 | } |
| 1942 | |
| 1943 | void LocationsBuilderMIPS64::VisitAnd(HAnd* instruction) { |
| 1944 | HandleBinaryOp(instruction); |
| 1945 | } |
| 1946 | |
| 1947 | void InstructionCodeGeneratorMIPS64::VisitAnd(HAnd* instruction) { |
| 1948 | HandleBinaryOp(instruction); |
| 1949 | } |
| 1950 | |
| 1951 | void LocationsBuilderMIPS64::VisitArrayGet(HArrayGet* instruction) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1952 | Primitive::Type type = instruction->GetType(); |
| 1953 | bool object_array_get_with_read_barrier = |
| 1954 | kEmitCompilerReadBarrier && (type == Primitive::kPrimNot); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1955 | LocationSummary* locations = |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1956 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 1957 | object_array_get_with_read_barrier |
| 1958 | ? LocationSummary::kCallOnSlowPath |
| 1959 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 1960 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 1961 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 1962 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1963 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1964 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1965 | if (Primitive::IsFloatingPointType(type)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1966 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1967 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1968 | // The output overlaps in the case of an object array get with |
| 1969 | // read barriers enabled: we do not want the move to overwrite the |
| 1970 | // array's location, as we need it to emit the read barrier. |
| 1971 | locations->SetOut(Location::RequiresRegister(), |
| 1972 | object_array_get_with_read_barrier |
| 1973 | ? Location::kOutputOverlap |
| 1974 | : Location::kNoOutputOverlap); |
| 1975 | } |
| 1976 | // We need a temporary register for the read barrier marking slow |
| 1977 | // path in CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier. |
| 1978 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 1979 | locations->AddTemp(Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1980 | } |
| 1981 | } |
| 1982 | |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 1983 | static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS64* codegen) { |
| 1984 | auto null_checker = [codegen, instruction]() { |
| 1985 | codegen->MaybeRecordImplicitNullCheck(instruction); |
| 1986 | }; |
| 1987 | return null_checker; |
| 1988 | } |
| 1989 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1990 | void InstructionCodeGeneratorMIPS64::VisitArrayGet(HArrayGet* instruction) { |
| 1991 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1992 | Location obj_loc = locations->InAt(0); |
| 1993 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
| 1994 | Location out_loc = locations->Out(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1995 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 1996 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 1997 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1998 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 1999 | Primitive::Type type = instruction->GetType(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2000 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2001 | instruction->IsStringCharAt(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2002 | switch (type) { |
| 2003 | case Primitive::kPrimBoolean: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2004 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2005 | if (index.IsConstant()) { |
| 2006 | size_t offset = |
| 2007 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2008 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2009 | } else { |
| 2010 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2011 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2012 | } |
| 2013 | break; |
| 2014 | } |
| 2015 | |
| 2016 | case Primitive::kPrimByte: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2017 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2018 | if (index.IsConstant()) { |
| 2019 | size_t offset = |
| 2020 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2021 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2022 | } else { |
| 2023 | __ Daddu(TMP, obj, index.AsRegister<GpuRegister>()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2024 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2025 | } |
| 2026 | break; |
| 2027 | } |
| 2028 | |
| 2029 | case Primitive::kPrimShort: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2030 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2031 | if (index.IsConstant()) { |
| 2032 | size_t offset = |
| 2033 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2034 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2035 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2036 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_2); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2037 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2038 | } |
| 2039 | break; |
| 2040 | } |
| 2041 | |
| 2042 | case Primitive::kPrimChar: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2043 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2044 | if (maybe_compressed_char_at) { |
| 2045 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2046 | __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2047 | __ Dext(TMP, TMP, 0, 1); |
| 2048 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2049 | "Expecting 0=compressed, 1=uncompressed"); |
| 2050 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2051 | if (index.IsConstant()) { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2052 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 2053 | if (maybe_compressed_char_at) { |
| 2054 | Mips64Label uncompressed_load, done; |
| 2055 | __ Bnezc(TMP, &uncompressed_load); |
| 2056 | __ LoadFromOffset(kLoadUnsignedByte, |
| 2057 | out, |
| 2058 | obj, |
| 2059 | data_offset + (const_index << TIMES_1)); |
| 2060 | __ Bc(&done); |
| 2061 | __ Bind(&uncompressed_load); |
| 2062 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2063 | out, |
| 2064 | obj, |
| 2065 | data_offset + (const_index << TIMES_2)); |
| 2066 | __ Bind(&done); |
| 2067 | } else { |
| 2068 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2069 | out, |
| 2070 | obj, |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2071 | data_offset + (const_index << TIMES_2), |
| 2072 | null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2073 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2074 | } else { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2075 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
| 2076 | if (maybe_compressed_char_at) { |
| 2077 | Mips64Label uncompressed_load, done; |
| 2078 | __ Bnezc(TMP, &uncompressed_load); |
| 2079 | __ Daddu(TMP, obj, index_reg); |
| 2080 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 2081 | __ Bc(&done); |
| 2082 | __ Bind(&uncompressed_load); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2083 | __ Dlsa(TMP, index_reg, obj, TIMES_2); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2084 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 2085 | __ Bind(&done); |
| 2086 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2087 | __ Dlsa(TMP, index_reg, obj, TIMES_2); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2088 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2089 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2090 | } |
| 2091 | break; |
| 2092 | } |
| 2093 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2094 | case Primitive::kPrimInt: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2095 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2096 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2097 | LoadOperandType load_type = (type == Primitive::kPrimNot) ? kLoadUnsignedWord : kLoadWord; |
| 2098 | if (index.IsConstant()) { |
| 2099 | size_t offset = |
| 2100 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2101 | __ LoadFromOffset(load_type, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2102 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2103 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2104 | __ LoadFromOffset(load_type, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2105 | } |
| 2106 | break; |
| 2107 | } |
| 2108 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2109 | case Primitive::kPrimNot: { |
| 2110 | static_assert( |
| 2111 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2112 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2113 | // /* HeapReference<Object> */ out = |
| 2114 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 2115 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2116 | Location temp = locations->GetTemp(0); |
| 2117 | // Note that a potential implicit null check is handled in this |
| 2118 | // CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier call. |
| 2119 | codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction, |
| 2120 | out_loc, |
| 2121 | obj, |
| 2122 | data_offset, |
| 2123 | index, |
| 2124 | temp, |
| 2125 | /* needs_null_check */ true); |
| 2126 | } else { |
| 2127 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 2128 | if (index.IsConstant()) { |
| 2129 | size_t offset = |
| 2130 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2131 | __ LoadFromOffset(kLoadUnsignedWord, out, obj, offset, null_checker); |
| 2132 | // If read barriers are enabled, emit read barriers other than |
| 2133 | // Baker's using a slow path (and also unpoison the loaded |
| 2134 | // reference, if heap poisoning is enabled). |
| 2135 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 2136 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2137 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2138 | __ LoadFromOffset(kLoadUnsignedWord, out, TMP, data_offset, null_checker); |
| 2139 | // If read barriers are enabled, emit read barriers other than |
| 2140 | // Baker's using a slow path (and also unpoison the loaded |
| 2141 | // reference, if heap poisoning is enabled). |
| 2142 | codegen_->MaybeGenerateReadBarrierSlow(instruction, |
| 2143 | out_loc, |
| 2144 | out_loc, |
| 2145 | obj_loc, |
| 2146 | data_offset, |
| 2147 | index); |
| 2148 | } |
| 2149 | } |
| 2150 | break; |
| 2151 | } |
| 2152 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2153 | case Primitive::kPrimLong: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2154 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2155 | if (index.IsConstant()) { |
| 2156 | size_t offset = |
| 2157 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2158 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2159 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2160 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2161 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2162 | } |
| 2163 | break; |
| 2164 | } |
| 2165 | |
| 2166 | case Primitive::kPrimFloat: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2167 | FpuRegister out = out_loc.AsFpuRegister<FpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2168 | if (index.IsConstant()) { |
| 2169 | size_t offset = |
| 2170 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2171 | __ LoadFpuFromOffset(kLoadWord, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2172 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2173 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2174 | __ LoadFpuFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2175 | } |
| 2176 | break; |
| 2177 | } |
| 2178 | |
| 2179 | case Primitive::kPrimDouble: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2180 | FpuRegister out = out_loc.AsFpuRegister<FpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2181 | if (index.IsConstant()) { |
| 2182 | size_t offset = |
| 2183 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2184 | __ LoadFpuFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2185 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2186 | __ Dlsa(TMP, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2187 | __ LoadFpuFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2188 | } |
| 2189 | break; |
| 2190 | } |
| 2191 | |
| 2192 | case Primitive::kPrimVoid: |
| 2193 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2194 | UNREACHABLE(); |
| 2195 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2196 | } |
| 2197 | |
| 2198 | void LocationsBuilderMIPS64::VisitArrayLength(HArrayLength* instruction) { |
| 2199 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2200 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2201 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2202 | } |
| 2203 | |
| 2204 | void InstructionCodeGeneratorMIPS64::VisitArrayLength(HArrayLength* instruction) { |
| 2205 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2206 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2207 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2208 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 2209 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2210 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2211 | // Mask out compression flag from String's array length. |
| 2212 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 2213 | __ Srl(out, out, 1u); |
| 2214 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2215 | } |
| 2216 | |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2217 | Location LocationsBuilderMIPS64::RegisterOrZeroConstant(HInstruction* instruction) { |
| 2218 | return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern()) |
| 2219 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 2220 | : Location::RequiresRegister(); |
| 2221 | } |
| 2222 | |
| 2223 | Location LocationsBuilderMIPS64::FpuRegisterOrConstantForStore(HInstruction* instruction) { |
| 2224 | // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register. |
| 2225 | // We can store a non-zero float or double constant without first loading it into the FPU, |
| 2226 | // but we should only prefer this if the constant has a single use. |
| 2227 | if (instruction->IsConstant() && |
| 2228 | (instruction->AsConstant()->IsZeroBitPattern() || |
| 2229 | instruction->GetUses().HasExactlyOneElement())) { |
| 2230 | return Location::ConstantLocation(instruction->AsConstant()); |
| 2231 | // Otherwise fall through and require an FPU register for the constant. |
| 2232 | } |
| 2233 | return Location::RequiresFpuRegister(); |
| 2234 | } |
| 2235 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2236 | void LocationsBuilderMIPS64::VisitArraySet(HArraySet* instruction) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2237 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2238 | |
| 2239 | bool needs_write_barrier = |
| 2240 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 2241 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 2242 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2243 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2244 | instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2245 | may_need_runtime_call_for_type_check ? |
| 2246 | LocationSummary::kCallOnSlowPath : |
| 2247 | LocationSummary::kNoCall); |
| 2248 | |
| 2249 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2250 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2251 | if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
| 2252 | locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2253 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2254 | locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2))); |
| 2255 | } |
| 2256 | if (needs_write_barrier) { |
| 2257 | // Temporary register for the write barrier. |
| 2258 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2259 | } |
| 2260 | } |
| 2261 | |
| 2262 | void InstructionCodeGeneratorMIPS64::VisitArraySet(HArraySet* instruction) { |
| 2263 | LocationSummary* locations = instruction->GetLocations(); |
| 2264 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2265 | Location index = locations->InAt(1); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2266 | Location value_location = locations->InAt(2); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2267 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2268 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2269 | bool needs_write_barrier = |
| 2270 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2271 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2272 | GpuRegister base_reg = index.IsConstant() ? obj : TMP; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2273 | |
| 2274 | switch (value_type) { |
| 2275 | case Primitive::kPrimBoolean: |
| 2276 | case Primitive::kPrimByte: { |
| 2277 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2278 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2279 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2280 | } else { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2281 | __ Daddu(base_reg, obj, index.AsRegister<GpuRegister>()); |
| 2282 | } |
| 2283 | if (value_location.IsConstant()) { |
| 2284 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2285 | __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker); |
| 2286 | } else { |
| 2287 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2288 | __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2289 | } |
| 2290 | break; |
| 2291 | } |
| 2292 | |
| 2293 | case Primitive::kPrimShort: |
| 2294 | case Primitive::kPrimChar: { |
| 2295 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2296 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2297 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2298 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2299 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_2); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2300 | } |
| 2301 | if (value_location.IsConstant()) { |
| 2302 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2303 | __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker); |
| 2304 | } else { |
| 2305 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2306 | __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2307 | } |
| 2308 | break; |
| 2309 | } |
| 2310 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2311 | case Primitive::kPrimInt: { |
| 2312 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2313 | if (index.IsConstant()) { |
| 2314 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
| 2315 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2316 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2317 | } |
| 2318 | if (value_location.IsConstant()) { |
| 2319 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2320 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2321 | } else { |
| 2322 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2323 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2324 | } |
| 2325 | break; |
| 2326 | } |
| 2327 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2328 | case Primitive::kPrimNot: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2329 | if (value_location.IsConstant()) { |
| 2330 | // Just setting null. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2331 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2332 | if (index.IsConstant()) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2333 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2334 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2335 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2336 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2337 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2338 | DCHECK_EQ(value, 0); |
| 2339 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2340 | DCHECK(!needs_write_barrier); |
| 2341 | DCHECK(!may_need_runtime_call_for_type_check); |
| 2342 | break; |
| 2343 | } |
| 2344 | |
| 2345 | DCHECK(needs_write_barrier); |
| 2346 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2347 | GpuRegister temp1 = locations->GetTemp(0).AsRegister<GpuRegister>(); |
| 2348 | GpuRegister temp2 = TMP; // Doesn't need to survive slow path. |
| 2349 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2350 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2351 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2352 | Mips64Label done; |
| 2353 | SlowPathCodeMIPS64* slow_path = nullptr; |
| 2354 | |
| 2355 | if (may_need_runtime_call_for_type_check) { |
| 2356 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathMIPS64(instruction); |
| 2357 | codegen_->AddSlowPath(slow_path); |
| 2358 | if (instruction->GetValueCanBeNull()) { |
| 2359 | Mips64Label non_zero; |
| 2360 | __ Bnezc(value, &non_zero); |
| 2361 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2362 | if (index.IsConstant()) { |
| 2363 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2364 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2365 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2366 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2367 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2368 | __ Bc(&done); |
| 2369 | __ Bind(&non_zero); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2370 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2371 | |
| 2372 | // Note that when read barriers are enabled, the type checks |
| 2373 | // are performed without read barriers. This is fine, even in |
| 2374 | // the case where a class object is in the from-space after |
| 2375 | // the flip, as a comparison involving such a type would not |
| 2376 | // produce a false positive; it may of course produce a false |
| 2377 | // negative, in which case we would take the ArraySet slow |
| 2378 | // path. |
| 2379 | |
| 2380 | // /* HeapReference<Class> */ temp1 = obj->klass_ |
| 2381 | __ LoadFromOffset(kLoadUnsignedWord, temp1, obj, class_offset, null_checker); |
| 2382 | __ MaybeUnpoisonHeapReference(temp1); |
| 2383 | |
| 2384 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 2385 | __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, component_offset); |
| 2386 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2387 | __ LoadFromOffset(kLoadUnsignedWord, temp2, value, class_offset); |
| 2388 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 2389 | // nor `temp2`, as we are comparing two poisoned references. |
| 2390 | |
| 2391 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2392 | Mips64Label do_put; |
| 2393 | __ Beqc(temp1, temp2, &do_put); |
| 2394 | // If heap poisoning is enabled, the `temp1` reference has |
| 2395 | // not been unpoisoned yet; unpoison it now. |
| 2396 | __ MaybeUnpoisonHeapReference(temp1); |
| 2397 | |
| 2398 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 2399 | __ LoadFromOffset(kLoadUnsignedWord, temp1, temp1, super_offset); |
| 2400 | // If heap poisoning is enabled, no need to unpoison |
| 2401 | // `temp1`, as we are comparing against null below. |
| 2402 | __ Bnezc(temp1, slow_path->GetEntryLabel()); |
| 2403 | __ Bind(&do_put); |
| 2404 | } else { |
| 2405 | __ Bnec(temp1, temp2, slow_path->GetEntryLabel()); |
| 2406 | } |
| 2407 | } |
| 2408 | |
| 2409 | GpuRegister source = value; |
| 2410 | if (kPoisonHeapReferences) { |
| 2411 | // Note that in the case where `value` is a null reference, |
| 2412 | // we do not enter this block, as a null reference does not |
| 2413 | // need poisoning. |
| 2414 | __ Move(temp1, value); |
| 2415 | __ PoisonHeapReference(temp1); |
| 2416 | source = temp1; |
| 2417 | } |
| 2418 | |
| 2419 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2420 | if (index.IsConstant()) { |
| 2421 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2422 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2423 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2424 | } |
| 2425 | __ StoreToOffset(kStoreWord, source, base_reg, data_offset); |
| 2426 | |
| 2427 | if (!may_need_runtime_call_for_type_check) { |
| 2428 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2429 | } |
| 2430 | |
| 2431 | codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull()); |
| 2432 | |
| 2433 | if (done.IsLinked()) { |
| 2434 | __ Bind(&done); |
| 2435 | } |
| 2436 | |
| 2437 | if (slow_path != nullptr) { |
| 2438 | __ Bind(slow_path->GetExitLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2439 | } |
| 2440 | break; |
| 2441 | } |
| 2442 | |
| 2443 | case Primitive::kPrimLong: { |
| 2444 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2445 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2446 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2447 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2448 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2449 | } |
| 2450 | if (value_location.IsConstant()) { |
| 2451 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2452 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2453 | } else { |
| 2454 | GpuRegister value = value_location.AsRegister<GpuRegister>(); |
| 2455 | __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2456 | } |
| 2457 | break; |
| 2458 | } |
| 2459 | |
| 2460 | case Primitive::kPrimFloat: { |
| 2461 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2462 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2463 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2464 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2465 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_4); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2466 | } |
| 2467 | if (value_location.IsConstant()) { |
| 2468 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2469 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2470 | } else { |
| 2471 | FpuRegister value = value_location.AsFpuRegister<FpuRegister>(); |
| 2472 | __ StoreFpuToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2473 | } |
| 2474 | break; |
| 2475 | } |
| 2476 | |
| 2477 | case Primitive::kPrimDouble: { |
| 2478 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2479 | if (index.IsConstant()) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2480 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2481 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2482 | __ Dlsa(base_reg, index.AsRegister<GpuRegister>(), obj, TIMES_8); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 2483 | } |
| 2484 | if (value_location.IsConstant()) { |
| 2485 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2486 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2487 | } else { |
| 2488 | FpuRegister value = value_location.AsFpuRegister<FpuRegister>(); |
| 2489 | __ StoreFpuToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2490 | } |
| 2491 | break; |
| 2492 | } |
| 2493 | |
| 2494 | case Primitive::kPrimVoid: |
| 2495 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2496 | UNREACHABLE(); |
| 2497 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2498 | } |
| 2499 | |
| 2500 | void LocationsBuilderMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2501 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2502 | InvokeRuntimeCallingConvention calling_convention; |
| 2503 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2504 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2505 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2506 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2507 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2508 | } |
| 2509 | |
| 2510 | void InstructionCodeGeneratorMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2511 | LocationSummary* locations = instruction->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2512 | BoundsCheckSlowPathMIPS64* slow_path = |
| 2513 | new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS64(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2514 | codegen_->AddSlowPath(slow_path); |
| 2515 | |
| 2516 | GpuRegister index = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2517 | GpuRegister length = locations->InAt(1).AsRegister<GpuRegister>(); |
| 2518 | |
| 2519 | // length is limited by the maximum positive signed 32-bit integer. |
| 2520 | // Unsigned comparison of length and index checks for index < 0 |
| 2521 | // and for length <= index simultaneously. |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 2522 | __ Bgeuc(index, length, slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2523 | } |
| 2524 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2525 | // Temp is used for read barrier. |
| 2526 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 2527 | if (kEmitCompilerReadBarrier && |
| 2528 | (kUseBakerReadBarrier || |
| 2529 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 2530 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 2531 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 2532 | return 1; |
| 2533 | } |
| 2534 | return 0; |
| 2535 | } |
| 2536 | |
| 2537 | // Extra temp is used for read barrier. |
| 2538 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 2539 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 2540 | } |
| 2541 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2542 | void LocationsBuilderMIPS64::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2543 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 2544 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 2545 | |
| 2546 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 2547 | switch (type_check_kind) { |
| 2548 | case TypeCheckKind::kExactCheck: |
| 2549 | case TypeCheckKind::kAbstractClassCheck: |
| 2550 | case TypeCheckKind::kClassHierarchyCheck: |
| 2551 | case TypeCheckKind::kArrayObjectCheck: |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2552 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2553 | ? LocationSummary::kCallOnSlowPath |
| 2554 | : LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
| 2555 | break; |
| 2556 | case TypeCheckKind::kArrayCheck: |
| 2557 | case TypeCheckKind::kUnresolvedCheck: |
| 2558 | case TypeCheckKind::kInterfaceCheck: |
| 2559 | call_kind = LocationSummary::kCallOnSlowPath; |
| 2560 | break; |
| 2561 | } |
| 2562 | |
| 2563 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2564 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2565 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2566 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2567 | } |
| 2568 | |
| 2569 | void InstructionCodeGeneratorMIPS64::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2570 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2571 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2572 | Location obj_loc = locations->InAt(0); |
| 2573 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2574 | GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2575 | Location temp_loc = locations->GetTemp(0); |
| 2576 | GpuRegister temp = temp_loc.AsRegister<GpuRegister>(); |
| 2577 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 2578 | DCHECK_LE(num_temps, 2u); |
| 2579 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2580 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2581 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2582 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2583 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 2584 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 2585 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 2586 | const uint32_t object_array_data_offset = |
| 2587 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| 2588 | Mips64Label done; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2589 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2590 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 2591 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 2592 | // read barriers is done for performance and code size reasons. |
| 2593 | bool is_type_check_slow_path_fatal = false; |
| 2594 | if (!kEmitCompilerReadBarrier) { |
| 2595 | is_type_check_slow_path_fatal = |
| 2596 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 2597 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 2598 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 2599 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 2600 | !instruction->CanThrowIntoCatchBlock(); |
| 2601 | } |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2602 | SlowPathCodeMIPS64* slow_path = |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2603 | new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction, |
| 2604 | is_type_check_slow_path_fatal); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2605 | codegen_->AddSlowPath(slow_path); |
| 2606 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2607 | // Avoid this check if we know `obj` is not null. |
| 2608 | if (instruction->MustDoNullCheck()) { |
| 2609 | __ Beqzc(obj, &done); |
| 2610 | } |
| 2611 | |
| 2612 | switch (type_check_kind) { |
| 2613 | case TypeCheckKind::kExactCheck: |
| 2614 | case TypeCheckKind::kArrayCheck: { |
| 2615 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2616 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2617 | temp_loc, |
| 2618 | obj_loc, |
| 2619 | class_offset, |
| 2620 | maybe_temp2_loc, |
| 2621 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2622 | // Jump to slow path for throwing the exception or doing a |
| 2623 | // more involved array check. |
| 2624 | __ Bnec(temp, cls, slow_path->GetEntryLabel()); |
| 2625 | break; |
| 2626 | } |
| 2627 | |
| 2628 | case TypeCheckKind::kAbstractClassCheck: { |
| 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 | // If the class is abstract, we eagerly fetch the super class of the |
| 2637 | // object to avoid doing a comparison we know will fail. |
| 2638 | Mips64Label loop; |
| 2639 | __ Bind(&loop); |
| 2640 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2641 | GenerateReferenceLoadOneRegister(instruction, |
| 2642 | temp_loc, |
| 2643 | super_offset, |
| 2644 | maybe_temp2_loc, |
| 2645 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2646 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 2647 | // exception. |
| 2648 | __ Beqzc(temp, slow_path->GetEntryLabel()); |
| 2649 | // Otherwise, compare the classes. |
| 2650 | __ Bnec(temp, cls, &loop); |
| 2651 | break; |
| 2652 | } |
| 2653 | |
| 2654 | case TypeCheckKind::kClassHierarchyCheck: { |
| 2655 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2656 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2657 | temp_loc, |
| 2658 | obj_loc, |
| 2659 | class_offset, |
| 2660 | maybe_temp2_loc, |
| 2661 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2662 | // Walk over the class hierarchy to find a match. |
| 2663 | Mips64Label loop; |
| 2664 | __ Bind(&loop); |
| 2665 | __ Beqc(temp, cls, &done); |
| 2666 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2667 | GenerateReferenceLoadOneRegister(instruction, |
| 2668 | temp_loc, |
| 2669 | super_offset, |
| 2670 | maybe_temp2_loc, |
| 2671 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2672 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 2673 | // exception. Otherwise, jump to the beginning of the loop. |
| 2674 | __ Bnezc(temp, &loop); |
| 2675 | __ Bc(slow_path->GetEntryLabel()); |
| 2676 | break; |
| 2677 | } |
| 2678 | |
| 2679 | case TypeCheckKind::kArrayObjectCheck: { |
| 2680 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2681 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2682 | temp_loc, |
| 2683 | obj_loc, |
| 2684 | class_offset, |
| 2685 | maybe_temp2_loc, |
| 2686 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2687 | // Do an exact check. |
| 2688 | __ Beqc(temp, cls, &done); |
| 2689 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 2690 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2691 | GenerateReferenceLoadOneRegister(instruction, |
| 2692 | temp_loc, |
| 2693 | component_offset, |
| 2694 | maybe_temp2_loc, |
| 2695 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2696 | // If the component type is null, jump to the slow path to throw the exception. |
| 2697 | __ Beqzc(temp, slow_path->GetEntryLabel()); |
| 2698 | // Otherwise, the object is indeed an array, further check that this component |
| 2699 | // type is not a primitive type. |
| 2700 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 2701 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 2702 | __ Bnezc(temp, slow_path->GetEntryLabel()); |
| 2703 | break; |
| 2704 | } |
| 2705 | |
| 2706 | case TypeCheckKind::kUnresolvedCheck: |
| 2707 | // We always go into the type check slow path for the unresolved check case. |
| 2708 | // We cannot directly call the CheckCast runtime entry point |
| 2709 | // without resorting to a type checking slow path here (i.e. by |
| 2710 | // calling InvokeRuntime directly), as it would require to |
| 2711 | // assign fixed registers for the inputs of this HInstanceOf |
| 2712 | // instruction (following the runtime calling convention), which |
| 2713 | // might be cluttered by the potential first read barrier |
| 2714 | // emission at the beginning of this method. |
| 2715 | __ Bc(slow_path->GetEntryLabel()); |
| 2716 | break; |
| 2717 | |
| 2718 | case TypeCheckKind::kInterfaceCheck: { |
| 2719 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 2720 | // positives by doing this. |
| 2721 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2722 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2723 | temp_loc, |
| 2724 | obj_loc, |
| 2725 | class_offset, |
| 2726 | maybe_temp2_loc, |
| 2727 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2728 | // /* HeapReference<Class> */ temp = temp->iftable_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2729 | GenerateReferenceLoadTwoRegisters(instruction, |
| 2730 | temp_loc, |
| 2731 | temp_loc, |
| 2732 | iftable_offset, |
| 2733 | maybe_temp2_loc, |
| 2734 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 2735 | // Iftable is never null. |
| 2736 | __ Lw(TMP, temp, array_length_offset); |
| 2737 | // Loop through the iftable and check if any class matches. |
| 2738 | Mips64Label loop; |
| 2739 | __ Bind(&loop); |
| 2740 | __ Beqzc(TMP, slow_path->GetEntryLabel()); |
| 2741 | __ Lwu(AT, temp, object_array_data_offset); |
| 2742 | __ MaybeUnpoisonHeapReference(AT); |
| 2743 | // Go to next interface. |
| 2744 | __ Daddiu(temp, temp, 2 * kHeapReferenceSize); |
| 2745 | __ Addiu(TMP, TMP, -2); |
| 2746 | // Compare the classes and continue the loop if they do not match. |
| 2747 | __ Bnec(AT, cls, &loop); |
| 2748 | break; |
| 2749 | } |
| 2750 | } |
| 2751 | |
| 2752 | __ Bind(&done); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2753 | __ Bind(slow_path->GetExitLabel()); |
| 2754 | } |
| 2755 | |
| 2756 | void LocationsBuilderMIPS64::VisitClinitCheck(HClinitCheck* check) { |
| 2757 | LocationSummary* locations = |
| 2758 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2759 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2760 | if (check->HasUses()) { |
| 2761 | locations->SetOut(Location::SameAsFirstInput()); |
| 2762 | } |
| 2763 | } |
| 2764 | |
| 2765 | void InstructionCodeGeneratorMIPS64::VisitClinitCheck(HClinitCheck* check) { |
| 2766 | // We assume the class is not null. |
| 2767 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64( |
| 2768 | check->GetLoadClass(), |
| 2769 | check, |
| 2770 | check->GetDexPc(), |
| 2771 | true); |
| 2772 | codegen_->AddSlowPath(slow_path); |
| 2773 | GenerateClassInitializationCheck(slow_path, |
| 2774 | check->GetLocations()->InAt(0).AsRegister<GpuRegister>()); |
| 2775 | } |
| 2776 | |
| 2777 | void LocationsBuilderMIPS64::VisitCompare(HCompare* compare) { |
| 2778 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 2779 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2780 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(compare); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2781 | |
| 2782 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2783 | case Primitive::kPrimBoolean: |
| 2784 | case Primitive::kPrimByte: |
| 2785 | case Primitive::kPrimShort: |
| 2786 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2787 | case Primitive::kPrimInt: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2788 | case Primitive::kPrimLong: |
| 2789 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 2790 | locations->SetInAt(1, Location::RegisterOrConstant(compare->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2791 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2792 | break; |
| 2793 | |
| 2794 | case Primitive::kPrimFloat: |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2795 | case Primitive::kPrimDouble: |
| 2796 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2797 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2798 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2799 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2800 | |
| 2801 | default: |
| 2802 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2803 | } |
| 2804 | } |
| 2805 | |
| 2806 | void InstructionCodeGeneratorMIPS64::VisitCompare(HCompare* instruction) { |
| 2807 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2808 | GpuRegister res = locations->Out().AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2809 | Primitive::Type in_type = instruction->InputAt(0)->GetType(); |
| 2810 | |
| 2811 | // 0 if: left == right |
| 2812 | // 1 if: left > right |
| 2813 | // -1 if: left < right |
| 2814 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2815 | case Primitive::kPrimBoolean: |
| 2816 | case Primitive::kPrimByte: |
| 2817 | case Primitive::kPrimShort: |
| 2818 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2819 | case Primitive::kPrimInt: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2820 | case Primitive::kPrimLong: { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2821 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 2822 | Location rhs_location = locations->InAt(1); |
| 2823 | bool use_imm = rhs_location.IsConstant(); |
| 2824 | GpuRegister rhs = ZERO; |
| 2825 | if (use_imm) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2826 | if (in_type == Primitive::kPrimLong) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2827 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 2828 | if (value != 0) { |
| 2829 | rhs = AT; |
| 2830 | __ LoadConst64(rhs, value); |
| 2831 | } |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2832 | } else { |
| 2833 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 2834 | if (value != 0) { |
| 2835 | rhs = AT; |
| 2836 | __ LoadConst32(rhs, value); |
| 2837 | } |
Alexey Frunze | 5c75ffa | 2015-09-24 14:41:59 -0700 | [diff] [blame] | 2838 | } |
| 2839 | } else { |
| 2840 | rhs = rhs_location.AsRegister<GpuRegister>(); |
| 2841 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2842 | __ Slt(TMP, lhs, rhs); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2843 | __ Slt(res, rhs, lhs); |
| 2844 | __ Subu(res, res, TMP); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2845 | break; |
| 2846 | } |
| 2847 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2848 | case Primitive::kPrimFloat: { |
| 2849 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 2850 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 2851 | Mips64Label done; |
| 2852 | __ CmpEqS(FTMP, lhs, rhs); |
| 2853 | __ LoadConst32(res, 0); |
| 2854 | __ Bc1nez(FTMP, &done); |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 2855 | if (instruction->IsGtBias()) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2856 | __ CmpLtS(FTMP, lhs, rhs); |
| 2857 | __ LoadConst32(res, -1); |
| 2858 | __ Bc1nez(FTMP, &done); |
| 2859 | __ LoadConst32(res, 1); |
| 2860 | } else { |
| 2861 | __ CmpLtS(FTMP, rhs, lhs); |
| 2862 | __ LoadConst32(res, 1); |
| 2863 | __ Bc1nez(FTMP, &done); |
| 2864 | __ LoadConst32(res, -1); |
| 2865 | } |
| 2866 | __ Bind(&done); |
| 2867 | break; |
| 2868 | } |
| 2869 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2870 | case Primitive::kPrimDouble: { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2871 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 2872 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 2873 | Mips64Label done; |
| 2874 | __ CmpEqD(FTMP, lhs, rhs); |
| 2875 | __ LoadConst32(res, 0); |
| 2876 | __ Bc1nez(FTMP, &done); |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 2877 | if (instruction->IsGtBias()) { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2878 | __ CmpLtD(FTMP, lhs, rhs); |
| 2879 | __ LoadConst32(res, -1); |
| 2880 | __ Bc1nez(FTMP, &done); |
| 2881 | __ LoadConst32(res, 1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2882 | } else { |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2883 | __ CmpLtD(FTMP, rhs, lhs); |
| 2884 | __ LoadConst32(res, 1); |
| 2885 | __ Bc1nez(FTMP, &done); |
| 2886 | __ LoadConst32(res, -1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2887 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2888 | __ Bind(&done); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2889 | break; |
| 2890 | } |
| 2891 | |
| 2892 | default: |
| 2893 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2894 | } |
| 2895 | } |
| 2896 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2897 | void LocationsBuilderMIPS64::HandleCondition(HCondition* instruction) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2898 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2899 | switch (instruction->InputAt(0)->GetType()) { |
| 2900 | default: |
| 2901 | case Primitive::kPrimLong: |
| 2902 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2903 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2904 | break; |
| 2905 | |
| 2906 | case Primitive::kPrimFloat: |
| 2907 | case Primitive::kPrimDouble: |
| 2908 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2909 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2910 | break; |
| 2911 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2912 | if (!instruction->IsEmittedAtUseSite()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2913 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2914 | } |
| 2915 | } |
| 2916 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2917 | void InstructionCodeGeneratorMIPS64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2918 | if (instruction->IsEmittedAtUseSite()) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2919 | return; |
| 2920 | } |
| 2921 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2922 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2923 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2924 | switch (type) { |
| 2925 | default: |
| 2926 | // Integer case. |
| 2927 | GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ false, locations); |
| 2928 | return; |
| 2929 | case Primitive::kPrimLong: |
| 2930 | GenerateIntLongCompare(instruction->GetCondition(), /* is64bit */ true, locations); |
| 2931 | return; |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 2932 | case Primitive::kPrimFloat: |
| 2933 | case Primitive::kPrimDouble: |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 2934 | GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations); |
| 2935 | return; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2936 | } |
| 2937 | } |
| 2938 | |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 2939 | void InstructionCodeGeneratorMIPS64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2940 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2941 | Primitive::Type type = instruction->GetResultType(); |
| 2942 | |
| 2943 | LocationSummary* locations = instruction->GetLocations(); |
| 2944 | Location second = locations->InAt(1); |
| 2945 | DCHECK(second.IsConstant()); |
| 2946 | |
| 2947 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 2948 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2949 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2950 | DCHECK(imm == 1 || imm == -1); |
| 2951 | |
| 2952 | if (instruction->IsRem()) { |
| 2953 | __ Move(out, ZERO); |
| 2954 | } else { |
| 2955 | if (imm == -1) { |
| 2956 | if (type == Primitive::kPrimInt) { |
| 2957 | __ Subu(out, ZERO, dividend); |
| 2958 | } else { |
| 2959 | DCHECK_EQ(type, Primitive::kPrimLong); |
| 2960 | __ Dsubu(out, ZERO, dividend); |
| 2961 | } |
| 2962 | } else if (out != dividend) { |
| 2963 | __ Move(out, dividend); |
| 2964 | } |
| 2965 | } |
| 2966 | } |
| 2967 | |
| 2968 | void InstructionCodeGeneratorMIPS64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2969 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2970 | Primitive::Type type = instruction->GetResultType(); |
| 2971 | |
| 2972 | LocationSummary* locations = instruction->GetLocations(); |
| 2973 | Location second = locations->InAt(1); |
| 2974 | DCHECK(second.IsConstant()); |
| 2975 | |
| 2976 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 2977 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 2978 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2979 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 2980 | int ctz_imm = CTZ(abs_imm); |
| 2981 | |
| 2982 | if (instruction->IsDiv()) { |
| 2983 | if (type == Primitive::kPrimInt) { |
| 2984 | if (ctz_imm == 1) { |
| 2985 | // Fast path for division by +/-2, which is very common. |
| 2986 | __ Srl(TMP, dividend, 31); |
| 2987 | } else { |
| 2988 | __ Sra(TMP, dividend, 31); |
| 2989 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 2990 | } |
| 2991 | __ Addu(out, dividend, TMP); |
| 2992 | __ Sra(out, out, ctz_imm); |
| 2993 | if (imm < 0) { |
| 2994 | __ Subu(out, ZERO, out); |
| 2995 | } |
| 2996 | } else { |
| 2997 | DCHECK_EQ(type, Primitive::kPrimLong); |
| 2998 | if (ctz_imm == 1) { |
| 2999 | // Fast path for division by +/-2, which is very common. |
| 3000 | __ Dsrl32(TMP, dividend, 31); |
| 3001 | } else { |
| 3002 | __ Dsra32(TMP, dividend, 31); |
| 3003 | if (ctz_imm > 32) { |
| 3004 | __ Dsrl(TMP, TMP, 64 - ctz_imm); |
| 3005 | } else { |
| 3006 | __ Dsrl32(TMP, TMP, 32 - ctz_imm); |
| 3007 | } |
| 3008 | } |
| 3009 | __ Daddu(out, dividend, TMP); |
| 3010 | if (ctz_imm < 32) { |
| 3011 | __ Dsra(out, out, ctz_imm); |
| 3012 | } else { |
| 3013 | __ Dsra32(out, out, ctz_imm - 32); |
| 3014 | } |
| 3015 | if (imm < 0) { |
| 3016 | __ Dsubu(out, ZERO, out); |
| 3017 | } |
| 3018 | } |
| 3019 | } else { |
| 3020 | if (type == Primitive::kPrimInt) { |
| 3021 | if (ctz_imm == 1) { |
| 3022 | // Fast path for modulo +/-2, which is very common. |
| 3023 | __ Sra(TMP, dividend, 31); |
| 3024 | __ Subu(out, dividend, TMP); |
| 3025 | __ Andi(out, out, 1); |
| 3026 | __ Addu(out, out, TMP); |
| 3027 | } else { |
| 3028 | __ Sra(TMP, dividend, 31); |
| 3029 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3030 | __ Addu(out, dividend, TMP); |
| 3031 | if (IsUint<16>(abs_imm - 1)) { |
| 3032 | __ Andi(out, out, abs_imm - 1); |
| 3033 | } else { |
| 3034 | __ Sll(out, out, 32 - ctz_imm); |
| 3035 | __ Srl(out, out, 32 - ctz_imm); |
| 3036 | } |
| 3037 | __ Subu(out, out, TMP); |
| 3038 | } |
| 3039 | } else { |
| 3040 | DCHECK_EQ(type, Primitive::kPrimLong); |
| 3041 | if (ctz_imm == 1) { |
| 3042 | // Fast path for modulo +/-2, which is very common. |
| 3043 | __ Dsra32(TMP, dividend, 31); |
| 3044 | __ Dsubu(out, dividend, TMP); |
| 3045 | __ Andi(out, out, 1); |
| 3046 | __ Daddu(out, out, TMP); |
| 3047 | } else { |
| 3048 | __ Dsra32(TMP, dividend, 31); |
| 3049 | if (ctz_imm > 32) { |
| 3050 | __ Dsrl(TMP, TMP, 64 - ctz_imm); |
| 3051 | } else { |
| 3052 | __ Dsrl32(TMP, TMP, 32 - ctz_imm); |
| 3053 | } |
| 3054 | __ Daddu(out, dividend, TMP); |
| 3055 | if (IsUint<16>(abs_imm - 1)) { |
| 3056 | __ Andi(out, out, abs_imm - 1); |
| 3057 | } else { |
| 3058 | if (ctz_imm > 32) { |
| 3059 | __ Dsll(out, out, 64 - ctz_imm); |
| 3060 | __ Dsrl(out, out, 64 - ctz_imm); |
| 3061 | } else { |
| 3062 | __ Dsll32(out, out, 32 - ctz_imm); |
| 3063 | __ Dsrl32(out, out, 32 - ctz_imm); |
| 3064 | } |
| 3065 | } |
| 3066 | __ Dsubu(out, out, TMP); |
| 3067 | } |
| 3068 | } |
| 3069 | } |
| 3070 | } |
| 3071 | |
| 3072 | void InstructionCodeGeneratorMIPS64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3073 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3074 | |
| 3075 | LocationSummary* locations = instruction->GetLocations(); |
| 3076 | Location second = locations->InAt(1); |
| 3077 | DCHECK(second.IsConstant()); |
| 3078 | |
| 3079 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3080 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3081 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3082 | |
| 3083 | Primitive::Type type = instruction->GetResultType(); |
| 3084 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong) << type; |
| 3085 | |
| 3086 | int64_t magic; |
| 3087 | int shift; |
| 3088 | CalculateMagicAndShiftForDivRem(imm, |
| 3089 | (type == Primitive::kPrimLong), |
| 3090 | &magic, |
| 3091 | &shift); |
| 3092 | |
| 3093 | if (type == Primitive::kPrimInt) { |
| 3094 | __ LoadConst32(TMP, magic); |
| 3095 | __ MuhR6(TMP, dividend, TMP); |
| 3096 | |
| 3097 | if (imm > 0 && magic < 0) { |
| 3098 | __ Addu(TMP, TMP, dividend); |
| 3099 | } else if (imm < 0 && magic > 0) { |
| 3100 | __ Subu(TMP, TMP, dividend); |
| 3101 | } |
| 3102 | |
| 3103 | if (shift != 0) { |
| 3104 | __ Sra(TMP, TMP, shift); |
| 3105 | } |
| 3106 | |
| 3107 | if (instruction->IsDiv()) { |
| 3108 | __ Sra(out, TMP, 31); |
| 3109 | __ Subu(out, TMP, out); |
| 3110 | } else { |
| 3111 | __ Sra(AT, TMP, 31); |
| 3112 | __ Subu(AT, TMP, AT); |
| 3113 | __ LoadConst32(TMP, imm); |
| 3114 | __ MulR6(TMP, AT, TMP); |
| 3115 | __ Subu(out, dividend, TMP); |
| 3116 | } |
| 3117 | } else { |
| 3118 | __ LoadConst64(TMP, magic); |
| 3119 | __ Dmuh(TMP, dividend, TMP); |
| 3120 | |
| 3121 | if (imm > 0 && magic < 0) { |
| 3122 | __ Daddu(TMP, TMP, dividend); |
| 3123 | } else if (imm < 0 && magic > 0) { |
| 3124 | __ Dsubu(TMP, TMP, dividend); |
| 3125 | } |
| 3126 | |
| 3127 | if (shift >= 32) { |
| 3128 | __ Dsra32(TMP, TMP, shift - 32); |
| 3129 | } else if (shift > 0) { |
| 3130 | __ Dsra(TMP, TMP, shift); |
| 3131 | } |
| 3132 | |
| 3133 | if (instruction->IsDiv()) { |
| 3134 | __ Dsra32(out, TMP, 31); |
| 3135 | __ Dsubu(out, TMP, out); |
| 3136 | } else { |
| 3137 | __ Dsra32(AT, TMP, 31); |
| 3138 | __ Dsubu(AT, TMP, AT); |
| 3139 | __ LoadConst64(TMP, imm); |
| 3140 | __ Dmul(TMP, AT, TMP); |
| 3141 | __ Dsubu(out, dividend, TMP); |
| 3142 | } |
| 3143 | } |
| 3144 | } |
| 3145 | |
| 3146 | void InstructionCodeGeneratorMIPS64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3147 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3148 | Primitive::Type type = instruction->GetResultType(); |
| 3149 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong) << type; |
| 3150 | |
| 3151 | LocationSummary* locations = instruction->GetLocations(); |
| 3152 | GpuRegister out = locations->Out().AsRegister<GpuRegister>(); |
| 3153 | Location second = locations->InAt(1); |
| 3154 | |
| 3155 | if (second.IsConstant()) { |
| 3156 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3157 | if (imm == 0) { |
| 3158 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3159 | } else if (imm == 1 || imm == -1) { |
| 3160 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3161 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3162 | DivRemByPowerOfTwo(instruction); |
| 3163 | } else { |
| 3164 | DCHECK(imm <= -2 || imm >= 2); |
| 3165 | GenerateDivRemWithAnyConstant(instruction); |
| 3166 | } |
| 3167 | } else { |
| 3168 | GpuRegister dividend = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3169 | GpuRegister divisor = second.AsRegister<GpuRegister>(); |
| 3170 | if (instruction->IsDiv()) { |
| 3171 | if (type == Primitive::kPrimInt) |
| 3172 | __ DivR6(out, dividend, divisor); |
| 3173 | else |
| 3174 | __ Ddiv(out, dividend, divisor); |
| 3175 | } else { |
| 3176 | if (type == Primitive::kPrimInt) |
| 3177 | __ ModR6(out, dividend, divisor); |
| 3178 | else |
| 3179 | __ Dmod(out, dividend, divisor); |
| 3180 | } |
| 3181 | } |
| 3182 | } |
| 3183 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3184 | void LocationsBuilderMIPS64::VisitDiv(HDiv* div) { |
| 3185 | LocationSummary* locations = |
| 3186 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3187 | switch (div->GetResultType()) { |
| 3188 | case Primitive::kPrimInt: |
| 3189 | case Primitive::kPrimLong: |
| 3190 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3191 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3192 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3193 | break; |
| 3194 | |
| 3195 | case Primitive::kPrimFloat: |
| 3196 | case Primitive::kPrimDouble: |
| 3197 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3198 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3199 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3200 | break; |
| 3201 | |
| 3202 | default: |
| 3203 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3204 | } |
| 3205 | } |
| 3206 | |
| 3207 | void InstructionCodeGeneratorMIPS64::VisitDiv(HDiv* instruction) { |
| 3208 | Primitive::Type type = instruction->GetType(); |
| 3209 | LocationSummary* locations = instruction->GetLocations(); |
| 3210 | |
| 3211 | switch (type) { |
| 3212 | case Primitive::kPrimInt: |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 3213 | case Primitive::kPrimLong: |
| 3214 | GenerateDivRemIntegral(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3215 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3216 | case Primitive::kPrimFloat: |
| 3217 | case Primitive::kPrimDouble: { |
| 3218 | FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>(); |
| 3219 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3220 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 3221 | if (type == Primitive::kPrimFloat) |
| 3222 | __ DivS(dst, lhs, rhs); |
| 3223 | else |
| 3224 | __ DivD(dst, lhs, rhs); |
| 3225 | break; |
| 3226 | } |
| 3227 | default: |
| 3228 | LOG(FATAL) << "Unexpected div type " << type; |
| 3229 | } |
| 3230 | } |
| 3231 | |
| 3232 | void LocationsBuilderMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3233 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3234 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3235 | } |
| 3236 | |
| 3237 | void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3238 | SlowPathCodeMIPS64* slow_path = |
| 3239 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS64(instruction); |
| 3240 | codegen_->AddSlowPath(slow_path); |
| 3241 | Location value = instruction->GetLocations()->InAt(0); |
| 3242 | |
| 3243 | Primitive::Type type = instruction->GetType(); |
| 3244 | |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3245 | if (!Primitive::IsIntegralType(type)) { |
| 3246 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3247 | return; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3248 | } |
| 3249 | |
| 3250 | if (value.IsConstant()) { |
| 3251 | int64_t divisor = codegen_->GetInt64ValueOf(value.GetConstant()->AsConstant()); |
| 3252 | if (divisor == 0) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3253 | __ Bc(slow_path->GetEntryLabel()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3254 | } else { |
| 3255 | // A division by a non-null constant is valid. We don't need to perform |
| 3256 | // any check, so simply fall through. |
| 3257 | } |
| 3258 | } else { |
| 3259 | __ Beqzc(value.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 3260 | } |
| 3261 | } |
| 3262 | |
| 3263 | void LocationsBuilderMIPS64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3264 | LocationSummary* locations = |
| 3265 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3266 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3267 | } |
| 3268 | |
| 3269 | void InstructionCodeGeneratorMIPS64::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 3270 | // Will be generated at use site. |
| 3271 | } |
| 3272 | |
| 3273 | void LocationsBuilderMIPS64::VisitExit(HExit* exit) { |
| 3274 | exit->SetLocations(nullptr); |
| 3275 | } |
| 3276 | |
| 3277 | void InstructionCodeGeneratorMIPS64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 3278 | } |
| 3279 | |
| 3280 | void LocationsBuilderMIPS64::VisitFloatConstant(HFloatConstant* constant) { |
| 3281 | LocationSummary* locations = |
| 3282 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3283 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3284 | } |
| 3285 | |
| 3286 | void InstructionCodeGeneratorMIPS64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 3287 | // Will be generated at use site. |
| 3288 | } |
| 3289 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3290 | void InstructionCodeGeneratorMIPS64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3291 | DCHECK(!successor->IsExitBlock()); |
| 3292 | HBasicBlock* block = got->GetBlock(); |
| 3293 | HInstruction* previous = got->GetPrevious(); |
| 3294 | HLoopInformation* info = block->GetLoopInformation(); |
| 3295 | |
| 3296 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| 3297 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 3298 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3299 | return; |
| 3300 | } |
| 3301 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3302 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 3303 | } |
| 3304 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3305 | __ Bc(codegen_->GetLabelOf(successor)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3306 | } |
| 3307 | } |
| 3308 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3309 | void LocationsBuilderMIPS64::VisitGoto(HGoto* got) { |
| 3310 | got->SetLocations(nullptr); |
| 3311 | } |
| 3312 | |
| 3313 | void InstructionCodeGeneratorMIPS64::VisitGoto(HGoto* got) { |
| 3314 | HandleGoto(got, got->GetSuccessor()); |
| 3315 | } |
| 3316 | |
| 3317 | void LocationsBuilderMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3318 | try_boundary->SetLocations(nullptr); |
| 3319 | } |
| 3320 | |
| 3321 | void InstructionCodeGeneratorMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3322 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3323 | if (!successor->IsExitBlock()) { |
| 3324 | HandleGoto(try_boundary, successor); |
| 3325 | } |
| 3326 | } |
| 3327 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3328 | void InstructionCodeGeneratorMIPS64::GenerateIntLongCompare(IfCondition cond, |
| 3329 | bool is64bit, |
| 3330 | LocationSummary* locations) { |
| 3331 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3332 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3333 | Location rhs_location = locations->InAt(1); |
| 3334 | GpuRegister rhs_reg = ZERO; |
| 3335 | int64_t rhs_imm = 0; |
| 3336 | bool use_imm = rhs_location.IsConstant(); |
| 3337 | if (use_imm) { |
| 3338 | if (is64bit) { |
| 3339 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3340 | } else { |
| 3341 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3342 | } |
| 3343 | } else { |
| 3344 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3345 | } |
| 3346 | int64_t rhs_imm_plus_one = rhs_imm + UINT64_C(1); |
| 3347 | |
| 3348 | switch (cond) { |
| 3349 | case kCondEQ: |
| 3350 | case kCondNE: |
Goran Jakovljevic | db3deee | 2016-12-28 14:33:21 +0100 | [diff] [blame] | 3351 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 3352 | if (rhs_imm == 0) { |
| 3353 | if (cond == kCondEQ) { |
| 3354 | __ Sltiu(dst, lhs, 1); |
| 3355 | } else { |
| 3356 | __ Sltu(dst, ZERO, lhs); |
| 3357 | } |
| 3358 | } else { |
| 3359 | if (is64bit) { |
| 3360 | __ Daddiu(dst, lhs, -rhs_imm); |
| 3361 | } else { |
| 3362 | __ Addiu(dst, lhs, -rhs_imm); |
| 3363 | } |
| 3364 | if (cond == kCondEQ) { |
| 3365 | __ Sltiu(dst, dst, 1); |
| 3366 | } else { |
| 3367 | __ Sltu(dst, ZERO, dst); |
| 3368 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3369 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3370 | } else { |
Goran Jakovljevic | db3deee | 2016-12-28 14:33:21 +0100 | [diff] [blame] | 3371 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 3372 | __ Xori(dst, lhs, rhs_imm); |
| 3373 | } else { |
| 3374 | if (use_imm) { |
| 3375 | rhs_reg = TMP; |
| 3376 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3377 | } |
| 3378 | __ Xor(dst, lhs, rhs_reg); |
| 3379 | } |
| 3380 | if (cond == kCondEQ) { |
| 3381 | __ Sltiu(dst, dst, 1); |
| 3382 | } else { |
| 3383 | __ Sltu(dst, ZERO, dst); |
| 3384 | } |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3385 | } |
| 3386 | break; |
| 3387 | |
| 3388 | case kCondLT: |
| 3389 | case kCondGE: |
| 3390 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3391 | __ Slti(dst, lhs, rhs_imm); |
| 3392 | } else { |
| 3393 | if (use_imm) { |
| 3394 | rhs_reg = TMP; |
| 3395 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3396 | } |
| 3397 | __ Slt(dst, lhs, rhs_reg); |
| 3398 | } |
| 3399 | if (cond == kCondGE) { |
| 3400 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 3401 | // only the slt instruction but no sge. |
| 3402 | __ Xori(dst, dst, 1); |
| 3403 | } |
| 3404 | break; |
| 3405 | |
| 3406 | case kCondLE: |
| 3407 | case kCondGT: |
| 3408 | if (use_imm && IsInt<16>(rhs_imm_plus_one)) { |
| 3409 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3410 | __ Slti(dst, lhs, rhs_imm_plus_one); |
| 3411 | if (cond == kCondGT) { |
| 3412 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 3413 | // only the slti instruction but no sgti. |
| 3414 | __ Xori(dst, dst, 1); |
| 3415 | } |
| 3416 | } else { |
| 3417 | if (use_imm) { |
| 3418 | rhs_reg = TMP; |
| 3419 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3420 | } |
| 3421 | __ Slt(dst, rhs_reg, lhs); |
| 3422 | if (cond == kCondLE) { |
| 3423 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 3424 | // only the slt instruction but no sle. |
| 3425 | __ Xori(dst, dst, 1); |
| 3426 | } |
| 3427 | } |
| 3428 | break; |
| 3429 | |
| 3430 | case kCondB: |
| 3431 | case kCondAE: |
| 3432 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3433 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3434 | // the comparison and thus lets us compare directly with |
| 3435 | // unsigned values in the ranges [0, 0x7fff] and |
| 3436 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3437 | __ Sltiu(dst, lhs, rhs_imm); |
| 3438 | } else { |
| 3439 | if (use_imm) { |
| 3440 | rhs_reg = TMP; |
| 3441 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3442 | } |
| 3443 | __ Sltu(dst, lhs, rhs_reg); |
| 3444 | } |
| 3445 | if (cond == kCondAE) { |
| 3446 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 3447 | // only the sltu instruction but no sgeu. |
| 3448 | __ Xori(dst, dst, 1); |
| 3449 | } |
| 3450 | break; |
| 3451 | |
| 3452 | case kCondBE: |
| 3453 | case kCondA: |
| 3454 | if (use_imm && (rhs_imm_plus_one != 0) && IsInt<16>(rhs_imm_plus_one)) { |
| 3455 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3456 | // Note that this only works if rhs + 1 does not overflow |
| 3457 | // to 0, hence the check above. |
| 3458 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3459 | // the comparison and thus lets us compare directly with |
| 3460 | // unsigned values in the ranges [0, 0x7fff] and |
| 3461 | // [0x[ffffffff]ffff8000, 0x[ffffffff]ffffffff]. |
| 3462 | __ Sltiu(dst, lhs, rhs_imm_plus_one); |
| 3463 | if (cond == kCondA) { |
| 3464 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 3465 | // only the sltiu instruction but no sgtiu. |
| 3466 | __ Xori(dst, dst, 1); |
| 3467 | } |
| 3468 | } else { |
| 3469 | if (use_imm) { |
| 3470 | rhs_reg = TMP; |
| 3471 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3472 | } |
| 3473 | __ Sltu(dst, rhs_reg, lhs); |
| 3474 | if (cond == kCondBE) { |
| 3475 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 3476 | // only the sltu instruction but no sleu. |
| 3477 | __ Xori(dst, dst, 1); |
| 3478 | } |
| 3479 | } |
| 3480 | break; |
| 3481 | } |
| 3482 | } |
| 3483 | |
| 3484 | void InstructionCodeGeneratorMIPS64::GenerateIntLongCompareAndBranch(IfCondition cond, |
| 3485 | bool is64bit, |
| 3486 | LocationSummary* locations, |
| 3487 | Mips64Label* label) { |
| 3488 | GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>(); |
| 3489 | Location rhs_location = locations->InAt(1); |
| 3490 | GpuRegister rhs_reg = ZERO; |
| 3491 | int64_t rhs_imm = 0; |
| 3492 | bool use_imm = rhs_location.IsConstant(); |
| 3493 | if (use_imm) { |
| 3494 | if (is64bit) { |
| 3495 | rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()); |
| 3496 | } else { |
| 3497 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3498 | } |
| 3499 | } else { |
| 3500 | rhs_reg = rhs_location.AsRegister<GpuRegister>(); |
| 3501 | } |
| 3502 | |
| 3503 | if (use_imm && rhs_imm == 0) { |
| 3504 | switch (cond) { |
| 3505 | case kCondEQ: |
| 3506 | case kCondBE: // <= 0 if zero |
| 3507 | __ Beqzc(lhs, label); |
| 3508 | break; |
| 3509 | case kCondNE: |
| 3510 | case kCondA: // > 0 if non-zero |
| 3511 | __ Bnezc(lhs, label); |
| 3512 | break; |
| 3513 | case kCondLT: |
| 3514 | __ Bltzc(lhs, label); |
| 3515 | break; |
| 3516 | case kCondGE: |
| 3517 | __ Bgezc(lhs, label); |
| 3518 | break; |
| 3519 | case kCondLE: |
| 3520 | __ Blezc(lhs, label); |
| 3521 | break; |
| 3522 | case kCondGT: |
| 3523 | __ Bgtzc(lhs, label); |
| 3524 | break; |
| 3525 | case kCondB: // always false |
| 3526 | break; |
| 3527 | case kCondAE: // always true |
| 3528 | __ Bc(label); |
| 3529 | break; |
| 3530 | } |
| 3531 | } else { |
| 3532 | if (use_imm) { |
| 3533 | rhs_reg = TMP; |
| 3534 | __ LoadConst64(rhs_reg, rhs_imm); |
| 3535 | } |
| 3536 | switch (cond) { |
| 3537 | case kCondEQ: |
| 3538 | __ Beqc(lhs, rhs_reg, label); |
| 3539 | break; |
| 3540 | case kCondNE: |
| 3541 | __ Bnec(lhs, rhs_reg, label); |
| 3542 | break; |
| 3543 | case kCondLT: |
| 3544 | __ Bltc(lhs, rhs_reg, label); |
| 3545 | break; |
| 3546 | case kCondGE: |
| 3547 | __ Bgec(lhs, rhs_reg, label); |
| 3548 | break; |
| 3549 | case kCondLE: |
| 3550 | __ Bgec(rhs_reg, lhs, label); |
| 3551 | break; |
| 3552 | case kCondGT: |
| 3553 | __ Bltc(rhs_reg, lhs, label); |
| 3554 | break; |
| 3555 | case kCondB: |
| 3556 | __ Bltuc(lhs, rhs_reg, label); |
| 3557 | break; |
| 3558 | case kCondAE: |
| 3559 | __ Bgeuc(lhs, rhs_reg, label); |
| 3560 | break; |
| 3561 | case kCondBE: |
| 3562 | __ Bgeuc(rhs_reg, lhs, label); |
| 3563 | break; |
| 3564 | case kCondA: |
| 3565 | __ Bltuc(rhs_reg, lhs, label); |
| 3566 | break; |
| 3567 | } |
| 3568 | } |
| 3569 | } |
| 3570 | |
Tijana Jakovljevic | 4375819 | 2016-12-30 09:23:01 +0100 | [diff] [blame] | 3571 | void InstructionCodeGeneratorMIPS64::GenerateFpCompare(IfCondition cond, |
| 3572 | bool gt_bias, |
| 3573 | Primitive::Type type, |
| 3574 | LocationSummary* locations) { |
| 3575 | GpuRegister dst = locations->Out().AsRegister<GpuRegister>(); |
| 3576 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3577 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 3578 | if (type == Primitive::kPrimFloat) { |
| 3579 | switch (cond) { |
| 3580 | case kCondEQ: |
| 3581 | __ CmpEqS(FTMP, lhs, rhs); |
| 3582 | __ Mfc1(dst, FTMP); |
| 3583 | __ Andi(dst, dst, 1); |
| 3584 | break; |
| 3585 | case kCondNE: |
| 3586 | __ CmpEqS(FTMP, lhs, rhs); |
| 3587 | __ Mfc1(dst, FTMP); |
| 3588 | __ Addiu(dst, dst, 1); |
| 3589 | break; |
| 3590 | case kCondLT: |
| 3591 | if (gt_bias) { |
| 3592 | __ CmpLtS(FTMP, lhs, rhs); |
| 3593 | } else { |
| 3594 | __ CmpUltS(FTMP, lhs, rhs); |
| 3595 | } |
| 3596 | __ Mfc1(dst, FTMP); |
| 3597 | __ Andi(dst, dst, 1); |
| 3598 | break; |
| 3599 | case kCondLE: |
| 3600 | if (gt_bias) { |
| 3601 | __ CmpLeS(FTMP, lhs, rhs); |
| 3602 | } else { |
| 3603 | __ CmpUleS(FTMP, lhs, rhs); |
| 3604 | } |
| 3605 | __ Mfc1(dst, FTMP); |
| 3606 | __ Andi(dst, dst, 1); |
| 3607 | break; |
| 3608 | case kCondGT: |
| 3609 | if (gt_bias) { |
| 3610 | __ CmpUltS(FTMP, rhs, lhs); |
| 3611 | } else { |
| 3612 | __ CmpLtS(FTMP, rhs, lhs); |
| 3613 | } |
| 3614 | __ Mfc1(dst, FTMP); |
| 3615 | __ Andi(dst, dst, 1); |
| 3616 | break; |
| 3617 | case kCondGE: |
| 3618 | if (gt_bias) { |
| 3619 | __ CmpUleS(FTMP, rhs, lhs); |
| 3620 | } else { |
| 3621 | __ CmpLeS(FTMP, rhs, lhs); |
| 3622 | } |
| 3623 | __ Mfc1(dst, FTMP); |
| 3624 | __ Andi(dst, dst, 1); |
| 3625 | break; |
| 3626 | default: |
| 3627 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3628 | UNREACHABLE(); |
| 3629 | } |
| 3630 | } else { |
| 3631 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 3632 | switch (cond) { |
| 3633 | case kCondEQ: |
| 3634 | __ CmpEqD(FTMP, lhs, rhs); |
| 3635 | __ Mfc1(dst, FTMP); |
| 3636 | __ Andi(dst, dst, 1); |
| 3637 | break; |
| 3638 | case kCondNE: |
| 3639 | __ CmpEqD(FTMP, lhs, rhs); |
| 3640 | __ Mfc1(dst, FTMP); |
| 3641 | __ Addiu(dst, dst, 1); |
| 3642 | break; |
| 3643 | case kCondLT: |
| 3644 | if (gt_bias) { |
| 3645 | __ CmpLtD(FTMP, lhs, rhs); |
| 3646 | } else { |
| 3647 | __ CmpUltD(FTMP, lhs, rhs); |
| 3648 | } |
| 3649 | __ Mfc1(dst, FTMP); |
| 3650 | __ Andi(dst, dst, 1); |
| 3651 | break; |
| 3652 | case kCondLE: |
| 3653 | if (gt_bias) { |
| 3654 | __ CmpLeD(FTMP, lhs, rhs); |
| 3655 | } else { |
| 3656 | __ CmpUleD(FTMP, lhs, rhs); |
| 3657 | } |
| 3658 | __ Mfc1(dst, FTMP); |
| 3659 | __ Andi(dst, dst, 1); |
| 3660 | break; |
| 3661 | case kCondGT: |
| 3662 | if (gt_bias) { |
| 3663 | __ CmpUltD(FTMP, rhs, lhs); |
| 3664 | } else { |
| 3665 | __ CmpLtD(FTMP, rhs, lhs); |
| 3666 | } |
| 3667 | __ Mfc1(dst, FTMP); |
| 3668 | __ Andi(dst, dst, 1); |
| 3669 | break; |
| 3670 | case kCondGE: |
| 3671 | if (gt_bias) { |
| 3672 | __ CmpUleD(FTMP, rhs, lhs); |
| 3673 | } else { |
| 3674 | __ CmpLeD(FTMP, rhs, lhs); |
| 3675 | } |
| 3676 | __ Mfc1(dst, FTMP); |
| 3677 | __ Andi(dst, dst, 1); |
| 3678 | break; |
| 3679 | default: |
| 3680 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3681 | UNREACHABLE(); |
| 3682 | } |
| 3683 | } |
| 3684 | } |
| 3685 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3686 | void InstructionCodeGeneratorMIPS64::GenerateFpCompareAndBranch(IfCondition cond, |
| 3687 | bool gt_bias, |
| 3688 | Primitive::Type type, |
| 3689 | LocationSummary* locations, |
| 3690 | Mips64Label* label) { |
| 3691 | FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>(); |
| 3692 | FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>(); |
| 3693 | if (type == Primitive::kPrimFloat) { |
| 3694 | switch (cond) { |
| 3695 | case kCondEQ: |
| 3696 | __ CmpEqS(FTMP, lhs, rhs); |
| 3697 | __ Bc1nez(FTMP, label); |
| 3698 | break; |
| 3699 | case kCondNE: |
| 3700 | __ CmpEqS(FTMP, lhs, rhs); |
| 3701 | __ Bc1eqz(FTMP, label); |
| 3702 | break; |
| 3703 | case kCondLT: |
| 3704 | if (gt_bias) { |
| 3705 | __ CmpLtS(FTMP, lhs, rhs); |
| 3706 | } else { |
| 3707 | __ CmpUltS(FTMP, lhs, rhs); |
| 3708 | } |
| 3709 | __ Bc1nez(FTMP, label); |
| 3710 | break; |
| 3711 | case kCondLE: |
| 3712 | if (gt_bias) { |
| 3713 | __ CmpLeS(FTMP, lhs, rhs); |
| 3714 | } else { |
| 3715 | __ CmpUleS(FTMP, lhs, rhs); |
| 3716 | } |
| 3717 | __ Bc1nez(FTMP, label); |
| 3718 | break; |
| 3719 | case kCondGT: |
| 3720 | if (gt_bias) { |
| 3721 | __ CmpUltS(FTMP, rhs, lhs); |
| 3722 | } else { |
| 3723 | __ CmpLtS(FTMP, rhs, lhs); |
| 3724 | } |
| 3725 | __ Bc1nez(FTMP, label); |
| 3726 | break; |
| 3727 | case kCondGE: |
| 3728 | if (gt_bias) { |
| 3729 | __ CmpUleS(FTMP, rhs, lhs); |
| 3730 | } else { |
| 3731 | __ CmpLeS(FTMP, rhs, lhs); |
| 3732 | } |
| 3733 | __ Bc1nez(FTMP, label); |
| 3734 | break; |
| 3735 | default: |
| 3736 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3737 | } |
| 3738 | } else { |
| 3739 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 3740 | switch (cond) { |
| 3741 | case kCondEQ: |
| 3742 | __ CmpEqD(FTMP, lhs, rhs); |
| 3743 | __ Bc1nez(FTMP, label); |
| 3744 | break; |
| 3745 | case kCondNE: |
| 3746 | __ CmpEqD(FTMP, lhs, rhs); |
| 3747 | __ Bc1eqz(FTMP, label); |
| 3748 | break; |
| 3749 | case kCondLT: |
| 3750 | if (gt_bias) { |
| 3751 | __ CmpLtD(FTMP, lhs, rhs); |
| 3752 | } else { |
| 3753 | __ CmpUltD(FTMP, lhs, rhs); |
| 3754 | } |
| 3755 | __ Bc1nez(FTMP, label); |
| 3756 | break; |
| 3757 | case kCondLE: |
| 3758 | if (gt_bias) { |
| 3759 | __ CmpLeD(FTMP, lhs, rhs); |
| 3760 | } else { |
| 3761 | __ CmpUleD(FTMP, lhs, rhs); |
| 3762 | } |
| 3763 | __ Bc1nez(FTMP, label); |
| 3764 | break; |
| 3765 | case kCondGT: |
| 3766 | if (gt_bias) { |
| 3767 | __ CmpUltD(FTMP, rhs, lhs); |
| 3768 | } else { |
| 3769 | __ CmpLtD(FTMP, rhs, lhs); |
| 3770 | } |
| 3771 | __ Bc1nez(FTMP, label); |
| 3772 | break; |
| 3773 | case kCondGE: |
| 3774 | if (gt_bias) { |
| 3775 | __ CmpUleD(FTMP, rhs, lhs); |
| 3776 | } else { |
| 3777 | __ CmpLeD(FTMP, rhs, lhs); |
| 3778 | } |
| 3779 | __ Bc1nez(FTMP, label); |
| 3780 | break; |
| 3781 | default: |
| 3782 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3783 | } |
| 3784 | } |
| 3785 | } |
| 3786 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3787 | void InstructionCodeGeneratorMIPS64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3788 | size_t condition_input_index, |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3789 | Mips64Label* true_target, |
| 3790 | Mips64Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3791 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3792 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3793 | if (true_target == nullptr && false_target == nullptr) { |
| 3794 | // Nothing to do. The code always falls through. |
| 3795 | return; |
| 3796 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3797 | // Constant condition, statically compared against "true" (integer value 1). |
| 3798 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3799 | if (true_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3800 | __ Bc(true_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3801 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3802 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3803 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3804 | if (false_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3805 | __ Bc(false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3806 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3807 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3808 | return; |
| 3809 | } |
| 3810 | |
| 3811 | // The following code generates these patterns: |
| 3812 | // (1) true_target == nullptr && false_target != nullptr |
| 3813 | // - opposite condition true => branch to false_target |
| 3814 | // (2) true_target != nullptr && false_target == nullptr |
| 3815 | // - condition true => branch to true_target |
| 3816 | // (3) true_target != nullptr && false_target != nullptr |
| 3817 | // - condition true => branch to true_target |
| 3818 | // - branch to false_target |
| 3819 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3820 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3821 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3822 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3823 | if (true_target == nullptr) { |
| 3824 | __ Beqzc(cond_val.AsRegister<GpuRegister>(), false_target); |
| 3825 | } else { |
| 3826 | __ Bnezc(cond_val.AsRegister<GpuRegister>(), true_target); |
| 3827 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3828 | } else { |
| 3829 | // The condition instruction has not been materialized, use its inputs as |
| 3830 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3831 | HCondition* condition = cond->AsCondition(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3832 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 3833 | LocationSummary* locations = cond->GetLocations(); |
| 3834 | IfCondition if_cond = condition->GetCondition(); |
| 3835 | Mips64Label* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3836 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3837 | if (true_target == nullptr) { |
| 3838 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3839 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3840 | } |
| 3841 | |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 3842 | switch (type) { |
| 3843 | default: |
| 3844 | GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ false, locations, branch_target); |
| 3845 | break; |
| 3846 | case Primitive::kPrimLong: |
| 3847 | GenerateIntLongCompareAndBranch(if_cond, /* is64bit */ true, locations, branch_target); |
| 3848 | break; |
| 3849 | case Primitive::kPrimFloat: |
| 3850 | case Primitive::kPrimDouble: |
| 3851 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 3852 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3853 | } |
| 3854 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3855 | |
| 3856 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3857 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3858 | if (true_target != nullptr && false_target != nullptr) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3859 | __ Bc(false_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3860 | } |
| 3861 | } |
| 3862 | |
| 3863 | void LocationsBuilderMIPS64::VisitIf(HIf* if_instr) { |
| 3864 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3865 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3866 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3867 | } |
| 3868 | } |
| 3869 | |
| 3870 | void InstructionCodeGeneratorMIPS64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3871 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3872 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3873 | Mips64Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3874 | nullptr : codegen_->GetLabelOf(true_successor); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 3875 | Mips64Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3876 | nullptr : codegen_->GetLabelOf(false_successor); |
| 3877 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3878 | } |
| 3879 | |
| 3880 | void LocationsBuilderMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3881 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3882 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3883 | InvokeRuntimeCallingConvention calling_convention; |
| 3884 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3885 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3886 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3887 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3888 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3889 | } |
| 3890 | } |
| 3891 | |
| 3892 | void InstructionCodeGeneratorMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3893 | SlowPathCodeMIPS64* slow_path = |
| 3894 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3895 | GenerateTestAndBranch(deoptimize, |
| 3896 | /* condition_input_index */ 0, |
| 3897 | slow_path->GetEntryLabel(), |
| 3898 | /* false_target */ nullptr); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3899 | } |
| 3900 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 3901 | void LocationsBuilderMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3902 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3903 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3904 | locations->SetOut(Location::RequiresRegister()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3905 | } |
| 3906 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 3907 | void InstructionCodeGeneratorMIPS64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3908 | __ LoadFromOffset(kLoadWord, |
| 3909 | flag->GetLocations()->Out().AsRegister<GpuRegister>(), |
| 3910 | SP, |
| 3911 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3912 | } |
| 3913 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3914 | void LocationsBuilderMIPS64::VisitSelect(HSelect* select) { |
| 3915 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 3916 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3917 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3918 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3919 | } else { |
| 3920 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3921 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3922 | } |
| 3923 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3924 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3925 | } |
| 3926 | locations->SetOut(Location::SameAsFirstInput()); |
| 3927 | } |
| 3928 | |
| 3929 | void InstructionCodeGeneratorMIPS64::VisitSelect(HSelect* select) { |
| 3930 | LocationSummary* locations = select->GetLocations(); |
| 3931 | Mips64Label false_target; |
| 3932 | GenerateTestAndBranch(select, |
| 3933 | /* condition_input_index */ 2, |
| 3934 | /* true_target */ nullptr, |
| 3935 | &false_target); |
| 3936 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 3937 | __ Bind(&false_target); |
| 3938 | } |
| 3939 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3940 | void LocationsBuilderMIPS64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3941 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3942 | } |
| 3943 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3944 | void InstructionCodeGeneratorMIPS64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3945 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3946 | } |
| 3947 | |
| 3948 | void CodeGeneratorMIPS64::GenerateNop() { |
| 3949 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3950 | } |
| 3951 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3952 | void LocationsBuilderMIPS64::HandleFieldGet(HInstruction* instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3953 | const FieldInfo& field_info) { |
| 3954 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3955 | bool object_field_get_with_read_barrier = |
| 3956 | kEmitCompilerReadBarrier && (field_type == Primitive::kPrimNot); |
| 3957 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 3958 | instruction, |
| 3959 | object_field_get_with_read_barrier |
| 3960 | ? LocationSummary::kCallOnSlowPath |
| 3961 | : LocationSummary::kNoCall); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 3962 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 3963 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 3964 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3965 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3966 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3967 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3968 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3969 | // The output overlaps in the case of an object field get with |
| 3970 | // read barriers enabled: we do not want the move to overwrite the |
| 3971 | // object's location, as we need it to emit the read barrier. |
| 3972 | locations->SetOut(Location::RequiresRegister(), |
| 3973 | object_field_get_with_read_barrier |
| 3974 | ? Location::kOutputOverlap |
| 3975 | : Location::kNoOutputOverlap); |
| 3976 | } |
| 3977 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 3978 | // We need a temporary register for the read barrier marking slow |
| 3979 | // path in CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier. |
| 3980 | locations->AddTemp(Location::RequiresRegister()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3981 | } |
| 3982 | } |
| 3983 | |
| 3984 | void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction, |
| 3985 | const FieldInfo& field_info) { |
| 3986 | Primitive::Type type = field_info.GetFieldType(); |
| 3987 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3988 | Location obj_loc = locations->InAt(0); |
| 3989 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
| 3990 | Location dst_loc = locations->Out(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3991 | LoadOperandType load_type = kLoadUnsignedByte; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3992 | bool is_volatile = field_info.IsVolatile(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 3993 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 3994 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
| 3995 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3996 | switch (type) { |
| 3997 | case Primitive::kPrimBoolean: |
| 3998 | load_type = kLoadUnsignedByte; |
| 3999 | break; |
| 4000 | case Primitive::kPrimByte: |
| 4001 | load_type = kLoadSignedByte; |
| 4002 | break; |
| 4003 | case Primitive::kPrimShort: |
| 4004 | load_type = kLoadSignedHalfword; |
| 4005 | break; |
| 4006 | case Primitive::kPrimChar: |
| 4007 | load_type = kLoadUnsignedHalfword; |
| 4008 | break; |
| 4009 | case Primitive::kPrimInt: |
| 4010 | case Primitive::kPrimFloat: |
| 4011 | load_type = kLoadWord; |
| 4012 | break; |
| 4013 | case Primitive::kPrimLong: |
| 4014 | case Primitive::kPrimDouble: |
| 4015 | load_type = kLoadDoubleword; |
| 4016 | break; |
| 4017 | case Primitive::kPrimNot: |
| 4018 | load_type = kLoadUnsignedWord; |
| 4019 | break; |
| 4020 | case Primitive::kPrimVoid: |
| 4021 | LOG(FATAL) << "Unreachable type " << type; |
| 4022 | UNREACHABLE(); |
| 4023 | } |
| 4024 | if (!Primitive::IsFloatingPointType(type)) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4025 | DCHECK(dst_loc.IsRegister()); |
| 4026 | GpuRegister dst = dst_loc.AsRegister<GpuRegister>(); |
| 4027 | if (type == Primitive::kPrimNot) { |
| 4028 | // /* HeapReference<Object> */ dst = *(obj + offset) |
| 4029 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4030 | Location temp_loc = locations->GetTemp(0); |
| 4031 | // Note that a potential implicit null check is handled in this |
| 4032 | // CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier call. |
| 4033 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4034 | dst_loc, |
| 4035 | obj, |
| 4036 | offset, |
| 4037 | temp_loc, |
| 4038 | /* needs_null_check */ true); |
| 4039 | if (is_volatile) { |
| 4040 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4041 | } |
| 4042 | } else { |
| 4043 | __ LoadFromOffset(kLoadUnsignedWord, dst, obj, offset, null_checker); |
| 4044 | if (is_volatile) { |
| 4045 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4046 | } |
| 4047 | // If read barriers are enabled, emit read barriers other than |
| 4048 | // Baker's using a slow path (and also unpoison the loaded |
| 4049 | // reference, if heap poisoning is enabled). |
| 4050 | codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset); |
| 4051 | } |
| 4052 | } else { |
| 4053 | __ LoadFromOffset(load_type, dst, obj, offset, null_checker); |
| 4054 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4055 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4056 | DCHECK(dst_loc.IsFpuRegister()); |
| 4057 | FpuRegister dst = dst_loc.AsFpuRegister<FpuRegister>(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4058 | __ LoadFpuFromOffset(load_type, dst, obj, offset, null_checker); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4059 | } |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4060 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4061 | // Memory barriers, in the case of references, are handled in the |
| 4062 | // previous switch statement. |
| 4063 | if (is_volatile && (type != Primitive::kPrimNot)) { |
| 4064 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4065 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4066 | } |
| 4067 | |
| 4068 | void LocationsBuilderMIPS64::HandleFieldSet(HInstruction* instruction, |
| 4069 | const FieldInfo& field_info ATTRIBUTE_UNUSED) { |
| 4070 | LocationSummary* locations = |
| 4071 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4072 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4073 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4074 | locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4075 | } else { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4076 | locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1))); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4077 | } |
| 4078 | } |
| 4079 | |
| 4080 | void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction, |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4081 | const FieldInfo& field_info, |
| 4082 | bool value_can_be_null) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4083 | Primitive::Type type = field_info.GetFieldType(); |
| 4084 | LocationSummary* locations = instruction->GetLocations(); |
| 4085 | GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>(); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4086 | Location value_location = locations->InAt(1); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4087 | StoreOperandType store_type = kStoreByte; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4088 | bool is_volatile = field_info.IsVolatile(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4089 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4090 | bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1)); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4091 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
| 4092 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4093 | switch (type) { |
| 4094 | case Primitive::kPrimBoolean: |
| 4095 | case Primitive::kPrimByte: |
| 4096 | store_type = kStoreByte; |
| 4097 | break; |
| 4098 | case Primitive::kPrimShort: |
| 4099 | case Primitive::kPrimChar: |
| 4100 | store_type = kStoreHalfword; |
| 4101 | break; |
| 4102 | case Primitive::kPrimInt: |
| 4103 | case Primitive::kPrimFloat: |
| 4104 | case Primitive::kPrimNot: |
| 4105 | store_type = kStoreWord; |
| 4106 | break; |
| 4107 | case Primitive::kPrimLong: |
| 4108 | case Primitive::kPrimDouble: |
| 4109 | store_type = kStoreDoubleword; |
| 4110 | break; |
| 4111 | case Primitive::kPrimVoid: |
| 4112 | LOG(FATAL) << "Unreachable type " << type; |
| 4113 | UNREACHABLE(); |
| 4114 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4115 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4116 | if (is_volatile) { |
| 4117 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 4118 | } |
| 4119 | |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4120 | if (value_location.IsConstant()) { |
| 4121 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 4122 | __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker); |
| 4123 | } else { |
| 4124 | if (!Primitive::IsFloatingPointType(type)) { |
| 4125 | DCHECK(value_location.IsRegister()); |
| 4126 | GpuRegister src = value_location.AsRegister<GpuRegister>(); |
| 4127 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4128 | // Note that in the case where `value` is a null reference, |
| 4129 | // we do not enter this block, as a null reference does not |
| 4130 | // need poisoning. |
| 4131 | DCHECK_EQ(type, Primitive::kPrimNot); |
| 4132 | __ PoisonHeapReference(TMP, src); |
| 4133 | __ StoreToOffset(store_type, TMP, obj, offset, null_checker); |
| 4134 | } else { |
| 4135 | __ StoreToOffset(store_type, src, obj, offset, null_checker); |
| 4136 | } |
| 4137 | } else { |
| 4138 | DCHECK(value_location.IsFpuRegister()); |
| 4139 | FpuRegister src = value_location.AsFpuRegister<FpuRegister>(); |
| 4140 | __ StoreFpuToOffset(store_type, src, obj, offset, null_checker); |
| 4141 | } |
| 4142 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4143 | |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4144 | if (needs_write_barrier) { |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 4145 | DCHECK(value_location.IsRegister()); |
| 4146 | GpuRegister src = value_location.AsRegister<GpuRegister>(); |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4147 | codegen_->MarkGCCard(obj, src, value_can_be_null); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4148 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4149 | |
| 4150 | if (is_volatile) { |
| 4151 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 4152 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4153 | } |
| 4154 | |
| 4155 | void LocationsBuilderMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4156 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4157 | } |
| 4158 | |
| 4159 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4160 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4161 | } |
| 4162 | |
| 4163 | void LocationsBuilderMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4164 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4165 | } |
| 4166 | |
| 4167 | void InstructionCodeGeneratorMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 4168 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4169 | } |
| 4170 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4171 | void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadOneRegister( |
| 4172 | HInstruction* instruction, |
| 4173 | Location out, |
| 4174 | uint32_t offset, |
| 4175 | Location maybe_temp, |
| 4176 | ReadBarrierOption read_barrier_option) { |
| 4177 | GpuRegister out_reg = out.AsRegister<GpuRegister>(); |
| 4178 | if (read_barrier_option == kWithReadBarrier) { |
| 4179 | CHECK(kEmitCompilerReadBarrier); |
| 4180 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 4181 | if (kUseBakerReadBarrier) { |
| 4182 | // Load with fast path based Baker's read barrier. |
| 4183 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4184 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4185 | out, |
| 4186 | out_reg, |
| 4187 | offset, |
| 4188 | maybe_temp, |
| 4189 | /* needs_null_check */ false); |
| 4190 | } else { |
| 4191 | // Load with slow path based read barrier. |
| 4192 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 4193 | // in the following move operation, as we will need it for the |
| 4194 | // read barrier below. |
| 4195 | __ Move(maybe_temp.AsRegister<GpuRegister>(), out_reg); |
| 4196 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4197 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset); |
| 4198 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 4199 | } |
| 4200 | } else { |
| 4201 | // Plain load with no read barrier. |
| 4202 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4203 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, out_reg, offset); |
| 4204 | __ MaybeUnpoisonHeapReference(out_reg); |
| 4205 | } |
| 4206 | } |
| 4207 | |
| 4208 | void InstructionCodeGeneratorMIPS64::GenerateReferenceLoadTwoRegisters( |
| 4209 | HInstruction* instruction, |
| 4210 | Location out, |
| 4211 | Location obj, |
| 4212 | uint32_t offset, |
| 4213 | Location maybe_temp, |
| 4214 | ReadBarrierOption read_barrier_option) { |
| 4215 | GpuRegister out_reg = out.AsRegister<GpuRegister>(); |
| 4216 | GpuRegister obj_reg = obj.AsRegister<GpuRegister>(); |
| 4217 | if (read_barrier_option == kWithReadBarrier) { |
| 4218 | CHECK(kEmitCompilerReadBarrier); |
| 4219 | if (kUseBakerReadBarrier) { |
| 4220 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 4221 | // Load with fast path based Baker's read barrier. |
| 4222 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 4223 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4224 | out, |
| 4225 | obj_reg, |
| 4226 | offset, |
| 4227 | maybe_temp, |
| 4228 | /* needs_null_check */ false); |
| 4229 | } else { |
| 4230 | // Load with slow path based read barrier. |
| 4231 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 4232 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset); |
| 4233 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 4234 | } |
| 4235 | } else { |
| 4236 | // Plain load with no read barrier. |
| 4237 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 4238 | __ LoadFromOffset(kLoadUnsignedWord, out_reg, obj_reg, offset); |
| 4239 | __ MaybeUnpoisonHeapReference(out_reg); |
| 4240 | } |
| 4241 | } |
| 4242 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4243 | void InstructionCodeGeneratorMIPS64::GenerateGcRootFieldLoad( |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4244 | HInstruction* instruction, |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4245 | Location root, |
| 4246 | GpuRegister obj, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4247 | uint32_t offset, |
| 4248 | ReadBarrierOption read_barrier_option) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4249 | GpuRegister root_reg = root.AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4250 | if (read_barrier_option == kWithReadBarrier) { |
| 4251 | DCHECK(kEmitCompilerReadBarrier); |
| 4252 | if (kUseBakerReadBarrier) { |
| 4253 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 4254 | // Baker's read barrier are used: |
| 4255 | // |
| 4256 | // root = obj.field; |
| 4257 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 4258 | // if (temp != null) { |
| 4259 | // root = temp(root) |
| 4260 | // } |
| 4261 | |
| 4262 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 4263 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset); |
| 4264 | static_assert( |
| 4265 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 4266 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 4267 | "have different sizes."); |
| 4268 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 4269 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 4270 | "have different sizes."); |
| 4271 | |
| 4272 | // Slow path marking the GC root `root`. |
| 4273 | Location temp = Location::RegisterLocation(T9); |
| 4274 | SlowPathCodeMIPS64* slow_path = |
| 4275 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathMIPS64( |
| 4276 | instruction, |
| 4277 | root, |
| 4278 | /*entrypoint*/ temp); |
| 4279 | codegen_->AddSlowPath(slow_path); |
| 4280 | |
| 4281 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 4282 | const int32_t entry_point_offset = |
| 4283 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kMips64PointerSize>(root.reg() - 1); |
| 4284 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 4285 | // threads are suspended or running a checkpoint. |
| 4286 | __ LoadFromOffset(kLoadDoubleword, temp.AsRegister<GpuRegister>(), TR, entry_point_offset); |
| 4287 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 4288 | // checking GetIsGcMarking. |
| 4289 | __ Bnezc(temp.AsRegister<GpuRegister>(), slow_path->GetEntryLabel()); |
| 4290 | __ Bind(slow_path->GetExitLabel()); |
| 4291 | } else { |
| 4292 | // GC root loaded through a slow path for read barriers other |
| 4293 | // than Baker's. |
| 4294 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 4295 | __ Daddiu64(root_reg, obj, static_cast<int32_t>(offset)); |
| 4296 | // /* mirror::Object* */ root = root->Read() |
| 4297 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 4298 | } |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4299 | } else { |
| 4300 | // Plain GC root load with no read barrier. |
| 4301 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 4302 | __ LoadFromOffset(kLoadUnsignedWord, root_reg, obj, offset); |
| 4303 | // Note that GC roots are not affected by heap poisoning, thus we |
| 4304 | // do not have to unpoison `root_reg` here. |
| 4305 | } |
| 4306 | } |
| 4307 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4308 | void CodeGeneratorMIPS64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 4309 | Location ref, |
| 4310 | GpuRegister obj, |
| 4311 | uint32_t offset, |
| 4312 | Location temp, |
| 4313 | bool needs_null_check) { |
| 4314 | DCHECK(kEmitCompilerReadBarrier); |
| 4315 | DCHECK(kUseBakerReadBarrier); |
| 4316 | |
| 4317 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 4318 | Location no_index = Location::NoLocation(); |
| 4319 | ScaleFactor no_scale_factor = TIMES_1; |
| 4320 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 4321 | ref, |
| 4322 | obj, |
| 4323 | offset, |
| 4324 | no_index, |
| 4325 | no_scale_factor, |
| 4326 | temp, |
| 4327 | needs_null_check); |
| 4328 | } |
| 4329 | |
| 4330 | void CodeGeneratorMIPS64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 4331 | Location ref, |
| 4332 | GpuRegister obj, |
| 4333 | uint32_t data_offset, |
| 4334 | Location index, |
| 4335 | Location temp, |
| 4336 | bool needs_null_check) { |
| 4337 | DCHECK(kEmitCompilerReadBarrier); |
| 4338 | DCHECK(kUseBakerReadBarrier); |
| 4339 | |
| 4340 | static_assert( |
| 4341 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4342 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 4343 | // /* HeapReference<Object> */ ref = |
| 4344 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4345 | ScaleFactor scale_factor = TIMES_4; |
| 4346 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 4347 | ref, |
| 4348 | obj, |
| 4349 | data_offset, |
| 4350 | index, |
| 4351 | scale_factor, |
| 4352 | temp, |
| 4353 | needs_null_check); |
| 4354 | } |
| 4355 | |
| 4356 | void CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 4357 | Location ref, |
| 4358 | GpuRegister obj, |
| 4359 | uint32_t offset, |
| 4360 | Location index, |
| 4361 | ScaleFactor scale_factor, |
| 4362 | Location temp, |
| 4363 | bool needs_null_check, |
| 4364 | bool always_update_field) { |
| 4365 | DCHECK(kEmitCompilerReadBarrier); |
| 4366 | DCHECK(kUseBakerReadBarrier); |
| 4367 | |
| 4368 | // In slow path based read barriers, the read barrier call is |
| 4369 | // inserted after the original load. However, in fast path based |
| 4370 | // Baker's read barriers, we need to perform the load of |
| 4371 | // mirror::Object::monitor_ *before* the original reference load. |
| 4372 | // This load-load ordering is required by the read barrier. |
| 4373 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 4374 | // |
| 4375 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 4376 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 4377 | // HeapReference<Object> ref = *src; // Original reference load. |
| 4378 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 4379 | // if (is_gray) { |
| 4380 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 4381 | // } |
| 4382 | // |
| 4383 | // Note: the original implementation in ReadBarrier::Barrier is |
| 4384 | // slightly more complex as it performs additional checks that we do |
| 4385 | // not do here for performance reasons. |
| 4386 | |
| 4387 | GpuRegister ref_reg = ref.AsRegister<GpuRegister>(); |
| 4388 | GpuRegister temp_reg = temp.AsRegister<GpuRegister>(); |
| 4389 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 4390 | |
| 4391 | // /* int32_t */ monitor = obj->monitor_ |
| 4392 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 4393 | if (needs_null_check) { |
| 4394 | MaybeRecordImplicitNullCheck(instruction); |
| 4395 | } |
| 4396 | // /* LockWord */ lock_word = LockWord(monitor) |
| 4397 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 4398 | "art::LockWord and int32_t have different sizes."); |
| 4399 | |
| 4400 | __ Sync(0); // Barrier to prevent load-load reordering. |
| 4401 | |
| 4402 | // The actual reference load. |
| 4403 | if (index.IsValid()) { |
| 4404 | // Load types involving an "index": ArrayGet, |
| 4405 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 4406 | // intrinsics. |
| 4407 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 4408 | if (index.IsConstant()) { |
| 4409 | size_t computed_offset = |
| 4410 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
| 4411 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, computed_offset); |
| 4412 | } else { |
| 4413 | GpuRegister index_reg = index.AsRegister<GpuRegister>(); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 4414 | if (scale_factor == TIMES_1) { |
| 4415 | __ Daddu(TMP, index_reg, obj); |
| 4416 | } else { |
| 4417 | __ Dlsa(TMP, index_reg, obj, scale_factor); |
| 4418 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4419 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, TMP, offset); |
| 4420 | } |
| 4421 | } else { |
| 4422 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 4423 | __ LoadFromOffset(kLoadUnsignedWord, ref_reg, obj, offset); |
| 4424 | } |
| 4425 | |
| 4426 | // Object* ref = ref_addr->AsMirrorPtr() |
| 4427 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 4428 | |
| 4429 | // Slow path marking the object `ref` when it is gray. |
| 4430 | SlowPathCodeMIPS64* slow_path; |
| 4431 | if (always_update_field) { |
| 4432 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS64 only supports address |
| 4433 | // of the form `obj + field_offset`, where `obj` is a register and |
| 4434 | // `field_offset` is a register. Thus `offset` and `scale_factor` |
| 4435 | // above are expected to be null in this code path. |
| 4436 | DCHECK_EQ(offset, 0u); |
| 4437 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
| 4438 | slow_path = new (GetGraph()->GetArena()) |
| 4439 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS64(instruction, |
| 4440 | ref, |
| 4441 | obj, |
| 4442 | /* field_offset */ index, |
| 4443 | temp_reg); |
| 4444 | } else { |
| 4445 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathMIPS64(instruction, ref); |
| 4446 | } |
| 4447 | AddSlowPath(slow_path); |
| 4448 | |
| 4449 | // if (rb_state == ReadBarrier::GrayState()) |
| 4450 | // ref = ReadBarrier::Mark(ref); |
| 4451 | // Given the numeric representation, it's enough to check the low bit of the |
| 4452 | // rb_state. We do that by shifting the bit into the sign bit (31) and |
| 4453 | // performing a branch on less than zero. |
| 4454 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 4455 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 4456 | static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size"); |
| 4457 | __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift); |
| 4458 | __ Bltzc(temp_reg, slow_path->GetEntryLabel()); |
| 4459 | __ Bind(slow_path->GetExitLabel()); |
| 4460 | } |
| 4461 | |
| 4462 | void CodeGeneratorMIPS64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 4463 | Location out, |
| 4464 | Location ref, |
| 4465 | Location obj, |
| 4466 | uint32_t offset, |
| 4467 | Location index) { |
| 4468 | DCHECK(kEmitCompilerReadBarrier); |
| 4469 | |
| 4470 | // Insert a slow path based read barrier *after* the reference load. |
| 4471 | // |
| 4472 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 4473 | // reference will be carried out by the runtime within the slow |
| 4474 | // path. |
| 4475 | // |
| 4476 | // Note that `ref` currently does not get unpoisoned (when heap |
| 4477 | // poisoning is enabled), which is alright as the `ref` argument is |
| 4478 | // not used by the artReadBarrierSlow entry point. |
| 4479 | // |
| 4480 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 4481 | SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) |
| 4482 | ReadBarrierForHeapReferenceSlowPathMIPS64(instruction, out, ref, obj, offset, index); |
| 4483 | AddSlowPath(slow_path); |
| 4484 | |
| 4485 | __ Bc(slow_path->GetEntryLabel()); |
| 4486 | __ Bind(slow_path->GetExitLabel()); |
| 4487 | } |
| 4488 | |
| 4489 | void CodeGeneratorMIPS64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 4490 | Location out, |
| 4491 | Location ref, |
| 4492 | Location obj, |
| 4493 | uint32_t offset, |
| 4494 | Location index) { |
| 4495 | if (kEmitCompilerReadBarrier) { |
| 4496 | // Baker's read barriers shall be handled by the fast path |
| 4497 | // (CodeGeneratorMIPS64::GenerateReferenceLoadWithBakerReadBarrier). |
| 4498 | DCHECK(!kUseBakerReadBarrier); |
| 4499 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 4500 | // by the runtime within the slow path. |
| 4501 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| 4502 | } else if (kPoisonHeapReferences) { |
| 4503 | __ UnpoisonHeapReference(out.AsRegister<GpuRegister>()); |
| 4504 | } |
| 4505 | } |
| 4506 | |
| 4507 | void CodeGeneratorMIPS64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 4508 | Location out, |
| 4509 | Location root) { |
| 4510 | DCHECK(kEmitCompilerReadBarrier); |
| 4511 | |
| 4512 | // Insert a slow path based read barrier *after* the GC root load. |
| 4513 | // |
| 4514 | // Note that GC roots are not affected by heap poisoning, so we do |
| 4515 | // not need to do anything special for this here. |
| 4516 | SlowPathCodeMIPS64* slow_path = |
| 4517 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathMIPS64(instruction, out, root); |
| 4518 | AddSlowPath(slow_path); |
| 4519 | |
| 4520 | __ Bc(slow_path->GetEntryLabel()); |
| 4521 | __ Bind(slow_path->GetExitLabel()); |
| 4522 | } |
| 4523 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4524 | void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4525 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4526 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 4527 | bool baker_read_barrier_slow_path = false; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4528 | switch (type_check_kind) { |
| 4529 | case TypeCheckKind::kExactCheck: |
| 4530 | case TypeCheckKind::kAbstractClassCheck: |
| 4531 | case TypeCheckKind::kClassHierarchyCheck: |
| 4532 | case TypeCheckKind::kArrayObjectCheck: |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4533 | call_kind = |
| 4534 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 4535 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4536 | break; |
| 4537 | case TypeCheckKind::kArrayCheck: |
| 4538 | case TypeCheckKind::kUnresolvedCheck: |
| 4539 | case TypeCheckKind::kInterfaceCheck: |
| 4540 | call_kind = LocationSummary::kCallOnSlowPath; |
| 4541 | break; |
| 4542 | } |
| 4543 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4544 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexey Frunze | c61c076 | 2017-04-10 13:54:23 -0700 | [diff] [blame] | 4545 | if (baker_read_barrier_slow_path) { |
| 4546 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 4547 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4548 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4549 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4550 | // The output does overlap inputs. |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4551 | // Note that TypeCheckSlowPathMIPS64 uses this register too. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4552 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4553 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4554 | } |
| 4555 | |
| 4556 | void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4557 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4558 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4559 | Location obj_loc = locations->InAt(0); |
| 4560 | GpuRegister obj = obj_loc.AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4561 | GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4562 | Location out_loc = locations->Out(); |
| 4563 | GpuRegister out = out_loc.AsRegister<GpuRegister>(); |
| 4564 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 4565 | DCHECK_LE(num_temps, 1u); |
| 4566 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4567 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4568 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4569 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4570 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4571 | Mips64Label done; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4572 | SlowPathCodeMIPS64* slow_path = nullptr; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4573 | |
| 4574 | // Return 0 if `obj` is null. |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4575 | // Avoid this check if we know `obj` is not null. |
| 4576 | if (instruction->MustDoNullCheck()) { |
| 4577 | __ Move(out, ZERO); |
| 4578 | __ Beqzc(obj, &done); |
| 4579 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4580 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4581 | switch (type_check_kind) { |
| 4582 | case TypeCheckKind::kExactCheck: { |
| 4583 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4584 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4585 | out_loc, |
| 4586 | obj_loc, |
| 4587 | class_offset, |
| 4588 | maybe_temp_loc, |
| 4589 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4590 | // Classes must be equal for the instanceof to succeed. |
| 4591 | __ Xor(out, out, cls); |
| 4592 | __ Sltiu(out, out, 1); |
| 4593 | break; |
| 4594 | } |
| 4595 | |
| 4596 | case TypeCheckKind::kAbstractClassCheck: { |
| 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 | // If the class is abstract, we eagerly fetch the super class of the |
| 4605 | // object to avoid doing a comparison we know will fail. |
| 4606 | Mips64Label loop; |
| 4607 | __ Bind(&loop); |
| 4608 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4609 | GenerateReferenceLoadOneRegister(instruction, |
| 4610 | out_loc, |
| 4611 | super_offset, |
| 4612 | maybe_temp_loc, |
| 4613 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4614 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4615 | __ Beqzc(out, &done); |
| 4616 | __ Bnec(out, cls, &loop); |
| 4617 | __ LoadConst32(out, 1); |
| 4618 | break; |
| 4619 | } |
| 4620 | |
| 4621 | case TypeCheckKind::kClassHierarchyCheck: { |
| 4622 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4623 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4624 | out_loc, |
| 4625 | obj_loc, |
| 4626 | class_offset, |
| 4627 | maybe_temp_loc, |
| 4628 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4629 | // Walk over the class hierarchy to find a match. |
| 4630 | Mips64Label loop, success; |
| 4631 | __ Bind(&loop); |
| 4632 | __ Beqc(out, cls, &success); |
| 4633 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4634 | GenerateReferenceLoadOneRegister(instruction, |
| 4635 | out_loc, |
| 4636 | super_offset, |
| 4637 | maybe_temp_loc, |
| 4638 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4639 | __ Bnezc(out, &loop); |
| 4640 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4641 | __ Bc(&done); |
| 4642 | __ Bind(&success); |
| 4643 | __ LoadConst32(out, 1); |
| 4644 | break; |
| 4645 | } |
| 4646 | |
| 4647 | case TypeCheckKind::kArrayObjectCheck: { |
| 4648 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4649 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4650 | out_loc, |
| 4651 | obj_loc, |
| 4652 | class_offset, |
| 4653 | maybe_temp_loc, |
| 4654 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4655 | // Do an exact check. |
| 4656 | Mips64Label success; |
| 4657 | __ Beqc(out, cls, &success); |
| 4658 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 4659 | // /* HeapReference<Class> */ out = out->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4660 | GenerateReferenceLoadOneRegister(instruction, |
| 4661 | out_loc, |
| 4662 | component_offset, |
| 4663 | maybe_temp_loc, |
| 4664 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4665 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4666 | __ Beqzc(out, &done); |
| 4667 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 4668 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4669 | __ Sltiu(out, out, 1); |
| 4670 | __ Bc(&done); |
| 4671 | __ Bind(&success); |
| 4672 | __ LoadConst32(out, 1); |
| 4673 | break; |
| 4674 | } |
| 4675 | |
| 4676 | case TypeCheckKind::kArrayCheck: { |
| 4677 | // No read barrier since the slow path will retry upon failure. |
| 4678 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 4679 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4680 | out_loc, |
| 4681 | obj_loc, |
| 4682 | class_offset, |
| 4683 | maybe_temp_loc, |
| 4684 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4685 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4686 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction, |
| 4687 | /* is_fatal */ false); |
| 4688 | codegen_->AddSlowPath(slow_path); |
| 4689 | __ Bnec(out, cls, slow_path->GetEntryLabel()); |
| 4690 | __ LoadConst32(out, 1); |
| 4691 | break; |
| 4692 | } |
| 4693 | |
| 4694 | case TypeCheckKind::kUnresolvedCheck: |
| 4695 | case TypeCheckKind::kInterfaceCheck: { |
| 4696 | // Note that we indeed only call on slow path, but we always go |
| 4697 | // into the slow path for the unresolved and interface check |
| 4698 | // cases. |
| 4699 | // |
| 4700 | // We cannot directly call the InstanceofNonTrivial runtime |
| 4701 | // entry point without resorting to a type checking slow path |
| 4702 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 4703 | // require to assign fixed registers for the inputs of this |
| 4704 | // HInstanceOf instruction (following the runtime calling |
| 4705 | // convention), which might be cluttered by the potential first |
| 4706 | // read barrier emission at the beginning of this method. |
| 4707 | // |
| 4708 | // TODO: Introduce a new runtime entry point taking the object |
| 4709 | // to test (instead of its class) as argument, and let it deal |
| 4710 | // with the read barrier issues. This will let us refactor this |
| 4711 | // case of the `switch` code as it was previously (with a direct |
| 4712 | // call to the runtime not using a type checking slow path). |
| 4713 | // This should also be beneficial for the other cases above. |
| 4714 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4715 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction, |
| 4716 | /* is_fatal */ false); |
| 4717 | codegen_->AddSlowPath(slow_path); |
| 4718 | __ Bc(slow_path->GetEntryLabel()); |
| 4719 | break; |
| 4720 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4721 | } |
| 4722 | |
| 4723 | __ Bind(&done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 4724 | |
| 4725 | if (slow_path != nullptr) { |
| 4726 | __ Bind(slow_path->GetExitLabel()); |
| 4727 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4728 | } |
| 4729 | |
| 4730 | void LocationsBuilderMIPS64::VisitIntConstant(HIntConstant* constant) { |
| 4731 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4732 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4733 | } |
| 4734 | |
| 4735 | void InstructionCodeGeneratorMIPS64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 4736 | // Will be generated at use site. |
| 4737 | } |
| 4738 | |
| 4739 | void LocationsBuilderMIPS64::VisitNullConstant(HNullConstant* constant) { |
| 4740 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4741 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4742 | } |
| 4743 | |
| 4744 | void InstructionCodeGeneratorMIPS64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 4745 | // Will be generated at use site. |
| 4746 | } |
| 4747 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4748 | void LocationsBuilderMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4749 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4750 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4751 | // the method_idx. |
| 4752 | HandleInvoke(invoke); |
| 4753 | } |
| 4754 | |
| 4755 | void InstructionCodeGeneratorMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4756 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 4757 | } |
| 4758 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4759 | void LocationsBuilderMIPS64::HandleInvoke(HInvoke* invoke) { |
| 4760 | InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor; |
| 4761 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 4762 | } |
| 4763 | |
| 4764 | void LocationsBuilderMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4765 | HandleInvoke(invoke); |
| 4766 | // The register T0 is required to be used for the hidden argument in |
| 4767 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
| 4768 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0)); |
| 4769 | } |
| 4770 | |
| 4771 | void InstructionCodeGeneratorMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4772 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 4773 | GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4774 | Location receiver = invoke->GetLocations()->InAt(0); |
| 4775 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4776 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64PointerSize); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4777 | |
| 4778 | // Set the hidden argument. |
| 4779 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<GpuRegister>(), |
| 4780 | invoke->GetDexMethodIndex()); |
| 4781 | |
| 4782 | // temp = object->GetClass(); |
| 4783 | if (receiver.IsStackSlot()) { |
| 4784 | __ LoadFromOffset(kLoadUnsignedWord, temp, SP, receiver.GetStackIndex()); |
| 4785 | __ LoadFromOffset(kLoadUnsignedWord, temp, temp, class_offset); |
| 4786 | } else { |
| 4787 | __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset); |
| 4788 | } |
| 4789 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4790 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4791 | // emit a read barrier for the previous class reference load. |
| 4792 | // However this is not required in practice, as this is an |
| 4793 | // intermediate/temporary reference and because the current |
| 4794 | // concurrent copying collector keeps the from-space memory |
| 4795 | // intact/accessible until the end of the marking phase (the |
| 4796 | // concurrent copying collector may not in the future). |
| 4797 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4798 | __ LoadFromOffset(kLoadDoubleword, temp, temp, |
| 4799 | mirror::Class::ImtPtrOffset(kMips64PointerSize).Uint32Value()); |
| 4800 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4801 | invoke->GetImtIndex(), kMips64PointerSize)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4802 | // temp = temp->GetImtEntryAt(method_offset); |
| 4803 | __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset); |
| 4804 | // T9 = temp->GetEntryPoint(); |
| 4805 | __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value()); |
| 4806 | // T9(); |
| 4807 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4808 | __ Nop(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4809 | DCHECK(!codegen_->IsLeafMethod()); |
| 4810 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4811 | } |
| 4812 | |
| 4813 | void LocationsBuilderMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 4814 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); |
| 4815 | if (intrinsic.TryDispatch(invoke)) { |
| 4816 | return; |
| 4817 | } |
| 4818 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4819 | HandleInvoke(invoke); |
| 4820 | } |
| 4821 | |
| 4822 | void LocationsBuilderMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4823 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4824 | // art::PrepareForRegisterAllocation. |
| 4825 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4826 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 4827 | IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_); |
| 4828 | if (intrinsic.TryDispatch(invoke)) { |
| 4829 | return; |
| 4830 | } |
| 4831 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4832 | HandleInvoke(invoke); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4833 | } |
| 4834 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4835 | void LocationsBuilderMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4836 | HandleInvoke(invoke); |
| 4837 | } |
| 4838 | |
| 4839 | void InstructionCodeGeneratorMIPS64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4840 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 4841 | } |
| 4842 | |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 4843 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS64* codegen) { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4844 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 3039e38 | 2015-08-26 07:54:08 -0700 | [diff] [blame] | 4845 | IntrinsicCodeGeneratorMIPS64 intrinsic(codegen); |
| 4846 | intrinsic.Dispatch(invoke); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4847 | return true; |
| 4848 | } |
| 4849 | return false; |
| 4850 | } |
| 4851 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4852 | HLoadString::LoadKind CodeGeneratorMIPS64::GetSupportedLoadStringKind( |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4853 | HLoadString::LoadKind desired_string_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4854 | bool fallback_load = false; |
| 4855 | switch (desired_string_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4856 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4857 | case HLoadString::LoadKind::kBssEntry: |
| 4858 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4859 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4860 | case HLoadString::LoadKind::kJitTableAddress: |
| 4861 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4862 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4863 | case HLoadString::LoadKind::kBootImageAddress: |
| 4864 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 4865 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4866 | } |
| 4867 | if (fallback_load) { |
| 4868 | desired_string_load_kind = HLoadString::LoadKind::kDexCacheViaMethod; |
| 4869 | } |
| 4870 | return desired_string_load_kind; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4871 | } |
| 4872 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4873 | HLoadClass::LoadKind CodeGeneratorMIPS64::GetSupportedLoadClassKind( |
| 4874 | HLoadClass::LoadKind desired_class_load_kind) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4875 | bool fallback_load = false; |
| 4876 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4877 | case HLoadClass::LoadKind::kInvalid: |
| 4878 | LOG(FATAL) << "UNREACHABLE"; |
| 4879 | UNREACHABLE(); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4880 | case HLoadClass::LoadKind::kReferrersClass: |
| 4881 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4882 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4883 | case HLoadClass::LoadKind::kBssEntry: |
| 4884 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4885 | break; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4886 | case HLoadClass::LoadKind::kJitTableAddress: |
| 4887 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4888 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4889 | case HLoadClass::LoadKind::kBootImageAddress: |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 4890 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 4891 | break; |
| 4892 | } |
| 4893 | if (fallback_load) { |
| 4894 | desired_class_load_kind = HLoadClass::LoadKind::kDexCacheViaMethod; |
| 4895 | } |
| 4896 | return desired_class_load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4897 | } |
| 4898 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4899 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4900 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4901 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 4902 | // On MIPS64 we support all dispatch types. |
| 4903 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4904 | } |
| 4905 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4906 | void CodeGeneratorMIPS64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4907 | // 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] | 4908 | 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] | 4909 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 4910 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
| 4911 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 4912 | switch (method_load_kind) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4913 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4914 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4915 | uint32_t offset = |
| 4916 | GetThreadOffset<kMips64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4917 | __ LoadFromOffset(kLoadDoubleword, |
| 4918 | temp.AsRegister<GpuRegister>(), |
| 4919 | TR, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4920 | offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4921 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4922 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4923 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4924 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4925 | break; |
| 4926 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 4927 | __ LoadLiteral(temp.AsRegister<GpuRegister>(), |
| 4928 | kLoadDoubleword, |
| 4929 | DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4930 | break; |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 4931 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4932 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 4933 | CodeGeneratorMIPS64::PcRelativePatchInfo* info = |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 4934 | NewPcRelativeDexCacheArrayPatch(invoke->GetDexFileForPcRelativeDexCache(), offset); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 4935 | EmitPcRelativeAddressPlaceholderHigh(info, AT); |
| 4936 | __ Ld(temp.AsRegister<GpuRegister>(), AT, /* placeholder */ 0x5678); |
| 4937 | break; |
| 4938 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4939 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4940 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4941 | GpuRegister reg = temp.AsRegister<GpuRegister>(); |
| 4942 | GpuRegister method_reg; |
| 4943 | if (current_method.IsRegister()) { |
| 4944 | method_reg = current_method.AsRegister<GpuRegister>(); |
| 4945 | } else { |
| 4946 | // TODO: use the appropriate DCHECK() here if possible. |
| 4947 | // DCHECK(invoke->GetLocations()->Intrinsified()); |
| 4948 | DCHECK(!current_method.IsValid()); |
| 4949 | method_reg = reg; |
| 4950 | __ Ld(reg, SP, kCurrentMethodStackOffset); |
| 4951 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4952 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4953 | // temp = temp->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4954 | __ LoadFromOffset(kLoadDoubleword, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4955 | reg, |
| 4956 | method_reg, |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4957 | ArtMethod::DexCacheResolvedMethodsOffset(kMips64PointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 4958 | // temp = temp[index_in_cache]; |
| 4959 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 4960 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4961 | __ LoadFromOffset(kLoadDoubleword, |
| 4962 | reg, |
| 4963 | reg, |
| 4964 | CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 4965 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4966 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4967 | } |
| 4968 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 4969 | switch (code_ptr_location) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4970 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 4971 | __ Balc(&frame_entry_label_); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4972 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4973 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4974 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
| 4975 | __ LoadFromOffset(kLoadDoubleword, |
| 4976 | T9, |
| 4977 | callee_method.AsRegister<GpuRegister>(), |
| 4978 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4979 | kMips64PointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4980 | // T9() |
| 4981 | __ Jalr(T9); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 4982 | __ Nop(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4983 | break; |
| 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()); |
| 5002 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 5003 | } |
| 5004 | |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 5005 | void CodeGeneratorMIPS64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
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(); |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 5037 | } |
| 5038 | |
| 5039 | void InstructionCodeGeneratorMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 5040 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 5041 | return; |
| 5042 | } |
| 5043 | |
| 5044 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5045 | DCHECK(!codegen_->IsLeafMethod()); |
| 5046 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 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(); |
| 5051 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
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(); |
| 5088 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 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 || |
| 5099 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 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 | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5153 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
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); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5202 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 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. |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5276 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 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 |