Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [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_mips.h" |
| 18 | |
| 19 | #include "arch/mips/entrypoints_direct_mips.h" |
| 20 | #include "arch/mips/instruction_set_features_mips.h" |
| 21 | #include "art_method.h" |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 22 | #include "code_generator_utils.h" |
Vladimir Marko | 3a21e38 | 2016-09-02 12:38:38 +0100 | [diff] [blame] | 23 | #include "compiled_method.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints.h" |
| 25 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
| 26 | #include "gc/accounting/card_table.h" |
| 27 | #include "intrinsics.h" |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 28 | #include "intrinsics_mips.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 29 | #include "mirror/array-inl.h" |
| 30 | #include "mirror/class-inl.h" |
| 31 | #include "offsets.h" |
| 32 | #include "thread.h" |
| 33 | #include "utils/assembler.h" |
| 34 | #include "utils/mips/assembler_mips.h" |
| 35 | #include "utils/stack_checks.h" |
| 36 | |
| 37 | namespace art { |
| 38 | namespace mips { |
| 39 | |
| 40 | static constexpr int kCurrentMethodStackOffset = 0; |
| 41 | static constexpr Register kMethodRegisterArgument = A0; |
| 42 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 43 | // We'll maximize the range of a single load instruction for dex cache array accesses |
| 44 | // by aligning offset -32768 with the offset of the first used element. |
| 45 | static constexpr uint32_t kDexCacheArrayLwOffset = 0x8000; |
| 46 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 47 | Location MipsReturnLocation(Primitive::Type return_type) { |
| 48 | switch (return_type) { |
| 49 | case Primitive::kPrimBoolean: |
| 50 | case Primitive::kPrimByte: |
| 51 | case Primitive::kPrimChar: |
| 52 | case Primitive::kPrimShort: |
| 53 | case Primitive::kPrimInt: |
| 54 | case Primitive::kPrimNot: |
| 55 | return Location::RegisterLocation(V0); |
| 56 | |
| 57 | case Primitive::kPrimLong: |
| 58 | return Location::RegisterPairLocation(V0, V1); |
| 59 | |
| 60 | case Primitive::kPrimFloat: |
| 61 | case Primitive::kPrimDouble: |
| 62 | return Location::FpuRegisterLocation(F0); |
| 63 | |
| 64 | case Primitive::kPrimVoid: |
| 65 | return Location(); |
| 66 | } |
| 67 | UNREACHABLE(); |
| 68 | } |
| 69 | |
| 70 | Location InvokeDexCallingConventionVisitorMIPS::GetReturnLocation(Primitive::Type type) const { |
| 71 | return MipsReturnLocation(type); |
| 72 | } |
| 73 | |
| 74 | Location InvokeDexCallingConventionVisitorMIPS::GetMethodLocation() const { |
| 75 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 76 | } |
| 77 | |
| 78 | Location InvokeDexCallingConventionVisitorMIPS::GetNextLocation(Primitive::Type type) { |
| 79 | Location next_location; |
| 80 | |
| 81 | switch (type) { |
| 82 | case Primitive::kPrimBoolean: |
| 83 | case Primitive::kPrimByte: |
| 84 | case Primitive::kPrimChar: |
| 85 | case Primitive::kPrimShort: |
| 86 | case Primitive::kPrimInt: |
| 87 | case Primitive::kPrimNot: { |
| 88 | uint32_t gp_index = gp_index_++; |
| 89 | if (gp_index < calling_convention.GetNumberOfRegisters()) { |
| 90 | next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index)); |
| 91 | } else { |
| 92 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
| 93 | next_location = Location::StackSlot(stack_offset); |
| 94 | } |
| 95 | break; |
| 96 | } |
| 97 | |
| 98 | case Primitive::kPrimLong: { |
| 99 | uint32_t gp_index = gp_index_; |
| 100 | gp_index_ += 2; |
| 101 | if (gp_index + 1 < calling_convention.GetNumberOfRegisters()) { |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 102 | Register reg = calling_convention.GetRegisterAt(gp_index); |
| 103 | if (reg == A1 || reg == A3) { |
| 104 | gp_index_++; // Skip A1(A3), and use A2_A3(T0_T1) instead. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 105 | gp_index++; |
| 106 | } |
| 107 | Register low_even = calling_convention.GetRegisterAt(gp_index); |
| 108 | Register high_odd = calling_convention.GetRegisterAt(gp_index + 1); |
| 109 | DCHECK_EQ(low_even + 1, high_odd); |
| 110 | next_location = Location::RegisterPairLocation(low_even, high_odd); |
| 111 | } else { |
| 112 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
| 113 | next_location = Location::DoubleStackSlot(stack_offset); |
| 114 | } |
| 115 | break; |
| 116 | } |
| 117 | |
| 118 | // Note: both float and double types are stored in even FPU registers. On 32 bit FPU, double |
| 119 | // will take up the even/odd pair, while floats are stored in even regs only. |
| 120 | // On 64 bit FPU, both double and float are stored in even registers only. |
| 121 | case Primitive::kPrimFloat: |
| 122 | case Primitive::kPrimDouble: { |
| 123 | uint32_t float_index = float_index_++; |
| 124 | if (float_index < calling_convention.GetNumberOfFpuRegisters()) { |
| 125 | next_location = Location::FpuRegisterLocation( |
| 126 | calling_convention.GetFpuRegisterAt(float_index)); |
| 127 | } else { |
| 128 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
| 129 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 130 | : Location::StackSlot(stack_offset); |
| 131 | } |
| 132 | break; |
| 133 | } |
| 134 | |
| 135 | case Primitive::kPrimVoid: |
| 136 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 137 | break; |
| 138 | } |
| 139 | |
| 140 | // Space on the stack is reserved for all arguments. |
| 141 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
| 142 | |
| 143 | return next_location; |
| 144 | } |
| 145 | |
| 146 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type type) { |
| 147 | return MipsReturnLocation(type); |
| 148 | } |
| 149 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 150 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 151 | #define __ down_cast<CodeGeneratorMIPS*>(codegen)->GetAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 152 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value() |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 153 | |
| 154 | class BoundsCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 155 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 156 | explicit BoundsCheckSlowPathMIPS(HBoundsCheck* instruction) : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 157 | |
| 158 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 159 | LocationSummary* locations = instruction_->GetLocations(); |
| 160 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 161 | __ Bind(GetEntryLabel()); |
| 162 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 163 | // Live registers will be restored in the catch block if caught. |
| 164 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 165 | } |
| 166 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 167 | // move resolver. |
| 168 | InvokeRuntimeCallingConvention calling_convention; |
| 169 | codegen->EmitParallelMoves(locations->InAt(0), |
| 170 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 171 | Primitive::kPrimInt, |
| 172 | locations->InAt(1), |
| 173 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 174 | Primitive::kPrimInt); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 175 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 176 | ? kQuickThrowStringBounds |
| 177 | : kQuickThrowArrayBounds; |
| 178 | mips_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 179 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 180 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 181 | } |
| 182 | |
| 183 | bool IsFatal() const OVERRIDE { return true; } |
| 184 | |
| 185 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS"; } |
| 186 | |
| 187 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 188 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS); |
| 189 | }; |
| 190 | |
| 191 | class DivZeroCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 192 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 193 | explicit DivZeroCheckSlowPathMIPS(HDivZeroCheck* instruction) : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 194 | |
| 195 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 196 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 197 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 198 | mips_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 199 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 200 | } |
| 201 | |
| 202 | bool IsFatal() const OVERRIDE { return true; } |
| 203 | |
| 204 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS"; } |
| 205 | |
| 206 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 207 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS); |
| 208 | }; |
| 209 | |
| 210 | class LoadClassSlowPathMIPS : public SlowPathCodeMIPS { |
| 211 | public: |
| 212 | LoadClassSlowPathMIPS(HLoadClass* cls, |
| 213 | HInstruction* at, |
| 214 | uint32_t dex_pc, |
| 215 | bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 216 | : SlowPathCodeMIPS(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 217 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 218 | } |
| 219 | |
| 220 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 221 | LocationSummary* locations = instruction_->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 222 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 223 | |
| 224 | __ Bind(GetEntryLabel()); |
| 225 | SaveLiveRegisters(codegen, locations); |
| 226 | |
| 227 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 228 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 229 | __ LoadConst32(calling_convention.GetRegisterAt(0), type_index.index_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 230 | |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 231 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 232 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 233 | mips_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 234 | if (do_clinit_) { |
| 235 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 236 | } else { |
| 237 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 238 | } |
| 239 | |
| 240 | // Move the class to the desired location. |
| 241 | Location out = locations->Out(); |
| 242 | if (out.IsValid()) { |
| 243 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 244 | Primitive::Type type = instruction_->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 245 | mips_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
| 246 | } |
| 247 | |
| 248 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 249 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 250 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 251 | if (cls_ == instruction_ && cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 252 | DCHECK(out.IsValid()); |
| 253 | // TODO: Change art_quick_initialize_type/art_quick_initialize_static_storage to |
| 254 | // kSaveEverything and use a temporary for the .bss entry address in the fast path, |
| 255 | // so that we can avoid another calculation here. |
| 256 | bool isR6 = mips_codegen->GetInstructionSetFeatures().IsR6(); |
| 257 | Register base = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>(); |
| 258 | DCHECK_NE(out.AsRegister<Register>(), AT); |
| 259 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 260 | mips_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 261 | bool reordering = __ SetReorder(false); |
| 262 | mips_codegen->EmitPcRelativeAddressPlaceholderHigh(info, TMP, base); |
| 263 | __ StoreToOffset(kStoreWord, out.AsRegister<Register>(), TMP, /* placeholder */ 0x5678); |
| 264 | __ SetReorder(reordering); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 265 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 266 | __ B(GetExitLabel()); |
| 267 | } |
| 268 | |
| 269 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS"; } |
| 270 | |
| 271 | private: |
| 272 | // The class this slow path will load. |
| 273 | HLoadClass* const cls_; |
| 274 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 275 | // The dex PC of `at_`. |
| 276 | const uint32_t dex_pc_; |
| 277 | |
| 278 | // Whether to initialize the class. |
| 279 | const bool do_clinit_; |
| 280 | |
| 281 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS); |
| 282 | }; |
| 283 | |
| 284 | class LoadStringSlowPathMIPS : public SlowPathCodeMIPS { |
| 285 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 286 | explicit LoadStringSlowPathMIPS(HLoadString* instruction) : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 287 | |
| 288 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 289 | LocationSummary* locations = instruction_->GetLocations(); |
| 290 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 291 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 292 | |
| 293 | __ Bind(GetEntryLabel()); |
| 294 | SaveLiveRegisters(codegen, locations); |
| 295 | |
| 296 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 297 | HLoadString* load = instruction_->AsLoadString(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 298 | const dex::StringIndex string_index = load->GetStringIndex(); |
| 299 | __ LoadConst32(calling_convention.GetRegisterAt(0), string_index.index_); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 300 | mips_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 301 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 302 | Primitive::Type type = instruction_->GetType(); |
| 303 | mips_codegen->MoveLocation(locations->Out(), |
| 304 | calling_convention.GetReturnLocation(type), |
| 305 | type); |
| 306 | |
| 307 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 308 | |
| 309 | // Store the resolved String to the BSS entry. |
| 310 | // TODO: Change art_quick_resolve_string to kSaveEverything and use a temporary for the |
| 311 | // .bss entry address in the fast path, so that we can avoid another calculation here. |
| 312 | bool isR6 = mips_codegen->GetInstructionSetFeatures().IsR6(); |
| 313 | Register base = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>(); |
| 314 | Register out = locations->Out().AsRegister<Register>(); |
| 315 | DCHECK_NE(out, AT); |
| 316 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
| 317 | mips_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 318 | bool reordering = __ SetReorder(false); |
| 319 | mips_codegen->EmitPcRelativeAddressPlaceholderHigh(info, TMP, base); |
| 320 | __ StoreToOffset(kStoreWord, out, TMP, /* placeholder */ 0x5678); |
| 321 | __ SetReorder(reordering); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 322 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 323 | __ B(GetExitLabel()); |
| 324 | } |
| 325 | |
| 326 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS"; } |
| 327 | |
| 328 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 329 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS); |
| 330 | }; |
| 331 | |
| 332 | class NullCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 333 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 334 | explicit NullCheckSlowPathMIPS(HNullCheck* instr) : SlowPathCodeMIPS(instr) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 335 | |
| 336 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 337 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 338 | __ Bind(GetEntryLabel()); |
| 339 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 340 | // Live registers will be restored in the catch block if caught. |
| 341 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 342 | } |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 343 | mips_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 344 | instruction_, |
| 345 | instruction_->GetDexPc(), |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 346 | this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 347 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 348 | } |
| 349 | |
| 350 | bool IsFatal() const OVERRIDE { return true; } |
| 351 | |
| 352 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS"; } |
| 353 | |
| 354 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 355 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS); |
| 356 | }; |
| 357 | |
| 358 | class SuspendCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 359 | public: |
| 360 | SuspendCheckSlowPathMIPS(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 361 | : SlowPathCodeMIPS(instruction), successor_(successor) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 362 | |
| 363 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 364 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 365 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 366 | mips_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 367 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 368 | if (successor_ == nullptr) { |
| 369 | __ B(GetReturnLabel()); |
| 370 | } else { |
| 371 | __ B(mips_codegen->GetLabelOf(successor_)); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | MipsLabel* GetReturnLabel() { |
| 376 | DCHECK(successor_ == nullptr); |
| 377 | return &return_label_; |
| 378 | } |
| 379 | |
| 380 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS"; } |
| 381 | |
| 382 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 383 | // If not null, the block to branch to after the suspend check. |
| 384 | HBasicBlock* const successor_; |
| 385 | |
| 386 | // If `successor_` is null, the label to branch to after the suspend check. |
| 387 | MipsLabel return_label_; |
| 388 | |
| 389 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS); |
| 390 | }; |
| 391 | |
| 392 | class TypeCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 393 | public: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 394 | explicit TypeCheckSlowPathMIPS(HInstruction* instruction, bool is_fatal) |
| 395 | : SlowPathCodeMIPS(instruction), is_fatal_(is_fatal) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 396 | |
| 397 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 398 | LocationSummary* locations = instruction_->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 399 | uint32_t dex_pc = instruction_->GetDexPc(); |
| 400 | DCHECK(instruction_->IsCheckCast() |
| 401 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 402 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 403 | |
| 404 | __ Bind(GetEntryLabel()); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 405 | if (!is_fatal_) { |
| 406 | SaveLiveRegisters(codegen, locations); |
| 407 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 408 | |
| 409 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 410 | // move resolver. |
| 411 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 412 | codegen->EmitParallelMoves(locations->InAt(0), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 413 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 414 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 415 | locations->InAt(1), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 416 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 417 | Primitive::kPrimNot); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 418 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 419 | mips_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 420 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 421 | Primitive::Type ret_type = instruction_->GetType(); |
| 422 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 423 | mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 424 | } else { |
| 425 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 426 | mips_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 427 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 428 | } |
| 429 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 430 | if (!is_fatal_) { |
| 431 | RestoreLiveRegisters(codegen, locations); |
| 432 | __ B(GetExitLabel()); |
| 433 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; } |
| 437 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 438 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 439 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 440 | private: |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 441 | const bool is_fatal_; |
| 442 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 443 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS); |
| 444 | }; |
| 445 | |
| 446 | class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS { |
| 447 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 448 | explicit DeoptimizationSlowPathMIPS(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 449 | : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 450 | |
| 451 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 452 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 453 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 454 | mips_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 455 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; } |
| 459 | |
| 460 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 461 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS); |
| 462 | }; |
| 463 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 464 | class ArraySetSlowPathMIPS : public SlowPathCodeMIPS { |
| 465 | public: |
| 466 | explicit ArraySetSlowPathMIPS(HInstruction* instruction) : SlowPathCodeMIPS(instruction) {} |
| 467 | |
| 468 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 469 | LocationSummary* locations = instruction_->GetLocations(); |
| 470 | __ Bind(GetEntryLabel()); |
| 471 | SaveLiveRegisters(codegen, locations); |
| 472 | |
| 473 | InvokeRuntimeCallingConvention calling_convention; |
| 474 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 475 | parallel_move.AddMove( |
| 476 | locations->InAt(0), |
| 477 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 478 | Primitive::kPrimNot, |
| 479 | nullptr); |
| 480 | parallel_move.AddMove( |
| 481 | locations->InAt(1), |
| 482 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 483 | Primitive::kPrimInt, |
| 484 | nullptr); |
| 485 | parallel_move.AddMove( |
| 486 | locations->InAt(2), |
| 487 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 488 | Primitive::kPrimNot, |
| 489 | nullptr); |
| 490 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 491 | |
| 492 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 493 | mips_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 494 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 495 | RestoreLiveRegisters(codegen, locations); |
| 496 | __ B(GetExitLabel()); |
| 497 | } |
| 498 | |
| 499 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathMIPS"; } |
| 500 | |
| 501 | private: |
| 502 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathMIPS); |
| 503 | }; |
| 504 | |
| 505 | // Slow path marking an object reference `ref` during a read |
| 506 | // barrier. The field `obj.field` in the object `obj` holding this |
| 507 | // reference does not get updated by this slow path after marking (see |
| 508 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS below for that). |
| 509 | // |
| 510 | // This means that after the execution of this slow path, `ref` will |
| 511 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 512 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 513 | // probably still be a from-space reference (unless it gets updated by |
| 514 | // another thread, or if another thread installed another object |
| 515 | // reference (different from `ref`) in `obj.field`). |
| 516 | // |
| 517 | // If `entrypoint` is a valid location it is assumed to already be |
| 518 | // holding the entrypoint. The case where the entrypoint is passed in |
| 519 | // is for the GcRoot read barrier. |
| 520 | class ReadBarrierMarkSlowPathMIPS : public SlowPathCodeMIPS { |
| 521 | public: |
| 522 | ReadBarrierMarkSlowPathMIPS(HInstruction* instruction, |
| 523 | Location ref, |
| 524 | Location entrypoint = Location::NoLocation()) |
| 525 | : SlowPathCodeMIPS(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 526 | DCHECK(kEmitCompilerReadBarrier); |
| 527 | } |
| 528 | |
| 529 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathMIPS"; } |
| 530 | |
| 531 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 532 | LocationSummary* locations = instruction_->GetLocations(); |
| 533 | Register ref_reg = ref_.AsRegister<Register>(); |
| 534 | DCHECK(locations->CanCall()); |
| 535 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 536 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 537 | instruction_->IsStaticFieldGet() || |
| 538 | instruction_->IsArrayGet() || |
| 539 | instruction_->IsArraySet() || |
| 540 | instruction_->IsLoadClass() || |
| 541 | instruction_->IsLoadString() || |
| 542 | instruction_->IsInstanceOf() || |
| 543 | instruction_->IsCheckCast() || |
| 544 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 545 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 546 | << "Unexpected instruction in read barrier marking slow path: " |
| 547 | << instruction_->DebugName(); |
| 548 | |
| 549 | __ Bind(GetEntryLabel()); |
| 550 | // No need to save live registers; it's taken care of by the |
| 551 | // entrypoint. Also, there is no need to update the stack mask, |
| 552 | // as this runtime call will not trigger a garbage collection. |
| 553 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 554 | DCHECK((V0 <= ref_reg && ref_reg <= T7) || |
| 555 | (S2 <= ref_reg && ref_reg <= S7) || |
| 556 | (ref_reg == FP)) << ref_reg; |
| 557 | // "Compact" slow path, saving two moves. |
| 558 | // |
| 559 | // Instead of using the standard runtime calling convention (input |
| 560 | // and output in A0 and V0 respectively): |
| 561 | // |
| 562 | // A0 <- ref |
| 563 | // V0 <- ReadBarrierMark(A0) |
| 564 | // ref <- V0 |
| 565 | // |
| 566 | // we just use rX (the register containing `ref`) as input and output |
| 567 | // of a dedicated entrypoint: |
| 568 | // |
| 569 | // rX <- ReadBarrierMarkRegX(rX) |
| 570 | // |
| 571 | if (entrypoint_.IsValid()) { |
| 572 | mips_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 573 | DCHECK_EQ(entrypoint_.AsRegister<Register>(), T9); |
| 574 | __ Jalr(entrypoint_.AsRegister<Register>()); |
| 575 | __ NopIfNoReordering(); |
| 576 | } else { |
| 577 | int32_t entry_point_offset = |
| 578 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(ref_reg - 1); |
| 579 | // This runtime call does not require a stack map. |
| 580 | mips_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 581 | instruction_, |
| 582 | this, |
| 583 | /* direct */ false); |
| 584 | } |
| 585 | __ B(GetExitLabel()); |
| 586 | } |
| 587 | |
| 588 | private: |
| 589 | // The location (register) of the marked object reference. |
| 590 | const Location ref_; |
| 591 | |
| 592 | // The location of the entrypoint if already loaded. |
| 593 | const Location entrypoint_; |
| 594 | |
| 595 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathMIPS); |
| 596 | }; |
| 597 | |
| 598 | // Slow path marking an object reference `ref` during a read barrier, |
| 599 | // and if needed, atomically updating the field `obj.field` in the |
| 600 | // object `obj` holding this reference after marking (contrary to |
| 601 | // ReadBarrierMarkSlowPathMIPS above, which never tries to update |
| 602 | // `obj.field`). |
| 603 | // |
| 604 | // This means that after the execution of this slow path, both `ref` |
| 605 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 606 | // hold the same to-space reference (unless another thread installed |
| 607 | // another object reference (different from `ref`) in `obj.field`). |
| 608 | class ReadBarrierMarkAndUpdateFieldSlowPathMIPS : public SlowPathCodeMIPS { |
| 609 | public: |
| 610 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS(HInstruction* instruction, |
| 611 | Location ref, |
| 612 | Register obj, |
| 613 | Location field_offset, |
| 614 | Register temp1) |
| 615 | : SlowPathCodeMIPS(instruction), |
| 616 | ref_(ref), |
| 617 | obj_(obj), |
| 618 | field_offset_(field_offset), |
| 619 | temp1_(temp1) { |
| 620 | DCHECK(kEmitCompilerReadBarrier); |
| 621 | } |
| 622 | |
| 623 | const char* GetDescription() const OVERRIDE { |
| 624 | return "ReadBarrierMarkAndUpdateFieldSlowPathMIPS"; |
| 625 | } |
| 626 | |
| 627 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 628 | LocationSummary* locations = instruction_->GetLocations(); |
| 629 | Register ref_reg = ref_.AsRegister<Register>(); |
| 630 | DCHECK(locations->CanCall()); |
| 631 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 632 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 633 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 634 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 635 | << instruction_->DebugName(); |
| 636 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 637 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 638 | DCHECK(field_offset_.IsRegisterPair()) << field_offset_; |
| 639 | |
| 640 | __ Bind(GetEntryLabel()); |
| 641 | |
| 642 | // Save the old reference. |
| 643 | // Note that we cannot use AT or TMP to save the old reference, as those |
| 644 | // are used by the code that follows, but we need the old reference after |
| 645 | // the call to the ReadBarrierMarkRegX entry point. |
| 646 | DCHECK_NE(temp1_, AT); |
| 647 | DCHECK_NE(temp1_, TMP); |
| 648 | __ Move(temp1_, ref_reg); |
| 649 | |
| 650 | // No need to save live registers; it's taken care of by the |
| 651 | // entrypoint. Also, there is no need to update the stack mask, |
| 652 | // as this runtime call will not trigger a garbage collection. |
| 653 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 654 | DCHECK((V0 <= ref_reg && ref_reg <= T7) || |
| 655 | (S2 <= ref_reg && ref_reg <= S7) || |
| 656 | (ref_reg == FP)) << ref_reg; |
| 657 | // "Compact" slow path, saving two moves. |
| 658 | // |
| 659 | // Instead of using the standard runtime calling convention (input |
| 660 | // and output in A0 and V0 respectively): |
| 661 | // |
| 662 | // A0 <- ref |
| 663 | // V0 <- ReadBarrierMark(A0) |
| 664 | // ref <- V0 |
| 665 | // |
| 666 | // we just use rX (the register containing `ref`) as input and output |
| 667 | // of a dedicated entrypoint: |
| 668 | // |
| 669 | // rX <- ReadBarrierMarkRegX(rX) |
| 670 | // |
| 671 | int32_t entry_point_offset = |
| 672 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(ref_reg - 1); |
| 673 | // This runtime call does not require a stack map. |
| 674 | mips_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, |
| 675 | instruction_, |
| 676 | this, |
| 677 | /* direct */ false); |
| 678 | |
| 679 | // If the new reference is different from the old reference, |
| 680 | // update the field in the holder (`*(obj_ + field_offset_)`). |
| 681 | // |
| 682 | // Note that this field could also hold a different object, if |
| 683 | // another thread had concurrently changed it. In that case, the |
| 684 | // the compare-and-set (CAS) loop below would abort, leaving the |
| 685 | // field as-is. |
| 686 | MipsLabel done; |
| 687 | __ Beq(temp1_, ref_reg, &done); |
| 688 | |
| 689 | // Update the the holder's field atomically. This may fail if |
| 690 | // mutator updates before us, but it's OK. This is achieved |
| 691 | // using a strong compare-and-set (CAS) operation with relaxed |
| 692 | // memory synchronization ordering, where the expected value is |
| 693 | // the old reference and the desired value is the new reference. |
| 694 | |
| 695 | // Convenience aliases. |
| 696 | Register base = obj_; |
| 697 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 698 | // offset ("long offset"), of which only the low part contains |
| 699 | // data. |
| 700 | Register offset = field_offset_.AsRegisterPairLow<Register>(); |
| 701 | Register expected = temp1_; |
| 702 | Register value = ref_reg; |
| 703 | Register tmp_ptr = TMP; // Pointer to actual memory. |
| 704 | Register tmp = AT; // Value in memory. |
| 705 | |
| 706 | __ Addu(tmp_ptr, base, offset); |
| 707 | |
| 708 | if (kPoisonHeapReferences) { |
| 709 | __ PoisonHeapReference(expected); |
| 710 | // Do not poison `value` if it is the same register as |
| 711 | // `expected`, which has just been poisoned. |
| 712 | if (value != expected) { |
| 713 | __ PoisonHeapReference(value); |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | // do { |
| 718 | // tmp = [r_ptr] - expected; |
| 719 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 720 | |
| 721 | bool is_r6 = mips_codegen->GetInstructionSetFeatures().IsR6(); |
| 722 | MipsLabel loop_head, exit_loop; |
| 723 | __ Bind(&loop_head); |
| 724 | if (is_r6) { |
| 725 | __ LlR6(tmp, tmp_ptr); |
| 726 | } else { |
| 727 | __ LlR2(tmp, tmp_ptr); |
| 728 | } |
| 729 | __ Bne(tmp, expected, &exit_loop); |
| 730 | __ Move(tmp, value); |
| 731 | if (is_r6) { |
| 732 | __ ScR6(tmp, tmp_ptr); |
| 733 | } else { |
| 734 | __ ScR2(tmp, tmp_ptr); |
| 735 | } |
| 736 | __ Beqz(tmp, &loop_head); |
| 737 | __ Bind(&exit_loop); |
| 738 | |
| 739 | if (kPoisonHeapReferences) { |
| 740 | __ UnpoisonHeapReference(expected); |
| 741 | // Do not unpoison `value` if it is the same register as |
| 742 | // `expected`, which has just been unpoisoned. |
| 743 | if (value != expected) { |
| 744 | __ UnpoisonHeapReference(value); |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | __ Bind(&done); |
| 749 | __ B(GetExitLabel()); |
| 750 | } |
| 751 | |
| 752 | private: |
| 753 | // The location (register) of the marked object reference. |
| 754 | const Location ref_; |
| 755 | // The register containing the object holding the marked object reference field. |
| 756 | const Register obj_; |
| 757 | // The location of the offset of the marked reference field within `obj_`. |
| 758 | Location field_offset_; |
| 759 | |
| 760 | const Register temp1_; |
| 761 | |
| 762 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathMIPS); |
| 763 | }; |
| 764 | |
| 765 | // Slow path generating a read barrier for a heap reference. |
| 766 | class ReadBarrierForHeapReferenceSlowPathMIPS : public SlowPathCodeMIPS { |
| 767 | public: |
| 768 | ReadBarrierForHeapReferenceSlowPathMIPS(HInstruction* instruction, |
| 769 | Location out, |
| 770 | Location ref, |
| 771 | Location obj, |
| 772 | uint32_t offset, |
| 773 | Location index) |
| 774 | : SlowPathCodeMIPS(instruction), |
| 775 | out_(out), |
| 776 | ref_(ref), |
| 777 | obj_(obj), |
| 778 | offset_(offset), |
| 779 | index_(index) { |
| 780 | DCHECK(kEmitCompilerReadBarrier); |
| 781 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 782 | // has been overwritten by (or after) the heap object reference load |
| 783 | // to be instrumented, e.g.: |
| 784 | // |
| 785 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 786 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 787 | // |
| 788 | // In that case, we have lost the information about the original |
| 789 | // object, and the emitted read barrier cannot work properly. |
| 790 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 791 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 792 | } |
| 793 | |
| 794 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 795 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 796 | LocationSummary* locations = instruction_->GetLocations(); |
| 797 | Register reg_out = out_.AsRegister<Register>(); |
| 798 | DCHECK(locations->CanCall()); |
| 799 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 800 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 801 | instruction_->IsStaticFieldGet() || |
| 802 | instruction_->IsArrayGet() || |
| 803 | instruction_->IsInstanceOf() || |
| 804 | instruction_->IsCheckCast() || |
| 805 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 806 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 807 | << instruction_->DebugName(); |
| 808 | |
| 809 | __ Bind(GetEntryLabel()); |
| 810 | SaveLiveRegisters(codegen, locations); |
| 811 | |
| 812 | // We may have to change the index's value, but as `index_` is a |
| 813 | // constant member (like other "inputs" of this slow path), |
| 814 | // introduce a copy of it, `index`. |
| 815 | Location index = index_; |
| 816 | if (index_.IsValid()) { |
| 817 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 818 | if (instruction_->IsArrayGet()) { |
| 819 | // Compute the actual memory offset and store it in `index`. |
| 820 | Register index_reg = index_.AsRegister<Register>(); |
| 821 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 822 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 823 | // We are about to change the value of `index_reg` (see the |
| 824 | // calls to art::mips::MipsAssembler::Sll and |
| 825 | // art::mips::MipsAssembler::Addiu32 below), but it has |
| 826 | // not been saved by the previous call to |
| 827 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 828 | // callee-save register -- |
| 829 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 830 | // callee-save registers, as it has been designed with the |
| 831 | // assumption that callee-save registers are supposed to be |
| 832 | // handled by the called function. So, as a callee-save |
| 833 | // register, `index_reg` _would_ eventually be saved onto |
| 834 | // the stack, but it would be too late: we would have |
| 835 | // changed its value earlier. Therefore, we manually save |
| 836 | // it here into another freely available register, |
| 837 | // `free_reg`, chosen of course among the caller-save |
| 838 | // registers (as a callee-save `free_reg` register would |
| 839 | // exhibit the same problem). |
| 840 | // |
| 841 | // Note we could have requested a temporary register from |
| 842 | // the register allocator instead; but we prefer not to, as |
| 843 | // this is a slow path, and we know we can find a |
| 844 | // caller-save register that is available. |
| 845 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 846 | __ Move(free_reg, index_reg); |
| 847 | index_reg = free_reg; |
| 848 | index = Location::RegisterLocation(index_reg); |
| 849 | } else { |
| 850 | // The initial register stored in `index_` has already been |
| 851 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 852 | // (as it is not a callee-save register), so we can freely |
| 853 | // use it. |
| 854 | } |
| 855 | // Shifting the index value contained in `index_reg` by the scale |
| 856 | // factor (2) cannot overflow in practice, as the runtime is |
| 857 | // unable to allocate object arrays with a size larger than |
| 858 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 859 | __ Sll(index_reg, index_reg, TIMES_4); |
| 860 | static_assert( |
| 861 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 862 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 863 | __ Addiu32(index_reg, index_reg, offset_); |
| 864 | } else { |
| 865 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 866 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 867 | // (as in the case of ArrayGet), as it is actually an offset |
| 868 | // to an object field within an object. |
| 869 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 870 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 871 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 872 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 873 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 874 | DCHECK_EQ(offset_, 0U); |
| 875 | DCHECK(index_.IsRegisterPair()); |
| 876 | // UnsafeGet's offset location is a register pair, the low |
| 877 | // part contains the correct offset. |
| 878 | index = index_.ToLow(); |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | // We're moving two or three locations to locations that could |
| 883 | // overlap, so we need a parallel move resolver. |
| 884 | InvokeRuntimeCallingConvention calling_convention; |
| 885 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 886 | parallel_move.AddMove(ref_, |
| 887 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 888 | Primitive::kPrimNot, |
| 889 | nullptr); |
| 890 | parallel_move.AddMove(obj_, |
| 891 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 892 | Primitive::kPrimNot, |
| 893 | nullptr); |
| 894 | if (index.IsValid()) { |
| 895 | parallel_move.AddMove(index, |
| 896 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 897 | Primitive::kPrimInt, |
| 898 | nullptr); |
| 899 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 900 | } else { |
| 901 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 902 | __ LoadConst32(calling_convention.GetRegisterAt(2), offset_); |
| 903 | } |
| 904 | mips_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
| 905 | instruction_, |
| 906 | instruction_->GetDexPc(), |
| 907 | this); |
| 908 | CheckEntrypointTypes< |
| 909 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 910 | mips_codegen->Move32(out_, calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 911 | |
| 912 | RestoreLiveRegisters(codegen, locations); |
| 913 | __ B(GetExitLabel()); |
| 914 | } |
| 915 | |
| 916 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathMIPS"; } |
| 917 | |
| 918 | private: |
| 919 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 920 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 921 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 922 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 923 | if (i != ref && |
| 924 | i != obj && |
| 925 | !codegen->IsCoreCalleeSaveRegister(i) && |
| 926 | !codegen->IsBlockedCoreRegister(i)) { |
| 927 | return static_cast<Register>(i); |
| 928 | } |
| 929 | } |
| 930 | // We shall never fail to find a free caller-save register, as |
| 931 | // there are more than two core caller-save registers on MIPS |
| 932 | // (meaning it is possible to find one which is different from |
| 933 | // `ref` and `obj`). |
| 934 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 935 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 936 | UNREACHABLE(); |
| 937 | } |
| 938 | |
| 939 | const Location out_; |
| 940 | const Location ref_; |
| 941 | const Location obj_; |
| 942 | const uint32_t offset_; |
| 943 | // An additional location containing an index to an array. |
| 944 | // Only used for HArrayGet and the UnsafeGetObject & |
| 945 | // UnsafeGetObjectVolatile intrinsics. |
| 946 | const Location index_; |
| 947 | |
| 948 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathMIPS); |
| 949 | }; |
| 950 | |
| 951 | // Slow path generating a read barrier for a GC root. |
| 952 | class ReadBarrierForRootSlowPathMIPS : public SlowPathCodeMIPS { |
| 953 | public: |
| 954 | ReadBarrierForRootSlowPathMIPS(HInstruction* instruction, Location out, Location root) |
| 955 | : SlowPathCodeMIPS(instruction), out_(out), root_(root) { |
| 956 | DCHECK(kEmitCompilerReadBarrier); |
| 957 | } |
| 958 | |
| 959 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 960 | LocationSummary* locations = instruction_->GetLocations(); |
| 961 | Register reg_out = out_.AsRegister<Register>(); |
| 962 | DCHECK(locations->CanCall()); |
| 963 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 964 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 965 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 966 | << instruction_->DebugName(); |
| 967 | |
| 968 | __ Bind(GetEntryLabel()); |
| 969 | SaveLiveRegisters(codegen, locations); |
| 970 | |
| 971 | InvokeRuntimeCallingConvention calling_convention; |
| 972 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 973 | mips_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| 974 | mips_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 975 | instruction_, |
| 976 | instruction_->GetDexPc(), |
| 977 | this); |
| 978 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 979 | mips_codegen->Move32(out_, calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 980 | |
| 981 | RestoreLiveRegisters(codegen, locations); |
| 982 | __ B(GetExitLabel()); |
| 983 | } |
| 984 | |
| 985 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathMIPS"; } |
| 986 | |
| 987 | private: |
| 988 | const Location out_; |
| 989 | const Location root_; |
| 990 | |
| 991 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathMIPS); |
| 992 | }; |
| 993 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 994 | CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph, |
| 995 | const MipsInstructionSetFeatures& isa_features, |
| 996 | const CompilerOptions& compiler_options, |
| 997 | OptimizingCompilerStats* stats) |
| 998 | : CodeGenerator(graph, |
| 999 | kNumberOfCoreRegisters, |
| 1000 | kNumberOfFRegisters, |
| 1001 | kNumberOfRegisterPairs, |
| 1002 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1003 | arraysize(kCoreCalleeSaves)), |
| 1004 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1005 | arraysize(kFpuCalleeSaves)), |
| 1006 | compiler_options, |
| 1007 | stats), |
| 1008 | block_labels_(nullptr), |
| 1009 | location_builder_(graph, this), |
| 1010 | instruction_visitor_(graph, this), |
| 1011 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1012 | assembler_(graph->GetArena(), &isa_features), |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1013 | isa_features_(isa_features), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1014 | uint32_literals_(std::less<uint32_t>(), |
| 1015 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1016 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1017 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 1018 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1019 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1020 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 1021 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1022 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1023 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1024 | jit_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1025 | jit_class_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1026 | clobbered_ra_(false) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1027 | // Save RA (containing the return address) to mimic Quick. |
| 1028 | AddAllocatedRegister(Location::RegisterLocation(RA)); |
| 1029 | } |
| 1030 | |
| 1031 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 1032 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 1033 | #define __ down_cast<MipsAssembler*>(GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1034 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value() |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1035 | |
| 1036 | void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) { |
| 1037 | // Ensure that we fix up branches. |
| 1038 | __ FinalizeCode(); |
| 1039 | |
| 1040 | // Adjust native pc offsets in stack maps. |
| 1041 | 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] | 1042 | uint32_t old_position = |
| 1043 | stack_map_stream_.GetStackMap(i).native_pc_code_offset.Uint32Value(kMips); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1044 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 1045 | DCHECK_GE(new_position, old_position); |
| 1046 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 1047 | } |
| 1048 | |
| 1049 | // Adjust pc offsets for the disassembly information. |
| 1050 | if (disasm_info_ != nullptr) { |
| 1051 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 1052 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 1053 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 1054 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 1055 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 1056 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 1057 | } |
| 1058 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1059 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1060 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | CodeGenerator::Finalize(allocator); |
| 1065 | } |
| 1066 | |
| 1067 | MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const { |
| 1068 | return codegen_->GetAssembler(); |
| 1069 | } |
| 1070 | |
| 1071 | void ParallelMoveResolverMIPS::EmitMove(size_t index) { |
| 1072 | DCHECK_LT(index, moves_.size()); |
| 1073 | MoveOperands* move = moves_[index]; |
| 1074 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); |
| 1075 | } |
| 1076 | |
| 1077 | void ParallelMoveResolverMIPS::EmitSwap(size_t index) { |
| 1078 | DCHECK_LT(index, moves_.size()); |
| 1079 | MoveOperands* move = moves_[index]; |
| 1080 | Primitive::Type type = move->GetType(); |
| 1081 | Location loc1 = move->GetDestination(); |
| 1082 | Location loc2 = move->GetSource(); |
| 1083 | |
| 1084 | DCHECK(!loc1.IsConstant()); |
| 1085 | DCHECK(!loc2.IsConstant()); |
| 1086 | |
| 1087 | if (loc1.Equals(loc2)) { |
| 1088 | return; |
| 1089 | } |
| 1090 | |
| 1091 | if (loc1.IsRegister() && loc2.IsRegister()) { |
| 1092 | // Swap 2 GPRs. |
| 1093 | Register r1 = loc1.AsRegister<Register>(); |
| 1094 | Register r2 = loc2.AsRegister<Register>(); |
| 1095 | __ Move(TMP, r2); |
| 1096 | __ Move(r2, r1); |
| 1097 | __ Move(r1, TMP); |
| 1098 | } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) { |
| 1099 | FRegister f1 = loc1.AsFpuRegister<FRegister>(); |
| 1100 | FRegister f2 = loc2.AsFpuRegister<FRegister>(); |
| 1101 | if (type == Primitive::kPrimFloat) { |
| 1102 | __ MovS(FTMP, f2); |
| 1103 | __ MovS(f2, f1); |
| 1104 | __ MovS(f1, FTMP); |
| 1105 | } else { |
| 1106 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1107 | __ MovD(FTMP, f2); |
| 1108 | __ MovD(f2, f1); |
| 1109 | __ MovD(f1, FTMP); |
| 1110 | } |
| 1111 | } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) || |
| 1112 | (loc1.IsFpuRegister() && loc2.IsRegister())) { |
| 1113 | // Swap FPR and GPR. |
| 1114 | DCHECK_EQ(type, Primitive::kPrimFloat); // Can only swap a float. |
| 1115 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 1116 | : loc2.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1117 | Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1118 | __ Move(TMP, r2); |
| 1119 | __ Mfc1(r2, f1); |
| 1120 | __ Mtc1(TMP, f1); |
| 1121 | } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) { |
| 1122 | // Swap 2 GPR register pairs. |
| 1123 | Register r1 = loc1.AsRegisterPairLow<Register>(); |
| 1124 | Register r2 = loc2.AsRegisterPairLow<Register>(); |
| 1125 | __ Move(TMP, r2); |
| 1126 | __ Move(r2, r1); |
| 1127 | __ Move(r1, TMP); |
| 1128 | r1 = loc1.AsRegisterPairHigh<Register>(); |
| 1129 | r2 = loc2.AsRegisterPairHigh<Register>(); |
| 1130 | __ Move(TMP, r2); |
| 1131 | __ Move(r2, r1); |
| 1132 | __ Move(r1, TMP); |
| 1133 | } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) || |
| 1134 | (loc1.IsFpuRegister() && loc2.IsRegisterPair())) { |
| 1135 | // Swap FPR and GPR register pair. |
| 1136 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1137 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 1138 | : loc2.AsFpuRegister<FRegister>(); |
| 1139 | Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 1140 | : loc2.AsRegisterPairLow<Register>(); |
| 1141 | Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 1142 | : loc2.AsRegisterPairHigh<Register>(); |
| 1143 | // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and |
| 1144 | // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR |
| 1145 | // unpredictable and the following mfch1 will fail. |
| 1146 | __ Mfc1(TMP, f1); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 1147 | __ MoveFromFpuHigh(AT, f1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1148 | __ Mtc1(r2_l, f1); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 1149 | __ MoveToFpuHigh(r2_h, f1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1150 | __ Move(r2_l, TMP); |
| 1151 | __ Move(r2_h, AT); |
| 1152 | } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) { |
| 1153 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false); |
| 1154 | } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) { |
| 1155 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1156 | } else if ((loc1.IsRegister() && loc2.IsStackSlot()) || |
| 1157 | (loc1.IsStackSlot() && loc2.IsRegister())) { |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1158 | Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>(); |
| 1159 | intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex(); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1160 | __ Move(TMP, reg); |
| 1161 | __ LoadFromOffset(kLoadWord, reg, SP, offset); |
| 1162 | __ StoreToOffset(kStoreWord, TMP, SP, offset); |
| 1163 | } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) || |
| 1164 | (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) { |
| 1165 | Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 1166 | : loc2.AsRegisterPairLow<Register>(); |
| 1167 | Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 1168 | : loc2.AsRegisterPairHigh<Register>(); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1169 | intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex(); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1170 | intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize) |
| 1171 | : loc2.GetHighStackIndex(kMipsWordSize); |
| 1172 | __ Move(TMP, reg_l); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1173 | __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 1174 | __ StoreToOffset(kStoreWord, TMP, SP, offset_l); |
David Brazdil | 04d3e87 | 2016-01-29 09:50:09 +0000 | [diff] [blame] | 1175 | __ Move(TMP, reg_h); |
| 1176 | __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h); |
| 1177 | __ StoreToOffset(kStoreWord, TMP, SP, offset_h); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 1178 | } else if (loc1.IsFpuRegister() || loc2.IsFpuRegister()) { |
| 1179 | FRegister reg = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 1180 | : loc2.AsFpuRegister<FRegister>(); |
| 1181 | intptr_t offset = loc1.IsFpuRegister() ? loc2.GetStackIndex() : loc1.GetStackIndex(); |
| 1182 | if (type == Primitive::kPrimFloat) { |
| 1183 | __ MovS(FTMP, reg); |
| 1184 | __ LoadSFromOffset(reg, SP, offset); |
| 1185 | __ StoreSToOffset(FTMP, SP, offset); |
| 1186 | } else { |
| 1187 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1188 | __ MovD(FTMP, reg); |
| 1189 | __ LoadDFromOffset(reg, SP, offset); |
| 1190 | __ StoreDToOffset(FTMP, SP, offset); |
| 1191 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1192 | } else { |
| 1193 | LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported"; |
| 1194 | } |
| 1195 | } |
| 1196 | |
| 1197 | void ParallelMoveResolverMIPS::RestoreScratch(int reg) { |
| 1198 | __ Pop(static_cast<Register>(reg)); |
| 1199 | } |
| 1200 | |
| 1201 | void ParallelMoveResolverMIPS::SpillScratch(int reg) { |
| 1202 | __ Push(static_cast<Register>(reg)); |
| 1203 | } |
| 1204 | |
| 1205 | void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) { |
| 1206 | // Allocate a scratch register other than TMP, if available. |
| 1207 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be |
| 1208 | // automatically unspilled when the scratch scope object is destroyed). |
| 1209 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); |
| 1210 | // If V0 spills onto the stack, SP-relative offsets need to be adjusted. |
| 1211 | int stack_offset = ensure_scratch.IsSpilled() ? kMipsWordSize : 0; |
| 1212 | for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) { |
| 1213 | __ LoadFromOffset(kLoadWord, |
| 1214 | Register(ensure_scratch.GetRegister()), |
| 1215 | SP, |
| 1216 | index1 + stack_offset); |
| 1217 | __ LoadFromOffset(kLoadWord, |
| 1218 | TMP, |
| 1219 | SP, |
| 1220 | index2 + stack_offset); |
| 1221 | __ StoreToOffset(kStoreWord, |
| 1222 | Register(ensure_scratch.GetRegister()), |
| 1223 | SP, |
| 1224 | index2 + stack_offset); |
| 1225 | __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset); |
| 1226 | } |
| 1227 | } |
| 1228 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1229 | void CodeGeneratorMIPS::ComputeSpillMask() { |
| 1230 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 1231 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 1232 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 1233 | // If there're FPU callee-saved registers and there's an odd number of GPR callee-saved |
| 1234 | // registers, include the ZERO register to force alignment of FPU callee-saved registers |
| 1235 | // within the stack frame. |
| 1236 | if ((fpu_spill_mask_ != 0) && (POPCOUNT(core_spill_mask_) % 2 != 0)) { |
| 1237 | core_spill_mask_ |= (1 << ZERO); |
| 1238 | } |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | bool CodeGeneratorMIPS::HasAllocatedCalleeSaveRegisters() const { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1242 | // If RA is clobbered by PC-relative operations on R2 and it's the only spilled register |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 1243 | // (this can happen in leaf methods), force CodeGenerator::InitializeCodeGeneration() |
| 1244 | // into the path that creates a stack frame so that RA can be explicitly saved and restored. |
| 1245 | // RA can't otherwise be saved/restored when it's the only spilled register. |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 1246 | return CodeGenerator::HasAllocatedCalleeSaveRegisters() || clobbered_ra_; |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1247 | } |
| 1248 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1249 | static dwarf::Reg DWARFReg(Register reg) { |
| 1250 | return dwarf::Reg::MipsCore(static_cast<int>(reg)); |
| 1251 | } |
| 1252 | |
| 1253 | // TODO: mapping of floating-point registers to DWARF. |
| 1254 | |
| 1255 | void CodeGeneratorMIPS::GenerateFrameEntry() { |
| 1256 | __ Bind(&frame_entry_label_); |
| 1257 | |
| 1258 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips) || !IsLeafMethod(); |
| 1259 | |
| 1260 | if (do_overflow_check) { |
| 1261 | __ LoadFromOffset(kLoadWord, |
| 1262 | ZERO, |
| 1263 | SP, |
| 1264 | -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips))); |
| 1265 | RecordPcInfo(nullptr, 0); |
| 1266 | } |
| 1267 | |
| 1268 | if (HasEmptyFrame()) { |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 1269 | CHECK_EQ(fpu_spill_mask_, 0u); |
| 1270 | CHECK_EQ(core_spill_mask_, 1u << RA); |
| 1271 | CHECK(!clobbered_ra_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1272 | return; |
| 1273 | } |
| 1274 | |
| 1275 | // Make sure the frame size isn't unreasonably large. |
| 1276 | if (GetFrameSize() > GetStackOverflowReservedBytes(kMips)) { |
| 1277 | LOG(FATAL) << "Stack frame larger than " << GetStackOverflowReservedBytes(kMips) << " bytes"; |
| 1278 | } |
| 1279 | |
| 1280 | // Spill callee-saved registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1281 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1282 | uint32_t ofs = GetFrameSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1283 | __ IncreaseFrameSize(ofs); |
| 1284 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1285 | for (uint32_t mask = core_spill_mask_; mask != 0; ) { |
| 1286 | Register reg = static_cast<Register>(MostSignificantBit(mask)); |
| 1287 | mask ^= 1u << reg; |
| 1288 | ofs -= kMipsWordSize; |
| 1289 | // The ZERO register is only included for alignment. |
| 1290 | if (reg != ZERO) { |
| 1291 | __ StoreToOffset(kStoreWord, reg, SP, ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1292 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 1293 | } |
| 1294 | } |
| 1295 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1296 | for (uint32_t mask = fpu_spill_mask_; mask != 0; ) { |
| 1297 | FRegister reg = static_cast<FRegister>(MostSignificantBit(mask)); |
| 1298 | mask ^= 1u << reg; |
| 1299 | ofs -= kMipsDoublewordSize; |
| 1300 | __ StoreDToOffset(reg, SP, ofs); |
| 1301 | // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1302 | } |
| 1303 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1304 | // Save the current method if we need it. Note that we do not |
| 1305 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1306 | // in the SSA graph. |
| 1307 | if (RequiresCurrentMethod()) { |
| 1308 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
| 1309 | } |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 1310 | |
| 1311 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1312 | // Initialize should deoptimize flag to 0. |
| 1313 | __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 1314 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | void CodeGeneratorMIPS::GenerateFrameExit() { |
| 1318 | __ cfi().RememberState(); |
| 1319 | |
| 1320 | if (!HasEmptyFrame()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1321 | // Restore callee-saved registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1322 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1323 | // For better instruction scheduling restore RA before other registers. |
| 1324 | uint32_t ofs = GetFrameSize(); |
| 1325 | for (uint32_t mask = core_spill_mask_; mask != 0; ) { |
| 1326 | Register reg = static_cast<Register>(MostSignificantBit(mask)); |
| 1327 | mask ^= 1u << reg; |
| 1328 | ofs -= kMipsWordSize; |
| 1329 | // The ZERO register is only included for alignment. |
| 1330 | if (reg != ZERO) { |
| 1331 | __ LoadFromOffset(kLoadWord, reg, SP, ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1332 | __ cfi().Restore(DWARFReg(reg)); |
| 1333 | } |
| 1334 | } |
| 1335 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 1336 | for (uint32_t mask = fpu_spill_mask_; mask != 0; ) { |
| 1337 | FRegister reg = static_cast<FRegister>(MostSignificantBit(mask)); |
| 1338 | mask ^= 1u << reg; |
| 1339 | ofs -= kMipsDoublewordSize; |
| 1340 | __ LoadDFromOffset(reg, SP, ofs); |
| 1341 | // TODO: __ cfi().Restore(DWARFReg(reg)); |
| 1342 | } |
| 1343 | |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1344 | size_t frame_size = GetFrameSize(); |
| 1345 | // Adjust the stack pointer in the delay slot if doing so doesn't break CFI. |
| 1346 | bool exchange = IsInt<16>(static_cast<int32_t>(frame_size)); |
| 1347 | bool reordering = __ SetReorder(false); |
| 1348 | if (exchange) { |
| 1349 | __ Jr(RA); |
| 1350 | __ DecreaseFrameSize(frame_size); // Single instruction in delay slot. |
| 1351 | } else { |
| 1352 | __ DecreaseFrameSize(frame_size); |
| 1353 | __ Jr(RA); |
| 1354 | __ Nop(); // In delay slot. |
| 1355 | } |
| 1356 | __ SetReorder(reordering); |
| 1357 | } else { |
| 1358 | __ Jr(RA); |
| 1359 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1360 | } |
| 1361 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1362 | __ cfi().RestoreState(); |
| 1363 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 1364 | } |
| 1365 | |
| 1366 | void CodeGeneratorMIPS::Bind(HBasicBlock* block) { |
| 1367 | __ Bind(GetLabelOf(block)); |
| 1368 | } |
| 1369 | |
| 1370 | void CodeGeneratorMIPS::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
| 1371 | if (src.Equals(dst)) { |
| 1372 | return; |
| 1373 | } |
| 1374 | |
| 1375 | if (src.IsConstant()) { |
| 1376 | MoveConstant(dst, src.GetConstant()); |
| 1377 | } else { |
| 1378 | if (Primitive::Is64BitType(dst_type)) { |
| 1379 | Move64(dst, src); |
| 1380 | } else { |
| 1381 | Move32(dst, src); |
| 1382 | } |
| 1383 | } |
| 1384 | } |
| 1385 | |
| 1386 | void CodeGeneratorMIPS::Move32(Location destination, Location source) { |
| 1387 | if (source.Equals(destination)) { |
| 1388 | return; |
| 1389 | } |
| 1390 | |
| 1391 | if (destination.IsRegister()) { |
| 1392 | if (source.IsRegister()) { |
| 1393 | __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 1394 | } else if (source.IsFpuRegister()) { |
| 1395 | __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>()); |
| 1396 | } else { |
| 1397 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 1398 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
| 1399 | } |
| 1400 | } else if (destination.IsFpuRegister()) { |
| 1401 | if (source.IsRegister()) { |
| 1402 | __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>()); |
| 1403 | } else if (source.IsFpuRegister()) { |
| 1404 | __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 1405 | } else { |
| 1406 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 1407 | __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 1408 | } |
| 1409 | } else { |
| 1410 | DCHECK(destination.IsStackSlot()) << destination; |
| 1411 | if (source.IsRegister()) { |
| 1412 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
| 1413 | } else if (source.IsFpuRegister()) { |
| 1414 | __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex()); |
| 1415 | } else { |
| 1416 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 1417 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 1418 | __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex()); |
| 1419 | } |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | void CodeGeneratorMIPS::Move64(Location destination, Location source) { |
| 1424 | if (source.Equals(destination)) { |
| 1425 | return; |
| 1426 | } |
| 1427 | |
| 1428 | if (destination.IsRegisterPair()) { |
| 1429 | if (source.IsRegisterPair()) { |
| 1430 | __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 1431 | __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 1432 | } else if (source.IsFpuRegister()) { |
| 1433 | Register dst_high = destination.AsRegisterPairHigh<Register>(); |
| 1434 | Register dst_low = destination.AsRegisterPairLow<Register>(); |
| 1435 | FRegister src = source.AsFpuRegister<FRegister>(); |
| 1436 | __ Mfc1(dst_low, src); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 1437 | __ MoveFromFpuHigh(dst_high, src); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1438 | } else { |
| 1439 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 1440 | int32_t off = source.GetStackIndex(); |
| 1441 | Register r = destination.AsRegisterPairLow<Register>(); |
| 1442 | __ LoadFromOffset(kLoadDoubleword, r, SP, off); |
| 1443 | } |
| 1444 | } else if (destination.IsFpuRegister()) { |
| 1445 | if (source.IsRegisterPair()) { |
| 1446 | FRegister dst = destination.AsFpuRegister<FRegister>(); |
| 1447 | Register src_high = source.AsRegisterPairHigh<Register>(); |
| 1448 | Register src_low = source.AsRegisterPairLow<Register>(); |
| 1449 | __ Mtc1(src_low, dst); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 1450 | __ MoveToFpuHigh(src_high, dst); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1451 | } else if (source.IsFpuRegister()) { |
| 1452 | __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 1453 | } else { |
| 1454 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 1455 | __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 1456 | } |
| 1457 | } else { |
| 1458 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 1459 | int32_t off = destination.GetStackIndex(); |
| 1460 | if (source.IsRegisterPair()) { |
| 1461 | __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, off); |
| 1462 | } else if (source.IsFpuRegister()) { |
| 1463 | __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, off); |
| 1464 | } else { |
| 1465 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 1466 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 1467 | __ StoreToOffset(kStoreWord, TMP, SP, off); |
| 1468 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4); |
| 1469 | __ StoreToOffset(kStoreWord, TMP, SP, off + 4); |
| 1470 | } |
| 1471 | } |
| 1472 | } |
| 1473 | |
| 1474 | void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) { |
| 1475 | if (c->IsIntConstant() || c->IsNullConstant()) { |
| 1476 | // Move 32 bit constant. |
| 1477 | int32_t value = GetInt32ValueOf(c); |
| 1478 | if (destination.IsRegister()) { |
| 1479 | Register dst = destination.AsRegister<Register>(); |
| 1480 | __ LoadConst32(dst, value); |
| 1481 | } else { |
| 1482 | DCHECK(destination.IsStackSlot()) |
| 1483 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1484 | __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1485 | } |
| 1486 | } else if (c->IsLongConstant()) { |
| 1487 | // Move 64 bit constant. |
| 1488 | int64_t value = GetInt64ValueOf(c); |
| 1489 | if (destination.IsRegisterPair()) { |
| 1490 | Register r_h = destination.AsRegisterPairHigh<Register>(); |
| 1491 | Register r_l = destination.AsRegisterPairLow<Register>(); |
| 1492 | __ LoadConst64(r_h, r_l, value); |
| 1493 | } else { |
| 1494 | DCHECK(destination.IsDoubleStackSlot()) |
| 1495 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1496 | __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1497 | } |
| 1498 | } else if (c->IsFloatConstant()) { |
| 1499 | // Move 32 bit float constant. |
| 1500 | int32_t value = GetInt32ValueOf(c); |
| 1501 | if (destination.IsFpuRegister()) { |
| 1502 | __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP); |
| 1503 | } else { |
| 1504 | DCHECK(destination.IsStackSlot()) |
| 1505 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1506 | __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1507 | } |
| 1508 | } else { |
| 1509 | // Move 64 bit double constant. |
| 1510 | DCHECK(c->IsDoubleConstant()) << c->DebugName(); |
| 1511 | int64_t value = GetInt64ValueOf(c); |
| 1512 | if (destination.IsFpuRegister()) { |
| 1513 | FRegister fd = destination.AsFpuRegister<FRegister>(); |
| 1514 | __ LoadDConst64(fd, value, TMP); |
| 1515 | } else { |
| 1516 | DCHECK(destination.IsDoubleStackSlot()) |
| 1517 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1518 | __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1519 | } |
| 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) { |
| 1524 | DCHECK(destination.IsRegister()); |
| 1525 | Register dst = destination.AsRegister<Register>(); |
| 1526 | __ LoadConst32(dst, value); |
| 1527 | } |
| 1528 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1529 | void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1530 | if (location.IsRegister()) { |
| 1531 | locations->AddTemp(location); |
Alexey Frunze | c9e94f3 | 2015-10-26 16:11:39 -0700 | [diff] [blame] | 1532 | } else if (location.IsRegisterPair()) { |
| 1533 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1534 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1535 | } else { |
| 1536 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1537 | } |
| 1538 | } |
| 1539 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1540 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 1541 | inline void CodeGeneratorMIPS::EmitPcRelativeLinkerPatches( |
| 1542 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 1543 | ArenaVector<LinkerPatch>* linker_patches) { |
| 1544 | for (const PcRelativePatchInfo& info : infos) { |
| 1545 | const DexFile& dex_file = info.target_dex_file; |
| 1546 | size_t offset_or_index = info.offset_or_index; |
| 1547 | DCHECK(info.high_label.IsBound()); |
| 1548 | uint32_t high_offset = __ GetLabelLocation(&info.high_label); |
| 1549 | // On R2 we use HMipsComputeBaseMethodAddress and patch relative to |
| 1550 | // the assembler's base label used for PC-relative addressing. |
| 1551 | uint32_t pc_rel_offset = info.pc_rel_label.IsBound() |
| 1552 | ? __ GetLabelLocation(&info.pc_rel_label) |
| 1553 | : __ GetPcRelBaseLabelLocation(); |
| 1554 | linker_patches->push_back(Factory(high_offset, &dex_file, pc_rel_offset, offset_or_index)); |
| 1555 | } |
| 1556 | } |
| 1557 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1558 | void CodeGeneratorMIPS::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 1559 | DCHECK(linker_patches->empty()); |
| 1560 | size_t size = |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1561 | pc_relative_dex_cache_patches_.size() + |
| 1562 | pc_relative_string_patches_.size() + |
| 1563 | pc_relative_type_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1564 | type_bss_entry_patches_.size() + |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1565 | boot_image_string_patches_.size() + |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 1566 | boot_image_type_patches_.size(); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1567 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1568 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 1569 | linker_patches); |
| 1570 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1571 | DCHECK(pc_relative_type_patches_.empty()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1572 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 1573 | linker_patches); |
| 1574 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1575 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 1576 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1577 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 1578 | linker_patches); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1579 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1580 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 1581 | linker_patches); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1582 | for (const auto& entry : boot_image_string_patches_) { |
| 1583 | const StringReference& target_string = entry.first; |
| 1584 | Literal* literal = entry.second; |
| 1585 | DCHECK(literal->GetLabel()->IsBound()); |
| 1586 | uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel()); |
| 1587 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 1588 | target_string.dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 1589 | target_string.string_index.index_)); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1590 | } |
| 1591 | for (const auto& entry : boot_image_type_patches_) { |
| 1592 | const TypeReference& target_type = entry.first; |
| 1593 | Literal* literal = entry.second; |
| 1594 | DCHECK(literal->GetLabel()->IsBound()); |
| 1595 | uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel()); |
| 1596 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 1597 | target_type.dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1598 | target_type.type_index.index_)); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1599 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1600 | DCHECK_EQ(size, linker_patches->size()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeStringPatch( |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1604 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 1605 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeTypePatch( |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1609 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 1610 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1611 | } |
| 1612 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1613 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewTypeBssEntryPatch( |
| 1614 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 1615 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 1616 | } |
| 1617 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1618 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeDexCacheArrayPatch( |
| 1619 | const DexFile& dex_file, uint32_t element_offset) { |
| 1620 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 1621 | } |
| 1622 | |
| 1623 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativePatch( |
| 1624 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 1625 | patches->emplace_back(dex_file, offset_or_index); |
| 1626 | return &patches->back(); |
| 1627 | } |
| 1628 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1629 | Literal* CodeGeneratorMIPS::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 1630 | return map->GetOrCreate( |
| 1631 | value, |
| 1632 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
| 1633 | } |
| 1634 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1635 | Literal* CodeGeneratorMIPS::DeduplicateMethodLiteral(MethodReference target_method, |
| 1636 | MethodToLiteralMap* map) { |
| 1637 | return map->GetOrCreate( |
| 1638 | target_method, |
| 1639 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1640 | } |
| 1641 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1642 | Literal* CodeGeneratorMIPS::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 1643 | dex::StringIndex string_index) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1644 | return boot_image_string_patches_.GetOrCreate( |
| 1645 | StringReference(&dex_file, string_index), |
| 1646 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1647 | } |
| 1648 | |
| 1649 | Literal* CodeGeneratorMIPS::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1650 | dex::TypeIndex type_index) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1651 | return boot_image_type_patches_.GetOrCreate( |
| 1652 | TypeReference(&dex_file, type_index), |
| 1653 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1654 | } |
| 1655 | |
| 1656 | Literal* CodeGeneratorMIPS::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 1657 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1658 | } |
| 1659 | |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1660 | void CodeGeneratorMIPS::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info, |
| 1661 | Register out, |
| 1662 | Register base) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1663 | if (GetInstructionSetFeatures().IsR6()) { |
| 1664 | DCHECK_EQ(base, ZERO); |
| 1665 | __ Bind(&info->high_label); |
| 1666 | __ Bind(&info->pc_rel_label); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1667 | // Add the high half of a 32-bit offset to PC. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1668 | __ Auipc(out, /* placeholder */ 0x1234); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1669 | } else { |
| 1670 | // If base is ZERO, emit NAL to obtain the actual base. |
| 1671 | if (base == ZERO) { |
| 1672 | // Generate a dummy PC-relative call to obtain PC. |
| 1673 | __ Nal(); |
| 1674 | } |
| 1675 | __ Bind(&info->high_label); |
| 1676 | __ Lui(out, /* placeholder */ 0x1234); |
| 1677 | // If we emitted the NAL, bind the pc_rel_label, otherwise base is a register holding |
| 1678 | // the HMipsComputeBaseMethodAddress which has its own label stored in MipsAssembler. |
| 1679 | if (base == ZERO) { |
| 1680 | __ Bind(&info->pc_rel_label); |
| 1681 | } |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1682 | // Add the high half of a 32-bit offset to PC. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1683 | __ Addu(out, out, (base == ZERO) ? RA : base); |
| 1684 | } |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1685 | // The immediately following instruction will add the sign-extended low half of the 32-bit |
| 1686 | // offset to `out` (e.g. lw, jialc, addiu). |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1687 | } |
| 1688 | |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1689 | CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootStringPatch( |
| 1690 | const DexFile& dex_file, |
| 1691 | dex::StringIndex dex_index, |
| 1692 | Handle<mirror::String> handle) { |
| 1693 | jit_string_roots_.Overwrite(StringReference(&dex_file, dex_index), |
| 1694 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
| 1695 | jit_string_patches_.emplace_back(dex_file, dex_index.index_); |
| 1696 | return &jit_string_patches_.back(); |
| 1697 | } |
| 1698 | |
| 1699 | CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootClassPatch( |
| 1700 | const DexFile& dex_file, |
| 1701 | dex::TypeIndex dex_index, |
| 1702 | Handle<mirror::Class> handle) { |
| 1703 | jit_class_roots_.Overwrite(TypeReference(&dex_file, dex_index), |
| 1704 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
| 1705 | jit_class_patches_.emplace_back(dex_file, dex_index.index_); |
| 1706 | return &jit_class_patches_.back(); |
| 1707 | } |
| 1708 | |
| 1709 | void CodeGeneratorMIPS::PatchJitRootUse(uint8_t* code, |
| 1710 | const uint8_t* roots_data, |
| 1711 | const CodeGeneratorMIPS::JitPatchInfo& info, |
| 1712 | uint64_t index_in_table) const { |
| 1713 | uint32_t literal_offset = GetAssembler().GetLabelLocation(&info.high_label); |
| 1714 | uintptr_t address = |
| 1715 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 1716 | uint32_t addr32 = dchecked_integral_cast<uint32_t>(address); |
| 1717 | // lui reg, addr32_high |
| 1718 | DCHECK_EQ(code[literal_offset + 0], 0x34); |
| 1719 | DCHECK_EQ(code[literal_offset + 1], 0x12); |
| 1720 | DCHECK_EQ((code[literal_offset + 2] & 0xE0), 0x00); |
| 1721 | DCHECK_EQ(code[literal_offset + 3], 0x3C); |
| 1722 | // lw reg, reg, addr32_low |
| 1723 | DCHECK_EQ(code[literal_offset + 4], 0x78); |
| 1724 | DCHECK_EQ(code[literal_offset + 5], 0x56); |
| 1725 | DCHECK_EQ((code[literal_offset + 7] & 0xFC), 0x8C); |
| 1726 | addr32 += (addr32 & 0x8000) << 1; // Account for sign extension in "lw reg, reg, addr32_low". |
| 1727 | // lui reg, addr32_high |
| 1728 | code[literal_offset + 0] = static_cast<uint8_t>(addr32 >> 16); |
| 1729 | code[literal_offset + 1] = static_cast<uint8_t>(addr32 >> 24); |
| 1730 | // lw reg, reg, addr32_low |
| 1731 | code[literal_offset + 4] = static_cast<uint8_t>(addr32 >> 0); |
| 1732 | code[literal_offset + 5] = static_cast<uint8_t>(addr32 >> 8); |
| 1733 | } |
| 1734 | |
| 1735 | void CodeGeneratorMIPS::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 1736 | for (const JitPatchInfo& info : jit_string_patches_) { |
| 1737 | const auto& it = jit_string_roots_.find(StringReference(&info.target_dex_file, |
| 1738 | dex::StringIndex(info.index))); |
| 1739 | DCHECK(it != jit_string_roots_.end()); |
| 1740 | PatchJitRootUse(code, roots_data, info, it->second); |
| 1741 | } |
| 1742 | for (const JitPatchInfo& info : jit_class_patches_) { |
| 1743 | const auto& it = jit_class_roots_.find(TypeReference(&info.target_dex_file, |
| 1744 | dex::TypeIndex(info.index))); |
| 1745 | DCHECK(it != jit_class_roots_.end()); |
| 1746 | PatchJitRootUse(code, roots_data, info, it->second); |
| 1747 | } |
| 1748 | } |
| 1749 | |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1750 | void CodeGeneratorMIPS::MarkGCCard(Register object, |
| 1751 | Register value, |
| 1752 | bool value_can_be_null) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1753 | MipsLabel done; |
| 1754 | Register card = AT; |
| 1755 | Register temp = TMP; |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1756 | if (value_can_be_null) { |
| 1757 | __ Beqz(value, &done); |
| 1758 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1759 | __ LoadFromOffset(kLoadWord, |
| 1760 | card, |
| 1761 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1762 | Thread::CardTableOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1763 | __ Srl(temp, object, gc::accounting::CardTable::kCardShift); |
| 1764 | __ Addu(temp, card, temp); |
| 1765 | __ Sb(card, temp, 0); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1766 | if (value_can_be_null) { |
| 1767 | __ Bind(&done); |
| 1768 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1769 | } |
| 1770 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1771 | void CodeGeneratorMIPS::SetupBlockedRegisters() const { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1772 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1773 | blocked_core_registers_[ZERO] = true; |
| 1774 | blocked_core_registers_[K0] = true; |
| 1775 | blocked_core_registers_[K1] = true; |
| 1776 | blocked_core_registers_[GP] = true; |
| 1777 | blocked_core_registers_[SP] = true; |
| 1778 | blocked_core_registers_[RA] = true; |
| 1779 | |
| 1780 | // AT and TMP(T8) are used as temporary/scratch registers |
| 1781 | // (similar to how AT is used by MIPS assemblers). |
| 1782 | blocked_core_registers_[AT] = true; |
| 1783 | blocked_core_registers_[TMP] = true; |
| 1784 | blocked_fpu_registers_[FTMP] = true; |
| 1785 | |
| 1786 | // Reserve suspend and thread registers. |
| 1787 | blocked_core_registers_[S0] = true; |
| 1788 | blocked_core_registers_[TR] = true; |
| 1789 | |
| 1790 | // Reserve T9 for function calls |
| 1791 | blocked_core_registers_[T9] = true; |
| 1792 | |
| 1793 | // Reserve odd-numbered FPU registers. |
| 1794 | for (size_t i = 1; i < kNumberOfFRegisters; i += 2) { |
| 1795 | blocked_fpu_registers_[i] = true; |
| 1796 | } |
| 1797 | |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 1798 | if (GetGraph()->IsDebuggable()) { |
| 1799 | // Stubs do not save callee-save floating point registers. If the graph |
| 1800 | // is debuggable, we need to deal with these registers differently. For |
| 1801 | // now, just block them. |
| 1802 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1803 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1804 | } |
| 1805 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1806 | } |
| 1807 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1808 | size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1809 | __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index); |
| 1810 | return kMipsWordSize; |
| 1811 | } |
| 1812 | |
| 1813 | size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1814 | __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index); |
| 1815 | return kMipsWordSize; |
| 1816 | } |
| 1817 | |
| 1818 | size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1819 | __ StoreDToOffset(FRegister(reg_id), SP, stack_index); |
| 1820 | return kMipsDoublewordSize; |
| 1821 | } |
| 1822 | |
| 1823 | size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1824 | __ LoadDFromOffset(FRegister(reg_id), SP, stack_index); |
| 1825 | return kMipsDoublewordSize; |
| 1826 | } |
| 1827 | |
| 1828 | void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1829 | stream << Register(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1833 | stream << FRegister(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1834 | } |
| 1835 | |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1836 | constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16; |
| 1837 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1838 | void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1839 | HInstruction* instruction, |
| 1840 | uint32_t dex_pc, |
| 1841 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1842 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1843 | GenerateInvokeRuntime(GetThreadOffset<kMipsPointerSize>(entrypoint).Int32Value(), |
| 1844 | IsDirectEntrypoint(entrypoint)); |
| 1845 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1846 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1847 | } |
| 1848 | } |
| 1849 | |
| 1850 | void CodeGeneratorMIPS::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1851 | HInstruction* instruction, |
| 1852 | SlowPathCode* slow_path, |
| 1853 | bool direct) { |
| 1854 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| 1855 | GenerateInvokeRuntime(entry_point_offset, direct); |
| 1856 | } |
| 1857 | |
| 1858 | void CodeGeneratorMIPS::GenerateInvokeRuntime(int32_t entry_point_offset, bool direct) { |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1859 | bool reordering = __ SetReorder(false); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1860 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1861 | __ Jalr(T9); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 1862 | if (direct) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1863 | // Reserve argument space on stack (for $a0-$a3) for |
| 1864 | // entrypoints that directly reference native implementations. |
| 1865 | // Called function may use this space to store $a0-$a3 regs. |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1866 | __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1867 | __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1868 | } else { |
| 1869 | __ Nop(); // In delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1870 | } |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1871 | __ SetReorder(reordering); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1872 | } |
| 1873 | |
| 1874 | void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path, |
| 1875 | Register class_reg) { |
| 1876 | __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 1877 | __ LoadConst32(AT, mirror::Class::kStatusInitialized); |
| 1878 | __ Blt(TMP, AT, slow_path->GetEntryLabel()); |
| 1879 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 1880 | __ Sync(0); |
| 1881 | __ Bind(slow_path->GetExitLabel()); |
| 1882 | } |
| 1883 | |
| 1884 | void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1885 | __ Sync(0); // Only stype 0 is supported. |
| 1886 | } |
| 1887 | |
| 1888 | void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1889 | HBasicBlock* successor) { |
| 1890 | SuspendCheckSlowPathMIPS* slow_path = |
| 1891 | new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS(instruction, successor); |
| 1892 | codegen_->AddSlowPath(slow_path); |
| 1893 | |
| 1894 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1895 | TMP, |
| 1896 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1897 | Thread::ThreadFlagsOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1898 | if (successor == nullptr) { |
| 1899 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
| 1900 | __ Bind(slow_path->GetReturnLabel()); |
| 1901 | } else { |
| 1902 | __ Beqz(TMP, codegen_->GetLabelOf(successor)); |
| 1903 | __ B(slow_path->GetEntryLabel()); |
| 1904 | // slow_path will return to GetLabelOf(successor). |
| 1905 | } |
| 1906 | } |
| 1907 | |
| 1908 | InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph, |
| 1909 | CodeGeneratorMIPS* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1910 | : InstructionCodeGenerator(graph, codegen), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1911 | assembler_(codegen->GetAssembler()), |
| 1912 | codegen_(codegen) {} |
| 1913 | |
| 1914 | void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1915 | DCHECK_EQ(instruction->InputCount(), 2U); |
| 1916 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1917 | Primitive::Type type = instruction->GetResultType(); |
| 1918 | switch (type) { |
| 1919 | case Primitive::kPrimInt: { |
| 1920 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1921 | HInstruction* right = instruction->InputAt(1); |
| 1922 | bool can_use_imm = false; |
| 1923 | if (right->IsConstant()) { |
| 1924 | int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant()); |
| 1925 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 1926 | can_use_imm = IsUint<16>(imm); |
| 1927 | } else if (instruction->IsAdd()) { |
| 1928 | can_use_imm = IsInt<16>(imm); |
| 1929 | } else { |
| 1930 | DCHECK(instruction->IsSub()); |
| 1931 | can_use_imm = IsInt<16>(-imm); |
| 1932 | } |
| 1933 | } |
| 1934 | if (can_use_imm) |
| 1935 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 1936 | else |
| 1937 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1938 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1939 | break; |
| 1940 | } |
| 1941 | |
| 1942 | case Primitive::kPrimLong: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1943 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1944 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1945 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1946 | break; |
| 1947 | } |
| 1948 | |
| 1949 | case Primitive::kPrimFloat: |
| 1950 | case Primitive::kPrimDouble: |
| 1951 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 1952 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1953 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1954 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1955 | break; |
| 1956 | |
| 1957 | default: |
| 1958 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 1959 | } |
| 1960 | } |
| 1961 | |
| 1962 | void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1963 | Primitive::Type type = instruction->GetType(); |
| 1964 | LocationSummary* locations = instruction->GetLocations(); |
| 1965 | |
| 1966 | switch (type) { |
| 1967 | case Primitive::kPrimInt: { |
| 1968 | Register dst = locations->Out().AsRegister<Register>(); |
| 1969 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 1970 | Location rhs_location = locations->InAt(1); |
| 1971 | |
| 1972 | Register rhs_reg = ZERO; |
| 1973 | int32_t rhs_imm = 0; |
| 1974 | bool use_imm = rhs_location.IsConstant(); |
| 1975 | if (use_imm) { |
| 1976 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 1977 | } else { |
| 1978 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 1979 | } |
| 1980 | |
| 1981 | if (instruction->IsAnd()) { |
| 1982 | if (use_imm) |
| 1983 | __ Andi(dst, lhs, rhs_imm); |
| 1984 | else |
| 1985 | __ And(dst, lhs, rhs_reg); |
| 1986 | } else if (instruction->IsOr()) { |
| 1987 | if (use_imm) |
| 1988 | __ Ori(dst, lhs, rhs_imm); |
| 1989 | else |
| 1990 | __ Or(dst, lhs, rhs_reg); |
| 1991 | } else if (instruction->IsXor()) { |
| 1992 | if (use_imm) |
| 1993 | __ Xori(dst, lhs, rhs_imm); |
| 1994 | else |
| 1995 | __ Xor(dst, lhs, rhs_reg); |
| 1996 | } else if (instruction->IsAdd()) { |
| 1997 | if (use_imm) |
| 1998 | __ Addiu(dst, lhs, rhs_imm); |
| 1999 | else |
| 2000 | __ Addu(dst, lhs, rhs_reg); |
| 2001 | } else { |
| 2002 | DCHECK(instruction->IsSub()); |
| 2003 | if (use_imm) |
| 2004 | __ Addiu(dst, lhs, -rhs_imm); |
| 2005 | else |
| 2006 | __ Subu(dst, lhs, rhs_reg); |
| 2007 | } |
| 2008 | break; |
| 2009 | } |
| 2010 | |
| 2011 | case Primitive::kPrimLong: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2012 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 2013 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 2014 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2015 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2016 | Location rhs_location = locations->InAt(1); |
| 2017 | bool use_imm = rhs_location.IsConstant(); |
| 2018 | if (!use_imm) { |
| 2019 | Register rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 2020 | Register rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 2021 | if (instruction->IsAnd()) { |
| 2022 | __ And(dst_low, lhs_low, rhs_low); |
| 2023 | __ And(dst_high, lhs_high, rhs_high); |
| 2024 | } else if (instruction->IsOr()) { |
| 2025 | __ Or(dst_low, lhs_low, rhs_low); |
| 2026 | __ Or(dst_high, lhs_high, rhs_high); |
| 2027 | } else if (instruction->IsXor()) { |
| 2028 | __ Xor(dst_low, lhs_low, rhs_low); |
| 2029 | __ Xor(dst_high, lhs_high, rhs_high); |
| 2030 | } else if (instruction->IsAdd()) { |
| 2031 | if (lhs_low == rhs_low) { |
| 2032 | // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs. |
| 2033 | __ Slt(TMP, lhs_low, ZERO); |
| 2034 | __ Addu(dst_low, lhs_low, rhs_low); |
| 2035 | } else { |
| 2036 | __ Addu(dst_low, lhs_low, rhs_low); |
| 2037 | // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged. |
| 2038 | __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low); |
| 2039 | } |
| 2040 | __ Addu(dst_high, lhs_high, rhs_high); |
| 2041 | __ Addu(dst_high, dst_high, TMP); |
| 2042 | } else { |
| 2043 | DCHECK(instruction->IsSub()); |
| 2044 | __ Sltu(TMP, lhs_low, rhs_low); |
| 2045 | __ Subu(dst_low, lhs_low, rhs_low); |
| 2046 | __ Subu(dst_high, lhs_high, rhs_high); |
| 2047 | __ Subu(dst_high, dst_high, TMP); |
| 2048 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2049 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2050 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 2051 | if (instruction->IsOr()) { |
| 2052 | uint32_t low = Low32Bits(value); |
| 2053 | uint32_t high = High32Bits(value); |
| 2054 | if (IsUint<16>(low)) { |
| 2055 | if (dst_low != lhs_low || low != 0) { |
| 2056 | __ Ori(dst_low, lhs_low, low); |
| 2057 | } |
| 2058 | } else { |
| 2059 | __ LoadConst32(TMP, low); |
| 2060 | __ Or(dst_low, lhs_low, TMP); |
| 2061 | } |
| 2062 | if (IsUint<16>(high)) { |
| 2063 | if (dst_high != lhs_high || high != 0) { |
| 2064 | __ Ori(dst_high, lhs_high, high); |
| 2065 | } |
| 2066 | } else { |
| 2067 | if (high != low) { |
| 2068 | __ LoadConst32(TMP, high); |
| 2069 | } |
| 2070 | __ Or(dst_high, lhs_high, TMP); |
| 2071 | } |
| 2072 | } else if (instruction->IsXor()) { |
| 2073 | uint32_t low = Low32Bits(value); |
| 2074 | uint32_t high = High32Bits(value); |
| 2075 | if (IsUint<16>(low)) { |
| 2076 | if (dst_low != lhs_low || low != 0) { |
| 2077 | __ Xori(dst_low, lhs_low, low); |
| 2078 | } |
| 2079 | } else { |
| 2080 | __ LoadConst32(TMP, low); |
| 2081 | __ Xor(dst_low, lhs_low, TMP); |
| 2082 | } |
| 2083 | if (IsUint<16>(high)) { |
| 2084 | if (dst_high != lhs_high || high != 0) { |
| 2085 | __ Xori(dst_high, lhs_high, high); |
| 2086 | } |
| 2087 | } else { |
| 2088 | if (high != low) { |
| 2089 | __ LoadConst32(TMP, high); |
| 2090 | } |
| 2091 | __ Xor(dst_high, lhs_high, TMP); |
| 2092 | } |
| 2093 | } else if (instruction->IsAnd()) { |
| 2094 | uint32_t low = Low32Bits(value); |
| 2095 | uint32_t high = High32Bits(value); |
| 2096 | if (IsUint<16>(low)) { |
| 2097 | __ Andi(dst_low, lhs_low, low); |
| 2098 | } else if (low != 0xFFFFFFFF) { |
| 2099 | __ LoadConst32(TMP, low); |
| 2100 | __ And(dst_low, lhs_low, TMP); |
| 2101 | } else if (dst_low != lhs_low) { |
| 2102 | __ Move(dst_low, lhs_low); |
| 2103 | } |
| 2104 | if (IsUint<16>(high)) { |
| 2105 | __ Andi(dst_high, lhs_high, high); |
| 2106 | } else if (high != 0xFFFFFFFF) { |
| 2107 | if (high != low) { |
| 2108 | __ LoadConst32(TMP, high); |
| 2109 | } |
| 2110 | __ And(dst_high, lhs_high, TMP); |
| 2111 | } else if (dst_high != lhs_high) { |
| 2112 | __ Move(dst_high, lhs_high); |
| 2113 | } |
| 2114 | } else { |
| 2115 | if (instruction->IsSub()) { |
| 2116 | value = -value; |
| 2117 | } else { |
| 2118 | DCHECK(instruction->IsAdd()); |
| 2119 | } |
| 2120 | int32_t low = Low32Bits(value); |
| 2121 | int32_t high = High32Bits(value); |
| 2122 | if (IsInt<16>(low)) { |
| 2123 | if (dst_low != lhs_low || low != 0) { |
| 2124 | __ Addiu(dst_low, lhs_low, low); |
| 2125 | } |
| 2126 | if (low != 0) { |
| 2127 | __ Sltiu(AT, dst_low, low); |
| 2128 | } |
| 2129 | } else { |
| 2130 | __ LoadConst32(TMP, low); |
| 2131 | __ Addu(dst_low, lhs_low, TMP); |
| 2132 | __ Sltu(AT, dst_low, TMP); |
| 2133 | } |
| 2134 | if (IsInt<16>(high)) { |
| 2135 | if (dst_high != lhs_high || high != 0) { |
| 2136 | __ Addiu(dst_high, lhs_high, high); |
| 2137 | } |
| 2138 | } else { |
| 2139 | if (high != low) { |
| 2140 | __ LoadConst32(TMP, high); |
| 2141 | } |
| 2142 | __ Addu(dst_high, lhs_high, TMP); |
| 2143 | } |
| 2144 | if (low != 0) { |
| 2145 | __ Addu(dst_high, dst_high, AT); |
| 2146 | } |
| 2147 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2148 | } |
| 2149 | break; |
| 2150 | } |
| 2151 | |
| 2152 | case Primitive::kPrimFloat: |
| 2153 | case Primitive::kPrimDouble: { |
| 2154 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 2155 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2156 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2157 | if (instruction->IsAdd()) { |
| 2158 | if (type == Primitive::kPrimFloat) { |
| 2159 | __ AddS(dst, lhs, rhs); |
| 2160 | } else { |
| 2161 | __ AddD(dst, lhs, rhs); |
| 2162 | } |
| 2163 | } else { |
| 2164 | DCHECK(instruction->IsSub()); |
| 2165 | if (type == Primitive::kPrimFloat) { |
| 2166 | __ SubS(dst, lhs, rhs); |
| 2167 | } else { |
| 2168 | __ SubD(dst, lhs, rhs); |
| 2169 | } |
| 2170 | } |
| 2171 | break; |
| 2172 | } |
| 2173 | |
| 2174 | default: |
| 2175 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 2176 | } |
| 2177 | } |
| 2178 | |
| 2179 | void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2180 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2181 | |
| 2182 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2183 | Primitive::Type type = instr->GetResultType(); |
| 2184 | switch (type) { |
| 2185 | case Primitive::kPrimInt: |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2186 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2187 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 2188 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2189 | break; |
| 2190 | case Primitive::kPrimLong: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2191 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2192 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 2193 | locations->SetOut(Location::RequiresRegister()); |
| 2194 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2195 | default: |
| 2196 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2197 | } |
| 2198 | } |
| 2199 | |
| 2200 | static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte; |
| 2201 | |
| 2202 | void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2203 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2204 | LocationSummary* locations = instr->GetLocations(); |
| 2205 | Primitive::Type type = instr->GetType(); |
| 2206 | |
| 2207 | Location rhs_location = locations->InAt(1); |
| 2208 | bool use_imm = rhs_location.IsConstant(); |
| 2209 | Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>(); |
| 2210 | int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2211 | const uint32_t shift_mask = |
| 2212 | (type == Primitive::kPrimInt) ? kMaxIntShiftDistance : kMaxLongShiftDistance; |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2213 | const uint32_t shift_value = rhs_imm & shift_mask; |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2214 | // Are the INS (Insert Bit Field) and ROTR instructions supported? |
| 2215 | bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2216 | |
| 2217 | switch (type) { |
| 2218 | case Primitive::kPrimInt: { |
| 2219 | Register dst = locations->Out().AsRegister<Register>(); |
| 2220 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2221 | if (use_imm) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2222 | if (shift_value == 0) { |
| 2223 | if (dst != lhs) { |
| 2224 | __ Move(dst, lhs); |
| 2225 | } |
| 2226 | } else if (instr->IsShl()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2227 | __ Sll(dst, lhs, shift_value); |
| 2228 | } else if (instr->IsShr()) { |
| 2229 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2230 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2231 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2232 | } else { |
| 2233 | if (has_ins_rotr) { |
| 2234 | __ Rotr(dst, lhs, shift_value); |
| 2235 | } else { |
| 2236 | __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask); |
| 2237 | __ Srl(dst, lhs, shift_value); |
| 2238 | __ Or(dst, dst, TMP); |
| 2239 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2240 | } |
| 2241 | } else { |
| 2242 | if (instr->IsShl()) { |
| 2243 | __ Sllv(dst, lhs, rhs_reg); |
| 2244 | } else if (instr->IsShr()) { |
| 2245 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2246 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2247 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2248 | } else { |
| 2249 | if (has_ins_rotr) { |
| 2250 | __ Rotrv(dst, lhs, rhs_reg); |
| 2251 | } else { |
| 2252 | __ Subu(TMP, ZERO, rhs_reg); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2253 | // 32-bit shift instructions use the 5 least significant bits of the shift count, so |
| 2254 | // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case |
| 2255 | // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out |
| 2256 | // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`, |
| 2257 | // IOW, the OR'd values are equal. |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2258 | __ Sllv(TMP, lhs, TMP); |
| 2259 | __ Srlv(dst, lhs, rhs_reg); |
| 2260 | __ Or(dst, dst, TMP); |
| 2261 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2262 | } |
| 2263 | } |
| 2264 | break; |
| 2265 | } |
| 2266 | |
| 2267 | case Primitive::kPrimLong: { |
| 2268 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 2269 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 2270 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2271 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 2272 | if (use_imm) { |
| 2273 | if (shift_value == 0) { |
| 2274 | codegen_->Move64(locations->Out(), locations->InAt(0)); |
| 2275 | } else if (shift_value < kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2276 | if (has_ins_rotr) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2277 | if (instr->IsShl()) { |
| 2278 | __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 2279 | __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value); |
| 2280 | __ Sll(dst_low, lhs_low, shift_value); |
| 2281 | } else if (instr->IsShr()) { |
| 2282 | __ Srl(dst_low, lhs_low, shift_value); |
| 2283 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2284 | __ Sra(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2285 | } else if (instr->IsUShr()) { |
| 2286 | __ Srl(dst_low, lhs_low, shift_value); |
| 2287 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2288 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2289 | } else { |
| 2290 | __ Srl(dst_low, lhs_low, shift_value); |
| 2291 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 2292 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2293 | __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2294 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2295 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2296 | if (instr->IsShl()) { |
| 2297 | __ Sll(dst_low, lhs_low, shift_value); |
| 2298 | __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value); |
| 2299 | __ Sll(dst_high, lhs_high, shift_value); |
| 2300 | __ Or(dst_high, dst_high, TMP); |
| 2301 | } else if (instr->IsShr()) { |
| 2302 | __ Sra(dst_high, lhs_high, shift_value); |
| 2303 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 2304 | __ Srl(dst_low, lhs_low, shift_value); |
| 2305 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2306 | } else if (instr->IsUShr()) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2307 | __ Srl(dst_high, lhs_high, shift_value); |
| 2308 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 2309 | __ Srl(dst_low, lhs_low, shift_value); |
| 2310 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2311 | } else { |
| 2312 | __ Srl(TMP, lhs_low, shift_value); |
| 2313 | __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value); |
| 2314 | __ Or(dst_low, dst_low, TMP); |
| 2315 | __ Srl(TMP, lhs_high, shift_value); |
| 2316 | __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 2317 | __ Or(dst_high, dst_high, TMP); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 2318 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2319 | } |
| 2320 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2321 | const uint32_t shift_value_high = shift_value - kMipsBitsPerWord; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2322 | if (instr->IsShl()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2323 | __ Sll(dst_high, lhs_low, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2324 | __ Move(dst_low, ZERO); |
| 2325 | } else if (instr->IsShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2326 | __ Sra(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2327 | __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2328 | } else if (instr->IsUShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2329 | __ Srl(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2330 | __ Move(dst_high, ZERO); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2331 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2332 | if (shift_value == kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2333 | // 64-bit rotation by 32 is just a swap. |
| 2334 | __ Move(dst_low, lhs_high); |
| 2335 | __ Move(dst_high, lhs_low); |
| 2336 | } else { |
| 2337 | if (has_ins_rotr) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2338 | __ Srl(dst_low, lhs_high, shift_value_high); |
| 2339 | __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high); |
| 2340 | __ Srl(dst_high, lhs_low, shift_value_high); |
| 2341 | __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2342 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2343 | __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high); |
| 2344 | __ Srl(dst_low, lhs_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2345 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 2346 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high); |
| 2347 | __ Srl(dst_high, lhs_low, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2348 | __ Or(dst_high, dst_high, TMP); |
| 2349 | } |
| 2350 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2351 | } |
| 2352 | } |
| 2353 | } else { |
| 2354 | MipsLabel done; |
| 2355 | if (instr->IsShl()) { |
| 2356 | __ Sllv(dst_low, lhs_low, rhs_reg); |
| 2357 | __ Nor(AT, ZERO, rhs_reg); |
| 2358 | __ Srl(TMP, lhs_low, 1); |
| 2359 | __ Srlv(TMP, TMP, AT); |
| 2360 | __ Sllv(dst_high, lhs_high, rhs_reg); |
| 2361 | __ Or(dst_high, dst_high, TMP); |
| 2362 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 2363 | __ Beqz(TMP, &done); |
| 2364 | __ Move(dst_high, dst_low); |
| 2365 | __ Move(dst_low, ZERO); |
| 2366 | } else if (instr->IsShr()) { |
| 2367 | __ Srav(dst_high, lhs_high, rhs_reg); |
| 2368 | __ Nor(AT, ZERO, rhs_reg); |
| 2369 | __ Sll(TMP, lhs_high, 1); |
| 2370 | __ Sllv(TMP, TMP, AT); |
| 2371 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 2372 | __ Or(dst_low, dst_low, TMP); |
| 2373 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 2374 | __ Beqz(TMP, &done); |
| 2375 | __ Move(dst_low, dst_high); |
| 2376 | __ Sra(dst_high, dst_high, 31); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2377 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2378 | __ Srlv(dst_high, lhs_high, rhs_reg); |
| 2379 | __ Nor(AT, ZERO, rhs_reg); |
| 2380 | __ Sll(TMP, lhs_high, 1); |
| 2381 | __ Sllv(TMP, TMP, AT); |
| 2382 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 2383 | __ Or(dst_low, dst_low, TMP); |
| 2384 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 2385 | __ Beqz(TMP, &done); |
| 2386 | __ Move(dst_low, dst_high); |
| 2387 | __ Move(dst_high, ZERO); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 2388 | } else { |
| 2389 | __ Nor(AT, ZERO, rhs_reg); |
| 2390 | __ Srlv(TMP, lhs_low, rhs_reg); |
| 2391 | __ Sll(dst_low, lhs_high, 1); |
| 2392 | __ Sllv(dst_low, dst_low, AT); |
| 2393 | __ Or(dst_low, dst_low, TMP); |
| 2394 | __ Srlv(TMP, lhs_high, rhs_reg); |
| 2395 | __ Sll(dst_high, lhs_low, 1); |
| 2396 | __ Sllv(dst_high, dst_high, AT); |
| 2397 | __ Or(dst_high, dst_high, TMP); |
| 2398 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 2399 | __ Beqz(TMP, &done); |
| 2400 | __ Move(TMP, dst_high); |
| 2401 | __ Move(dst_high, dst_low); |
| 2402 | __ Move(dst_low, TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2403 | } |
| 2404 | __ Bind(&done); |
| 2405 | } |
| 2406 | break; |
| 2407 | } |
| 2408 | |
| 2409 | default: |
| 2410 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2411 | } |
| 2412 | } |
| 2413 | |
| 2414 | void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) { |
| 2415 | HandleBinaryOp(instruction); |
| 2416 | } |
| 2417 | |
| 2418 | void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) { |
| 2419 | HandleBinaryOp(instruction); |
| 2420 | } |
| 2421 | |
| 2422 | void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) { |
| 2423 | HandleBinaryOp(instruction); |
| 2424 | } |
| 2425 | |
| 2426 | void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) { |
| 2427 | HandleBinaryOp(instruction); |
| 2428 | } |
| 2429 | |
| 2430 | void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2431 | Primitive::Type type = instruction->GetType(); |
| 2432 | bool object_array_get_with_read_barrier = |
| 2433 | kEmitCompilerReadBarrier && (type == Primitive::kPrimNot); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2434 | LocationSummary* locations = |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2435 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2436 | object_array_get_with_read_barrier |
| 2437 | ? LocationSummary::kCallOnSlowPath |
| 2438 | : LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2439 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2440 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2441 | if (Primitive::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2442 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2443 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2444 | // The output overlaps in the case of an object array get with |
| 2445 | // read barriers enabled: we do not want the move to overwrite the |
| 2446 | // array's location, as we need it to emit the read barrier. |
| 2447 | locations->SetOut(Location::RequiresRegister(), |
| 2448 | object_array_get_with_read_barrier |
| 2449 | ? Location::kOutputOverlap |
| 2450 | : Location::kNoOutputOverlap); |
| 2451 | } |
| 2452 | // We need a temporary register for the read barrier marking slow |
| 2453 | // path in CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier. |
| 2454 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 2455 | locations->AddTemp(Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2456 | } |
| 2457 | } |
| 2458 | |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2459 | static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS* codegen) { |
| 2460 | auto null_checker = [codegen, instruction]() { |
| 2461 | codegen->MaybeRecordImplicitNullCheck(instruction); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2462 | }; |
| 2463 | return null_checker; |
| 2464 | } |
| 2465 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2466 | void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) { |
| 2467 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2468 | Location obj_loc = locations->InAt(0); |
| 2469 | Register obj = obj_loc.AsRegister<Register>(); |
| 2470 | Location out_loc = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2471 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2472 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2473 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2474 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2475 | Primitive::Type type = instruction->GetType(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2476 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2477 | instruction->IsStringCharAt(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2478 | switch (type) { |
| 2479 | case Primitive::kPrimBoolean: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2480 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2481 | if (index.IsConstant()) { |
| 2482 | size_t offset = |
| 2483 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2484 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2485 | } else { |
| 2486 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2487 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2488 | } |
| 2489 | break; |
| 2490 | } |
| 2491 | |
| 2492 | case Primitive::kPrimByte: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2493 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2494 | if (index.IsConstant()) { |
| 2495 | size_t offset = |
| 2496 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2497 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2498 | } else { |
| 2499 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2500 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2501 | } |
| 2502 | break; |
| 2503 | } |
| 2504 | |
| 2505 | case Primitive::kPrimShort: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2506 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2507 | if (index.IsConstant()) { |
| 2508 | size_t offset = |
| 2509 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2510 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2511 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2512 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_2, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2513 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2514 | } |
| 2515 | break; |
| 2516 | } |
| 2517 | |
| 2518 | case Primitive::kPrimChar: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2519 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2520 | if (maybe_compressed_char_at) { |
| 2521 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2522 | __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker); |
| 2523 | __ Sll(TMP, TMP, 31); // Extract compression flag into the most significant bit of TMP. |
| 2524 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2525 | "Expecting 0=compressed, 1=uncompressed"); |
| 2526 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2527 | if (index.IsConstant()) { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2528 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 2529 | if (maybe_compressed_char_at) { |
| 2530 | MipsLabel uncompressed_load, done; |
| 2531 | __ Bnez(TMP, &uncompressed_load); |
| 2532 | __ LoadFromOffset(kLoadUnsignedByte, |
| 2533 | out, |
| 2534 | obj, |
| 2535 | data_offset + (const_index << TIMES_1)); |
| 2536 | __ B(&done); |
| 2537 | __ Bind(&uncompressed_load); |
| 2538 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2539 | out, |
| 2540 | obj, |
| 2541 | data_offset + (const_index << TIMES_2)); |
| 2542 | __ Bind(&done); |
| 2543 | } else { |
| 2544 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 2545 | out, |
| 2546 | obj, |
| 2547 | data_offset + (const_index << TIMES_2), |
| 2548 | null_checker); |
| 2549 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2550 | } else { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2551 | Register index_reg = index.AsRegister<Register>(); |
| 2552 | if (maybe_compressed_char_at) { |
| 2553 | MipsLabel uncompressed_load, done; |
| 2554 | __ Bnez(TMP, &uncompressed_load); |
| 2555 | __ Addu(TMP, obj, index_reg); |
| 2556 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 2557 | __ B(&done); |
| 2558 | __ Bind(&uncompressed_load); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2559 | __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2560 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 2561 | __ Bind(&done); |
| 2562 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2563 | __ ShiftAndAdd(TMP, index_reg, obj, TIMES_2, TMP); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2564 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
| 2565 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2566 | } |
| 2567 | break; |
| 2568 | } |
| 2569 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2570 | case Primitive::kPrimInt: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2571 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2572 | Register out = out_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2573 | if (index.IsConstant()) { |
| 2574 | size_t offset = |
| 2575 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2576 | __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2577 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2578 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2579 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2580 | } |
| 2581 | break; |
| 2582 | } |
| 2583 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2584 | case Primitive::kPrimNot: { |
| 2585 | static_assert( |
| 2586 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2587 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2588 | // /* HeapReference<Object> */ out = |
| 2589 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 2590 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2591 | Location temp = locations->GetTemp(0); |
| 2592 | // Note that a potential implicit null check is handled in this |
| 2593 | // CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier call. |
| 2594 | codegen_->GenerateArrayLoadWithBakerReadBarrier(instruction, |
| 2595 | out_loc, |
| 2596 | obj, |
| 2597 | data_offset, |
| 2598 | index, |
| 2599 | temp, |
| 2600 | /* needs_null_check */ true); |
| 2601 | } else { |
| 2602 | Register out = out_loc.AsRegister<Register>(); |
| 2603 | if (index.IsConstant()) { |
| 2604 | size_t offset = |
| 2605 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2606 | __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker); |
| 2607 | // If read barriers are enabled, emit read barriers other than |
| 2608 | // Baker's using a slow path (and also unpoison the loaded |
| 2609 | // reference, if heap poisoning is enabled). |
| 2610 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 2611 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2612 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2613 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
| 2614 | // If read barriers are enabled, emit read barriers other than |
| 2615 | // Baker's using a slow path (and also unpoison the loaded |
| 2616 | // reference, if heap poisoning is enabled). |
| 2617 | codegen_->MaybeGenerateReadBarrierSlow(instruction, |
| 2618 | out_loc, |
| 2619 | out_loc, |
| 2620 | obj_loc, |
| 2621 | data_offset, |
| 2622 | index); |
| 2623 | } |
| 2624 | } |
| 2625 | break; |
| 2626 | } |
| 2627 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2628 | case Primitive::kPrimLong: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2629 | Register out = out_loc.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2630 | if (index.IsConstant()) { |
| 2631 | size_t offset = |
| 2632 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2633 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2634 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2635 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2636 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2637 | } |
| 2638 | break; |
| 2639 | } |
| 2640 | |
| 2641 | case Primitive::kPrimFloat: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2642 | FRegister out = out_loc.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2643 | if (index.IsConstant()) { |
| 2644 | size_t offset = |
| 2645 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2646 | __ LoadSFromOffset(out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2647 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2648 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_4, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2649 | __ LoadSFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2650 | } |
| 2651 | break; |
| 2652 | } |
| 2653 | |
| 2654 | case Primitive::kPrimDouble: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2655 | FRegister out = out_loc.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2656 | if (index.IsConstant()) { |
| 2657 | size_t offset = |
| 2658 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2659 | __ LoadDFromOffset(out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2660 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2661 | __ ShiftAndAdd(TMP, index.AsRegister<Register>(), obj, TIMES_8, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2662 | __ LoadDFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2663 | } |
| 2664 | break; |
| 2665 | } |
| 2666 | |
| 2667 | case Primitive::kPrimVoid: |
| 2668 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2669 | UNREACHABLE(); |
| 2670 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) { |
| 2674 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2675 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2676 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2677 | } |
| 2678 | |
| 2679 | void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) { |
| 2680 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2681 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2682 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2683 | Register out = locations->Out().AsRegister<Register>(); |
| 2684 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2685 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2686 | // Mask out compression flag from String's array length. |
| 2687 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 2688 | __ Srl(out, out, 1u); |
| 2689 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2690 | } |
| 2691 | |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2692 | Location LocationsBuilderMIPS::RegisterOrZeroConstant(HInstruction* instruction) { |
| 2693 | return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern()) |
| 2694 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 2695 | : Location::RequiresRegister(); |
| 2696 | } |
| 2697 | |
| 2698 | Location LocationsBuilderMIPS::FpuRegisterOrConstantForStore(HInstruction* instruction) { |
| 2699 | // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register. |
| 2700 | // We can store a non-zero float or double constant without first loading it into the FPU, |
| 2701 | // but we should only prefer this if the constant has a single use. |
| 2702 | if (instruction->IsConstant() && |
| 2703 | (instruction->AsConstant()->IsZeroBitPattern() || |
| 2704 | instruction->GetUses().HasExactlyOneElement())) { |
| 2705 | return Location::ConstantLocation(instruction->AsConstant()); |
| 2706 | // Otherwise fall through and require an FPU register for the constant. |
| 2707 | } |
| 2708 | return Location::RequiresFpuRegister(); |
| 2709 | } |
| 2710 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2711 | void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2712 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2713 | |
| 2714 | bool needs_write_barrier = |
| 2715 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 2716 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 2717 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2718 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2719 | instruction, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2720 | may_need_runtime_call_for_type_check ? |
| 2721 | LocationSummary::kCallOnSlowPath : |
| 2722 | LocationSummary::kNoCall); |
| 2723 | |
| 2724 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2725 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2726 | if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
| 2727 | locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2728 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2729 | locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2))); |
| 2730 | } |
| 2731 | if (needs_write_barrier) { |
| 2732 | // Temporary register for the write barrier. |
| 2733 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2734 | } |
| 2735 | } |
| 2736 | |
| 2737 | void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) { |
| 2738 | LocationSummary* locations = instruction->GetLocations(); |
| 2739 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2740 | Location index = locations->InAt(1); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2741 | Location value_location = locations->InAt(2); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2742 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2743 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2744 | bool needs_write_barrier = |
| 2745 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2746 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2747 | Register base_reg = index.IsConstant() ? obj : TMP; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2748 | |
| 2749 | switch (value_type) { |
| 2750 | case Primitive::kPrimBoolean: |
| 2751 | case Primitive::kPrimByte: { |
| 2752 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2753 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2754 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2755 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2756 | __ Addu(base_reg, obj, index.AsRegister<Register>()); |
| 2757 | } |
| 2758 | if (value_location.IsConstant()) { |
| 2759 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2760 | __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker); |
| 2761 | } else { |
| 2762 | Register value = value_location.AsRegister<Register>(); |
| 2763 | __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2764 | } |
| 2765 | break; |
| 2766 | } |
| 2767 | |
| 2768 | case Primitive::kPrimShort: |
| 2769 | case Primitive::kPrimChar: { |
| 2770 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2771 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2772 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2773 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2774 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_2, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2775 | } |
| 2776 | if (value_location.IsConstant()) { |
| 2777 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2778 | __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker); |
| 2779 | } else { |
| 2780 | Register value = value_location.AsRegister<Register>(); |
| 2781 | __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2782 | } |
| 2783 | break; |
| 2784 | } |
| 2785 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2786 | case Primitive::kPrimInt: { |
| 2787 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2788 | if (index.IsConstant()) { |
| 2789 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
| 2790 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2791 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2792 | } |
| 2793 | if (value_location.IsConstant()) { |
| 2794 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2795 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2796 | } else { |
| 2797 | Register value = value_location.AsRegister<Register>(); |
| 2798 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2799 | } |
| 2800 | break; |
| 2801 | } |
| 2802 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2803 | case Primitive::kPrimNot: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2804 | if (value_location.IsConstant()) { |
| 2805 | // Just setting null. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2806 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2807 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2808 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2809 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2810 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2811 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2812 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2813 | DCHECK_EQ(value, 0); |
| 2814 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2815 | DCHECK(!needs_write_barrier); |
| 2816 | DCHECK(!may_need_runtime_call_for_type_check); |
| 2817 | break; |
| 2818 | } |
| 2819 | |
| 2820 | DCHECK(needs_write_barrier); |
| 2821 | Register value = value_location.AsRegister<Register>(); |
| 2822 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 2823 | Register temp2 = TMP; // Doesn't need to survive slow path. |
| 2824 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2825 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2826 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2827 | MipsLabel done; |
| 2828 | SlowPathCodeMIPS* slow_path = nullptr; |
| 2829 | |
| 2830 | if (may_need_runtime_call_for_type_check) { |
| 2831 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathMIPS(instruction); |
| 2832 | codegen_->AddSlowPath(slow_path); |
| 2833 | if (instruction->GetValueCanBeNull()) { |
| 2834 | MipsLabel non_zero; |
| 2835 | __ Bnez(value, &non_zero); |
| 2836 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2837 | if (index.IsConstant()) { |
| 2838 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2839 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2840 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2841 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2842 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2843 | __ B(&done); |
| 2844 | __ Bind(&non_zero); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2845 | } |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2846 | |
| 2847 | // Note that when read barriers are enabled, the type checks |
| 2848 | // are performed without read barriers. This is fine, even in |
| 2849 | // the case where a class object is in the from-space after |
| 2850 | // the flip, as a comparison involving such a type would not |
| 2851 | // produce a false positive; it may of course produce a false |
| 2852 | // negative, in which case we would take the ArraySet slow |
| 2853 | // path. |
| 2854 | |
| 2855 | // /* HeapReference<Class> */ temp1 = obj->klass_ |
| 2856 | __ LoadFromOffset(kLoadWord, temp1, obj, class_offset, null_checker); |
| 2857 | __ MaybeUnpoisonHeapReference(temp1); |
| 2858 | |
| 2859 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 2860 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 2861 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2862 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 2863 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 2864 | // nor `temp2`, as we are comparing two poisoned references. |
| 2865 | |
| 2866 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2867 | MipsLabel do_put; |
| 2868 | __ Beq(temp1, temp2, &do_put); |
| 2869 | // If heap poisoning is enabled, the `temp1` reference has |
| 2870 | // not been unpoisoned yet; unpoison it now. |
| 2871 | __ MaybeUnpoisonHeapReference(temp1); |
| 2872 | |
| 2873 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 2874 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 2875 | // If heap poisoning is enabled, no need to unpoison |
| 2876 | // `temp1`, as we are comparing against null below. |
| 2877 | __ Bnez(temp1, slow_path->GetEntryLabel()); |
| 2878 | __ Bind(&do_put); |
| 2879 | } else { |
| 2880 | __ Bne(temp1, temp2, slow_path->GetEntryLabel()); |
| 2881 | } |
| 2882 | } |
| 2883 | |
| 2884 | Register source = value; |
| 2885 | if (kPoisonHeapReferences) { |
| 2886 | // Note that in the case where `value` is a null reference, |
| 2887 | // we do not enter this block, as a null reference does not |
| 2888 | // need poisoning. |
| 2889 | __ Move(temp1, value); |
| 2890 | __ PoisonHeapReference(temp1); |
| 2891 | source = temp1; |
| 2892 | } |
| 2893 | |
| 2894 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2895 | if (index.IsConstant()) { |
| 2896 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2897 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2898 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 2899 | } |
| 2900 | __ StoreToOffset(kStoreWord, source, base_reg, data_offset); |
| 2901 | |
| 2902 | if (!may_need_runtime_call_for_type_check) { |
| 2903 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2904 | } |
| 2905 | |
| 2906 | codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull()); |
| 2907 | |
| 2908 | if (done.IsLinked()) { |
| 2909 | __ Bind(&done); |
| 2910 | } |
| 2911 | |
| 2912 | if (slow_path != nullptr) { |
| 2913 | __ Bind(slow_path->GetExitLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2914 | } |
| 2915 | break; |
| 2916 | } |
| 2917 | |
| 2918 | case Primitive::kPrimLong: { |
| 2919 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2920 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2921 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2922 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2923 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2924 | } |
| 2925 | if (value_location.IsConstant()) { |
| 2926 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2927 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2928 | } else { |
| 2929 | Register value = value_location.AsRegisterPairLow<Register>(); |
| 2930 | __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2931 | } |
| 2932 | break; |
| 2933 | } |
| 2934 | |
| 2935 | case Primitive::kPrimFloat: { |
| 2936 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2937 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2938 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2939 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2940 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_4, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2941 | } |
| 2942 | if (value_location.IsConstant()) { |
| 2943 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2944 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2945 | } else { |
| 2946 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 2947 | __ StoreSToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2948 | } |
| 2949 | break; |
| 2950 | } |
| 2951 | |
| 2952 | case Primitive::kPrimDouble: { |
| 2953 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2954 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2955 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2956 | } else { |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 2957 | __ ShiftAndAdd(base_reg, index.AsRegister<Register>(), obj, TIMES_8, base_reg); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2958 | } |
| 2959 | if (value_location.IsConstant()) { |
| 2960 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2961 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2962 | } else { |
| 2963 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 2964 | __ StoreDToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2965 | } |
| 2966 | break; |
| 2967 | } |
| 2968 | |
| 2969 | case Primitive::kPrimVoid: |
| 2970 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2971 | UNREACHABLE(); |
| 2972 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2973 | } |
| 2974 | |
| 2975 | void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2976 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2977 | InvokeRuntimeCallingConvention calling_convention; |
| 2978 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2979 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2980 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2981 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2982 | locations->SetInAt(1, Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2983 | } |
| 2984 | |
| 2985 | void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2986 | LocationSummary* locations = instruction->GetLocations(); |
| 2987 | BoundsCheckSlowPathMIPS* slow_path = |
| 2988 | new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS(instruction); |
| 2989 | codegen_->AddSlowPath(slow_path); |
| 2990 | |
| 2991 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 2992 | Register length = locations->InAt(1).AsRegister<Register>(); |
| 2993 | |
| 2994 | // length is limited by the maximum positive signed 32-bit integer. |
| 2995 | // Unsigned comparison of length and index checks for index < 0 |
| 2996 | // and for length <= index simultaneously. |
| 2997 | __ Bgeu(index, length, slow_path->GetEntryLabel()); |
| 2998 | } |
| 2999 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3000 | // Temp is used for read barrier. |
| 3001 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3002 | if (kEmitCompilerReadBarrier && |
| 3003 | (kUseBakerReadBarrier || |
| 3004 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3005 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3006 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3007 | return 1; |
| 3008 | } |
| 3009 | return 0; |
| 3010 | } |
| 3011 | |
| 3012 | // Extra temp is used for read barrier. |
| 3013 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3014 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 3015 | } |
| 3016 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3017 | void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3018 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3019 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 3020 | |
| 3021 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 3022 | switch (type_check_kind) { |
| 3023 | case TypeCheckKind::kExactCheck: |
| 3024 | case TypeCheckKind::kAbstractClassCheck: |
| 3025 | case TypeCheckKind::kClassHierarchyCheck: |
| 3026 | case TypeCheckKind::kArrayObjectCheck: |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3027 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3028 | ? LocationSummary::kCallOnSlowPath |
| 3029 | : LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
| 3030 | break; |
| 3031 | case TypeCheckKind::kArrayCheck: |
| 3032 | case TypeCheckKind::kUnresolvedCheck: |
| 3033 | case TypeCheckKind::kInterfaceCheck: |
| 3034 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3035 | break; |
| 3036 | } |
| 3037 | |
| 3038 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3039 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3040 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3041 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3042 | } |
| 3043 | |
| 3044 | void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3045 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3046 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3047 | Location obj_loc = locations->InAt(0); |
| 3048 | Register obj = obj_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3049 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3050 | Location temp_loc = locations->GetTemp(0); |
| 3051 | Register temp = temp_loc.AsRegister<Register>(); |
| 3052 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 3053 | DCHECK_LE(num_temps, 2u); |
| 3054 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3055 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3056 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3057 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3058 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 3059 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 3060 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 3061 | const uint32_t object_array_data_offset = |
| 3062 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| 3063 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3064 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3065 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 3066 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 3067 | // read barriers is done for performance and code size reasons. |
| 3068 | bool is_type_check_slow_path_fatal = false; |
| 3069 | if (!kEmitCompilerReadBarrier) { |
| 3070 | is_type_check_slow_path_fatal = |
| 3071 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 3072 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3073 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3074 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 3075 | !instruction->CanThrowIntoCatchBlock(); |
| 3076 | } |
| 3077 | SlowPathCodeMIPS* slow_path = |
| 3078 | new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction, |
| 3079 | is_type_check_slow_path_fatal); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3080 | codegen_->AddSlowPath(slow_path); |
| 3081 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3082 | // Avoid this check if we know `obj` is not null. |
| 3083 | if (instruction->MustDoNullCheck()) { |
| 3084 | __ Beqz(obj, &done); |
| 3085 | } |
| 3086 | |
| 3087 | switch (type_check_kind) { |
| 3088 | case TypeCheckKind::kExactCheck: |
| 3089 | case TypeCheckKind::kArrayCheck: { |
| 3090 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3091 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3092 | temp_loc, |
| 3093 | obj_loc, |
| 3094 | class_offset, |
| 3095 | maybe_temp2_loc, |
| 3096 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3097 | // Jump to slow path for throwing the exception or doing a |
| 3098 | // more involved array check. |
| 3099 | __ Bne(temp, cls, slow_path->GetEntryLabel()); |
| 3100 | break; |
| 3101 | } |
| 3102 | |
| 3103 | case TypeCheckKind::kAbstractClassCheck: { |
| 3104 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3105 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3106 | temp_loc, |
| 3107 | obj_loc, |
| 3108 | class_offset, |
| 3109 | maybe_temp2_loc, |
| 3110 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3111 | // If the class is abstract, we eagerly fetch the super class of the |
| 3112 | // object to avoid doing a comparison we know will fail. |
| 3113 | MipsLabel loop; |
| 3114 | __ Bind(&loop); |
| 3115 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3116 | GenerateReferenceLoadOneRegister(instruction, |
| 3117 | temp_loc, |
| 3118 | super_offset, |
| 3119 | maybe_temp2_loc, |
| 3120 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3121 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3122 | // exception. |
| 3123 | __ Beqz(temp, slow_path->GetEntryLabel()); |
| 3124 | // Otherwise, compare the classes. |
| 3125 | __ Bne(temp, cls, &loop); |
| 3126 | break; |
| 3127 | } |
| 3128 | |
| 3129 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3130 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3131 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3132 | temp_loc, |
| 3133 | obj_loc, |
| 3134 | class_offset, |
| 3135 | maybe_temp2_loc, |
| 3136 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3137 | // Walk over the class hierarchy to find a match. |
| 3138 | MipsLabel loop; |
| 3139 | __ Bind(&loop); |
| 3140 | __ Beq(temp, cls, &done); |
| 3141 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3142 | GenerateReferenceLoadOneRegister(instruction, |
| 3143 | temp_loc, |
| 3144 | super_offset, |
| 3145 | maybe_temp2_loc, |
| 3146 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3147 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3148 | // exception. Otherwise, jump to the beginning of the loop. |
| 3149 | __ Bnez(temp, &loop); |
| 3150 | __ B(slow_path->GetEntryLabel()); |
| 3151 | break; |
| 3152 | } |
| 3153 | |
| 3154 | case TypeCheckKind::kArrayObjectCheck: { |
| 3155 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3156 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3157 | temp_loc, |
| 3158 | obj_loc, |
| 3159 | class_offset, |
| 3160 | maybe_temp2_loc, |
| 3161 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3162 | // Do an exact check. |
| 3163 | __ Beq(temp, cls, &done); |
| 3164 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 3165 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3166 | GenerateReferenceLoadOneRegister(instruction, |
| 3167 | temp_loc, |
| 3168 | component_offset, |
| 3169 | maybe_temp2_loc, |
| 3170 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3171 | // If the component type is null, jump to the slow path to throw the exception. |
| 3172 | __ Beqz(temp, slow_path->GetEntryLabel()); |
| 3173 | // Otherwise, the object is indeed an array, further check that this component |
| 3174 | // type is not a primitive type. |
| 3175 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 3176 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3177 | __ Bnez(temp, slow_path->GetEntryLabel()); |
| 3178 | break; |
| 3179 | } |
| 3180 | |
| 3181 | case TypeCheckKind::kUnresolvedCheck: |
| 3182 | // We always go into the type check slow path for the unresolved check case. |
| 3183 | // We cannot directly call the CheckCast runtime entry point |
| 3184 | // without resorting to a type checking slow path here (i.e. by |
| 3185 | // calling InvokeRuntime directly), as it would require to |
| 3186 | // assign fixed registers for the inputs of this HInstanceOf |
| 3187 | // instruction (following the runtime calling convention), which |
| 3188 | // might be cluttered by the potential first read barrier |
| 3189 | // emission at the beginning of this method. |
| 3190 | __ B(slow_path->GetEntryLabel()); |
| 3191 | break; |
| 3192 | |
| 3193 | case TypeCheckKind::kInterfaceCheck: { |
| 3194 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 3195 | // positives by doing this. |
| 3196 | // /* HeapReference<Class> */ temp = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3197 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3198 | temp_loc, |
| 3199 | obj_loc, |
| 3200 | class_offset, |
| 3201 | maybe_temp2_loc, |
| 3202 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3203 | // /* HeapReference<Class> */ temp = temp->iftable_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 3204 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3205 | temp_loc, |
| 3206 | temp_loc, |
| 3207 | iftable_offset, |
| 3208 | maybe_temp2_loc, |
| 3209 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 3210 | // Iftable is never null. |
| 3211 | __ Lw(TMP, temp, array_length_offset); |
| 3212 | // Loop through the iftable and check if any class matches. |
| 3213 | MipsLabel loop; |
| 3214 | __ Bind(&loop); |
| 3215 | __ Addiu(temp, temp, 2 * kHeapReferenceSize); // Possibly in delay slot on R2. |
| 3216 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 3217 | __ Lw(AT, temp, object_array_data_offset - 2 * kHeapReferenceSize); |
| 3218 | __ MaybeUnpoisonHeapReference(AT); |
| 3219 | // Go to next interface. |
| 3220 | __ Addiu(TMP, TMP, -2); |
| 3221 | // Compare the classes and continue the loop if they do not match. |
| 3222 | __ Bne(AT, cls, &loop); |
| 3223 | break; |
| 3224 | } |
| 3225 | } |
| 3226 | |
| 3227 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3228 | __ Bind(slow_path->GetExitLabel()); |
| 3229 | } |
| 3230 | |
| 3231 | void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 3232 | LocationSummary* locations = |
| 3233 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 3234 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3235 | if (check->HasUses()) { |
| 3236 | locations->SetOut(Location::SameAsFirstInput()); |
| 3237 | } |
| 3238 | } |
| 3239 | |
| 3240 | void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 3241 | // We assume the class is not null. |
| 3242 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS( |
| 3243 | check->GetLoadClass(), |
| 3244 | check, |
| 3245 | check->GetDexPc(), |
| 3246 | true); |
| 3247 | codegen_->AddSlowPath(slow_path); |
| 3248 | GenerateClassInitializationCheck(slow_path, |
| 3249 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
| 3250 | } |
| 3251 | |
| 3252 | void LocationsBuilderMIPS::VisitCompare(HCompare* compare) { |
| 3253 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 3254 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3255 | LocationSummary* locations = |
| 3256 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3257 | |
| 3258 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3259 | case Primitive::kPrimBoolean: |
| 3260 | case Primitive::kPrimByte: |
| 3261 | case Primitive::kPrimShort: |
| 3262 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3263 | case Primitive::kPrimInt: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 3264 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3265 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3266 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3267 | break; |
| 3268 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3269 | case Primitive::kPrimLong: |
| 3270 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3271 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3272 | // Output overlaps because it is written before doing the low comparison. |
| 3273 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3274 | break; |
| 3275 | |
| 3276 | case Primitive::kPrimFloat: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3277 | case Primitive::kPrimDouble: |
| 3278 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3279 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3280 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3281 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3282 | |
| 3283 | default: |
| 3284 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3285 | } |
| 3286 | } |
| 3287 | |
| 3288 | void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) { |
| 3289 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3290 | Register res = locations->Out().AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3291 | Primitive::Type in_type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3292 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3293 | |
| 3294 | // 0 if: left == right |
| 3295 | // 1 if: left > right |
| 3296 | // -1 if: left < right |
| 3297 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3298 | case Primitive::kPrimBoolean: |
| 3299 | case Primitive::kPrimByte: |
| 3300 | case Primitive::kPrimShort: |
| 3301 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3302 | case Primitive::kPrimInt: { |
| 3303 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 3304 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 3305 | __ Slt(TMP, lhs, rhs); |
| 3306 | __ Slt(res, rhs, lhs); |
| 3307 | __ Subu(res, res, TMP); |
| 3308 | break; |
| 3309 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3310 | case Primitive::kPrimLong: { |
| 3311 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3312 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3313 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3314 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 3315 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 3316 | // TODO: more efficient (direct) comparison with a constant. |
| 3317 | __ Slt(TMP, lhs_high, rhs_high); |
| 3318 | __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt. |
| 3319 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 3320 | __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal. |
| 3321 | __ Sltu(TMP, lhs_low, rhs_low); |
| 3322 | __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt. |
| 3323 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 3324 | __ Bind(&done); |
| 3325 | break; |
| 3326 | } |
| 3327 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3328 | case Primitive::kPrimFloat: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3329 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3330 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3331 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3332 | MipsLabel done; |
| 3333 | if (isR6) { |
| 3334 | __ CmpEqS(FTMP, lhs, rhs); |
| 3335 | __ LoadConst32(res, 0); |
| 3336 | __ Bc1nez(FTMP, &done); |
| 3337 | if (gt_bias) { |
| 3338 | __ CmpLtS(FTMP, lhs, rhs); |
| 3339 | __ LoadConst32(res, -1); |
| 3340 | __ Bc1nez(FTMP, &done); |
| 3341 | __ LoadConst32(res, 1); |
| 3342 | } else { |
| 3343 | __ CmpLtS(FTMP, rhs, lhs); |
| 3344 | __ LoadConst32(res, 1); |
| 3345 | __ Bc1nez(FTMP, &done); |
| 3346 | __ LoadConst32(res, -1); |
| 3347 | } |
| 3348 | } else { |
| 3349 | if (gt_bias) { |
| 3350 | __ ColtS(0, lhs, rhs); |
| 3351 | __ LoadConst32(res, -1); |
| 3352 | __ Bc1t(0, &done); |
| 3353 | __ CeqS(0, lhs, rhs); |
| 3354 | __ LoadConst32(res, 1); |
| 3355 | __ Movt(res, ZERO, 0); |
| 3356 | } else { |
| 3357 | __ ColtS(0, rhs, lhs); |
| 3358 | __ LoadConst32(res, 1); |
| 3359 | __ Bc1t(0, &done); |
| 3360 | __ CeqS(0, lhs, rhs); |
| 3361 | __ LoadConst32(res, -1); |
| 3362 | __ Movt(res, ZERO, 0); |
| 3363 | } |
| 3364 | } |
| 3365 | __ Bind(&done); |
| 3366 | break; |
| 3367 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3368 | case Primitive::kPrimDouble: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 3369 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3370 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3371 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3372 | MipsLabel done; |
| 3373 | if (isR6) { |
| 3374 | __ CmpEqD(FTMP, lhs, rhs); |
| 3375 | __ LoadConst32(res, 0); |
| 3376 | __ Bc1nez(FTMP, &done); |
| 3377 | if (gt_bias) { |
| 3378 | __ CmpLtD(FTMP, lhs, rhs); |
| 3379 | __ LoadConst32(res, -1); |
| 3380 | __ Bc1nez(FTMP, &done); |
| 3381 | __ LoadConst32(res, 1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3382 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3383 | __ CmpLtD(FTMP, rhs, lhs); |
| 3384 | __ LoadConst32(res, 1); |
| 3385 | __ Bc1nez(FTMP, &done); |
| 3386 | __ LoadConst32(res, -1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3387 | } |
| 3388 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3389 | if (gt_bias) { |
| 3390 | __ ColtD(0, lhs, rhs); |
| 3391 | __ LoadConst32(res, -1); |
| 3392 | __ Bc1t(0, &done); |
| 3393 | __ CeqD(0, lhs, rhs); |
| 3394 | __ LoadConst32(res, 1); |
| 3395 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3396 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3397 | __ ColtD(0, rhs, lhs); |
| 3398 | __ LoadConst32(res, 1); |
| 3399 | __ Bc1t(0, &done); |
| 3400 | __ CeqD(0, lhs, rhs); |
| 3401 | __ LoadConst32(res, -1); |
| 3402 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3403 | } |
| 3404 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3405 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3406 | break; |
| 3407 | } |
| 3408 | |
| 3409 | default: |
| 3410 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3411 | } |
| 3412 | } |
| 3413 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3414 | void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3415 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3416 | switch (instruction->InputAt(0)->GetType()) { |
| 3417 | default: |
| 3418 | case Primitive::kPrimLong: |
| 3419 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3420 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3421 | break; |
| 3422 | |
| 3423 | case Primitive::kPrimFloat: |
| 3424 | case Primitive::kPrimDouble: |
| 3425 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3426 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3427 | break; |
| 3428 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3429 | if (!instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3430 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3431 | } |
| 3432 | } |
| 3433 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3434 | void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3435 | if (instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3436 | return; |
| 3437 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3438 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3439 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3440 | LocationSummary* locations = instruction->GetLocations(); |
| 3441 | Register dst = locations->Out().AsRegister<Register>(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3442 | MipsLabel true_label; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3443 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3444 | switch (type) { |
| 3445 | default: |
| 3446 | // Integer case. |
| 3447 | GenerateIntCompare(instruction->GetCondition(), locations); |
| 3448 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3449 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3450 | case Primitive::kPrimLong: |
| 3451 | // TODO: don't use branches. |
| 3452 | GenerateLongCompareAndBranch(instruction->GetCondition(), locations, &true_label); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3453 | break; |
| 3454 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3455 | case Primitive::kPrimFloat: |
| 3456 | case Primitive::kPrimDouble: |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 3457 | GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations); |
| 3458 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3459 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3460 | |
| 3461 | // Convert the branches into the result. |
| 3462 | MipsLabel done; |
| 3463 | |
| 3464 | // False case: result = 0. |
| 3465 | __ LoadConst32(dst, 0); |
| 3466 | __ B(&done); |
| 3467 | |
| 3468 | // True case: result = 1. |
| 3469 | __ Bind(&true_label); |
| 3470 | __ LoadConst32(dst, 1); |
| 3471 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3472 | } |
| 3473 | |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3474 | void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3475 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3476 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 3477 | |
| 3478 | LocationSummary* locations = instruction->GetLocations(); |
| 3479 | Location second = locations->InAt(1); |
| 3480 | DCHECK(second.IsConstant()); |
| 3481 | |
| 3482 | Register out = locations->Out().AsRegister<Register>(); |
| 3483 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3484 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3485 | DCHECK(imm == 1 || imm == -1); |
| 3486 | |
| 3487 | if (instruction->IsRem()) { |
| 3488 | __ Move(out, ZERO); |
| 3489 | } else { |
| 3490 | if (imm == -1) { |
| 3491 | __ Subu(out, ZERO, dividend); |
| 3492 | } else if (out != dividend) { |
| 3493 | __ Move(out, dividend); |
| 3494 | } |
| 3495 | } |
| 3496 | } |
| 3497 | |
| 3498 | void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3499 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3500 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 3501 | |
| 3502 | LocationSummary* locations = instruction->GetLocations(); |
| 3503 | Location second = locations->InAt(1); |
| 3504 | DCHECK(second.IsConstant()); |
| 3505 | |
| 3506 | Register out = locations->Out().AsRegister<Register>(); |
| 3507 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3508 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3509 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3510 | int ctz_imm = CTZ(abs_imm); |
| 3511 | |
| 3512 | if (instruction->IsDiv()) { |
| 3513 | if (ctz_imm == 1) { |
| 3514 | // Fast path for division by +/-2, which is very common. |
| 3515 | __ Srl(TMP, dividend, 31); |
| 3516 | } else { |
| 3517 | __ Sra(TMP, dividend, 31); |
| 3518 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3519 | } |
| 3520 | __ Addu(out, dividend, TMP); |
| 3521 | __ Sra(out, out, ctz_imm); |
| 3522 | if (imm < 0) { |
| 3523 | __ Subu(out, ZERO, out); |
| 3524 | } |
| 3525 | } else { |
| 3526 | if (ctz_imm == 1) { |
| 3527 | // Fast path for modulo +/-2, which is very common. |
| 3528 | __ Sra(TMP, dividend, 31); |
| 3529 | __ Subu(out, dividend, TMP); |
| 3530 | __ Andi(out, out, 1); |
| 3531 | __ Addu(out, out, TMP); |
| 3532 | } else { |
| 3533 | __ Sra(TMP, dividend, 31); |
| 3534 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 3535 | __ Addu(out, dividend, TMP); |
| 3536 | if (IsUint<16>(abs_imm - 1)) { |
| 3537 | __ Andi(out, out, abs_imm - 1); |
| 3538 | } else { |
| 3539 | __ Sll(out, out, 32 - ctz_imm); |
| 3540 | __ Srl(out, out, 32 - ctz_imm); |
| 3541 | } |
| 3542 | __ Subu(out, out, TMP); |
| 3543 | } |
| 3544 | } |
| 3545 | } |
| 3546 | |
| 3547 | void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3548 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3549 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 3550 | |
| 3551 | LocationSummary* locations = instruction->GetLocations(); |
| 3552 | Location second = locations->InAt(1); |
| 3553 | DCHECK(second.IsConstant()); |
| 3554 | |
| 3555 | Register out = locations->Out().AsRegister<Register>(); |
| 3556 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3557 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3558 | |
| 3559 | int64_t magic; |
| 3560 | int shift; |
| 3561 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3562 | |
| 3563 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3564 | |
| 3565 | __ LoadConst32(TMP, magic); |
| 3566 | if (isR6) { |
| 3567 | __ MuhR6(TMP, dividend, TMP); |
| 3568 | } else { |
| 3569 | __ MultR2(dividend, TMP); |
| 3570 | __ Mfhi(TMP); |
| 3571 | } |
| 3572 | if (imm > 0 && magic < 0) { |
| 3573 | __ Addu(TMP, TMP, dividend); |
| 3574 | } else if (imm < 0 && magic > 0) { |
| 3575 | __ Subu(TMP, TMP, dividend); |
| 3576 | } |
| 3577 | |
| 3578 | if (shift != 0) { |
| 3579 | __ Sra(TMP, TMP, shift); |
| 3580 | } |
| 3581 | |
| 3582 | if (instruction->IsDiv()) { |
| 3583 | __ Sra(out, TMP, 31); |
| 3584 | __ Subu(out, TMP, out); |
| 3585 | } else { |
| 3586 | __ Sra(AT, TMP, 31); |
| 3587 | __ Subu(AT, TMP, AT); |
| 3588 | __ LoadConst32(TMP, imm); |
| 3589 | if (isR6) { |
| 3590 | __ MulR6(TMP, AT, TMP); |
| 3591 | } else { |
| 3592 | __ MulR2(TMP, AT, TMP); |
| 3593 | } |
| 3594 | __ Subu(out, dividend, TMP); |
| 3595 | } |
| 3596 | } |
| 3597 | |
| 3598 | void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3599 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3600 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 3601 | |
| 3602 | LocationSummary* locations = instruction->GetLocations(); |
| 3603 | Register out = locations->Out().AsRegister<Register>(); |
| 3604 | Location second = locations->InAt(1); |
| 3605 | |
| 3606 | if (second.IsConstant()) { |
| 3607 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3608 | if (imm == 0) { |
| 3609 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3610 | } else if (imm == 1 || imm == -1) { |
| 3611 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3612 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3613 | DivRemByPowerOfTwo(instruction); |
| 3614 | } else { |
| 3615 | DCHECK(imm <= -2 || imm >= 2); |
| 3616 | GenerateDivRemWithAnyConstant(instruction); |
| 3617 | } |
| 3618 | } else { |
| 3619 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3620 | Register divisor = second.AsRegister<Register>(); |
| 3621 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3622 | if (instruction->IsDiv()) { |
| 3623 | if (isR6) { |
| 3624 | __ DivR6(out, dividend, divisor); |
| 3625 | } else { |
| 3626 | __ DivR2(out, dividend, divisor); |
| 3627 | } |
| 3628 | } else { |
| 3629 | if (isR6) { |
| 3630 | __ ModR6(out, dividend, divisor); |
| 3631 | } else { |
| 3632 | __ ModR2(out, dividend, divisor); |
| 3633 | } |
| 3634 | } |
| 3635 | } |
| 3636 | } |
| 3637 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3638 | void LocationsBuilderMIPS::VisitDiv(HDiv* div) { |
| 3639 | Primitive::Type type = div->GetResultType(); |
| 3640 | LocationSummary::CallKind call_kind = (type == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3641 | ? LocationSummary::kCallOnMainOnly |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3642 | : LocationSummary::kNoCall; |
| 3643 | |
| 3644 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3645 | |
| 3646 | switch (type) { |
| 3647 | case Primitive::kPrimInt: |
| 3648 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3649 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3650 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3651 | break; |
| 3652 | |
| 3653 | case Primitive::kPrimLong: { |
| 3654 | InvokeRuntimeCallingConvention calling_convention; |
| 3655 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3656 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3657 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3658 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3659 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 3660 | break; |
| 3661 | } |
| 3662 | |
| 3663 | case Primitive::kPrimFloat: |
| 3664 | case Primitive::kPrimDouble: |
| 3665 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3666 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3667 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3668 | break; |
| 3669 | |
| 3670 | default: |
| 3671 | LOG(FATAL) << "Unexpected div type " << type; |
| 3672 | } |
| 3673 | } |
| 3674 | |
| 3675 | void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) { |
| 3676 | Primitive::Type type = instruction->GetType(); |
| 3677 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3678 | |
| 3679 | switch (type) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 3680 | case Primitive::kPrimInt: |
| 3681 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3682 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3683 | case Primitive::kPrimLong: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 3684 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3685 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| 3686 | break; |
| 3687 | } |
| 3688 | case Primitive::kPrimFloat: |
| 3689 | case Primitive::kPrimDouble: { |
| 3690 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 3691 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3692 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3693 | if (type == Primitive::kPrimFloat) { |
| 3694 | __ DivS(dst, lhs, rhs); |
| 3695 | } else { |
| 3696 | __ DivD(dst, lhs, rhs); |
| 3697 | } |
| 3698 | break; |
| 3699 | } |
| 3700 | default: |
| 3701 | LOG(FATAL) << "Unexpected div type " << type; |
| 3702 | } |
| 3703 | } |
| 3704 | |
| 3705 | void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3706 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3707 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3708 | } |
| 3709 | |
| 3710 | void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3711 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS(instruction); |
| 3712 | codegen_->AddSlowPath(slow_path); |
| 3713 | Location value = instruction->GetLocations()->InAt(0); |
| 3714 | Primitive::Type type = instruction->GetType(); |
| 3715 | |
| 3716 | switch (type) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3717 | case Primitive::kPrimBoolean: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3718 | case Primitive::kPrimByte: |
| 3719 | case Primitive::kPrimChar: |
| 3720 | case Primitive::kPrimShort: |
| 3721 | case Primitive::kPrimInt: { |
| 3722 | if (value.IsConstant()) { |
| 3723 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3724 | __ B(slow_path->GetEntryLabel()); |
| 3725 | } else { |
| 3726 | // A division by a non-null constant is valid. We don't need to perform |
| 3727 | // any check, so simply fall through. |
| 3728 | } |
| 3729 | } else { |
| 3730 | DCHECK(value.IsRegister()) << value; |
| 3731 | __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 3732 | } |
| 3733 | break; |
| 3734 | } |
| 3735 | case Primitive::kPrimLong: { |
| 3736 | if (value.IsConstant()) { |
| 3737 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3738 | __ B(slow_path->GetEntryLabel()); |
| 3739 | } else { |
| 3740 | // A division by a non-null constant is valid. We don't need to perform |
| 3741 | // any check, so simply fall through. |
| 3742 | } |
| 3743 | } else { |
| 3744 | DCHECK(value.IsRegisterPair()) << value; |
| 3745 | __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>()); |
| 3746 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 3747 | } |
| 3748 | break; |
| 3749 | } |
| 3750 | default: |
| 3751 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
| 3752 | } |
| 3753 | } |
| 3754 | |
| 3755 | void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3756 | LocationSummary* locations = |
| 3757 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3758 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3759 | } |
| 3760 | |
| 3761 | void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 3762 | // Will be generated at use site. |
| 3763 | } |
| 3764 | |
| 3765 | void LocationsBuilderMIPS::VisitExit(HExit* exit) { |
| 3766 | exit->SetLocations(nullptr); |
| 3767 | } |
| 3768 | |
| 3769 | void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 3770 | } |
| 3771 | |
| 3772 | void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) { |
| 3773 | LocationSummary* locations = |
| 3774 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3775 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3776 | } |
| 3777 | |
| 3778 | void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 3779 | // Will be generated at use site. |
| 3780 | } |
| 3781 | |
| 3782 | void LocationsBuilderMIPS::VisitGoto(HGoto* got) { |
| 3783 | got->SetLocations(nullptr); |
| 3784 | } |
| 3785 | |
| 3786 | void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| 3787 | DCHECK(!successor->IsExitBlock()); |
| 3788 | HBasicBlock* block = got->GetBlock(); |
| 3789 | HInstruction* previous = got->GetPrevious(); |
| 3790 | HLoopInformation* info = block->GetLoopInformation(); |
| 3791 | |
| 3792 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| 3793 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 3794 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3795 | return; |
| 3796 | } |
| 3797 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3798 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 3799 | } |
| 3800 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 3801 | __ B(codegen_->GetLabelOf(successor)); |
| 3802 | } |
| 3803 | } |
| 3804 | |
| 3805 | void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) { |
| 3806 | HandleGoto(got, got->GetSuccessor()); |
| 3807 | } |
| 3808 | |
| 3809 | void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3810 | try_boundary->SetLocations(nullptr); |
| 3811 | } |
| 3812 | |
| 3813 | void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3814 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3815 | if (!successor->IsExitBlock()) { |
| 3816 | HandleGoto(try_boundary, successor); |
| 3817 | } |
| 3818 | } |
| 3819 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3820 | void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond, |
| 3821 | LocationSummary* locations) { |
| 3822 | Register dst = locations->Out().AsRegister<Register>(); |
| 3823 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 3824 | Location rhs_location = locations->InAt(1); |
| 3825 | Register rhs_reg = ZERO; |
| 3826 | int64_t rhs_imm = 0; |
| 3827 | bool use_imm = rhs_location.IsConstant(); |
| 3828 | if (use_imm) { |
| 3829 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3830 | } else { |
| 3831 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 3832 | } |
| 3833 | |
| 3834 | switch (cond) { |
| 3835 | case kCondEQ: |
| 3836 | case kCondNE: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 3837 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 3838 | if (rhs_imm == 0) { |
| 3839 | if (cond == kCondEQ) { |
| 3840 | __ Sltiu(dst, lhs, 1); |
| 3841 | } else { |
| 3842 | __ Sltu(dst, ZERO, lhs); |
| 3843 | } |
| 3844 | } else { |
| 3845 | __ Addiu(dst, lhs, -rhs_imm); |
| 3846 | if (cond == kCondEQ) { |
| 3847 | __ Sltiu(dst, dst, 1); |
| 3848 | } else { |
| 3849 | __ Sltu(dst, ZERO, dst); |
| 3850 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3851 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3852 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 3853 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 3854 | __ Xori(dst, lhs, rhs_imm); |
| 3855 | } else { |
| 3856 | if (use_imm) { |
| 3857 | rhs_reg = TMP; |
| 3858 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3859 | } |
| 3860 | __ Xor(dst, lhs, rhs_reg); |
| 3861 | } |
| 3862 | if (cond == kCondEQ) { |
| 3863 | __ Sltiu(dst, dst, 1); |
| 3864 | } else { |
| 3865 | __ Sltu(dst, ZERO, dst); |
| 3866 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3867 | } |
| 3868 | break; |
| 3869 | |
| 3870 | case kCondLT: |
| 3871 | case kCondGE: |
| 3872 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3873 | __ Slti(dst, lhs, rhs_imm); |
| 3874 | } else { |
| 3875 | if (use_imm) { |
| 3876 | rhs_reg = TMP; |
| 3877 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3878 | } |
| 3879 | __ Slt(dst, lhs, rhs_reg); |
| 3880 | } |
| 3881 | if (cond == kCondGE) { |
| 3882 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 3883 | // only the slt instruction but no sge. |
| 3884 | __ Xori(dst, dst, 1); |
| 3885 | } |
| 3886 | break; |
| 3887 | |
| 3888 | case kCondLE: |
| 3889 | case kCondGT: |
| 3890 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 3891 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3892 | __ Slti(dst, lhs, rhs_imm + 1); |
| 3893 | if (cond == kCondGT) { |
| 3894 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 3895 | // only the slti instruction but no sgti. |
| 3896 | __ Xori(dst, dst, 1); |
| 3897 | } |
| 3898 | } else { |
| 3899 | if (use_imm) { |
| 3900 | rhs_reg = TMP; |
| 3901 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3902 | } |
| 3903 | __ Slt(dst, rhs_reg, lhs); |
| 3904 | if (cond == kCondLE) { |
| 3905 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 3906 | // only the slt instruction but no sle. |
| 3907 | __ Xori(dst, dst, 1); |
| 3908 | } |
| 3909 | } |
| 3910 | break; |
| 3911 | |
| 3912 | case kCondB: |
| 3913 | case kCondAE: |
| 3914 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3915 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3916 | // the comparison and thus lets us compare directly with |
| 3917 | // unsigned values in the ranges [0, 0x7fff] and |
| 3918 | // [0xffff8000, 0xffffffff]. |
| 3919 | __ Sltiu(dst, lhs, rhs_imm); |
| 3920 | } else { |
| 3921 | if (use_imm) { |
| 3922 | rhs_reg = TMP; |
| 3923 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3924 | } |
| 3925 | __ Sltu(dst, lhs, rhs_reg); |
| 3926 | } |
| 3927 | if (cond == kCondAE) { |
| 3928 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 3929 | // only the sltu instruction but no sgeu. |
| 3930 | __ Xori(dst, dst, 1); |
| 3931 | } |
| 3932 | break; |
| 3933 | |
| 3934 | case kCondBE: |
| 3935 | case kCondA: |
| 3936 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 3937 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3938 | // Note that this only works if rhs + 1 does not overflow |
| 3939 | // to 0, hence the check above. |
| 3940 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3941 | // the comparison and thus lets us compare directly with |
| 3942 | // unsigned values in the ranges [0, 0x7fff] and |
| 3943 | // [0xffff8000, 0xffffffff]. |
| 3944 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 3945 | if (cond == kCondA) { |
| 3946 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 3947 | // only the sltiu instruction but no sgtiu. |
| 3948 | __ Xori(dst, dst, 1); |
| 3949 | } |
| 3950 | } else { |
| 3951 | if (use_imm) { |
| 3952 | rhs_reg = TMP; |
| 3953 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3954 | } |
| 3955 | __ Sltu(dst, rhs_reg, lhs); |
| 3956 | if (cond == kCondBE) { |
| 3957 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 3958 | // only the sltu instruction but no sleu. |
| 3959 | __ Xori(dst, dst, 1); |
| 3960 | } |
| 3961 | } |
| 3962 | break; |
| 3963 | } |
| 3964 | } |
| 3965 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 3966 | bool InstructionCodeGeneratorMIPS::MaterializeIntCompare(IfCondition cond, |
| 3967 | LocationSummary* input_locations, |
| 3968 | Register dst) { |
| 3969 | Register lhs = input_locations->InAt(0).AsRegister<Register>(); |
| 3970 | Location rhs_location = input_locations->InAt(1); |
| 3971 | Register rhs_reg = ZERO; |
| 3972 | int64_t rhs_imm = 0; |
| 3973 | bool use_imm = rhs_location.IsConstant(); |
| 3974 | if (use_imm) { |
| 3975 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3976 | } else { |
| 3977 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 3978 | } |
| 3979 | |
| 3980 | switch (cond) { |
| 3981 | case kCondEQ: |
| 3982 | case kCondNE: |
| 3983 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 3984 | __ Addiu(dst, lhs, -rhs_imm); |
| 3985 | } else if (use_imm && IsUint<16>(rhs_imm)) { |
| 3986 | __ Xori(dst, lhs, rhs_imm); |
| 3987 | } else { |
| 3988 | if (use_imm) { |
| 3989 | rhs_reg = TMP; |
| 3990 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3991 | } |
| 3992 | __ Xor(dst, lhs, rhs_reg); |
| 3993 | } |
| 3994 | return (cond == kCondEQ); |
| 3995 | |
| 3996 | case kCondLT: |
| 3997 | case kCondGE: |
| 3998 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3999 | __ Slti(dst, lhs, rhs_imm); |
| 4000 | } else { |
| 4001 | if (use_imm) { |
| 4002 | rhs_reg = TMP; |
| 4003 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4004 | } |
| 4005 | __ Slt(dst, lhs, rhs_reg); |
| 4006 | } |
| 4007 | return (cond == kCondGE); |
| 4008 | |
| 4009 | case kCondLE: |
| 4010 | case kCondGT: |
| 4011 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 4012 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4013 | __ Slti(dst, lhs, rhs_imm + 1); |
| 4014 | return (cond == kCondGT); |
| 4015 | } else { |
| 4016 | if (use_imm) { |
| 4017 | rhs_reg = TMP; |
| 4018 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4019 | } |
| 4020 | __ Slt(dst, rhs_reg, lhs); |
| 4021 | return (cond == kCondLE); |
| 4022 | } |
| 4023 | |
| 4024 | case kCondB: |
| 4025 | case kCondAE: |
| 4026 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 4027 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4028 | // the comparison and thus lets us compare directly with |
| 4029 | // unsigned values in the ranges [0, 0x7fff] and |
| 4030 | // [0xffff8000, 0xffffffff]. |
| 4031 | __ Sltiu(dst, lhs, rhs_imm); |
| 4032 | } else { |
| 4033 | if (use_imm) { |
| 4034 | rhs_reg = TMP; |
| 4035 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4036 | } |
| 4037 | __ Sltu(dst, lhs, rhs_reg); |
| 4038 | } |
| 4039 | return (cond == kCondAE); |
| 4040 | |
| 4041 | case kCondBE: |
| 4042 | case kCondA: |
| 4043 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4044 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4045 | // Note that this only works if rhs + 1 does not overflow |
| 4046 | // to 0, hence the check above. |
| 4047 | // Sltiu sign-extends its 16-bit immediate operand before |
| 4048 | // the comparison and thus lets us compare directly with |
| 4049 | // unsigned values in the ranges [0, 0x7fff] and |
| 4050 | // [0xffff8000, 0xffffffff]. |
| 4051 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 4052 | return (cond == kCondA); |
| 4053 | } else { |
| 4054 | if (use_imm) { |
| 4055 | rhs_reg = TMP; |
| 4056 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4057 | } |
| 4058 | __ Sltu(dst, rhs_reg, lhs); |
| 4059 | return (cond == kCondBE); |
| 4060 | } |
| 4061 | } |
| 4062 | } |
| 4063 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4064 | void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond, |
| 4065 | LocationSummary* locations, |
| 4066 | MipsLabel* label) { |
| 4067 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 4068 | Location rhs_location = locations->InAt(1); |
| 4069 | Register rhs_reg = ZERO; |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4070 | int64_t rhs_imm = 0; |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4071 | bool use_imm = rhs_location.IsConstant(); |
| 4072 | if (use_imm) { |
| 4073 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 4074 | } else { |
| 4075 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 4076 | } |
| 4077 | |
| 4078 | if (use_imm && rhs_imm == 0) { |
| 4079 | switch (cond) { |
| 4080 | case kCondEQ: |
| 4081 | case kCondBE: // <= 0 if zero |
| 4082 | __ Beqz(lhs, label); |
| 4083 | break; |
| 4084 | case kCondNE: |
| 4085 | case kCondA: // > 0 if non-zero |
| 4086 | __ Bnez(lhs, label); |
| 4087 | break; |
| 4088 | case kCondLT: |
| 4089 | __ Bltz(lhs, label); |
| 4090 | break; |
| 4091 | case kCondGE: |
| 4092 | __ Bgez(lhs, label); |
| 4093 | break; |
| 4094 | case kCondLE: |
| 4095 | __ Blez(lhs, label); |
| 4096 | break; |
| 4097 | case kCondGT: |
| 4098 | __ Bgtz(lhs, label); |
| 4099 | break; |
| 4100 | case kCondB: // always false |
| 4101 | break; |
| 4102 | case kCondAE: // always true |
| 4103 | __ B(label); |
| 4104 | break; |
| 4105 | } |
| 4106 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 4107 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4108 | if (isR6 || !use_imm) { |
| 4109 | if (use_imm) { |
| 4110 | rhs_reg = TMP; |
| 4111 | __ LoadConst32(rhs_reg, rhs_imm); |
| 4112 | } |
| 4113 | switch (cond) { |
| 4114 | case kCondEQ: |
| 4115 | __ Beq(lhs, rhs_reg, label); |
| 4116 | break; |
| 4117 | case kCondNE: |
| 4118 | __ Bne(lhs, rhs_reg, label); |
| 4119 | break; |
| 4120 | case kCondLT: |
| 4121 | __ Blt(lhs, rhs_reg, label); |
| 4122 | break; |
| 4123 | case kCondGE: |
| 4124 | __ Bge(lhs, rhs_reg, label); |
| 4125 | break; |
| 4126 | case kCondLE: |
| 4127 | __ Bge(rhs_reg, lhs, label); |
| 4128 | break; |
| 4129 | case kCondGT: |
| 4130 | __ Blt(rhs_reg, lhs, label); |
| 4131 | break; |
| 4132 | case kCondB: |
| 4133 | __ Bltu(lhs, rhs_reg, label); |
| 4134 | break; |
| 4135 | case kCondAE: |
| 4136 | __ Bgeu(lhs, rhs_reg, label); |
| 4137 | break; |
| 4138 | case kCondBE: |
| 4139 | __ Bgeu(rhs_reg, lhs, label); |
| 4140 | break; |
| 4141 | case kCondA: |
| 4142 | __ Bltu(rhs_reg, lhs, label); |
| 4143 | break; |
| 4144 | } |
| 4145 | } else { |
| 4146 | // Special cases for more efficient comparison with constants on R2. |
| 4147 | switch (cond) { |
| 4148 | case kCondEQ: |
| 4149 | __ LoadConst32(TMP, rhs_imm); |
| 4150 | __ Beq(lhs, TMP, label); |
| 4151 | break; |
| 4152 | case kCondNE: |
| 4153 | __ LoadConst32(TMP, rhs_imm); |
| 4154 | __ Bne(lhs, TMP, label); |
| 4155 | break; |
| 4156 | case kCondLT: |
| 4157 | if (IsInt<16>(rhs_imm)) { |
| 4158 | __ Slti(TMP, lhs, rhs_imm); |
| 4159 | __ Bnez(TMP, label); |
| 4160 | } else { |
| 4161 | __ LoadConst32(TMP, rhs_imm); |
| 4162 | __ Blt(lhs, TMP, label); |
| 4163 | } |
| 4164 | break; |
| 4165 | case kCondGE: |
| 4166 | if (IsInt<16>(rhs_imm)) { |
| 4167 | __ Slti(TMP, lhs, rhs_imm); |
| 4168 | __ Beqz(TMP, label); |
| 4169 | } else { |
| 4170 | __ LoadConst32(TMP, rhs_imm); |
| 4171 | __ Bge(lhs, TMP, label); |
| 4172 | } |
| 4173 | break; |
| 4174 | case kCondLE: |
| 4175 | if (IsInt<16>(rhs_imm + 1)) { |
| 4176 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4177 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 4178 | __ Bnez(TMP, label); |
| 4179 | } else { |
| 4180 | __ LoadConst32(TMP, rhs_imm); |
| 4181 | __ Bge(TMP, lhs, label); |
| 4182 | } |
| 4183 | break; |
| 4184 | case kCondGT: |
| 4185 | if (IsInt<16>(rhs_imm + 1)) { |
| 4186 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 4187 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 4188 | __ Beqz(TMP, label); |
| 4189 | } else { |
| 4190 | __ LoadConst32(TMP, rhs_imm); |
| 4191 | __ Blt(TMP, lhs, label); |
| 4192 | } |
| 4193 | break; |
| 4194 | case kCondB: |
| 4195 | if (IsInt<16>(rhs_imm)) { |
| 4196 | __ Sltiu(TMP, lhs, rhs_imm); |
| 4197 | __ Bnez(TMP, label); |
| 4198 | } else { |
| 4199 | __ LoadConst32(TMP, rhs_imm); |
| 4200 | __ Bltu(lhs, TMP, label); |
| 4201 | } |
| 4202 | break; |
| 4203 | case kCondAE: |
| 4204 | if (IsInt<16>(rhs_imm)) { |
| 4205 | __ Sltiu(TMP, lhs, rhs_imm); |
| 4206 | __ Beqz(TMP, label); |
| 4207 | } else { |
| 4208 | __ LoadConst32(TMP, rhs_imm); |
| 4209 | __ Bgeu(lhs, TMP, label); |
| 4210 | } |
| 4211 | break; |
| 4212 | case kCondBE: |
| 4213 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4214 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 4215 | // Note that this only works if rhs + 1 does not overflow |
| 4216 | // to 0, hence the check above. |
| 4217 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 4218 | __ Bnez(TMP, label); |
| 4219 | } else { |
| 4220 | __ LoadConst32(TMP, rhs_imm); |
| 4221 | __ Bgeu(TMP, lhs, label); |
| 4222 | } |
| 4223 | break; |
| 4224 | case kCondA: |
| 4225 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 4226 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 4227 | // Note that this only works if rhs + 1 does not overflow |
| 4228 | // to 0, hence the check above. |
| 4229 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 4230 | __ Beqz(TMP, label); |
| 4231 | } else { |
| 4232 | __ LoadConst32(TMP, rhs_imm); |
| 4233 | __ Bltu(TMP, lhs, label); |
| 4234 | } |
| 4235 | break; |
| 4236 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4237 | } |
| 4238 | } |
| 4239 | } |
| 4240 | |
| 4241 | void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond, |
| 4242 | LocationSummary* locations, |
| 4243 | MipsLabel* label) { |
| 4244 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4245 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4246 | Location rhs_location = locations->InAt(1); |
| 4247 | Register rhs_high = ZERO; |
| 4248 | Register rhs_low = ZERO; |
| 4249 | int64_t imm = 0; |
| 4250 | uint32_t imm_high = 0; |
| 4251 | uint32_t imm_low = 0; |
| 4252 | bool use_imm = rhs_location.IsConstant(); |
| 4253 | if (use_imm) { |
| 4254 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); |
| 4255 | imm_high = High32Bits(imm); |
| 4256 | imm_low = Low32Bits(imm); |
| 4257 | } else { |
| 4258 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 4259 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 4260 | } |
| 4261 | |
| 4262 | if (use_imm && imm == 0) { |
| 4263 | switch (cond) { |
| 4264 | case kCondEQ: |
| 4265 | case kCondBE: // <= 0 if zero |
| 4266 | __ Or(TMP, lhs_high, lhs_low); |
| 4267 | __ Beqz(TMP, label); |
| 4268 | break; |
| 4269 | case kCondNE: |
| 4270 | case kCondA: // > 0 if non-zero |
| 4271 | __ Or(TMP, lhs_high, lhs_low); |
| 4272 | __ Bnez(TMP, label); |
| 4273 | break; |
| 4274 | case kCondLT: |
| 4275 | __ Bltz(lhs_high, label); |
| 4276 | break; |
| 4277 | case kCondGE: |
| 4278 | __ Bgez(lhs_high, label); |
| 4279 | break; |
| 4280 | case kCondLE: |
| 4281 | __ Or(TMP, lhs_high, lhs_low); |
| 4282 | __ Sra(AT, lhs_high, 31); |
| 4283 | __ Bgeu(AT, TMP, label); |
| 4284 | break; |
| 4285 | case kCondGT: |
| 4286 | __ Or(TMP, lhs_high, lhs_low); |
| 4287 | __ Sra(AT, lhs_high, 31); |
| 4288 | __ Bltu(AT, TMP, label); |
| 4289 | break; |
| 4290 | case kCondB: // always false |
| 4291 | break; |
| 4292 | case kCondAE: // always true |
| 4293 | __ B(label); |
| 4294 | break; |
| 4295 | } |
| 4296 | } else if (use_imm) { |
| 4297 | // TODO: more efficient comparison with constants without loading them into TMP/AT. |
| 4298 | switch (cond) { |
| 4299 | case kCondEQ: |
| 4300 | __ LoadConst32(TMP, imm_high); |
| 4301 | __ Xor(TMP, TMP, lhs_high); |
| 4302 | __ LoadConst32(AT, imm_low); |
| 4303 | __ Xor(AT, AT, lhs_low); |
| 4304 | __ Or(TMP, TMP, AT); |
| 4305 | __ Beqz(TMP, label); |
| 4306 | break; |
| 4307 | case kCondNE: |
| 4308 | __ LoadConst32(TMP, imm_high); |
| 4309 | __ Xor(TMP, TMP, lhs_high); |
| 4310 | __ LoadConst32(AT, imm_low); |
| 4311 | __ Xor(AT, AT, lhs_low); |
| 4312 | __ Or(TMP, TMP, AT); |
| 4313 | __ Bnez(TMP, label); |
| 4314 | break; |
| 4315 | case kCondLT: |
| 4316 | __ LoadConst32(TMP, imm_high); |
| 4317 | __ Blt(lhs_high, TMP, label); |
| 4318 | __ Slt(TMP, TMP, lhs_high); |
| 4319 | __ LoadConst32(AT, imm_low); |
| 4320 | __ Sltu(AT, lhs_low, AT); |
| 4321 | __ Blt(TMP, AT, label); |
| 4322 | break; |
| 4323 | case kCondGE: |
| 4324 | __ LoadConst32(TMP, imm_high); |
| 4325 | __ Blt(TMP, lhs_high, label); |
| 4326 | __ Slt(TMP, lhs_high, TMP); |
| 4327 | __ LoadConst32(AT, imm_low); |
| 4328 | __ Sltu(AT, lhs_low, AT); |
| 4329 | __ Or(TMP, TMP, AT); |
| 4330 | __ Beqz(TMP, label); |
| 4331 | break; |
| 4332 | case kCondLE: |
| 4333 | __ LoadConst32(TMP, imm_high); |
| 4334 | __ Blt(lhs_high, TMP, label); |
| 4335 | __ Slt(TMP, TMP, lhs_high); |
| 4336 | __ LoadConst32(AT, imm_low); |
| 4337 | __ Sltu(AT, AT, lhs_low); |
| 4338 | __ Or(TMP, TMP, AT); |
| 4339 | __ Beqz(TMP, label); |
| 4340 | break; |
| 4341 | case kCondGT: |
| 4342 | __ LoadConst32(TMP, imm_high); |
| 4343 | __ Blt(TMP, lhs_high, label); |
| 4344 | __ Slt(TMP, lhs_high, TMP); |
| 4345 | __ LoadConst32(AT, imm_low); |
| 4346 | __ Sltu(AT, AT, lhs_low); |
| 4347 | __ Blt(TMP, AT, label); |
| 4348 | break; |
| 4349 | case kCondB: |
| 4350 | __ LoadConst32(TMP, imm_high); |
| 4351 | __ Bltu(lhs_high, TMP, label); |
| 4352 | __ Sltu(TMP, TMP, lhs_high); |
| 4353 | __ LoadConst32(AT, imm_low); |
| 4354 | __ Sltu(AT, lhs_low, AT); |
| 4355 | __ Blt(TMP, AT, label); |
| 4356 | break; |
| 4357 | case kCondAE: |
| 4358 | __ LoadConst32(TMP, imm_high); |
| 4359 | __ Bltu(TMP, lhs_high, label); |
| 4360 | __ Sltu(TMP, lhs_high, TMP); |
| 4361 | __ LoadConst32(AT, imm_low); |
| 4362 | __ Sltu(AT, lhs_low, AT); |
| 4363 | __ Or(TMP, TMP, AT); |
| 4364 | __ Beqz(TMP, label); |
| 4365 | break; |
| 4366 | case kCondBE: |
| 4367 | __ LoadConst32(TMP, imm_high); |
| 4368 | __ Bltu(lhs_high, TMP, label); |
| 4369 | __ Sltu(TMP, TMP, lhs_high); |
| 4370 | __ LoadConst32(AT, imm_low); |
| 4371 | __ Sltu(AT, AT, lhs_low); |
| 4372 | __ Or(TMP, TMP, AT); |
| 4373 | __ Beqz(TMP, label); |
| 4374 | break; |
| 4375 | case kCondA: |
| 4376 | __ LoadConst32(TMP, imm_high); |
| 4377 | __ Bltu(TMP, lhs_high, label); |
| 4378 | __ Sltu(TMP, lhs_high, TMP); |
| 4379 | __ LoadConst32(AT, imm_low); |
| 4380 | __ Sltu(AT, AT, lhs_low); |
| 4381 | __ Blt(TMP, AT, label); |
| 4382 | break; |
| 4383 | } |
| 4384 | } else { |
| 4385 | switch (cond) { |
| 4386 | case kCondEQ: |
| 4387 | __ Xor(TMP, lhs_high, rhs_high); |
| 4388 | __ Xor(AT, lhs_low, rhs_low); |
| 4389 | __ Or(TMP, TMP, AT); |
| 4390 | __ Beqz(TMP, label); |
| 4391 | break; |
| 4392 | case kCondNE: |
| 4393 | __ Xor(TMP, lhs_high, rhs_high); |
| 4394 | __ Xor(AT, lhs_low, rhs_low); |
| 4395 | __ Or(TMP, TMP, AT); |
| 4396 | __ Bnez(TMP, label); |
| 4397 | break; |
| 4398 | case kCondLT: |
| 4399 | __ Blt(lhs_high, rhs_high, label); |
| 4400 | __ Slt(TMP, rhs_high, lhs_high); |
| 4401 | __ Sltu(AT, lhs_low, rhs_low); |
| 4402 | __ Blt(TMP, AT, label); |
| 4403 | break; |
| 4404 | case kCondGE: |
| 4405 | __ Blt(rhs_high, lhs_high, label); |
| 4406 | __ Slt(TMP, lhs_high, rhs_high); |
| 4407 | __ Sltu(AT, lhs_low, rhs_low); |
| 4408 | __ Or(TMP, TMP, AT); |
| 4409 | __ Beqz(TMP, label); |
| 4410 | break; |
| 4411 | case kCondLE: |
| 4412 | __ Blt(lhs_high, rhs_high, label); |
| 4413 | __ Slt(TMP, rhs_high, lhs_high); |
| 4414 | __ Sltu(AT, rhs_low, lhs_low); |
| 4415 | __ Or(TMP, TMP, AT); |
| 4416 | __ Beqz(TMP, label); |
| 4417 | break; |
| 4418 | case kCondGT: |
| 4419 | __ Blt(rhs_high, lhs_high, label); |
| 4420 | __ Slt(TMP, lhs_high, rhs_high); |
| 4421 | __ Sltu(AT, rhs_low, lhs_low); |
| 4422 | __ Blt(TMP, AT, label); |
| 4423 | break; |
| 4424 | case kCondB: |
| 4425 | __ Bltu(lhs_high, rhs_high, label); |
| 4426 | __ Sltu(TMP, rhs_high, lhs_high); |
| 4427 | __ Sltu(AT, lhs_low, rhs_low); |
| 4428 | __ Blt(TMP, AT, label); |
| 4429 | break; |
| 4430 | case kCondAE: |
| 4431 | __ Bltu(rhs_high, lhs_high, label); |
| 4432 | __ Sltu(TMP, lhs_high, rhs_high); |
| 4433 | __ Sltu(AT, lhs_low, rhs_low); |
| 4434 | __ Or(TMP, TMP, AT); |
| 4435 | __ Beqz(TMP, label); |
| 4436 | break; |
| 4437 | case kCondBE: |
| 4438 | __ Bltu(lhs_high, rhs_high, label); |
| 4439 | __ Sltu(TMP, rhs_high, lhs_high); |
| 4440 | __ Sltu(AT, rhs_low, lhs_low); |
| 4441 | __ Or(TMP, TMP, AT); |
| 4442 | __ Beqz(TMP, label); |
| 4443 | break; |
| 4444 | case kCondA: |
| 4445 | __ Bltu(rhs_high, lhs_high, label); |
| 4446 | __ Sltu(TMP, lhs_high, rhs_high); |
| 4447 | __ Sltu(AT, rhs_low, lhs_low); |
| 4448 | __ Blt(TMP, AT, label); |
| 4449 | break; |
| 4450 | } |
| 4451 | } |
| 4452 | } |
| 4453 | |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 4454 | void InstructionCodeGeneratorMIPS::GenerateFpCompare(IfCondition cond, |
| 4455 | bool gt_bias, |
| 4456 | Primitive::Type type, |
| 4457 | LocationSummary* locations) { |
| 4458 | Register dst = locations->Out().AsRegister<Register>(); |
| 4459 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 4460 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 4461 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4462 | if (type == Primitive::kPrimFloat) { |
| 4463 | if (isR6) { |
| 4464 | switch (cond) { |
| 4465 | case kCondEQ: |
| 4466 | __ CmpEqS(FTMP, lhs, rhs); |
| 4467 | __ Mfc1(dst, FTMP); |
| 4468 | __ Andi(dst, dst, 1); |
| 4469 | break; |
| 4470 | case kCondNE: |
| 4471 | __ CmpEqS(FTMP, lhs, rhs); |
| 4472 | __ Mfc1(dst, FTMP); |
| 4473 | __ Addiu(dst, dst, 1); |
| 4474 | break; |
| 4475 | case kCondLT: |
| 4476 | if (gt_bias) { |
| 4477 | __ CmpLtS(FTMP, lhs, rhs); |
| 4478 | } else { |
| 4479 | __ CmpUltS(FTMP, lhs, rhs); |
| 4480 | } |
| 4481 | __ Mfc1(dst, FTMP); |
| 4482 | __ Andi(dst, dst, 1); |
| 4483 | break; |
| 4484 | case kCondLE: |
| 4485 | if (gt_bias) { |
| 4486 | __ CmpLeS(FTMP, lhs, rhs); |
| 4487 | } else { |
| 4488 | __ CmpUleS(FTMP, lhs, rhs); |
| 4489 | } |
| 4490 | __ Mfc1(dst, FTMP); |
| 4491 | __ Andi(dst, dst, 1); |
| 4492 | break; |
| 4493 | case kCondGT: |
| 4494 | if (gt_bias) { |
| 4495 | __ CmpUltS(FTMP, rhs, lhs); |
| 4496 | } else { |
| 4497 | __ CmpLtS(FTMP, rhs, lhs); |
| 4498 | } |
| 4499 | __ Mfc1(dst, FTMP); |
| 4500 | __ Andi(dst, dst, 1); |
| 4501 | break; |
| 4502 | case kCondGE: |
| 4503 | if (gt_bias) { |
| 4504 | __ CmpUleS(FTMP, rhs, lhs); |
| 4505 | } else { |
| 4506 | __ CmpLeS(FTMP, rhs, lhs); |
| 4507 | } |
| 4508 | __ Mfc1(dst, FTMP); |
| 4509 | __ Andi(dst, dst, 1); |
| 4510 | break; |
| 4511 | default: |
| 4512 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4513 | UNREACHABLE(); |
| 4514 | } |
| 4515 | } else { |
| 4516 | switch (cond) { |
| 4517 | case kCondEQ: |
| 4518 | __ CeqS(0, lhs, rhs); |
| 4519 | __ LoadConst32(dst, 1); |
| 4520 | __ Movf(dst, ZERO, 0); |
| 4521 | break; |
| 4522 | case kCondNE: |
| 4523 | __ CeqS(0, lhs, rhs); |
| 4524 | __ LoadConst32(dst, 1); |
| 4525 | __ Movt(dst, ZERO, 0); |
| 4526 | break; |
| 4527 | case kCondLT: |
| 4528 | if (gt_bias) { |
| 4529 | __ ColtS(0, lhs, rhs); |
| 4530 | } else { |
| 4531 | __ CultS(0, lhs, rhs); |
| 4532 | } |
| 4533 | __ LoadConst32(dst, 1); |
| 4534 | __ Movf(dst, ZERO, 0); |
| 4535 | break; |
| 4536 | case kCondLE: |
| 4537 | if (gt_bias) { |
| 4538 | __ ColeS(0, lhs, rhs); |
| 4539 | } else { |
| 4540 | __ CuleS(0, lhs, rhs); |
| 4541 | } |
| 4542 | __ LoadConst32(dst, 1); |
| 4543 | __ Movf(dst, ZERO, 0); |
| 4544 | break; |
| 4545 | case kCondGT: |
| 4546 | if (gt_bias) { |
| 4547 | __ CultS(0, rhs, lhs); |
| 4548 | } else { |
| 4549 | __ ColtS(0, rhs, lhs); |
| 4550 | } |
| 4551 | __ LoadConst32(dst, 1); |
| 4552 | __ Movf(dst, ZERO, 0); |
| 4553 | break; |
| 4554 | case kCondGE: |
| 4555 | if (gt_bias) { |
| 4556 | __ CuleS(0, rhs, lhs); |
| 4557 | } else { |
| 4558 | __ ColeS(0, rhs, lhs); |
| 4559 | } |
| 4560 | __ LoadConst32(dst, 1); |
| 4561 | __ Movf(dst, ZERO, 0); |
| 4562 | break; |
| 4563 | default: |
| 4564 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4565 | UNREACHABLE(); |
| 4566 | } |
| 4567 | } |
| 4568 | } else { |
| 4569 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 4570 | if (isR6) { |
| 4571 | switch (cond) { |
| 4572 | case kCondEQ: |
| 4573 | __ CmpEqD(FTMP, lhs, rhs); |
| 4574 | __ Mfc1(dst, FTMP); |
| 4575 | __ Andi(dst, dst, 1); |
| 4576 | break; |
| 4577 | case kCondNE: |
| 4578 | __ CmpEqD(FTMP, lhs, rhs); |
| 4579 | __ Mfc1(dst, FTMP); |
| 4580 | __ Addiu(dst, dst, 1); |
| 4581 | break; |
| 4582 | case kCondLT: |
| 4583 | if (gt_bias) { |
| 4584 | __ CmpLtD(FTMP, lhs, rhs); |
| 4585 | } else { |
| 4586 | __ CmpUltD(FTMP, lhs, rhs); |
| 4587 | } |
| 4588 | __ Mfc1(dst, FTMP); |
| 4589 | __ Andi(dst, dst, 1); |
| 4590 | break; |
| 4591 | case kCondLE: |
| 4592 | if (gt_bias) { |
| 4593 | __ CmpLeD(FTMP, lhs, rhs); |
| 4594 | } else { |
| 4595 | __ CmpUleD(FTMP, lhs, rhs); |
| 4596 | } |
| 4597 | __ Mfc1(dst, FTMP); |
| 4598 | __ Andi(dst, dst, 1); |
| 4599 | break; |
| 4600 | case kCondGT: |
| 4601 | if (gt_bias) { |
| 4602 | __ CmpUltD(FTMP, rhs, lhs); |
| 4603 | } else { |
| 4604 | __ CmpLtD(FTMP, rhs, lhs); |
| 4605 | } |
| 4606 | __ Mfc1(dst, FTMP); |
| 4607 | __ Andi(dst, dst, 1); |
| 4608 | break; |
| 4609 | case kCondGE: |
| 4610 | if (gt_bias) { |
| 4611 | __ CmpUleD(FTMP, rhs, lhs); |
| 4612 | } else { |
| 4613 | __ CmpLeD(FTMP, rhs, lhs); |
| 4614 | } |
| 4615 | __ Mfc1(dst, FTMP); |
| 4616 | __ Andi(dst, dst, 1); |
| 4617 | break; |
| 4618 | default: |
| 4619 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4620 | UNREACHABLE(); |
| 4621 | } |
| 4622 | } else { |
| 4623 | switch (cond) { |
| 4624 | case kCondEQ: |
| 4625 | __ CeqD(0, lhs, rhs); |
| 4626 | __ LoadConst32(dst, 1); |
| 4627 | __ Movf(dst, ZERO, 0); |
| 4628 | break; |
| 4629 | case kCondNE: |
| 4630 | __ CeqD(0, lhs, rhs); |
| 4631 | __ LoadConst32(dst, 1); |
| 4632 | __ Movt(dst, ZERO, 0); |
| 4633 | break; |
| 4634 | case kCondLT: |
| 4635 | if (gt_bias) { |
| 4636 | __ ColtD(0, lhs, rhs); |
| 4637 | } else { |
| 4638 | __ CultD(0, lhs, rhs); |
| 4639 | } |
| 4640 | __ LoadConst32(dst, 1); |
| 4641 | __ Movf(dst, ZERO, 0); |
| 4642 | break; |
| 4643 | case kCondLE: |
| 4644 | if (gt_bias) { |
| 4645 | __ ColeD(0, lhs, rhs); |
| 4646 | } else { |
| 4647 | __ CuleD(0, lhs, rhs); |
| 4648 | } |
| 4649 | __ LoadConst32(dst, 1); |
| 4650 | __ Movf(dst, ZERO, 0); |
| 4651 | break; |
| 4652 | case kCondGT: |
| 4653 | if (gt_bias) { |
| 4654 | __ CultD(0, rhs, lhs); |
| 4655 | } else { |
| 4656 | __ ColtD(0, rhs, lhs); |
| 4657 | } |
| 4658 | __ LoadConst32(dst, 1); |
| 4659 | __ Movf(dst, ZERO, 0); |
| 4660 | break; |
| 4661 | case kCondGE: |
| 4662 | if (gt_bias) { |
| 4663 | __ CuleD(0, rhs, lhs); |
| 4664 | } else { |
| 4665 | __ ColeD(0, rhs, lhs); |
| 4666 | } |
| 4667 | __ LoadConst32(dst, 1); |
| 4668 | __ Movf(dst, ZERO, 0); |
| 4669 | break; |
| 4670 | default: |
| 4671 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 4672 | UNREACHABLE(); |
| 4673 | } |
| 4674 | } |
| 4675 | } |
| 4676 | } |
| 4677 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4678 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR2(IfCondition cond, |
| 4679 | bool gt_bias, |
| 4680 | Primitive::Type type, |
| 4681 | LocationSummary* input_locations, |
| 4682 | int cc) { |
| 4683 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 4684 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 4685 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
| 4686 | if (type == Primitive::kPrimFloat) { |
| 4687 | switch (cond) { |
| 4688 | case kCondEQ: |
| 4689 | __ CeqS(cc, lhs, rhs); |
| 4690 | return false; |
| 4691 | case kCondNE: |
| 4692 | __ CeqS(cc, lhs, rhs); |
| 4693 | return true; |
| 4694 | case kCondLT: |
| 4695 | if (gt_bias) { |
| 4696 | __ ColtS(cc, lhs, rhs); |
| 4697 | } else { |
| 4698 | __ CultS(cc, lhs, rhs); |
| 4699 | } |
| 4700 | return false; |
| 4701 | case kCondLE: |
| 4702 | if (gt_bias) { |
| 4703 | __ ColeS(cc, lhs, rhs); |
| 4704 | } else { |
| 4705 | __ CuleS(cc, lhs, rhs); |
| 4706 | } |
| 4707 | return false; |
| 4708 | case kCondGT: |
| 4709 | if (gt_bias) { |
| 4710 | __ CultS(cc, rhs, lhs); |
| 4711 | } else { |
| 4712 | __ ColtS(cc, rhs, lhs); |
| 4713 | } |
| 4714 | return false; |
| 4715 | case kCondGE: |
| 4716 | if (gt_bias) { |
| 4717 | __ CuleS(cc, rhs, lhs); |
| 4718 | } else { |
| 4719 | __ ColeS(cc, rhs, lhs); |
| 4720 | } |
| 4721 | return false; |
| 4722 | default: |
| 4723 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 4724 | UNREACHABLE(); |
| 4725 | } |
| 4726 | } else { |
| 4727 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 4728 | switch (cond) { |
| 4729 | case kCondEQ: |
| 4730 | __ CeqD(cc, lhs, rhs); |
| 4731 | return false; |
| 4732 | case kCondNE: |
| 4733 | __ CeqD(cc, lhs, rhs); |
| 4734 | return true; |
| 4735 | case kCondLT: |
| 4736 | if (gt_bias) { |
| 4737 | __ ColtD(cc, lhs, rhs); |
| 4738 | } else { |
| 4739 | __ CultD(cc, lhs, rhs); |
| 4740 | } |
| 4741 | return false; |
| 4742 | case kCondLE: |
| 4743 | if (gt_bias) { |
| 4744 | __ ColeD(cc, lhs, rhs); |
| 4745 | } else { |
| 4746 | __ CuleD(cc, lhs, rhs); |
| 4747 | } |
| 4748 | return false; |
| 4749 | case kCondGT: |
| 4750 | if (gt_bias) { |
| 4751 | __ CultD(cc, rhs, lhs); |
| 4752 | } else { |
| 4753 | __ ColtD(cc, rhs, lhs); |
| 4754 | } |
| 4755 | return false; |
| 4756 | case kCondGE: |
| 4757 | if (gt_bias) { |
| 4758 | __ CuleD(cc, rhs, lhs); |
| 4759 | } else { |
| 4760 | __ ColeD(cc, rhs, lhs); |
| 4761 | } |
| 4762 | return false; |
| 4763 | default: |
| 4764 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 4765 | UNREACHABLE(); |
| 4766 | } |
| 4767 | } |
| 4768 | } |
| 4769 | |
| 4770 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR6(IfCondition cond, |
| 4771 | bool gt_bias, |
| 4772 | Primitive::Type type, |
| 4773 | LocationSummary* input_locations, |
| 4774 | FRegister dst) { |
| 4775 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 4776 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 4777 | CHECK(codegen_->GetInstructionSetFeatures().IsR6()); |
| 4778 | if (type == Primitive::kPrimFloat) { |
| 4779 | switch (cond) { |
| 4780 | case kCondEQ: |
| 4781 | __ CmpEqS(dst, lhs, rhs); |
| 4782 | return false; |
| 4783 | case kCondNE: |
| 4784 | __ CmpEqS(dst, lhs, rhs); |
| 4785 | return true; |
| 4786 | case kCondLT: |
| 4787 | if (gt_bias) { |
| 4788 | __ CmpLtS(dst, lhs, rhs); |
| 4789 | } else { |
| 4790 | __ CmpUltS(dst, lhs, rhs); |
| 4791 | } |
| 4792 | return false; |
| 4793 | case kCondLE: |
| 4794 | if (gt_bias) { |
| 4795 | __ CmpLeS(dst, lhs, rhs); |
| 4796 | } else { |
| 4797 | __ CmpUleS(dst, lhs, rhs); |
| 4798 | } |
| 4799 | return false; |
| 4800 | case kCondGT: |
| 4801 | if (gt_bias) { |
| 4802 | __ CmpUltS(dst, rhs, lhs); |
| 4803 | } else { |
| 4804 | __ CmpLtS(dst, rhs, lhs); |
| 4805 | } |
| 4806 | return false; |
| 4807 | case kCondGE: |
| 4808 | if (gt_bias) { |
| 4809 | __ CmpUleS(dst, rhs, lhs); |
| 4810 | } else { |
| 4811 | __ CmpLeS(dst, rhs, lhs); |
| 4812 | } |
| 4813 | return false; |
| 4814 | default: |
| 4815 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 4816 | UNREACHABLE(); |
| 4817 | } |
| 4818 | } else { |
| 4819 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 4820 | switch (cond) { |
| 4821 | case kCondEQ: |
| 4822 | __ CmpEqD(dst, lhs, rhs); |
| 4823 | return false; |
| 4824 | case kCondNE: |
| 4825 | __ CmpEqD(dst, lhs, rhs); |
| 4826 | return true; |
| 4827 | case kCondLT: |
| 4828 | if (gt_bias) { |
| 4829 | __ CmpLtD(dst, lhs, rhs); |
| 4830 | } else { |
| 4831 | __ CmpUltD(dst, lhs, rhs); |
| 4832 | } |
| 4833 | return false; |
| 4834 | case kCondLE: |
| 4835 | if (gt_bias) { |
| 4836 | __ CmpLeD(dst, lhs, rhs); |
| 4837 | } else { |
| 4838 | __ CmpUleD(dst, lhs, rhs); |
| 4839 | } |
| 4840 | return false; |
| 4841 | case kCondGT: |
| 4842 | if (gt_bias) { |
| 4843 | __ CmpUltD(dst, rhs, lhs); |
| 4844 | } else { |
| 4845 | __ CmpLtD(dst, rhs, lhs); |
| 4846 | } |
| 4847 | return false; |
| 4848 | case kCondGE: |
| 4849 | if (gt_bias) { |
| 4850 | __ CmpUleD(dst, rhs, lhs); |
| 4851 | } else { |
| 4852 | __ CmpLeD(dst, rhs, lhs); |
| 4853 | } |
| 4854 | return false; |
| 4855 | default: |
| 4856 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 4857 | UNREACHABLE(); |
| 4858 | } |
| 4859 | } |
| 4860 | } |
| 4861 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4862 | void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond, |
| 4863 | bool gt_bias, |
| 4864 | Primitive::Type type, |
| 4865 | LocationSummary* locations, |
| 4866 | MipsLabel* label) { |
| 4867 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 4868 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 4869 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4870 | if (type == Primitive::kPrimFloat) { |
| 4871 | if (isR6) { |
| 4872 | switch (cond) { |
| 4873 | case kCondEQ: |
| 4874 | __ CmpEqS(FTMP, lhs, rhs); |
| 4875 | __ Bc1nez(FTMP, label); |
| 4876 | break; |
| 4877 | case kCondNE: |
| 4878 | __ CmpEqS(FTMP, lhs, rhs); |
| 4879 | __ Bc1eqz(FTMP, label); |
| 4880 | break; |
| 4881 | case kCondLT: |
| 4882 | if (gt_bias) { |
| 4883 | __ CmpLtS(FTMP, lhs, rhs); |
| 4884 | } else { |
| 4885 | __ CmpUltS(FTMP, lhs, rhs); |
| 4886 | } |
| 4887 | __ Bc1nez(FTMP, label); |
| 4888 | break; |
| 4889 | case kCondLE: |
| 4890 | if (gt_bias) { |
| 4891 | __ CmpLeS(FTMP, lhs, rhs); |
| 4892 | } else { |
| 4893 | __ CmpUleS(FTMP, lhs, rhs); |
| 4894 | } |
| 4895 | __ Bc1nez(FTMP, label); |
| 4896 | break; |
| 4897 | case kCondGT: |
| 4898 | if (gt_bias) { |
| 4899 | __ CmpUltS(FTMP, rhs, lhs); |
| 4900 | } else { |
| 4901 | __ CmpLtS(FTMP, rhs, lhs); |
| 4902 | } |
| 4903 | __ Bc1nez(FTMP, label); |
| 4904 | break; |
| 4905 | case kCondGE: |
| 4906 | if (gt_bias) { |
| 4907 | __ CmpUleS(FTMP, rhs, lhs); |
| 4908 | } else { |
| 4909 | __ CmpLeS(FTMP, rhs, lhs); |
| 4910 | } |
| 4911 | __ Bc1nez(FTMP, label); |
| 4912 | break; |
| 4913 | default: |
| 4914 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4915 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4916 | } |
| 4917 | } else { |
| 4918 | switch (cond) { |
| 4919 | case kCondEQ: |
| 4920 | __ CeqS(0, lhs, rhs); |
| 4921 | __ Bc1t(0, label); |
| 4922 | break; |
| 4923 | case kCondNE: |
| 4924 | __ CeqS(0, lhs, rhs); |
| 4925 | __ Bc1f(0, label); |
| 4926 | break; |
| 4927 | case kCondLT: |
| 4928 | if (gt_bias) { |
| 4929 | __ ColtS(0, lhs, rhs); |
| 4930 | } else { |
| 4931 | __ CultS(0, lhs, rhs); |
| 4932 | } |
| 4933 | __ Bc1t(0, label); |
| 4934 | break; |
| 4935 | case kCondLE: |
| 4936 | if (gt_bias) { |
| 4937 | __ ColeS(0, lhs, rhs); |
| 4938 | } else { |
| 4939 | __ CuleS(0, lhs, rhs); |
| 4940 | } |
| 4941 | __ Bc1t(0, label); |
| 4942 | break; |
| 4943 | case kCondGT: |
| 4944 | if (gt_bias) { |
| 4945 | __ CultS(0, rhs, lhs); |
| 4946 | } else { |
| 4947 | __ ColtS(0, rhs, lhs); |
| 4948 | } |
| 4949 | __ Bc1t(0, label); |
| 4950 | break; |
| 4951 | case kCondGE: |
| 4952 | if (gt_bias) { |
| 4953 | __ CuleS(0, rhs, lhs); |
| 4954 | } else { |
| 4955 | __ ColeS(0, rhs, lhs); |
| 4956 | } |
| 4957 | __ Bc1t(0, label); |
| 4958 | break; |
| 4959 | default: |
| 4960 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4961 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4962 | } |
| 4963 | } |
| 4964 | } else { |
| 4965 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 4966 | if (isR6) { |
| 4967 | switch (cond) { |
| 4968 | case kCondEQ: |
| 4969 | __ CmpEqD(FTMP, lhs, rhs); |
| 4970 | __ Bc1nez(FTMP, label); |
| 4971 | break; |
| 4972 | case kCondNE: |
| 4973 | __ CmpEqD(FTMP, lhs, rhs); |
| 4974 | __ Bc1eqz(FTMP, label); |
| 4975 | break; |
| 4976 | case kCondLT: |
| 4977 | if (gt_bias) { |
| 4978 | __ CmpLtD(FTMP, lhs, rhs); |
| 4979 | } else { |
| 4980 | __ CmpUltD(FTMP, lhs, rhs); |
| 4981 | } |
| 4982 | __ Bc1nez(FTMP, label); |
| 4983 | break; |
| 4984 | case kCondLE: |
| 4985 | if (gt_bias) { |
| 4986 | __ CmpLeD(FTMP, lhs, rhs); |
| 4987 | } else { |
| 4988 | __ CmpUleD(FTMP, lhs, rhs); |
| 4989 | } |
| 4990 | __ Bc1nez(FTMP, label); |
| 4991 | break; |
| 4992 | case kCondGT: |
| 4993 | if (gt_bias) { |
| 4994 | __ CmpUltD(FTMP, rhs, lhs); |
| 4995 | } else { |
| 4996 | __ CmpLtD(FTMP, rhs, lhs); |
| 4997 | } |
| 4998 | __ Bc1nez(FTMP, label); |
| 4999 | break; |
| 5000 | case kCondGE: |
| 5001 | if (gt_bias) { |
| 5002 | __ CmpUleD(FTMP, rhs, lhs); |
| 5003 | } else { |
| 5004 | __ CmpLeD(FTMP, rhs, lhs); |
| 5005 | } |
| 5006 | __ Bc1nez(FTMP, label); |
| 5007 | break; |
| 5008 | default: |
| 5009 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5010 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5011 | } |
| 5012 | } else { |
| 5013 | switch (cond) { |
| 5014 | case kCondEQ: |
| 5015 | __ CeqD(0, lhs, rhs); |
| 5016 | __ Bc1t(0, label); |
| 5017 | break; |
| 5018 | case kCondNE: |
| 5019 | __ CeqD(0, lhs, rhs); |
| 5020 | __ Bc1f(0, label); |
| 5021 | break; |
| 5022 | case kCondLT: |
| 5023 | if (gt_bias) { |
| 5024 | __ ColtD(0, lhs, rhs); |
| 5025 | } else { |
| 5026 | __ CultD(0, lhs, rhs); |
| 5027 | } |
| 5028 | __ Bc1t(0, label); |
| 5029 | break; |
| 5030 | case kCondLE: |
| 5031 | if (gt_bias) { |
| 5032 | __ ColeD(0, lhs, rhs); |
| 5033 | } else { |
| 5034 | __ CuleD(0, lhs, rhs); |
| 5035 | } |
| 5036 | __ Bc1t(0, label); |
| 5037 | break; |
| 5038 | case kCondGT: |
| 5039 | if (gt_bias) { |
| 5040 | __ CultD(0, rhs, lhs); |
| 5041 | } else { |
| 5042 | __ ColtD(0, rhs, lhs); |
| 5043 | } |
| 5044 | __ Bc1t(0, label); |
| 5045 | break; |
| 5046 | case kCondGE: |
| 5047 | if (gt_bias) { |
| 5048 | __ CuleD(0, rhs, lhs); |
| 5049 | } else { |
| 5050 | __ ColeD(0, rhs, lhs); |
| 5051 | } |
| 5052 | __ Bc1t(0, label); |
| 5053 | break; |
| 5054 | default: |
| 5055 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5056 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5057 | } |
| 5058 | } |
| 5059 | } |
| 5060 | } |
| 5061 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5062 | void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5063 | size_t condition_input_index, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5064 | MipsLabel* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5065 | MipsLabel* false_target) { |
| 5066 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5067 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5068 | if (true_target == nullptr && false_target == nullptr) { |
| 5069 | // Nothing to do. The code always falls through. |
| 5070 | return; |
| 5071 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 5072 | // Constant condition, statically compared against "true" (integer value 1). |
| 5073 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5074 | if (true_target != nullptr) { |
| 5075 | __ B(true_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5076 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5077 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 5078 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5079 | if (false_target != nullptr) { |
| 5080 | __ B(false_target); |
| 5081 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5082 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5083 | return; |
| 5084 | } |
| 5085 | |
| 5086 | // The following code generates these patterns: |
| 5087 | // (1) true_target == nullptr && false_target != nullptr |
| 5088 | // - opposite condition true => branch to false_target |
| 5089 | // (2) true_target != nullptr && false_target == nullptr |
| 5090 | // - condition true => branch to true_target |
| 5091 | // (3) true_target != nullptr && false_target != nullptr |
| 5092 | // - condition true => branch to true_target |
| 5093 | // - branch to false_target |
| 5094 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5095 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5096 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5097 | DCHECK(cond_val.IsRegister()); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5098 | if (true_target == nullptr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5099 | __ Beqz(cond_val.AsRegister<Register>(), false_target); |
| 5100 | } else { |
| 5101 | __ Bnez(cond_val.AsRegister<Register>(), true_target); |
| 5102 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5103 | } else { |
| 5104 | // The condition instruction has not been materialized, use its inputs as |
| 5105 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5106 | HCondition* condition = cond->AsCondition(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5107 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 5108 | LocationSummary* locations = cond->GetLocations(); |
| 5109 | IfCondition if_cond = condition->GetCondition(); |
| 5110 | MipsLabel* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5111 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5112 | if (true_target == nullptr) { |
| 5113 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5114 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5115 | } |
| 5116 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 5117 | switch (type) { |
| 5118 | default: |
| 5119 | GenerateIntCompareAndBranch(if_cond, locations, branch_target); |
| 5120 | break; |
| 5121 | case Primitive::kPrimLong: |
| 5122 | GenerateLongCompareAndBranch(if_cond, locations, branch_target); |
| 5123 | break; |
| 5124 | case Primitive::kPrimFloat: |
| 5125 | case Primitive::kPrimDouble: |
| 5126 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 5127 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5128 | } |
| 5129 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5130 | |
| 5131 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 5132 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 5133 | if (true_target != nullptr && false_target != nullptr) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5134 | __ B(false_target); |
| 5135 | } |
| 5136 | } |
| 5137 | |
| 5138 | void LocationsBuilderMIPS::VisitIf(HIf* if_instr) { |
| 5139 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5140 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5141 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5142 | } |
| 5143 | } |
| 5144 | |
| 5145 | void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5146 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 5147 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 5148 | MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 5149 | nullptr : codegen_->GetLabelOf(true_successor); |
| 5150 | MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 5151 | nullptr : codegen_->GetLabelOf(false_successor); |
| 5152 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5153 | } |
| 5154 | |
| 5155 | void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 5156 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 5157 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5158 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5159 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5160 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5161 | } |
| 5162 | } |
| 5163 | |
| 5164 | void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 5165 | SlowPathCodeMIPS* slow_path = |
| 5166 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 5167 | GenerateTestAndBranch(deoptimize, |
| 5168 | /* condition_input_index */ 0, |
| 5169 | slow_path->GetEntryLabel(), |
| 5170 | /* false_target */ nullptr); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5171 | } |
| 5172 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5173 | // This function returns true if a conditional move can be generated for HSelect. |
| 5174 | // Otherwise it returns false and HSelect must be implemented in terms of conditonal |
| 5175 | // branches and regular moves. |
| 5176 | // |
| 5177 | // If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect. |
| 5178 | // |
| 5179 | // While determining feasibility of a conditional move and setting inputs/outputs |
| 5180 | // are two distinct tasks, this function does both because they share quite a bit |
| 5181 | // of common logic. |
| 5182 | static bool CanMoveConditionally(HSelect* select, bool is_r6, LocationSummary* locations_to_set) { |
| 5183 | bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition()); |
| 5184 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 5185 | HCondition* condition = cond->AsCondition(); |
| 5186 | |
| 5187 | Primitive::Type cond_type = materialized ? Primitive::kPrimInt : condition->InputAt(0)->GetType(); |
| 5188 | Primitive::Type dst_type = select->GetType(); |
| 5189 | |
| 5190 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 5191 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 5192 | bool is_true_value_zero_constant = |
| 5193 | (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern()); |
| 5194 | bool is_false_value_zero_constant = |
| 5195 | (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern()); |
| 5196 | |
| 5197 | bool can_move_conditionally = false; |
| 5198 | bool use_const_for_false_in = false; |
| 5199 | bool use_const_for_true_in = false; |
| 5200 | |
| 5201 | if (!cond->IsConstant()) { |
| 5202 | switch (cond_type) { |
| 5203 | default: |
| 5204 | switch (dst_type) { |
| 5205 | default: |
| 5206 | // Moving int on int condition. |
| 5207 | if (is_r6) { |
| 5208 | if (is_true_value_zero_constant) { |
| 5209 | // seleqz out_reg, false_reg, cond_reg |
| 5210 | can_move_conditionally = true; |
| 5211 | use_const_for_true_in = true; |
| 5212 | } else if (is_false_value_zero_constant) { |
| 5213 | // selnez out_reg, true_reg, cond_reg |
| 5214 | can_move_conditionally = true; |
| 5215 | use_const_for_false_in = true; |
| 5216 | } else if (materialized) { |
| 5217 | // Not materializing unmaterialized int conditions |
| 5218 | // to keep the instruction count low. |
| 5219 | // selnez AT, true_reg, cond_reg |
| 5220 | // seleqz TMP, false_reg, cond_reg |
| 5221 | // or out_reg, AT, TMP |
| 5222 | can_move_conditionally = true; |
| 5223 | } |
| 5224 | } else { |
| 5225 | // movn out_reg, true_reg/ZERO, cond_reg |
| 5226 | can_move_conditionally = true; |
| 5227 | use_const_for_true_in = is_true_value_zero_constant; |
| 5228 | } |
| 5229 | break; |
| 5230 | case Primitive::kPrimLong: |
| 5231 | // Moving long on int condition. |
| 5232 | if (is_r6) { |
| 5233 | if (is_true_value_zero_constant) { |
| 5234 | // seleqz out_reg_lo, false_reg_lo, cond_reg |
| 5235 | // seleqz out_reg_hi, false_reg_hi, cond_reg |
| 5236 | can_move_conditionally = true; |
| 5237 | use_const_for_true_in = true; |
| 5238 | } else if (is_false_value_zero_constant) { |
| 5239 | // selnez out_reg_lo, true_reg_lo, cond_reg |
| 5240 | // selnez out_reg_hi, true_reg_hi, cond_reg |
| 5241 | can_move_conditionally = true; |
| 5242 | use_const_for_false_in = true; |
| 5243 | } |
| 5244 | // Other long conditional moves would generate 6+ instructions, |
| 5245 | // which is too many. |
| 5246 | } else { |
| 5247 | // movn out_reg_lo, true_reg_lo/ZERO, cond_reg |
| 5248 | // movn out_reg_hi, true_reg_hi/ZERO, cond_reg |
| 5249 | can_move_conditionally = true; |
| 5250 | use_const_for_true_in = is_true_value_zero_constant; |
| 5251 | } |
| 5252 | break; |
| 5253 | case Primitive::kPrimFloat: |
| 5254 | case Primitive::kPrimDouble: |
| 5255 | // Moving float/double on int condition. |
| 5256 | if (is_r6) { |
| 5257 | if (materialized) { |
| 5258 | // Not materializing unmaterialized int conditions |
| 5259 | // to keep the instruction count low. |
| 5260 | can_move_conditionally = true; |
| 5261 | if (is_true_value_zero_constant) { |
| 5262 | // sltu TMP, ZERO, cond_reg |
| 5263 | // mtc1 TMP, temp_cond_reg |
| 5264 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 5265 | use_const_for_true_in = true; |
| 5266 | } else if (is_false_value_zero_constant) { |
| 5267 | // sltu TMP, ZERO, cond_reg |
| 5268 | // mtc1 TMP, temp_cond_reg |
| 5269 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 5270 | use_const_for_false_in = true; |
| 5271 | } else { |
| 5272 | // sltu TMP, ZERO, cond_reg |
| 5273 | // mtc1 TMP, temp_cond_reg |
| 5274 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 5275 | // mov.fmt out_reg, temp_cond_reg |
| 5276 | } |
| 5277 | } |
| 5278 | } else { |
| 5279 | // movn.fmt out_reg, true_reg, cond_reg |
| 5280 | can_move_conditionally = true; |
| 5281 | } |
| 5282 | break; |
| 5283 | } |
| 5284 | break; |
| 5285 | case Primitive::kPrimLong: |
| 5286 | // We don't materialize long comparison now |
| 5287 | // and use conditional branches instead. |
| 5288 | break; |
| 5289 | case Primitive::kPrimFloat: |
| 5290 | case Primitive::kPrimDouble: |
| 5291 | switch (dst_type) { |
| 5292 | default: |
| 5293 | // Moving int on float/double condition. |
| 5294 | if (is_r6) { |
| 5295 | if (is_true_value_zero_constant) { |
| 5296 | // mfc1 TMP, temp_cond_reg |
| 5297 | // seleqz out_reg, false_reg, TMP |
| 5298 | can_move_conditionally = true; |
| 5299 | use_const_for_true_in = true; |
| 5300 | } else if (is_false_value_zero_constant) { |
| 5301 | // mfc1 TMP, temp_cond_reg |
| 5302 | // selnez out_reg, true_reg, TMP |
| 5303 | can_move_conditionally = true; |
| 5304 | use_const_for_false_in = true; |
| 5305 | } else { |
| 5306 | // mfc1 TMP, temp_cond_reg |
| 5307 | // selnez AT, true_reg, TMP |
| 5308 | // seleqz TMP, false_reg, TMP |
| 5309 | // or out_reg, AT, TMP |
| 5310 | can_move_conditionally = true; |
| 5311 | } |
| 5312 | } else { |
| 5313 | // movt out_reg, true_reg/ZERO, cc |
| 5314 | can_move_conditionally = true; |
| 5315 | use_const_for_true_in = is_true_value_zero_constant; |
| 5316 | } |
| 5317 | break; |
| 5318 | case Primitive::kPrimLong: |
| 5319 | // Moving long on float/double condition. |
| 5320 | if (is_r6) { |
| 5321 | if (is_true_value_zero_constant) { |
| 5322 | // mfc1 TMP, temp_cond_reg |
| 5323 | // seleqz out_reg_lo, false_reg_lo, TMP |
| 5324 | // seleqz out_reg_hi, false_reg_hi, TMP |
| 5325 | can_move_conditionally = true; |
| 5326 | use_const_for_true_in = true; |
| 5327 | } else if (is_false_value_zero_constant) { |
| 5328 | // mfc1 TMP, temp_cond_reg |
| 5329 | // selnez out_reg_lo, true_reg_lo, TMP |
| 5330 | // selnez out_reg_hi, true_reg_hi, TMP |
| 5331 | can_move_conditionally = true; |
| 5332 | use_const_for_false_in = true; |
| 5333 | } |
| 5334 | // Other long conditional moves would generate 6+ instructions, |
| 5335 | // which is too many. |
| 5336 | } else { |
| 5337 | // movt out_reg_lo, true_reg_lo/ZERO, cc |
| 5338 | // movt out_reg_hi, true_reg_hi/ZERO, cc |
| 5339 | can_move_conditionally = true; |
| 5340 | use_const_for_true_in = is_true_value_zero_constant; |
| 5341 | } |
| 5342 | break; |
| 5343 | case Primitive::kPrimFloat: |
| 5344 | case Primitive::kPrimDouble: |
| 5345 | // Moving float/double on float/double condition. |
| 5346 | if (is_r6) { |
| 5347 | can_move_conditionally = true; |
| 5348 | if (is_true_value_zero_constant) { |
| 5349 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 5350 | use_const_for_true_in = true; |
| 5351 | } else if (is_false_value_zero_constant) { |
| 5352 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 5353 | use_const_for_false_in = true; |
| 5354 | } else { |
| 5355 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 5356 | // mov.fmt out_reg, temp_cond_reg |
| 5357 | } |
| 5358 | } else { |
| 5359 | // movt.fmt out_reg, true_reg, cc |
| 5360 | can_move_conditionally = true; |
| 5361 | } |
| 5362 | break; |
| 5363 | } |
| 5364 | break; |
| 5365 | } |
| 5366 | } |
| 5367 | |
| 5368 | if (can_move_conditionally) { |
| 5369 | DCHECK(!use_const_for_false_in || !use_const_for_true_in); |
| 5370 | } else { |
| 5371 | DCHECK(!use_const_for_false_in); |
| 5372 | DCHECK(!use_const_for_true_in); |
| 5373 | } |
| 5374 | |
| 5375 | if (locations_to_set != nullptr) { |
| 5376 | if (use_const_for_false_in) { |
| 5377 | locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value)); |
| 5378 | } else { |
| 5379 | locations_to_set->SetInAt(0, |
| 5380 | Primitive::IsFloatingPointType(dst_type) |
| 5381 | ? Location::RequiresFpuRegister() |
| 5382 | : Location::RequiresRegister()); |
| 5383 | } |
| 5384 | if (use_const_for_true_in) { |
| 5385 | locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value)); |
| 5386 | } else { |
| 5387 | locations_to_set->SetInAt(1, |
| 5388 | Primitive::IsFloatingPointType(dst_type) |
| 5389 | ? Location::RequiresFpuRegister() |
| 5390 | : Location::RequiresRegister()); |
| 5391 | } |
| 5392 | if (materialized) { |
| 5393 | locations_to_set->SetInAt(2, Location::RequiresRegister()); |
| 5394 | } |
| 5395 | // On R6 we don't require the output to be the same as the |
| 5396 | // first input for conditional moves unlike on R2. |
| 5397 | bool is_out_same_as_first_in = !can_move_conditionally || !is_r6; |
| 5398 | if (is_out_same_as_first_in) { |
| 5399 | locations_to_set->SetOut(Location::SameAsFirstInput()); |
| 5400 | } else { |
| 5401 | locations_to_set->SetOut(Primitive::IsFloatingPointType(dst_type) |
| 5402 | ? Location::RequiresFpuRegister() |
| 5403 | : Location::RequiresRegister()); |
| 5404 | } |
| 5405 | } |
| 5406 | |
| 5407 | return can_move_conditionally; |
| 5408 | } |
| 5409 | |
| 5410 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR2(HSelect* select) { |
| 5411 | LocationSummary* locations = select->GetLocations(); |
| 5412 | Location dst = locations->Out(); |
| 5413 | Location src = locations->InAt(1); |
| 5414 | Register src_reg = ZERO; |
| 5415 | Register src_reg_high = ZERO; |
| 5416 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 5417 | Register cond_reg = TMP; |
| 5418 | int cond_cc = 0; |
| 5419 | Primitive::Type cond_type = Primitive::kPrimInt; |
| 5420 | bool cond_inverted = false; |
| 5421 | Primitive::Type dst_type = select->GetType(); |
| 5422 | |
| 5423 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 5424 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 5425 | } else { |
| 5426 | HCondition* condition = cond->AsCondition(); |
| 5427 | LocationSummary* cond_locations = cond->GetLocations(); |
| 5428 | IfCondition if_cond = condition->GetCondition(); |
| 5429 | cond_type = condition->InputAt(0)->GetType(); |
| 5430 | switch (cond_type) { |
| 5431 | default: |
| 5432 | DCHECK_NE(cond_type, Primitive::kPrimLong); |
| 5433 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 5434 | break; |
| 5435 | case Primitive::kPrimFloat: |
| 5436 | case Primitive::kPrimDouble: |
| 5437 | cond_inverted = MaterializeFpCompareR2(if_cond, |
| 5438 | condition->IsGtBias(), |
| 5439 | cond_type, |
| 5440 | cond_locations, |
| 5441 | cond_cc); |
| 5442 | break; |
| 5443 | } |
| 5444 | } |
| 5445 | |
| 5446 | DCHECK(dst.Equals(locations->InAt(0))); |
| 5447 | if (src.IsRegister()) { |
| 5448 | src_reg = src.AsRegister<Register>(); |
| 5449 | } else if (src.IsRegisterPair()) { |
| 5450 | src_reg = src.AsRegisterPairLow<Register>(); |
| 5451 | src_reg_high = src.AsRegisterPairHigh<Register>(); |
| 5452 | } else if (src.IsConstant()) { |
| 5453 | DCHECK(src.GetConstant()->IsZeroBitPattern()); |
| 5454 | } |
| 5455 | |
| 5456 | switch (cond_type) { |
| 5457 | default: |
| 5458 | switch (dst_type) { |
| 5459 | default: |
| 5460 | if (cond_inverted) { |
| 5461 | __ Movz(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 5462 | } else { |
| 5463 | __ Movn(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 5464 | } |
| 5465 | break; |
| 5466 | case Primitive::kPrimLong: |
| 5467 | if (cond_inverted) { |
| 5468 | __ Movz(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 5469 | __ Movz(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 5470 | } else { |
| 5471 | __ Movn(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 5472 | __ Movn(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 5473 | } |
| 5474 | break; |
| 5475 | case Primitive::kPrimFloat: |
| 5476 | if (cond_inverted) { |
| 5477 | __ MovzS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 5478 | } else { |
| 5479 | __ MovnS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 5480 | } |
| 5481 | break; |
| 5482 | case Primitive::kPrimDouble: |
| 5483 | if (cond_inverted) { |
| 5484 | __ MovzD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 5485 | } else { |
| 5486 | __ MovnD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 5487 | } |
| 5488 | break; |
| 5489 | } |
| 5490 | break; |
| 5491 | case Primitive::kPrimLong: |
| 5492 | LOG(FATAL) << "Unreachable"; |
| 5493 | UNREACHABLE(); |
| 5494 | case Primitive::kPrimFloat: |
| 5495 | case Primitive::kPrimDouble: |
| 5496 | switch (dst_type) { |
| 5497 | default: |
| 5498 | if (cond_inverted) { |
| 5499 | __ Movf(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 5500 | } else { |
| 5501 | __ Movt(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 5502 | } |
| 5503 | break; |
| 5504 | case Primitive::kPrimLong: |
| 5505 | if (cond_inverted) { |
| 5506 | __ Movf(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 5507 | __ Movf(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 5508 | } else { |
| 5509 | __ Movt(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 5510 | __ Movt(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 5511 | } |
| 5512 | break; |
| 5513 | case Primitive::kPrimFloat: |
| 5514 | if (cond_inverted) { |
| 5515 | __ MovfS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 5516 | } else { |
| 5517 | __ MovtS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 5518 | } |
| 5519 | break; |
| 5520 | case Primitive::kPrimDouble: |
| 5521 | if (cond_inverted) { |
| 5522 | __ MovfD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 5523 | } else { |
| 5524 | __ MovtD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 5525 | } |
| 5526 | break; |
| 5527 | } |
| 5528 | break; |
| 5529 | } |
| 5530 | } |
| 5531 | |
| 5532 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR6(HSelect* select) { |
| 5533 | LocationSummary* locations = select->GetLocations(); |
| 5534 | Location dst = locations->Out(); |
| 5535 | Location false_src = locations->InAt(0); |
| 5536 | Location true_src = locations->InAt(1); |
| 5537 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 5538 | Register cond_reg = TMP; |
| 5539 | FRegister fcond_reg = FTMP; |
| 5540 | Primitive::Type cond_type = Primitive::kPrimInt; |
| 5541 | bool cond_inverted = false; |
| 5542 | Primitive::Type dst_type = select->GetType(); |
| 5543 | |
| 5544 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 5545 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 5546 | } else { |
| 5547 | HCondition* condition = cond->AsCondition(); |
| 5548 | LocationSummary* cond_locations = cond->GetLocations(); |
| 5549 | IfCondition if_cond = condition->GetCondition(); |
| 5550 | cond_type = condition->InputAt(0)->GetType(); |
| 5551 | switch (cond_type) { |
| 5552 | default: |
| 5553 | DCHECK_NE(cond_type, Primitive::kPrimLong); |
| 5554 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 5555 | break; |
| 5556 | case Primitive::kPrimFloat: |
| 5557 | case Primitive::kPrimDouble: |
| 5558 | cond_inverted = MaterializeFpCompareR6(if_cond, |
| 5559 | condition->IsGtBias(), |
| 5560 | cond_type, |
| 5561 | cond_locations, |
| 5562 | fcond_reg); |
| 5563 | break; |
| 5564 | } |
| 5565 | } |
| 5566 | |
| 5567 | if (true_src.IsConstant()) { |
| 5568 | DCHECK(true_src.GetConstant()->IsZeroBitPattern()); |
| 5569 | } |
| 5570 | if (false_src.IsConstant()) { |
| 5571 | DCHECK(false_src.GetConstant()->IsZeroBitPattern()); |
| 5572 | } |
| 5573 | |
| 5574 | switch (dst_type) { |
| 5575 | default: |
| 5576 | if (Primitive::IsFloatingPointType(cond_type)) { |
| 5577 | __ Mfc1(cond_reg, fcond_reg); |
| 5578 | } |
| 5579 | if (true_src.IsConstant()) { |
| 5580 | if (cond_inverted) { |
| 5581 | __ Selnez(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 5582 | } else { |
| 5583 | __ Seleqz(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 5584 | } |
| 5585 | } else if (false_src.IsConstant()) { |
| 5586 | if (cond_inverted) { |
| 5587 | __ Seleqz(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 5588 | } else { |
| 5589 | __ Selnez(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 5590 | } |
| 5591 | } else { |
| 5592 | DCHECK_NE(cond_reg, AT); |
| 5593 | if (cond_inverted) { |
| 5594 | __ Seleqz(AT, true_src.AsRegister<Register>(), cond_reg); |
| 5595 | __ Selnez(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 5596 | } else { |
| 5597 | __ Selnez(AT, true_src.AsRegister<Register>(), cond_reg); |
| 5598 | __ Seleqz(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 5599 | } |
| 5600 | __ Or(dst.AsRegister<Register>(), AT, TMP); |
| 5601 | } |
| 5602 | break; |
| 5603 | case Primitive::kPrimLong: { |
| 5604 | if (Primitive::IsFloatingPointType(cond_type)) { |
| 5605 | __ Mfc1(cond_reg, fcond_reg); |
| 5606 | } |
| 5607 | Register dst_lo = dst.AsRegisterPairLow<Register>(); |
| 5608 | Register dst_hi = dst.AsRegisterPairHigh<Register>(); |
| 5609 | if (true_src.IsConstant()) { |
| 5610 | Register src_lo = false_src.AsRegisterPairLow<Register>(); |
| 5611 | Register src_hi = false_src.AsRegisterPairHigh<Register>(); |
| 5612 | if (cond_inverted) { |
| 5613 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 5614 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 5615 | } else { |
| 5616 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 5617 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 5618 | } |
| 5619 | } else { |
| 5620 | DCHECK(false_src.IsConstant()); |
| 5621 | Register src_lo = true_src.AsRegisterPairLow<Register>(); |
| 5622 | Register src_hi = true_src.AsRegisterPairHigh<Register>(); |
| 5623 | if (cond_inverted) { |
| 5624 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 5625 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 5626 | } else { |
| 5627 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 5628 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 5629 | } |
| 5630 | } |
| 5631 | break; |
| 5632 | } |
| 5633 | case Primitive::kPrimFloat: { |
| 5634 | if (!Primitive::IsFloatingPointType(cond_type)) { |
| 5635 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 5636 | __ Sltu(TMP, ZERO, cond_reg); |
| 5637 | __ Mtc1(TMP, fcond_reg); |
| 5638 | } |
| 5639 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 5640 | if (true_src.IsConstant()) { |
| 5641 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 5642 | if (cond_inverted) { |
| 5643 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 5644 | } else { |
| 5645 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 5646 | } |
| 5647 | } else if (false_src.IsConstant()) { |
| 5648 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 5649 | if (cond_inverted) { |
| 5650 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 5651 | } else { |
| 5652 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 5653 | } |
| 5654 | } else { |
| 5655 | if (cond_inverted) { |
| 5656 | __ SelS(fcond_reg, |
| 5657 | true_src.AsFpuRegister<FRegister>(), |
| 5658 | false_src.AsFpuRegister<FRegister>()); |
| 5659 | } else { |
| 5660 | __ SelS(fcond_reg, |
| 5661 | false_src.AsFpuRegister<FRegister>(), |
| 5662 | true_src.AsFpuRegister<FRegister>()); |
| 5663 | } |
| 5664 | __ MovS(dst_reg, fcond_reg); |
| 5665 | } |
| 5666 | break; |
| 5667 | } |
| 5668 | case Primitive::kPrimDouble: { |
| 5669 | if (!Primitive::IsFloatingPointType(cond_type)) { |
| 5670 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 5671 | __ Sltu(TMP, ZERO, cond_reg); |
| 5672 | __ Mtc1(TMP, fcond_reg); |
| 5673 | } |
| 5674 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 5675 | if (true_src.IsConstant()) { |
| 5676 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 5677 | if (cond_inverted) { |
| 5678 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 5679 | } else { |
| 5680 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 5681 | } |
| 5682 | } else if (false_src.IsConstant()) { |
| 5683 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 5684 | if (cond_inverted) { |
| 5685 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 5686 | } else { |
| 5687 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 5688 | } |
| 5689 | } else { |
| 5690 | if (cond_inverted) { |
| 5691 | __ SelD(fcond_reg, |
| 5692 | true_src.AsFpuRegister<FRegister>(), |
| 5693 | false_src.AsFpuRegister<FRegister>()); |
| 5694 | } else { |
| 5695 | __ SelD(fcond_reg, |
| 5696 | false_src.AsFpuRegister<FRegister>(), |
| 5697 | true_src.AsFpuRegister<FRegister>()); |
| 5698 | } |
| 5699 | __ MovD(dst_reg, fcond_reg); |
| 5700 | } |
| 5701 | break; |
| 5702 | } |
| 5703 | } |
| 5704 | } |
| 5705 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 5706 | void LocationsBuilderMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 5707 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 5708 | LocationSummary(flag, LocationSummary::kNoCall); |
| 5709 | locations->SetOut(Location::RequiresRegister()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 5710 | } |
| 5711 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 5712 | void InstructionCodeGeneratorMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 5713 | __ LoadFromOffset(kLoadWord, |
| 5714 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 5715 | SP, |
| 5716 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 5717 | } |
| 5718 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5719 | void LocationsBuilderMIPS::VisitSelect(HSelect* select) { |
| 5720 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5721 | CanMoveConditionally(select, codegen_->GetInstructionSetFeatures().IsR6(), locations); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5722 | } |
| 5723 | |
| 5724 | void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 5725 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 5726 | if (CanMoveConditionally(select, is_r6, /* locations_to_set */ nullptr)) { |
| 5727 | if (is_r6) { |
| 5728 | GenConditionalMoveR6(select); |
| 5729 | } else { |
| 5730 | GenConditionalMoveR2(select); |
| 5731 | } |
| 5732 | } else { |
| 5733 | LocationSummary* locations = select->GetLocations(); |
| 5734 | MipsLabel false_target; |
| 5735 | GenerateTestAndBranch(select, |
| 5736 | /* condition_input_index */ 2, |
| 5737 | /* true_target */ nullptr, |
| 5738 | &false_target); |
| 5739 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 5740 | __ Bind(&false_target); |
| 5741 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5742 | } |
| 5743 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 5744 | void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 5745 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 5746 | } |
| 5747 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 5748 | void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 5749 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 5750 | } |
| 5751 | |
| 5752 | void CodeGeneratorMIPS::GenerateNop() { |
| 5753 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 5754 | } |
| 5755 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5756 | void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5757 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5758 | bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble); |
| 5759 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5760 | bool object_field_get_with_read_barrier = |
| 5761 | kEmitCompilerReadBarrier && (field_type == Primitive::kPrimNot); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5762 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5763 | instruction, |
| 5764 | generate_volatile |
| 5765 | ? LocationSummary::kCallOnMainOnly |
| 5766 | : (object_field_get_with_read_barrier |
| 5767 | ? LocationSummary::kCallOnSlowPath |
| 5768 | : LocationSummary::kNoCall)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5769 | |
| 5770 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5771 | if (generate_volatile) { |
| 5772 | InvokeRuntimeCallingConvention calling_convention; |
| 5773 | // need A0 to hold base + offset |
| 5774 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5775 | if (field_type == Primitive::kPrimLong) { |
| 5776 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimLong)); |
| 5777 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 5778 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 5779 | locations->SetOut(Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5780 | // Need some temp core regs since FP results are returned in core registers |
| 5781 | Location reg = calling_convention.GetReturnLocation(Primitive::kPrimLong); |
| 5782 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>())); |
| 5783 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>())); |
| 5784 | } |
| 5785 | } else { |
| 5786 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5787 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5788 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5789 | // The output overlaps in the case of an object field get with |
| 5790 | // read barriers enabled: we do not want the move to overwrite the |
| 5791 | // object's location, as we need it to emit the read barrier. |
| 5792 | locations->SetOut(Location::RequiresRegister(), |
| 5793 | object_field_get_with_read_barrier |
| 5794 | ? Location::kOutputOverlap |
| 5795 | : Location::kNoOutputOverlap); |
| 5796 | } |
| 5797 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5798 | // We need a temporary register for the read barrier marking slow |
| 5799 | // path in CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier. |
| 5800 | locations->AddTemp(Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5801 | } |
| 5802 | } |
| 5803 | } |
| 5804 | |
| 5805 | void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction, |
| 5806 | const FieldInfo& field_info, |
| 5807 | uint32_t dex_pc) { |
| 5808 | Primitive::Type type = field_info.GetFieldType(); |
| 5809 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5810 | Location obj_loc = locations->InAt(0); |
| 5811 | Register obj = obj_loc.AsRegister<Register>(); |
| 5812 | Location dst_loc = locations->Out(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5813 | LoadOperandType load_type = kLoadUnsignedByte; |
| 5814 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 5815 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 5816 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5817 | |
| 5818 | switch (type) { |
| 5819 | case Primitive::kPrimBoolean: |
| 5820 | load_type = kLoadUnsignedByte; |
| 5821 | break; |
| 5822 | case Primitive::kPrimByte: |
| 5823 | load_type = kLoadSignedByte; |
| 5824 | break; |
| 5825 | case Primitive::kPrimShort: |
| 5826 | load_type = kLoadSignedHalfword; |
| 5827 | break; |
| 5828 | case Primitive::kPrimChar: |
| 5829 | load_type = kLoadUnsignedHalfword; |
| 5830 | break; |
| 5831 | case Primitive::kPrimInt: |
| 5832 | case Primitive::kPrimFloat: |
| 5833 | case Primitive::kPrimNot: |
| 5834 | load_type = kLoadWord; |
| 5835 | break; |
| 5836 | case Primitive::kPrimLong: |
| 5837 | case Primitive::kPrimDouble: |
| 5838 | load_type = kLoadDoubleword; |
| 5839 | break; |
| 5840 | case Primitive::kPrimVoid: |
| 5841 | LOG(FATAL) << "Unreachable type " << type; |
| 5842 | UNREACHABLE(); |
| 5843 | } |
| 5844 | |
| 5845 | if (is_volatile && load_type == kLoadDoubleword) { |
| 5846 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 5847 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5848 | // Do implicit Null check |
| 5849 | __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0); |
| 5850 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 5851 | codegen_->InvokeRuntime(kQuickA64Load, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5852 | CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>(); |
| 5853 | if (type == Primitive::kPrimDouble) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 5854 | // FP results are returned in core registers. Need to move them. |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5855 | if (dst_loc.IsFpuRegister()) { |
| 5856 | __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), dst_loc.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 5857 | __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5858 | dst_loc.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 5859 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5860 | DCHECK(dst_loc.IsDoubleStackSlot()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 5861 | __ StoreToOffset(kStoreWord, |
| 5862 | locations->GetTemp(1).AsRegister<Register>(), |
| 5863 | SP, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5864 | dst_loc.GetStackIndex()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 5865 | __ StoreToOffset(kStoreWord, |
| 5866 | locations->GetTemp(2).AsRegister<Register>(), |
| 5867 | SP, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5868 | dst_loc.GetStackIndex() + 4); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 5869 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5870 | } |
| 5871 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5872 | if (type == Primitive::kPrimNot) { |
| 5873 | // /* HeapReference<Object> */ dst = *(obj + offset) |
| 5874 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5875 | Location temp_loc = locations->GetTemp(0); |
| 5876 | // Note that a potential implicit null check is handled in this |
| 5877 | // CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier call. |
| 5878 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5879 | dst_loc, |
| 5880 | obj, |
| 5881 | offset, |
| 5882 | temp_loc, |
| 5883 | /* needs_null_check */ true); |
| 5884 | if (is_volatile) { |
| 5885 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5886 | } |
| 5887 | } else { |
| 5888 | __ LoadFromOffset(kLoadWord, dst_loc.AsRegister<Register>(), obj, offset, null_checker); |
| 5889 | if (is_volatile) { |
| 5890 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5891 | } |
| 5892 | // If read barriers are enabled, emit read barriers other than |
| 5893 | // Baker's using a slow path (and also unpoison the loaded |
| 5894 | // reference, if heap poisoning is enabled). |
| 5895 | codegen_->MaybeGenerateReadBarrierSlow(instruction, dst_loc, dst_loc, obj_loc, offset); |
| 5896 | } |
| 5897 | } else if (!Primitive::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5898 | Register dst; |
| 5899 | if (type == Primitive::kPrimLong) { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5900 | DCHECK(dst_loc.IsRegisterPair()); |
| 5901 | dst = dst_loc.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5902 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5903 | DCHECK(dst_loc.IsRegister()); |
| 5904 | dst = dst_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5905 | } |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 5906 | __ LoadFromOffset(load_type, dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5907 | } else { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5908 | DCHECK(dst_loc.IsFpuRegister()); |
| 5909 | FRegister dst = dst_loc.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5910 | if (type == Primitive::kPrimFloat) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 5911 | __ LoadSFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5912 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 5913 | __ LoadDFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5914 | } |
| 5915 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5916 | } |
| 5917 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 5918 | // Memory barriers, in the case of references, are handled in the |
| 5919 | // previous switch statement. |
| 5920 | if (is_volatile && (type != Primitive::kPrimNot)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5921 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5922 | } |
| 5923 | } |
| 5924 | |
| 5925 | void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5926 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5927 | bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble); |
| 5928 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
| 5929 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5930 | instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5931 | |
| 5932 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5933 | if (generate_volatile) { |
| 5934 | InvokeRuntimeCallingConvention calling_convention; |
| 5935 | // need A0 to hold base + offset |
| 5936 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5937 | if (field_type == Primitive::kPrimLong) { |
| 5938 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 5939 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 5940 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 5941 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 5942 | locations->SetInAt(1, Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5943 | // Pass FP parameters in core registers. |
| 5944 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 5945 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3))); |
| 5946 | } |
| 5947 | } else { |
| 5948 | if (Primitive::IsFloatingPointType(field_type)) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 5949 | locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5950 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 5951 | locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5952 | } |
| 5953 | } |
| 5954 | } |
| 5955 | |
| 5956 | void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction, |
| 5957 | const FieldInfo& field_info, |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 5958 | uint32_t dex_pc, |
| 5959 | bool value_can_be_null) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5960 | Primitive::Type type = field_info.GetFieldType(); |
| 5961 | LocationSummary* locations = instruction->GetLocations(); |
| 5962 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 5963 | Location value_location = locations->InAt(1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5964 | StoreOperandType store_type = kStoreByte; |
| 5965 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 5966 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5967 | bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1)); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 5968 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5969 | |
| 5970 | switch (type) { |
| 5971 | case Primitive::kPrimBoolean: |
| 5972 | case Primitive::kPrimByte: |
| 5973 | store_type = kStoreByte; |
| 5974 | break; |
| 5975 | case Primitive::kPrimShort: |
| 5976 | case Primitive::kPrimChar: |
| 5977 | store_type = kStoreHalfword; |
| 5978 | break; |
| 5979 | case Primitive::kPrimInt: |
| 5980 | case Primitive::kPrimFloat: |
| 5981 | case Primitive::kPrimNot: |
| 5982 | store_type = kStoreWord; |
| 5983 | break; |
| 5984 | case Primitive::kPrimLong: |
| 5985 | case Primitive::kPrimDouble: |
| 5986 | store_type = kStoreDoubleword; |
| 5987 | break; |
| 5988 | case Primitive::kPrimVoid: |
| 5989 | LOG(FATAL) << "Unreachable type " << type; |
| 5990 | UNREACHABLE(); |
| 5991 | } |
| 5992 | |
| 5993 | if (is_volatile) { |
| 5994 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 5995 | } |
| 5996 | |
| 5997 | if (is_volatile && store_type == kStoreDoubleword) { |
| 5998 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 5999 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6000 | // Do implicit Null check. |
| 6001 | __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0); |
| 6002 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 6003 | if (type == Primitive::kPrimDouble) { |
| 6004 | // Pass FP parameters in core registers. |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6005 | if (value_location.IsFpuRegister()) { |
| 6006 | __ Mfc1(locations->GetTemp(1).AsRegister<Register>(), |
| 6007 | value_location.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6008 | __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6009 | value_location.AsFpuRegister<FRegister>()); |
| 6010 | } else if (value_location.IsDoubleStackSlot()) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6011 | __ LoadFromOffset(kLoadWord, |
| 6012 | locations->GetTemp(1).AsRegister<Register>(), |
| 6013 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6014 | value_location.GetStackIndex()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6015 | __ LoadFromOffset(kLoadWord, |
| 6016 | locations->GetTemp(2).AsRegister<Register>(), |
| 6017 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6018 | value_location.GetStackIndex() + 4); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6019 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6020 | DCHECK(value_location.IsConstant()); |
| 6021 | DCHECK(value_location.GetConstant()->IsDoubleConstant()); |
| 6022 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 6023 | __ LoadConst64(locations->GetTemp(2).AsRegister<Register>(), |
| 6024 | locations->GetTemp(1).AsRegister<Register>(), |
| 6025 | value); |
| 6026 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6027 | } |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6028 | codegen_->InvokeRuntime(kQuickA64Store, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6029 | CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>(); |
| 6030 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6031 | if (value_location.IsConstant()) { |
| 6032 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 6033 | __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker); |
| 6034 | } else if (!Primitive::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6035 | Register src; |
| 6036 | if (type == Primitive::kPrimLong) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6037 | src = value_location.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6038 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6039 | src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6040 | } |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6041 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 6042 | // Note that in the case where `value` is a null reference, |
| 6043 | // we do not enter this block, as a null reference does not |
| 6044 | // need poisoning. |
| 6045 | DCHECK_EQ(type, Primitive::kPrimNot); |
| 6046 | __ PoisonHeapReference(TMP, src); |
| 6047 | __ StoreToOffset(store_type, TMP, obj, offset, null_checker); |
| 6048 | } else { |
| 6049 | __ StoreToOffset(store_type, src, obj, offset, null_checker); |
| 6050 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6051 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6052 | FRegister src = value_location.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6053 | if (type == Primitive::kPrimFloat) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6054 | __ StoreSToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6055 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 6056 | __ StoreDToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6057 | } |
| 6058 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6059 | } |
| 6060 | |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6061 | if (needs_write_barrier) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 6062 | Register src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6063 | codegen_->MarkGCCard(obj, src, value_can_be_null); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6064 | } |
| 6065 | |
| 6066 | if (is_volatile) { |
| 6067 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 6068 | } |
| 6069 | } |
| 6070 | |
| 6071 | void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6072 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6073 | } |
| 6074 | |
| 6075 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6076 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 6077 | } |
| 6078 | |
| 6079 | void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 6080 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6081 | } |
| 6082 | |
| 6083 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6084 | HandleFieldSet(instruction, |
| 6085 | instruction->GetFieldInfo(), |
| 6086 | instruction->GetDexPc(), |
| 6087 | instruction->GetValueCanBeNull()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6088 | } |
| 6089 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6090 | void InstructionCodeGeneratorMIPS::GenerateReferenceLoadOneRegister( |
| 6091 | HInstruction* instruction, |
| 6092 | Location out, |
| 6093 | uint32_t offset, |
| 6094 | Location maybe_temp, |
| 6095 | ReadBarrierOption read_barrier_option) { |
| 6096 | Register out_reg = out.AsRegister<Register>(); |
| 6097 | if (read_barrier_option == kWithReadBarrier) { |
| 6098 | CHECK(kEmitCompilerReadBarrier); |
| 6099 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 6100 | if (kUseBakerReadBarrier) { |
| 6101 | // Load with fast path based Baker's read barrier. |
| 6102 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6103 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6104 | out, |
| 6105 | out_reg, |
| 6106 | offset, |
| 6107 | maybe_temp, |
| 6108 | /* needs_null_check */ false); |
| 6109 | } else { |
| 6110 | // Load with slow path based read barrier. |
| 6111 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 6112 | // in the following move operation, as we will need it for the |
| 6113 | // read barrier below. |
| 6114 | __ Move(maybe_temp.AsRegister<Register>(), out_reg); |
| 6115 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6116 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6117 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 6118 | } |
| 6119 | } else { |
| 6120 | // Plain load with no read barrier. |
| 6121 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6122 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6123 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6124 | } |
| 6125 | } |
| 6126 | |
| 6127 | void InstructionCodeGeneratorMIPS::GenerateReferenceLoadTwoRegisters( |
| 6128 | HInstruction* instruction, |
| 6129 | Location out, |
| 6130 | Location obj, |
| 6131 | uint32_t offset, |
| 6132 | Location maybe_temp, |
| 6133 | ReadBarrierOption read_barrier_option) { |
| 6134 | Register out_reg = out.AsRegister<Register>(); |
| 6135 | Register obj_reg = obj.AsRegister<Register>(); |
| 6136 | if (read_barrier_option == kWithReadBarrier) { |
| 6137 | CHECK(kEmitCompilerReadBarrier); |
| 6138 | if (kUseBakerReadBarrier) { |
| 6139 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 6140 | // Load with fast path based Baker's read barrier. |
| 6141 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6142 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6143 | out, |
| 6144 | obj_reg, |
| 6145 | offset, |
| 6146 | maybe_temp, |
| 6147 | /* needs_null_check */ false); |
| 6148 | } else { |
| 6149 | // Load with slow path based read barrier. |
| 6150 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6151 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6152 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6153 | } |
| 6154 | } else { |
| 6155 | // Plain load with no read barrier. |
| 6156 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6157 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6158 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6159 | } |
| 6160 | } |
| 6161 | |
| 6162 | void InstructionCodeGeneratorMIPS::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6163 | Location root, |
| 6164 | Register obj, |
| 6165 | uint32_t offset, |
| 6166 | ReadBarrierOption read_barrier_option) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6167 | Register root_reg = root.AsRegister<Register>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6168 | if (read_barrier_option == kWithReadBarrier) { |
| 6169 | DCHECK(kEmitCompilerReadBarrier); |
| 6170 | if (kUseBakerReadBarrier) { |
| 6171 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6172 | // Baker's read barrier are used: |
| 6173 | // |
| 6174 | // root = obj.field; |
| 6175 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6176 | // if (temp != null) { |
| 6177 | // root = temp(root) |
| 6178 | // } |
| 6179 | |
| 6180 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6181 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6182 | static_assert( |
| 6183 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6184 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6185 | "have different sizes."); |
| 6186 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6187 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6188 | "have different sizes."); |
| 6189 | |
| 6190 | // Slow path marking the GC root `root`. |
| 6191 | Location temp = Location::RegisterLocation(T9); |
| 6192 | SlowPathCodeMIPS* slow_path = |
| 6193 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathMIPS( |
| 6194 | instruction, |
| 6195 | root, |
| 6196 | /*entrypoint*/ temp); |
| 6197 | codegen_->AddSlowPath(slow_path); |
| 6198 | |
| 6199 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6200 | const int32_t entry_point_offset = |
| 6201 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kMipsPointerSize>(root.reg() - 1); |
| 6202 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6203 | // threads are suspended or running a checkpoint. |
| 6204 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset); |
| 6205 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 6206 | // checking GetIsGcMarking. |
| 6207 | __ Bnez(temp.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 6208 | __ Bind(slow_path->GetExitLabel()); |
| 6209 | } else { |
| 6210 | // GC root loaded through a slow path for read barriers other |
| 6211 | // than Baker's. |
| 6212 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6213 | __ Addiu32(root_reg, obj, offset); |
| 6214 | // /* mirror::Object* */ root = root->Read() |
| 6215 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6216 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6217 | } else { |
| 6218 | // Plain GC root load with no read barrier. |
| 6219 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6220 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6221 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6222 | // do not have to unpoison `root_reg` here. |
| 6223 | } |
| 6224 | } |
| 6225 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6226 | void CodeGeneratorMIPS::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6227 | Location ref, |
| 6228 | Register obj, |
| 6229 | uint32_t offset, |
| 6230 | Location temp, |
| 6231 | bool needs_null_check) { |
| 6232 | DCHECK(kEmitCompilerReadBarrier); |
| 6233 | DCHECK(kUseBakerReadBarrier); |
| 6234 | |
| 6235 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6236 | Location no_index = Location::NoLocation(); |
| 6237 | ScaleFactor no_scale_factor = TIMES_1; |
| 6238 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6239 | ref, |
| 6240 | obj, |
| 6241 | offset, |
| 6242 | no_index, |
| 6243 | no_scale_factor, |
| 6244 | temp, |
| 6245 | needs_null_check); |
| 6246 | } |
| 6247 | |
| 6248 | void CodeGeneratorMIPS::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6249 | Location ref, |
| 6250 | Register obj, |
| 6251 | uint32_t data_offset, |
| 6252 | Location index, |
| 6253 | Location temp, |
| 6254 | bool needs_null_check) { |
| 6255 | DCHECK(kEmitCompilerReadBarrier); |
| 6256 | DCHECK(kUseBakerReadBarrier); |
| 6257 | |
| 6258 | static_assert( |
| 6259 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6260 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 6261 | // /* HeapReference<Object> */ ref = |
| 6262 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6263 | ScaleFactor scale_factor = TIMES_4; |
| 6264 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6265 | ref, |
| 6266 | obj, |
| 6267 | data_offset, |
| 6268 | index, |
| 6269 | scale_factor, |
| 6270 | temp, |
| 6271 | needs_null_check); |
| 6272 | } |
| 6273 | |
| 6274 | void CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6275 | Location ref, |
| 6276 | Register obj, |
| 6277 | uint32_t offset, |
| 6278 | Location index, |
| 6279 | ScaleFactor scale_factor, |
| 6280 | Location temp, |
| 6281 | bool needs_null_check, |
| 6282 | bool always_update_field) { |
| 6283 | DCHECK(kEmitCompilerReadBarrier); |
| 6284 | DCHECK(kUseBakerReadBarrier); |
| 6285 | |
| 6286 | // In slow path based read barriers, the read barrier call is |
| 6287 | // inserted after the original load. However, in fast path based |
| 6288 | // Baker's read barriers, we need to perform the load of |
| 6289 | // mirror::Object::monitor_ *before* the original reference load. |
| 6290 | // This load-load ordering is required by the read barrier. |
| 6291 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6292 | // |
| 6293 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6294 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6295 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6296 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6297 | // if (is_gray) { |
| 6298 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6299 | // } |
| 6300 | // |
| 6301 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6302 | // slightly more complex as it performs additional checks that we do |
| 6303 | // not do here for performance reasons. |
| 6304 | |
| 6305 | Register ref_reg = ref.AsRegister<Register>(); |
| 6306 | Register temp_reg = temp.AsRegister<Register>(); |
| 6307 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6308 | |
| 6309 | // /* int32_t */ monitor = obj->monitor_ |
| 6310 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 6311 | if (needs_null_check) { |
| 6312 | MaybeRecordImplicitNullCheck(instruction); |
| 6313 | } |
| 6314 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6315 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6316 | "art::LockWord and int32_t have different sizes."); |
| 6317 | |
| 6318 | __ Sync(0); // Barrier to prevent load-load reordering. |
| 6319 | |
| 6320 | // The actual reference load. |
| 6321 | if (index.IsValid()) { |
| 6322 | // Load types involving an "index": ArrayGet, |
| 6323 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 6324 | // intrinsics. |
| 6325 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 6326 | if (index.IsConstant()) { |
| 6327 | size_t computed_offset = |
| 6328 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
| 6329 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 6330 | } else { |
| 6331 | // Handle the special case of the |
| 6332 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 6333 | // intrinsics, which use a register pair as index ("long |
| 6334 | // offset"), of which only the low part contains data. |
| 6335 | Register index_reg = index.IsRegisterPair() |
| 6336 | ? index.AsRegisterPairLow<Register>() |
| 6337 | : index.AsRegister<Register>(); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 6338 | __ ShiftAndAdd(TMP, index_reg, obj, scale_factor, TMP); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6339 | __ LoadFromOffset(kLoadWord, ref_reg, TMP, offset); |
| 6340 | } |
| 6341 | } else { |
| 6342 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6343 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 6344 | } |
| 6345 | |
| 6346 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6347 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6348 | |
| 6349 | // Slow path marking the object `ref` when it is gray. |
| 6350 | SlowPathCodeMIPS* slow_path; |
| 6351 | if (always_update_field) { |
| 6352 | // ReadBarrierMarkAndUpdateFieldSlowPathMIPS only supports address |
| 6353 | // of the form `obj + field_offset`, where `obj` is a register and |
| 6354 | // `field_offset` is a register pair (of which only the lower half |
| 6355 | // is used). Thus `offset` and `scale_factor` above are expected |
| 6356 | // to be null in this code path. |
| 6357 | DCHECK_EQ(offset, 0u); |
| 6358 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
| 6359 | slow_path = new (GetGraph()->GetArena()) |
| 6360 | ReadBarrierMarkAndUpdateFieldSlowPathMIPS(instruction, |
| 6361 | ref, |
| 6362 | obj, |
| 6363 | /* field_offset */ index, |
| 6364 | temp_reg); |
| 6365 | } else { |
| 6366 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathMIPS(instruction, ref); |
| 6367 | } |
| 6368 | AddSlowPath(slow_path); |
| 6369 | |
| 6370 | // if (rb_state == ReadBarrier::GrayState()) |
| 6371 | // ref = ReadBarrier::Mark(ref); |
| 6372 | // Given the numeric representation, it's enough to check the low bit of the |
| 6373 | // rb_state. We do that by shifting the bit into the sign bit (31) and |
| 6374 | // performing a branch on less than zero. |
| 6375 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 6376 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 6377 | static_assert(LockWord::kReadBarrierStateSize == 1, "Expecting 1-bit read barrier state size"); |
| 6378 | __ Sll(temp_reg, temp_reg, 31 - LockWord::kReadBarrierStateShift); |
| 6379 | __ Bltz(temp_reg, slow_path->GetEntryLabel()); |
| 6380 | __ Bind(slow_path->GetExitLabel()); |
| 6381 | } |
| 6382 | |
| 6383 | void CodeGeneratorMIPS::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6384 | Location out, |
| 6385 | Location ref, |
| 6386 | Location obj, |
| 6387 | uint32_t offset, |
| 6388 | Location index) { |
| 6389 | DCHECK(kEmitCompilerReadBarrier); |
| 6390 | |
| 6391 | // Insert a slow path based read barrier *after* the reference load. |
| 6392 | // |
| 6393 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6394 | // reference will be carried out by the runtime within the slow |
| 6395 | // path. |
| 6396 | // |
| 6397 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6398 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6399 | // not used by the artReadBarrierSlow entry point. |
| 6400 | // |
| 6401 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6402 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) |
| 6403 | ReadBarrierForHeapReferenceSlowPathMIPS(instruction, out, ref, obj, offset, index); |
| 6404 | AddSlowPath(slow_path); |
| 6405 | |
| 6406 | __ B(slow_path->GetEntryLabel()); |
| 6407 | __ Bind(slow_path->GetExitLabel()); |
| 6408 | } |
| 6409 | |
| 6410 | void CodeGeneratorMIPS::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6411 | Location out, |
| 6412 | Location ref, |
| 6413 | Location obj, |
| 6414 | uint32_t offset, |
| 6415 | Location index) { |
| 6416 | if (kEmitCompilerReadBarrier) { |
| 6417 | // Baker's read barriers shall be handled by the fast path |
| 6418 | // (CodeGeneratorMIPS::GenerateReferenceLoadWithBakerReadBarrier). |
| 6419 | DCHECK(!kUseBakerReadBarrier); |
| 6420 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6421 | // by the runtime within the slow path. |
| 6422 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| 6423 | } else if (kPoisonHeapReferences) { |
| 6424 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6425 | } |
| 6426 | } |
| 6427 | |
| 6428 | void CodeGeneratorMIPS::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6429 | Location out, |
| 6430 | Location root) { |
| 6431 | DCHECK(kEmitCompilerReadBarrier); |
| 6432 | |
| 6433 | // Insert a slow path based read barrier *after* the GC root load. |
| 6434 | // |
| 6435 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6436 | // not need to do anything special for this here. |
| 6437 | SlowPathCodeMIPS* slow_path = |
| 6438 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathMIPS(instruction, out, root); |
| 6439 | AddSlowPath(slow_path); |
| 6440 | |
| 6441 | __ B(slow_path->GetEntryLabel()); |
| 6442 | __ Bind(slow_path->GetExitLabel()); |
| 6443 | } |
| 6444 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6445 | void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 6446 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6447 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6448 | switch (type_check_kind) { |
| 6449 | case TypeCheckKind::kExactCheck: |
| 6450 | case TypeCheckKind::kAbstractClassCheck: |
| 6451 | case TypeCheckKind::kClassHierarchyCheck: |
| 6452 | case TypeCheckKind::kArrayObjectCheck: |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6453 | call_kind = |
| 6454 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 6455 | break; |
| 6456 | case TypeCheckKind::kArrayCheck: |
| 6457 | case TypeCheckKind::kUnresolvedCheck: |
| 6458 | case TypeCheckKind::kInterfaceCheck: |
| 6459 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6460 | break; |
| 6461 | } |
| 6462 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6463 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6464 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6465 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6466 | // The output does overlap inputs. |
| 6467 | // Note that TypeCheckSlowPathMIPS uses this register too. |
| 6468 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6469 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6470 | } |
| 6471 | |
| 6472 | void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 6473 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6474 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6475 | Location obj_loc = locations->InAt(0); |
| 6476 | Register obj = obj_loc.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6477 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6478 | Location out_loc = locations->Out(); |
| 6479 | Register out = out_loc.AsRegister<Register>(); |
| 6480 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6481 | DCHECK_LE(num_temps, 1u); |
| 6482 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 6483 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6484 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6485 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6486 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6487 | MipsLabel done; |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 6488 | SlowPathCodeMIPS* slow_path = nullptr; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6489 | |
| 6490 | // Return 0 if `obj` is null. |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 6491 | // Avoid this check if we know `obj` is not null. |
| 6492 | if (instruction->MustDoNullCheck()) { |
| 6493 | __ Move(out, ZERO); |
| 6494 | __ Beqz(obj, &done); |
| 6495 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6496 | |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 6497 | switch (type_check_kind) { |
| 6498 | case TypeCheckKind::kExactCheck: { |
| 6499 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6500 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6501 | out_loc, |
| 6502 | obj_loc, |
| 6503 | class_offset, |
| 6504 | maybe_temp_loc, |
| 6505 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 6506 | // Classes must be equal for the instanceof to succeed. |
| 6507 | __ Xor(out, out, cls); |
| 6508 | __ Sltiu(out, out, 1); |
| 6509 | break; |
| 6510 | } |
| 6511 | |
| 6512 | case TypeCheckKind::kAbstractClassCheck: { |
| 6513 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6514 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6515 | out_loc, |
| 6516 | obj_loc, |
| 6517 | class_offset, |
| 6518 | maybe_temp_loc, |
| 6519 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 6520 | // If the class is abstract, we eagerly fetch the super class of the |
| 6521 | // object to avoid doing a comparison we know will fail. |
| 6522 | MipsLabel loop; |
| 6523 | __ Bind(&loop); |
| 6524 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6525 | GenerateReferenceLoadOneRegister(instruction, |
| 6526 | out_loc, |
| 6527 | super_offset, |
| 6528 | maybe_temp_loc, |
| 6529 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 6530 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6531 | __ Beqz(out, &done); |
| 6532 | __ Bne(out, cls, &loop); |
| 6533 | __ LoadConst32(out, 1); |
| 6534 | break; |
| 6535 | } |
| 6536 | |
| 6537 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6538 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6539 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6540 | out_loc, |
| 6541 | obj_loc, |
| 6542 | class_offset, |
| 6543 | maybe_temp_loc, |
| 6544 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 6545 | // Walk over the class hierarchy to find a match. |
| 6546 | MipsLabel loop, success; |
| 6547 | __ Bind(&loop); |
| 6548 | __ Beq(out, cls, &success); |
| 6549 | // /* HeapReference<Class> */ out = out->super_class_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6550 | GenerateReferenceLoadOneRegister(instruction, |
| 6551 | out_loc, |
| 6552 | super_offset, |
| 6553 | maybe_temp_loc, |
| 6554 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 6555 | __ Bnez(out, &loop); |
| 6556 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6557 | __ B(&done); |
| 6558 | __ Bind(&success); |
| 6559 | __ LoadConst32(out, 1); |
| 6560 | break; |
| 6561 | } |
| 6562 | |
| 6563 | case TypeCheckKind::kArrayObjectCheck: { |
| 6564 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6565 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6566 | out_loc, |
| 6567 | obj_loc, |
| 6568 | class_offset, |
| 6569 | maybe_temp_loc, |
| 6570 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 6571 | // Do an exact check. |
| 6572 | MipsLabel success; |
| 6573 | __ Beq(out, cls, &success); |
| 6574 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 6575 | // /* HeapReference<Class> */ out = out->component_type_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6576 | GenerateReferenceLoadOneRegister(instruction, |
| 6577 | out_loc, |
| 6578 | component_offset, |
| 6579 | maybe_temp_loc, |
| 6580 | kCompilerReadBarrierOption); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 6581 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6582 | __ Beqz(out, &done); |
| 6583 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 6584 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 6585 | __ Sltiu(out, out, 1); |
| 6586 | __ B(&done); |
| 6587 | __ Bind(&success); |
| 6588 | __ LoadConst32(out, 1); |
| 6589 | break; |
| 6590 | } |
| 6591 | |
| 6592 | case TypeCheckKind::kArrayCheck: { |
| 6593 | // No read barrier since the slow path will retry upon failure. |
| 6594 | // /* HeapReference<Class> */ out = obj->klass_ |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 6595 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6596 | out_loc, |
| 6597 | obj_loc, |
| 6598 | class_offset, |
| 6599 | maybe_temp_loc, |
| 6600 | kWithoutReadBarrier); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 6601 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6602 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction, |
| 6603 | /* is_fatal */ false); |
| 6604 | codegen_->AddSlowPath(slow_path); |
| 6605 | __ Bne(out, cls, slow_path->GetEntryLabel()); |
| 6606 | __ LoadConst32(out, 1); |
| 6607 | break; |
| 6608 | } |
| 6609 | |
| 6610 | case TypeCheckKind::kUnresolvedCheck: |
| 6611 | case TypeCheckKind::kInterfaceCheck: { |
| 6612 | // Note that we indeed only call on slow path, but we always go |
| 6613 | // into the slow path for the unresolved and interface check |
| 6614 | // cases. |
| 6615 | // |
| 6616 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6617 | // entry point without resorting to a type checking slow path |
| 6618 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6619 | // require to assign fixed registers for the inputs of this |
| 6620 | // HInstanceOf instruction (following the runtime calling |
| 6621 | // convention), which might be cluttered by the potential first |
| 6622 | // read barrier emission at the beginning of this method. |
| 6623 | // |
| 6624 | // TODO: Introduce a new runtime entry point taking the object |
| 6625 | // to test (instead of its class) as argument, and let it deal |
| 6626 | // with the read barrier issues. This will let us refactor this |
| 6627 | // case of the `switch` code as it was previously (with a direct |
| 6628 | // call to the runtime not using a type checking slow path). |
| 6629 | // This should also be beneficial for the other cases above. |
| 6630 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6631 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction, |
| 6632 | /* is_fatal */ false); |
| 6633 | codegen_->AddSlowPath(slow_path); |
| 6634 | __ B(slow_path->GetEntryLabel()); |
| 6635 | break; |
| 6636 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6637 | } |
| 6638 | |
| 6639 | __ Bind(&done); |
Alexey Frunze | 66b69ad | 2017-02-24 00:51:44 -0800 | [diff] [blame] | 6640 | |
| 6641 | if (slow_path != nullptr) { |
| 6642 | __ Bind(slow_path->GetExitLabel()); |
| 6643 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6644 | } |
| 6645 | |
| 6646 | void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) { |
| 6647 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 6648 | locations->SetOut(Location::ConstantLocation(constant)); |
| 6649 | } |
| 6650 | |
| 6651 | void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 6652 | // Will be generated at use site. |
| 6653 | } |
| 6654 | |
| 6655 | void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) { |
| 6656 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 6657 | locations->SetOut(Location::ConstantLocation(constant)); |
| 6658 | } |
| 6659 | |
| 6660 | void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 6661 | // Will be generated at use site. |
| 6662 | } |
| 6663 | |
| 6664 | void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) { |
| 6665 | InvokeDexCallingConventionVisitorMIPS calling_convention_visitor; |
| 6666 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 6667 | } |
| 6668 | |
| 6669 | void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 6670 | HandleInvoke(invoke); |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 6671 | // The register T7 is required to be used for the hidden argument in |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6672 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 6673 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T7)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6674 | } |
| 6675 | |
| 6676 | void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 6677 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 6678 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6679 | Location receiver = invoke->GetLocations()->InAt(0); |
| 6680 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6681 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6682 | |
| 6683 | // Set the hidden argument. |
| 6684 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(), |
| 6685 | invoke->GetDexMethodIndex()); |
| 6686 | |
| 6687 | // temp = object->GetClass(); |
| 6688 | if (receiver.IsStackSlot()) { |
| 6689 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 6690 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 6691 | } else { |
| 6692 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
| 6693 | } |
| 6694 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6695 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 6696 | // emit a read barrier for the previous class reference load. |
| 6697 | // However this is not required in practice, as this is an |
| 6698 | // intermediate/temporary reference and because the current |
| 6699 | // concurrent copying collector keeps the from-space memory |
| 6700 | // intact/accessible until the end of the marking phase (the |
| 6701 | // concurrent copying collector may not in the future). |
| 6702 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6703 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 6704 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
| 6705 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6706 | invoke->GetImtIndex(), kMipsPointerSize)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6707 | // temp = temp->GetImtEntryAt(method_offset); |
| 6708 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 6709 | // T9 = temp->GetEntryPoint(); |
| 6710 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 6711 | // T9(); |
| 6712 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 6713 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6714 | DCHECK(!codegen_->IsLeafMethod()); |
| 6715 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 6716 | } |
| 6717 | |
| 6718 | void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 6719 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 6720 | if (intrinsic.TryDispatch(invoke)) { |
| 6721 | return; |
| 6722 | } |
| 6723 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6724 | HandleInvoke(invoke); |
| 6725 | } |
| 6726 | |
| 6727 | void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 6728 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 6729 | // art::PrepareForRegisterAllocation. |
| 6730 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6731 | |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 6732 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 6733 | bool has_extra_input = invoke->HasPcRelativeDexCache() && !is_r6; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6734 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 6735 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 6736 | if (intrinsic.TryDispatch(invoke)) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6737 | if (invoke->GetLocations()->CanCall() && has_extra_input) { |
| 6738 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 6739 | } |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 6740 | return; |
| 6741 | } |
| 6742 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6743 | HandleInvoke(invoke); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6744 | |
| 6745 | // Add the extra input register if either the dex cache array base register |
| 6746 | // or the PC-relative base register for accessing literals is needed. |
| 6747 | if (has_extra_input) { |
| 6748 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 6749 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6750 | } |
| 6751 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 6752 | void LocationsBuilderMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 6753 | HandleInvoke(invoke); |
| 6754 | } |
| 6755 | |
| 6756 | void InstructionCodeGeneratorMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 6757 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 6758 | } |
| 6759 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 6760 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6761 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 6762 | IntrinsicCodeGeneratorMIPS intrinsic(codegen); |
| 6763 | intrinsic.Dispatch(invoke); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6764 | return true; |
| 6765 | } |
| 6766 | return false; |
| 6767 | } |
| 6768 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6769 | HLoadString::LoadKind CodeGeneratorMIPS::GetSupportedLoadStringKind( |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6770 | HLoadString::LoadKind desired_string_load_kind) { |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 6771 | // We disable PC-relative load on pre-R6 when there is an irreducible loop, as the optimization |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6772 | // is incompatible with it. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6773 | // TODO: Create as many MipsDexCacheArraysBase instructions as needed for methods |
| 6774 | // with irreducible loops. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6775 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 6776 | bool is_r6 = GetInstructionSetFeatures().IsR6(); |
| 6777 | bool fallback_load = has_irreducible_loops && !is_r6; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6778 | switch (desired_string_load_kind) { |
| 6779 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 6780 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6781 | break; |
| 6782 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6783 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6784 | break; |
| 6785 | case HLoadString::LoadKind::kBootImageAddress: |
| 6786 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6787 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6788 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6789 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6790 | case HLoadString::LoadKind::kJitTableAddress: |
| 6791 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 6792 | fallback_load = false; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6793 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6794 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 6795 | fallback_load = false; |
| 6796 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6797 | } |
| 6798 | if (fallback_load) { |
| 6799 | desired_string_load_kind = HLoadString::LoadKind::kDexCacheViaMethod; |
| 6800 | } |
| 6801 | return desired_string_load_kind; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6802 | } |
| 6803 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6804 | HLoadClass::LoadKind CodeGeneratorMIPS::GetSupportedLoadClassKind( |
| 6805 | HLoadClass::LoadKind desired_class_load_kind) { |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 6806 | // We disable PC-relative load on pre-R6 when there is an irreducible loop, as the optimization |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6807 | // is incompatible with it. |
| 6808 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 6809 | bool is_r6 = GetInstructionSetFeatures().IsR6(); |
| 6810 | bool fallback_load = has_irreducible_loops && !is_r6; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6811 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6812 | case HLoadClass::LoadKind::kInvalid: |
| 6813 | LOG(FATAL) << "UNREACHABLE"; |
| 6814 | UNREACHABLE(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6815 | case HLoadClass::LoadKind::kReferrersClass: |
| 6816 | fallback_load = false; |
| 6817 | break; |
| 6818 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 6819 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6820 | break; |
| 6821 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 6822 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6823 | break; |
| 6824 | case HLoadClass::LoadKind::kBootImageAddress: |
| 6825 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6826 | case HLoadClass::LoadKind::kBssEntry: |
| 6827 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 6828 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6829 | case HLoadClass::LoadKind::kJitTableAddress: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6830 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 6831 | fallback_load = false; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6832 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6833 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 6834 | fallback_load = false; |
| 6835 | break; |
| 6836 | } |
| 6837 | if (fallback_load) { |
| 6838 | desired_class_load_kind = HLoadClass::LoadKind::kDexCacheViaMethod; |
| 6839 | } |
| 6840 | return desired_class_load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6841 | } |
| 6842 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6843 | Register CodeGeneratorMIPS::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 6844 | Register temp) { |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 6845 | CHECK(!GetInstructionSetFeatures().IsR6()); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6846 | CHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 6847 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 6848 | if (!invoke->GetLocations()->Intrinsified()) { |
| 6849 | return location.AsRegister<Register>(); |
| 6850 | } |
| 6851 | // For intrinsics we allow any location, so it may be on the stack. |
| 6852 | if (!location.IsRegister()) { |
| 6853 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 6854 | return temp; |
| 6855 | } |
| 6856 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 6857 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 6858 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 6859 | // simple and more robust approach rather that trying to determine if that's the case. |
| 6860 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 6861 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 6862 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 6863 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 6864 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 6865 | return temp; |
| 6866 | } |
| 6867 | return location.AsRegister<Register>(); |
| 6868 | } |
| 6869 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6870 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch( |
| 6871 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 6872 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6873 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 6874 | // We disable PC-relative load on pre-R6 when there is an irreducible loop, as the optimization |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6875 | // is incompatible with it. |
| 6876 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 6877 | bool is_r6 = GetInstructionSetFeatures().IsR6(); |
| 6878 | bool fallback_load = has_irreducible_loops && !is_r6; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6879 | switch (dispatch_info.method_load_kind) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6880 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6881 | break; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6882 | default: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6883 | fallback_load = false; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6884 | break; |
| 6885 | } |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6886 | if (fallback_load) { |
| 6887 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 6888 | dispatch_info.method_load_data = 0; |
| 6889 | } |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6890 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6891 | } |
| 6892 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6893 | void CodeGeneratorMIPS::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 6894 | // All registers are assumed to be correctly set up per the calling convention. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6895 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6896 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 6897 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 6898 | bool is_r6 = GetInstructionSetFeatures().IsR6(); |
| 6899 | Register base_reg = (invoke->HasPcRelativeDexCache() && !is_r6) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6900 | ? GetInvokeStaticOrDirectExtraParameter(invoke, temp.AsRegister<Register>()) |
| 6901 | : ZERO; |
| 6902 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6903 | switch (method_load_kind) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 6904 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6905 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 6906 | uint32_t offset = |
| 6907 | GetThreadOffset<kMipsPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6908 | __ LoadFromOffset(kLoadWord, |
| 6909 | temp.AsRegister<Register>(), |
| 6910 | TR, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 6911 | offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6912 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 6913 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6914 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 6915 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6916 | break; |
| 6917 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 6918 | __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 6919 | break; |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 6920 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
| 6921 | if (is_r6) { |
| 6922 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 6923 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
| 6924 | NewPcRelativeDexCacheArrayPatch(invoke->GetDexFileForPcRelativeDexCache(), offset); |
| 6925 | bool reordering = __ SetReorder(false); |
| 6926 | EmitPcRelativeAddressPlaceholderHigh(info, TMP, ZERO); |
| 6927 | __ Lw(temp.AsRegister<Register>(), TMP, /* placeholder */ 0x5678); |
| 6928 | __ SetReorder(reordering); |
| 6929 | } else { |
| 6930 | HMipsDexCacheArraysBase* base = |
| 6931 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsMipsDexCacheArraysBase(); |
| 6932 | int32_t offset = |
| 6933 | invoke->GetDexCacheArrayOffset() - base->GetElementOffset() - kDexCacheArrayLwOffset; |
| 6934 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 6935 | } |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6936 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6937 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 6938 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6939 | Register reg = temp.AsRegister<Register>(); |
| 6940 | Register method_reg; |
| 6941 | if (current_method.IsRegister()) { |
| 6942 | method_reg = current_method.AsRegister<Register>(); |
| 6943 | } else { |
| 6944 | // TODO: use the appropriate DCHECK() here if possible. |
| 6945 | // DCHECK(invoke->GetLocations()->Intrinsified()); |
| 6946 | DCHECK(!current_method.IsValid()); |
| 6947 | method_reg = reg; |
| 6948 | __ Lw(reg, SP, kCurrentMethodStackOffset); |
| 6949 | } |
| 6950 | |
| 6951 | // temp = temp->dex_cache_resolved_methods_; |
| 6952 | __ LoadFromOffset(kLoadWord, |
| 6953 | reg, |
| 6954 | method_reg, |
| 6955 | ArtMethod::DexCacheResolvedMethodsOffset(kMipsPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 6956 | // temp = temp[index_in_cache]; |
| 6957 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 6958 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6959 | __ LoadFromOffset(kLoadWord, |
| 6960 | reg, |
| 6961 | reg, |
| 6962 | CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 6963 | break; |
| 6964 | } |
| 6965 | } |
| 6966 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6967 | switch (code_ptr_location) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6968 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6969 | __ Bal(&frame_entry_label_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6970 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6971 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 6972 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
Goran Jakovljevic | 1a87837 | 2015-10-26 14:28:52 +0100 | [diff] [blame] | 6973 | __ LoadFromOffset(kLoadWord, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6974 | T9, |
| 6975 | callee_method.AsRegister<Register>(), |
| 6976 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6977 | kMipsPointerSize).Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6978 | // T9() |
| 6979 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 6980 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6981 | break; |
| 6982 | } |
| 6983 | DCHECK(!IsLeafMethod()); |
| 6984 | } |
| 6985 | |
| 6986 | void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 6987 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 6988 | // art::PrepareForRegisterAllocation. |
| 6989 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6990 | |
| 6991 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 6992 | return; |
| 6993 | } |
| 6994 | |
| 6995 | LocationSummary* locations = invoke->GetLocations(); |
| 6996 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 6997 | locations->HasTemps() |
| 6998 | ? locations->GetTemp(0) |
| 6999 | : Location::NoLocation()); |
| 7000 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 7001 | } |
| 7002 | |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 7003 | void CodeGeneratorMIPS::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 7004 | // Use the calling convention instead of the location of the receiver, as |
| 7005 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 7006 | // slow path, the arguments have been moved to the right place, so here we are |
| 7007 | // guaranteed that the receiver is the first register of the calling convention. |
| 7008 | InvokeDexCallingConvention calling_convention; |
| 7009 | Register receiver = calling_convention.GetRegisterAt(0); |
| 7010 | |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 7011 | Register temp = temp_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7012 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7013 | invoke->GetVTableIndex(), kMipsPointerSize).SizeValue(); |
| 7014 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7015 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7016 | |
| 7017 | // temp = object->GetClass(); |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 7018 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 7019 | MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 7020 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7021 | // emit a read barrier for the previous class reference load. |
| 7022 | // However this is not required in practice, as this is an |
| 7023 | // intermediate/temporary reference and because the current |
| 7024 | // concurrent copying collector keeps the from-space memory |
| 7025 | // intact/accessible until the end of the marking phase (the |
| 7026 | // concurrent copying collector may not in the future). |
| 7027 | __ MaybeUnpoisonHeapReference(temp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7028 | // temp = temp->GetMethodAt(method_offset); |
| 7029 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7030 | // T9 = temp->GetEntryPoint(); |
| 7031 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 7032 | // T9(); |
| 7033 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 7034 | __ NopIfNoReordering(); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 7035 | } |
| 7036 | |
| 7037 | void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 7038 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 7039 | return; |
| 7040 | } |
| 7041 | |
| 7042 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7043 | DCHECK(!codegen_->IsLeafMethod()); |
| 7044 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 7045 | } |
| 7046 | |
| 7047 | void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7048 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 7049 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7050 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7051 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7052 | cls, |
| 7053 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7054 | calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7055 | return; |
| 7056 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7057 | DCHECK(!cls->NeedsAccessCheck()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7058 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7059 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 7060 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7061 | ? LocationSummary::kCallOnSlowPath |
| 7062 | : LocationSummary::kNoCall; |
| 7063 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7064 | switch (load_kind) { |
| 7065 | // We need an extra register for PC-relative literals on R2. |
| 7066 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7067 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7068 | case HLoadClass::LoadKind::kBootImageAddress: |
| 7069 | case HLoadClass::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7070 | if (codegen_->GetInstructionSetFeatures().IsR6()) { |
| 7071 | break; |
| 7072 | } |
| 7073 | FALLTHROUGH_INTENDED; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7074 | case HLoadClass::LoadKind::kReferrersClass: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7075 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7076 | break; |
| 7077 | default: |
| 7078 | break; |
| 7079 | } |
| 7080 | locations->SetOut(Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7081 | } |
| 7082 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7083 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7084 | // move. |
| 7085 | void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7086 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 7087 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 7088 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 7089 | return; |
| 7090 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7091 | DCHECK(!cls->NeedsAccessCheck()); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 7092 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7093 | LocationSummary* locations = cls->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7094 | Location out_loc = locations->Out(); |
| 7095 | Register out = out_loc.AsRegister<Register>(); |
| 7096 | Register base_or_current_method_reg; |
| 7097 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 7098 | switch (load_kind) { |
| 7099 | // We need an extra register for PC-relative literals on R2. |
| 7100 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7101 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7102 | case HLoadClass::LoadKind::kBootImageAddress: |
| 7103 | case HLoadClass::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7104 | base_or_current_method_reg = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>(); |
| 7105 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7106 | case HLoadClass::LoadKind::kReferrersClass: |
| 7107 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 7108 | base_or_current_method_reg = locations->InAt(0).AsRegister<Register>(); |
| 7109 | break; |
| 7110 | default: |
| 7111 | base_or_current_method_reg = ZERO; |
| 7112 | break; |
| 7113 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 7114 | |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7115 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 7116 | ? kWithoutReadBarrier |
| 7117 | : kCompilerReadBarrierOption; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7118 | bool generate_null_check = false; |
| 7119 | switch (load_kind) { |
| 7120 | case HLoadClass::LoadKind::kReferrersClass: { |
| 7121 | DCHECK(!cls->CanCallRuntime()); |
| 7122 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 7123 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 7124 | GenerateGcRootFieldLoad(cls, |
| 7125 | out_loc, |
| 7126 | base_or_current_method_reg, |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7127 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 7128 | read_barrier_option); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7129 | break; |
| 7130 | } |
| 7131 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7132 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7133 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7134 | __ LoadLiteral(out, |
| 7135 | base_or_current_method_reg, |
| 7136 | codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 7137 | cls->GetTypeIndex())); |
| 7138 | break; |
| 7139 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7140 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7141 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7142 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
| 7143 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7144 | bool reordering = __ SetReorder(false); |
| 7145 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info, out, base_or_current_method_reg); |
| 7146 | __ Addiu(out, out, /* placeholder */ 0x5678); |
| 7147 | __ SetReorder(reordering); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7148 | break; |
| 7149 | } |
| 7150 | case HLoadClass::LoadKind::kBootImageAddress: { |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7151 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7152 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7153 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 7154 | DCHECK_NE(address, 0u); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7155 | __ LoadLiteral(out, |
| 7156 | base_or_current_method_reg, |
| 7157 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7158 | break; |
| 7159 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7160 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7161 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7162 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7163 | bool reordering = __ SetReorder(false); |
| 7164 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info, out, base_or_current_method_reg); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7165 | GenerateGcRootFieldLoad(cls, out_loc, out, /* placeholder */ 0x5678, read_barrier_option); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7166 | __ SetReorder(reordering); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7167 | generate_null_check = true; |
| 7168 | break; |
| 7169 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7170 | case HLoadClass::LoadKind::kJitTableAddress: { |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 7171 | CodeGeneratorMIPS::JitPatchInfo* info = codegen_->NewJitRootClassPatch(cls->GetDexFile(), |
| 7172 | cls->GetTypeIndex(), |
| 7173 | cls->GetClass()); |
| 7174 | bool reordering = __ SetReorder(false); |
| 7175 | __ Bind(&info->high_label); |
| 7176 | __ Lui(out, /* placeholder */ 0x1234); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7177 | GenerateGcRootFieldLoad(cls, out_loc, out, /* placeholder */ 0x5678, read_barrier_option); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 7178 | __ SetReorder(reordering); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7179 | break; |
| 7180 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7181 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7182 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7183 | LOG(FATAL) << "UNREACHABLE"; |
| 7184 | UNREACHABLE(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7185 | } |
| 7186 | |
| 7187 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 7188 | DCHECK(cls->CanCallRuntime()); |
| 7189 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS( |
| 7190 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 7191 | codegen_->AddSlowPath(slow_path); |
| 7192 | if (generate_null_check) { |
| 7193 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 7194 | } |
| 7195 | if (cls->MustGenerateClinitCheck()) { |
| 7196 | GenerateClassInitializationCheck(slow_path, out); |
| 7197 | } else { |
| 7198 | __ Bind(slow_path->GetExitLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7199 | } |
| 7200 | } |
| 7201 | } |
| 7202 | |
| 7203 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7204 | return Thread::ExceptionOffset<kMipsPointerSize>().Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7205 | } |
| 7206 | |
| 7207 | void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) { |
| 7208 | LocationSummary* locations = |
| 7209 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 7210 | locations->SetOut(Location::RequiresRegister()); |
| 7211 | } |
| 7212 | |
| 7213 | void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) { |
| 7214 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
| 7215 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 7216 | } |
| 7217 | |
| 7218 | void LocationsBuilderMIPS::VisitClearException(HClearException* clear) { |
| 7219 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 7220 | } |
| 7221 | |
| 7222 | void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 7223 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
| 7224 | } |
| 7225 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7226 | void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 7227 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 7228 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7229 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 7230 | switch (load_kind) { |
| 7231 | // We need an extra register for PC-relative literals on R2. |
| 7232 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 7233 | case HLoadString::LoadKind::kBootImageAddress: |
| 7234 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7235 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7236 | if (codegen_->GetInstructionSetFeatures().IsR6()) { |
| 7237 | break; |
| 7238 | } |
| 7239 | FALLTHROUGH_INTENDED; |
| 7240 | // We need an extra register for PC-relative dex cache accesses. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7241 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 7242 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7243 | break; |
| 7244 | default: |
| 7245 | break; |
| 7246 | } |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 7247 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 7248 | InvokeRuntimeCallingConvention calling_convention; |
| 7249 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 7250 | } else { |
| 7251 | locations->SetOut(Location::RequiresRegister()); |
| 7252 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7253 | } |
| 7254 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7255 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7256 | // move. |
| 7257 | void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7258 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7259 | LocationSummary* locations = load->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7260 | Location out_loc = locations->Out(); |
| 7261 | Register out = out_loc.AsRegister<Register>(); |
| 7262 | Register base_or_current_method_reg; |
| 7263 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 7264 | switch (load_kind) { |
| 7265 | // We need an extra register for PC-relative literals on R2. |
| 7266 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 7267 | case HLoadString::LoadKind::kBootImageAddress: |
| 7268 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7269 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7270 | base_or_current_method_reg = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>(); |
| 7271 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7272 | default: |
| 7273 | base_or_current_method_reg = ZERO; |
| 7274 | break; |
| 7275 | } |
| 7276 | |
| 7277 | switch (load_kind) { |
| 7278 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7279 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7280 | __ LoadLiteral(out, |
| 7281 | base_or_current_method_reg, |
| 7282 | codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 7283 | load->GetStringIndex())); |
| 7284 | return; // No dex cache slow path. |
| 7285 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7286 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7287 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7288 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7289 | bool reordering = __ SetReorder(false); |
| 7290 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info, out, base_or_current_method_reg); |
| 7291 | __ Addiu(out, out, /* placeholder */ 0x5678); |
| 7292 | __ SetReorder(reordering); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7293 | return; // No dex cache slow path. |
| 7294 | } |
| 7295 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7296 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7297 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 7298 | DCHECK_NE(address, 0u); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7299 | __ LoadLiteral(out, |
| 7300 | base_or_current_method_reg, |
| 7301 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7302 | return; // No dex cache slow path. |
| 7303 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7304 | case HLoadString::LoadKind::kBssEntry: { |
| 7305 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7306 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7307 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7308 | bool reordering = __ SetReorder(false); |
| 7309 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info, out, base_or_current_method_reg); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7310 | GenerateGcRootFieldLoad(load, |
| 7311 | out_loc, |
| 7312 | out, |
| 7313 | /* placeholder */ 0x5678, |
| 7314 | kCompilerReadBarrierOption); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7315 | __ SetReorder(reordering); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7316 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS(load); |
| 7317 | codegen_->AddSlowPath(slow_path); |
| 7318 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 7319 | __ Bind(slow_path->GetExitLabel()); |
| 7320 | return; |
| 7321 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 7322 | case HLoadString::LoadKind::kJitTableAddress: { |
| 7323 | CodeGeneratorMIPS::JitPatchInfo* info = |
| 7324 | codegen_->NewJitRootStringPatch(load->GetDexFile(), |
| 7325 | load->GetStringIndex(), |
| 7326 | load->GetString()); |
| 7327 | bool reordering = __ SetReorder(false); |
| 7328 | __ Bind(&info->high_label); |
| 7329 | __ Lui(out, /* placeholder */ 0x1234); |
Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 7330 | GenerateGcRootFieldLoad(load, |
| 7331 | out_loc, |
| 7332 | out, |
| 7333 | /* placeholder */ 0x5678, |
| 7334 | kCompilerReadBarrierOption); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 7335 | __ SetReorder(reordering); |
| 7336 | return; |
| 7337 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7338 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 7339 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7340 | } |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 7341 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 7342 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7343 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 7344 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7345 | __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7346 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7347 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7348 | } |
| 7349 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7350 | void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) { |
| 7351 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 7352 | locations->SetOut(Location::ConstantLocation(constant)); |
| 7353 | } |
| 7354 | |
| 7355 | void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 7356 | // Will be generated at use site. |
| 7357 | } |
| 7358 | |
| 7359 | void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 7360 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 7361 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7362 | InvokeRuntimeCallingConvention calling_convention; |
| 7363 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7364 | } |
| 7365 | |
| 7366 | void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 7367 | if (instruction->IsEnter()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 7368 | codegen_->InvokeRuntime(kQuickLockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7369 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7370 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 7371 | codegen_->InvokeRuntime(kQuickUnlockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7372 | } |
| 7373 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7374 | } |
| 7375 | |
| 7376 | void LocationsBuilderMIPS::VisitMul(HMul* mul) { |
| 7377 | LocationSummary* locations = |
| 7378 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 7379 | switch (mul->GetResultType()) { |
| 7380 | case Primitive::kPrimInt: |
| 7381 | case Primitive::kPrimLong: |
| 7382 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7383 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7384 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7385 | break; |
| 7386 | |
| 7387 | case Primitive::kPrimFloat: |
| 7388 | case Primitive::kPrimDouble: |
| 7389 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 7390 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 7391 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 7392 | break; |
| 7393 | |
| 7394 | default: |
| 7395 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 7396 | } |
| 7397 | } |
| 7398 | |
| 7399 | void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) { |
| 7400 | Primitive::Type type = instruction->GetType(); |
| 7401 | LocationSummary* locations = instruction->GetLocations(); |
| 7402 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 7403 | |
| 7404 | switch (type) { |
| 7405 | case Primitive::kPrimInt: { |
| 7406 | Register dst = locations->Out().AsRegister<Register>(); |
| 7407 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 7408 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 7409 | |
| 7410 | if (isR6) { |
| 7411 | __ MulR6(dst, lhs, rhs); |
| 7412 | } else { |
| 7413 | __ MulR2(dst, lhs, rhs); |
| 7414 | } |
| 7415 | break; |
| 7416 | } |
| 7417 | case Primitive::kPrimLong: { |
| 7418 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 7419 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 7420 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 7421 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 7422 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 7423 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 7424 | |
| 7425 | // Extra checks to protect caused by the existance of A1_A2. |
| 7426 | // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo: |
| 7427 | // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2). |
| 7428 | DCHECK_NE(dst_high, lhs_low); |
| 7429 | DCHECK_NE(dst_high, rhs_low); |
| 7430 | |
| 7431 | // A_B * C_D |
| 7432 | // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ] |
| 7433 | // dst_lo: [ low(B*D) ] |
| 7434 | // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result. |
| 7435 | |
| 7436 | if (isR6) { |
| 7437 | __ MulR6(TMP, lhs_high, rhs_low); |
| 7438 | __ MulR6(dst_high, lhs_low, rhs_high); |
| 7439 | __ Addu(dst_high, dst_high, TMP); |
| 7440 | __ MuhuR6(TMP, lhs_low, rhs_low); |
| 7441 | __ Addu(dst_high, dst_high, TMP); |
| 7442 | __ MulR6(dst_low, lhs_low, rhs_low); |
| 7443 | } else { |
| 7444 | __ MulR2(TMP, lhs_high, rhs_low); |
| 7445 | __ MulR2(dst_high, lhs_low, rhs_high); |
| 7446 | __ Addu(dst_high, dst_high, TMP); |
| 7447 | __ MultuR2(lhs_low, rhs_low); |
| 7448 | __ Mfhi(TMP); |
| 7449 | __ Addu(dst_high, dst_high, TMP); |
| 7450 | __ Mflo(dst_low); |
| 7451 | } |
| 7452 | break; |
| 7453 | } |
| 7454 | case Primitive::kPrimFloat: |
| 7455 | case Primitive::kPrimDouble: { |
| 7456 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 7457 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 7458 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 7459 | if (type == Primitive::kPrimFloat) { |
| 7460 | __ MulS(dst, lhs, rhs); |
| 7461 | } else { |
| 7462 | __ MulD(dst, lhs, rhs); |
| 7463 | } |
| 7464 | break; |
| 7465 | } |
| 7466 | default: |
| 7467 | LOG(FATAL) << "Unexpected mul type " << type; |
| 7468 | } |
| 7469 | } |
| 7470 | |
| 7471 | void LocationsBuilderMIPS::VisitNeg(HNeg* neg) { |
| 7472 | LocationSummary* locations = |
| 7473 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 7474 | switch (neg->GetResultType()) { |
| 7475 | case Primitive::kPrimInt: |
| 7476 | case Primitive::kPrimLong: |
| 7477 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7478 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7479 | break; |
| 7480 | |
| 7481 | case Primitive::kPrimFloat: |
| 7482 | case Primitive::kPrimDouble: |
| 7483 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 7484 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 7485 | break; |
| 7486 | |
| 7487 | default: |
| 7488 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 7489 | } |
| 7490 | } |
| 7491 | |
| 7492 | void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) { |
| 7493 | Primitive::Type type = instruction->GetType(); |
| 7494 | LocationSummary* locations = instruction->GetLocations(); |
| 7495 | |
| 7496 | switch (type) { |
| 7497 | case Primitive::kPrimInt: { |
| 7498 | Register dst = locations->Out().AsRegister<Register>(); |
| 7499 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 7500 | __ Subu(dst, ZERO, src); |
| 7501 | break; |
| 7502 | } |
| 7503 | case Primitive::kPrimLong: { |
| 7504 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 7505 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 7506 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 7507 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 7508 | __ Subu(dst_low, ZERO, src_low); |
| 7509 | __ Sltu(TMP, ZERO, dst_low); |
| 7510 | __ Subu(dst_high, ZERO, src_high); |
| 7511 | __ Subu(dst_high, dst_high, TMP); |
| 7512 | break; |
| 7513 | } |
| 7514 | case Primitive::kPrimFloat: |
| 7515 | case Primitive::kPrimDouble: { |
| 7516 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 7517 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 7518 | if (type == Primitive::kPrimFloat) { |
| 7519 | __ NegS(dst, src); |
| 7520 | } else { |
| 7521 | __ NegD(dst, src); |
| 7522 | } |
| 7523 | break; |
| 7524 | } |
| 7525 | default: |
| 7526 | LOG(FATAL) << "Unexpected neg type " << type; |
| 7527 | } |
| 7528 | } |
| 7529 | |
| 7530 | void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) { |
| 7531 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 7532 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7533 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7534 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 7535 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7536 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7537 | } |
| 7538 | |
| 7539 | void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 7540 | // Note: if heap poisoning is enabled, the entry point takes care |
| 7541 | // of poisoning the reference. |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 7542 | codegen_->InvokeRuntime(kQuickAllocArrayResolved, instruction, instruction->GetDexPc()); |
| 7543 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7544 | } |
| 7545 | |
| 7546 | void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) { |
| 7547 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 7548 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7549 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 7550 | if (instruction->IsStringAlloc()) { |
| 7551 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 7552 | } else { |
| 7553 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 7554 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7555 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 7556 | } |
| 7557 | |
| 7558 | void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 7559 | // Note: if heap poisoning is enabled, the entry point takes care |
| 7560 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 7561 | if (instruction->IsStringAlloc()) { |
| 7562 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 7563 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7564 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 7565 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 7566 | __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value()); |
| 7567 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 7568 | __ NopIfNoReordering(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 7569 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 7570 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 7571 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 7572 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 7573 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7574 | } |
| 7575 | |
| 7576 | void LocationsBuilderMIPS::VisitNot(HNot* instruction) { |
| 7577 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 7578 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7579 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7580 | } |
| 7581 | |
| 7582 | void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) { |
| 7583 | Primitive::Type type = instruction->GetType(); |
| 7584 | LocationSummary* locations = instruction->GetLocations(); |
| 7585 | |
| 7586 | switch (type) { |
| 7587 | case Primitive::kPrimInt: { |
| 7588 | Register dst = locations->Out().AsRegister<Register>(); |
| 7589 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 7590 | __ Nor(dst, src, ZERO); |
| 7591 | break; |
| 7592 | } |
| 7593 | |
| 7594 | case Primitive::kPrimLong: { |
| 7595 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 7596 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 7597 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 7598 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 7599 | __ Nor(dst_high, src_high, ZERO); |
| 7600 | __ Nor(dst_low, src_low, ZERO); |
| 7601 | break; |
| 7602 | } |
| 7603 | |
| 7604 | default: |
| 7605 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 7606 | } |
| 7607 | } |
| 7608 | |
| 7609 | void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
| 7610 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 7611 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7612 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7613 | } |
| 7614 | |
| 7615 | void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
| 7616 | LocationSummary* locations = instruction->GetLocations(); |
| 7617 | __ Xori(locations->Out().AsRegister<Register>(), |
| 7618 | locations->InAt(0).AsRegister<Register>(), |
| 7619 | 1); |
| 7620 | } |
| 7621 | |
| 7622 | void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 7623 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 7624 | locations->SetInAt(0, Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7625 | } |
| 7626 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 7627 | void CodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 7628 | if (CanMoveNullCheckToUser(instruction)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7629 | return; |
| 7630 | } |
| 7631 | Location obj = instruction->GetLocations()->InAt(0); |
| 7632 | |
| 7633 | __ Lw(ZERO, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 7634 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7635 | } |
| 7636 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 7637 | void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7638 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 7639 | AddSlowPath(slow_path); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7640 | |
| 7641 | Location obj = instruction->GetLocations()->InAt(0); |
| 7642 | |
| 7643 | __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 7644 | } |
| 7645 | |
| 7646 | void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 7647 | codegen_->GenerateNullCheck(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7648 | } |
| 7649 | |
| 7650 | void LocationsBuilderMIPS::VisitOr(HOr* instruction) { |
| 7651 | HandleBinaryOp(instruction); |
| 7652 | } |
| 7653 | |
| 7654 | void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) { |
| 7655 | HandleBinaryOp(instruction); |
| 7656 | } |
| 7657 | |
| 7658 | void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 7659 | LOG(FATAL) << "Unreachable"; |
| 7660 | } |
| 7661 | |
| 7662 | void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) { |
| 7663 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 7664 | } |
| 7665 | |
| 7666 | void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) { |
| 7667 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 7668 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 7669 | if (location.IsStackSlot()) { |
| 7670 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 7671 | } else if (location.IsDoubleStackSlot()) { |
| 7672 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 7673 | } |
| 7674 | locations->SetOut(location); |
| 7675 | } |
| 7676 | |
| 7677 | void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction |
| 7678 | ATTRIBUTE_UNUSED) { |
| 7679 | // Nothing to do, the parameter is already at its location. |
| 7680 | } |
| 7681 | |
| 7682 | void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 7683 | LocationSummary* locations = |
| 7684 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7685 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 7686 | } |
| 7687 | |
| 7688 | void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction |
| 7689 | ATTRIBUTE_UNUSED) { |
| 7690 | // Nothing to do, the method is already at its location. |
| 7691 | } |
| 7692 | |
| 7693 | void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) { |
| 7694 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 7695 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7696 | locations->SetInAt(i, Location::Any()); |
| 7697 | } |
| 7698 | locations->SetOut(Location::Any()); |
| 7699 | } |
| 7700 | |
| 7701 | void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 7702 | LOG(FATAL) << "Unreachable"; |
| 7703 | } |
| 7704 | |
| 7705 | void LocationsBuilderMIPS::VisitRem(HRem* rem) { |
| 7706 | Primitive::Type type = rem->GetResultType(); |
| 7707 | LocationSummary::CallKind call_kind = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 7708 | (type == Primitive::kPrimInt) ? LocationSummary::kNoCall : LocationSummary::kCallOnMainOnly; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7709 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 7710 | |
| 7711 | switch (type) { |
| 7712 | case Primitive::kPrimInt: |
| 7713 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 7714 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7715 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7716 | break; |
| 7717 | |
| 7718 | case Primitive::kPrimLong: { |
| 7719 | InvokeRuntimeCallingConvention calling_convention; |
| 7720 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 7721 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 7722 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 7723 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 7724 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 7725 | break; |
| 7726 | } |
| 7727 | |
| 7728 | case Primitive::kPrimFloat: |
| 7729 | case Primitive::kPrimDouble: { |
| 7730 | InvokeRuntimeCallingConvention calling_convention; |
| 7731 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 7732 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 7733 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 7734 | break; |
| 7735 | } |
| 7736 | |
| 7737 | default: |
| 7738 | LOG(FATAL) << "Unexpected rem type " << type; |
| 7739 | } |
| 7740 | } |
| 7741 | |
| 7742 | void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) { |
| 7743 | Primitive::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7744 | |
| 7745 | switch (type) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 7746 | case Primitive::kPrimInt: |
| 7747 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7748 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7749 | case Primitive::kPrimLong: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 7750 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7751 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 7752 | break; |
| 7753 | } |
| 7754 | case Primitive::kPrimFloat: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 7755 | codegen_->InvokeRuntime(kQuickFmodf, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7756 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7757 | break; |
| 7758 | } |
| 7759 | case Primitive::kPrimDouble: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 7760 | codegen_->InvokeRuntime(kQuickFmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7761 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7762 | break; |
| 7763 | } |
| 7764 | default: |
| 7765 | LOG(FATAL) << "Unexpected rem type " << type; |
| 7766 | } |
| 7767 | } |
| 7768 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame^] | 7769 | void LocationsBuilderMIPS::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 7770 | constructor_fence->SetLocations(nullptr); |
| 7771 | } |
| 7772 | |
| 7773 | void InstructionCodeGeneratorMIPS::VisitConstructorFence( |
| 7774 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 7775 | GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 7776 | } |
| 7777 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7778 | void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 7779 | memory_barrier->SetLocations(nullptr); |
| 7780 | } |
| 7781 | |
| 7782 | void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 7783 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 7784 | } |
| 7785 | |
| 7786 | void LocationsBuilderMIPS::VisitReturn(HReturn* ret) { |
| 7787 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret); |
| 7788 | Primitive::Type return_type = ret->InputAt(0)->GetType(); |
| 7789 | locations->SetInAt(0, MipsReturnLocation(return_type)); |
| 7790 | } |
| 7791 | |
| 7792 | void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 7793 | codegen_->GenerateFrameExit(); |
| 7794 | } |
| 7795 | |
| 7796 | void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) { |
| 7797 | ret->SetLocations(nullptr); |
| 7798 | } |
| 7799 | |
| 7800 | void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 7801 | codegen_->GenerateFrameExit(); |
| 7802 | } |
| 7803 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 7804 | void LocationsBuilderMIPS::VisitRor(HRor* ror) { |
| 7805 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 7806 | } |
| 7807 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 7808 | void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) { |
| 7809 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 7810 | } |
| 7811 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7812 | void LocationsBuilderMIPS::VisitShl(HShl* shl) { |
| 7813 | HandleShift(shl); |
| 7814 | } |
| 7815 | |
| 7816 | void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) { |
| 7817 | HandleShift(shl); |
| 7818 | } |
| 7819 | |
| 7820 | void LocationsBuilderMIPS::VisitShr(HShr* shr) { |
| 7821 | HandleShift(shr); |
| 7822 | } |
| 7823 | |
| 7824 | void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) { |
| 7825 | HandleShift(shr); |
| 7826 | } |
| 7827 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7828 | void LocationsBuilderMIPS::VisitSub(HSub* instruction) { |
| 7829 | HandleBinaryOp(instruction); |
| 7830 | } |
| 7831 | |
| 7832 | void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) { |
| 7833 | HandleBinaryOp(instruction); |
| 7834 | } |
| 7835 | |
| 7836 | void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 7837 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 7838 | } |
| 7839 | |
| 7840 | void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 7841 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 7842 | } |
| 7843 | |
| 7844 | void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 7845 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 7846 | } |
| 7847 | |
| 7848 | void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 7849 | HandleFieldSet(instruction, |
| 7850 | instruction->GetFieldInfo(), |
| 7851 | instruction->GetDexPc(), |
| 7852 | instruction->GetValueCanBeNull()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7853 | } |
| 7854 | |
| 7855 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet( |
| 7856 | HUnresolvedInstanceFieldGet* instruction) { |
| 7857 | FieldAccessCallingConventionMIPS calling_convention; |
| 7858 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 7859 | instruction->GetFieldType(), |
| 7860 | calling_convention); |
| 7861 | } |
| 7862 | |
| 7863 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet( |
| 7864 | HUnresolvedInstanceFieldGet* instruction) { |
| 7865 | FieldAccessCallingConventionMIPS calling_convention; |
| 7866 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 7867 | instruction->GetFieldType(), |
| 7868 | instruction->GetFieldIndex(), |
| 7869 | instruction->GetDexPc(), |
| 7870 | calling_convention); |
| 7871 | } |
| 7872 | |
| 7873 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet( |
| 7874 | HUnresolvedInstanceFieldSet* instruction) { |
| 7875 | FieldAccessCallingConventionMIPS calling_convention; |
| 7876 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 7877 | instruction->GetFieldType(), |
| 7878 | calling_convention); |
| 7879 | } |
| 7880 | |
| 7881 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet( |
| 7882 | HUnresolvedInstanceFieldSet* instruction) { |
| 7883 | FieldAccessCallingConventionMIPS calling_convention; |
| 7884 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 7885 | instruction->GetFieldType(), |
| 7886 | instruction->GetFieldIndex(), |
| 7887 | instruction->GetDexPc(), |
| 7888 | calling_convention); |
| 7889 | } |
| 7890 | |
| 7891 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet( |
| 7892 | HUnresolvedStaticFieldGet* instruction) { |
| 7893 | FieldAccessCallingConventionMIPS calling_convention; |
| 7894 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 7895 | instruction->GetFieldType(), |
| 7896 | calling_convention); |
| 7897 | } |
| 7898 | |
| 7899 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet( |
| 7900 | HUnresolvedStaticFieldGet* instruction) { |
| 7901 | FieldAccessCallingConventionMIPS calling_convention; |
| 7902 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 7903 | instruction->GetFieldType(), |
| 7904 | instruction->GetFieldIndex(), |
| 7905 | instruction->GetDexPc(), |
| 7906 | calling_convention); |
| 7907 | } |
| 7908 | |
| 7909 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet( |
| 7910 | HUnresolvedStaticFieldSet* instruction) { |
| 7911 | FieldAccessCallingConventionMIPS calling_convention; |
| 7912 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 7913 | instruction->GetFieldType(), |
| 7914 | calling_convention); |
| 7915 | } |
| 7916 | |
| 7917 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet( |
| 7918 | HUnresolvedStaticFieldSet* instruction) { |
| 7919 | FieldAccessCallingConventionMIPS calling_convention; |
| 7920 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 7921 | instruction->GetFieldType(), |
| 7922 | instruction->GetFieldIndex(), |
| 7923 | instruction->GetDexPc(), |
| 7924 | calling_convention); |
| 7925 | } |
| 7926 | |
| 7927 | void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7928 | LocationSummary* locations = |
| 7929 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 7930 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7931 | } |
| 7932 | |
| 7933 | void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 7934 | HBasicBlock* block = instruction->GetBlock(); |
| 7935 | if (block->GetLoopInformation() != nullptr) { |
| 7936 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 7937 | // The back edge will generate the suspend check. |
| 7938 | return; |
| 7939 | } |
| 7940 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 7941 | // The goto will generate the suspend check. |
| 7942 | return; |
| 7943 | } |
| 7944 | GenerateSuspendCheck(instruction, nullptr); |
| 7945 | } |
| 7946 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7947 | void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) { |
| 7948 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 7949 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7950 | InvokeRuntimeCallingConvention calling_convention; |
| 7951 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7952 | } |
| 7953 | |
| 7954 | void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 7955 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7956 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 7957 | } |
| 7958 | |
| 7959 | void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
| 7960 | Primitive::Type input_type = conversion->GetInputType(); |
| 7961 | Primitive::Type result_type = conversion->GetResultType(); |
| 7962 | DCHECK_NE(input_type, result_type); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7963 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7964 | |
| 7965 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 7966 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 7967 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 7968 | } |
| 7969 | |
| 7970 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 7971 | if (!isR6 && |
| 7972 | ((Primitive::IsFloatingPointType(result_type) && input_type == Primitive::kPrimLong) || |
| 7973 | (result_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(input_type)))) { |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 7974 | call_kind = LocationSummary::kCallOnMainOnly; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7975 | } |
| 7976 | |
| 7977 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 7978 | |
| 7979 | if (call_kind == LocationSummary::kNoCall) { |
| 7980 | if (Primitive::IsFloatingPointType(input_type)) { |
| 7981 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 7982 | } else { |
| 7983 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7984 | } |
| 7985 | |
| 7986 | if (Primitive::IsFloatingPointType(result_type)) { |
| 7987 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 7988 | } else { |
| 7989 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7990 | } |
| 7991 | } else { |
| 7992 | InvokeRuntimeCallingConvention calling_convention; |
| 7993 | |
| 7994 | if (Primitive::IsFloatingPointType(input_type)) { |
| 7995 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 7996 | } else { |
| 7997 | DCHECK_EQ(input_type, Primitive::kPrimLong); |
| 7998 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 7999 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 8000 | } |
| 8001 | |
| 8002 | locations->SetOut(calling_convention.GetReturnLocation(result_type)); |
| 8003 | } |
| 8004 | } |
| 8005 | |
| 8006 | void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
| 8007 | LocationSummary* locations = conversion->GetLocations(); |
| 8008 | Primitive::Type result_type = conversion->GetResultType(); |
| 8009 | Primitive::Type input_type = conversion->GetInputType(); |
| 8010 | bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8011 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8012 | |
| 8013 | DCHECK_NE(input_type, result_type); |
| 8014 | |
| 8015 | if (result_type == Primitive::kPrimLong && Primitive::IsIntegralType(input_type)) { |
| 8016 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8017 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8018 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8019 | |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 8020 | if (dst_low != src) { |
| 8021 | __ Move(dst_low, src); |
| 8022 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8023 | __ Sra(dst_high, src, 31); |
| 8024 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
| 8025 | Register dst = locations->Out().AsRegister<Register>(); |
| 8026 | Register src = (input_type == Primitive::kPrimLong) |
| 8027 | ? locations->InAt(0).AsRegisterPairLow<Register>() |
| 8028 | : locations->InAt(0).AsRegister<Register>(); |
| 8029 | |
| 8030 | switch (result_type) { |
| 8031 | case Primitive::kPrimChar: |
| 8032 | __ Andi(dst, src, 0xFFFF); |
| 8033 | break; |
| 8034 | case Primitive::kPrimByte: |
| 8035 | if (has_sign_extension) { |
| 8036 | __ Seb(dst, src); |
| 8037 | } else { |
| 8038 | __ Sll(dst, src, 24); |
| 8039 | __ Sra(dst, dst, 24); |
| 8040 | } |
| 8041 | break; |
| 8042 | case Primitive::kPrimShort: |
| 8043 | if (has_sign_extension) { |
| 8044 | __ Seh(dst, src); |
| 8045 | } else { |
| 8046 | __ Sll(dst, src, 16); |
| 8047 | __ Sra(dst, dst, 16); |
| 8048 | } |
| 8049 | break; |
| 8050 | case Primitive::kPrimInt: |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 8051 | if (dst != src) { |
| 8052 | __ Move(dst, src); |
| 8053 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8054 | break; |
| 8055 | |
| 8056 | default: |
| 8057 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 8058 | << " to " << result_type; |
| 8059 | } |
| 8060 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8061 | if (input_type == Primitive::kPrimLong) { |
| 8062 | if (isR6) { |
| 8063 | // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 8064 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 8065 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 8066 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 8067 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8068 | __ Mtc1(src_low, FTMP); |
| 8069 | __ Mthc1(src_high, FTMP); |
| 8070 | if (result_type == Primitive::kPrimFloat) { |
| 8071 | __ Cvtsl(dst, FTMP); |
| 8072 | } else { |
| 8073 | __ Cvtdl(dst, FTMP); |
| 8074 | } |
| 8075 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8076 | QuickEntrypointEnum entrypoint = (result_type == Primitive::kPrimFloat) ? kQuickL2f |
| 8077 | : kQuickL2d; |
| 8078 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8079 | if (result_type == Primitive::kPrimFloat) { |
| 8080 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 8081 | } else { |
| 8082 | CheckEntrypointTypes<kQuickL2d, double, int64_t>(); |
| 8083 | } |
| 8084 | } |
| 8085 | } else { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8086 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 8087 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8088 | __ Mtc1(src, FTMP); |
| 8089 | if (result_type == Primitive::kPrimFloat) { |
| 8090 | __ Cvtsw(dst, FTMP); |
| 8091 | } else { |
| 8092 | __ Cvtdw(dst, FTMP); |
| 8093 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8094 | } |
| 8095 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
| 8096 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8097 | if (result_type == Primitive::kPrimLong) { |
| 8098 | if (isR6) { |
| 8099 | // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 8100 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 8101 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 8102 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 8103 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 8104 | MipsLabel truncate; |
| 8105 | MipsLabel done; |
| 8106 | |
| 8107 | // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive |
| 8108 | // value when the input is either a NaN or is outside of the range of the output type |
| 8109 | // after the truncation. IOW, the three special cases (NaN, too small, too big) produce |
| 8110 | // the same result. |
| 8111 | // |
| 8112 | // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum |
| 8113 | // value of the output type if the input is outside of the range after the truncation or |
| 8114 | // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct |
| 8115 | // results. This matches the desired float/double-to-int/long conversion exactly. |
| 8116 | // |
| 8117 | // So, NAN2008 affects handling of negative values and NaNs by the truncate instruction. |
| 8118 | // |
| 8119 | // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate |
| 8120 | // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6, |
| 8121 | // even though it must be NAN2008=1 on R6. |
| 8122 | // |
| 8123 | // The code takes care of the different behaviors by first comparing the input to the |
| 8124 | // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int). |
| 8125 | // If the input is greater than or equal to the minimum, it procedes to the truncate |
| 8126 | // instruction, which will handle such an input the same way irrespective of NAN2008. |
| 8127 | // Otherwise the input is compared to itself to determine whether it is a NaN or not |
| 8128 | // in order to return either zero or the minimum value. |
| 8129 | // |
| 8130 | // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the |
| 8131 | // truncate instruction for MIPS64R6. |
| 8132 | if (input_type == Primitive::kPrimFloat) { |
| 8133 | uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int64_t>::min()); |
| 8134 | __ LoadConst32(TMP, min_val); |
| 8135 | __ Mtc1(TMP, FTMP); |
| 8136 | __ CmpLeS(FTMP, FTMP, src); |
| 8137 | } else { |
| 8138 | uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int64_t>::min()); |
| 8139 | __ LoadConst32(TMP, High32Bits(min_val)); |
| 8140 | __ Mtc1(ZERO, FTMP); |
| 8141 | __ Mthc1(TMP, FTMP); |
| 8142 | __ CmpLeD(FTMP, FTMP, src); |
| 8143 | } |
| 8144 | |
| 8145 | __ Bc1nez(FTMP, &truncate); |
| 8146 | |
| 8147 | if (input_type == Primitive::kPrimFloat) { |
| 8148 | __ CmpEqS(FTMP, src, src); |
| 8149 | } else { |
| 8150 | __ CmpEqD(FTMP, src, src); |
| 8151 | } |
| 8152 | __ Move(dst_low, ZERO); |
| 8153 | __ LoadConst32(dst_high, std::numeric_limits<int32_t>::min()); |
| 8154 | __ Mfc1(TMP, FTMP); |
| 8155 | __ And(dst_high, dst_high, TMP); |
| 8156 | |
| 8157 | __ B(&done); |
| 8158 | |
| 8159 | __ Bind(&truncate); |
| 8160 | |
| 8161 | if (input_type == Primitive::kPrimFloat) { |
| 8162 | __ TruncLS(FTMP, src); |
| 8163 | } else { |
| 8164 | __ TruncLD(FTMP, src); |
| 8165 | } |
| 8166 | __ Mfc1(dst_low, FTMP); |
| 8167 | __ Mfhc1(dst_high, FTMP); |
| 8168 | |
| 8169 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8170 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 8171 | QuickEntrypointEnum entrypoint = (input_type == Primitive::kPrimFloat) ? kQuickF2l |
| 8172 | : kQuickD2l; |
| 8173 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8174 | if (input_type == Primitive::kPrimFloat) { |
| 8175 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 8176 | } else { |
| 8177 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 8178 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8179 | } |
| 8180 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8181 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 8182 | Register dst = locations->Out().AsRegister<Register>(); |
| 8183 | MipsLabel truncate; |
| 8184 | MipsLabel done; |
| 8185 | |
| 8186 | // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate |
| 8187 | // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6, |
| 8188 | // even though it must be NAN2008=1 on R6. |
| 8189 | // |
| 8190 | // For details see the large comment above for the truncation of float/double to long on R6. |
| 8191 | // |
| 8192 | // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the |
| 8193 | // truncate instruction for MIPS64R6. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8194 | if (input_type == Primitive::kPrimFloat) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8195 | uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min()); |
| 8196 | __ LoadConst32(TMP, min_val); |
| 8197 | __ Mtc1(TMP, FTMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8198 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8199 | uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min()); |
| 8200 | __ LoadConst32(TMP, High32Bits(min_val)); |
| 8201 | __ Mtc1(ZERO, FTMP); |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 8202 | __ MoveToFpuHigh(TMP, FTMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8203 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 8204 | |
| 8205 | if (isR6) { |
| 8206 | if (input_type == Primitive::kPrimFloat) { |
| 8207 | __ CmpLeS(FTMP, FTMP, src); |
| 8208 | } else { |
| 8209 | __ CmpLeD(FTMP, FTMP, src); |
| 8210 | } |
| 8211 | __ Bc1nez(FTMP, &truncate); |
| 8212 | |
| 8213 | if (input_type == Primitive::kPrimFloat) { |
| 8214 | __ CmpEqS(FTMP, src, src); |
| 8215 | } else { |
| 8216 | __ CmpEqD(FTMP, src, src); |
| 8217 | } |
| 8218 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); |
| 8219 | __ Mfc1(TMP, FTMP); |
| 8220 | __ And(dst, dst, TMP); |
| 8221 | } else { |
| 8222 | if (input_type == Primitive::kPrimFloat) { |
| 8223 | __ ColeS(0, FTMP, src); |
| 8224 | } else { |
| 8225 | __ ColeD(0, FTMP, src); |
| 8226 | } |
| 8227 | __ Bc1t(0, &truncate); |
| 8228 | |
| 8229 | if (input_type == Primitive::kPrimFloat) { |
| 8230 | __ CeqS(0, src, src); |
| 8231 | } else { |
| 8232 | __ CeqD(0, src, src); |
| 8233 | } |
| 8234 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); |
| 8235 | __ Movf(dst, ZERO, 0); |
| 8236 | } |
| 8237 | |
| 8238 | __ B(&done); |
| 8239 | |
| 8240 | __ Bind(&truncate); |
| 8241 | |
| 8242 | if (input_type == Primitive::kPrimFloat) { |
| 8243 | __ TruncWS(FTMP, src); |
| 8244 | } else { |
| 8245 | __ TruncWD(FTMP, src); |
| 8246 | } |
| 8247 | __ Mfc1(dst, FTMP); |
| 8248 | |
| 8249 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8250 | } |
| 8251 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 8252 | Primitive::IsFloatingPointType(input_type)) { |
| 8253 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 8254 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 8255 | if (result_type == Primitive::kPrimFloat) { |
| 8256 | __ Cvtsd(dst, src); |
| 8257 | } else { |
| 8258 | __ Cvtds(dst, src); |
| 8259 | } |
| 8260 | } else { |
| 8261 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 8262 | << " to " << result_type; |
| 8263 | } |
| 8264 | } |
| 8265 | |
| 8266 | void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) { |
| 8267 | HandleShift(ushr); |
| 8268 | } |
| 8269 | |
| 8270 | void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) { |
| 8271 | HandleShift(ushr); |
| 8272 | } |
| 8273 | |
| 8274 | void LocationsBuilderMIPS::VisitXor(HXor* instruction) { |
| 8275 | HandleBinaryOp(instruction); |
| 8276 | } |
| 8277 | |
| 8278 | void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) { |
| 8279 | HandleBinaryOp(instruction); |
| 8280 | } |
| 8281 | |
| 8282 | void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 8283 | // Nothing to do, this should be removed during prepare for register allocator. |
| 8284 | LOG(FATAL) << "Unreachable"; |
| 8285 | } |
| 8286 | |
| 8287 | void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 8288 | // Nothing to do, this should be removed during prepare for register allocator. |
| 8289 | LOG(FATAL) << "Unreachable"; |
| 8290 | } |
| 8291 | |
| 8292 | void LocationsBuilderMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8293 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8294 | } |
| 8295 | |
| 8296 | void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8297 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8298 | } |
| 8299 | |
| 8300 | void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8301 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8302 | } |
| 8303 | |
| 8304 | void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8305 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8306 | } |
| 8307 | |
| 8308 | void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8309 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8310 | } |
| 8311 | |
| 8312 | void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8313 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8314 | } |
| 8315 | |
| 8316 | void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8317 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8318 | } |
| 8319 | |
| 8320 | void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8321 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8322 | } |
| 8323 | |
| 8324 | void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8325 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8326 | } |
| 8327 | |
| 8328 | void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8329 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8330 | } |
| 8331 | |
| 8332 | void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8333 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8334 | } |
| 8335 | |
| 8336 | void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8337 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8338 | } |
| 8339 | |
| 8340 | void LocationsBuilderMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8341 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8342 | } |
| 8343 | |
| 8344 | void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8345 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8346 | } |
| 8347 | |
| 8348 | void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8349 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8350 | } |
| 8351 | |
| 8352 | void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8353 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8354 | } |
| 8355 | |
| 8356 | void LocationsBuilderMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8357 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8358 | } |
| 8359 | |
| 8360 | void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8361 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8362 | } |
| 8363 | |
| 8364 | void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8365 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8366 | } |
| 8367 | |
| 8368 | void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8369 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8370 | } |
| 8371 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8372 | void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8373 | LocationSummary* locations = |
| 8374 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 8375 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8376 | } |
| 8377 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 8378 | void InstructionCodeGeneratorMIPS::GenPackedSwitchWithCompares(Register value_reg, |
| 8379 | int32_t lower_bound, |
| 8380 | uint32_t num_entries, |
| 8381 | HBasicBlock* switch_block, |
| 8382 | HBasicBlock* default_block) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8383 | // Create a set of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8384 | Register temp_reg = TMP; |
| 8385 | __ Addiu32(temp_reg, value_reg, -lower_bound); |
| 8386 | // Jump to default if index is negative |
| 8387 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 8388 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 8389 | __ Bltz(temp_reg, codegen_->GetLabelOf(default_block)); |
| 8390 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 8391 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8392 | // Jump to successors[0] if value == lower_bound. |
| 8393 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 8394 | int32_t last_index = 0; |
| 8395 | for (; num_entries - last_index > 2; last_index += 2) { |
| 8396 | __ Addiu(temp_reg, temp_reg, -2); |
| 8397 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 8398 | __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 8399 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 8400 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 8401 | } |
| 8402 | if (num_entries - last_index == 2) { |
| 8403 | // The last missing case_value. |
| 8404 | __ Addiu(temp_reg, temp_reg, -1); |
| 8405 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8406 | } |
| 8407 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8408 | // And the default for any other value. |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 8409 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8410 | __ B(codegen_->GetLabelOf(default_block)); |
| 8411 | } |
| 8412 | } |
| 8413 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 8414 | void InstructionCodeGeneratorMIPS::GenTableBasedPackedSwitch(Register value_reg, |
| 8415 | Register constant_area, |
| 8416 | int32_t lower_bound, |
| 8417 | uint32_t num_entries, |
| 8418 | HBasicBlock* switch_block, |
| 8419 | HBasicBlock* default_block) { |
| 8420 | // Create a jump table. |
| 8421 | std::vector<MipsLabel*> labels(num_entries); |
| 8422 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 8423 | for (uint32_t i = 0; i < num_entries; i++) { |
| 8424 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 8425 | } |
| 8426 | JumpTable* table = __ CreateJumpTable(std::move(labels)); |
| 8427 | |
| 8428 | // Is the value in range? |
| 8429 | __ Addiu32(TMP, value_reg, -lower_bound); |
| 8430 | if (IsInt<16>(static_cast<int32_t>(num_entries))) { |
| 8431 | __ Sltiu(AT, TMP, num_entries); |
| 8432 | __ Beqz(AT, codegen_->GetLabelOf(default_block)); |
| 8433 | } else { |
| 8434 | __ LoadConst32(AT, num_entries); |
| 8435 | __ Bgeu(TMP, AT, codegen_->GetLabelOf(default_block)); |
| 8436 | } |
| 8437 | |
| 8438 | // We are in the range of the table. |
| 8439 | // Load the target address from the jump table, indexing by the value. |
| 8440 | __ LoadLabelAddress(AT, constant_area, table->GetLabel()); |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 8441 | __ ShiftAndAdd(TMP, TMP, AT, 2, TMP); |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 8442 | __ Lw(TMP, TMP, 0); |
| 8443 | // Compute the absolute target address by adding the table start address |
| 8444 | // (the table contains offsets to targets relative to its start). |
| 8445 | __ Addu(TMP, TMP, AT); |
| 8446 | // And jump. |
| 8447 | __ Jr(TMP); |
| 8448 | __ NopIfNoReordering(); |
| 8449 | } |
| 8450 | |
| 8451 | void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8452 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 8453 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 8454 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8455 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8456 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 8457 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 8458 | |
| 8459 | if (codegen_->GetInstructionSetFeatures().IsR6() && |
| 8460 | num_entries > kPackedSwitchJumpTableThreshold) { |
| 8461 | // R6 uses PC-relative addressing to access the jump table. |
| 8462 | // R2, OTOH, requires an HMipsComputeBaseMethodAddress input to access |
| 8463 | // the jump table and it is implemented by changing HPackedSwitch to |
| 8464 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress. |
| 8465 | // See VisitMipsPackedSwitch() for the table-based implementation on R2. |
| 8466 | GenTableBasedPackedSwitch(value_reg, |
| 8467 | ZERO, |
| 8468 | lower_bound, |
| 8469 | num_entries, |
| 8470 | switch_block, |
| 8471 | default_block); |
| 8472 | } else { |
| 8473 | GenPackedSwitchWithCompares(value_reg, |
| 8474 | lower_bound, |
| 8475 | num_entries, |
| 8476 | switch_block, |
| 8477 | default_block); |
| 8478 | } |
| 8479 | } |
| 8480 | |
| 8481 | void LocationsBuilderMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 8482 | LocationSummary* locations = |
| 8483 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 8484 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8485 | // Constant area pointer (HMipsComputeBaseMethodAddress). |
| 8486 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8487 | } |
| 8488 | |
| 8489 | void InstructionCodeGeneratorMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 8490 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 8491 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 8492 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8493 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8494 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 8495 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 8496 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 8497 | |
| 8498 | // This is an R2-only path. HPackedSwitch has been changed to |
| 8499 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress |
| 8500 | // required to address the jump table relative to PC. |
| 8501 | GenTableBasedPackedSwitch(value_reg, |
| 8502 | constant_area, |
| 8503 | lower_bound, |
| 8504 | num_entries, |
| 8505 | switch_block, |
| 8506 | default_block); |
| 8507 | } |
| 8508 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 8509 | void LocationsBuilderMIPS::VisitMipsComputeBaseMethodAddress( |
| 8510 | HMipsComputeBaseMethodAddress* insn) { |
| 8511 | LocationSummary* locations = |
| 8512 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 8513 | locations->SetOut(Location::RequiresRegister()); |
| 8514 | } |
| 8515 | |
| 8516 | void InstructionCodeGeneratorMIPS::VisitMipsComputeBaseMethodAddress( |
| 8517 | HMipsComputeBaseMethodAddress* insn) { |
| 8518 | LocationSummary* locations = insn->GetLocations(); |
| 8519 | Register reg = locations->Out().AsRegister<Register>(); |
| 8520 | |
| 8521 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
| 8522 | |
| 8523 | // Generate a dummy PC-relative call to obtain PC. |
| 8524 | __ Nal(); |
| 8525 | // Grab the return address off RA. |
| 8526 | __ Move(reg, RA); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 8527 | // TODO: Can we share this code with that of VisitMipsDexCacheArraysBase()? |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 8528 | |
| 8529 | // Remember this offset (the obtained PC value) for later use with constant area. |
| 8530 | __ BindPcRelBaseLabel(); |
| 8531 | } |
| 8532 | |
| 8533 | void LocationsBuilderMIPS::VisitMipsDexCacheArraysBase(HMipsDexCacheArraysBase* base) { |
| 8534 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 8535 | locations->SetOut(Location::RequiresRegister()); |
| 8536 | } |
| 8537 | |
| 8538 | void InstructionCodeGeneratorMIPS::VisitMipsDexCacheArraysBase(HMipsDexCacheArraysBase* base) { |
| 8539 | Register reg = base->GetLocations()->Out().AsRegister<Register>(); |
| 8540 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
| 8541 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 8542 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
| 8543 | bool reordering = __ SetReorder(false); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8544 | // TODO: Reuse MipsComputeBaseMethodAddress on R2 instead of passing ZERO to force emitting NAL. |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 8545 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info, reg, ZERO); |
| 8546 | __ Addiu(reg, reg, /* placeholder */ 0x5678); |
| 8547 | __ SetReorder(reordering); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 8548 | } |
| 8549 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8550 | void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 8551 | // The trampoline uses the same calling convention as dex calling conventions, |
| 8552 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 8553 | // the method_idx. |
| 8554 | HandleInvoke(invoke); |
| 8555 | } |
| 8556 | |
| 8557 | void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 8558 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 8559 | } |
| 8560 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 8561 | void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 8562 | LocationSummary* locations = |
| 8563 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 8564 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8565 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8566 | } |
| 8567 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 8568 | void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 8569 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8570 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8571 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 8572 | instruction->GetIndex(), kMipsPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8573 | __ LoadFromOffset(kLoadWord, |
| 8574 | locations->Out().AsRegister<Register>(), |
| 8575 | locations->InAt(0).AsRegister<Register>(), |
| 8576 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 8577 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8578 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 8579 | instruction->GetIndex(), kMipsPointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 8580 | __ LoadFromOffset(kLoadWord, |
| 8581 | locations->Out().AsRegister<Register>(), |
| 8582 | locations->InAt(0).AsRegister<Register>(), |
| 8583 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8584 | __ LoadFromOffset(kLoadWord, |
| 8585 | locations->Out().AsRegister<Register>(), |
| 8586 | locations->Out().AsRegister<Register>(), |
| 8587 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 8588 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8589 | } |
| 8590 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 8591 | #undef __ |
| 8592 | #undef QUICK_ENTRY_POINT |
| 8593 | |
| 8594 | } // namespace mips |
| 8595 | } // namespace art |