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