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: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 394 | explicit TypeCheckSlowPathMIPS(HInstruction* instruction) : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 395 | |
| 396 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 397 | LocationSummary* locations = instruction_->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 398 | uint32_t dex_pc = instruction_->GetDexPc(); |
| 399 | DCHECK(instruction_->IsCheckCast() |
| 400 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 401 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 402 | |
| 403 | __ Bind(GetEntryLabel()); |
| 404 | SaveLiveRegisters(codegen, locations); |
| 405 | |
| 406 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 407 | // move resolver. |
| 408 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 409 | codegen->EmitParallelMoves(locations->InAt(0), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 410 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 411 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 412 | locations->InAt(1), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 413 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 414 | Primitive::kPrimNot); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 415 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 416 | mips_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 417 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 418 | Primitive::Type ret_type = instruction_->GetType(); |
| 419 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 420 | mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 421 | } else { |
| 422 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 423 | mips_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 424 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | RestoreLiveRegisters(codegen, locations); |
| 428 | __ B(GetExitLabel()); |
| 429 | } |
| 430 | |
| 431 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; } |
| 432 | |
| 433 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 434 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS); |
| 435 | }; |
| 436 | |
| 437 | class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS { |
| 438 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 439 | explicit DeoptimizationSlowPathMIPS(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 440 | : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 441 | |
| 442 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 443 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 444 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 445 | mips_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 446 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; } |
| 450 | |
| 451 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 452 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS); |
| 453 | }; |
| 454 | |
| 455 | CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph, |
| 456 | const MipsInstructionSetFeatures& isa_features, |
| 457 | const CompilerOptions& compiler_options, |
| 458 | OptimizingCompilerStats* stats) |
| 459 | : CodeGenerator(graph, |
| 460 | kNumberOfCoreRegisters, |
| 461 | kNumberOfFRegisters, |
| 462 | kNumberOfRegisterPairs, |
| 463 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 464 | arraysize(kCoreCalleeSaves)), |
| 465 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 466 | arraysize(kFpuCalleeSaves)), |
| 467 | compiler_options, |
| 468 | stats), |
| 469 | block_labels_(nullptr), |
| 470 | location_builder_(graph, this), |
| 471 | instruction_visitor_(graph, this), |
| 472 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 473 | assembler_(graph->GetArena(), &isa_features), |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 474 | isa_features_(isa_features), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 475 | uint32_literals_(std::less<uint32_t>(), |
| 476 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 477 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 478 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 479 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 480 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 481 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 482 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 483 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 484 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 485 | boot_image_address_patches_(std::less<uint32_t>(), |
| 486 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 487 | jit_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 488 | jit_class_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 489 | clobbered_ra_(false) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 490 | // Save RA (containing the return address) to mimic Quick. |
| 491 | AddAllocatedRegister(Location::RegisterLocation(RA)); |
| 492 | } |
| 493 | |
| 494 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 495 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 496 | #define __ down_cast<MipsAssembler*>(GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 497 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value() |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 498 | |
| 499 | void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) { |
| 500 | // Ensure that we fix up branches. |
| 501 | __ FinalizeCode(); |
| 502 | |
| 503 | // Adjust native pc offsets in stack maps. |
| 504 | 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] | 505 | uint32_t old_position = |
| 506 | stack_map_stream_.GetStackMap(i).native_pc_code_offset.Uint32Value(kMips); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 507 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 508 | DCHECK_GE(new_position, old_position); |
| 509 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 510 | } |
| 511 | |
| 512 | // Adjust pc offsets for the disassembly information. |
| 513 | if (disasm_info_ != nullptr) { |
| 514 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 515 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 516 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 517 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 518 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 519 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 520 | } |
| 521 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 522 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 523 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | CodeGenerator::Finalize(allocator); |
| 528 | } |
| 529 | |
| 530 | MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const { |
| 531 | return codegen_->GetAssembler(); |
| 532 | } |
| 533 | |
| 534 | void ParallelMoveResolverMIPS::EmitMove(size_t index) { |
| 535 | DCHECK_LT(index, moves_.size()); |
| 536 | MoveOperands* move = moves_[index]; |
| 537 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); |
| 538 | } |
| 539 | |
| 540 | void ParallelMoveResolverMIPS::EmitSwap(size_t index) { |
| 541 | DCHECK_LT(index, moves_.size()); |
| 542 | MoveOperands* move = moves_[index]; |
| 543 | Primitive::Type type = move->GetType(); |
| 544 | Location loc1 = move->GetDestination(); |
| 545 | Location loc2 = move->GetSource(); |
| 546 | |
| 547 | DCHECK(!loc1.IsConstant()); |
| 548 | DCHECK(!loc2.IsConstant()); |
| 549 | |
| 550 | if (loc1.Equals(loc2)) { |
| 551 | return; |
| 552 | } |
| 553 | |
| 554 | if (loc1.IsRegister() && loc2.IsRegister()) { |
| 555 | // Swap 2 GPRs. |
| 556 | Register r1 = loc1.AsRegister<Register>(); |
| 557 | Register r2 = loc2.AsRegister<Register>(); |
| 558 | __ Move(TMP, r2); |
| 559 | __ Move(r2, r1); |
| 560 | __ Move(r1, TMP); |
| 561 | } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) { |
| 562 | FRegister f1 = loc1.AsFpuRegister<FRegister>(); |
| 563 | FRegister f2 = loc2.AsFpuRegister<FRegister>(); |
| 564 | if (type == Primitive::kPrimFloat) { |
| 565 | __ MovS(FTMP, f2); |
| 566 | __ MovS(f2, f1); |
| 567 | __ MovS(f1, FTMP); |
| 568 | } else { |
| 569 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 570 | __ MovD(FTMP, f2); |
| 571 | __ MovD(f2, f1); |
| 572 | __ MovD(f1, FTMP); |
| 573 | } |
| 574 | } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) || |
| 575 | (loc1.IsFpuRegister() && loc2.IsRegister())) { |
| 576 | // Swap FPR and GPR. |
| 577 | DCHECK_EQ(type, Primitive::kPrimFloat); // Can only swap a float. |
| 578 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 579 | : loc2.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 580 | Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 581 | __ Move(TMP, r2); |
| 582 | __ Mfc1(r2, f1); |
| 583 | __ Mtc1(TMP, f1); |
| 584 | } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) { |
| 585 | // Swap 2 GPR register pairs. |
| 586 | Register r1 = loc1.AsRegisterPairLow<Register>(); |
| 587 | Register r2 = loc2.AsRegisterPairLow<Register>(); |
| 588 | __ Move(TMP, r2); |
| 589 | __ Move(r2, r1); |
| 590 | __ Move(r1, TMP); |
| 591 | r1 = loc1.AsRegisterPairHigh<Register>(); |
| 592 | r2 = loc2.AsRegisterPairHigh<Register>(); |
| 593 | __ Move(TMP, r2); |
| 594 | __ Move(r2, r1); |
| 595 | __ Move(r1, TMP); |
| 596 | } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) || |
| 597 | (loc1.IsFpuRegister() && loc2.IsRegisterPair())) { |
| 598 | // Swap FPR and GPR register pair. |
| 599 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 600 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 601 | : loc2.AsFpuRegister<FRegister>(); |
| 602 | Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 603 | : loc2.AsRegisterPairLow<Register>(); |
| 604 | Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 605 | : loc2.AsRegisterPairHigh<Register>(); |
| 606 | // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and |
| 607 | // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR |
| 608 | // unpredictable and the following mfch1 will fail. |
| 609 | __ Mfc1(TMP, f1); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 610 | __ MoveFromFpuHigh(AT, f1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 611 | __ Mtc1(r2_l, f1); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 612 | __ MoveToFpuHigh(r2_h, f1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 613 | __ Move(r2_l, TMP); |
| 614 | __ Move(r2_h, AT); |
| 615 | } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) { |
| 616 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false); |
| 617 | } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) { |
| 618 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 619 | } else if ((loc1.IsRegister() && loc2.IsStackSlot()) || |
| 620 | (loc1.IsStackSlot() && loc2.IsRegister())) { |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 621 | Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>(); |
| 622 | intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex(); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 623 | __ Move(TMP, reg); |
| 624 | __ LoadFromOffset(kLoadWord, reg, SP, offset); |
| 625 | __ StoreToOffset(kStoreWord, TMP, SP, offset); |
| 626 | } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) || |
| 627 | (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) { |
| 628 | Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 629 | : loc2.AsRegisterPairLow<Register>(); |
| 630 | Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 631 | : loc2.AsRegisterPairHigh<Register>(); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 632 | intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex(); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 633 | intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize) |
| 634 | : loc2.GetHighStackIndex(kMipsWordSize); |
| 635 | __ Move(TMP, reg_l); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 636 | __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 637 | __ StoreToOffset(kStoreWord, TMP, SP, offset_l); |
David Brazdil | 04d3e87 | 2016-01-29 09:50:09 +0000 | [diff] [blame] | 638 | __ Move(TMP, reg_h); |
| 639 | __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h); |
| 640 | __ StoreToOffset(kStoreWord, TMP, SP, offset_h); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 641 | } else if (loc1.IsFpuRegister() || loc2.IsFpuRegister()) { |
| 642 | FRegister reg = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 643 | : loc2.AsFpuRegister<FRegister>(); |
| 644 | intptr_t offset = loc1.IsFpuRegister() ? loc2.GetStackIndex() : loc1.GetStackIndex(); |
| 645 | if (type == Primitive::kPrimFloat) { |
| 646 | __ MovS(FTMP, reg); |
| 647 | __ LoadSFromOffset(reg, SP, offset); |
| 648 | __ StoreSToOffset(FTMP, SP, offset); |
| 649 | } else { |
| 650 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 651 | __ MovD(FTMP, reg); |
| 652 | __ LoadDFromOffset(reg, SP, offset); |
| 653 | __ StoreDToOffset(FTMP, SP, offset); |
| 654 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 655 | } else { |
| 656 | LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported"; |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | void ParallelMoveResolverMIPS::RestoreScratch(int reg) { |
| 661 | __ Pop(static_cast<Register>(reg)); |
| 662 | } |
| 663 | |
| 664 | void ParallelMoveResolverMIPS::SpillScratch(int reg) { |
| 665 | __ Push(static_cast<Register>(reg)); |
| 666 | } |
| 667 | |
| 668 | void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) { |
| 669 | // Allocate a scratch register other than TMP, if available. |
| 670 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be |
| 671 | // automatically unspilled when the scratch scope object is destroyed). |
| 672 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); |
| 673 | // If V0 spills onto the stack, SP-relative offsets need to be adjusted. |
| 674 | int stack_offset = ensure_scratch.IsSpilled() ? kMipsWordSize : 0; |
| 675 | for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) { |
| 676 | __ LoadFromOffset(kLoadWord, |
| 677 | Register(ensure_scratch.GetRegister()), |
| 678 | SP, |
| 679 | index1 + stack_offset); |
| 680 | __ LoadFromOffset(kLoadWord, |
| 681 | TMP, |
| 682 | SP, |
| 683 | index2 + stack_offset); |
| 684 | __ StoreToOffset(kStoreWord, |
| 685 | Register(ensure_scratch.GetRegister()), |
| 686 | SP, |
| 687 | index2 + stack_offset); |
| 688 | __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset); |
| 689 | } |
| 690 | } |
| 691 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 692 | void CodeGeneratorMIPS::ComputeSpillMask() { |
| 693 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 694 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 695 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 696 | // If there're FPU callee-saved registers and there's an odd number of GPR callee-saved |
| 697 | // registers, include the ZERO register to force alignment of FPU callee-saved registers |
| 698 | // within the stack frame. |
| 699 | if ((fpu_spill_mask_ != 0) && (POPCOUNT(core_spill_mask_) % 2 != 0)) { |
| 700 | core_spill_mask_ |= (1 << ZERO); |
| 701 | } |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | bool CodeGeneratorMIPS::HasAllocatedCalleeSaveRegisters() const { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 705 | // 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] | 706 | // (this can happen in leaf methods), force CodeGenerator::InitializeCodeGeneration() |
| 707 | // into the path that creates a stack frame so that RA can be explicitly saved and restored. |
| 708 | // 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] | 709 | return CodeGenerator::HasAllocatedCalleeSaveRegisters() || clobbered_ra_; |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 710 | } |
| 711 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 712 | static dwarf::Reg DWARFReg(Register reg) { |
| 713 | return dwarf::Reg::MipsCore(static_cast<int>(reg)); |
| 714 | } |
| 715 | |
| 716 | // TODO: mapping of floating-point registers to DWARF. |
| 717 | |
| 718 | void CodeGeneratorMIPS::GenerateFrameEntry() { |
| 719 | __ Bind(&frame_entry_label_); |
| 720 | |
| 721 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips) || !IsLeafMethod(); |
| 722 | |
| 723 | if (do_overflow_check) { |
| 724 | __ LoadFromOffset(kLoadWord, |
| 725 | ZERO, |
| 726 | SP, |
| 727 | -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips))); |
| 728 | RecordPcInfo(nullptr, 0); |
| 729 | } |
| 730 | |
| 731 | if (HasEmptyFrame()) { |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 732 | CHECK_EQ(fpu_spill_mask_, 0u); |
| 733 | CHECK_EQ(core_spill_mask_, 1u << RA); |
| 734 | CHECK(!clobbered_ra_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 735 | return; |
| 736 | } |
| 737 | |
| 738 | // Make sure the frame size isn't unreasonably large. |
| 739 | if (GetFrameSize() > GetStackOverflowReservedBytes(kMips)) { |
| 740 | LOG(FATAL) << "Stack frame larger than " << GetStackOverflowReservedBytes(kMips) << " bytes"; |
| 741 | } |
| 742 | |
| 743 | // Spill callee-saved registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 744 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 745 | uint32_t ofs = GetFrameSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 746 | __ IncreaseFrameSize(ofs); |
| 747 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 748 | for (uint32_t mask = core_spill_mask_; mask != 0; ) { |
| 749 | Register reg = static_cast<Register>(MostSignificantBit(mask)); |
| 750 | mask ^= 1u << reg; |
| 751 | ofs -= kMipsWordSize; |
| 752 | // The ZERO register is only included for alignment. |
| 753 | if (reg != ZERO) { |
| 754 | __ StoreToOffset(kStoreWord, reg, SP, ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 755 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 756 | } |
| 757 | } |
| 758 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 759 | for (uint32_t mask = fpu_spill_mask_; mask != 0; ) { |
| 760 | FRegister reg = static_cast<FRegister>(MostSignificantBit(mask)); |
| 761 | mask ^= 1u << reg; |
| 762 | ofs -= kMipsDoublewordSize; |
| 763 | __ StoreDToOffset(reg, SP, ofs); |
| 764 | // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 765 | } |
| 766 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 767 | // Save the current method if we need it. Note that we do not |
| 768 | // do this in HCurrentMethod, as the instruction might have been removed |
| 769 | // in the SSA graph. |
| 770 | if (RequiresCurrentMethod()) { |
| 771 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
| 772 | } |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 773 | |
| 774 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 775 | // Initialize should deoptimize flag to 0. |
| 776 | __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 777 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | void CodeGeneratorMIPS::GenerateFrameExit() { |
| 781 | __ cfi().RememberState(); |
| 782 | |
| 783 | if (!HasEmptyFrame()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 784 | // Restore callee-saved registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 785 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 786 | // For better instruction scheduling restore RA before other registers. |
| 787 | uint32_t ofs = GetFrameSize(); |
| 788 | for (uint32_t mask = core_spill_mask_; mask != 0; ) { |
| 789 | Register reg = static_cast<Register>(MostSignificantBit(mask)); |
| 790 | mask ^= 1u << reg; |
| 791 | ofs -= kMipsWordSize; |
| 792 | // The ZERO register is only included for alignment. |
| 793 | if (reg != ZERO) { |
| 794 | __ LoadFromOffset(kLoadWord, reg, SP, ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 795 | __ cfi().Restore(DWARFReg(reg)); |
| 796 | } |
| 797 | } |
| 798 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 799 | for (uint32_t mask = fpu_spill_mask_; mask != 0; ) { |
| 800 | FRegister reg = static_cast<FRegister>(MostSignificantBit(mask)); |
| 801 | mask ^= 1u << reg; |
| 802 | ofs -= kMipsDoublewordSize; |
| 803 | __ LoadDFromOffset(reg, SP, ofs); |
| 804 | // TODO: __ cfi().Restore(DWARFReg(reg)); |
| 805 | } |
| 806 | |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 807 | size_t frame_size = GetFrameSize(); |
| 808 | // Adjust the stack pointer in the delay slot if doing so doesn't break CFI. |
| 809 | bool exchange = IsInt<16>(static_cast<int32_t>(frame_size)); |
| 810 | bool reordering = __ SetReorder(false); |
| 811 | if (exchange) { |
| 812 | __ Jr(RA); |
| 813 | __ DecreaseFrameSize(frame_size); // Single instruction in delay slot. |
| 814 | } else { |
| 815 | __ DecreaseFrameSize(frame_size); |
| 816 | __ Jr(RA); |
| 817 | __ Nop(); // In delay slot. |
| 818 | } |
| 819 | __ SetReorder(reordering); |
| 820 | } else { |
| 821 | __ Jr(RA); |
| 822 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 823 | } |
| 824 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 825 | __ cfi().RestoreState(); |
| 826 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 827 | } |
| 828 | |
| 829 | void CodeGeneratorMIPS::Bind(HBasicBlock* block) { |
| 830 | __ Bind(GetLabelOf(block)); |
| 831 | } |
| 832 | |
| 833 | void CodeGeneratorMIPS::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
| 834 | if (src.Equals(dst)) { |
| 835 | return; |
| 836 | } |
| 837 | |
| 838 | if (src.IsConstant()) { |
| 839 | MoveConstant(dst, src.GetConstant()); |
| 840 | } else { |
| 841 | if (Primitive::Is64BitType(dst_type)) { |
| 842 | Move64(dst, src); |
| 843 | } else { |
| 844 | Move32(dst, src); |
| 845 | } |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | void CodeGeneratorMIPS::Move32(Location destination, Location source) { |
| 850 | if (source.Equals(destination)) { |
| 851 | return; |
| 852 | } |
| 853 | |
| 854 | if (destination.IsRegister()) { |
| 855 | if (source.IsRegister()) { |
| 856 | __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 857 | } else if (source.IsFpuRegister()) { |
| 858 | __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>()); |
| 859 | } else { |
| 860 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 861 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
| 862 | } |
| 863 | } else if (destination.IsFpuRegister()) { |
| 864 | if (source.IsRegister()) { |
| 865 | __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>()); |
| 866 | } else if (source.IsFpuRegister()) { |
| 867 | __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 868 | } else { |
| 869 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 870 | __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 871 | } |
| 872 | } else { |
| 873 | DCHECK(destination.IsStackSlot()) << destination; |
| 874 | if (source.IsRegister()) { |
| 875 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
| 876 | } else if (source.IsFpuRegister()) { |
| 877 | __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex()); |
| 878 | } else { |
| 879 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 880 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 881 | __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex()); |
| 882 | } |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | void CodeGeneratorMIPS::Move64(Location destination, Location source) { |
| 887 | if (source.Equals(destination)) { |
| 888 | return; |
| 889 | } |
| 890 | |
| 891 | if (destination.IsRegisterPair()) { |
| 892 | if (source.IsRegisterPair()) { |
| 893 | __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 894 | __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 895 | } else if (source.IsFpuRegister()) { |
| 896 | Register dst_high = destination.AsRegisterPairHigh<Register>(); |
| 897 | Register dst_low = destination.AsRegisterPairLow<Register>(); |
| 898 | FRegister src = source.AsFpuRegister<FRegister>(); |
| 899 | __ Mfc1(dst_low, src); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 900 | __ MoveFromFpuHigh(dst_high, src); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 901 | } else { |
| 902 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 903 | int32_t off = source.GetStackIndex(); |
| 904 | Register r = destination.AsRegisterPairLow<Register>(); |
| 905 | __ LoadFromOffset(kLoadDoubleword, r, SP, off); |
| 906 | } |
| 907 | } else if (destination.IsFpuRegister()) { |
| 908 | if (source.IsRegisterPair()) { |
| 909 | FRegister dst = destination.AsFpuRegister<FRegister>(); |
| 910 | Register src_high = source.AsRegisterPairHigh<Register>(); |
| 911 | Register src_low = source.AsRegisterPairLow<Register>(); |
| 912 | __ Mtc1(src_low, dst); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 913 | __ MoveToFpuHigh(src_high, dst); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 914 | } else if (source.IsFpuRegister()) { |
| 915 | __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 916 | } else { |
| 917 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 918 | __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 919 | } |
| 920 | } else { |
| 921 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 922 | int32_t off = destination.GetStackIndex(); |
| 923 | if (source.IsRegisterPair()) { |
| 924 | __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, off); |
| 925 | } else if (source.IsFpuRegister()) { |
| 926 | __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, off); |
| 927 | } else { |
| 928 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 929 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 930 | __ StoreToOffset(kStoreWord, TMP, SP, off); |
| 931 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4); |
| 932 | __ StoreToOffset(kStoreWord, TMP, SP, off + 4); |
| 933 | } |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) { |
| 938 | if (c->IsIntConstant() || c->IsNullConstant()) { |
| 939 | // Move 32 bit constant. |
| 940 | int32_t value = GetInt32ValueOf(c); |
| 941 | if (destination.IsRegister()) { |
| 942 | Register dst = destination.AsRegister<Register>(); |
| 943 | __ LoadConst32(dst, value); |
| 944 | } else { |
| 945 | DCHECK(destination.IsStackSlot()) |
| 946 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 947 | __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 948 | } |
| 949 | } else if (c->IsLongConstant()) { |
| 950 | // Move 64 bit constant. |
| 951 | int64_t value = GetInt64ValueOf(c); |
| 952 | if (destination.IsRegisterPair()) { |
| 953 | Register r_h = destination.AsRegisterPairHigh<Register>(); |
| 954 | Register r_l = destination.AsRegisterPairLow<Register>(); |
| 955 | __ LoadConst64(r_h, r_l, value); |
| 956 | } else { |
| 957 | DCHECK(destination.IsDoubleStackSlot()) |
| 958 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 959 | __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 960 | } |
| 961 | } else if (c->IsFloatConstant()) { |
| 962 | // Move 32 bit float constant. |
| 963 | int32_t value = GetInt32ValueOf(c); |
| 964 | if (destination.IsFpuRegister()) { |
| 965 | __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP); |
| 966 | } else { |
| 967 | DCHECK(destination.IsStackSlot()) |
| 968 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 969 | __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 970 | } |
| 971 | } else { |
| 972 | // Move 64 bit double constant. |
| 973 | DCHECK(c->IsDoubleConstant()) << c->DebugName(); |
| 974 | int64_t value = GetInt64ValueOf(c); |
| 975 | if (destination.IsFpuRegister()) { |
| 976 | FRegister fd = destination.AsFpuRegister<FRegister>(); |
| 977 | __ LoadDConst64(fd, value, TMP); |
| 978 | } else { |
| 979 | DCHECK(destination.IsDoubleStackSlot()) |
| 980 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 981 | __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 982 | } |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) { |
| 987 | DCHECK(destination.IsRegister()); |
| 988 | Register dst = destination.AsRegister<Register>(); |
| 989 | __ LoadConst32(dst, value); |
| 990 | } |
| 991 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 992 | void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 993 | if (location.IsRegister()) { |
| 994 | locations->AddTemp(location); |
Alexey Frunze | c9e94f3 | 2015-10-26 16:11:39 -0700 | [diff] [blame] | 995 | } else if (location.IsRegisterPair()) { |
| 996 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 997 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 998 | } else { |
| 999 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1000 | } |
| 1001 | } |
| 1002 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1003 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 1004 | inline void CodeGeneratorMIPS::EmitPcRelativeLinkerPatches( |
| 1005 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 1006 | ArenaVector<LinkerPatch>* linker_patches) { |
| 1007 | for (const PcRelativePatchInfo& info : infos) { |
| 1008 | const DexFile& dex_file = info.target_dex_file; |
| 1009 | size_t offset_or_index = info.offset_or_index; |
| 1010 | DCHECK(info.high_label.IsBound()); |
| 1011 | uint32_t high_offset = __ GetLabelLocation(&info.high_label); |
| 1012 | // On R2 we use HMipsComputeBaseMethodAddress and patch relative to |
| 1013 | // the assembler's base label used for PC-relative addressing. |
| 1014 | uint32_t pc_rel_offset = info.pc_rel_label.IsBound() |
| 1015 | ? __ GetLabelLocation(&info.pc_rel_label) |
| 1016 | : __ GetPcRelBaseLabelLocation(); |
| 1017 | linker_patches->push_back(Factory(high_offset, &dex_file, pc_rel_offset, offset_or_index)); |
| 1018 | } |
| 1019 | } |
| 1020 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1021 | void CodeGeneratorMIPS::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 1022 | DCHECK(linker_patches->empty()); |
| 1023 | size_t size = |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1024 | pc_relative_dex_cache_patches_.size() + |
| 1025 | pc_relative_string_patches_.size() + |
| 1026 | pc_relative_type_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1027 | type_bss_entry_patches_.size() + |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1028 | boot_image_string_patches_.size() + |
| 1029 | boot_image_type_patches_.size() + |
| 1030 | boot_image_address_patches_.size(); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1031 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1032 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 1033 | linker_patches); |
| 1034 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1035 | DCHECK(pc_relative_type_patches_.empty()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1036 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 1037 | linker_patches); |
| 1038 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1039 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 1040 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1041 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 1042 | linker_patches); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1043 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1044 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 1045 | linker_patches); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1046 | for (const auto& entry : boot_image_string_patches_) { |
| 1047 | const StringReference& target_string = entry.first; |
| 1048 | Literal* literal = entry.second; |
| 1049 | DCHECK(literal->GetLabel()->IsBound()); |
| 1050 | uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel()); |
| 1051 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 1052 | target_string.dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 1053 | target_string.string_index.index_)); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1054 | } |
| 1055 | for (const auto& entry : boot_image_type_patches_) { |
| 1056 | const TypeReference& target_type = entry.first; |
| 1057 | Literal* literal = entry.second; |
| 1058 | DCHECK(literal->GetLabel()->IsBound()); |
| 1059 | uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel()); |
| 1060 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 1061 | target_type.dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1062 | target_type.type_index.index_)); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1063 | } |
| 1064 | for (const auto& entry : boot_image_address_patches_) { |
| 1065 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
| 1066 | Literal* literal = entry.second; |
| 1067 | DCHECK(literal->GetLabel()->IsBound()); |
| 1068 | uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel()); |
| 1069 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 1070 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1071 | DCHECK_EQ(size, linker_patches->size()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeStringPatch( |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1075 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 1076 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeTypePatch( |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1080 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 1081 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1082 | } |
| 1083 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1084 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewTypeBssEntryPatch( |
| 1085 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 1086 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 1087 | } |
| 1088 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1089 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeDexCacheArrayPatch( |
| 1090 | const DexFile& dex_file, uint32_t element_offset) { |
| 1091 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 1092 | } |
| 1093 | |
| 1094 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativePatch( |
| 1095 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 1096 | patches->emplace_back(dex_file, offset_or_index); |
| 1097 | return &patches->back(); |
| 1098 | } |
| 1099 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1100 | Literal* CodeGeneratorMIPS::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 1101 | return map->GetOrCreate( |
| 1102 | value, |
| 1103 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
| 1104 | } |
| 1105 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1106 | Literal* CodeGeneratorMIPS::DeduplicateMethodLiteral(MethodReference target_method, |
| 1107 | MethodToLiteralMap* map) { |
| 1108 | return map->GetOrCreate( |
| 1109 | target_method, |
| 1110 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1111 | } |
| 1112 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1113 | Literal* CodeGeneratorMIPS::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 1114 | dex::StringIndex string_index) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1115 | return boot_image_string_patches_.GetOrCreate( |
| 1116 | StringReference(&dex_file, string_index), |
| 1117 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1118 | } |
| 1119 | |
| 1120 | Literal* CodeGeneratorMIPS::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1121 | dex::TypeIndex type_index) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1122 | return boot_image_type_patches_.GetOrCreate( |
| 1123 | TypeReference(&dex_file, type_index), |
| 1124 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1125 | } |
| 1126 | |
| 1127 | Literal* CodeGeneratorMIPS::DeduplicateBootImageAddressLiteral(uint32_t address) { |
| 1128 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 1129 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 1130 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 1131 | } |
| 1132 | |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1133 | void CodeGeneratorMIPS::EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info, |
| 1134 | Register out, |
| 1135 | Register base) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1136 | if (GetInstructionSetFeatures().IsR6()) { |
| 1137 | DCHECK_EQ(base, ZERO); |
| 1138 | __ Bind(&info->high_label); |
| 1139 | __ Bind(&info->pc_rel_label); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1140 | // Add the high half of a 32-bit offset to PC. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1141 | __ Auipc(out, /* placeholder */ 0x1234); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1142 | } else { |
| 1143 | // If base is ZERO, emit NAL to obtain the actual base. |
| 1144 | if (base == ZERO) { |
| 1145 | // Generate a dummy PC-relative call to obtain PC. |
| 1146 | __ Nal(); |
| 1147 | } |
| 1148 | __ Bind(&info->high_label); |
| 1149 | __ Lui(out, /* placeholder */ 0x1234); |
| 1150 | // If we emitted the NAL, bind the pc_rel_label, otherwise base is a register holding |
| 1151 | // the HMipsComputeBaseMethodAddress which has its own label stored in MipsAssembler. |
| 1152 | if (base == ZERO) { |
| 1153 | __ Bind(&info->pc_rel_label); |
| 1154 | } |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1155 | // Add the high half of a 32-bit offset to PC. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1156 | __ Addu(out, out, (base == ZERO) ? RA : base); |
| 1157 | } |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 1158 | // The immediately following instruction will add the sign-extended low half of the 32-bit |
| 1159 | // offset to `out` (e.g. lw, jialc, addiu). |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 1162 | CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootStringPatch( |
| 1163 | const DexFile& dex_file, |
| 1164 | dex::StringIndex dex_index, |
| 1165 | Handle<mirror::String> handle) { |
| 1166 | jit_string_roots_.Overwrite(StringReference(&dex_file, dex_index), |
| 1167 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
| 1168 | jit_string_patches_.emplace_back(dex_file, dex_index.index_); |
| 1169 | return &jit_string_patches_.back(); |
| 1170 | } |
| 1171 | |
| 1172 | CodeGeneratorMIPS::JitPatchInfo* CodeGeneratorMIPS::NewJitRootClassPatch( |
| 1173 | const DexFile& dex_file, |
| 1174 | dex::TypeIndex dex_index, |
| 1175 | Handle<mirror::Class> handle) { |
| 1176 | jit_class_roots_.Overwrite(TypeReference(&dex_file, dex_index), |
| 1177 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
| 1178 | jit_class_patches_.emplace_back(dex_file, dex_index.index_); |
| 1179 | return &jit_class_patches_.back(); |
| 1180 | } |
| 1181 | |
| 1182 | void CodeGeneratorMIPS::PatchJitRootUse(uint8_t* code, |
| 1183 | const uint8_t* roots_data, |
| 1184 | const CodeGeneratorMIPS::JitPatchInfo& info, |
| 1185 | uint64_t index_in_table) const { |
| 1186 | uint32_t literal_offset = GetAssembler().GetLabelLocation(&info.high_label); |
| 1187 | uintptr_t address = |
| 1188 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 1189 | uint32_t addr32 = dchecked_integral_cast<uint32_t>(address); |
| 1190 | // lui reg, addr32_high |
| 1191 | DCHECK_EQ(code[literal_offset + 0], 0x34); |
| 1192 | DCHECK_EQ(code[literal_offset + 1], 0x12); |
| 1193 | DCHECK_EQ((code[literal_offset + 2] & 0xE0), 0x00); |
| 1194 | DCHECK_EQ(code[literal_offset + 3], 0x3C); |
| 1195 | // lw reg, reg, addr32_low |
| 1196 | DCHECK_EQ(code[literal_offset + 4], 0x78); |
| 1197 | DCHECK_EQ(code[literal_offset + 5], 0x56); |
| 1198 | DCHECK_EQ((code[literal_offset + 7] & 0xFC), 0x8C); |
| 1199 | addr32 += (addr32 & 0x8000) << 1; // Account for sign extension in "lw reg, reg, addr32_low". |
| 1200 | // lui reg, addr32_high |
| 1201 | code[literal_offset + 0] = static_cast<uint8_t>(addr32 >> 16); |
| 1202 | code[literal_offset + 1] = static_cast<uint8_t>(addr32 >> 24); |
| 1203 | // lw reg, reg, addr32_low |
| 1204 | code[literal_offset + 4] = static_cast<uint8_t>(addr32 >> 0); |
| 1205 | code[literal_offset + 5] = static_cast<uint8_t>(addr32 >> 8); |
| 1206 | } |
| 1207 | |
| 1208 | void CodeGeneratorMIPS::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 1209 | for (const JitPatchInfo& info : jit_string_patches_) { |
| 1210 | const auto& it = jit_string_roots_.find(StringReference(&info.target_dex_file, |
| 1211 | dex::StringIndex(info.index))); |
| 1212 | DCHECK(it != jit_string_roots_.end()); |
| 1213 | PatchJitRootUse(code, roots_data, info, it->second); |
| 1214 | } |
| 1215 | for (const JitPatchInfo& info : jit_class_patches_) { |
| 1216 | const auto& it = jit_class_roots_.find(TypeReference(&info.target_dex_file, |
| 1217 | dex::TypeIndex(info.index))); |
| 1218 | DCHECK(it != jit_class_roots_.end()); |
| 1219 | PatchJitRootUse(code, roots_data, info, it->second); |
| 1220 | } |
| 1221 | } |
| 1222 | |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1223 | void CodeGeneratorMIPS::MarkGCCard(Register object, |
| 1224 | Register value, |
| 1225 | bool value_can_be_null) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1226 | MipsLabel done; |
| 1227 | Register card = AT; |
| 1228 | Register temp = TMP; |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1229 | if (value_can_be_null) { |
| 1230 | __ Beqz(value, &done); |
| 1231 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1232 | __ LoadFromOffset(kLoadWord, |
| 1233 | card, |
| 1234 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1235 | Thread::CardTableOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1236 | __ Srl(temp, object, gc::accounting::CardTable::kCardShift); |
| 1237 | __ Addu(temp, card, temp); |
| 1238 | __ Sb(card, temp, 0); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1239 | if (value_can_be_null) { |
| 1240 | __ Bind(&done); |
| 1241 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1242 | } |
| 1243 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1244 | void CodeGeneratorMIPS::SetupBlockedRegisters() const { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1245 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1246 | blocked_core_registers_[ZERO] = true; |
| 1247 | blocked_core_registers_[K0] = true; |
| 1248 | blocked_core_registers_[K1] = true; |
| 1249 | blocked_core_registers_[GP] = true; |
| 1250 | blocked_core_registers_[SP] = true; |
| 1251 | blocked_core_registers_[RA] = true; |
| 1252 | |
| 1253 | // AT and TMP(T8) are used as temporary/scratch registers |
| 1254 | // (similar to how AT is used by MIPS assemblers). |
| 1255 | blocked_core_registers_[AT] = true; |
| 1256 | blocked_core_registers_[TMP] = true; |
| 1257 | blocked_fpu_registers_[FTMP] = true; |
| 1258 | |
| 1259 | // Reserve suspend and thread registers. |
| 1260 | blocked_core_registers_[S0] = true; |
| 1261 | blocked_core_registers_[TR] = true; |
| 1262 | |
| 1263 | // Reserve T9 for function calls |
| 1264 | blocked_core_registers_[T9] = true; |
| 1265 | |
| 1266 | // Reserve odd-numbered FPU registers. |
| 1267 | for (size_t i = 1; i < kNumberOfFRegisters; i += 2) { |
| 1268 | blocked_fpu_registers_[i] = true; |
| 1269 | } |
| 1270 | |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 1271 | if (GetGraph()->IsDebuggable()) { |
| 1272 | // Stubs do not save callee-save floating point registers. If the graph |
| 1273 | // is debuggable, we need to deal with these registers differently. For |
| 1274 | // now, just block them. |
| 1275 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1276 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1277 | } |
| 1278 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1279 | } |
| 1280 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1281 | size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1282 | __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index); |
| 1283 | return kMipsWordSize; |
| 1284 | } |
| 1285 | |
| 1286 | size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1287 | __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index); |
| 1288 | return kMipsWordSize; |
| 1289 | } |
| 1290 | |
| 1291 | size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1292 | __ StoreDToOffset(FRegister(reg_id), SP, stack_index); |
| 1293 | return kMipsDoublewordSize; |
| 1294 | } |
| 1295 | |
| 1296 | size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1297 | __ LoadDFromOffset(FRegister(reg_id), SP, stack_index); |
| 1298 | return kMipsDoublewordSize; |
| 1299 | } |
| 1300 | |
| 1301 | void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1302 | stream << Register(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1306 | stream << FRegister(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1307 | } |
| 1308 | |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1309 | constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16; |
| 1310 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1311 | void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1312 | HInstruction* instruction, |
| 1313 | uint32_t dex_pc, |
| 1314 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1315 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1316 | bool reordering = __ SetReorder(false); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1317 | __ LoadFromOffset(kLoadWord, T9, TR, GetThreadOffset<kMipsPointerSize>(entrypoint).Int32Value()); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1318 | __ Jalr(T9); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1319 | if (IsDirectEntrypoint(entrypoint)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1320 | // Reserve argument space on stack (for $a0-$a3) for |
| 1321 | // entrypoints that directly reference native implementations. |
| 1322 | // Called function may use this space to store $a0-$a3 regs. |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1323 | __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1324 | __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1325 | } else { |
| 1326 | __ Nop(); // In delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1327 | } |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1328 | __ SetReorder(reordering); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1329 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1330 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1331 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path, |
| 1335 | Register class_reg) { |
| 1336 | __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 1337 | __ LoadConst32(AT, mirror::Class::kStatusInitialized); |
| 1338 | __ Blt(TMP, AT, slow_path->GetEntryLabel()); |
| 1339 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 1340 | __ Sync(0); |
| 1341 | __ Bind(slow_path->GetExitLabel()); |
| 1342 | } |
| 1343 | |
| 1344 | void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1345 | __ Sync(0); // Only stype 0 is supported. |
| 1346 | } |
| 1347 | |
| 1348 | void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1349 | HBasicBlock* successor) { |
| 1350 | SuspendCheckSlowPathMIPS* slow_path = |
| 1351 | new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS(instruction, successor); |
| 1352 | codegen_->AddSlowPath(slow_path); |
| 1353 | |
| 1354 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1355 | TMP, |
| 1356 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1357 | Thread::ThreadFlagsOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1358 | if (successor == nullptr) { |
| 1359 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
| 1360 | __ Bind(slow_path->GetReturnLabel()); |
| 1361 | } else { |
| 1362 | __ Beqz(TMP, codegen_->GetLabelOf(successor)); |
| 1363 | __ B(slow_path->GetEntryLabel()); |
| 1364 | // slow_path will return to GetLabelOf(successor). |
| 1365 | } |
| 1366 | } |
| 1367 | |
| 1368 | InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph, |
| 1369 | CodeGeneratorMIPS* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1370 | : InstructionCodeGenerator(graph, codegen), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1371 | assembler_(codegen->GetAssembler()), |
| 1372 | codegen_(codegen) {} |
| 1373 | |
| 1374 | void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1375 | DCHECK_EQ(instruction->InputCount(), 2U); |
| 1376 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1377 | Primitive::Type type = instruction->GetResultType(); |
| 1378 | switch (type) { |
| 1379 | case Primitive::kPrimInt: { |
| 1380 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1381 | HInstruction* right = instruction->InputAt(1); |
| 1382 | bool can_use_imm = false; |
| 1383 | if (right->IsConstant()) { |
| 1384 | int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant()); |
| 1385 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 1386 | can_use_imm = IsUint<16>(imm); |
| 1387 | } else if (instruction->IsAdd()) { |
| 1388 | can_use_imm = IsInt<16>(imm); |
| 1389 | } else { |
| 1390 | DCHECK(instruction->IsSub()); |
| 1391 | can_use_imm = IsInt<16>(-imm); |
| 1392 | } |
| 1393 | } |
| 1394 | if (can_use_imm) |
| 1395 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 1396 | else |
| 1397 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1398 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1399 | break; |
| 1400 | } |
| 1401 | |
| 1402 | case Primitive::kPrimLong: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1403 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1404 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1405 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1406 | break; |
| 1407 | } |
| 1408 | |
| 1409 | case Primitive::kPrimFloat: |
| 1410 | case Primitive::kPrimDouble: |
| 1411 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 1412 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1413 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1414 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1415 | break; |
| 1416 | |
| 1417 | default: |
| 1418 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 1419 | } |
| 1420 | } |
| 1421 | |
| 1422 | void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1423 | Primitive::Type type = instruction->GetType(); |
| 1424 | LocationSummary* locations = instruction->GetLocations(); |
| 1425 | |
| 1426 | switch (type) { |
| 1427 | case Primitive::kPrimInt: { |
| 1428 | Register dst = locations->Out().AsRegister<Register>(); |
| 1429 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 1430 | Location rhs_location = locations->InAt(1); |
| 1431 | |
| 1432 | Register rhs_reg = ZERO; |
| 1433 | int32_t rhs_imm = 0; |
| 1434 | bool use_imm = rhs_location.IsConstant(); |
| 1435 | if (use_imm) { |
| 1436 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 1437 | } else { |
| 1438 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 1439 | } |
| 1440 | |
| 1441 | if (instruction->IsAnd()) { |
| 1442 | if (use_imm) |
| 1443 | __ Andi(dst, lhs, rhs_imm); |
| 1444 | else |
| 1445 | __ And(dst, lhs, rhs_reg); |
| 1446 | } else if (instruction->IsOr()) { |
| 1447 | if (use_imm) |
| 1448 | __ Ori(dst, lhs, rhs_imm); |
| 1449 | else |
| 1450 | __ Or(dst, lhs, rhs_reg); |
| 1451 | } else if (instruction->IsXor()) { |
| 1452 | if (use_imm) |
| 1453 | __ Xori(dst, lhs, rhs_imm); |
| 1454 | else |
| 1455 | __ Xor(dst, lhs, rhs_reg); |
| 1456 | } else if (instruction->IsAdd()) { |
| 1457 | if (use_imm) |
| 1458 | __ Addiu(dst, lhs, rhs_imm); |
| 1459 | else |
| 1460 | __ Addu(dst, lhs, rhs_reg); |
| 1461 | } else { |
| 1462 | DCHECK(instruction->IsSub()); |
| 1463 | if (use_imm) |
| 1464 | __ Addiu(dst, lhs, -rhs_imm); |
| 1465 | else |
| 1466 | __ Subu(dst, lhs, rhs_reg); |
| 1467 | } |
| 1468 | break; |
| 1469 | } |
| 1470 | |
| 1471 | case Primitive::kPrimLong: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1472 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 1473 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 1474 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 1475 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1476 | Location rhs_location = locations->InAt(1); |
| 1477 | bool use_imm = rhs_location.IsConstant(); |
| 1478 | if (!use_imm) { |
| 1479 | Register rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 1480 | Register rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 1481 | if (instruction->IsAnd()) { |
| 1482 | __ And(dst_low, lhs_low, rhs_low); |
| 1483 | __ And(dst_high, lhs_high, rhs_high); |
| 1484 | } else if (instruction->IsOr()) { |
| 1485 | __ Or(dst_low, lhs_low, rhs_low); |
| 1486 | __ Or(dst_high, lhs_high, rhs_high); |
| 1487 | } else if (instruction->IsXor()) { |
| 1488 | __ Xor(dst_low, lhs_low, rhs_low); |
| 1489 | __ Xor(dst_high, lhs_high, rhs_high); |
| 1490 | } else if (instruction->IsAdd()) { |
| 1491 | if (lhs_low == rhs_low) { |
| 1492 | // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs. |
| 1493 | __ Slt(TMP, lhs_low, ZERO); |
| 1494 | __ Addu(dst_low, lhs_low, rhs_low); |
| 1495 | } else { |
| 1496 | __ Addu(dst_low, lhs_low, rhs_low); |
| 1497 | // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged. |
| 1498 | __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low); |
| 1499 | } |
| 1500 | __ Addu(dst_high, lhs_high, rhs_high); |
| 1501 | __ Addu(dst_high, dst_high, TMP); |
| 1502 | } else { |
| 1503 | DCHECK(instruction->IsSub()); |
| 1504 | __ Sltu(TMP, lhs_low, rhs_low); |
| 1505 | __ Subu(dst_low, lhs_low, rhs_low); |
| 1506 | __ Subu(dst_high, lhs_high, rhs_high); |
| 1507 | __ Subu(dst_high, dst_high, TMP); |
| 1508 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1509 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1510 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 1511 | if (instruction->IsOr()) { |
| 1512 | uint32_t low = Low32Bits(value); |
| 1513 | uint32_t high = High32Bits(value); |
| 1514 | if (IsUint<16>(low)) { |
| 1515 | if (dst_low != lhs_low || low != 0) { |
| 1516 | __ Ori(dst_low, lhs_low, low); |
| 1517 | } |
| 1518 | } else { |
| 1519 | __ LoadConst32(TMP, low); |
| 1520 | __ Or(dst_low, lhs_low, TMP); |
| 1521 | } |
| 1522 | if (IsUint<16>(high)) { |
| 1523 | if (dst_high != lhs_high || high != 0) { |
| 1524 | __ Ori(dst_high, lhs_high, high); |
| 1525 | } |
| 1526 | } else { |
| 1527 | if (high != low) { |
| 1528 | __ LoadConst32(TMP, high); |
| 1529 | } |
| 1530 | __ Or(dst_high, lhs_high, TMP); |
| 1531 | } |
| 1532 | } else if (instruction->IsXor()) { |
| 1533 | uint32_t low = Low32Bits(value); |
| 1534 | uint32_t high = High32Bits(value); |
| 1535 | if (IsUint<16>(low)) { |
| 1536 | if (dst_low != lhs_low || low != 0) { |
| 1537 | __ Xori(dst_low, lhs_low, low); |
| 1538 | } |
| 1539 | } else { |
| 1540 | __ LoadConst32(TMP, low); |
| 1541 | __ Xor(dst_low, lhs_low, TMP); |
| 1542 | } |
| 1543 | if (IsUint<16>(high)) { |
| 1544 | if (dst_high != lhs_high || high != 0) { |
| 1545 | __ Xori(dst_high, lhs_high, high); |
| 1546 | } |
| 1547 | } else { |
| 1548 | if (high != low) { |
| 1549 | __ LoadConst32(TMP, high); |
| 1550 | } |
| 1551 | __ Xor(dst_high, lhs_high, TMP); |
| 1552 | } |
| 1553 | } else if (instruction->IsAnd()) { |
| 1554 | uint32_t low = Low32Bits(value); |
| 1555 | uint32_t high = High32Bits(value); |
| 1556 | if (IsUint<16>(low)) { |
| 1557 | __ Andi(dst_low, lhs_low, low); |
| 1558 | } else if (low != 0xFFFFFFFF) { |
| 1559 | __ LoadConst32(TMP, low); |
| 1560 | __ And(dst_low, lhs_low, TMP); |
| 1561 | } else if (dst_low != lhs_low) { |
| 1562 | __ Move(dst_low, lhs_low); |
| 1563 | } |
| 1564 | if (IsUint<16>(high)) { |
| 1565 | __ Andi(dst_high, lhs_high, high); |
| 1566 | } else if (high != 0xFFFFFFFF) { |
| 1567 | if (high != low) { |
| 1568 | __ LoadConst32(TMP, high); |
| 1569 | } |
| 1570 | __ And(dst_high, lhs_high, TMP); |
| 1571 | } else if (dst_high != lhs_high) { |
| 1572 | __ Move(dst_high, lhs_high); |
| 1573 | } |
| 1574 | } else { |
| 1575 | if (instruction->IsSub()) { |
| 1576 | value = -value; |
| 1577 | } else { |
| 1578 | DCHECK(instruction->IsAdd()); |
| 1579 | } |
| 1580 | int32_t low = Low32Bits(value); |
| 1581 | int32_t high = High32Bits(value); |
| 1582 | if (IsInt<16>(low)) { |
| 1583 | if (dst_low != lhs_low || low != 0) { |
| 1584 | __ Addiu(dst_low, lhs_low, low); |
| 1585 | } |
| 1586 | if (low != 0) { |
| 1587 | __ Sltiu(AT, dst_low, low); |
| 1588 | } |
| 1589 | } else { |
| 1590 | __ LoadConst32(TMP, low); |
| 1591 | __ Addu(dst_low, lhs_low, TMP); |
| 1592 | __ Sltu(AT, dst_low, TMP); |
| 1593 | } |
| 1594 | if (IsInt<16>(high)) { |
| 1595 | if (dst_high != lhs_high || high != 0) { |
| 1596 | __ Addiu(dst_high, lhs_high, high); |
| 1597 | } |
| 1598 | } else { |
| 1599 | if (high != low) { |
| 1600 | __ LoadConst32(TMP, high); |
| 1601 | } |
| 1602 | __ Addu(dst_high, lhs_high, TMP); |
| 1603 | } |
| 1604 | if (low != 0) { |
| 1605 | __ Addu(dst_high, dst_high, AT); |
| 1606 | } |
| 1607 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1608 | } |
| 1609 | break; |
| 1610 | } |
| 1611 | |
| 1612 | case Primitive::kPrimFloat: |
| 1613 | case Primitive::kPrimDouble: { |
| 1614 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 1615 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 1616 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 1617 | if (instruction->IsAdd()) { |
| 1618 | if (type == Primitive::kPrimFloat) { |
| 1619 | __ AddS(dst, lhs, rhs); |
| 1620 | } else { |
| 1621 | __ AddD(dst, lhs, rhs); |
| 1622 | } |
| 1623 | } else { |
| 1624 | DCHECK(instruction->IsSub()); |
| 1625 | if (type == Primitive::kPrimFloat) { |
| 1626 | __ SubS(dst, lhs, rhs); |
| 1627 | } else { |
| 1628 | __ SubD(dst, lhs, rhs); |
| 1629 | } |
| 1630 | } |
| 1631 | break; |
| 1632 | } |
| 1633 | |
| 1634 | default: |
| 1635 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 1636 | } |
| 1637 | } |
| 1638 | |
| 1639 | void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1640 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1641 | |
| 1642 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1643 | Primitive::Type type = instr->GetResultType(); |
| 1644 | switch (type) { |
| 1645 | case Primitive::kPrimInt: |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1646 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1647 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 1648 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1649 | break; |
| 1650 | case Primitive::kPrimLong: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1651 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1652 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 1653 | locations->SetOut(Location::RequiresRegister()); |
| 1654 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1655 | default: |
| 1656 | LOG(FATAL) << "Unexpected shift type " << type; |
| 1657 | } |
| 1658 | } |
| 1659 | |
| 1660 | static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte; |
| 1661 | |
| 1662 | void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1663 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1664 | LocationSummary* locations = instr->GetLocations(); |
| 1665 | Primitive::Type type = instr->GetType(); |
| 1666 | |
| 1667 | Location rhs_location = locations->InAt(1); |
| 1668 | bool use_imm = rhs_location.IsConstant(); |
| 1669 | Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>(); |
| 1670 | int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 1671 | const uint32_t shift_mask = |
| 1672 | (type == Primitive::kPrimInt) ? kMaxIntShiftDistance : kMaxLongShiftDistance; |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1673 | const uint32_t shift_value = rhs_imm & shift_mask; |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1674 | // Are the INS (Insert Bit Field) and ROTR instructions supported? |
| 1675 | bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1676 | |
| 1677 | switch (type) { |
| 1678 | case Primitive::kPrimInt: { |
| 1679 | Register dst = locations->Out().AsRegister<Register>(); |
| 1680 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 1681 | if (use_imm) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1682 | if (shift_value == 0) { |
| 1683 | if (dst != lhs) { |
| 1684 | __ Move(dst, lhs); |
| 1685 | } |
| 1686 | } else if (instr->IsShl()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1687 | __ Sll(dst, lhs, shift_value); |
| 1688 | } else if (instr->IsShr()) { |
| 1689 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1690 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1691 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1692 | } else { |
| 1693 | if (has_ins_rotr) { |
| 1694 | __ Rotr(dst, lhs, shift_value); |
| 1695 | } else { |
| 1696 | __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask); |
| 1697 | __ Srl(dst, lhs, shift_value); |
| 1698 | __ Or(dst, dst, TMP); |
| 1699 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1700 | } |
| 1701 | } else { |
| 1702 | if (instr->IsShl()) { |
| 1703 | __ Sllv(dst, lhs, rhs_reg); |
| 1704 | } else if (instr->IsShr()) { |
| 1705 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1706 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1707 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1708 | } else { |
| 1709 | if (has_ins_rotr) { |
| 1710 | __ Rotrv(dst, lhs, rhs_reg); |
| 1711 | } else { |
| 1712 | __ Subu(TMP, ZERO, rhs_reg); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1713 | // 32-bit shift instructions use the 5 least significant bits of the shift count, so |
| 1714 | // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case |
| 1715 | // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out |
| 1716 | // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`, |
| 1717 | // IOW, the OR'd values are equal. |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1718 | __ Sllv(TMP, lhs, TMP); |
| 1719 | __ Srlv(dst, lhs, rhs_reg); |
| 1720 | __ Or(dst, dst, TMP); |
| 1721 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1722 | } |
| 1723 | } |
| 1724 | break; |
| 1725 | } |
| 1726 | |
| 1727 | case Primitive::kPrimLong: { |
| 1728 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 1729 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 1730 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 1731 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 1732 | if (use_imm) { |
| 1733 | if (shift_value == 0) { |
| 1734 | codegen_->Move64(locations->Out(), locations->InAt(0)); |
| 1735 | } else if (shift_value < kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1736 | if (has_ins_rotr) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1737 | if (instr->IsShl()) { |
| 1738 | __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 1739 | __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value); |
| 1740 | __ Sll(dst_low, lhs_low, shift_value); |
| 1741 | } else if (instr->IsShr()) { |
| 1742 | __ Srl(dst_low, lhs_low, shift_value); |
| 1743 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 1744 | __ Sra(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1745 | } else if (instr->IsUShr()) { |
| 1746 | __ Srl(dst_low, lhs_low, shift_value); |
| 1747 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 1748 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1749 | } else { |
| 1750 | __ Srl(dst_low, lhs_low, shift_value); |
| 1751 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 1752 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1753 | __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1754 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1755 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1756 | if (instr->IsShl()) { |
| 1757 | __ Sll(dst_low, lhs_low, shift_value); |
| 1758 | __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value); |
| 1759 | __ Sll(dst_high, lhs_high, shift_value); |
| 1760 | __ Or(dst_high, dst_high, TMP); |
| 1761 | } else if (instr->IsShr()) { |
| 1762 | __ Sra(dst_high, lhs_high, shift_value); |
| 1763 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 1764 | __ Srl(dst_low, lhs_low, shift_value); |
| 1765 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1766 | } else if (instr->IsUShr()) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1767 | __ Srl(dst_high, lhs_high, shift_value); |
| 1768 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 1769 | __ Srl(dst_low, lhs_low, shift_value); |
| 1770 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1771 | } else { |
| 1772 | __ Srl(TMP, lhs_low, shift_value); |
| 1773 | __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value); |
| 1774 | __ Or(dst_low, dst_low, TMP); |
| 1775 | __ Srl(TMP, lhs_high, shift_value); |
| 1776 | __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 1777 | __ Or(dst_high, dst_high, TMP); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1778 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1779 | } |
| 1780 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1781 | const uint32_t shift_value_high = shift_value - kMipsBitsPerWord; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1782 | if (instr->IsShl()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1783 | __ Sll(dst_high, lhs_low, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1784 | __ Move(dst_low, ZERO); |
| 1785 | } else if (instr->IsShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1786 | __ Sra(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1787 | __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1788 | } else if (instr->IsUShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1789 | __ Srl(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1790 | __ Move(dst_high, ZERO); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1791 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1792 | if (shift_value == kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1793 | // 64-bit rotation by 32 is just a swap. |
| 1794 | __ Move(dst_low, lhs_high); |
| 1795 | __ Move(dst_high, lhs_low); |
| 1796 | } else { |
| 1797 | if (has_ins_rotr) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1798 | __ Srl(dst_low, lhs_high, shift_value_high); |
| 1799 | __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high); |
| 1800 | __ Srl(dst_high, lhs_low, shift_value_high); |
| 1801 | __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1802 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1803 | __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high); |
| 1804 | __ Srl(dst_low, lhs_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1805 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1806 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high); |
| 1807 | __ Srl(dst_high, lhs_low, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1808 | __ Or(dst_high, dst_high, TMP); |
| 1809 | } |
| 1810 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1811 | } |
| 1812 | } |
| 1813 | } else { |
| 1814 | MipsLabel done; |
| 1815 | if (instr->IsShl()) { |
| 1816 | __ Sllv(dst_low, lhs_low, rhs_reg); |
| 1817 | __ Nor(AT, ZERO, rhs_reg); |
| 1818 | __ Srl(TMP, lhs_low, 1); |
| 1819 | __ Srlv(TMP, TMP, AT); |
| 1820 | __ Sllv(dst_high, lhs_high, rhs_reg); |
| 1821 | __ Or(dst_high, dst_high, TMP); |
| 1822 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 1823 | __ Beqz(TMP, &done); |
| 1824 | __ Move(dst_high, dst_low); |
| 1825 | __ Move(dst_low, ZERO); |
| 1826 | } else if (instr->IsShr()) { |
| 1827 | __ Srav(dst_high, lhs_high, rhs_reg); |
| 1828 | __ Nor(AT, ZERO, rhs_reg); |
| 1829 | __ Sll(TMP, lhs_high, 1); |
| 1830 | __ Sllv(TMP, TMP, AT); |
| 1831 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 1832 | __ Or(dst_low, dst_low, TMP); |
| 1833 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 1834 | __ Beqz(TMP, &done); |
| 1835 | __ Move(dst_low, dst_high); |
| 1836 | __ Sra(dst_high, dst_high, 31); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1837 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1838 | __ Srlv(dst_high, lhs_high, rhs_reg); |
| 1839 | __ Nor(AT, ZERO, rhs_reg); |
| 1840 | __ Sll(TMP, lhs_high, 1); |
| 1841 | __ Sllv(TMP, TMP, AT); |
| 1842 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 1843 | __ Or(dst_low, dst_low, TMP); |
| 1844 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 1845 | __ Beqz(TMP, &done); |
| 1846 | __ Move(dst_low, dst_high); |
| 1847 | __ Move(dst_high, ZERO); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1848 | } else { |
| 1849 | __ Nor(AT, ZERO, rhs_reg); |
| 1850 | __ Srlv(TMP, lhs_low, rhs_reg); |
| 1851 | __ Sll(dst_low, lhs_high, 1); |
| 1852 | __ Sllv(dst_low, dst_low, AT); |
| 1853 | __ Or(dst_low, dst_low, TMP); |
| 1854 | __ Srlv(TMP, lhs_high, rhs_reg); |
| 1855 | __ Sll(dst_high, lhs_low, 1); |
| 1856 | __ Sllv(dst_high, dst_high, AT); |
| 1857 | __ Or(dst_high, dst_high, TMP); |
| 1858 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 1859 | __ Beqz(TMP, &done); |
| 1860 | __ Move(TMP, dst_high); |
| 1861 | __ Move(dst_high, dst_low); |
| 1862 | __ Move(dst_low, TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1863 | } |
| 1864 | __ Bind(&done); |
| 1865 | } |
| 1866 | break; |
| 1867 | } |
| 1868 | |
| 1869 | default: |
| 1870 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 1871 | } |
| 1872 | } |
| 1873 | |
| 1874 | void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) { |
| 1875 | HandleBinaryOp(instruction); |
| 1876 | } |
| 1877 | |
| 1878 | void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) { |
| 1879 | HandleBinaryOp(instruction); |
| 1880 | } |
| 1881 | |
| 1882 | void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) { |
| 1883 | HandleBinaryOp(instruction); |
| 1884 | } |
| 1885 | |
| 1886 | void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) { |
| 1887 | HandleBinaryOp(instruction); |
| 1888 | } |
| 1889 | |
| 1890 | void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) { |
| 1891 | LocationSummary* locations = |
| 1892 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1893 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1894 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1895 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 1896 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1897 | } else { |
| 1898 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1899 | } |
| 1900 | } |
| 1901 | |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 1902 | static auto GetImplicitNullChecker(HInstruction* instruction, CodeGeneratorMIPS* codegen) { |
| 1903 | auto null_checker = [codegen, instruction]() { |
| 1904 | codegen->MaybeRecordImplicitNullCheck(instruction); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1905 | }; |
| 1906 | return null_checker; |
| 1907 | } |
| 1908 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1909 | void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) { |
| 1910 | LocationSummary* locations = instruction->GetLocations(); |
| 1911 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 1912 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 1913 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 1914 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1915 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 1916 | Primitive::Type type = instruction->GetType(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 1917 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 1918 | instruction->IsStringCharAt(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1919 | switch (type) { |
| 1920 | case Primitive::kPrimBoolean: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1921 | Register out = locations->Out().AsRegister<Register>(); |
| 1922 | if (index.IsConstant()) { |
| 1923 | size_t offset = |
| 1924 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1925 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1926 | } else { |
| 1927 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1928 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1929 | } |
| 1930 | break; |
| 1931 | } |
| 1932 | |
| 1933 | case Primitive::kPrimByte: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1934 | Register out = locations->Out().AsRegister<Register>(); |
| 1935 | if (index.IsConstant()) { |
| 1936 | size_t offset = |
| 1937 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1938 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1939 | } else { |
| 1940 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1941 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1942 | } |
| 1943 | break; |
| 1944 | } |
| 1945 | |
| 1946 | case Primitive::kPrimShort: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1947 | Register out = locations->Out().AsRegister<Register>(); |
| 1948 | if (index.IsConstant()) { |
| 1949 | size_t offset = |
| 1950 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1951 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1952 | } else { |
| 1953 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_2); |
| 1954 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1955 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1956 | } |
| 1957 | break; |
| 1958 | } |
| 1959 | |
| 1960 | case Primitive::kPrimChar: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1961 | Register out = locations->Out().AsRegister<Register>(); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 1962 | if (maybe_compressed_char_at) { |
| 1963 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 1964 | __ LoadFromOffset(kLoadWord, TMP, obj, count_offset, null_checker); |
| 1965 | __ Sll(TMP, TMP, 31); // Extract compression flag into the most significant bit of TMP. |
| 1966 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 1967 | "Expecting 0=compressed, 1=uncompressed"); |
| 1968 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1969 | if (index.IsConstant()) { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 1970 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 1971 | if (maybe_compressed_char_at) { |
| 1972 | MipsLabel uncompressed_load, done; |
| 1973 | __ Bnez(TMP, &uncompressed_load); |
| 1974 | __ LoadFromOffset(kLoadUnsignedByte, |
| 1975 | out, |
| 1976 | obj, |
| 1977 | data_offset + (const_index << TIMES_1)); |
| 1978 | __ B(&done); |
| 1979 | __ Bind(&uncompressed_load); |
| 1980 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1981 | out, |
| 1982 | obj, |
| 1983 | data_offset + (const_index << TIMES_2)); |
| 1984 | __ Bind(&done); |
| 1985 | } else { |
| 1986 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1987 | out, |
| 1988 | obj, |
| 1989 | data_offset + (const_index << TIMES_2), |
| 1990 | null_checker); |
| 1991 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1992 | } else { |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 1993 | Register index_reg = index.AsRegister<Register>(); |
| 1994 | if (maybe_compressed_char_at) { |
| 1995 | MipsLabel uncompressed_load, done; |
| 1996 | __ Bnez(TMP, &uncompressed_load); |
| 1997 | __ Addu(TMP, obj, index_reg); |
| 1998 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 1999 | __ B(&done); |
| 2000 | __ Bind(&uncompressed_load); |
| 2001 | __ Sll(TMP, index_reg, TIMES_2); |
| 2002 | __ Addu(TMP, obj, TMP); |
| 2003 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 2004 | __ Bind(&done); |
| 2005 | } else { |
| 2006 | __ Sll(TMP, index_reg, TIMES_2); |
| 2007 | __ Addu(TMP, obj, TMP); |
| 2008 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
| 2009 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2010 | } |
| 2011 | break; |
| 2012 | } |
| 2013 | |
| 2014 | case Primitive::kPrimInt: |
| 2015 | case Primitive::kPrimNot: { |
| 2016 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2017 | Register out = locations->Out().AsRegister<Register>(); |
| 2018 | if (index.IsConstant()) { |
| 2019 | size_t offset = |
| 2020 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2021 | __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2022 | } else { |
| 2023 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_4); |
| 2024 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2025 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2026 | } |
| 2027 | break; |
| 2028 | } |
| 2029 | |
| 2030 | case Primitive::kPrimLong: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2031 | Register out = locations->Out().AsRegisterPairLow<Register>(); |
| 2032 | if (index.IsConstant()) { |
| 2033 | size_t offset = |
| 2034 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2035 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2036 | } else { |
| 2037 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_8); |
| 2038 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2039 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2040 | } |
| 2041 | break; |
| 2042 | } |
| 2043 | |
| 2044 | case Primitive::kPrimFloat: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2045 | FRegister out = locations->Out().AsFpuRegister<FRegister>(); |
| 2046 | if (index.IsConstant()) { |
| 2047 | size_t offset = |
| 2048 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2049 | __ LoadSFromOffset(out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2050 | } else { |
| 2051 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_4); |
| 2052 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2053 | __ LoadSFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2054 | } |
| 2055 | break; |
| 2056 | } |
| 2057 | |
| 2058 | case Primitive::kPrimDouble: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2059 | FRegister out = locations->Out().AsFpuRegister<FRegister>(); |
| 2060 | if (index.IsConstant()) { |
| 2061 | size_t offset = |
| 2062 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2063 | __ LoadDFromOffset(out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2064 | } else { |
| 2065 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_8); |
| 2066 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2067 | __ LoadDFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2068 | } |
| 2069 | break; |
| 2070 | } |
| 2071 | |
| 2072 | case Primitive::kPrimVoid: |
| 2073 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2074 | UNREACHABLE(); |
| 2075 | } |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2076 | |
| 2077 | if (type == Primitive::kPrimNot) { |
| 2078 | Register out = locations->Out().AsRegister<Register>(); |
| 2079 | __ MaybeUnpoisonHeapReference(out); |
| 2080 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) { |
| 2084 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2085 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2086 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2087 | } |
| 2088 | |
| 2089 | void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) { |
| 2090 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2091 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2092 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2093 | Register out = locations->Out().AsRegister<Register>(); |
| 2094 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2095 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Goran Jakovljevic | f94fa81 | 2017-02-10 17:48:52 +0100 | [diff] [blame] | 2096 | // Mask out compression flag from String's array length. |
| 2097 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 2098 | __ Srl(out, out, 1u); |
| 2099 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2100 | } |
| 2101 | |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2102 | Location LocationsBuilderMIPS::RegisterOrZeroConstant(HInstruction* instruction) { |
| 2103 | return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern()) |
| 2104 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 2105 | : Location::RequiresRegister(); |
| 2106 | } |
| 2107 | |
| 2108 | Location LocationsBuilderMIPS::FpuRegisterOrConstantForStore(HInstruction* instruction) { |
| 2109 | // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register. |
| 2110 | // We can store a non-zero float or double constant without first loading it into the FPU, |
| 2111 | // but we should only prefer this if the constant has a single use. |
| 2112 | if (instruction->IsConstant() && |
| 2113 | (instruction->AsConstant()->IsZeroBitPattern() || |
| 2114 | instruction->GetUses().HasExactlyOneElement())) { |
| 2115 | return Location::ConstantLocation(instruction->AsConstant()); |
| 2116 | // Otherwise fall through and require an FPU register for the constant. |
| 2117 | } |
| 2118 | return Location::RequiresFpuRegister(); |
| 2119 | } |
| 2120 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2121 | void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) { |
Pavle Batuta | 934808f | 2015-11-03 13:23:54 +0100 | [diff] [blame] | 2122 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2123 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2124 | instruction, |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2125 | needs_runtime_call ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); |
Pavle Batuta | 934808f | 2015-11-03 13:23:54 +0100 | [diff] [blame] | 2126 | if (needs_runtime_call) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2127 | InvokeRuntimeCallingConvention calling_convention; |
| 2128 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2129 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2130 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 2131 | } else { |
| 2132 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2133 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2134 | if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2135 | locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2136 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2137 | locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2138 | } |
| 2139 | } |
| 2140 | } |
| 2141 | |
| 2142 | void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) { |
| 2143 | LocationSummary* locations = instruction->GetLocations(); |
| 2144 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2145 | Location index = locations->InAt(1); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2146 | Location value_location = locations->InAt(2); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2147 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2148 | bool needs_runtime_call = locations->WillCall(); |
| 2149 | bool needs_write_barrier = |
| 2150 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 2151 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2152 | Register base_reg = index.IsConstant() ? obj : TMP; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2153 | |
| 2154 | switch (value_type) { |
| 2155 | case Primitive::kPrimBoolean: |
| 2156 | case Primitive::kPrimByte: { |
| 2157 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2158 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2159 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2160 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2161 | __ Addu(base_reg, obj, index.AsRegister<Register>()); |
| 2162 | } |
| 2163 | if (value_location.IsConstant()) { |
| 2164 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2165 | __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker); |
| 2166 | } else { |
| 2167 | Register value = value_location.AsRegister<Register>(); |
| 2168 | __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2169 | } |
| 2170 | break; |
| 2171 | } |
| 2172 | |
| 2173 | case Primitive::kPrimShort: |
| 2174 | case Primitive::kPrimChar: { |
| 2175 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2176 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2177 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2178 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2179 | __ Sll(base_reg, index.AsRegister<Register>(), TIMES_2); |
| 2180 | __ Addu(base_reg, obj, base_reg); |
| 2181 | } |
| 2182 | if (value_location.IsConstant()) { |
| 2183 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2184 | __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker); |
| 2185 | } else { |
| 2186 | Register value = value_location.AsRegister<Register>(); |
| 2187 | __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2188 | } |
| 2189 | break; |
| 2190 | } |
| 2191 | |
| 2192 | case Primitive::kPrimInt: |
| 2193 | case Primitive::kPrimNot: { |
| 2194 | if (!needs_runtime_call) { |
| 2195 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2196 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2197 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2198 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2199 | __ Sll(base_reg, index.AsRegister<Register>(), TIMES_4); |
| 2200 | __ Addu(base_reg, obj, base_reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2201 | } |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2202 | if (value_location.IsConstant()) { |
| 2203 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2204 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2205 | DCHECK(!needs_write_barrier); |
| 2206 | } else { |
| 2207 | Register value = value_location.AsRegister<Register>(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2208 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 2209 | // Note that in the case where `value` is a null reference, |
| 2210 | // we do not enter this block, as a null reference does not |
| 2211 | // need poisoning. |
| 2212 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 2213 | // Use Sw() instead of StoreToOffset() in order to be able to |
| 2214 | // hold the poisoned reference in AT and thus avoid allocating |
| 2215 | // yet another temporary register. |
| 2216 | if (index.IsConstant()) { |
| 2217 | if (!IsInt<16>(static_cast<int32_t>(data_offset))) { |
| 2218 | int16_t low = Low16Bits(data_offset); |
| 2219 | uint32_t high = data_offset - low; |
| 2220 | __ Addiu32(TMP, obj, high); |
| 2221 | base_reg = TMP; |
| 2222 | data_offset = low; |
| 2223 | } |
| 2224 | } else { |
| 2225 | DCHECK(IsInt<16>(static_cast<int32_t>(data_offset))); |
| 2226 | } |
| 2227 | __ PoisonHeapReference(AT, value); |
| 2228 | __ Sw(AT, base_reg, data_offset); |
| 2229 | null_checker(); |
| 2230 | } else { |
| 2231 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2232 | } |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2233 | if (needs_write_barrier) { |
| 2234 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 2235 | codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull()); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2236 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2237 | } |
| 2238 | } else { |
| 2239 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2240 | // Note: if heap poisoning is enabled, pAputObject takes care |
| 2241 | // of poisoning the reference. |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 2242 | codegen_->InvokeRuntime(kQuickAputObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2243 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 2244 | } |
| 2245 | break; |
| 2246 | } |
| 2247 | |
| 2248 | case Primitive::kPrimLong: { |
| 2249 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2250 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2251 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2252 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2253 | __ Sll(base_reg, index.AsRegister<Register>(), TIMES_8); |
| 2254 | __ Addu(base_reg, obj, base_reg); |
| 2255 | } |
| 2256 | if (value_location.IsConstant()) { |
| 2257 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2258 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2259 | } else { |
| 2260 | Register value = value_location.AsRegisterPairLow<Register>(); |
| 2261 | __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2262 | } |
| 2263 | break; |
| 2264 | } |
| 2265 | |
| 2266 | case Primitive::kPrimFloat: { |
| 2267 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2268 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2269 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2270 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2271 | __ Sll(base_reg, index.AsRegister<Register>(), TIMES_4); |
| 2272 | __ Addu(base_reg, obj, base_reg); |
| 2273 | } |
| 2274 | if (value_location.IsConstant()) { |
| 2275 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2276 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2277 | } else { |
| 2278 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 2279 | __ StoreSToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2280 | } |
| 2281 | break; |
| 2282 | } |
| 2283 | |
| 2284 | case Primitive::kPrimDouble: { |
| 2285 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2286 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2287 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2288 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2289 | __ Sll(base_reg, index.AsRegister<Register>(), TIMES_8); |
| 2290 | __ Addu(base_reg, obj, base_reg); |
| 2291 | } |
| 2292 | if (value_location.IsConstant()) { |
| 2293 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2294 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2295 | } else { |
| 2296 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 2297 | __ StoreDToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2298 | } |
| 2299 | break; |
| 2300 | } |
| 2301 | |
| 2302 | case Primitive::kPrimVoid: |
| 2303 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2304 | UNREACHABLE(); |
| 2305 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2306 | } |
| 2307 | |
| 2308 | void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2309 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2310 | InvokeRuntimeCallingConvention calling_convention; |
| 2311 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2312 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2313 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2314 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2315 | locations->SetInAt(1, Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2316 | } |
| 2317 | |
| 2318 | void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2319 | LocationSummary* locations = instruction->GetLocations(); |
| 2320 | BoundsCheckSlowPathMIPS* slow_path = |
| 2321 | new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS(instruction); |
| 2322 | codegen_->AddSlowPath(slow_path); |
| 2323 | |
| 2324 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 2325 | Register length = locations->InAt(1).AsRegister<Register>(); |
| 2326 | |
| 2327 | // length is limited by the maximum positive signed 32-bit integer. |
| 2328 | // Unsigned comparison of length and index checks for index < 0 |
| 2329 | // and for length <= index simultaneously. |
| 2330 | __ Bgeu(index, length, slow_path->GetEntryLabel()); |
| 2331 | } |
| 2332 | |
| 2333 | void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) { |
| 2334 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2335 | instruction, |
| 2336 | LocationSummary::kCallOnSlowPath); |
| 2337 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2338 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2339 | // Note that TypeCheckSlowPathMIPS uses this register too. |
| 2340 | locations->AddTemp(Location::RequiresRegister()); |
| 2341 | } |
| 2342 | |
| 2343 | void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) { |
| 2344 | LocationSummary* locations = instruction->GetLocations(); |
| 2345 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2346 | Register cls = locations->InAt(1).AsRegister<Register>(); |
| 2347 | Register obj_cls = locations->GetTemp(0).AsRegister<Register>(); |
| 2348 | |
| 2349 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction); |
| 2350 | codegen_->AddSlowPath(slow_path); |
| 2351 | |
| 2352 | // TODO: avoid this check if we know obj is not null. |
| 2353 | __ Beqz(obj, slow_path->GetExitLabel()); |
| 2354 | // Compare the class of `obj` with `cls`. |
| 2355 | __ LoadFromOffset(kLoadWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value()); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 2356 | __ MaybeUnpoisonHeapReference(obj_cls); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2357 | __ Bne(obj_cls, cls, slow_path->GetEntryLabel()); |
| 2358 | __ Bind(slow_path->GetExitLabel()); |
| 2359 | } |
| 2360 | |
| 2361 | void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 2362 | LocationSummary* locations = |
| 2363 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2364 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2365 | if (check->HasUses()) { |
| 2366 | locations->SetOut(Location::SameAsFirstInput()); |
| 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 2371 | // We assume the class is not null. |
| 2372 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS( |
| 2373 | check->GetLoadClass(), |
| 2374 | check, |
| 2375 | check->GetDexPc(), |
| 2376 | true); |
| 2377 | codegen_->AddSlowPath(slow_path); |
| 2378 | GenerateClassInitializationCheck(slow_path, |
| 2379 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
| 2380 | } |
| 2381 | |
| 2382 | void LocationsBuilderMIPS::VisitCompare(HCompare* compare) { |
| 2383 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 2384 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2385 | LocationSummary* locations = |
| 2386 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2387 | |
| 2388 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2389 | case Primitive::kPrimBoolean: |
| 2390 | case Primitive::kPrimByte: |
| 2391 | case Primitive::kPrimShort: |
| 2392 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2393 | case Primitive::kPrimInt: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 2394 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2395 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2396 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2397 | break; |
| 2398 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2399 | case Primitive::kPrimLong: |
| 2400 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2401 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2402 | // Output overlaps because it is written before doing the low comparison. |
| 2403 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2404 | break; |
| 2405 | |
| 2406 | case Primitive::kPrimFloat: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2407 | case Primitive::kPrimDouble: |
| 2408 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2409 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2410 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2411 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2412 | |
| 2413 | default: |
| 2414 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2415 | } |
| 2416 | } |
| 2417 | |
| 2418 | void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) { |
| 2419 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2420 | Register res = locations->Out().AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2421 | Primitive::Type in_type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2422 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2423 | |
| 2424 | // 0 if: left == right |
| 2425 | // 1 if: left > right |
| 2426 | // -1 if: left < right |
| 2427 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2428 | case Primitive::kPrimBoolean: |
| 2429 | case Primitive::kPrimByte: |
| 2430 | case Primitive::kPrimShort: |
| 2431 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2432 | case Primitive::kPrimInt: { |
| 2433 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2434 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 2435 | __ Slt(TMP, lhs, rhs); |
| 2436 | __ Slt(res, rhs, lhs); |
| 2437 | __ Subu(res, res, TMP); |
| 2438 | break; |
| 2439 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2440 | case Primitive::kPrimLong: { |
| 2441 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2442 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2443 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 2444 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 2445 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 2446 | // TODO: more efficient (direct) comparison with a constant. |
| 2447 | __ Slt(TMP, lhs_high, rhs_high); |
| 2448 | __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt. |
| 2449 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 2450 | __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal. |
| 2451 | __ Sltu(TMP, lhs_low, rhs_low); |
| 2452 | __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt. |
| 2453 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 2454 | __ Bind(&done); |
| 2455 | break; |
| 2456 | } |
| 2457 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2458 | case Primitive::kPrimFloat: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 2459 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2460 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2461 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2462 | MipsLabel done; |
| 2463 | if (isR6) { |
| 2464 | __ CmpEqS(FTMP, lhs, rhs); |
| 2465 | __ LoadConst32(res, 0); |
| 2466 | __ Bc1nez(FTMP, &done); |
| 2467 | if (gt_bias) { |
| 2468 | __ CmpLtS(FTMP, lhs, rhs); |
| 2469 | __ LoadConst32(res, -1); |
| 2470 | __ Bc1nez(FTMP, &done); |
| 2471 | __ LoadConst32(res, 1); |
| 2472 | } else { |
| 2473 | __ CmpLtS(FTMP, rhs, lhs); |
| 2474 | __ LoadConst32(res, 1); |
| 2475 | __ Bc1nez(FTMP, &done); |
| 2476 | __ LoadConst32(res, -1); |
| 2477 | } |
| 2478 | } else { |
| 2479 | if (gt_bias) { |
| 2480 | __ ColtS(0, lhs, rhs); |
| 2481 | __ LoadConst32(res, -1); |
| 2482 | __ Bc1t(0, &done); |
| 2483 | __ CeqS(0, lhs, rhs); |
| 2484 | __ LoadConst32(res, 1); |
| 2485 | __ Movt(res, ZERO, 0); |
| 2486 | } else { |
| 2487 | __ ColtS(0, rhs, lhs); |
| 2488 | __ LoadConst32(res, 1); |
| 2489 | __ Bc1t(0, &done); |
| 2490 | __ CeqS(0, lhs, rhs); |
| 2491 | __ LoadConst32(res, -1); |
| 2492 | __ Movt(res, ZERO, 0); |
| 2493 | } |
| 2494 | } |
| 2495 | __ Bind(&done); |
| 2496 | break; |
| 2497 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2498 | case Primitive::kPrimDouble: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 2499 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2500 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2501 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2502 | MipsLabel done; |
| 2503 | if (isR6) { |
| 2504 | __ CmpEqD(FTMP, lhs, rhs); |
| 2505 | __ LoadConst32(res, 0); |
| 2506 | __ Bc1nez(FTMP, &done); |
| 2507 | if (gt_bias) { |
| 2508 | __ CmpLtD(FTMP, lhs, rhs); |
| 2509 | __ LoadConst32(res, -1); |
| 2510 | __ Bc1nez(FTMP, &done); |
| 2511 | __ LoadConst32(res, 1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2512 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2513 | __ CmpLtD(FTMP, rhs, lhs); |
| 2514 | __ LoadConst32(res, 1); |
| 2515 | __ Bc1nez(FTMP, &done); |
| 2516 | __ LoadConst32(res, -1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2517 | } |
| 2518 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2519 | if (gt_bias) { |
| 2520 | __ ColtD(0, lhs, rhs); |
| 2521 | __ LoadConst32(res, -1); |
| 2522 | __ Bc1t(0, &done); |
| 2523 | __ CeqD(0, lhs, rhs); |
| 2524 | __ LoadConst32(res, 1); |
| 2525 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2526 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2527 | __ ColtD(0, rhs, lhs); |
| 2528 | __ LoadConst32(res, 1); |
| 2529 | __ Bc1t(0, &done); |
| 2530 | __ CeqD(0, lhs, rhs); |
| 2531 | __ LoadConst32(res, -1); |
| 2532 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2533 | } |
| 2534 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2535 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2536 | break; |
| 2537 | } |
| 2538 | |
| 2539 | default: |
| 2540 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2541 | } |
| 2542 | } |
| 2543 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2544 | void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2545 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2546 | switch (instruction->InputAt(0)->GetType()) { |
| 2547 | default: |
| 2548 | case Primitive::kPrimLong: |
| 2549 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2550 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2551 | break; |
| 2552 | |
| 2553 | case Primitive::kPrimFloat: |
| 2554 | case Primitive::kPrimDouble: |
| 2555 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2556 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2557 | break; |
| 2558 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2559 | if (!instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2560 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2561 | } |
| 2562 | } |
| 2563 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2564 | void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2565 | if (instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2566 | return; |
| 2567 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2568 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2569 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2570 | LocationSummary* locations = instruction->GetLocations(); |
| 2571 | Register dst = locations->Out().AsRegister<Register>(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2572 | MipsLabel true_label; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2573 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2574 | switch (type) { |
| 2575 | default: |
| 2576 | // Integer case. |
| 2577 | GenerateIntCompare(instruction->GetCondition(), locations); |
| 2578 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2579 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2580 | case Primitive::kPrimLong: |
| 2581 | // TODO: don't use branches. |
| 2582 | GenerateLongCompareAndBranch(instruction->GetCondition(), locations, &true_label); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2583 | break; |
| 2584 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2585 | case Primitive::kPrimFloat: |
| 2586 | case Primitive::kPrimDouble: |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 2587 | GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations); |
| 2588 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2589 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2590 | |
| 2591 | // Convert the branches into the result. |
| 2592 | MipsLabel done; |
| 2593 | |
| 2594 | // False case: result = 0. |
| 2595 | __ LoadConst32(dst, 0); |
| 2596 | __ B(&done); |
| 2597 | |
| 2598 | // True case: result = 1. |
| 2599 | __ Bind(&true_label); |
| 2600 | __ LoadConst32(dst, 1); |
| 2601 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2602 | } |
| 2603 | |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2604 | void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2605 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2606 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 2607 | |
| 2608 | LocationSummary* locations = instruction->GetLocations(); |
| 2609 | Location second = locations->InAt(1); |
| 2610 | DCHECK(second.IsConstant()); |
| 2611 | |
| 2612 | Register out = locations->Out().AsRegister<Register>(); |
| 2613 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2614 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2615 | DCHECK(imm == 1 || imm == -1); |
| 2616 | |
| 2617 | if (instruction->IsRem()) { |
| 2618 | __ Move(out, ZERO); |
| 2619 | } else { |
| 2620 | if (imm == -1) { |
| 2621 | __ Subu(out, ZERO, dividend); |
| 2622 | } else if (out != dividend) { |
| 2623 | __ Move(out, dividend); |
| 2624 | } |
| 2625 | } |
| 2626 | } |
| 2627 | |
| 2628 | void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2629 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2630 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 2631 | |
| 2632 | LocationSummary* locations = instruction->GetLocations(); |
| 2633 | Location second = locations->InAt(1); |
| 2634 | DCHECK(second.IsConstant()); |
| 2635 | |
| 2636 | Register out = locations->Out().AsRegister<Register>(); |
| 2637 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2638 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2639 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2640 | int ctz_imm = CTZ(abs_imm); |
| 2641 | |
| 2642 | if (instruction->IsDiv()) { |
| 2643 | if (ctz_imm == 1) { |
| 2644 | // Fast path for division by +/-2, which is very common. |
| 2645 | __ Srl(TMP, dividend, 31); |
| 2646 | } else { |
| 2647 | __ Sra(TMP, dividend, 31); |
| 2648 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 2649 | } |
| 2650 | __ Addu(out, dividend, TMP); |
| 2651 | __ Sra(out, out, ctz_imm); |
| 2652 | if (imm < 0) { |
| 2653 | __ Subu(out, ZERO, out); |
| 2654 | } |
| 2655 | } else { |
| 2656 | if (ctz_imm == 1) { |
| 2657 | // Fast path for modulo +/-2, which is very common. |
| 2658 | __ Sra(TMP, dividend, 31); |
| 2659 | __ Subu(out, dividend, TMP); |
| 2660 | __ Andi(out, out, 1); |
| 2661 | __ Addu(out, out, TMP); |
| 2662 | } else { |
| 2663 | __ Sra(TMP, dividend, 31); |
| 2664 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 2665 | __ Addu(out, dividend, TMP); |
| 2666 | if (IsUint<16>(abs_imm - 1)) { |
| 2667 | __ Andi(out, out, abs_imm - 1); |
| 2668 | } else { |
| 2669 | __ Sll(out, out, 32 - ctz_imm); |
| 2670 | __ Srl(out, out, 32 - ctz_imm); |
| 2671 | } |
| 2672 | __ Subu(out, out, TMP); |
| 2673 | } |
| 2674 | } |
| 2675 | } |
| 2676 | |
| 2677 | void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2678 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2679 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 2680 | |
| 2681 | LocationSummary* locations = instruction->GetLocations(); |
| 2682 | Location second = locations->InAt(1); |
| 2683 | DCHECK(second.IsConstant()); |
| 2684 | |
| 2685 | Register out = locations->Out().AsRegister<Register>(); |
| 2686 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2687 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2688 | |
| 2689 | int64_t magic; |
| 2690 | int shift; |
| 2691 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2692 | |
| 2693 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 2694 | |
| 2695 | __ LoadConst32(TMP, magic); |
| 2696 | if (isR6) { |
| 2697 | __ MuhR6(TMP, dividend, TMP); |
| 2698 | } else { |
| 2699 | __ MultR2(dividend, TMP); |
| 2700 | __ Mfhi(TMP); |
| 2701 | } |
| 2702 | if (imm > 0 && magic < 0) { |
| 2703 | __ Addu(TMP, TMP, dividend); |
| 2704 | } else if (imm < 0 && magic > 0) { |
| 2705 | __ Subu(TMP, TMP, dividend); |
| 2706 | } |
| 2707 | |
| 2708 | if (shift != 0) { |
| 2709 | __ Sra(TMP, TMP, shift); |
| 2710 | } |
| 2711 | |
| 2712 | if (instruction->IsDiv()) { |
| 2713 | __ Sra(out, TMP, 31); |
| 2714 | __ Subu(out, TMP, out); |
| 2715 | } else { |
| 2716 | __ Sra(AT, TMP, 31); |
| 2717 | __ Subu(AT, TMP, AT); |
| 2718 | __ LoadConst32(TMP, imm); |
| 2719 | if (isR6) { |
| 2720 | __ MulR6(TMP, AT, TMP); |
| 2721 | } else { |
| 2722 | __ MulR2(TMP, AT, TMP); |
| 2723 | } |
| 2724 | __ Subu(out, dividend, TMP); |
| 2725 | } |
| 2726 | } |
| 2727 | |
| 2728 | void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2729 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2730 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 2731 | |
| 2732 | LocationSummary* locations = instruction->GetLocations(); |
| 2733 | Register out = locations->Out().AsRegister<Register>(); |
| 2734 | Location second = locations->InAt(1); |
| 2735 | |
| 2736 | if (second.IsConstant()) { |
| 2737 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2738 | if (imm == 0) { |
| 2739 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2740 | } else if (imm == 1 || imm == -1) { |
| 2741 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2742 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2743 | DivRemByPowerOfTwo(instruction); |
| 2744 | } else { |
| 2745 | DCHECK(imm <= -2 || imm >= 2); |
| 2746 | GenerateDivRemWithAnyConstant(instruction); |
| 2747 | } |
| 2748 | } else { |
| 2749 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2750 | Register divisor = second.AsRegister<Register>(); |
| 2751 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 2752 | if (instruction->IsDiv()) { |
| 2753 | if (isR6) { |
| 2754 | __ DivR6(out, dividend, divisor); |
| 2755 | } else { |
| 2756 | __ DivR2(out, dividend, divisor); |
| 2757 | } |
| 2758 | } else { |
| 2759 | if (isR6) { |
| 2760 | __ ModR6(out, dividend, divisor); |
| 2761 | } else { |
| 2762 | __ ModR2(out, dividend, divisor); |
| 2763 | } |
| 2764 | } |
| 2765 | } |
| 2766 | } |
| 2767 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2768 | void LocationsBuilderMIPS::VisitDiv(HDiv* div) { |
| 2769 | Primitive::Type type = div->GetResultType(); |
| 2770 | LocationSummary::CallKind call_kind = (type == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2771 | ? LocationSummary::kCallOnMainOnly |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2772 | : LocationSummary::kNoCall; |
| 2773 | |
| 2774 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2775 | |
| 2776 | switch (type) { |
| 2777 | case Primitive::kPrimInt: |
| 2778 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2779 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2780 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2781 | break; |
| 2782 | |
| 2783 | case Primitive::kPrimLong: { |
| 2784 | InvokeRuntimeCallingConvention calling_convention; |
| 2785 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2786 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2787 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2788 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2789 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 2790 | break; |
| 2791 | } |
| 2792 | |
| 2793 | case Primitive::kPrimFloat: |
| 2794 | case Primitive::kPrimDouble: |
| 2795 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2796 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2797 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2798 | break; |
| 2799 | |
| 2800 | default: |
| 2801 | LOG(FATAL) << "Unexpected div type " << type; |
| 2802 | } |
| 2803 | } |
| 2804 | |
| 2805 | void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) { |
| 2806 | Primitive::Type type = instruction->GetType(); |
| 2807 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2808 | |
| 2809 | switch (type) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2810 | case Primitive::kPrimInt: |
| 2811 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2812 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2813 | case Primitive::kPrimLong: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 2814 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2815 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| 2816 | break; |
| 2817 | } |
| 2818 | case Primitive::kPrimFloat: |
| 2819 | case Primitive::kPrimDouble: { |
| 2820 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 2821 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2822 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2823 | if (type == Primitive::kPrimFloat) { |
| 2824 | __ DivS(dst, lhs, rhs); |
| 2825 | } else { |
| 2826 | __ DivD(dst, lhs, rhs); |
| 2827 | } |
| 2828 | break; |
| 2829 | } |
| 2830 | default: |
| 2831 | LOG(FATAL) << "Unexpected div type " << type; |
| 2832 | } |
| 2833 | } |
| 2834 | |
| 2835 | void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2836 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2837 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2838 | } |
| 2839 | |
| 2840 | void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2841 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS(instruction); |
| 2842 | codegen_->AddSlowPath(slow_path); |
| 2843 | Location value = instruction->GetLocations()->InAt(0); |
| 2844 | Primitive::Type type = instruction->GetType(); |
| 2845 | |
| 2846 | switch (type) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 2847 | case Primitive::kPrimBoolean: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2848 | case Primitive::kPrimByte: |
| 2849 | case Primitive::kPrimChar: |
| 2850 | case Primitive::kPrimShort: |
| 2851 | case Primitive::kPrimInt: { |
| 2852 | if (value.IsConstant()) { |
| 2853 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 2854 | __ B(slow_path->GetEntryLabel()); |
| 2855 | } else { |
| 2856 | // A division by a non-null constant is valid. We don't need to perform |
| 2857 | // any check, so simply fall through. |
| 2858 | } |
| 2859 | } else { |
| 2860 | DCHECK(value.IsRegister()) << value; |
| 2861 | __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 2862 | } |
| 2863 | break; |
| 2864 | } |
| 2865 | case Primitive::kPrimLong: { |
| 2866 | if (value.IsConstant()) { |
| 2867 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 2868 | __ B(slow_path->GetEntryLabel()); |
| 2869 | } else { |
| 2870 | // A division by a non-null constant is valid. We don't need to perform |
| 2871 | // any check, so simply fall through. |
| 2872 | } |
| 2873 | } else { |
| 2874 | DCHECK(value.IsRegisterPair()) << value; |
| 2875 | __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>()); |
| 2876 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 2877 | } |
| 2878 | break; |
| 2879 | } |
| 2880 | default: |
| 2881 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
| 2882 | } |
| 2883 | } |
| 2884 | |
| 2885 | void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2886 | LocationSummary* locations = |
| 2887 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2888 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2889 | } |
| 2890 | |
| 2891 | void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 2892 | // Will be generated at use site. |
| 2893 | } |
| 2894 | |
| 2895 | void LocationsBuilderMIPS::VisitExit(HExit* exit) { |
| 2896 | exit->SetLocations(nullptr); |
| 2897 | } |
| 2898 | |
| 2899 | void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 2900 | } |
| 2901 | |
| 2902 | void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) { |
| 2903 | LocationSummary* locations = |
| 2904 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2905 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2906 | } |
| 2907 | |
| 2908 | void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 2909 | // Will be generated at use site. |
| 2910 | } |
| 2911 | |
| 2912 | void LocationsBuilderMIPS::VisitGoto(HGoto* got) { |
| 2913 | got->SetLocations(nullptr); |
| 2914 | } |
| 2915 | |
| 2916 | void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| 2917 | DCHECK(!successor->IsExitBlock()); |
| 2918 | HBasicBlock* block = got->GetBlock(); |
| 2919 | HInstruction* previous = got->GetPrevious(); |
| 2920 | HLoopInformation* info = block->GetLoopInformation(); |
| 2921 | |
| 2922 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| 2923 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2924 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2925 | return; |
| 2926 | } |
| 2927 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2928 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2929 | } |
| 2930 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 2931 | __ B(codegen_->GetLabelOf(successor)); |
| 2932 | } |
| 2933 | } |
| 2934 | |
| 2935 | void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) { |
| 2936 | HandleGoto(got, got->GetSuccessor()); |
| 2937 | } |
| 2938 | |
| 2939 | void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2940 | try_boundary->SetLocations(nullptr); |
| 2941 | } |
| 2942 | |
| 2943 | void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2944 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2945 | if (!successor->IsExitBlock()) { |
| 2946 | HandleGoto(try_boundary, successor); |
| 2947 | } |
| 2948 | } |
| 2949 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2950 | void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond, |
| 2951 | LocationSummary* locations) { |
| 2952 | Register dst = locations->Out().AsRegister<Register>(); |
| 2953 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2954 | Location rhs_location = locations->InAt(1); |
| 2955 | Register rhs_reg = ZERO; |
| 2956 | int64_t rhs_imm = 0; |
| 2957 | bool use_imm = rhs_location.IsConstant(); |
| 2958 | if (use_imm) { |
| 2959 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 2960 | } else { |
| 2961 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 2962 | } |
| 2963 | |
| 2964 | switch (cond) { |
| 2965 | case kCondEQ: |
| 2966 | case kCondNE: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 2967 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 2968 | if (rhs_imm == 0) { |
| 2969 | if (cond == kCondEQ) { |
| 2970 | __ Sltiu(dst, lhs, 1); |
| 2971 | } else { |
| 2972 | __ Sltu(dst, ZERO, lhs); |
| 2973 | } |
| 2974 | } else { |
| 2975 | __ Addiu(dst, lhs, -rhs_imm); |
| 2976 | if (cond == kCondEQ) { |
| 2977 | __ Sltiu(dst, dst, 1); |
| 2978 | } else { |
| 2979 | __ Sltu(dst, ZERO, dst); |
| 2980 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2981 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2982 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 2983 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 2984 | __ Xori(dst, lhs, rhs_imm); |
| 2985 | } else { |
| 2986 | if (use_imm) { |
| 2987 | rhs_reg = TMP; |
| 2988 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2989 | } |
| 2990 | __ Xor(dst, lhs, rhs_reg); |
| 2991 | } |
| 2992 | if (cond == kCondEQ) { |
| 2993 | __ Sltiu(dst, dst, 1); |
| 2994 | } else { |
| 2995 | __ Sltu(dst, ZERO, dst); |
| 2996 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2997 | } |
| 2998 | break; |
| 2999 | |
| 3000 | case kCondLT: |
| 3001 | case kCondGE: |
| 3002 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3003 | __ Slti(dst, lhs, rhs_imm); |
| 3004 | } else { |
| 3005 | if (use_imm) { |
| 3006 | rhs_reg = TMP; |
| 3007 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3008 | } |
| 3009 | __ Slt(dst, lhs, rhs_reg); |
| 3010 | } |
| 3011 | if (cond == kCondGE) { |
| 3012 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 3013 | // only the slt instruction but no sge. |
| 3014 | __ Xori(dst, dst, 1); |
| 3015 | } |
| 3016 | break; |
| 3017 | |
| 3018 | case kCondLE: |
| 3019 | case kCondGT: |
| 3020 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 3021 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3022 | __ Slti(dst, lhs, rhs_imm + 1); |
| 3023 | if (cond == kCondGT) { |
| 3024 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 3025 | // only the slti instruction but no sgti. |
| 3026 | __ Xori(dst, dst, 1); |
| 3027 | } |
| 3028 | } else { |
| 3029 | if (use_imm) { |
| 3030 | rhs_reg = TMP; |
| 3031 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3032 | } |
| 3033 | __ Slt(dst, rhs_reg, lhs); |
| 3034 | if (cond == kCondLE) { |
| 3035 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 3036 | // only the slt instruction but no sle. |
| 3037 | __ Xori(dst, dst, 1); |
| 3038 | } |
| 3039 | } |
| 3040 | break; |
| 3041 | |
| 3042 | case kCondB: |
| 3043 | case kCondAE: |
| 3044 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3045 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3046 | // the comparison and thus lets us compare directly with |
| 3047 | // unsigned values in the ranges [0, 0x7fff] and |
| 3048 | // [0xffff8000, 0xffffffff]. |
| 3049 | __ Sltiu(dst, lhs, rhs_imm); |
| 3050 | } else { |
| 3051 | if (use_imm) { |
| 3052 | rhs_reg = TMP; |
| 3053 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3054 | } |
| 3055 | __ Sltu(dst, lhs, rhs_reg); |
| 3056 | } |
| 3057 | if (cond == kCondAE) { |
| 3058 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 3059 | // only the sltu instruction but no sgeu. |
| 3060 | __ Xori(dst, dst, 1); |
| 3061 | } |
| 3062 | break; |
| 3063 | |
| 3064 | case kCondBE: |
| 3065 | case kCondA: |
| 3066 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 3067 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3068 | // Note that this only works if rhs + 1 does not overflow |
| 3069 | // to 0, hence the check above. |
| 3070 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3071 | // the comparison and thus lets us compare directly with |
| 3072 | // unsigned values in the ranges [0, 0x7fff] and |
| 3073 | // [0xffff8000, 0xffffffff]. |
| 3074 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 3075 | if (cond == kCondA) { |
| 3076 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 3077 | // only the sltiu instruction but no sgtiu. |
| 3078 | __ Xori(dst, dst, 1); |
| 3079 | } |
| 3080 | } else { |
| 3081 | if (use_imm) { |
| 3082 | rhs_reg = TMP; |
| 3083 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3084 | } |
| 3085 | __ Sltu(dst, rhs_reg, lhs); |
| 3086 | if (cond == kCondBE) { |
| 3087 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 3088 | // only the sltu instruction but no sleu. |
| 3089 | __ Xori(dst, dst, 1); |
| 3090 | } |
| 3091 | } |
| 3092 | break; |
| 3093 | } |
| 3094 | } |
| 3095 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 3096 | bool InstructionCodeGeneratorMIPS::MaterializeIntCompare(IfCondition cond, |
| 3097 | LocationSummary* input_locations, |
| 3098 | Register dst) { |
| 3099 | Register lhs = input_locations->InAt(0).AsRegister<Register>(); |
| 3100 | Location rhs_location = input_locations->InAt(1); |
| 3101 | Register rhs_reg = ZERO; |
| 3102 | int64_t rhs_imm = 0; |
| 3103 | bool use_imm = rhs_location.IsConstant(); |
| 3104 | if (use_imm) { |
| 3105 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3106 | } else { |
| 3107 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 3108 | } |
| 3109 | |
| 3110 | switch (cond) { |
| 3111 | case kCondEQ: |
| 3112 | case kCondNE: |
| 3113 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 3114 | __ Addiu(dst, lhs, -rhs_imm); |
| 3115 | } else if (use_imm && IsUint<16>(rhs_imm)) { |
| 3116 | __ Xori(dst, lhs, rhs_imm); |
| 3117 | } else { |
| 3118 | if (use_imm) { |
| 3119 | rhs_reg = TMP; |
| 3120 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3121 | } |
| 3122 | __ Xor(dst, lhs, rhs_reg); |
| 3123 | } |
| 3124 | return (cond == kCondEQ); |
| 3125 | |
| 3126 | case kCondLT: |
| 3127 | case kCondGE: |
| 3128 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3129 | __ Slti(dst, lhs, rhs_imm); |
| 3130 | } else { |
| 3131 | if (use_imm) { |
| 3132 | rhs_reg = TMP; |
| 3133 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3134 | } |
| 3135 | __ Slt(dst, lhs, rhs_reg); |
| 3136 | } |
| 3137 | return (cond == kCondGE); |
| 3138 | |
| 3139 | case kCondLE: |
| 3140 | case kCondGT: |
| 3141 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 3142 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3143 | __ Slti(dst, lhs, rhs_imm + 1); |
| 3144 | return (cond == kCondGT); |
| 3145 | } else { |
| 3146 | if (use_imm) { |
| 3147 | rhs_reg = TMP; |
| 3148 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3149 | } |
| 3150 | __ Slt(dst, rhs_reg, lhs); |
| 3151 | return (cond == kCondLE); |
| 3152 | } |
| 3153 | |
| 3154 | case kCondB: |
| 3155 | case kCondAE: |
| 3156 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3157 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3158 | // the comparison and thus lets us compare directly with |
| 3159 | // unsigned values in the ranges [0, 0x7fff] and |
| 3160 | // [0xffff8000, 0xffffffff]. |
| 3161 | __ Sltiu(dst, lhs, rhs_imm); |
| 3162 | } else { |
| 3163 | if (use_imm) { |
| 3164 | rhs_reg = TMP; |
| 3165 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3166 | } |
| 3167 | __ Sltu(dst, lhs, rhs_reg); |
| 3168 | } |
| 3169 | return (cond == kCondAE); |
| 3170 | |
| 3171 | case kCondBE: |
| 3172 | case kCondA: |
| 3173 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 3174 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3175 | // Note that this only works if rhs + 1 does not overflow |
| 3176 | // to 0, hence the check above. |
| 3177 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3178 | // the comparison and thus lets us compare directly with |
| 3179 | // unsigned values in the ranges [0, 0x7fff] and |
| 3180 | // [0xffff8000, 0xffffffff]. |
| 3181 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 3182 | return (cond == kCondA); |
| 3183 | } else { |
| 3184 | if (use_imm) { |
| 3185 | rhs_reg = TMP; |
| 3186 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3187 | } |
| 3188 | __ Sltu(dst, rhs_reg, lhs); |
| 3189 | return (cond == kCondBE); |
| 3190 | } |
| 3191 | } |
| 3192 | } |
| 3193 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3194 | void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond, |
| 3195 | LocationSummary* locations, |
| 3196 | MipsLabel* label) { |
| 3197 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 3198 | Location rhs_location = locations->InAt(1); |
| 3199 | Register rhs_reg = ZERO; |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 3200 | int64_t rhs_imm = 0; |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3201 | bool use_imm = rhs_location.IsConstant(); |
| 3202 | if (use_imm) { |
| 3203 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3204 | } else { |
| 3205 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 3206 | } |
| 3207 | |
| 3208 | if (use_imm && rhs_imm == 0) { |
| 3209 | switch (cond) { |
| 3210 | case kCondEQ: |
| 3211 | case kCondBE: // <= 0 if zero |
| 3212 | __ Beqz(lhs, label); |
| 3213 | break; |
| 3214 | case kCondNE: |
| 3215 | case kCondA: // > 0 if non-zero |
| 3216 | __ Bnez(lhs, label); |
| 3217 | break; |
| 3218 | case kCondLT: |
| 3219 | __ Bltz(lhs, label); |
| 3220 | break; |
| 3221 | case kCondGE: |
| 3222 | __ Bgez(lhs, label); |
| 3223 | break; |
| 3224 | case kCondLE: |
| 3225 | __ Blez(lhs, label); |
| 3226 | break; |
| 3227 | case kCondGT: |
| 3228 | __ Bgtz(lhs, label); |
| 3229 | break; |
| 3230 | case kCondB: // always false |
| 3231 | break; |
| 3232 | case kCondAE: // always true |
| 3233 | __ B(label); |
| 3234 | break; |
| 3235 | } |
| 3236 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 3237 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3238 | if (isR6 || !use_imm) { |
| 3239 | if (use_imm) { |
| 3240 | rhs_reg = TMP; |
| 3241 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3242 | } |
| 3243 | switch (cond) { |
| 3244 | case kCondEQ: |
| 3245 | __ Beq(lhs, rhs_reg, label); |
| 3246 | break; |
| 3247 | case kCondNE: |
| 3248 | __ Bne(lhs, rhs_reg, label); |
| 3249 | break; |
| 3250 | case kCondLT: |
| 3251 | __ Blt(lhs, rhs_reg, label); |
| 3252 | break; |
| 3253 | case kCondGE: |
| 3254 | __ Bge(lhs, rhs_reg, label); |
| 3255 | break; |
| 3256 | case kCondLE: |
| 3257 | __ Bge(rhs_reg, lhs, label); |
| 3258 | break; |
| 3259 | case kCondGT: |
| 3260 | __ Blt(rhs_reg, lhs, label); |
| 3261 | break; |
| 3262 | case kCondB: |
| 3263 | __ Bltu(lhs, rhs_reg, label); |
| 3264 | break; |
| 3265 | case kCondAE: |
| 3266 | __ Bgeu(lhs, rhs_reg, label); |
| 3267 | break; |
| 3268 | case kCondBE: |
| 3269 | __ Bgeu(rhs_reg, lhs, label); |
| 3270 | break; |
| 3271 | case kCondA: |
| 3272 | __ Bltu(rhs_reg, lhs, label); |
| 3273 | break; |
| 3274 | } |
| 3275 | } else { |
| 3276 | // Special cases for more efficient comparison with constants on R2. |
| 3277 | switch (cond) { |
| 3278 | case kCondEQ: |
| 3279 | __ LoadConst32(TMP, rhs_imm); |
| 3280 | __ Beq(lhs, TMP, label); |
| 3281 | break; |
| 3282 | case kCondNE: |
| 3283 | __ LoadConst32(TMP, rhs_imm); |
| 3284 | __ Bne(lhs, TMP, label); |
| 3285 | break; |
| 3286 | case kCondLT: |
| 3287 | if (IsInt<16>(rhs_imm)) { |
| 3288 | __ Slti(TMP, lhs, rhs_imm); |
| 3289 | __ Bnez(TMP, label); |
| 3290 | } else { |
| 3291 | __ LoadConst32(TMP, rhs_imm); |
| 3292 | __ Blt(lhs, TMP, label); |
| 3293 | } |
| 3294 | break; |
| 3295 | case kCondGE: |
| 3296 | if (IsInt<16>(rhs_imm)) { |
| 3297 | __ Slti(TMP, lhs, rhs_imm); |
| 3298 | __ Beqz(TMP, label); |
| 3299 | } else { |
| 3300 | __ LoadConst32(TMP, rhs_imm); |
| 3301 | __ Bge(lhs, TMP, label); |
| 3302 | } |
| 3303 | break; |
| 3304 | case kCondLE: |
| 3305 | if (IsInt<16>(rhs_imm + 1)) { |
| 3306 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3307 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 3308 | __ Bnez(TMP, label); |
| 3309 | } else { |
| 3310 | __ LoadConst32(TMP, rhs_imm); |
| 3311 | __ Bge(TMP, lhs, label); |
| 3312 | } |
| 3313 | break; |
| 3314 | case kCondGT: |
| 3315 | if (IsInt<16>(rhs_imm + 1)) { |
| 3316 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 3317 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 3318 | __ Beqz(TMP, label); |
| 3319 | } else { |
| 3320 | __ LoadConst32(TMP, rhs_imm); |
| 3321 | __ Blt(TMP, lhs, label); |
| 3322 | } |
| 3323 | break; |
| 3324 | case kCondB: |
| 3325 | if (IsInt<16>(rhs_imm)) { |
| 3326 | __ Sltiu(TMP, lhs, rhs_imm); |
| 3327 | __ Bnez(TMP, label); |
| 3328 | } else { |
| 3329 | __ LoadConst32(TMP, rhs_imm); |
| 3330 | __ Bltu(lhs, TMP, label); |
| 3331 | } |
| 3332 | break; |
| 3333 | case kCondAE: |
| 3334 | if (IsInt<16>(rhs_imm)) { |
| 3335 | __ Sltiu(TMP, lhs, rhs_imm); |
| 3336 | __ Beqz(TMP, label); |
| 3337 | } else { |
| 3338 | __ LoadConst32(TMP, rhs_imm); |
| 3339 | __ Bgeu(lhs, TMP, label); |
| 3340 | } |
| 3341 | break; |
| 3342 | case kCondBE: |
| 3343 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 3344 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3345 | // Note that this only works if rhs + 1 does not overflow |
| 3346 | // to 0, hence the check above. |
| 3347 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 3348 | __ Bnez(TMP, label); |
| 3349 | } else { |
| 3350 | __ LoadConst32(TMP, rhs_imm); |
| 3351 | __ Bgeu(TMP, lhs, label); |
| 3352 | } |
| 3353 | break; |
| 3354 | case kCondA: |
| 3355 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 3356 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 3357 | // Note that this only works if rhs + 1 does not overflow |
| 3358 | // to 0, hence the check above. |
| 3359 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 3360 | __ Beqz(TMP, label); |
| 3361 | } else { |
| 3362 | __ LoadConst32(TMP, rhs_imm); |
| 3363 | __ Bltu(TMP, lhs, label); |
| 3364 | } |
| 3365 | break; |
| 3366 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3367 | } |
| 3368 | } |
| 3369 | } |
| 3370 | |
| 3371 | void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond, |
| 3372 | LocationSummary* locations, |
| 3373 | MipsLabel* label) { |
| 3374 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3375 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3376 | Location rhs_location = locations->InAt(1); |
| 3377 | Register rhs_high = ZERO; |
| 3378 | Register rhs_low = ZERO; |
| 3379 | int64_t imm = 0; |
| 3380 | uint32_t imm_high = 0; |
| 3381 | uint32_t imm_low = 0; |
| 3382 | bool use_imm = rhs_location.IsConstant(); |
| 3383 | if (use_imm) { |
| 3384 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); |
| 3385 | imm_high = High32Bits(imm); |
| 3386 | imm_low = Low32Bits(imm); |
| 3387 | } else { |
| 3388 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 3389 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 3390 | } |
| 3391 | |
| 3392 | if (use_imm && imm == 0) { |
| 3393 | switch (cond) { |
| 3394 | case kCondEQ: |
| 3395 | case kCondBE: // <= 0 if zero |
| 3396 | __ Or(TMP, lhs_high, lhs_low); |
| 3397 | __ Beqz(TMP, label); |
| 3398 | break; |
| 3399 | case kCondNE: |
| 3400 | case kCondA: // > 0 if non-zero |
| 3401 | __ Or(TMP, lhs_high, lhs_low); |
| 3402 | __ Bnez(TMP, label); |
| 3403 | break; |
| 3404 | case kCondLT: |
| 3405 | __ Bltz(lhs_high, label); |
| 3406 | break; |
| 3407 | case kCondGE: |
| 3408 | __ Bgez(lhs_high, label); |
| 3409 | break; |
| 3410 | case kCondLE: |
| 3411 | __ Or(TMP, lhs_high, lhs_low); |
| 3412 | __ Sra(AT, lhs_high, 31); |
| 3413 | __ Bgeu(AT, TMP, label); |
| 3414 | break; |
| 3415 | case kCondGT: |
| 3416 | __ Or(TMP, lhs_high, lhs_low); |
| 3417 | __ Sra(AT, lhs_high, 31); |
| 3418 | __ Bltu(AT, TMP, label); |
| 3419 | break; |
| 3420 | case kCondB: // always false |
| 3421 | break; |
| 3422 | case kCondAE: // always true |
| 3423 | __ B(label); |
| 3424 | break; |
| 3425 | } |
| 3426 | } else if (use_imm) { |
| 3427 | // TODO: more efficient comparison with constants without loading them into TMP/AT. |
| 3428 | switch (cond) { |
| 3429 | case kCondEQ: |
| 3430 | __ LoadConst32(TMP, imm_high); |
| 3431 | __ Xor(TMP, TMP, lhs_high); |
| 3432 | __ LoadConst32(AT, imm_low); |
| 3433 | __ Xor(AT, AT, lhs_low); |
| 3434 | __ Or(TMP, TMP, AT); |
| 3435 | __ Beqz(TMP, label); |
| 3436 | break; |
| 3437 | case kCondNE: |
| 3438 | __ LoadConst32(TMP, imm_high); |
| 3439 | __ Xor(TMP, TMP, lhs_high); |
| 3440 | __ LoadConst32(AT, imm_low); |
| 3441 | __ Xor(AT, AT, lhs_low); |
| 3442 | __ Or(TMP, TMP, AT); |
| 3443 | __ Bnez(TMP, label); |
| 3444 | break; |
| 3445 | case kCondLT: |
| 3446 | __ LoadConst32(TMP, imm_high); |
| 3447 | __ Blt(lhs_high, TMP, label); |
| 3448 | __ Slt(TMP, TMP, lhs_high); |
| 3449 | __ LoadConst32(AT, imm_low); |
| 3450 | __ Sltu(AT, lhs_low, AT); |
| 3451 | __ Blt(TMP, AT, label); |
| 3452 | break; |
| 3453 | case kCondGE: |
| 3454 | __ LoadConst32(TMP, imm_high); |
| 3455 | __ Blt(TMP, lhs_high, label); |
| 3456 | __ Slt(TMP, lhs_high, TMP); |
| 3457 | __ LoadConst32(AT, imm_low); |
| 3458 | __ Sltu(AT, lhs_low, AT); |
| 3459 | __ Or(TMP, TMP, AT); |
| 3460 | __ Beqz(TMP, label); |
| 3461 | break; |
| 3462 | case kCondLE: |
| 3463 | __ LoadConst32(TMP, imm_high); |
| 3464 | __ Blt(lhs_high, TMP, label); |
| 3465 | __ Slt(TMP, TMP, lhs_high); |
| 3466 | __ LoadConst32(AT, imm_low); |
| 3467 | __ Sltu(AT, AT, lhs_low); |
| 3468 | __ Or(TMP, TMP, AT); |
| 3469 | __ Beqz(TMP, label); |
| 3470 | break; |
| 3471 | case kCondGT: |
| 3472 | __ LoadConst32(TMP, imm_high); |
| 3473 | __ Blt(TMP, lhs_high, label); |
| 3474 | __ Slt(TMP, lhs_high, TMP); |
| 3475 | __ LoadConst32(AT, imm_low); |
| 3476 | __ Sltu(AT, AT, lhs_low); |
| 3477 | __ Blt(TMP, AT, label); |
| 3478 | break; |
| 3479 | case kCondB: |
| 3480 | __ LoadConst32(TMP, imm_high); |
| 3481 | __ Bltu(lhs_high, TMP, label); |
| 3482 | __ Sltu(TMP, TMP, lhs_high); |
| 3483 | __ LoadConst32(AT, imm_low); |
| 3484 | __ Sltu(AT, lhs_low, AT); |
| 3485 | __ Blt(TMP, AT, label); |
| 3486 | break; |
| 3487 | case kCondAE: |
| 3488 | __ LoadConst32(TMP, imm_high); |
| 3489 | __ Bltu(TMP, lhs_high, label); |
| 3490 | __ Sltu(TMP, lhs_high, TMP); |
| 3491 | __ LoadConst32(AT, imm_low); |
| 3492 | __ Sltu(AT, lhs_low, AT); |
| 3493 | __ Or(TMP, TMP, AT); |
| 3494 | __ Beqz(TMP, label); |
| 3495 | break; |
| 3496 | case kCondBE: |
| 3497 | __ LoadConst32(TMP, imm_high); |
| 3498 | __ Bltu(lhs_high, TMP, label); |
| 3499 | __ Sltu(TMP, TMP, lhs_high); |
| 3500 | __ LoadConst32(AT, imm_low); |
| 3501 | __ Sltu(AT, AT, lhs_low); |
| 3502 | __ Or(TMP, TMP, AT); |
| 3503 | __ Beqz(TMP, label); |
| 3504 | break; |
| 3505 | case kCondA: |
| 3506 | __ LoadConst32(TMP, imm_high); |
| 3507 | __ Bltu(TMP, lhs_high, label); |
| 3508 | __ Sltu(TMP, lhs_high, TMP); |
| 3509 | __ LoadConst32(AT, imm_low); |
| 3510 | __ Sltu(AT, AT, lhs_low); |
| 3511 | __ Blt(TMP, AT, label); |
| 3512 | break; |
| 3513 | } |
| 3514 | } else { |
| 3515 | switch (cond) { |
| 3516 | case kCondEQ: |
| 3517 | __ Xor(TMP, lhs_high, rhs_high); |
| 3518 | __ Xor(AT, lhs_low, rhs_low); |
| 3519 | __ Or(TMP, TMP, AT); |
| 3520 | __ Beqz(TMP, label); |
| 3521 | break; |
| 3522 | case kCondNE: |
| 3523 | __ Xor(TMP, lhs_high, rhs_high); |
| 3524 | __ Xor(AT, lhs_low, rhs_low); |
| 3525 | __ Or(TMP, TMP, AT); |
| 3526 | __ Bnez(TMP, label); |
| 3527 | break; |
| 3528 | case kCondLT: |
| 3529 | __ Blt(lhs_high, rhs_high, label); |
| 3530 | __ Slt(TMP, rhs_high, lhs_high); |
| 3531 | __ Sltu(AT, lhs_low, rhs_low); |
| 3532 | __ Blt(TMP, AT, label); |
| 3533 | break; |
| 3534 | case kCondGE: |
| 3535 | __ Blt(rhs_high, lhs_high, label); |
| 3536 | __ Slt(TMP, lhs_high, rhs_high); |
| 3537 | __ Sltu(AT, lhs_low, rhs_low); |
| 3538 | __ Or(TMP, TMP, AT); |
| 3539 | __ Beqz(TMP, label); |
| 3540 | break; |
| 3541 | case kCondLE: |
| 3542 | __ Blt(lhs_high, rhs_high, label); |
| 3543 | __ Slt(TMP, rhs_high, lhs_high); |
| 3544 | __ Sltu(AT, rhs_low, lhs_low); |
| 3545 | __ Or(TMP, TMP, AT); |
| 3546 | __ Beqz(TMP, label); |
| 3547 | break; |
| 3548 | case kCondGT: |
| 3549 | __ Blt(rhs_high, lhs_high, label); |
| 3550 | __ Slt(TMP, lhs_high, rhs_high); |
| 3551 | __ Sltu(AT, rhs_low, lhs_low); |
| 3552 | __ Blt(TMP, AT, label); |
| 3553 | break; |
| 3554 | case kCondB: |
| 3555 | __ Bltu(lhs_high, rhs_high, label); |
| 3556 | __ Sltu(TMP, rhs_high, lhs_high); |
| 3557 | __ Sltu(AT, lhs_low, rhs_low); |
| 3558 | __ Blt(TMP, AT, label); |
| 3559 | break; |
| 3560 | case kCondAE: |
| 3561 | __ Bltu(rhs_high, lhs_high, label); |
| 3562 | __ Sltu(TMP, lhs_high, rhs_high); |
| 3563 | __ Sltu(AT, lhs_low, rhs_low); |
| 3564 | __ Or(TMP, TMP, AT); |
| 3565 | __ Beqz(TMP, label); |
| 3566 | break; |
| 3567 | case kCondBE: |
| 3568 | __ Bltu(lhs_high, rhs_high, label); |
| 3569 | __ Sltu(TMP, rhs_high, lhs_high); |
| 3570 | __ Sltu(AT, rhs_low, lhs_low); |
| 3571 | __ Or(TMP, TMP, AT); |
| 3572 | __ Beqz(TMP, label); |
| 3573 | break; |
| 3574 | case kCondA: |
| 3575 | __ Bltu(rhs_high, lhs_high, label); |
| 3576 | __ Sltu(TMP, lhs_high, rhs_high); |
| 3577 | __ Sltu(AT, rhs_low, lhs_low); |
| 3578 | __ Blt(TMP, AT, label); |
| 3579 | break; |
| 3580 | } |
| 3581 | } |
| 3582 | } |
| 3583 | |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 3584 | void InstructionCodeGeneratorMIPS::GenerateFpCompare(IfCondition cond, |
| 3585 | bool gt_bias, |
| 3586 | Primitive::Type type, |
| 3587 | LocationSummary* locations) { |
| 3588 | Register dst = locations->Out().AsRegister<Register>(); |
| 3589 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3590 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3591 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3592 | if (type == Primitive::kPrimFloat) { |
| 3593 | if (isR6) { |
| 3594 | switch (cond) { |
| 3595 | case kCondEQ: |
| 3596 | __ CmpEqS(FTMP, lhs, rhs); |
| 3597 | __ Mfc1(dst, FTMP); |
| 3598 | __ Andi(dst, dst, 1); |
| 3599 | break; |
| 3600 | case kCondNE: |
| 3601 | __ CmpEqS(FTMP, lhs, rhs); |
| 3602 | __ Mfc1(dst, FTMP); |
| 3603 | __ Addiu(dst, dst, 1); |
| 3604 | break; |
| 3605 | case kCondLT: |
| 3606 | if (gt_bias) { |
| 3607 | __ CmpLtS(FTMP, lhs, rhs); |
| 3608 | } else { |
| 3609 | __ CmpUltS(FTMP, lhs, rhs); |
| 3610 | } |
| 3611 | __ Mfc1(dst, FTMP); |
| 3612 | __ Andi(dst, dst, 1); |
| 3613 | break; |
| 3614 | case kCondLE: |
| 3615 | if (gt_bias) { |
| 3616 | __ CmpLeS(FTMP, lhs, rhs); |
| 3617 | } else { |
| 3618 | __ CmpUleS(FTMP, lhs, rhs); |
| 3619 | } |
| 3620 | __ Mfc1(dst, FTMP); |
| 3621 | __ Andi(dst, dst, 1); |
| 3622 | break; |
| 3623 | case kCondGT: |
| 3624 | if (gt_bias) { |
| 3625 | __ CmpUltS(FTMP, rhs, lhs); |
| 3626 | } else { |
| 3627 | __ CmpLtS(FTMP, rhs, lhs); |
| 3628 | } |
| 3629 | __ Mfc1(dst, FTMP); |
| 3630 | __ Andi(dst, dst, 1); |
| 3631 | break; |
| 3632 | case kCondGE: |
| 3633 | if (gt_bias) { |
| 3634 | __ CmpUleS(FTMP, rhs, lhs); |
| 3635 | } else { |
| 3636 | __ CmpLeS(FTMP, rhs, lhs); |
| 3637 | } |
| 3638 | __ Mfc1(dst, FTMP); |
| 3639 | __ Andi(dst, dst, 1); |
| 3640 | break; |
| 3641 | default: |
| 3642 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3643 | UNREACHABLE(); |
| 3644 | } |
| 3645 | } else { |
| 3646 | switch (cond) { |
| 3647 | case kCondEQ: |
| 3648 | __ CeqS(0, lhs, rhs); |
| 3649 | __ LoadConst32(dst, 1); |
| 3650 | __ Movf(dst, ZERO, 0); |
| 3651 | break; |
| 3652 | case kCondNE: |
| 3653 | __ CeqS(0, lhs, rhs); |
| 3654 | __ LoadConst32(dst, 1); |
| 3655 | __ Movt(dst, ZERO, 0); |
| 3656 | break; |
| 3657 | case kCondLT: |
| 3658 | if (gt_bias) { |
| 3659 | __ ColtS(0, lhs, rhs); |
| 3660 | } else { |
| 3661 | __ CultS(0, lhs, rhs); |
| 3662 | } |
| 3663 | __ LoadConst32(dst, 1); |
| 3664 | __ Movf(dst, ZERO, 0); |
| 3665 | break; |
| 3666 | case kCondLE: |
| 3667 | if (gt_bias) { |
| 3668 | __ ColeS(0, lhs, rhs); |
| 3669 | } else { |
| 3670 | __ CuleS(0, lhs, rhs); |
| 3671 | } |
| 3672 | __ LoadConst32(dst, 1); |
| 3673 | __ Movf(dst, ZERO, 0); |
| 3674 | break; |
| 3675 | case kCondGT: |
| 3676 | if (gt_bias) { |
| 3677 | __ CultS(0, rhs, lhs); |
| 3678 | } else { |
| 3679 | __ ColtS(0, rhs, lhs); |
| 3680 | } |
| 3681 | __ LoadConst32(dst, 1); |
| 3682 | __ Movf(dst, ZERO, 0); |
| 3683 | break; |
| 3684 | case kCondGE: |
| 3685 | if (gt_bias) { |
| 3686 | __ CuleS(0, rhs, lhs); |
| 3687 | } else { |
| 3688 | __ ColeS(0, rhs, lhs); |
| 3689 | } |
| 3690 | __ LoadConst32(dst, 1); |
| 3691 | __ Movf(dst, ZERO, 0); |
| 3692 | break; |
| 3693 | default: |
| 3694 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3695 | UNREACHABLE(); |
| 3696 | } |
| 3697 | } |
| 3698 | } else { |
| 3699 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 3700 | if (isR6) { |
| 3701 | switch (cond) { |
| 3702 | case kCondEQ: |
| 3703 | __ CmpEqD(FTMP, lhs, rhs); |
| 3704 | __ Mfc1(dst, FTMP); |
| 3705 | __ Andi(dst, dst, 1); |
| 3706 | break; |
| 3707 | case kCondNE: |
| 3708 | __ CmpEqD(FTMP, lhs, rhs); |
| 3709 | __ Mfc1(dst, FTMP); |
| 3710 | __ Addiu(dst, dst, 1); |
| 3711 | break; |
| 3712 | case kCondLT: |
| 3713 | if (gt_bias) { |
| 3714 | __ CmpLtD(FTMP, lhs, rhs); |
| 3715 | } else { |
| 3716 | __ CmpUltD(FTMP, lhs, rhs); |
| 3717 | } |
| 3718 | __ Mfc1(dst, FTMP); |
| 3719 | __ Andi(dst, dst, 1); |
| 3720 | break; |
| 3721 | case kCondLE: |
| 3722 | if (gt_bias) { |
| 3723 | __ CmpLeD(FTMP, lhs, rhs); |
| 3724 | } else { |
| 3725 | __ CmpUleD(FTMP, lhs, rhs); |
| 3726 | } |
| 3727 | __ Mfc1(dst, FTMP); |
| 3728 | __ Andi(dst, dst, 1); |
| 3729 | break; |
| 3730 | case kCondGT: |
| 3731 | if (gt_bias) { |
| 3732 | __ CmpUltD(FTMP, rhs, lhs); |
| 3733 | } else { |
| 3734 | __ CmpLtD(FTMP, rhs, lhs); |
| 3735 | } |
| 3736 | __ Mfc1(dst, FTMP); |
| 3737 | __ Andi(dst, dst, 1); |
| 3738 | break; |
| 3739 | case kCondGE: |
| 3740 | if (gt_bias) { |
| 3741 | __ CmpUleD(FTMP, rhs, lhs); |
| 3742 | } else { |
| 3743 | __ CmpLeD(FTMP, rhs, lhs); |
| 3744 | } |
| 3745 | __ Mfc1(dst, FTMP); |
| 3746 | __ Andi(dst, dst, 1); |
| 3747 | break; |
| 3748 | default: |
| 3749 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3750 | UNREACHABLE(); |
| 3751 | } |
| 3752 | } else { |
| 3753 | switch (cond) { |
| 3754 | case kCondEQ: |
| 3755 | __ CeqD(0, lhs, rhs); |
| 3756 | __ LoadConst32(dst, 1); |
| 3757 | __ Movf(dst, ZERO, 0); |
| 3758 | break; |
| 3759 | case kCondNE: |
| 3760 | __ CeqD(0, lhs, rhs); |
| 3761 | __ LoadConst32(dst, 1); |
| 3762 | __ Movt(dst, ZERO, 0); |
| 3763 | break; |
| 3764 | case kCondLT: |
| 3765 | if (gt_bias) { |
| 3766 | __ ColtD(0, lhs, rhs); |
| 3767 | } else { |
| 3768 | __ CultD(0, lhs, rhs); |
| 3769 | } |
| 3770 | __ LoadConst32(dst, 1); |
| 3771 | __ Movf(dst, ZERO, 0); |
| 3772 | break; |
| 3773 | case kCondLE: |
| 3774 | if (gt_bias) { |
| 3775 | __ ColeD(0, lhs, rhs); |
| 3776 | } else { |
| 3777 | __ CuleD(0, lhs, rhs); |
| 3778 | } |
| 3779 | __ LoadConst32(dst, 1); |
| 3780 | __ Movf(dst, ZERO, 0); |
| 3781 | break; |
| 3782 | case kCondGT: |
| 3783 | if (gt_bias) { |
| 3784 | __ CultD(0, rhs, lhs); |
| 3785 | } else { |
| 3786 | __ ColtD(0, rhs, lhs); |
| 3787 | } |
| 3788 | __ LoadConst32(dst, 1); |
| 3789 | __ Movf(dst, ZERO, 0); |
| 3790 | break; |
| 3791 | case kCondGE: |
| 3792 | if (gt_bias) { |
| 3793 | __ CuleD(0, rhs, lhs); |
| 3794 | } else { |
| 3795 | __ ColeD(0, rhs, lhs); |
| 3796 | } |
| 3797 | __ LoadConst32(dst, 1); |
| 3798 | __ Movf(dst, ZERO, 0); |
| 3799 | break; |
| 3800 | default: |
| 3801 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3802 | UNREACHABLE(); |
| 3803 | } |
| 3804 | } |
| 3805 | } |
| 3806 | } |
| 3807 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 3808 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR2(IfCondition cond, |
| 3809 | bool gt_bias, |
| 3810 | Primitive::Type type, |
| 3811 | LocationSummary* input_locations, |
| 3812 | int cc) { |
| 3813 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3814 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3815 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
| 3816 | if (type == Primitive::kPrimFloat) { |
| 3817 | switch (cond) { |
| 3818 | case kCondEQ: |
| 3819 | __ CeqS(cc, lhs, rhs); |
| 3820 | return false; |
| 3821 | case kCondNE: |
| 3822 | __ CeqS(cc, lhs, rhs); |
| 3823 | return true; |
| 3824 | case kCondLT: |
| 3825 | if (gt_bias) { |
| 3826 | __ ColtS(cc, lhs, rhs); |
| 3827 | } else { |
| 3828 | __ CultS(cc, lhs, rhs); |
| 3829 | } |
| 3830 | return false; |
| 3831 | case kCondLE: |
| 3832 | if (gt_bias) { |
| 3833 | __ ColeS(cc, lhs, rhs); |
| 3834 | } else { |
| 3835 | __ CuleS(cc, lhs, rhs); |
| 3836 | } |
| 3837 | return false; |
| 3838 | case kCondGT: |
| 3839 | if (gt_bias) { |
| 3840 | __ CultS(cc, rhs, lhs); |
| 3841 | } else { |
| 3842 | __ ColtS(cc, rhs, lhs); |
| 3843 | } |
| 3844 | return false; |
| 3845 | case kCondGE: |
| 3846 | if (gt_bias) { |
| 3847 | __ CuleS(cc, rhs, lhs); |
| 3848 | } else { |
| 3849 | __ ColeS(cc, rhs, lhs); |
| 3850 | } |
| 3851 | return false; |
| 3852 | default: |
| 3853 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3854 | UNREACHABLE(); |
| 3855 | } |
| 3856 | } else { |
| 3857 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 3858 | switch (cond) { |
| 3859 | case kCondEQ: |
| 3860 | __ CeqD(cc, lhs, rhs); |
| 3861 | return false; |
| 3862 | case kCondNE: |
| 3863 | __ CeqD(cc, lhs, rhs); |
| 3864 | return true; |
| 3865 | case kCondLT: |
| 3866 | if (gt_bias) { |
| 3867 | __ ColtD(cc, lhs, rhs); |
| 3868 | } else { |
| 3869 | __ CultD(cc, lhs, rhs); |
| 3870 | } |
| 3871 | return false; |
| 3872 | case kCondLE: |
| 3873 | if (gt_bias) { |
| 3874 | __ ColeD(cc, lhs, rhs); |
| 3875 | } else { |
| 3876 | __ CuleD(cc, lhs, rhs); |
| 3877 | } |
| 3878 | return false; |
| 3879 | case kCondGT: |
| 3880 | if (gt_bias) { |
| 3881 | __ CultD(cc, rhs, lhs); |
| 3882 | } else { |
| 3883 | __ ColtD(cc, rhs, lhs); |
| 3884 | } |
| 3885 | return false; |
| 3886 | case kCondGE: |
| 3887 | if (gt_bias) { |
| 3888 | __ CuleD(cc, rhs, lhs); |
| 3889 | } else { |
| 3890 | __ ColeD(cc, rhs, lhs); |
| 3891 | } |
| 3892 | return false; |
| 3893 | default: |
| 3894 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3895 | UNREACHABLE(); |
| 3896 | } |
| 3897 | } |
| 3898 | } |
| 3899 | |
| 3900 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR6(IfCondition cond, |
| 3901 | bool gt_bias, |
| 3902 | Primitive::Type type, |
| 3903 | LocationSummary* input_locations, |
| 3904 | FRegister dst) { |
| 3905 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3906 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3907 | CHECK(codegen_->GetInstructionSetFeatures().IsR6()); |
| 3908 | if (type == Primitive::kPrimFloat) { |
| 3909 | switch (cond) { |
| 3910 | case kCondEQ: |
| 3911 | __ CmpEqS(dst, lhs, rhs); |
| 3912 | return false; |
| 3913 | case kCondNE: |
| 3914 | __ CmpEqS(dst, lhs, rhs); |
| 3915 | return true; |
| 3916 | case kCondLT: |
| 3917 | if (gt_bias) { |
| 3918 | __ CmpLtS(dst, lhs, rhs); |
| 3919 | } else { |
| 3920 | __ CmpUltS(dst, lhs, rhs); |
| 3921 | } |
| 3922 | return false; |
| 3923 | case kCondLE: |
| 3924 | if (gt_bias) { |
| 3925 | __ CmpLeS(dst, lhs, rhs); |
| 3926 | } else { |
| 3927 | __ CmpUleS(dst, lhs, rhs); |
| 3928 | } |
| 3929 | return false; |
| 3930 | case kCondGT: |
| 3931 | if (gt_bias) { |
| 3932 | __ CmpUltS(dst, rhs, lhs); |
| 3933 | } else { |
| 3934 | __ CmpLtS(dst, rhs, lhs); |
| 3935 | } |
| 3936 | return false; |
| 3937 | case kCondGE: |
| 3938 | if (gt_bias) { |
| 3939 | __ CmpUleS(dst, rhs, lhs); |
| 3940 | } else { |
| 3941 | __ CmpLeS(dst, rhs, lhs); |
| 3942 | } |
| 3943 | return false; |
| 3944 | default: |
| 3945 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3946 | UNREACHABLE(); |
| 3947 | } |
| 3948 | } else { |
| 3949 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 3950 | switch (cond) { |
| 3951 | case kCondEQ: |
| 3952 | __ CmpEqD(dst, lhs, rhs); |
| 3953 | return false; |
| 3954 | case kCondNE: |
| 3955 | __ CmpEqD(dst, lhs, rhs); |
| 3956 | return true; |
| 3957 | case kCondLT: |
| 3958 | if (gt_bias) { |
| 3959 | __ CmpLtD(dst, lhs, rhs); |
| 3960 | } else { |
| 3961 | __ CmpUltD(dst, lhs, rhs); |
| 3962 | } |
| 3963 | return false; |
| 3964 | case kCondLE: |
| 3965 | if (gt_bias) { |
| 3966 | __ CmpLeD(dst, lhs, rhs); |
| 3967 | } else { |
| 3968 | __ CmpUleD(dst, lhs, rhs); |
| 3969 | } |
| 3970 | return false; |
| 3971 | case kCondGT: |
| 3972 | if (gt_bias) { |
| 3973 | __ CmpUltD(dst, rhs, lhs); |
| 3974 | } else { |
| 3975 | __ CmpLtD(dst, rhs, lhs); |
| 3976 | } |
| 3977 | return false; |
| 3978 | case kCondGE: |
| 3979 | if (gt_bias) { |
| 3980 | __ CmpUleD(dst, rhs, lhs); |
| 3981 | } else { |
| 3982 | __ CmpLeD(dst, rhs, lhs); |
| 3983 | } |
| 3984 | return false; |
| 3985 | default: |
| 3986 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3987 | UNREACHABLE(); |
| 3988 | } |
| 3989 | } |
| 3990 | } |
| 3991 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3992 | void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond, |
| 3993 | bool gt_bias, |
| 3994 | Primitive::Type type, |
| 3995 | LocationSummary* locations, |
| 3996 | MipsLabel* label) { |
| 3997 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3998 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3999 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4000 | if (type == Primitive::kPrimFloat) { |
| 4001 | if (isR6) { |
| 4002 | switch (cond) { |
| 4003 | case kCondEQ: |
| 4004 | __ CmpEqS(FTMP, lhs, rhs); |
| 4005 | __ Bc1nez(FTMP, label); |
| 4006 | break; |
| 4007 | case kCondNE: |
| 4008 | __ CmpEqS(FTMP, lhs, rhs); |
| 4009 | __ Bc1eqz(FTMP, label); |
| 4010 | break; |
| 4011 | case kCondLT: |
| 4012 | if (gt_bias) { |
| 4013 | __ CmpLtS(FTMP, lhs, rhs); |
| 4014 | } else { |
| 4015 | __ CmpUltS(FTMP, lhs, rhs); |
| 4016 | } |
| 4017 | __ Bc1nez(FTMP, label); |
| 4018 | break; |
| 4019 | case kCondLE: |
| 4020 | if (gt_bias) { |
| 4021 | __ CmpLeS(FTMP, lhs, rhs); |
| 4022 | } else { |
| 4023 | __ CmpUleS(FTMP, lhs, rhs); |
| 4024 | } |
| 4025 | __ Bc1nez(FTMP, label); |
| 4026 | break; |
| 4027 | case kCondGT: |
| 4028 | if (gt_bias) { |
| 4029 | __ CmpUltS(FTMP, rhs, lhs); |
| 4030 | } else { |
| 4031 | __ CmpLtS(FTMP, rhs, lhs); |
| 4032 | } |
| 4033 | __ Bc1nez(FTMP, label); |
| 4034 | break; |
| 4035 | case kCondGE: |
| 4036 | if (gt_bias) { |
| 4037 | __ CmpUleS(FTMP, rhs, lhs); |
| 4038 | } else { |
| 4039 | __ CmpLeS(FTMP, rhs, lhs); |
| 4040 | } |
| 4041 | __ Bc1nez(FTMP, label); |
| 4042 | break; |
| 4043 | default: |
| 4044 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4045 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4046 | } |
| 4047 | } else { |
| 4048 | switch (cond) { |
| 4049 | case kCondEQ: |
| 4050 | __ CeqS(0, lhs, rhs); |
| 4051 | __ Bc1t(0, label); |
| 4052 | break; |
| 4053 | case kCondNE: |
| 4054 | __ CeqS(0, lhs, rhs); |
| 4055 | __ Bc1f(0, label); |
| 4056 | break; |
| 4057 | case kCondLT: |
| 4058 | if (gt_bias) { |
| 4059 | __ ColtS(0, lhs, rhs); |
| 4060 | } else { |
| 4061 | __ CultS(0, lhs, rhs); |
| 4062 | } |
| 4063 | __ Bc1t(0, label); |
| 4064 | break; |
| 4065 | case kCondLE: |
| 4066 | if (gt_bias) { |
| 4067 | __ ColeS(0, lhs, rhs); |
| 4068 | } else { |
| 4069 | __ CuleS(0, lhs, rhs); |
| 4070 | } |
| 4071 | __ Bc1t(0, label); |
| 4072 | break; |
| 4073 | case kCondGT: |
| 4074 | if (gt_bias) { |
| 4075 | __ CultS(0, rhs, lhs); |
| 4076 | } else { |
| 4077 | __ ColtS(0, rhs, lhs); |
| 4078 | } |
| 4079 | __ Bc1t(0, label); |
| 4080 | break; |
| 4081 | case kCondGE: |
| 4082 | if (gt_bias) { |
| 4083 | __ CuleS(0, rhs, lhs); |
| 4084 | } else { |
| 4085 | __ ColeS(0, rhs, lhs); |
| 4086 | } |
| 4087 | __ Bc1t(0, label); |
| 4088 | break; |
| 4089 | default: |
| 4090 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4091 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4092 | } |
| 4093 | } |
| 4094 | } else { |
| 4095 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 4096 | if (isR6) { |
| 4097 | switch (cond) { |
| 4098 | case kCondEQ: |
| 4099 | __ CmpEqD(FTMP, lhs, rhs); |
| 4100 | __ Bc1nez(FTMP, label); |
| 4101 | break; |
| 4102 | case kCondNE: |
| 4103 | __ CmpEqD(FTMP, lhs, rhs); |
| 4104 | __ Bc1eqz(FTMP, label); |
| 4105 | break; |
| 4106 | case kCondLT: |
| 4107 | if (gt_bias) { |
| 4108 | __ CmpLtD(FTMP, lhs, rhs); |
| 4109 | } else { |
| 4110 | __ CmpUltD(FTMP, lhs, rhs); |
| 4111 | } |
| 4112 | __ Bc1nez(FTMP, label); |
| 4113 | break; |
| 4114 | case kCondLE: |
| 4115 | if (gt_bias) { |
| 4116 | __ CmpLeD(FTMP, lhs, rhs); |
| 4117 | } else { |
| 4118 | __ CmpUleD(FTMP, lhs, rhs); |
| 4119 | } |
| 4120 | __ Bc1nez(FTMP, label); |
| 4121 | break; |
| 4122 | case kCondGT: |
| 4123 | if (gt_bias) { |
| 4124 | __ CmpUltD(FTMP, rhs, lhs); |
| 4125 | } else { |
| 4126 | __ CmpLtD(FTMP, rhs, lhs); |
| 4127 | } |
| 4128 | __ Bc1nez(FTMP, label); |
| 4129 | break; |
| 4130 | case kCondGE: |
| 4131 | if (gt_bias) { |
| 4132 | __ CmpUleD(FTMP, rhs, lhs); |
| 4133 | } else { |
| 4134 | __ CmpLeD(FTMP, rhs, lhs); |
| 4135 | } |
| 4136 | __ Bc1nez(FTMP, label); |
| 4137 | break; |
| 4138 | default: |
| 4139 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4140 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4141 | } |
| 4142 | } else { |
| 4143 | switch (cond) { |
| 4144 | case kCondEQ: |
| 4145 | __ CeqD(0, lhs, rhs); |
| 4146 | __ Bc1t(0, label); |
| 4147 | break; |
| 4148 | case kCondNE: |
| 4149 | __ CeqD(0, lhs, rhs); |
| 4150 | __ Bc1f(0, label); |
| 4151 | break; |
| 4152 | case kCondLT: |
| 4153 | if (gt_bias) { |
| 4154 | __ ColtD(0, lhs, rhs); |
| 4155 | } else { |
| 4156 | __ CultD(0, lhs, rhs); |
| 4157 | } |
| 4158 | __ Bc1t(0, label); |
| 4159 | break; |
| 4160 | case kCondLE: |
| 4161 | if (gt_bias) { |
| 4162 | __ ColeD(0, lhs, rhs); |
| 4163 | } else { |
| 4164 | __ CuleD(0, lhs, rhs); |
| 4165 | } |
| 4166 | __ Bc1t(0, label); |
| 4167 | break; |
| 4168 | case kCondGT: |
| 4169 | if (gt_bias) { |
| 4170 | __ CultD(0, rhs, lhs); |
| 4171 | } else { |
| 4172 | __ ColtD(0, rhs, lhs); |
| 4173 | } |
| 4174 | __ Bc1t(0, label); |
| 4175 | break; |
| 4176 | case kCondGE: |
| 4177 | if (gt_bias) { |
| 4178 | __ CuleD(0, rhs, lhs); |
| 4179 | } else { |
| 4180 | __ ColeD(0, rhs, lhs); |
| 4181 | } |
| 4182 | __ Bc1t(0, label); |
| 4183 | break; |
| 4184 | default: |
| 4185 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4186 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4187 | } |
| 4188 | } |
| 4189 | } |
| 4190 | } |
| 4191 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4192 | void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4193 | size_t condition_input_index, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4194 | MipsLabel* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4195 | MipsLabel* false_target) { |
| 4196 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4197 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4198 | if (true_target == nullptr && false_target == nullptr) { |
| 4199 | // Nothing to do. The code always falls through. |
| 4200 | return; |
| 4201 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 4202 | // Constant condition, statically compared against "true" (integer value 1). |
| 4203 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4204 | if (true_target != nullptr) { |
| 4205 | __ B(true_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4206 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4207 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 4208 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4209 | if (false_target != nullptr) { |
| 4210 | __ B(false_target); |
| 4211 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4212 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4213 | return; |
| 4214 | } |
| 4215 | |
| 4216 | // The following code generates these patterns: |
| 4217 | // (1) true_target == nullptr && false_target != nullptr |
| 4218 | // - opposite condition true => branch to false_target |
| 4219 | // (2) true_target != nullptr && false_target == nullptr |
| 4220 | // - condition true => branch to true_target |
| 4221 | // (3) true_target != nullptr && false_target != nullptr |
| 4222 | // - condition true => branch to true_target |
| 4223 | // - branch to false_target |
| 4224 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4225 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4226 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4227 | DCHECK(cond_val.IsRegister()); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4228 | if (true_target == nullptr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4229 | __ Beqz(cond_val.AsRegister<Register>(), false_target); |
| 4230 | } else { |
| 4231 | __ Bnez(cond_val.AsRegister<Register>(), true_target); |
| 4232 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4233 | } else { |
| 4234 | // The condition instruction has not been materialized, use its inputs as |
| 4235 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4236 | HCondition* condition = cond->AsCondition(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4237 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 4238 | LocationSummary* locations = cond->GetLocations(); |
| 4239 | IfCondition if_cond = condition->GetCondition(); |
| 4240 | MipsLabel* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4241 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4242 | if (true_target == nullptr) { |
| 4243 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4244 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4245 | } |
| 4246 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4247 | switch (type) { |
| 4248 | default: |
| 4249 | GenerateIntCompareAndBranch(if_cond, locations, branch_target); |
| 4250 | break; |
| 4251 | case Primitive::kPrimLong: |
| 4252 | GenerateLongCompareAndBranch(if_cond, locations, branch_target); |
| 4253 | break; |
| 4254 | case Primitive::kPrimFloat: |
| 4255 | case Primitive::kPrimDouble: |
| 4256 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 4257 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4258 | } |
| 4259 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4260 | |
| 4261 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 4262 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 4263 | if (true_target != nullptr && false_target != nullptr) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4264 | __ B(false_target); |
| 4265 | } |
| 4266 | } |
| 4267 | |
| 4268 | void LocationsBuilderMIPS::VisitIf(HIf* if_instr) { |
| 4269 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4270 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4271 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4272 | } |
| 4273 | } |
| 4274 | |
| 4275 | void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4276 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 4277 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 4278 | MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 4279 | nullptr : codegen_->GetLabelOf(true_successor); |
| 4280 | MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 4281 | nullptr : codegen_->GetLabelOf(false_successor); |
| 4282 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4283 | } |
| 4284 | |
| 4285 | void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 4286 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 4287 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4288 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4289 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4290 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4291 | } |
| 4292 | } |
| 4293 | |
| 4294 | void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 4295 | SlowPathCodeMIPS* slow_path = |
| 4296 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4297 | GenerateTestAndBranch(deoptimize, |
| 4298 | /* condition_input_index */ 0, |
| 4299 | slow_path->GetEntryLabel(), |
| 4300 | /* false_target */ nullptr); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4301 | } |
| 4302 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4303 | // This function returns true if a conditional move can be generated for HSelect. |
| 4304 | // Otherwise it returns false and HSelect must be implemented in terms of conditonal |
| 4305 | // branches and regular moves. |
| 4306 | // |
| 4307 | // If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect. |
| 4308 | // |
| 4309 | // While determining feasibility of a conditional move and setting inputs/outputs |
| 4310 | // are two distinct tasks, this function does both because they share quite a bit |
| 4311 | // of common logic. |
| 4312 | static bool CanMoveConditionally(HSelect* select, bool is_r6, LocationSummary* locations_to_set) { |
| 4313 | bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition()); |
| 4314 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4315 | HCondition* condition = cond->AsCondition(); |
| 4316 | |
| 4317 | Primitive::Type cond_type = materialized ? Primitive::kPrimInt : condition->InputAt(0)->GetType(); |
| 4318 | Primitive::Type dst_type = select->GetType(); |
| 4319 | |
| 4320 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 4321 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 4322 | bool is_true_value_zero_constant = |
| 4323 | (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern()); |
| 4324 | bool is_false_value_zero_constant = |
| 4325 | (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern()); |
| 4326 | |
| 4327 | bool can_move_conditionally = false; |
| 4328 | bool use_const_for_false_in = false; |
| 4329 | bool use_const_for_true_in = false; |
| 4330 | |
| 4331 | if (!cond->IsConstant()) { |
| 4332 | switch (cond_type) { |
| 4333 | default: |
| 4334 | switch (dst_type) { |
| 4335 | default: |
| 4336 | // Moving int on int condition. |
| 4337 | if (is_r6) { |
| 4338 | if (is_true_value_zero_constant) { |
| 4339 | // seleqz out_reg, false_reg, cond_reg |
| 4340 | can_move_conditionally = true; |
| 4341 | use_const_for_true_in = true; |
| 4342 | } else if (is_false_value_zero_constant) { |
| 4343 | // selnez out_reg, true_reg, cond_reg |
| 4344 | can_move_conditionally = true; |
| 4345 | use_const_for_false_in = true; |
| 4346 | } else if (materialized) { |
| 4347 | // Not materializing unmaterialized int conditions |
| 4348 | // to keep the instruction count low. |
| 4349 | // selnez AT, true_reg, cond_reg |
| 4350 | // seleqz TMP, false_reg, cond_reg |
| 4351 | // or out_reg, AT, TMP |
| 4352 | can_move_conditionally = true; |
| 4353 | } |
| 4354 | } else { |
| 4355 | // movn out_reg, true_reg/ZERO, cond_reg |
| 4356 | can_move_conditionally = true; |
| 4357 | use_const_for_true_in = is_true_value_zero_constant; |
| 4358 | } |
| 4359 | break; |
| 4360 | case Primitive::kPrimLong: |
| 4361 | // Moving long on int condition. |
| 4362 | if (is_r6) { |
| 4363 | if (is_true_value_zero_constant) { |
| 4364 | // seleqz out_reg_lo, false_reg_lo, cond_reg |
| 4365 | // seleqz out_reg_hi, false_reg_hi, cond_reg |
| 4366 | can_move_conditionally = true; |
| 4367 | use_const_for_true_in = true; |
| 4368 | } else if (is_false_value_zero_constant) { |
| 4369 | // selnez out_reg_lo, true_reg_lo, cond_reg |
| 4370 | // selnez out_reg_hi, true_reg_hi, cond_reg |
| 4371 | can_move_conditionally = true; |
| 4372 | use_const_for_false_in = true; |
| 4373 | } |
| 4374 | // Other long conditional moves would generate 6+ instructions, |
| 4375 | // which is too many. |
| 4376 | } else { |
| 4377 | // movn out_reg_lo, true_reg_lo/ZERO, cond_reg |
| 4378 | // movn out_reg_hi, true_reg_hi/ZERO, cond_reg |
| 4379 | can_move_conditionally = true; |
| 4380 | use_const_for_true_in = is_true_value_zero_constant; |
| 4381 | } |
| 4382 | break; |
| 4383 | case Primitive::kPrimFloat: |
| 4384 | case Primitive::kPrimDouble: |
| 4385 | // Moving float/double on int condition. |
| 4386 | if (is_r6) { |
| 4387 | if (materialized) { |
| 4388 | // Not materializing unmaterialized int conditions |
| 4389 | // to keep the instruction count low. |
| 4390 | can_move_conditionally = true; |
| 4391 | if (is_true_value_zero_constant) { |
| 4392 | // sltu TMP, ZERO, cond_reg |
| 4393 | // mtc1 TMP, temp_cond_reg |
| 4394 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 4395 | use_const_for_true_in = true; |
| 4396 | } else if (is_false_value_zero_constant) { |
| 4397 | // sltu TMP, ZERO, cond_reg |
| 4398 | // mtc1 TMP, temp_cond_reg |
| 4399 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 4400 | use_const_for_false_in = true; |
| 4401 | } else { |
| 4402 | // sltu TMP, ZERO, cond_reg |
| 4403 | // mtc1 TMP, temp_cond_reg |
| 4404 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 4405 | // mov.fmt out_reg, temp_cond_reg |
| 4406 | } |
| 4407 | } |
| 4408 | } else { |
| 4409 | // movn.fmt out_reg, true_reg, cond_reg |
| 4410 | can_move_conditionally = true; |
| 4411 | } |
| 4412 | break; |
| 4413 | } |
| 4414 | break; |
| 4415 | case Primitive::kPrimLong: |
| 4416 | // We don't materialize long comparison now |
| 4417 | // and use conditional branches instead. |
| 4418 | break; |
| 4419 | case Primitive::kPrimFloat: |
| 4420 | case Primitive::kPrimDouble: |
| 4421 | switch (dst_type) { |
| 4422 | default: |
| 4423 | // Moving int on float/double condition. |
| 4424 | if (is_r6) { |
| 4425 | if (is_true_value_zero_constant) { |
| 4426 | // mfc1 TMP, temp_cond_reg |
| 4427 | // seleqz out_reg, false_reg, TMP |
| 4428 | can_move_conditionally = true; |
| 4429 | use_const_for_true_in = true; |
| 4430 | } else if (is_false_value_zero_constant) { |
| 4431 | // mfc1 TMP, temp_cond_reg |
| 4432 | // selnez out_reg, true_reg, TMP |
| 4433 | can_move_conditionally = true; |
| 4434 | use_const_for_false_in = true; |
| 4435 | } else { |
| 4436 | // mfc1 TMP, temp_cond_reg |
| 4437 | // selnez AT, true_reg, TMP |
| 4438 | // seleqz TMP, false_reg, TMP |
| 4439 | // or out_reg, AT, TMP |
| 4440 | can_move_conditionally = true; |
| 4441 | } |
| 4442 | } else { |
| 4443 | // movt out_reg, true_reg/ZERO, cc |
| 4444 | can_move_conditionally = true; |
| 4445 | use_const_for_true_in = is_true_value_zero_constant; |
| 4446 | } |
| 4447 | break; |
| 4448 | case Primitive::kPrimLong: |
| 4449 | // Moving long on float/double condition. |
| 4450 | if (is_r6) { |
| 4451 | if (is_true_value_zero_constant) { |
| 4452 | // mfc1 TMP, temp_cond_reg |
| 4453 | // seleqz out_reg_lo, false_reg_lo, TMP |
| 4454 | // seleqz out_reg_hi, false_reg_hi, TMP |
| 4455 | can_move_conditionally = true; |
| 4456 | use_const_for_true_in = true; |
| 4457 | } else if (is_false_value_zero_constant) { |
| 4458 | // mfc1 TMP, temp_cond_reg |
| 4459 | // selnez out_reg_lo, true_reg_lo, TMP |
| 4460 | // selnez out_reg_hi, true_reg_hi, TMP |
| 4461 | can_move_conditionally = true; |
| 4462 | use_const_for_false_in = true; |
| 4463 | } |
| 4464 | // Other long conditional moves would generate 6+ instructions, |
| 4465 | // which is too many. |
| 4466 | } else { |
| 4467 | // movt out_reg_lo, true_reg_lo/ZERO, cc |
| 4468 | // movt out_reg_hi, true_reg_hi/ZERO, cc |
| 4469 | can_move_conditionally = true; |
| 4470 | use_const_for_true_in = is_true_value_zero_constant; |
| 4471 | } |
| 4472 | break; |
| 4473 | case Primitive::kPrimFloat: |
| 4474 | case Primitive::kPrimDouble: |
| 4475 | // Moving float/double on float/double condition. |
| 4476 | if (is_r6) { |
| 4477 | can_move_conditionally = true; |
| 4478 | if (is_true_value_zero_constant) { |
| 4479 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 4480 | use_const_for_true_in = true; |
| 4481 | } else if (is_false_value_zero_constant) { |
| 4482 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 4483 | use_const_for_false_in = true; |
| 4484 | } else { |
| 4485 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 4486 | // mov.fmt out_reg, temp_cond_reg |
| 4487 | } |
| 4488 | } else { |
| 4489 | // movt.fmt out_reg, true_reg, cc |
| 4490 | can_move_conditionally = true; |
| 4491 | } |
| 4492 | break; |
| 4493 | } |
| 4494 | break; |
| 4495 | } |
| 4496 | } |
| 4497 | |
| 4498 | if (can_move_conditionally) { |
| 4499 | DCHECK(!use_const_for_false_in || !use_const_for_true_in); |
| 4500 | } else { |
| 4501 | DCHECK(!use_const_for_false_in); |
| 4502 | DCHECK(!use_const_for_true_in); |
| 4503 | } |
| 4504 | |
| 4505 | if (locations_to_set != nullptr) { |
| 4506 | if (use_const_for_false_in) { |
| 4507 | locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value)); |
| 4508 | } else { |
| 4509 | locations_to_set->SetInAt(0, |
| 4510 | Primitive::IsFloatingPointType(dst_type) |
| 4511 | ? Location::RequiresFpuRegister() |
| 4512 | : Location::RequiresRegister()); |
| 4513 | } |
| 4514 | if (use_const_for_true_in) { |
| 4515 | locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value)); |
| 4516 | } else { |
| 4517 | locations_to_set->SetInAt(1, |
| 4518 | Primitive::IsFloatingPointType(dst_type) |
| 4519 | ? Location::RequiresFpuRegister() |
| 4520 | : Location::RequiresRegister()); |
| 4521 | } |
| 4522 | if (materialized) { |
| 4523 | locations_to_set->SetInAt(2, Location::RequiresRegister()); |
| 4524 | } |
| 4525 | // On R6 we don't require the output to be the same as the |
| 4526 | // first input for conditional moves unlike on R2. |
| 4527 | bool is_out_same_as_first_in = !can_move_conditionally || !is_r6; |
| 4528 | if (is_out_same_as_first_in) { |
| 4529 | locations_to_set->SetOut(Location::SameAsFirstInput()); |
| 4530 | } else { |
| 4531 | locations_to_set->SetOut(Primitive::IsFloatingPointType(dst_type) |
| 4532 | ? Location::RequiresFpuRegister() |
| 4533 | : Location::RequiresRegister()); |
| 4534 | } |
| 4535 | } |
| 4536 | |
| 4537 | return can_move_conditionally; |
| 4538 | } |
| 4539 | |
| 4540 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR2(HSelect* select) { |
| 4541 | LocationSummary* locations = select->GetLocations(); |
| 4542 | Location dst = locations->Out(); |
| 4543 | Location src = locations->InAt(1); |
| 4544 | Register src_reg = ZERO; |
| 4545 | Register src_reg_high = ZERO; |
| 4546 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4547 | Register cond_reg = TMP; |
| 4548 | int cond_cc = 0; |
| 4549 | Primitive::Type cond_type = Primitive::kPrimInt; |
| 4550 | bool cond_inverted = false; |
| 4551 | Primitive::Type dst_type = select->GetType(); |
| 4552 | |
| 4553 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 4554 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 4555 | } else { |
| 4556 | HCondition* condition = cond->AsCondition(); |
| 4557 | LocationSummary* cond_locations = cond->GetLocations(); |
| 4558 | IfCondition if_cond = condition->GetCondition(); |
| 4559 | cond_type = condition->InputAt(0)->GetType(); |
| 4560 | switch (cond_type) { |
| 4561 | default: |
| 4562 | DCHECK_NE(cond_type, Primitive::kPrimLong); |
| 4563 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 4564 | break; |
| 4565 | case Primitive::kPrimFloat: |
| 4566 | case Primitive::kPrimDouble: |
| 4567 | cond_inverted = MaterializeFpCompareR2(if_cond, |
| 4568 | condition->IsGtBias(), |
| 4569 | cond_type, |
| 4570 | cond_locations, |
| 4571 | cond_cc); |
| 4572 | break; |
| 4573 | } |
| 4574 | } |
| 4575 | |
| 4576 | DCHECK(dst.Equals(locations->InAt(0))); |
| 4577 | if (src.IsRegister()) { |
| 4578 | src_reg = src.AsRegister<Register>(); |
| 4579 | } else if (src.IsRegisterPair()) { |
| 4580 | src_reg = src.AsRegisterPairLow<Register>(); |
| 4581 | src_reg_high = src.AsRegisterPairHigh<Register>(); |
| 4582 | } else if (src.IsConstant()) { |
| 4583 | DCHECK(src.GetConstant()->IsZeroBitPattern()); |
| 4584 | } |
| 4585 | |
| 4586 | switch (cond_type) { |
| 4587 | default: |
| 4588 | switch (dst_type) { |
| 4589 | default: |
| 4590 | if (cond_inverted) { |
| 4591 | __ Movz(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 4592 | } else { |
| 4593 | __ Movn(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 4594 | } |
| 4595 | break; |
| 4596 | case Primitive::kPrimLong: |
| 4597 | if (cond_inverted) { |
| 4598 | __ Movz(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 4599 | __ Movz(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 4600 | } else { |
| 4601 | __ Movn(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 4602 | __ Movn(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 4603 | } |
| 4604 | break; |
| 4605 | case Primitive::kPrimFloat: |
| 4606 | if (cond_inverted) { |
| 4607 | __ MovzS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 4608 | } else { |
| 4609 | __ MovnS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 4610 | } |
| 4611 | break; |
| 4612 | case Primitive::kPrimDouble: |
| 4613 | if (cond_inverted) { |
| 4614 | __ MovzD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 4615 | } else { |
| 4616 | __ MovnD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 4617 | } |
| 4618 | break; |
| 4619 | } |
| 4620 | break; |
| 4621 | case Primitive::kPrimLong: |
| 4622 | LOG(FATAL) << "Unreachable"; |
| 4623 | UNREACHABLE(); |
| 4624 | case Primitive::kPrimFloat: |
| 4625 | case Primitive::kPrimDouble: |
| 4626 | switch (dst_type) { |
| 4627 | default: |
| 4628 | if (cond_inverted) { |
| 4629 | __ Movf(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 4630 | } else { |
| 4631 | __ Movt(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 4632 | } |
| 4633 | break; |
| 4634 | case Primitive::kPrimLong: |
| 4635 | if (cond_inverted) { |
| 4636 | __ Movf(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 4637 | __ Movf(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 4638 | } else { |
| 4639 | __ Movt(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 4640 | __ Movt(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 4641 | } |
| 4642 | break; |
| 4643 | case Primitive::kPrimFloat: |
| 4644 | if (cond_inverted) { |
| 4645 | __ MovfS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 4646 | } else { |
| 4647 | __ MovtS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 4648 | } |
| 4649 | break; |
| 4650 | case Primitive::kPrimDouble: |
| 4651 | if (cond_inverted) { |
| 4652 | __ MovfD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 4653 | } else { |
| 4654 | __ MovtD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 4655 | } |
| 4656 | break; |
| 4657 | } |
| 4658 | break; |
| 4659 | } |
| 4660 | } |
| 4661 | |
| 4662 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR6(HSelect* select) { |
| 4663 | LocationSummary* locations = select->GetLocations(); |
| 4664 | Location dst = locations->Out(); |
| 4665 | Location false_src = locations->InAt(0); |
| 4666 | Location true_src = locations->InAt(1); |
| 4667 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4668 | Register cond_reg = TMP; |
| 4669 | FRegister fcond_reg = FTMP; |
| 4670 | Primitive::Type cond_type = Primitive::kPrimInt; |
| 4671 | bool cond_inverted = false; |
| 4672 | Primitive::Type dst_type = select->GetType(); |
| 4673 | |
| 4674 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 4675 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 4676 | } else { |
| 4677 | HCondition* condition = cond->AsCondition(); |
| 4678 | LocationSummary* cond_locations = cond->GetLocations(); |
| 4679 | IfCondition if_cond = condition->GetCondition(); |
| 4680 | cond_type = condition->InputAt(0)->GetType(); |
| 4681 | switch (cond_type) { |
| 4682 | default: |
| 4683 | DCHECK_NE(cond_type, Primitive::kPrimLong); |
| 4684 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 4685 | break; |
| 4686 | case Primitive::kPrimFloat: |
| 4687 | case Primitive::kPrimDouble: |
| 4688 | cond_inverted = MaterializeFpCompareR6(if_cond, |
| 4689 | condition->IsGtBias(), |
| 4690 | cond_type, |
| 4691 | cond_locations, |
| 4692 | fcond_reg); |
| 4693 | break; |
| 4694 | } |
| 4695 | } |
| 4696 | |
| 4697 | if (true_src.IsConstant()) { |
| 4698 | DCHECK(true_src.GetConstant()->IsZeroBitPattern()); |
| 4699 | } |
| 4700 | if (false_src.IsConstant()) { |
| 4701 | DCHECK(false_src.GetConstant()->IsZeroBitPattern()); |
| 4702 | } |
| 4703 | |
| 4704 | switch (dst_type) { |
| 4705 | default: |
| 4706 | if (Primitive::IsFloatingPointType(cond_type)) { |
| 4707 | __ Mfc1(cond_reg, fcond_reg); |
| 4708 | } |
| 4709 | if (true_src.IsConstant()) { |
| 4710 | if (cond_inverted) { |
| 4711 | __ Selnez(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 4712 | } else { |
| 4713 | __ Seleqz(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 4714 | } |
| 4715 | } else if (false_src.IsConstant()) { |
| 4716 | if (cond_inverted) { |
| 4717 | __ Seleqz(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 4718 | } else { |
| 4719 | __ Selnez(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 4720 | } |
| 4721 | } else { |
| 4722 | DCHECK_NE(cond_reg, AT); |
| 4723 | if (cond_inverted) { |
| 4724 | __ Seleqz(AT, true_src.AsRegister<Register>(), cond_reg); |
| 4725 | __ Selnez(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 4726 | } else { |
| 4727 | __ Selnez(AT, true_src.AsRegister<Register>(), cond_reg); |
| 4728 | __ Seleqz(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 4729 | } |
| 4730 | __ Or(dst.AsRegister<Register>(), AT, TMP); |
| 4731 | } |
| 4732 | break; |
| 4733 | case Primitive::kPrimLong: { |
| 4734 | if (Primitive::IsFloatingPointType(cond_type)) { |
| 4735 | __ Mfc1(cond_reg, fcond_reg); |
| 4736 | } |
| 4737 | Register dst_lo = dst.AsRegisterPairLow<Register>(); |
| 4738 | Register dst_hi = dst.AsRegisterPairHigh<Register>(); |
| 4739 | if (true_src.IsConstant()) { |
| 4740 | Register src_lo = false_src.AsRegisterPairLow<Register>(); |
| 4741 | Register src_hi = false_src.AsRegisterPairHigh<Register>(); |
| 4742 | if (cond_inverted) { |
| 4743 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 4744 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 4745 | } else { |
| 4746 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 4747 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 4748 | } |
| 4749 | } else { |
| 4750 | DCHECK(false_src.IsConstant()); |
| 4751 | Register src_lo = true_src.AsRegisterPairLow<Register>(); |
| 4752 | Register src_hi = true_src.AsRegisterPairHigh<Register>(); |
| 4753 | if (cond_inverted) { |
| 4754 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 4755 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 4756 | } else { |
| 4757 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 4758 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 4759 | } |
| 4760 | } |
| 4761 | break; |
| 4762 | } |
| 4763 | case Primitive::kPrimFloat: { |
| 4764 | if (!Primitive::IsFloatingPointType(cond_type)) { |
| 4765 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 4766 | __ Sltu(TMP, ZERO, cond_reg); |
| 4767 | __ Mtc1(TMP, fcond_reg); |
| 4768 | } |
| 4769 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 4770 | if (true_src.IsConstant()) { |
| 4771 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 4772 | if (cond_inverted) { |
| 4773 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 4774 | } else { |
| 4775 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 4776 | } |
| 4777 | } else if (false_src.IsConstant()) { |
| 4778 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 4779 | if (cond_inverted) { |
| 4780 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 4781 | } else { |
| 4782 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 4783 | } |
| 4784 | } else { |
| 4785 | if (cond_inverted) { |
| 4786 | __ SelS(fcond_reg, |
| 4787 | true_src.AsFpuRegister<FRegister>(), |
| 4788 | false_src.AsFpuRegister<FRegister>()); |
| 4789 | } else { |
| 4790 | __ SelS(fcond_reg, |
| 4791 | false_src.AsFpuRegister<FRegister>(), |
| 4792 | true_src.AsFpuRegister<FRegister>()); |
| 4793 | } |
| 4794 | __ MovS(dst_reg, fcond_reg); |
| 4795 | } |
| 4796 | break; |
| 4797 | } |
| 4798 | case Primitive::kPrimDouble: { |
| 4799 | if (!Primitive::IsFloatingPointType(cond_type)) { |
| 4800 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 4801 | __ Sltu(TMP, ZERO, cond_reg); |
| 4802 | __ Mtc1(TMP, fcond_reg); |
| 4803 | } |
| 4804 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 4805 | if (true_src.IsConstant()) { |
| 4806 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 4807 | if (cond_inverted) { |
| 4808 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 4809 | } else { |
| 4810 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 4811 | } |
| 4812 | } else if (false_src.IsConstant()) { |
| 4813 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 4814 | if (cond_inverted) { |
| 4815 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 4816 | } else { |
| 4817 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 4818 | } |
| 4819 | } else { |
| 4820 | if (cond_inverted) { |
| 4821 | __ SelD(fcond_reg, |
| 4822 | true_src.AsFpuRegister<FRegister>(), |
| 4823 | false_src.AsFpuRegister<FRegister>()); |
| 4824 | } else { |
| 4825 | __ SelD(fcond_reg, |
| 4826 | false_src.AsFpuRegister<FRegister>(), |
| 4827 | true_src.AsFpuRegister<FRegister>()); |
| 4828 | } |
| 4829 | __ MovD(dst_reg, fcond_reg); |
| 4830 | } |
| 4831 | break; |
| 4832 | } |
| 4833 | } |
| 4834 | } |
| 4835 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 4836 | void LocationsBuilderMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 4837 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 4838 | LocationSummary(flag, LocationSummary::kNoCall); |
| 4839 | locations->SetOut(Location::RequiresRegister()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 4840 | } |
| 4841 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 4842 | void InstructionCodeGeneratorMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 4843 | __ LoadFromOffset(kLoadWord, |
| 4844 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 4845 | SP, |
| 4846 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 4847 | } |
| 4848 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4849 | void LocationsBuilderMIPS::VisitSelect(HSelect* select) { |
| 4850 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4851 | CanMoveConditionally(select, codegen_->GetInstructionSetFeatures().IsR6(), locations); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4852 | } |
| 4853 | |
| 4854 | void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4855 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4856 | if (CanMoveConditionally(select, is_r6, /* locations_to_set */ nullptr)) { |
| 4857 | if (is_r6) { |
| 4858 | GenConditionalMoveR6(select); |
| 4859 | } else { |
| 4860 | GenConditionalMoveR2(select); |
| 4861 | } |
| 4862 | } else { |
| 4863 | LocationSummary* locations = select->GetLocations(); |
| 4864 | MipsLabel false_target; |
| 4865 | GenerateTestAndBranch(select, |
| 4866 | /* condition_input_index */ 2, |
| 4867 | /* true_target */ nullptr, |
| 4868 | &false_target); |
| 4869 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 4870 | __ Bind(&false_target); |
| 4871 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4872 | } |
| 4873 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4874 | void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 4875 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 4876 | } |
| 4877 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 4878 | void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 4879 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 4880 | } |
| 4881 | |
| 4882 | void CodeGeneratorMIPS::GenerateNop() { |
| 4883 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4884 | } |
| 4885 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4886 | void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4887 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4888 | bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble); |
| 4889 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
| 4890 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4891 | instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4892 | |
| 4893 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4894 | if (generate_volatile) { |
| 4895 | InvokeRuntimeCallingConvention calling_convention; |
| 4896 | // need A0 to hold base + offset |
| 4897 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4898 | if (field_type == Primitive::kPrimLong) { |
| 4899 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimLong)); |
| 4900 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4901 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 4902 | locations->SetOut(Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4903 | // Need some temp core regs since FP results are returned in core registers |
| 4904 | Location reg = calling_convention.GetReturnLocation(Primitive::kPrimLong); |
| 4905 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>())); |
| 4906 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>())); |
| 4907 | } |
| 4908 | } else { |
| 4909 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4910 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4911 | } else { |
| 4912 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4913 | } |
| 4914 | } |
| 4915 | } |
| 4916 | |
| 4917 | void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction, |
| 4918 | const FieldInfo& field_info, |
| 4919 | uint32_t dex_pc) { |
| 4920 | Primitive::Type type = field_info.GetFieldType(); |
| 4921 | LocationSummary* locations = instruction->GetLocations(); |
| 4922 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4923 | LoadOperandType load_type = kLoadUnsignedByte; |
| 4924 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 4925 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 4926 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4927 | |
| 4928 | switch (type) { |
| 4929 | case Primitive::kPrimBoolean: |
| 4930 | load_type = kLoadUnsignedByte; |
| 4931 | break; |
| 4932 | case Primitive::kPrimByte: |
| 4933 | load_type = kLoadSignedByte; |
| 4934 | break; |
| 4935 | case Primitive::kPrimShort: |
| 4936 | load_type = kLoadSignedHalfword; |
| 4937 | break; |
| 4938 | case Primitive::kPrimChar: |
| 4939 | load_type = kLoadUnsignedHalfword; |
| 4940 | break; |
| 4941 | case Primitive::kPrimInt: |
| 4942 | case Primitive::kPrimFloat: |
| 4943 | case Primitive::kPrimNot: |
| 4944 | load_type = kLoadWord; |
| 4945 | break; |
| 4946 | case Primitive::kPrimLong: |
| 4947 | case Primitive::kPrimDouble: |
| 4948 | load_type = kLoadDoubleword; |
| 4949 | break; |
| 4950 | case Primitive::kPrimVoid: |
| 4951 | LOG(FATAL) << "Unreachable type " << type; |
| 4952 | UNREACHABLE(); |
| 4953 | } |
| 4954 | |
| 4955 | if (is_volatile && load_type == kLoadDoubleword) { |
| 4956 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 4957 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4958 | // Do implicit Null check |
| 4959 | __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0); |
| 4960 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 4961 | codegen_->InvokeRuntime(kQuickA64Load, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4962 | CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>(); |
| 4963 | if (type == Primitive::kPrimDouble) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4964 | // FP results are returned in core registers. Need to move them. |
| 4965 | Location out = locations->Out(); |
| 4966 | if (out.IsFpuRegister()) { |
| 4967 | __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), out.AsFpuRegister<FRegister>()); |
| 4968 | __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
| 4969 | out.AsFpuRegister<FRegister>()); |
| 4970 | } else { |
| 4971 | DCHECK(out.IsDoubleStackSlot()); |
| 4972 | __ StoreToOffset(kStoreWord, |
| 4973 | locations->GetTemp(1).AsRegister<Register>(), |
| 4974 | SP, |
| 4975 | out.GetStackIndex()); |
| 4976 | __ StoreToOffset(kStoreWord, |
| 4977 | locations->GetTemp(2).AsRegister<Register>(), |
| 4978 | SP, |
| 4979 | out.GetStackIndex() + 4); |
| 4980 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4981 | } |
| 4982 | } else { |
| 4983 | if (!Primitive::IsFloatingPointType(type)) { |
| 4984 | Register dst; |
| 4985 | if (type == Primitive::kPrimLong) { |
| 4986 | DCHECK(locations->Out().IsRegisterPair()); |
| 4987 | dst = locations->Out().AsRegisterPairLow<Register>(); |
| 4988 | } else { |
| 4989 | DCHECK(locations->Out().IsRegister()); |
| 4990 | dst = locations->Out().AsRegister<Register>(); |
| 4991 | } |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4992 | __ LoadFromOffset(load_type, dst, obj, offset, null_checker); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 4993 | if (type == Primitive::kPrimNot) { |
| 4994 | __ MaybeUnpoisonHeapReference(dst); |
| 4995 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4996 | } else { |
| 4997 | DCHECK(locations->Out().IsFpuRegister()); |
| 4998 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 4999 | if (type == Primitive::kPrimFloat) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 5000 | __ LoadSFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5001 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 5002 | __ LoadDFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5003 | } |
| 5004 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5005 | } |
| 5006 | |
| 5007 | if (is_volatile) { |
| 5008 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5009 | } |
| 5010 | } |
| 5011 | |
| 5012 | void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5013 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5014 | bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble); |
| 5015 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
| 5016 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5017 | instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5018 | |
| 5019 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5020 | if (generate_volatile) { |
| 5021 | InvokeRuntimeCallingConvention calling_convention; |
| 5022 | // need A0 to hold base + offset |
| 5023 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5024 | if (field_type == Primitive::kPrimLong) { |
| 5025 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 5026 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 5027 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 5028 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 5029 | locations->SetInAt(1, Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5030 | // Pass FP parameters in core registers. |
| 5031 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 5032 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3))); |
| 5033 | } |
| 5034 | } else { |
| 5035 | if (Primitive::IsFloatingPointType(field_type)) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 5036 | locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5037 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 5038 | locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5039 | } |
| 5040 | } |
| 5041 | } |
| 5042 | |
| 5043 | void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction, |
| 5044 | const FieldInfo& field_info, |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 5045 | uint32_t dex_pc, |
| 5046 | bool value_can_be_null) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5047 | Primitive::Type type = field_info.GetFieldType(); |
| 5048 | LocationSummary* locations = instruction->GetLocations(); |
| 5049 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 5050 | Location value_location = locations->InAt(1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5051 | StoreOperandType store_type = kStoreByte; |
| 5052 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 5053 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5054 | bool needs_write_barrier = CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1)); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 5055 | auto null_checker = GetImplicitNullChecker(instruction, codegen_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5056 | |
| 5057 | switch (type) { |
| 5058 | case Primitive::kPrimBoolean: |
| 5059 | case Primitive::kPrimByte: |
| 5060 | store_type = kStoreByte; |
| 5061 | break; |
| 5062 | case Primitive::kPrimShort: |
| 5063 | case Primitive::kPrimChar: |
| 5064 | store_type = kStoreHalfword; |
| 5065 | break; |
| 5066 | case Primitive::kPrimInt: |
| 5067 | case Primitive::kPrimFloat: |
| 5068 | case Primitive::kPrimNot: |
| 5069 | store_type = kStoreWord; |
| 5070 | break; |
| 5071 | case Primitive::kPrimLong: |
| 5072 | case Primitive::kPrimDouble: |
| 5073 | store_type = kStoreDoubleword; |
| 5074 | break; |
| 5075 | case Primitive::kPrimVoid: |
| 5076 | LOG(FATAL) << "Unreachable type " << type; |
| 5077 | UNREACHABLE(); |
| 5078 | } |
| 5079 | |
| 5080 | if (is_volatile) { |
| 5081 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 5082 | } |
| 5083 | |
| 5084 | if (is_volatile && store_type == kStoreDoubleword) { |
| 5085 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 5086 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5087 | // Do implicit Null check. |
| 5088 | __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0); |
| 5089 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5090 | if (type == Primitive::kPrimDouble) { |
| 5091 | // Pass FP parameters in core registers. |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 5092 | if (value_location.IsFpuRegister()) { |
| 5093 | __ Mfc1(locations->GetTemp(1).AsRegister<Register>(), |
| 5094 | value_location.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 5095 | __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 5096 | value_location.AsFpuRegister<FRegister>()); |
| 5097 | } else if (value_location.IsDoubleStackSlot()) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 5098 | __ LoadFromOffset(kLoadWord, |
| 5099 | locations->GetTemp(1).AsRegister<Register>(), |
| 5100 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 5101 | value_location.GetStackIndex()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 5102 | __ LoadFromOffset(kLoadWord, |
| 5103 | locations->GetTemp(2).AsRegister<Register>(), |
| 5104 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 5105 | value_location.GetStackIndex() + 4); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 5106 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 5107 | DCHECK(value_location.IsConstant()); |
| 5108 | DCHECK(value_location.GetConstant()->IsDoubleConstant()); |
| 5109 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 5110 | __ LoadConst64(locations->GetTemp(2).AsRegister<Register>(), |
| 5111 | locations->GetTemp(1).AsRegister<Register>(), |
| 5112 | value); |
| 5113 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5114 | } |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 5115 | codegen_->InvokeRuntime(kQuickA64Store, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5116 | CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>(); |
| 5117 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 5118 | if (value_location.IsConstant()) { |
| 5119 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 5120 | __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker); |
| 5121 | } else if (!Primitive::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5122 | Register src; |
| 5123 | if (type == Primitive::kPrimLong) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 5124 | src = value_location.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5125 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 5126 | src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5127 | } |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5128 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5129 | // Note that in the case where `value` is a null reference, |
| 5130 | // we do not enter this block, as a null reference does not |
| 5131 | // need poisoning. |
| 5132 | DCHECK_EQ(type, Primitive::kPrimNot); |
| 5133 | __ PoisonHeapReference(TMP, src); |
| 5134 | __ StoreToOffset(store_type, TMP, obj, offset, null_checker); |
| 5135 | } else { |
| 5136 | __ StoreToOffset(store_type, src, obj, offset, null_checker); |
| 5137 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5138 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 5139 | FRegister src = value_location.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5140 | if (type == Primitive::kPrimFloat) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 5141 | __ StoreSToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5142 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 5143 | __ StoreDToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5144 | } |
| 5145 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5146 | } |
| 5147 | |
| 5148 | // TODO: memory barriers? |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5149 | if (needs_write_barrier) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 5150 | Register src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 5151 | codegen_->MarkGCCard(obj, src, value_can_be_null); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5152 | } |
| 5153 | |
| 5154 | if (is_volatile) { |
| 5155 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 5156 | } |
| 5157 | } |
| 5158 | |
| 5159 | void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5160 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5161 | } |
| 5162 | |
| 5163 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5164 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 5165 | } |
| 5166 | |
| 5167 | void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5168 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5169 | } |
| 5170 | |
| 5171 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 5172 | HandleFieldSet(instruction, |
| 5173 | instruction->GetFieldInfo(), |
| 5174 | instruction->GetDexPc(), |
| 5175 | instruction->GetValueCanBeNull()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5176 | } |
| 5177 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5178 | void InstructionCodeGeneratorMIPS::GenerateGcRootFieldLoad( |
| 5179 | HInstruction* instruction ATTRIBUTE_UNUSED, |
| 5180 | Location root, |
| 5181 | Register obj, |
| 5182 | uint32_t offset) { |
| 5183 | Register root_reg = root.AsRegister<Register>(); |
| 5184 | if (kEmitCompilerReadBarrier) { |
| 5185 | UNIMPLEMENTED(FATAL) << "for read barrier"; |
| 5186 | } else { |
| 5187 | // Plain GC root load with no read barrier. |
| 5188 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5189 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 5190 | // Note that GC roots are not affected by heap poisoning, thus we |
| 5191 | // do not have to unpoison `root_reg` here. |
| 5192 | } |
| 5193 | } |
| 5194 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5195 | void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
| 5196 | LocationSummary::CallKind call_kind = |
| 5197 | instruction->IsExactCheck() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath; |
| 5198 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5199 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5200 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5201 | // The output does overlap inputs. |
| 5202 | // Note that TypeCheckSlowPathMIPS uses this register too. |
| 5203 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5204 | } |
| 5205 | |
| 5206 | void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
| 5207 | LocationSummary* locations = instruction->GetLocations(); |
| 5208 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5209 | Register cls = locations->InAt(1).AsRegister<Register>(); |
| 5210 | Register out = locations->Out().AsRegister<Register>(); |
| 5211 | |
| 5212 | MipsLabel done; |
| 5213 | |
| 5214 | // Return 0 if `obj` is null. |
| 5215 | // TODO: Avoid this check if we know `obj` is not null. |
| 5216 | __ Move(out, ZERO); |
| 5217 | __ Beqz(obj, &done); |
| 5218 | |
| 5219 | // Compare the class of `obj` with `cls`. |
| 5220 | __ LoadFromOffset(kLoadWord, out, obj, mirror::Object::ClassOffset().Int32Value()); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5221 | __ MaybeUnpoisonHeapReference(out); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5222 | if (instruction->IsExactCheck()) { |
| 5223 | // Classes must be equal for the instanceof to succeed. |
| 5224 | __ Xor(out, out, cls); |
| 5225 | __ Sltiu(out, out, 1); |
| 5226 | } else { |
| 5227 | // If the classes are not equal, we go into a slow path. |
| 5228 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5229 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction); |
| 5230 | codegen_->AddSlowPath(slow_path); |
| 5231 | __ Bne(out, cls, slow_path->GetEntryLabel()); |
| 5232 | __ LoadConst32(out, 1); |
| 5233 | __ Bind(slow_path->GetExitLabel()); |
| 5234 | } |
| 5235 | |
| 5236 | __ Bind(&done); |
| 5237 | } |
| 5238 | |
| 5239 | void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) { |
| 5240 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5241 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5242 | } |
| 5243 | |
| 5244 | void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 5245 | // Will be generated at use site. |
| 5246 | } |
| 5247 | |
| 5248 | void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) { |
| 5249 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5250 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5251 | } |
| 5252 | |
| 5253 | void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 5254 | // Will be generated at use site. |
| 5255 | } |
| 5256 | |
| 5257 | void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) { |
| 5258 | InvokeDexCallingConventionVisitorMIPS calling_convention_visitor; |
| 5259 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 5260 | } |
| 5261 | |
| 5262 | void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 5263 | HandleInvoke(invoke); |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 5264 | // 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] | 5265 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 5266 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T7)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5267 | } |
| 5268 | |
| 5269 | void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 5270 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 5271 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5272 | Location receiver = invoke->GetLocations()->InAt(0); |
| 5273 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5274 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5275 | |
| 5276 | // Set the hidden argument. |
| 5277 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(), |
| 5278 | invoke->GetDexMethodIndex()); |
| 5279 | |
| 5280 | // temp = object->GetClass(); |
| 5281 | if (receiver.IsStackSlot()) { |
| 5282 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 5283 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 5284 | } else { |
| 5285 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
| 5286 | } |
| 5287 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5288 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 5289 | // emit a read barrier for the previous class reference load. |
| 5290 | // However this is not required in practice, as this is an |
| 5291 | // intermediate/temporary reference and because the current |
| 5292 | // concurrent copying collector keeps the from-space memory |
| 5293 | // intact/accessible until the end of the marking phase (the |
| 5294 | // concurrent copying collector may not in the future). |
| 5295 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 5296 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 5297 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
| 5298 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 5299 | invoke->GetImtIndex(), kMipsPointerSize)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5300 | // temp = temp->GetImtEntryAt(method_offset); |
| 5301 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 5302 | // T9 = temp->GetEntryPoint(); |
| 5303 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 5304 | // T9(); |
| 5305 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 5306 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5307 | DCHECK(!codegen_->IsLeafMethod()); |
| 5308 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 5309 | } |
| 5310 | |
| 5311 | void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 5312 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 5313 | if (intrinsic.TryDispatch(invoke)) { |
| 5314 | return; |
| 5315 | } |
| 5316 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5317 | HandleInvoke(invoke); |
| 5318 | } |
| 5319 | |
| 5320 | void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5321 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5322 | // art::PrepareForRegisterAllocation. |
| 5323 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5324 | |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 5325 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 5326 | bool has_extra_input = invoke->HasPcRelativeDexCache() && !is_r6; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5327 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 5328 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 5329 | if (intrinsic.TryDispatch(invoke)) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5330 | if (invoke->GetLocations()->CanCall() && has_extra_input) { |
| 5331 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 5332 | } |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 5333 | return; |
| 5334 | } |
| 5335 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5336 | HandleInvoke(invoke); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5337 | |
| 5338 | // Add the extra input register if either the dex cache array base register |
| 5339 | // or the PC-relative base register for accessing literals is needed. |
| 5340 | if (has_extra_input) { |
| 5341 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 5342 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5343 | } |
| 5344 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 5345 | void LocationsBuilderMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 5346 | HandleInvoke(invoke); |
| 5347 | } |
| 5348 | |
| 5349 | void InstructionCodeGeneratorMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 5350 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 5351 | } |
| 5352 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 5353 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5354 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 5355 | IntrinsicCodeGeneratorMIPS intrinsic(codegen); |
| 5356 | intrinsic.Dispatch(invoke); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5357 | return true; |
| 5358 | } |
| 5359 | return false; |
| 5360 | } |
| 5361 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5362 | HLoadString::LoadKind CodeGeneratorMIPS::GetSupportedLoadStringKind( |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5363 | HLoadString::LoadKind desired_string_load_kind) { |
| 5364 | if (kEmitCompilerReadBarrier) { |
| 5365 | UNIMPLEMENTED(FATAL) << "for read barrier"; |
| 5366 | } |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 5367 | // 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] | 5368 | // is incompatible with it. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5369 | // TODO: Create as many MipsDexCacheArraysBase instructions as needed for methods |
| 5370 | // with irreducible loops. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5371 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 5372 | bool is_r6 = GetInstructionSetFeatures().IsR6(); |
| 5373 | bool fallback_load = has_irreducible_loops && !is_r6; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5374 | switch (desired_string_load_kind) { |
| 5375 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5376 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5377 | break; |
| 5378 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5379 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5380 | break; |
| 5381 | case HLoadString::LoadKind::kBootImageAddress: |
| 5382 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5383 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5384 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5385 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5386 | case HLoadString::LoadKind::kJitTableAddress: |
| 5387 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 5388 | fallback_load = false; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5389 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5390 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5391 | fallback_load = false; |
| 5392 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5393 | } |
| 5394 | if (fallback_load) { |
| 5395 | desired_string_load_kind = HLoadString::LoadKind::kDexCacheViaMethod; |
| 5396 | } |
| 5397 | return desired_string_load_kind; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5398 | } |
| 5399 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5400 | HLoadClass::LoadKind CodeGeneratorMIPS::GetSupportedLoadClassKind( |
| 5401 | HLoadClass::LoadKind desired_class_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5402 | if (kEmitCompilerReadBarrier) { |
| 5403 | UNIMPLEMENTED(FATAL) << "for read barrier"; |
| 5404 | } |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 5405 | // 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] | 5406 | // is incompatible with it. |
| 5407 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 5408 | bool is_r6 = GetInstructionSetFeatures().IsR6(); |
| 5409 | bool fallback_load = has_irreducible_loops && !is_r6; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5410 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5411 | case HLoadClass::LoadKind::kInvalid: |
| 5412 | LOG(FATAL) << "UNREACHABLE"; |
| 5413 | UNREACHABLE(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5414 | case HLoadClass::LoadKind::kReferrersClass: |
| 5415 | fallback_load = false; |
| 5416 | break; |
| 5417 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5418 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5419 | break; |
| 5420 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5421 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5422 | break; |
| 5423 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5424 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5425 | case HLoadClass::LoadKind::kBssEntry: |
| 5426 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5427 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5428 | case HLoadClass::LoadKind::kJitTableAddress: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5429 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 5430 | fallback_load = false; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5431 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5432 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5433 | fallback_load = false; |
| 5434 | break; |
| 5435 | } |
| 5436 | if (fallback_load) { |
| 5437 | desired_class_load_kind = HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5438 | } |
| 5439 | return desired_class_load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5440 | } |
| 5441 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5442 | Register CodeGeneratorMIPS::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 5443 | Register temp) { |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 5444 | CHECK(!GetInstructionSetFeatures().IsR6()); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5445 | CHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 5446 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 5447 | if (!invoke->GetLocations()->Intrinsified()) { |
| 5448 | return location.AsRegister<Register>(); |
| 5449 | } |
| 5450 | // For intrinsics we allow any location, so it may be on the stack. |
| 5451 | if (!location.IsRegister()) { |
| 5452 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 5453 | return temp; |
| 5454 | } |
| 5455 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 5456 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 5457 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 5458 | // simple and more robust approach rather that trying to determine if that's the case. |
| 5459 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 5460 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 5461 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 5462 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 5463 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 5464 | return temp; |
| 5465 | } |
| 5466 | return location.AsRegister<Register>(); |
| 5467 | } |
| 5468 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5469 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch( |
| 5470 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5471 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5472 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 5473 | // 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] | 5474 | // is incompatible with it. |
| 5475 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 5476 | bool is_r6 = GetInstructionSetFeatures().IsR6(); |
| 5477 | bool fallback_load = has_irreducible_loops && !is_r6; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5478 | switch (dispatch_info.method_load_kind) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5479 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5480 | break; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5481 | default: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5482 | fallback_load = false; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5483 | break; |
| 5484 | } |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5485 | if (fallback_load) { |
| 5486 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 5487 | dispatch_info.method_load_data = 0; |
| 5488 | } |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5489 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5490 | } |
| 5491 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5492 | void CodeGeneratorMIPS::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 5493 | // 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] | 5494 | 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] | 5495 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 5496 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 5497 | bool is_r6 = GetInstructionSetFeatures().IsR6(); |
| 5498 | Register base_reg = (invoke->HasPcRelativeDexCache() && !is_r6) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5499 | ? GetInvokeStaticOrDirectExtraParameter(invoke, temp.AsRegister<Register>()) |
| 5500 | : ZERO; |
| 5501 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5502 | switch (method_load_kind) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5503 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5504 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5505 | uint32_t offset = |
| 5506 | GetThreadOffset<kMipsPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5507 | __ LoadFromOffset(kLoadWord, |
| 5508 | temp.AsRegister<Register>(), |
| 5509 | TR, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5510 | offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5511 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5512 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5513 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 5514 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5515 | break; |
| 5516 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 5517 | __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 5518 | break; |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 5519 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
| 5520 | if (is_r6) { |
| 5521 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 5522 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
| 5523 | NewPcRelativeDexCacheArrayPatch(invoke->GetDexFileForPcRelativeDexCache(), offset); |
| 5524 | bool reordering = __ SetReorder(false); |
| 5525 | EmitPcRelativeAddressPlaceholderHigh(info, TMP, ZERO); |
| 5526 | __ Lw(temp.AsRegister<Register>(), TMP, /* placeholder */ 0x5678); |
| 5527 | __ SetReorder(reordering); |
| 5528 | } else { |
| 5529 | HMipsDexCacheArraysBase* base = |
| 5530 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsMipsDexCacheArraysBase(); |
| 5531 | int32_t offset = |
| 5532 | invoke->GetDexCacheArrayOffset() - base->GetElementOffset() - kDexCacheArrayLwOffset; |
| 5533 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 5534 | } |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5535 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5536 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 5537 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5538 | Register reg = temp.AsRegister<Register>(); |
| 5539 | Register method_reg; |
| 5540 | if (current_method.IsRegister()) { |
| 5541 | method_reg = current_method.AsRegister<Register>(); |
| 5542 | } else { |
| 5543 | // TODO: use the appropriate DCHECK() here if possible. |
| 5544 | // DCHECK(invoke->GetLocations()->Intrinsified()); |
| 5545 | DCHECK(!current_method.IsValid()); |
| 5546 | method_reg = reg; |
| 5547 | __ Lw(reg, SP, kCurrentMethodStackOffset); |
| 5548 | } |
| 5549 | |
| 5550 | // temp = temp->dex_cache_resolved_methods_; |
| 5551 | __ LoadFromOffset(kLoadWord, |
| 5552 | reg, |
| 5553 | method_reg, |
| 5554 | ArtMethod::DexCacheResolvedMethodsOffset(kMipsPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 5555 | // temp = temp[index_in_cache]; |
| 5556 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 5557 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5558 | __ LoadFromOffset(kLoadWord, |
| 5559 | reg, |
| 5560 | reg, |
| 5561 | CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 5562 | break; |
| 5563 | } |
| 5564 | } |
| 5565 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5566 | switch (code_ptr_location) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5567 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5568 | __ Bal(&frame_entry_label_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5569 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5570 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 5571 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
Goran Jakovljevic | 1a87837 | 2015-10-26 14:28:52 +0100 | [diff] [blame] | 5572 | __ LoadFromOffset(kLoadWord, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5573 | T9, |
| 5574 | callee_method.AsRegister<Register>(), |
| 5575 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5576 | kMipsPointerSize).Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5577 | // T9() |
| 5578 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 5579 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5580 | break; |
| 5581 | } |
| 5582 | DCHECK(!IsLeafMethod()); |
| 5583 | } |
| 5584 | |
| 5585 | void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5586 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5587 | // art::PrepareForRegisterAllocation. |
| 5588 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5589 | |
| 5590 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 5591 | return; |
| 5592 | } |
| 5593 | |
| 5594 | LocationSummary* locations = invoke->GetLocations(); |
| 5595 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 5596 | locations->HasTemps() |
| 5597 | ? locations->GetTemp(0) |
| 5598 | : Location::NoLocation()); |
| 5599 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 5600 | } |
| 5601 | |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 5602 | void CodeGeneratorMIPS::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 5603 | // Use the calling convention instead of the location of the receiver, as |
| 5604 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 5605 | // slow path, the arguments have been moved to the right place, so here we are |
| 5606 | // guaranteed that the receiver is the first register of the calling convention. |
| 5607 | InvokeDexCallingConvention calling_convention; |
| 5608 | Register receiver = calling_convention.GetRegisterAt(0); |
| 5609 | |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 5610 | Register temp = temp_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5611 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 5612 | invoke->GetVTableIndex(), kMipsPointerSize).SizeValue(); |
| 5613 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5614 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5615 | |
| 5616 | // temp = object->GetClass(); |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 5617 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 5618 | MaybeRecordImplicitNullCheck(invoke); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5619 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 5620 | // emit a read barrier for the previous class reference load. |
| 5621 | // However this is not required in practice, as this is an |
| 5622 | // intermediate/temporary reference and because the current |
| 5623 | // concurrent copying collector keeps the from-space memory |
| 5624 | // intact/accessible until the end of the marking phase (the |
| 5625 | // concurrent copying collector may not in the future). |
| 5626 | __ MaybeUnpoisonHeapReference(temp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5627 | // temp = temp->GetMethodAt(method_offset); |
| 5628 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 5629 | // T9 = temp->GetEntryPoint(); |
| 5630 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 5631 | // T9(); |
| 5632 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 5633 | __ NopIfNoReordering(); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 5634 | } |
| 5635 | |
| 5636 | void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 5637 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 5638 | return; |
| 5639 | } |
| 5640 | |
| 5641 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5642 | DCHECK(!codegen_->IsLeafMethod()); |
| 5643 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 5644 | } |
| 5645 | |
| 5646 | void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5647 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5648 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5649 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5650 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5651 | cls, |
| 5652 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5653 | Location::RegisterLocation(V0)); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5654 | return; |
| 5655 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5656 | DCHECK(!cls->NeedsAccessCheck()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5657 | |
| 5658 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier) |
| 5659 | ? LocationSummary::kCallOnSlowPath |
| 5660 | : LocationSummary::kNoCall; |
| 5661 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5662 | switch (load_kind) { |
| 5663 | // We need an extra register for PC-relative literals on R2. |
| 5664 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5665 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5666 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5667 | case HLoadClass::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5668 | if (codegen_->GetInstructionSetFeatures().IsR6()) { |
| 5669 | break; |
| 5670 | } |
| 5671 | FALLTHROUGH_INTENDED; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5672 | case HLoadClass::LoadKind::kReferrersClass: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5673 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5674 | break; |
| 5675 | default: |
| 5676 | break; |
| 5677 | } |
| 5678 | locations->SetOut(Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5679 | } |
| 5680 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5681 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5682 | // move. |
| 5683 | void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5684 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5685 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 5686 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 5687 | return; |
| 5688 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5689 | DCHECK(!cls->NeedsAccessCheck()); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 5690 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5691 | LocationSummary* locations = cls->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5692 | Location out_loc = locations->Out(); |
| 5693 | Register out = out_loc.AsRegister<Register>(); |
| 5694 | Register base_or_current_method_reg; |
| 5695 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 5696 | switch (load_kind) { |
| 5697 | // We need an extra register for PC-relative literals on R2. |
| 5698 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5699 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5700 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5701 | case HLoadClass::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5702 | base_or_current_method_reg = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>(); |
| 5703 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5704 | case HLoadClass::LoadKind::kReferrersClass: |
| 5705 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5706 | base_or_current_method_reg = locations->InAt(0).AsRegister<Register>(); |
| 5707 | break; |
| 5708 | default: |
| 5709 | base_or_current_method_reg = ZERO; |
| 5710 | break; |
| 5711 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5712 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5713 | bool generate_null_check = false; |
| 5714 | switch (load_kind) { |
| 5715 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5716 | DCHECK(!cls->CanCallRuntime()); |
| 5717 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5718 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5719 | GenerateGcRootFieldLoad(cls, |
| 5720 | out_loc, |
| 5721 | base_or_current_method_reg, |
| 5722 | ArtMethod::DeclaringClassOffset().Int32Value()); |
| 5723 | break; |
| 5724 | } |
| 5725 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5726 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5727 | __ LoadLiteral(out, |
| 5728 | base_or_current_method_reg, |
| 5729 | codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 5730 | cls->GetTypeIndex())); |
| 5731 | break; |
| 5732 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5733 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5734 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
| 5735 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 5736 | bool reordering = __ SetReorder(false); |
| 5737 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info, out, base_or_current_method_reg); |
| 5738 | __ Addiu(out, out, /* placeholder */ 0x5678); |
| 5739 | __ SetReorder(reordering); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5740 | break; |
| 5741 | } |
| 5742 | case HLoadClass::LoadKind::kBootImageAddress: { |
| 5743 | DCHECK(!kEmitCompilerReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5744 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5745 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 5746 | DCHECK_NE(address, 0u); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5747 | __ LoadLiteral(out, |
| 5748 | base_or_current_method_reg, |
| 5749 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5750 | break; |
| 5751 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5752 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5753 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5754 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 5755 | bool reordering = __ SetReorder(false); |
| 5756 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info, out, base_or_current_method_reg); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5757 | GenerateGcRootFieldLoad(cls, out_loc, out, /* placeholder */ 0x5678); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 5758 | __ SetReorder(reordering); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5759 | generate_null_check = true; |
| 5760 | break; |
| 5761 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5762 | case HLoadClass::LoadKind::kJitTableAddress: { |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 5763 | CodeGeneratorMIPS::JitPatchInfo* info = codegen_->NewJitRootClassPatch(cls->GetDexFile(), |
| 5764 | cls->GetTypeIndex(), |
| 5765 | cls->GetClass()); |
| 5766 | bool reordering = __ SetReorder(false); |
| 5767 | __ Bind(&info->high_label); |
| 5768 | __ Lui(out, /* placeholder */ 0x1234); |
| 5769 | GenerateGcRootFieldLoad(cls, out_loc, out, /* placeholder */ 0x5678); |
| 5770 | __ SetReorder(reordering); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5771 | break; |
| 5772 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5773 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5774 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5775 | LOG(FATAL) << "UNREACHABLE"; |
| 5776 | UNREACHABLE(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5777 | } |
| 5778 | |
| 5779 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5780 | DCHECK(cls->CanCallRuntime()); |
| 5781 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS( |
| 5782 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5783 | codegen_->AddSlowPath(slow_path); |
| 5784 | if (generate_null_check) { |
| 5785 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 5786 | } |
| 5787 | if (cls->MustGenerateClinitCheck()) { |
| 5788 | GenerateClassInitializationCheck(slow_path, out); |
| 5789 | } else { |
| 5790 | __ Bind(slow_path->GetExitLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5791 | } |
| 5792 | } |
| 5793 | } |
| 5794 | |
| 5795 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5796 | return Thread::ExceptionOffset<kMipsPointerSize>().Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5797 | } |
| 5798 | |
| 5799 | void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) { |
| 5800 | LocationSummary* locations = |
| 5801 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5802 | locations->SetOut(Location::RequiresRegister()); |
| 5803 | } |
| 5804 | |
| 5805 | void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) { |
| 5806 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
| 5807 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 5808 | } |
| 5809 | |
| 5810 | void LocationsBuilderMIPS::VisitClearException(HClearException* clear) { |
| 5811 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5812 | } |
| 5813 | |
| 5814 | void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5815 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
| 5816 | } |
| 5817 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5818 | void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5819 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5820 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5821 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 5822 | switch (load_kind) { |
| 5823 | // We need an extra register for PC-relative literals on R2. |
| 5824 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5825 | case HLoadString::LoadKind::kBootImageAddress: |
| 5826 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5827 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5828 | if (codegen_->GetInstructionSetFeatures().IsR6()) { |
| 5829 | break; |
| 5830 | } |
| 5831 | FALLTHROUGH_INTENDED; |
| 5832 | // We need an extra register for PC-relative dex cache accesses. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5833 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5834 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5835 | break; |
| 5836 | default: |
| 5837 | break; |
| 5838 | } |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 5839 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 5840 | InvokeRuntimeCallingConvention calling_convention; |
| 5841 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5842 | } else { |
| 5843 | locations->SetOut(Location::RequiresRegister()); |
| 5844 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5845 | } |
| 5846 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5847 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5848 | // move. |
| 5849 | void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5850 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5851 | LocationSummary* locations = load->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5852 | Location out_loc = locations->Out(); |
| 5853 | Register out = out_loc.AsRegister<Register>(); |
| 5854 | Register base_or_current_method_reg; |
| 5855 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 5856 | switch (load_kind) { |
| 5857 | // We need an extra register for PC-relative literals on R2. |
| 5858 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5859 | case HLoadString::LoadKind::kBootImageAddress: |
| 5860 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5861 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5862 | base_or_current_method_reg = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>(); |
| 5863 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5864 | default: |
| 5865 | base_or_current_method_reg = ZERO; |
| 5866 | break; |
| 5867 | } |
| 5868 | |
| 5869 | switch (load_kind) { |
| 5870 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5871 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5872 | __ LoadLiteral(out, |
| 5873 | base_or_current_method_reg, |
| 5874 | codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 5875 | load->GetStringIndex())); |
| 5876 | return; // No dex cache slow path. |
| 5877 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5878 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5879 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5880 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 5881 | bool reordering = __ SetReorder(false); |
| 5882 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info, out, base_or_current_method_reg); |
| 5883 | __ Addiu(out, out, /* placeholder */ 0x5678); |
| 5884 | __ SetReorder(reordering); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5885 | return; // No dex cache slow path. |
| 5886 | } |
| 5887 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5888 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5889 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5890 | DCHECK_NE(address, 0u); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5891 | __ LoadLiteral(out, |
| 5892 | base_or_current_method_reg, |
| 5893 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5894 | return; // No dex cache slow path. |
| 5895 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5896 | case HLoadString::LoadKind::kBssEntry: { |
| 5897 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 5898 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5899 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 5900 | bool reordering = __ SetReorder(false); |
| 5901 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info, out, base_or_current_method_reg); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 5902 | GenerateGcRootFieldLoad(load, out_loc, out, /* placeholder */ 0x5678); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 5903 | __ SetReorder(reordering); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5904 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS(load); |
| 5905 | codegen_->AddSlowPath(slow_path); |
| 5906 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 5907 | __ Bind(slow_path->GetExitLabel()); |
| 5908 | return; |
| 5909 | } |
Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 5910 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5911 | CodeGeneratorMIPS::JitPatchInfo* info = |
| 5912 | codegen_->NewJitRootStringPatch(load->GetDexFile(), |
| 5913 | load->GetStringIndex(), |
| 5914 | load->GetString()); |
| 5915 | bool reordering = __ SetReorder(false); |
| 5916 | __ Bind(&info->high_label); |
| 5917 | __ Lui(out, /* placeholder */ 0x1234); |
| 5918 | GenerateGcRootFieldLoad(load, out_loc, out, /* placeholder */ 0x5678); |
| 5919 | __ SetReorder(reordering); |
| 5920 | return; |
| 5921 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5922 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5923 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5924 | } |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5925 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5926 | // 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] | 5927 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 5928 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5929 | __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5930 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5931 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5932 | } |
| 5933 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5934 | void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) { |
| 5935 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5936 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5937 | } |
| 5938 | |
| 5939 | void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 5940 | // Will be generated at use site. |
| 5941 | } |
| 5942 | |
| 5943 | void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5944 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5945 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5946 | InvokeRuntimeCallingConvention calling_convention; |
| 5947 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5948 | } |
| 5949 | |
| 5950 | void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5951 | if (instruction->IsEnter()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 5952 | codegen_->InvokeRuntime(kQuickLockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5953 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5954 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 5955 | codegen_->InvokeRuntime(kQuickUnlockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5956 | } |
| 5957 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5958 | } |
| 5959 | |
| 5960 | void LocationsBuilderMIPS::VisitMul(HMul* mul) { |
| 5961 | LocationSummary* locations = |
| 5962 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 5963 | switch (mul->GetResultType()) { |
| 5964 | case Primitive::kPrimInt: |
| 5965 | case Primitive::kPrimLong: |
| 5966 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5967 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5968 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5969 | break; |
| 5970 | |
| 5971 | case Primitive::kPrimFloat: |
| 5972 | case Primitive::kPrimDouble: |
| 5973 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5974 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5975 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5976 | break; |
| 5977 | |
| 5978 | default: |
| 5979 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5980 | } |
| 5981 | } |
| 5982 | |
| 5983 | void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) { |
| 5984 | Primitive::Type type = instruction->GetType(); |
| 5985 | LocationSummary* locations = instruction->GetLocations(); |
| 5986 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 5987 | |
| 5988 | switch (type) { |
| 5989 | case Primitive::kPrimInt: { |
| 5990 | Register dst = locations->Out().AsRegister<Register>(); |
| 5991 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 5992 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 5993 | |
| 5994 | if (isR6) { |
| 5995 | __ MulR6(dst, lhs, rhs); |
| 5996 | } else { |
| 5997 | __ MulR2(dst, lhs, rhs); |
| 5998 | } |
| 5999 | break; |
| 6000 | } |
| 6001 | case Primitive::kPrimLong: { |
| 6002 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 6003 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 6004 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 6005 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 6006 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 6007 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 6008 | |
| 6009 | // Extra checks to protect caused by the existance of A1_A2. |
| 6010 | // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo: |
| 6011 | // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2). |
| 6012 | DCHECK_NE(dst_high, lhs_low); |
| 6013 | DCHECK_NE(dst_high, rhs_low); |
| 6014 | |
| 6015 | // A_B * C_D |
| 6016 | // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ] |
| 6017 | // dst_lo: [ low(B*D) ] |
| 6018 | // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result. |
| 6019 | |
| 6020 | if (isR6) { |
| 6021 | __ MulR6(TMP, lhs_high, rhs_low); |
| 6022 | __ MulR6(dst_high, lhs_low, rhs_high); |
| 6023 | __ Addu(dst_high, dst_high, TMP); |
| 6024 | __ MuhuR6(TMP, lhs_low, rhs_low); |
| 6025 | __ Addu(dst_high, dst_high, TMP); |
| 6026 | __ MulR6(dst_low, lhs_low, rhs_low); |
| 6027 | } else { |
| 6028 | __ MulR2(TMP, lhs_high, rhs_low); |
| 6029 | __ MulR2(dst_high, lhs_low, rhs_high); |
| 6030 | __ Addu(dst_high, dst_high, TMP); |
| 6031 | __ MultuR2(lhs_low, rhs_low); |
| 6032 | __ Mfhi(TMP); |
| 6033 | __ Addu(dst_high, dst_high, TMP); |
| 6034 | __ Mflo(dst_low); |
| 6035 | } |
| 6036 | break; |
| 6037 | } |
| 6038 | case Primitive::kPrimFloat: |
| 6039 | case Primitive::kPrimDouble: { |
| 6040 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 6041 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 6042 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 6043 | if (type == Primitive::kPrimFloat) { |
| 6044 | __ MulS(dst, lhs, rhs); |
| 6045 | } else { |
| 6046 | __ MulD(dst, lhs, rhs); |
| 6047 | } |
| 6048 | break; |
| 6049 | } |
| 6050 | default: |
| 6051 | LOG(FATAL) << "Unexpected mul type " << type; |
| 6052 | } |
| 6053 | } |
| 6054 | |
| 6055 | void LocationsBuilderMIPS::VisitNeg(HNeg* neg) { |
| 6056 | LocationSummary* locations = |
| 6057 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 6058 | switch (neg->GetResultType()) { |
| 6059 | case Primitive::kPrimInt: |
| 6060 | case Primitive::kPrimLong: |
| 6061 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6062 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6063 | break; |
| 6064 | |
| 6065 | case Primitive::kPrimFloat: |
| 6066 | case Primitive::kPrimDouble: |
| 6067 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6068 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6069 | break; |
| 6070 | |
| 6071 | default: |
| 6072 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 6073 | } |
| 6074 | } |
| 6075 | |
| 6076 | void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) { |
| 6077 | Primitive::Type type = instruction->GetType(); |
| 6078 | LocationSummary* locations = instruction->GetLocations(); |
| 6079 | |
| 6080 | switch (type) { |
| 6081 | case Primitive::kPrimInt: { |
| 6082 | Register dst = locations->Out().AsRegister<Register>(); |
| 6083 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 6084 | __ Subu(dst, ZERO, src); |
| 6085 | break; |
| 6086 | } |
| 6087 | case Primitive::kPrimLong: { |
| 6088 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 6089 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 6090 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 6091 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 6092 | __ Subu(dst_low, ZERO, src_low); |
| 6093 | __ Sltu(TMP, ZERO, dst_low); |
| 6094 | __ Subu(dst_high, ZERO, src_high); |
| 6095 | __ Subu(dst_high, dst_high, TMP); |
| 6096 | break; |
| 6097 | } |
| 6098 | case Primitive::kPrimFloat: |
| 6099 | case Primitive::kPrimDouble: { |
| 6100 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 6101 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 6102 | if (type == Primitive::kPrimFloat) { |
| 6103 | __ NegS(dst, src); |
| 6104 | } else { |
| 6105 | __ NegD(dst, src); |
| 6106 | } |
| 6107 | break; |
| 6108 | } |
| 6109 | default: |
| 6110 | LOG(FATAL) << "Unexpected neg type " << type; |
| 6111 | } |
| 6112 | } |
| 6113 | |
| 6114 | void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) { |
| 6115 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6116 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6117 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6118 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6119 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6120 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6121 | } |
| 6122 | |
| 6123 | void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6124 | // Note: if heap poisoning is enabled, the entry point takes care |
| 6125 | // of poisoning the reference. |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6126 | codegen_->InvokeRuntime(kQuickAllocArrayResolved, instruction, instruction->GetDexPc()); |
| 6127 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6128 | } |
| 6129 | |
| 6130 | void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) { |
| 6131 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6132 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6133 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6134 | if (instruction->IsStringAlloc()) { |
| 6135 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 6136 | } else { |
| 6137 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6138 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6139 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 6140 | } |
| 6141 | |
| 6142 | void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) { |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 6143 | // Note: if heap poisoning is enabled, the entry point takes care |
| 6144 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6145 | if (instruction->IsStringAlloc()) { |
| 6146 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 6147 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6148 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6149 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 6150 | __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value()); |
| 6151 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 6152 | __ NopIfNoReordering(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6153 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 6154 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6155 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 6156 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6157 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6158 | } |
| 6159 | |
| 6160 | void LocationsBuilderMIPS::VisitNot(HNot* instruction) { |
| 6161 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 6162 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6163 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6164 | } |
| 6165 | |
| 6166 | void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) { |
| 6167 | Primitive::Type type = instruction->GetType(); |
| 6168 | LocationSummary* locations = instruction->GetLocations(); |
| 6169 | |
| 6170 | switch (type) { |
| 6171 | case Primitive::kPrimInt: { |
| 6172 | Register dst = locations->Out().AsRegister<Register>(); |
| 6173 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 6174 | __ Nor(dst, src, ZERO); |
| 6175 | break; |
| 6176 | } |
| 6177 | |
| 6178 | case Primitive::kPrimLong: { |
| 6179 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 6180 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 6181 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 6182 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 6183 | __ Nor(dst_high, src_high, ZERO); |
| 6184 | __ Nor(dst_low, src_low, ZERO); |
| 6185 | break; |
| 6186 | } |
| 6187 | |
| 6188 | default: |
| 6189 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 6190 | } |
| 6191 | } |
| 6192 | |
| 6193 | void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
| 6194 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 6195 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6196 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6197 | } |
| 6198 | |
| 6199 | void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
| 6200 | LocationSummary* locations = instruction->GetLocations(); |
| 6201 | __ Xori(locations->Out().AsRegister<Register>(), |
| 6202 | locations->InAt(0).AsRegister<Register>(), |
| 6203 | 1); |
| 6204 | } |
| 6205 | |
| 6206 | void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6207 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 6208 | locations->SetInAt(0, Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6209 | } |
| 6210 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6211 | void CodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 6212 | if (CanMoveNullCheckToUser(instruction)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6213 | return; |
| 6214 | } |
| 6215 | Location obj = instruction->GetLocations()->InAt(0); |
| 6216 | |
| 6217 | __ Lw(ZERO, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6218 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6219 | } |
| 6220 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6221 | void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6222 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6223 | AddSlowPath(slow_path); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6224 | |
| 6225 | Location obj = instruction->GetLocations()->InAt(0); |
| 6226 | |
| 6227 | __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 6228 | } |
| 6229 | |
| 6230 | void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6231 | codegen_->GenerateNullCheck(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6232 | } |
| 6233 | |
| 6234 | void LocationsBuilderMIPS::VisitOr(HOr* instruction) { |
| 6235 | HandleBinaryOp(instruction); |
| 6236 | } |
| 6237 | |
| 6238 | void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) { |
| 6239 | HandleBinaryOp(instruction); |
| 6240 | } |
| 6241 | |
| 6242 | void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 6243 | LOG(FATAL) << "Unreachable"; |
| 6244 | } |
| 6245 | |
| 6246 | void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) { |
| 6247 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6248 | } |
| 6249 | |
| 6250 | void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) { |
| 6251 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 6252 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 6253 | if (location.IsStackSlot()) { |
| 6254 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 6255 | } else if (location.IsDoubleStackSlot()) { |
| 6256 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 6257 | } |
| 6258 | locations->SetOut(location); |
| 6259 | } |
| 6260 | |
| 6261 | void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction |
| 6262 | ATTRIBUTE_UNUSED) { |
| 6263 | // Nothing to do, the parameter is already at its location. |
| 6264 | } |
| 6265 | |
| 6266 | void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 6267 | LocationSummary* locations = |
| 6268 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6269 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 6270 | } |
| 6271 | |
| 6272 | void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction |
| 6273 | ATTRIBUTE_UNUSED) { |
| 6274 | // Nothing to do, the method is already at its location. |
| 6275 | } |
| 6276 | |
| 6277 | void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) { |
| 6278 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6279 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6280 | locations->SetInAt(i, Location::Any()); |
| 6281 | } |
| 6282 | locations->SetOut(Location::Any()); |
| 6283 | } |
| 6284 | |
| 6285 | void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 6286 | LOG(FATAL) << "Unreachable"; |
| 6287 | } |
| 6288 | |
| 6289 | void LocationsBuilderMIPS::VisitRem(HRem* rem) { |
| 6290 | Primitive::Type type = rem->GetResultType(); |
| 6291 | LocationSummary::CallKind call_kind = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6292 | (type == Primitive::kPrimInt) ? LocationSummary::kNoCall : LocationSummary::kCallOnMainOnly; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6293 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 6294 | |
| 6295 | switch (type) { |
| 6296 | case Primitive::kPrimInt: |
| 6297 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 6298 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6299 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6300 | break; |
| 6301 | |
| 6302 | case Primitive::kPrimLong: { |
| 6303 | InvokeRuntimeCallingConvention calling_convention; |
| 6304 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 6305 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 6306 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 6307 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 6308 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 6309 | break; |
| 6310 | } |
| 6311 | |
| 6312 | case Primitive::kPrimFloat: |
| 6313 | case Primitive::kPrimDouble: { |
| 6314 | InvokeRuntimeCallingConvention calling_convention; |
| 6315 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 6316 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 6317 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 6318 | break; |
| 6319 | } |
| 6320 | |
| 6321 | default: |
| 6322 | LOG(FATAL) << "Unexpected rem type " << type; |
| 6323 | } |
| 6324 | } |
| 6325 | |
| 6326 | void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) { |
| 6327 | Primitive::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6328 | |
| 6329 | switch (type) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 6330 | case Primitive::kPrimInt: |
| 6331 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6332 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6333 | case Primitive::kPrimLong: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6334 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6335 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 6336 | break; |
| 6337 | } |
| 6338 | case Primitive::kPrimFloat: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6339 | codegen_->InvokeRuntime(kQuickFmodf, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6340 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6341 | break; |
| 6342 | } |
| 6343 | case Primitive::kPrimDouble: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6344 | codegen_->InvokeRuntime(kQuickFmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6345 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6346 | break; |
| 6347 | } |
| 6348 | default: |
| 6349 | LOG(FATAL) << "Unexpected rem type " << type; |
| 6350 | } |
| 6351 | } |
| 6352 | |
| 6353 | void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 6354 | memory_barrier->SetLocations(nullptr); |
| 6355 | } |
| 6356 | |
| 6357 | void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 6358 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 6359 | } |
| 6360 | |
| 6361 | void LocationsBuilderMIPS::VisitReturn(HReturn* ret) { |
| 6362 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret); |
| 6363 | Primitive::Type return_type = ret->InputAt(0)->GetType(); |
| 6364 | locations->SetInAt(0, MipsReturnLocation(return_type)); |
| 6365 | } |
| 6366 | |
| 6367 | void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 6368 | codegen_->GenerateFrameExit(); |
| 6369 | } |
| 6370 | |
| 6371 | void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) { |
| 6372 | ret->SetLocations(nullptr); |
| 6373 | } |
| 6374 | |
| 6375 | void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 6376 | codegen_->GenerateFrameExit(); |
| 6377 | } |
| 6378 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 6379 | void LocationsBuilderMIPS::VisitRor(HRor* ror) { |
| 6380 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6381 | } |
| 6382 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 6383 | void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) { |
| 6384 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6385 | } |
| 6386 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6387 | void LocationsBuilderMIPS::VisitShl(HShl* shl) { |
| 6388 | HandleShift(shl); |
| 6389 | } |
| 6390 | |
| 6391 | void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) { |
| 6392 | HandleShift(shl); |
| 6393 | } |
| 6394 | |
| 6395 | void LocationsBuilderMIPS::VisitShr(HShr* shr) { |
| 6396 | HandleShift(shr); |
| 6397 | } |
| 6398 | |
| 6399 | void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) { |
| 6400 | HandleShift(shr); |
| 6401 | } |
| 6402 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6403 | void LocationsBuilderMIPS::VisitSub(HSub* instruction) { |
| 6404 | HandleBinaryOp(instruction); |
| 6405 | } |
| 6406 | |
| 6407 | void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) { |
| 6408 | HandleBinaryOp(instruction); |
| 6409 | } |
| 6410 | |
| 6411 | void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6412 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6413 | } |
| 6414 | |
| 6415 | void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6416 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 6417 | } |
| 6418 | |
| 6419 | void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6420 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6421 | } |
| 6422 | |
| 6423 | void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6424 | HandleFieldSet(instruction, |
| 6425 | instruction->GetFieldInfo(), |
| 6426 | instruction->GetDexPc(), |
| 6427 | instruction->GetValueCanBeNull()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6428 | } |
| 6429 | |
| 6430 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet( |
| 6431 | HUnresolvedInstanceFieldGet* instruction) { |
| 6432 | FieldAccessCallingConventionMIPS calling_convention; |
| 6433 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 6434 | instruction->GetFieldType(), |
| 6435 | calling_convention); |
| 6436 | } |
| 6437 | |
| 6438 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet( |
| 6439 | HUnresolvedInstanceFieldGet* instruction) { |
| 6440 | FieldAccessCallingConventionMIPS calling_convention; |
| 6441 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6442 | instruction->GetFieldType(), |
| 6443 | instruction->GetFieldIndex(), |
| 6444 | instruction->GetDexPc(), |
| 6445 | calling_convention); |
| 6446 | } |
| 6447 | |
| 6448 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet( |
| 6449 | HUnresolvedInstanceFieldSet* instruction) { |
| 6450 | FieldAccessCallingConventionMIPS calling_convention; |
| 6451 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 6452 | instruction->GetFieldType(), |
| 6453 | calling_convention); |
| 6454 | } |
| 6455 | |
| 6456 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet( |
| 6457 | HUnresolvedInstanceFieldSet* instruction) { |
| 6458 | FieldAccessCallingConventionMIPS calling_convention; |
| 6459 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6460 | instruction->GetFieldType(), |
| 6461 | instruction->GetFieldIndex(), |
| 6462 | instruction->GetDexPc(), |
| 6463 | calling_convention); |
| 6464 | } |
| 6465 | |
| 6466 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet( |
| 6467 | HUnresolvedStaticFieldGet* instruction) { |
| 6468 | FieldAccessCallingConventionMIPS calling_convention; |
| 6469 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 6470 | instruction->GetFieldType(), |
| 6471 | calling_convention); |
| 6472 | } |
| 6473 | |
| 6474 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet( |
| 6475 | HUnresolvedStaticFieldGet* instruction) { |
| 6476 | FieldAccessCallingConventionMIPS calling_convention; |
| 6477 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6478 | instruction->GetFieldType(), |
| 6479 | instruction->GetFieldIndex(), |
| 6480 | instruction->GetDexPc(), |
| 6481 | calling_convention); |
| 6482 | } |
| 6483 | |
| 6484 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet( |
| 6485 | HUnresolvedStaticFieldSet* instruction) { |
| 6486 | FieldAccessCallingConventionMIPS calling_convention; |
| 6487 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 6488 | instruction->GetFieldType(), |
| 6489 | calling_convention); |
| 6490 | } |
| 6491 | |
| 6492 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet( |
| 6493 | HUnresolvedStaticFieldSet* instruction) { |
| 6494 | FieldAccessCallingConventionMIPS calling_convention; |
| 6495 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6496 | instruction->GetFieldType(), |
| 6497 | instruction->GetFieldIndex(), |
| 6498 | instruction->GetDexPc(), |
| 6499 | calling_convention); |
| 6500 | } |
| 6501 | |
| 6502 | void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6503 | LocationSummary* locations = |
| 6504 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6505 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6506 | } |
| 6507 | |
| 6508 | void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 6509 | HBasicBlock* block = instruction->GetBlock(); |
| 6510 | if (block->GetLoopInformation() != nullptr) { |
| 6511 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6512 | // The back edge will generate the suspend check. |
| 6513 | return; |
| 6514 | } |
| 6515 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6516 | // The goto will generate the suspend check. |
| 6517 | return; |
| 6518 | } |
| 6519 | GenerateSuspendCheck(instruction, nullptr); |
| 6520 | } |
| 6521 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6522 | void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) { |
| 6523 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6524 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6525 | InvokeRuntimeCallingConvention calling_convention; |
| 6526 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6527 | } |
| 6528 | |
| 6529 | void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6530 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6531 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 6532 | } |
| 6533 | |
| 6534 | void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
| 6535 | Primitive::Type input_type = conversion->GetInputType(); |
| 6536 | Primitive::Type result_type = conversion->GetResultType(); |
| 6537 | DCHECK_NE(input_type, result_type); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6538 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6539 | |
| 6540 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 6541 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 6542 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 6543 | } |
| 6544 | |
| 6545 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6546 | if (!isR6 && |
| 6547 | ((Primitive::IsFloatingPointType(result_type) && input_type == Primitive::kPrimLong) || |
| 6548 | (result_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(input_type)))) { |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6549 | call_kind = LocationSummary::kCallOnMainOnly; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6550 | } |
| 6551 | |
| 6552 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 6553 | |
| 6554 | if (call_kind == LocationSummary::kNoCall) { |
| 6555 | if (Primitive::IsFloatingPointType(input_type)) { |
| 6556 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6557 | } else { |
| 6558 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6559 | } |
| 6560 | |
| 6561 | if (Primitive::IsFloatingPointType(result_type)) { |
| 6562 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6563 | } else { |
| 6564 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6565 | } |
| 6566 | } else { |
| 6567 | InvokeRuntimeCallingConvention calling_convention; |
| 6568 | |
| 6569 | if (Primitive::IsFloatingPointType(input_type)) { |
| 6570 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 6571 | } else { |
| 6572 | DCHECK_EQ(input_type, Primitive::kPrimLong); |
| 6573 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 6574 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 6575 | } |
| 6576 | |
| 6577 | locations->SetOut(calling_convention.GetReturnLocation(result_type)); |
| 6578 | } |
| 6579 | } |
| 6580 | |
| 6581 | void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
| 6582 | LocationSummary* locations = conversion->GetLocations(); |
| 6583 | Primitive::Type result_type = conversion->GetResultType(); |
| 6584 | Primitive::Type input_type = conversion->GetInputType(); |
| 6585 | bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6586 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6587 | |
| 6588 | DCHECK_NE(input_type, result_type); |
| 6589 | |
| 6590 | if (result_type == Primitive::kPrimLong && Primitive::IsIntegralType(input_type)) { |
| 6591 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 6592 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 6593 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 6594 | |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 6595 | if (dst_low != src) { |
| 6596 | __ Move(dst_low, src); |
| 6597 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6598 | __ Sra(dst_high, src, 31); |
| 6599 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
| 6600 | Register dst = locations->Out().AsRegister<Register>(); |
| 6601 | Register src = (input_type == Primitive::kPrimLong) |
| 6602 | ? locations->InAt(0).AsRegisterPairLow<Register>() |
| 6603 | : locations->InAt(0).AsRegister<Register>(); |
| 6604 | |
| 6605 | switch (result_type) { |
| 6606 | case Primitive::kPrimChar: |
| 6607 | __ Andi(dst, src, 0xFFFF); |
| 6608 | break; |
| 6609 | case Primitive::kPrimByte: |
| 6610 | if (has_sign_extension) { |
| 6611 | __ Seb(dst, src); |
| 6612 | } else { |
| 6613 | __ Sll(dst, src, 24); |
| 6614 | __ Sra(dst, dst, 24); |
| 6615 | } |
| 6616 | break; |
| 6617 | case Primitive::kPrimShort: |
| 6618 | if (has_sign_extension) { |
| 6619 | __ Seh(dst, src); |
| 6620 | } else { |
| 6621 | __ Sll(dst, src, 16); |
| 6622 | __ Sra(dst, dst, 16); |
| 6623 | } |
| 6624 | break; |
| 6625 | case Primitive::kPrimInt: |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 6626 | if (dst != src) { |
| 6627 | __ Move(dst, src); |
| 6628 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6629 | break; |
| 6630 | |
| 6631 | default: |
| 6632 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 6633 | << " to " << result_type; |
| 6634 | } |
| 6635 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6636 | if (input_type == Primitive::kPrimLong) { |
| 6637 | if (isR6) { |
| 6638 | // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 6639 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 6640 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 6641 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 6642 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 6643 | __ Mtc1(src_low, FTMP); |
| 6644 | __ Mthc1(src_high, FTMP); |
| 6645 | if (result_type == Primitive::kPrimFloat) { |
| 6646 | __ Cvtsl(dst, FTMP); |
| 6647 | } else { |
| 6648 | __ Cvtdl(dst, FTMP); |
| 6649 | } |
| 6650 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6651 | QuickEntrypointEnum entrypoint = (result_type == Primitive::kPrimFloat) ? kQuickL2f |
| 6652 | : kQuickL2d; |
| 6653 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6654 | if (result_type == Primitive::kPrimFloat) { |
| 6655 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 6656 | } else { |
| 6657 | CheckEntrypointTypes<kQuickL2d, double, int64_t>(); |
| 6658 | } |
| 6659 | } |
| 6660 | } else { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6661 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 6662 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 6663 | __ Mtc1(src, FTMP); |
| 6664 | if (result_type == Primitive::kPrimFloat) { |
| 6665 | __ Cvtsw(dst, FTMP); |
| 6666 | } else { |
| 6667 | __ Cvtdw(dst, FTMP); |
| 6668 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6669 | } |
| 6670 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
| 6671 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6672 | if (result_type == Primitive::kPrimLong) { |
| 6673 | if (isR6) { |
| 6674 | // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 6675 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 6676 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 6677 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 6678 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 6679 | MipsLabel truncate; |
| 6680 | MipsLabel done; |
| 6681 | |
| 6682 | // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive |
| 6683 | // value when the input is either a NaN or is outside of the range of the output type |
| 6684 | // after the truncation. IOW, the three special cases (NaN, too small, too big) produce |
| 6685 | // the same result. |
| 6686 | // |
| 6687 | // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum |
| 6688 | // value of the output type if the input is outside of the range after the truncation or |
| 6689 | // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct |
| 6690 | // results. This matches the desired float/double-to-int/long conversion exactly. |
| 6691 | // |
| 6692 | // So, NAN2008 affects handling of negative values and NaNs by the truncate instruction. |
| 6693 | // |
| 6694 | // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate |
| 6695 | // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6, |
| 6696 | // even though it must be NAN2008=1 on R6. |
| 6697 | // |
| 6698 | // The code takes care of the different behaviors by first comparing the input to the |
| 6699 | // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int). |
| 6700 | // If the input is greater than or equal to the minimum, it procedes to the truncate |
| 6701 | // instruction, which will handle such an input the same way irrespective of NAN2008. |
| 6702 | // Otherwise the input is compared to itself to determine whether it is a NaN or not |
| 6703 | // in order to return either zero or the minimum value. |
| 6704 | // |
| 6705 | // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the |
| 6706 | // truncate instruction for MIPS64R6. |
| 6707 | if (input_type == Primitive::kPrimFloat) { |
| 6708 | uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int64_t>::min()); |
| 6709 | __ LoadConst32(TMP, min_val); |
| 6710 | __ Mtc1(TMP, FTMP); |
| 6711 | __ CmpLeS(FTMP, FTMP, src); |
| 6712 | } else { |
| 6713 | uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int64_t>::min()); |
| 6714 | __ LoadConst32(TMP, High32Bits(min_val)); |
| 6715 | __ Mtc1(ZERO, FTMP); |
| 6716 | __ Mthc1(TMP, FTMP); |
| 6717 | __ CmpLeD(FTMP, FTMP, src); |
| 6718 | } |
| 6719 | |
| 6720 | __ Bc1nez(FTMP, &truncate); |
| 6721 | |
| 6722 | if (input_type == Primitive::kPrimFloat) { |
| 6723 | __ CmpEqS(FTMP, src, src); |
| 6724 | } else { |
| 6725 | __ CmpEqD(FTMP, src, src); |
| 6726 | } |
| 6727 | __ Move(dst_low, ZERO); |
| 6728 | __ LoadConst32(dst_high, std::numeric_limits<int32_t>::min()); |
| 6729 | __ Mfc1(TMP, FTMP); |
| 6730 | __ And(dst_high, dst_high, TMP); |
| 6731 | |
| 6732 | __ B(&done); |
| 6733 | |
| 6734 | __ Bind(&truncate); |
| 6735 | |
| 6736 | if (input_type == Primitive::kPrimFloat) { |
| 6737 | __ TruncLS(FTMP, src); |
| 6738 | } else { |
| 6739 | __ TruncLD(FTMP, src); |
| 6740 | } |
| 6741 | __ Mfc1(dst_low, FTMP); |
| 6742 | __ Mfhc1(dst_high, FTMP); |
| 6743 | |
| 6744 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6745 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6746 | QuickEntrypointEnum entrypoint = (input_type == Primitive::kPrimFloat) ? kQuickF2l |
| 6747 | : kQuickD2l; |
| 6748 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6749 | if (input_type == Primitive::kPrimFloat) { |
| 6750 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 6751 | } else { |
| 6752 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 6753 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6754 | } |
| 6755 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6756 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 6757 | Register dst = locations->Out().AsRegister<Register>(); |
| 6758 | MipsLabel truncate; |
| 6759 | MipsLabel done; |
| 6760 | |
| 6761 | // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate |
| 6762 | // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6, |
| 6763 | // even though it must be NAN2008=1 on R6. |
| 6764 | // |
| 6765 | // For details see the large comment above for the truncation of float/double to long on R6. |
| 6766 | // |
| 6767 | // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the |
| 6768 | // truncate instruction for MIPS64R6. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6769 | if (input_type == Primitive::kPrimFloat) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6770 | uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min()); |
| 6771 | __ LoadConst32(TMP, min_val); |
| 6772 | __ Mtc1(TMP, FTMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6773 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6774 | uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min()); |
| 6775 | __ LoadConst32(TMP, High32Bits(min_val)); |
| 6776 | __ Mtc1(ZERO, FTMP); |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 6777 | __ MoveToFpuHigh(TMP, FTMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6778 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6779 | |
| 6780 | if (isR6) { |
| 6781 | if (input_type == Primitive::kPrimFloat) { |
| 6782 | __ CmpLeS(FTMP, FTMP, src); |
| 6783 | } else { |
| 6784 | __ CmpLeD(FTMP, FTMP, src); |
| 6785 | } |
| 6786 | __ Bc1nez(FTMP, &truncate); |
| 6787 | |
| 6788 | if (input_type == Primitive::kPrimFloat) { |
| 6789 | __ CmpEqS(FTMP, src, src); |
| 6790 | } else { |
| 6791 | __ CmpEqD(FTMP, src, src); |
| 6792 | } |
| 6793 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); |
| 6794 | __ Mfc1(TMP, FTMP); |
| 6795 | __ And(dst, dst, TMP); |
| 6796 | } else { |
| 6797 | if (input_type == Primitive::kPrimFloat) { |
| 6798 | __ ColeS(0, FTMP, src); |
| 6799 | } else { |
| 6800 | __ ColeD(0, FTMP, src); |
| 6801 | } |
| 6802 | __ Bc1t(0, &truncate); |
| 6803 | |
| 6804 | if (input_type == Primitive::kPrimFloat) { |
| 6805 | __ CeqS(0, src, src); |
| 6806 | } else { |
| 6807 | __ CeqD(0, src, src); |
| 6808 | } |
| 6809 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); |
| 6810 | __ Movf(dst, ZERO, 0); |
| 6811 | } |
| 6812 | |
| 6813 | __ B(&done); |
| 6814 | |
| 6815 | __ Bind(&truncate); |
| 6816 | |
| 6817 | if (input_type == Primitive::kPrimFloat) { |
| 6818 | __ TruncWS(FTMP, src); |
| 6819 | } else { |
| 6820 | __ TruncWD(FTMP, src); |
| 6821 | } |
| 6822 | __ Mfc1(dst, FTMP); |
| 6823 | |
| 6824 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6825 | } |
| 6826 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 6827 | Primitive::IsFloatingPointType(input_type)) { |
| 6828 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 6829 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 6830 | if (result_type == Primitive::kPrimFloat) { |
| 6831 | __ Cvtsd(dst, src); |
| 6832 | } else { |
| 6833 | __ Cvtds(dst, src); |
| 6834 | } |
| 6835 | } else { |
| 6836 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 6837 | << " to " << result_type; |
| 6838 | } |
| 6839 | } |
| 6840 | |
| 6841 | void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) { |
| 6842 | HandleShift(ushr); |
| 6843 | } |
| 6844 | |
| 6845 | void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) { |
| 6846 | HandleShift(ushr); |
| 6847 | } |
| 6848 | |
| 6849 | void LocationsBuilderMIPS::VisitXor(HXor* instruction) { |
| 6850 | HandleBinaryOp(instruction); |
| 6851 | } |
| 6852 | |
| 6853 | void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) { |
| 6854 | HandleBinaryOp(instruction); |
| 6855 | } |
| 6856 | |
| 6857 | void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 6858 | // Nothing to do, this should be removed during prepare for register allocator. |
| 6859 | LOG(FATAL) << "Unreachable"; |
| 6860 | } |
| 6861 | |
| 6862 | void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 6863 | // Nothing to do, this should be removed during prepare for register allocator. |
| 6864 | LOG(FATAL) << "Unreachable"; |
| 6865 | } |
| 6866 | |
| 6867 | void LocationsBuilderMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6868 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6869 | } |
| 6870 | |
| 6871 | void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6872 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6873 | } |
| 6874 | |
| 6875 | void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6876 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6877 | } |
| 6878 | |
| 6879 | void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6880 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6881 | } |
| 6882 | |
| 6883 | void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6884 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6885 | } |
| 6886 | |
| 6887 | void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6888 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6889 | } |
| 6890 | |
| 6891 | void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6892 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6893 | } |
| 6894 | |
| 6895 | void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6896 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6897 | } |
| 6898 | |
| 6899 | void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6900 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6901 | } |
| 6902 | |
| 6903 | void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6904 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6905 | } |
| 6906 | |
| 6907 | void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6908 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6909 | } |
| 6910 | |
| 6911 | void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6912 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6913 | } |
| 6914 | |
| 6915 | void LocationsBuilderMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6916 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6917 | } |
| 6918 | |
| 6919 | void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6920 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6921 | } |
| 6922 | |
| 6923 | void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6924 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6925 | } |
| 6926 | |
| 6927 | void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6928 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6929 | } |
| 6930 | |
| 6931 | void LocationsBuilderMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6932 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6933 | } |
| 6934 | |
| 6935 | void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6936 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6937 | } |
| 6938 | |
| 6939 | void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6940 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6941 | } |
| 6942 | |
| 6943 | void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6944 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6945 | } |
| 6946 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6947 | void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6948 | LocationSummary* locations = |
| 6949 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6950 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6951 | } |
| 6952 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 6953 | void InstructionCodeGeneratorMIPS::GenPackedSwitchWithCompares(Register value_reg, |
| 6954 | int32_t lower_bound, |
| 6955 | uint32_t num_entries, |
| 6956 | HBasicBlock* switch_block, |
| 6957 | HBasicBlock* default_block) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6958 | // Create a set of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6959 | Register temp_reg = TMP; |
| 6960 | __ Addiu32(temp_reg, value_reg, -lower_bound); |
| 6961 | // Jump to default if index is negative |
| 6962 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 6963 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 6964 | __ Bltz(temp_reg, codegen_->GetLabelOf(default_block)); |
| 6965 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 6966 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6967 | // Jump to successors[0] if value == lower_bound. |
| 6968 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 6969 | int32_t last_index = 0; |
| 6970 | for (; num_entries - last_index > 2; last_index += 2) { |
| 6971 | __ Addiu(temp_reg, temp_reg, -2); |
| 6972 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 6973 | __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 6974 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 6975 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 6976 | } |
| 6977 | if (num_entries - last_index == 2) { |
| 6978 | // The last missing case_value. |
| 6979 | __ Addiu(temp_reg, temp_reg, -1); |
| 6980 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6981 | } |
| 6982 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6983 | // And the default for any other value. |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 6984 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6985 | __ B(codegen_->GetLabelOf(default_block)); |
| 6986 | } |
| 6987 | } |
| 6988 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 6989 | void InstructionCodeGeneratorMIPS::GenTableBasedPackedSwitch(Register value_reg, |
| 6990 | Register constant_area, |
| 6991 | int32_t lower_bound, |
| 6992 | uint32_t num_entries, |
| 6993 | HBasicBlock* switch_block, |
| 6994 | HBasicBlock* default_block) { |
| 6995 | // Create a jump table. |
| 6996 | std::vector<MipsLabel*> labels(num_entries); |
| 6997 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 6998 | for (uint32_t i = 0; i < num_entries; i++) { |
| 6999 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 7000 | } |
| 7001 | JumpTable* table = __ CreateJumpTable(std::move(labels)); |
| 7002 | |
| 7003 | // Is the value in range? |
| 7004 | __ Addiu32(TMP, value_reg, -lower_bound); |
| 7005 | if (IsInt<16>(static_cast<int32_t>(num_entries))) { |
| 7006 | __ Sltiu(AT, TMP, num_entries); |
| 7007 | __ Beqz(AT, codegen_->GetLabelOf(default_block)); |
| 7008 | } else { |
| 7009 | __ LoadConst32(AT, num_entries); |
| 7010 | __ Bgeu(TMP, AT, codegen_->GetLabelOf(default_block)); |
| 7011 | } |
| 7012 | |
| 7013 | // We are in the range of the table. |
| 7014 | // Load the target address from the jump table, indexing by the value. |
| 7015 | __ LoadLabelAddress(AT, constant_area, table->GetLabel()); |
| 7016 | __ Sll(TMP, TMP, 2); |
| 7017 | __ Addu(TMP, TMP, AT); |
| 7018 | __ Lw(TMP, TMP, 0); |
| 7019 | // Compute the absolute target address by adding the table start address |
| 7020 | // (the table contains offsets to targets relative to its start). |
| 7021 | __ Addu(TMP, TMP, AT); |
| 7022 | // And jump. |
| 7023 | __ Jr(TMP); |
| 7024 | __ NopIfNoReordering(); |
| 7025 | } |
| 7026 | |
| 7027 | void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7028 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7029 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7030 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7031 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7032 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 7033 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7034 | |
| 7035 | if (codegen_->GetInstructionSetFeatures().IsR6() && |
| 7036 | num_entries > kPackedSwitchJumpTableThreshold) { |
| 7037 | // R6 uses PC-relative addressing to access the jump table. |
| 7038 | // R2, OTOH, requires an HMipsComputeBaseMethodAddress input to access |
| 7039 | // the jump table and it is implemented by changing HPackedSwitch to |
| 7040 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress. |
| 7041 | // See VisitMipsPackedSwitch() for the table-based implementation on R2. |
| 7042 | GenTableBasedPackedSwitch(value_reg, |
| 7043 | ZERO, |
| 7044 | lower_bound, |
| 7045 | num_entries, |
| 7046 | switch_block, |
| 7047 | default_block); |
| 7048 | } else { |
| 7049 | GenPackedSwitchWithCompares(value_reg, |
| 7050 | lower_bound, |
| 7051 | num_entries, |
| 7052 | switch_block, |
| 7053 | default_block); |
| 7054 | } |
| 7055 | } |
| 7056 | |
| 7057 | void LocationsBuilderMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 7058 | LocationSummary* locations = |
| 7059 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7060 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7061 | // Constant area pointer (HMipsComputeBaseMethodAddress). |
| 7062 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7063 | } |
| 7064 | |
| 7065 | void InstructionCodeGeneratorMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 7066 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7067 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7068 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7069 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7070 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7071 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 7072 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7073 | |
| 7074 | // This is an R2-only path. HPackedSwitch has been changed to |
| 7075 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress |
| 7076 | // required to address the jump table relative to PC. |
| 7077 | GenTableBasedPackedSwitch(value_reg, |
| 7078 | constant_area, |
| 7079 | lower_bound, |
| 7080 | num_entries, |
| 7081 | switch_block, |
| 7082 | default_block); |
| 7083 | } |
| 7084 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7085 | void LocationsBuilderMIPS::VisitMipsComputeBaseMethodAddress( |
| 7086 | HMipsComputeBaseMethodAddress* insn) { |
| 7087 | LocationSummary* locations = |
| 7088 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7089 | locations->SetOut(Location::RequiresRegister()); |
| 7090 | } |
| 7091 | |
| 7092 | void InstructionCodeGeneratorMIPS::VisitMipsComputeBaseMethodAddress( |
| 7093 | HMipsComputeBaseMethodAddress* insn) { |
| 7094 | LocationSummary* locations = insn->GetLocations(); |
| 7095 | Register reg = locations->Out().AsRegister<Register>(); |
| 7096 | |
| 7097 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
| 7098 | |
| 7099 | // Generate a dummy PC-relative call to obtain PC. |
| 7100 | __ Nal(); |
| 7101 | // Grab the return address off RA. |
| 7102 | __ Move(reg, RA); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7103 | // TODO: Can we share this code with that of VisitMipsDexCacheArraysBase()? |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7104 | |
| 7105 | // Remember this offset (the obtained PC value) for later use with constant area. |
| 7106 | __ BindPcRelBaseLabel(); |
| 7107 | } |
| 7108 | |
| 7109 | void LocationsBuilderMIPS::VisitMipsDexCacheArraysBase(HMipsDexCacheArraysBase* base) { |
| 7110 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 7111 | locations->SetOut(Location::RequiresRegister()); |
| 7112 | } |
| 7113 | |
| 7114 | void InstructionCodeGeneratorMIPS::VisitMipsDexCacheArraysBase(HMipsDexCacheArraysBase* base) { |
| 7115 | Register reg = base->GetLocations()->Out().AsRegister<Register>(); |
| 7116 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
| 7117 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Alexey Frunze | 6b892cd | 2017-01-03 17:11:38 -0800 | [diff] [blame] | 7118 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
| 7119 | bool reordering = __ SetReorder(false); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7120 | // 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] | 7121 | codegen_->EmitPcRelativeAddressPlaceholderHigh(info, reg, ZERO); |
| 7122 | __ Addiu(reg, reg, /* placeholder */ 0x5678); |
| 7123 | __ SetReorder(reordering); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7124 | } |
| 7125 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7126 | void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 7127 | // The trampoline uses the same calling convention as dex calling conventions, |
| 7128 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 7129 | // the method_idx. |
| 7130 | HandleInvoke(invoke); |
| 7131 | } |
| 7132 | |
| 7133 | void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 7134 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 7135 | } |
| 7136 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 7137 | void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 7138 | LocationSummary* locations = |
| 7139 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7140 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7141 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7142 | } |
| 7143 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 7144 | void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 7145 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7146 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7147 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 7148 | instruction->GetIndex(), kMipsPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7149 | __ LoadFromOffset(kLoadWord, |
| 7150 | locations->Out().AsRegister<Register>(), |
| 7151 | locations->InAt(0).AsRegister<Register>(), |
| 7152 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 7153 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7154 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 7155 | instruction->GetIndex(), kMipsPointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 7156 | __ LoadFromOffset(kLoadWord, |
| 7157 | locations->Out().AsRegister<Register>(), |
| 7158 | locations->InAt(0).AsRegister<Register>(), |
| 7159 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7160 | __ LoadFromOffset(kLoadWord, |
| 7161 | locations->Out().AsRegister<Register>(), |
| 7162 | locations->Out().AsRegister<Register>(), |
| 7163 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 7164 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7165 | } |
| 7166 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7167 | #undef __ |
| 7168 | #undef QUICK_ENTRY_POINT |
| 7169 | |
| 7170 | } // namespace mips |
| 7171 | } // namespace art |