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); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 261 | mips_codegen->EmitPcRelativeAddressPlaceholder(info, TMP, base); |
| 262 | __ StoreToOffset(kStoreWord, out.AsRegister<Register>(), TMP, 0); |
| 263 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 264 | __ B(GetExitLabel()); |
| 265 | } |
| 266 | |
| 267 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS"; } |
| 268 | |
| 269 | private: |
| 270 | // The class this slow path will load. |
| 271 | HLoadClass* const cls_; |
| 272 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 273 | // The dex PC of `at_`. |
| 274 | const uint32_t dex_pc_; |
| 275 | |
| 276 | // Whether to initialize the class. |
| 277 | const bool do_clinit_; |
| 278 | |
| 279 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS); |
| 280 | }; |
| 281 | |
| 282 | class LoadStringSlowPathMIPS : public SlowPathCodeMIPS { |
| 283 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 284 | explicit LoadStringSlowPathMIPS(HLoadString* instruction) : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 285 | |
| 286 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 287 | LocationSummary* locations = instruction_->GetLocations(); |
| 288 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 289 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 290 | |
| 291 | __ Bind(GetEntryLabel()); |
| 292 | SaveLiveRegisters(codegen, locations); |
| 293 | |
| 294 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 295 | HLoadString* load = instruction_->AsLoadString(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 296 | const dex::StringIndex string_index = load->GetStringIndex(); |
| 297 | __ LoadConst32(calling_convention.GetRegisterAt(0), string_index.index_); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 298 | mips_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 299 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 300 | Primitive::Type type = instruction_->GetType(); |
| 301 | mips_codegen->MoveLocation(locations->Out(), |
| 302 | calling_convention.GetReturnLocation(type), |
| 303 | type); |
| 304 | |
| 305 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 306 | |
| 307 | // Store the resolved String to the BSS entry. |
| 308 | // TODO: Change art_quick_resolve_string to kSaveEverything and use a temporary for the |
| 309 | // .bss entry address in the fast path, so that we can avoid another calculation here. |
| 310 | bool isR6 = mips_codegen->GetInstructionSetFeatures().IsR6(); |
| 311 | Register base = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>(); |
| 312 | Register out = locations->Out().AsRegister<Register>(); |
| 313 | DCHECK_NE(out, AT); |
| 314 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
| 315 | mips_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index); |
| 316 | mips_codegen->EmitPcRelativeAddressPlaceholder(info, TMP, base); |
| 317 | __ StoreToOffset(kStoreWord, out, TMP, 0); |
| 318 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 319 | __ B(GetExitLabel()); |
| 320 | } |
| 321 | |
| 322 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS"; } |
| 323 | |
| 324 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 325 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS); |
| 326 | }; |
| 327 | |
| 328 | class NullCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 329 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 330 | explicit NullCheckSlowPathMIPS(HNullCheck* instr) : SlowPathCodeMIPS(instr) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 331 | |
| 332 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 333 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 334 | __ Bind(GetEntryLabel()); |
| 335 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 336 | // Live registers will be restored in the catch block if caught. |
| 337 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 338 | } |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 339 | mips_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 340 | instruction_, |
| 341 | instruction_->GetDexPc(), |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 342 | this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 343 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 344 | } |
| 345 | |
| 346 | bool IsFatal() const OVERRIDE { return true; } |
| 347 | |
| 348 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS"; } |
| 349 | |
| 350 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 351 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS); |
| 352 | }; |
| 353 | |
| 354 | class SuspendCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 355 | public: |
| 356 | SuspendCheckSlowPathMIPS(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 357 | : SlowPathCodeMIPS(instruction), successor_(successor) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 358 | |
| 359 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 360 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 361 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 362 | mips_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 363 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 364 | if (successor_ == nullptr) { |
| 365 | __ B(GetReturnLabel()); |
| 366 | } else { |
| 367 | __ B(mips_codegen->GetLabelOf(successor_)); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | MipsLabel* GetReturnLabel() { |
| 372 | DCHECK(successor_ == nullptr); |
| 373 | return &return_label_; |
| 374 | } |
| 375 | |
| 376 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS"; } |
| 377 | |
| 378 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 379 | // If not null, the block to branch to after the suspend check. |
| 380 | HBasicBlock* const successor_; |
| 381 | |
| 382 | // If `successor_` is null, the label to branch to after the suspend check. |
| 383 | MipsLabel return_label_; |
| 384 | |
| 385 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS); |
| 386 | }; |
| 387 | |
| 388 | class TypeCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 389 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 390 | explicit TypeCheckSlowPathMIPS(HInstruction* instruction) : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 391 | |
| 392 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 393 | LocationSummary* locations = instruction_->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 394 | uint32_t dex_pc = instruction_->GetDexPc(); |
| 395 | DCHECK(instruction_->IsCheckCast() |
| 396 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 397 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 398 | |
| 399 | __ Bind(GetEntryLabel()); |
| 400 | SaveLiveRegisters(codegen, locations); |
| 401 | |
| 402 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 403 | // move resolver. |
| 404 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 405 | codegen->EmitParallelMoves(locations->InAt(0), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 406 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 407 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 408 | locations->InAt(1), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 409 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 410 | Primitive::kPrimNot); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 411 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 412 | mips_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 413 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 414 | Primitive::Type ret_type = instruction_->GetType(); |
| 415 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 416 | mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 417 | } else { |
| 418 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 419 | mips_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 420 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | RestoreLiveRegisters(codegen, locations); |
| 424 | __ B(GetExitLabel()); |
| 425 | } |
| 426 | |
| 427 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; } |
| 428 | |
| 429 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 430 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS); |
| 431 | }; |
| 432 | |
| 433 | class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS { |
| 434 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 435 | explicit DeoptimizationSlowPathMIPS(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 436 | : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 437 | |
| 438 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 439 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 440 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 441 | mips_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 442 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; } |
| 446 | |
| 447 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 448 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS); |
| 449 | }; |
| 450 | |
| 451 | CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph, |
| 452 | const MipsInstructionSetFeatures& isa_features, |
| 453 | const CompilerOptions& compiler_options, |
| 454 | OptimizingCompilerStats* stats) |
| 455 | : CodeGenerator(graph, |
| 456 | kNumberOfCoreRegisters, |
| 457 | kNumberOfFRegisters, |
| 458 | kNumberOfRegisterPairs, |
| 459 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 460 | arraysize(kCoreCalleeSaves)), |
| 461 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 462 | arraysize(kFpuCalleeSaves)), |
| 463 | compiler_options, |
| 464 | stats), |
| 465 | block_labels_(nullptr), |
| 466 | location_builder_(graph, this), |
| 467 | instruction_visitor_(graph, this), |
| 468 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 469 | assembler_(graph->GetArena(), &isa_features), |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 470 | isa_features_(isa_features), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 471 | uint32_literals_(std::less<uint32_t>(), |
| 472 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 473 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 474 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 475 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 476 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 477 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 478 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 479 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame^] | 480 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 481 | boot_image_address_patches_(std::less<uint32_t>(), |
| 482 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 483 | clobbered_ra_(false) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 484 | // Save RA (containing the return address) to mimic Quick. |
| 485 | AddAllocatedRegister(Location::RegisterLocation(RA)); |
| 486 | } |
| 487 | |
| 488 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 489 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 490 | #define __ down_cast<MipsAssembler*>(GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 491 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value() |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 492 | |
| 493 | void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) { |
| 494 | // Ensure that we fix up branches. |
| 495 | __ FinalizeCode(); |
| 496 | |
| 497 | // Adjust native pc offsets in stack maps. |
| 498 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
| 499 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; |
| 500 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 501 | DCHECK_GE(new_position, old_position); |
| 502 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 503 | } |
| 504 | |
| 505 | // Adjust pc offsets for the disassembly information. |
| 506 | if (disasm_info_ != nullptr) { |
| 507 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 508 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 509 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 510 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 511 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 512 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 513 | } |
| 514 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 515 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 516 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | CodeGenerator::Finalize(allocator); |
| 521 | } |
| 522 | |
| 523 | MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const { |
| 524 | return codegen_->GetAssembler(); |
| 525 | } |
| 526 | |
| 527 | void ParallelMoveResolverMIPS::EmitMove(size_t index) { |
| 528 | DCHECK_LT(index, moves_.size()); |
| 529 | MoveOperands* move = moves_[index]; |
| 530 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); |
| 531 | } |
| 532 | |
| 533 | void ParallelMoveResolverMIPS::EmitSwap(size_t index) { |
| 534 | DCHECK_LT(index, moves_.size()); |
| 535 | MoveOperands* move = moves_[index]; |
| 536 | Primitive::Type type = move->GetType(); |
| 537 | Location loc1 = move->GetDestination(); |
| 538 | Location loc2 = move->GetSource(); |
| 539 | |
| 540 | DCHECK(!loc1.IsConstant()); |
| 541 | DCHECK(!loc2.IsConstant()); |
| 542 | |
| 543 | if (loc1.Equals(loc2)) { |
| 544 | return; |
| 545 | } |
| 546 | |
| 547 | if (loc1.IsRegister() && loc2.IsRegister()) { |
| 548 | // Swap 2 GPRs. |
| 549 | Register r1 = loc1.AsRegister<Register>(); |
| 550 | Register r2 = loc2.AsRegister<Register>(); |
| 551 | __ Move(TMP, r2); |
| 552 | __ Move(r2, r1); |
| 553 | __ Move(r1, TMP); |
| 554 | } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) { |
| 555 | FRegister f1 = loc1.AsFpuRegister<FRegister>(); |
| 556 | FRegister f2 = loc2.AsFpuRegister<FRegister>(); |
| 557 | if (type == Primitive::kPrimFloat) { |
| 558 | __ MovS(FTMP, f2); |
| 559 | __ MovS(f2, f1); |
| 560 | __ MovS(f1, FTMP); |
| 561 | } else { |
| 562 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 563 | __ MovD(FTMP, f2); |
| 564 | __ MovD(f2, f1); |
| 565 | __ MovD(f1, FTMP); |
| 566 | } |
| 567 | } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) || |
| 568 | (loc1.IsFpuRegister() && loc2.IsRegister())) { |
| 569 | // Swap FPR and GPR. |
| 570 | DCHECK_EQ(type, Primitive::kPrimFloat); // Can only swap a float. |
| 571 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 572 | : loc2.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 573 | Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 574 | __ Move(TMP, r2); |
| 575 | __ Mfc1(r2, f1); |
| 576 | __ Mtc1(TMP, f1); |
| 577 | } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) { |
| 578 | // Swap 2 GPR register pairs. |
| 579 | Register r1 = loc1.AsRegisterPairLow<Register>(); |
| 580 | Register r2 = loc2.AsRegisterPairLow<Register>(); |
| 581 | __ Move(TMP, r2); |
| 582 | __ Move(r2, r1); |
| 583 | __ Move(r1, TMP); |
| 584 | r1 = loc1.AsRegisterPairHigh<Register>(); |
| 585 | r2 = loc2.AsRegisterPairHigh<Register>(); |
| 586 | __ Move(TMP, r2); |
| 587 | __ Move(r2, r1); |
| 588 | __ Move(r1, TMP); |
| 589 | } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) || |
| 590 | (loc1.IsFpuRegister() && loc2.IsRegisterPair())) { |
| 591 | // Swap FPR and GPR register pair. |
| 592 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 593 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 594 | : loc2.AsFpuRegister<FRegister>(); |
| 595 | Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 596 | : loc2.AsRegisterPairLow<Register>(); |
| 597 | Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 598 | : loc2.AsRegisterPairHigh<Register>(); |
| 599 | // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and |
| 600 | // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR |
| 601 | // unpredictable and the following mfch1 will fail. |
| 602 | __ Mfc1(TMP, f1); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 603 | __ MoveFromFpuHigh(AT, f1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 604 | __ Mtc1(r2_l, f1); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 605 | __ MoveToFpuHigh(r2_h, f1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 606 | __ Move(r2_l, TMP); |
| 607 | __ Move(r2_h, AT); |
| 608 | } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) { |
| 609 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false); |
| 610 | } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) { |
| 611 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 612 | } else if ((loc1.IsRegister() && loc2.IsStackSlot()) || |
| 613 | (loc1.IsStackSlot() && loc2.IsRegister())) { |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 614 | Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>(); |
| 615 | intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex(); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 616 | __ Move(TMP, reg); |
| 617 | __ LoadFromOffset(kLoadWord, reg, SP, offset); |
| 618 | __ StoreToOffset(kStoreWord, TMP, SP, offset); |
| 619 | } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) || |
| 620 | (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) { |
| 621 | Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 622 | : loc2.AsRegisterPairLow<Register>(); |
| 623 | Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 624 | : loc2.AsRegisterPairHigh<Register>(); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 625 | intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex(); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 626 | intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize) |
| 627 | : loc2.GetHighStackIndex(kMipsWordSize); |
| 628 | __ Move(TMP, reg_l); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 629 | __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 630 | __ StoreToOffset(kStoreWord, TMP, SP, offset_l); |
David Brazdil | 04d3e87 | 2016-01-29 09:50:09 +0000 | [diff] [blame] | 631 | __ Move(TMP, reg_h); |
| 632 | __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h); |
| 633 | __ StoreToOffset(kStoreWord, TMP, SP, offset_h); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 634 | } else if (loc1.IsFpuRegister() || loc2.IsFpuRegister()) { |
| 635 | FRegister reg = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 636 | : loc2.AsFpuRegister<FRegister>(); |
| 637 | intptr_t offset = loc1.IsFpuRegister() ? loc2.GetStackIndex() : loc1.GetStackIndex(); |
| 638 | if (type == Primitive::kPrimFloat) { |
| 639 | __ MovS(FTMP, reg); |
| 640 | __ LoadSFromOffset(reg, SP, offset); |
| 641 | __ StoreSToOffset(FTMP, SP, offset); |
| 642 | } else { |
| 643 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 644 | __ MovD(FTMP, reg); |
| 645 | __ LoadDFromOffset(reg, SP, offset); |
| 646 | __ StoreDToOffset(FTMP, SP, offset); |
| 647 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 648 | } else { |
| 649 | LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported"; |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | void ParallelMoveResolverMIPS::RestoreScratch(int reg) { |
| 654 | __ Pop(static_cast<Register>(reg)); |
| 655 | } |
| 656 | |
| 657 | void ParallelMoveResolverMIPS::SpillScratch(int reg) { |
| 658 | __ Push(static_cast<Register>(reg)); |
| 659 | } |
| 660 | |
| 661 | void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) { |
| 662 | // Allocate a scratch register other than TMP, if available. |
| 663 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be |
| 664 | // automatically unspilled when the scratch scope object is destroyed). |
| 665 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); |
| 666 | // If V0 spills onto the stack, SP-relative offsets need to be adjusted. |
| 667 | int stack_offset = ensure_scratch.IsSpilled() ? kMipsWordSize : 0; |
| 668 | for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) { |
| 669 | __ LoadFromOffset(kLoadWord, |
| 670 | Register(ensure_scratch.GetRegister()), |
| 671 | SP, |
| 672 | index1 + stack_offset); |
| 673 | __ LoadFromOffset(kLoadWord, |
| 674 | TMP, |
| 675 | SP, |
| 676 | index2 + stack_offset); |
| 677 | __ StoreToOffset(kStoreWord, |
| 678 | Register(ensure_scratch.GetRegister()), |
| 679 | SP, |
| 680 | index2 + stack_offset); |
| 681 | __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset); |
| 682 | } |
| 683 | } |
| 684 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 685 | void CodeGeneratorMIPS::ComputeSpillMask() { |
| 686 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 687 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 688 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 689 | // If there're FPU callee-saved registers and there's an odd number of GPR callee-saved |
| 690 | // registers, include the ZERO register to force alignment of FPU callee-saved registers |
| 691 | // within the stack frame. |
| 692 | if ((fpu_spill_mask_ != 0) && (POPCOUNT(core_spill_mask_) % 2 != 0)) { |
| 693 | core_spill_mask_ |= (1 << ZERO); |
| 694 | } |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | bool CodeGeneratorMIPS::HasAllocatedCalleeSaveRegisters() const { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 698 | // 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] | 699 | // (this can happen in leaf methods), force CodeGenerator::InitializeCodeGeneration() |
| 700 | // into the path that creates a stack frame so that RA can be explicitly saved and restored. |
| 701 | // RA can't otherwise be saved/restored when it's the only spilled register. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 702 | // TODO: Can this be improved? It causes creation of a stack frame (while RA might be |
| 703 | // saved in an unused temporary register) and saving of RA and the current method pointer |
| 704 | // in the frame. |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 705 | return CodeGenerator::HasAllocatedCalleeSaveRegisters() || clobbered_ra_; |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 708 | static dwarf::Reg DWARFReg(Register reg) { |
| 709 | return dwarf::Reg::MipsCore(static_cast<int>(reg)); |
| 710 | } |
| 711 | |
| 712 | // TODO: mapping of floating-point registers to DWARF. |
| 713 | |
| 714 | void CodeGeneratorMIPS::GenerateFrameEntry() { |
| 715 | __ Bind(&frame_entry_label_); |
| 716 | |
| 717 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips) || !IsLeafMethod(); |
| 718 | |
| 719 | if (do_overflow_check) { |
| 720 | __ LoadFromOffset(kLoadWord, |
| 721 | ZERO, |
| 722 | SP, |
| 723 | -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips))); |
| 724 | RecordPcInfo(nullptr, 0); |
| 725 | } |
| 726 | |
| 727 | if (HasEmptyFrame()) { |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 728 | CHECK_EQ(fpu_spill_mask_, 0u); |
| 729 | CHECK_EQ(core_spill_mask_, 1u << RA); |
| 730 | CHECK(!clobbered_ra_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 731 | return; |
| 732 | } |
| 733 | |
| 734 | // Make sure the frame size isn't unreasonably large. |
| 735 | if (GetFrameSize() > GetStackOverflowReservedBytes(kMips)) { |
| 736 | LOG(FATAL) << "Stack frame larger than " << GetStackOverflowReservedBytes(kMips) << " bytes"; |
| 737 | } |
| 738 | |
| 739 | // Spill callee-saved registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 740 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 741 | uint32_t ofs = GetFrameSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 742 | __ IncreaseFrameSize(ofs); |
| 743 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 744 | for (uint32_t mask = core_spill_mask_; mask != 0; ) { |
| 745 | Register reg = static_cast<Register>(MostSignificantBit(mask)); |
| 746 | mask ^= 1u << reg; |
| 747 | ofs -= kMipsWordSize; |
| 748 | // The ZERO register is only included for alignment. |
| 749 | if (reg != ZERO) { |
| 750 | __ StoreToOffset(kStoreWord, reg, SP, ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 751 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 752 | } |
| 753 | } |
| 754 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 755 | for (uint32_t mask = fpu_spill_mask_; mask != 0; ) { |
| 756 | FRegister reg = static_cast<FRegister>(MostSignificantBit(mask)); |
| 757 | mask ^= 1u << reg; |
| 758 | ofs -= kMipsDoublewordSize; |
| 759 | __ StoreDToOffset(reg, SP, ofs); |
| 760 | // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 761 | } |
| 762 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 763 | // Save the current method if we need it. Note that we do not |
| 764 | // do this in HCurrentMethod, as the instruction might have been removed |
| 765 | // in the SSA graph. |
| 766 | if (RequiresCurrentMethod()) { |
| 767 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
| 768 | } |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 769 | |
| 770 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 771 | // Initialize should deoptimize flag to 0. |
| 772 | __ StoreToOffset(kStoreWord, ZERO, SP, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 773 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | void CodeGeneratorMIPS::GenerateFrameExit() { |
| 777 | __ cfi().RememberState(); |
| 778 | |
| 779 | if (!HasEmptyFrame()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 780 | // Restore callee-saved registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 781 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 782 | // For better instruction scheduling restore RA before other registers. |
| 783 | uint32_t ofs = GetFrameSize(); |
| 784 | for (uint32_t mask = core_spill_mask_; mask != 0; ) { |
| 785 | Register reg = static_cast<Register>(MostSignificantBit(mask)); |
| 786 | mask ^= 1u << reg; |
| 787 | ofs -= kMipsWordSize; |
| 788 | // The ZERO register is only included for alignment. |
| 789 | if (reg != ZERO) { |
| 790 | __ LoadFromOffset(kLoadWord, reg, SP, ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 791 | __ cfi().Restore(DWARFReg(reg)); |
| 792 | } |
| 793 | } |
| 794 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 795 | for (uint32_t mask = fpu_spill_mask_; mask != 0; ) { |
| 796 | FRegister reg = static_cast<FRegister>(MostSignificantBit(mask)); |
| 797 | mask ^= 1u << reg; |
| 798 | ofs -= kMipsDoublewordSize; |
| 799 | __ LoadDFromOffset(reg, SP, ofs); |
| 800 | // TODO: __ cfi().Restore(DWARFReg(reg)); |
| 801 | } |
| 802 | |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 803 | size_t frame_size = GetFrameSize(); |
| 804 | // Adjust the stack pointer in the delay slot if doing so doesn't break CFI. |
| 805 | bool exchange = IsInt<16>(static_cast<int32_t>(frame_size)); |
| 806 | bool reordering = __ SetReorder(false); |
| 807 | if (exchange) { |
| 808 | __ Jr(RA); |
| 809 | __ DecreaseFrameSize(frame_size); // Single instruction in delay slot. |
| 810 | } else { |
| 811 | __ DecreaseFrameSize(frame_size); |
| 812 | __ Jr(RA); |
| 813 | __ Nop(); // In delay slot. |
| 814 | } |
| 815 | __ SetReorder(reordering); |
| 816 | } else { |
| 817 | __ Jr(RA); |
| 818 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 819 | } |
| 820 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 821 | __ cfi().RestoreState(); |
| 822 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 823 | } |
| 824 | |
| 825 | void CodeGeneratorMIPS::Bind(HBasicBlock* block) { |
| 826 | __ Bind(GetLabelOf(block)); |
| 827 | } |
| 828 | |
| 829 | void CodeGeneratorMIPS::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
| 830 | if (src.Equals(dst)) { |
| 831 | return; |
| 832 | } |
| 833 | |
| 834 | if (src.IsConstant()) { |
| 835 | MoveConstant(dst, src.GetConstant()); |
| 836 | } else { |
| 837 | if (Primitive::Is64BitType(dst_type)) { |
| 838 | Move64(dst, src); |
| 839 | } else { |
| 840 | Move32(dst, src); |
| 841 | } |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | void CodeGeneratorMIPS::Move32(Location destination, Location source) { |
| 846 | if (source.Equals(destination)) { |
| 847 | return; |
| 848 | } |
| 849 | |
| 850 | if (destination.IsRegister()) { |
| 851 | if (source.IsRegister()) { |
| 852 | __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 853 | } else if (source.IsFpuRegister()) { |
| 854 | __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>()); |
| 855 | } else { |
| 856 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 857 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
| 858 | } |
| 859 | } else if (destination.IsFpuRegister()) { |
| 860 | if (source.IsRegister()) { |
| 861 | __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>()); |
| 862 | } else if (source.IsFpuRegister()) { |
| 863 | __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 864 | } else { |
| 865 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 866 | __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 867 | } |
| 868 | } else { |
| 869 | DCHECK(destination.IsStackSlot()) << destination; |
| 870 | if (source.IsRegister()) { |
| 871 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
| 872 | } else if (source.IsFpuRegister()) { |
| 873 | __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex()); |
| 874 | } else { |
| 875 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 876 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 877 | __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex()); |
| 878 | } |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | void CodeGeneratorMIPS::Move64(Location destination, Location source) { |
| 883 | if (source.Equals(destination)) { |
| 884 | return; |
| 885 | } |
| 886 | |
| 887 | if (destination.IsRegisterPair()) { |
| 888 | if (source.IsRegisterPair()) { |
| 889 | __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 890 | __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 891 | } else if (source.IsFpuRegister()) { |
| 892 | Register dst_high = destination.AsRegisterPairHigh<Register>(); |
| 893 | Register dst_low = destination.AsRegisterPairLow<Register>(); |
| 894 | FRegister src = source.AsFpuRegister<FRegister>(); |
| 895 | __ Mfc1(dst_low, src); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 896 | __ MoveFromFpuHigh(dst_high, src); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 897 | } else { |
| 898 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 899 | int32_t off = source.GetStackIndex(); |
| 900 | Register r = destination.AsRegisterPairLow<Register>(); |
| 901 | __ LoadFromOffset(kLoadDoubleword, r, SP, off); |
| 902 | } |
| 903 | } else if (destination.IsFpuRegister()) { |
| 904 | if (source.IsRegisterPair()) { |
| 905 | FRegister dst = destination.AsFpuRegister<FRegister>(); |
| 906 | Register src_high = source.AsRegisterPairHigh<Register>(); |
| 907 | Register src_low = source.AsRegisterPairLow<Register>(); |
| 908 | __ Mtc1(src_low, dst); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 909 | __ MoveToFpuHigh(src_high, dst); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 910 | } else if (source.IsFpuRegister()) { |
| 911 | __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 912 | } else { |
| 913 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 914 | __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 915 | } |
| 916 | } else { |
| 917 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 918 | int32_t off = destination.GetStackIndex(); |
| 919 | if (source.IsRegisterPair()) { |
| 920 | __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, off); |
| 921 | } else if (source.IsFpuRegister()) { |
| 922 | __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, off); |
| 923 | } else { |
| 924 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 925 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 926 | __ StoreToOffset(kStoreWord, TMP, SP, off); |
| 927 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4); |
| 928 | __ StoreToOffset(kStoreWord, TMP, SP, off + 4); |
| 929 | } |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) { |
| 934 | if (c->IsIntConstant() || c->IsNullConstant()) { |
| 935 | // Move 32 bit constant. |
| 936 | int32_t value = GetInt32ValueOf(c); |
| 937 | if (destination.IsRegister()) { |
| 938 | Register dst = destination.AsRegister<Register>(); |
| 939 | __ LoadConst32(dst, value); |
| 940 | } else { |
| 941 | DCHECK(destination.IsStackSlot()) |
| 942 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 943 | __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 944 | } |
| 945 | } else if (c->IsLongConstant()) { |
| 946 | // Move 64 bit constant. |
| 947 | int64_t value = GetInt64ValueOf(c); |
| 948 | if (destination.IsRegisterPair()) { |
| 949 | Register r_h = destination.AsRegisterPairHigh<Register>(); |
| 950 | Register r_l = destination.AsRegisterPairLow<Register>(); |
| 951 | __ LoadConst64(r_h, r_l, value); |
| 952 | } else { |
| 953 | DCHECK(destination.IsDoubleStackSlot()) |
| 954 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 955 | __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 956 | } |
| 957 | } else if (c->IsFloatConstant()) { |
| 958 | // Move 32 bit float constant. |
| 959 | int32_t value = GetInt32ValueOf(c); |
| 960 | if (destination.IsFpuRegister()) { |
| 961 | __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP); |
| 962 | } else { |
| 963 | DCHECK(destination.IsStackSlot()) |
| 964 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 965 | __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 966 | } |
| 967 | } else { |
| 968 | // Move 64 bit double constant. |
| 969 | DCHECK(c->IsDoubleConstant()) << c->DebugName(); |
| 970 | int64_t value = GetInt64ValueOf(c); |
| 971 | if (destination.IsFpuRegister()) { |
| 972 | FRegister fd = destination.AsFpuRegister<FRegister>(); |
| 973 | __ LoadDConst64(fd, value, TMP); |
| 974 | } else { |
| 975 | DCHECK(destination.IsDoubleStackSlot()) |
| 976 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 977 | __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 978 | } |
| 979 | } |
| 980 | } |
| 981 | |
| 982 | void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) { |
| 983 | DCHECK(destination.IsRegister()); |
| 984 | Register dst = destination.AsRegister<Register>(); |
| 985 | __ LoadConst32(dst, value); |
| 986 | } |
| 987 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 988 | void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 989 | if (location.IsRegister()) { |
| 990 | locations->AddTemp(location); |
Alexey Frunze | c9e94f3 | 2015-10-26 16:11:39 -0700 | [diff] [blame] | 991 | } else if (location.IsRegisterPair()) { |
| 992 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 993 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 994 | } else { |
| 995 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 996 | } |
| 997 | } |
| 998 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 999 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 1000 | inline void CodeGeneratorMIPS::EmitPcRelativeLinkerPatches( |
| 1001 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 1002 | ArenaVector<LinkerPatch>* linker_patches) { |
| 1003 | for (const PcRelativePatchInfo& info : infos) { |
| 1004 | const DexFile& dex_file = info.target_dex_file; |
| 1005 | size_t offset_or_index = info.offset_or_index; |
| 1006 | DCHECK(info.high_label.IsBound()); |
| 1007 | uint32_t high_offset = __ GetLabelLocation(&info.high_label); |
| 1008 | // On R2 we use HMipsComputeBaseMethodAddress and patch relative to |
| 1009 | // the assembler's base label used for PC-relative addressing. |
| 1010 | uint32_t pc_rel_offset = info.pc_rel_label.IsBound() |
| 1011 | ? __ GetLabelLocation(&info.pc_rel_label) |
| 1012 | : __ GetPcRelBaseLabelLocation(); |
| 1013 | linker_patches->push_back(Factory(high_offset, &dex_file, pc_rel_offset, offset_or_index)); |
| 1014 | } |
| 1015 | } |
| 1016 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1017 | void CodeGeneratorMIPS::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 1018 | DCHECK(linker_patches->empty()); |
| 1019 | size_t size = |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1020 | pc_relative_dex_cache_patches_.size() + |
| 1021 | pc_relative_string_patches_.size() + |
| 1022 | pc_relative_type_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame^] | 1023 | type_bss_entry_patches_.size() + |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1024 | boot_image_string_patches_.size() + |
| 1025 | boot_image_type_patches_.size() + |
| 1026 | boot_image_address_patches_.size(); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1027 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1028 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 1029 | linker_patches); |
| 1030 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame^] | 1031 | DCHECK(pc_relative_type_patches_.empty()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1032 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 1033 | linker_patches); |
| 1034 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1035 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 1036 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1037 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 1038 | linker_patches); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1039 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame^] | 1040 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 1041 | linker_patches); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1042 | for (const auto& entry : boot_image_string_patches_) { |
| 1043 | const StringReference& target_string = entry.first; |
| 1044 | Literal* literal = entry.second; |
| 1045 | DCHECK(literal->GetLabel()->IsBound()); |
| 1046 | uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel()); |
| 1047 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 1048 | target_string.dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 1049 | target_string.string_index.index_)); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1050 | } |
| 1051 | for (const auto& entry : boot_image_type_patches_) { |
| 1052 | const TypeReference& target_type = entry.first; |
| 1053 | Literal* literal = entry.second; |
| 1054 | DCHECK(literal->GetLabel()->IsBound()); |
| 1055 | uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel()); |
| 1056 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 1057 | target_type.dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1058 | target_type.type_index.index_)); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1059 | } |
| 1060 | for (const auto& entry : boot_image_address_patches_) { |
| 1061 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
| 1062 | Literal* literal = entry.second; |
| 1063 | DCHECK(literal->GetLabel()->IsBound()); |
| 1064 | uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel()); |
| 1065 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 1066 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame^] | 1067 | DCHECK_EQ(size, linker_patches->size()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeStringPatch( |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1071 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 1072 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeTypePatch( |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1076 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 1077 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1078 | } |
| 1079 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame^] | 1080 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewTypeBssEntryPatch( |
| 1081 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 1082 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 1083 | } |
| 1084 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1085 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeDexCacheArrayPatch( |
| 1086 | const DexFile& dex_file, uint32_t element_offset) { |
| 1087 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 1088 | } |
| 1089 | |
| 1090 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativePatch( |
| 1091 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 1092 | patches->emplace_back(dex_file, offset_or_index); |
| 1093 | return &patches->back(); |
| 1094 | } |
| 1095 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1096 | Literal* CodeGeneratorMIPS::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 1097 | return map->GetOrCreate( |
| 1098 | value, |
| 1099 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
| 1100 | } |
| 1101 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1102 | Literal* CodeGeneratorMIPS::DeduplicateMethodLiteral(MethodReference target_method, |
| 1103 | MethodToLiteralMap* map) { |
| 1104 | return map->GetOrCreate( |
| 1105 | target_method, |
| 1106 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1107 | } |
| 1108 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1109 | Literal* CodeGeneratorMIPS::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 1110 | dex::StringIndex string_index) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1111 | return boot_image_string_patches_.GetOrCreate( |
| 1112 | StringReference(&dex_file, string_index), |
| 1113 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1114 | } |
| 1115 | |
| 1116 | Literal* CodeGeneratorMIPS::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1117 | dex::TypeIndex type_index) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1118 | return boot_image_type_patches_.GetOrCreate( |
| 1119 | TypeReference(&dex_file, type_index), |
| 1120 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1121 | } |
| 1122 | |
| 1123 | Literal* CodeGeneratorMIPS::DeduplicateBootImageAddressLiteral(uint32_t address) { |
| 1124 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 1125 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 1126 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 1127 | } |
| 1128 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1129 | void CodeGeneratorMIPS::EmitPcRelativeAddressPlaceholder( |
| 1130 | PcRelativePatchInfo* info, Register out, Register base) { |
| 1131 | bool reordering = __ SetReorder(false); |
| 1132 | if (GetInstructionSetFeatures().IsR6()) { |
| 1133 | DCHECK_EQ(base, ZERO); |
| 1134 | __ Bind(&info->high_label); |
| 1135 | __ Bind(&info->pc_rel_label); |
| 1136 | // Add a 32-bit offset to PC. |
| 1137 | __ Auipc(out, /* placeholder */ 0x1234); |
| 1138 | __ Addiu(out, out, /* placeholder */ 0x5678); |
| 1139 | } else { |
| 1140 | // If base is ZERO, emit NAL to obtain the actual base. |
| 1141 | if (base == ZERO) { |
| 1142 | // Generate a dummy PC-relative call to obtain PC. |
| 1143 | __ Nal(); |
| 1144 | } |
| 1145 | __ Bind(&info->high_label); |
| 1146 | __ Lui(out, /* placeholder */ 0x1234); |
| 1147 | // If we emitted the NAL, bind the pc_rel_label, otherwise base is a register holding |
| 1148 | // the HMipsComputeBaseMethodAddress which has its own label stored in MipsAssembler. |
| 1149 | if (base == ZERO) { |
| 1150 | __ Bind(&info->pc_rel_label); |
| 1151 | } |
| 1152 | __ Ori(out, out, /* placeholder */ 0x5678); |
| 1153 | // Add a 32-bit offset to PC. |
| 1154 | __ Addu(out, out, (base == ZERO) ? RA : base); |
| 1155 | } |
| 1156 | __ SetReorder(reordering); |
| 1157 | } |
| 1158 | |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1159 | void CodeGeneratorMIPS::MarkGCCard(Register object, |
| 1160 | Register value, |
| 1161 | bool value_can_be_null) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1162 | MipsLabel done; |
| 1163 | Register card = AT; |
| 1164 | Register temp = TMP; |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1165 | if (value_can_be_null) { |
| 1166 | __ Beqz(value, &done); |
| 1167 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1168 | __ LoadFromOffset(kLoadWord, |
| 1169 | card, |
| 1170 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1171 | Thread::CardTableOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1172 | __ Srl(temp, object, gc::accounting::CardTable::kCardShift); |
| 1173 | __ Addu(temp, card, temp); |
| 1174 | __ Sb(card, temp, 0); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 1175 | if (value_can_be_null) { |
| 1176 | __ Bind(&done); |
| 1177 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1178 | } |
| 1179 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1180 | void CodeGeneratorMIPS::SetupBlockedRegisters() const { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1181 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1182 | blocked_core_registers_[ZERO] = true; |
| 1183 | blocked_core_registers_[K0] = true; |
| 1184 | blocked_core_registers_[K1] = true; |
| 1185 | blocked_core_registers_[GP] = true; |
| 1186 | blocked_core_registers_[SP] = true; |
| 1187 | blocked_core_registers_[RA] = true; |
| 1188 | |
| 1189 | // AT and TMP(T8) are used as temporary/scratch registers |
| 1190 | // (similar to how AT is used by MIPS assemblers). |
| 1191 | blocked_core_registers_[AT] = true; |
| 1192 | blocked_core_registers_[TMP] = true; |
| 1193 | blocked_fpu_registers_[FTMP] = true; |
| 1194 | |
| 1195 | // Reserve suspend and thread registers. |
| 1196 | blocked_core_registers_[S0] = true; |
| 1197 | blocked_core_registers_[TR] = true; |
| 1198 | |
| 1199 | // Reserve T9 for function calls |
| 1200 | blocked_core_registers_[T9] = true; |
| 1201 | |
| 1202 | // Reserve odd-numbered FPU registers. |
| 1203 | for (size_t i = 1; i < kNumberOfFRegisters; i += 2) { |
| 1204 | blocked_fpu_registers_[i] = true; |
| 1205 | } |
| 1206 | |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 1207 | if (GetGraph()->IsDebuggable()) { |
| 1208 | // Stubs do not save callee-save floating point registers. If the graph |
| 1209 | // is debuggable, we need to deal with these registers differently. For |
| 1210 | // now, just block them. |
| 1211 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1212 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1213 | } |
| 1214 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1215 | } |
| 1216 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1217 | size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1218 | __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index); |
| 1219 | return kMipsWordSize; |
| 1220 | } |
| 1221 | |
| 1222 | size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1223 | __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index); |
| 1224 | return kMipsWordSize; |
| 1225 | } |
| 1226 | |
| 1227 | size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1228 | __ StoreDToOffset(FRegister(reg_id), SP, stack_index); |
| 1229 | return kMipsDoublewordSize; |
| 1230 | } |
| 1231 | |
| 1232 | size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1233 | __ LoadDFromOffset(FRegister(reg_id), SP, stack_index); |
| 1234 | return kMipsDoublewordSize; |
| 1235 | } |
| 1236 | |
| 1237 | void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1238 | stream << Register(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1242 | stream << FRegister(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1243 | } |
| 1244 | |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1245 | constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16; |
| 1246 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1247 | void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1248 | HInstruction* instruction, |
| 1249 | uint32_t dex_pc, |
| 1250 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1251 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1252 | bool reordering = __ SetReorder(false); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1253 | __ LoadFromOffset(kLoadWord, T9, TR, GetThreadOffset<kMipsPointerSize>(entrypoint).Int32Value()); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1254 | __ Jalr(T9); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1255 | if (IsDirectEntrypoint(entrypoint)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1256 | // Reserve argument space on stack (for $a0-$a3) for |
| 1257 | // entrypoints that directly reference native implementations. |
| 1258 | // Called function may use this space to store $a0-$a3 regs. |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1259 | __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1260 | __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1261 | } else { |
| 1262 | __ Nop(); // In delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1263 | } |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1264 | __ SetReorder(reordering); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1265 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1266 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1267 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path, |
| 1271 | Register class_reg) { |
| 1272 | __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 1273 | __ LoadConst32(AT, mirror::Class::kStatusInitialized); |
| 1274 | __ Blt(TMP, AT, slow_path->GetEntryLabel()); |
| 1275 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 1276 | __ Sync(0); |
| 1277 | __ Bind(slow_path->GetExitLabel()); |
| 1278 | } |
| 1279 | |
| 1280 | void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1281 | __ Sync(0); // Only stype 0 is supported. |
| 1282 | } |
| 1283 | |
| 1284 | void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1285 | HBasicBlock* successor) { |
| 1286 | SuspendCheckSlowPathMIPS* slow_path = |
| 1287 | new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS(instruction, successor); |
| 1288 | codegen_->AddSlowPath(slow_path); |
| 1289 | |
| 1290 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1291 | TMP, |
| 1292 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1293 | Thread::ThreadFlagsOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1294 | if (successor == nullptr) { |
| 1295 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
| 1296 | __ Bind(slow_path->GetReturnLabel()); |
| 1297 | } else { |
| 1298 | __ Beqz(TMP, codegen_->GetLabelOf(successor)); |
| 1299 | __ B(slow_path->GetEntryLabel()); |
| 1300 | // slow_path will return to GetLabelOf(successor). |
| 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph, |
| 1305 | CodeGeneratorMIPS* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1306 | : InstructionCodeGenerator(graph, codegen), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1307 | assembler_(codegen->GetAssembler()), |
| 1308 | codegen_(codegen) {} |
| 1309 | |
| 1310 | void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1311 | DCHECK_EQ(instruction->InputCount(), 2U); |
| 1312 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1313 | Primitive::Type type = instruction->GetResultType(); |
| 1314 | switch (type) { |
| 1315 | case Primitive::kPrimInt: { |
| 1316 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1317 | HInstruction* right = instruction->InputAt(1); |
| 1318 | bool can_use_imm = false; |
| 1319 | if (right->IsConstant()) { |
| 1320 | int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant()); |
| 1321 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 1322 | can_use_imm = IsUint<16>(imm); |
| 1323 | } else if (instruction->IsAdd()) { |
| 1324 | can_use_imm = IsInt<16>(imm); |
| 1325 | } else { |
| 1326 | DCHECK(instruction->IsSub()); |
| 1327 | can_use_imm = IsInt<16>(-imm); |
| 1328 | } |
| 1329 | } |
| 1330 | if (can_use_imm) |
| 1331 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 1332 | else |
| 1333 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1334 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1335 | break; |
| 1336 | } |
| 1337 | |
| 1338 | case Primitive::kPrimLong: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1339 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1340 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1341 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1342 | break; |
| 1343 | } |
| 1344 | |
| 1345 | case Primitive::kPrimFloat: |
| 1346 | case Primitive::kPrimDouble: |
| 1347 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 1348 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1349 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1350 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1351 | break; |
| 1352 | |
| 1353 | default: |
| 1354 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 1355 | } |
| 1356 | } |
| 1357 | |
| 1358 | void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1359 | Primitive::Type type = instruction->GetType(); |
| 1360 | LocationSummary* locations = instruction->GetLocations(); |
| 1361 | |
| 1362 | switch (type) { |
| 1363 | case Primitive::kPrimInt: { |
| 1364 | Register dst = locations->Out().AsRegister<Register>(); |
| 1365 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 1366 | Location rhs_location = locations->InAt(1); |
| 1367 | |
| 1368 | Register rhs_reg = ZERO; |
| 1369 | int32_t rhs_imm = 0; |
| 1370 | bool use_imm = rhs_location.IsConstant(); |
| 1371 | if (use_imm) { |
| 1372 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 1373 | } else { |
| 1374 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 1375 | } |
| 1376 | |
| 1377 | if (instruction->IsAnd()) { |
| 1378 | if (use_imm) |
| 1379 | __ Andi(dst, lhs, rhs_imm); |
| 1380 | else |
| 1381 | __ And(dst, lhs, rhs_reg); |
| 1382 | } else if (instruction->IsOr()) { |
| 1383 | if (use_imm) |
| 1384 | __ Ori(dst, lhs, rhs_imm); |
| 1385 | else |
| 1386 | __ Or(dst, lhs, rhs_reg); |
| 1387 | } else if (instruction->IsXor()) { |
| 1388 | if (use_imm) |
| 1389 | __ Xori(dst, lhs, rhs_imm); |
| 1390 | else |
| 1391 | __ Xor(dst, lhs, rhs_reg); |
| 1392 | } else if (instruction->IsAdd()) { |
| 1393 | if (use_imm) |
| 1394 | __ Addiu(dst, lhs, rhs_imm); |
| 1395 | else |
| 1396 | __ Addu(dst, lhs, rhs_reg); |
| 1397 | } else { |
| 1398 | DCHECK(instruction->IsSub()); |
| 1399 | if (use_imm) |
| 1400 | __ Addiu(dst, lhs, -rhs_imm); |
| 1401 | else |
| 1402 | __ Subu(dst, lhs, rhs_reg); |
| 1403 | } |
| 1404 | break; |
| 1405 | } |
| 1406 | |
| 1407 | case Primitive::kPrimLong: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1408 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 1409 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 1410 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 1411 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1412 | Location rhs_location = locations->InAt(1); |
| 1413 | bool use_imm = rhs_location.IsConstant(); |
| 1414 | if (!use_imm) { |
| 1415 | Register rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 1416 | Register rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 1417 | if (instruction->IsAnd()) { |
| 1418 | __ And(dst_low, lhs_low, rhs_low); |
| 1419 | __ And(dst_high, lhs_high, rhs_high); |
| 1420 | } else if (instruction->IsOr()) { |
| 1421 | __ Or(dst_low, lhs_low, rhs_low); |
| 1422 | __ Or(dst_high, lhs_high, rhs_high); |
| 1423 | } else if (instruction->IsXor()) { |
| 1424 | __ Xor(dst_low, lhs_low, rhs_low); |
| 1425 | __ Xor(dst_high, lhs_high, rhs_high); |
| 1426 | } else if (instruction->IsAdd()) { |
| 1427 | if (lhs_low == rhs_low) { |
| 1428 | // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs. |
| 1429 | __ Slt(TMP, lhs_low, ZERO); |
| 1430 | __ Addu(dst_low, lhs_low, rhs_low); |
| 1431 | } else { |
| 1432 | __ Addu(dst_low, lhs_low, rhs_low); |
| 1433 | // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged. |
| 1434 | __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low); |
| 1435 | } |
| 1436 | __ Addu(dst_high, lhs_high, rhs_high); |
| 1437 | __ Addu(dst_high, dst_high, TMP); |
| 1438 | } else { |
| 1439 | DCHECK(instruction->IsSub()); |
| 1440 | __ Sltu(TMP, lhs_low, rhs_low); |
| 1441 | __ Subu(dst_low, lhs_low, rhs_low); |
| 1442 | __ Subu(dst_high, lhs_high, rhs_high); |
| 1443 | __ Subu(dst_high, dst_high, TMP); |
| 1444 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1445 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1446 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 1447 | if (instruction->IsOr()) { |
| 1448 | uint32_t low = Low32Bits(value); |
| 1449 | uint32_t high = High32Bits(value); |
| 1450 | if (IsUint<16>(low)) { |
| 1451 | if (dst_low != lhs_low || low != 0) { |
| 1452 | __ Ori(dst_low, lhs_low, low); |
| 1453 | } |
| 1454 | } else { |
| 1455 | __ LoadConst32(TMP, low); |
| 1456 | __ Or(dst_low, lhs_low, TMP); |
| 1457 | } |
| 1458 | if (IsUint<16>(high)) { |
| 1459 | if (dst_high != lhs_high || high != 0) { |
| 1460 | __ Ori(dst_high, lhs_high, high); |
| 1461 | } |
| 1462 | } else { |
| 1463 | if (high != low) { |
| 1464 | __ LoadConst32(TMP, high); |
| 1465 | } |
| 1466 | __ Or(dst_high, lhs_high, TMP); |
| 1467 | } |
| 1468 | } else if (instruction->IsXor()) { |
| 1469 | uint32_t low = Low32Bits(value); |
| 1470 | uint32_t high = High32Bits(value); |
| 1471 | if (IsUint<16>(low)) { |
| 1472 | if (dst_low != lhs_low || low != 0) { |
| 1473 | __ Xori(dst_low, lhs_low, low); |
| 1474 | } |
| 1475 | } else { |
| 1476 | __ LoadConst32(TMP, low); |
| 1477 | __ Xor(dst_low, lhs_low, TMP); |
| 1478 | } |
| 1479 | if (IsUint<16>(high)) { |
| 1480 | if (dst_high != lhs_high || high != 0) { |
| 1481 | __ Xori(dst_high, lhs_high, high); |
| 1482 | } |
| 1483 | } else { |
| 1484 | if (high != low) { |
| 1485 | __ LoadConst32(TMP, high); |
| 1486 | } |
| 1487 | __ Xor(dst_high, lhs_high, TMP); |
| 1488 | } |
| 1489 | } else if (instruction->IsAnd()) { |
| 1490 | uint32_t low = Low32Bits(value); |
| 1491 | uint32_t high = High32Bits(value); |
| 1492 | if (IsUint<16>(low)) { |
| 1493 | __ Andi(dst_low, lhs_low, low); |
| 1494 | } else if (low != 0xFFFFFFFF) { |
| 1495 | __ LoadConst32(TMP, low); |
| 1496 | __ And(dst_low, lhs_low, TMP); |
| 1497 | } else if (dst_low != lhs_low) { |
| 1498 | __ Move(dst_low, lhs_low); |
| 1499 | } |
| 1500 | if (IsUint<16>(high)) { |
| 1501 | __ Andi(dst_high, lhs_high, high); |
| 1502 | } else if (high != 0xFFFFFFFF) { |
| 1503 | if (high != low) { |
| 1504 | __ LoadConst32(TMP, high); |
| 1505 | } |
| 1506 | __ And(dst_high, lhs_high, TMP); |
| 1507 | } else if (dst_high != lhs_high) { |
| 1508 | __ Move(dst_high, lhs_high); |
| 1509 | } |
| 1510 | } else { |
| 1511 | if (instruction->IsSub()) { |
| 1512 | value = -value; |
| 1513 | } else { |
| 1514 | DCHECK(instruction->IsAdd()); |
| 1515 | } |
| 1516 | int32_t low = Low32Bits(value); |
| 1517 | int32_t high = High32Bits(value); |
| 1518 | if (IsInt<16>(low)) { |
| 1519 | if (dst_low != lhs_low || low != 0) { |
| 1520 | __ Addiu(dst_low, lhs_low, low); |
| 1521 | } |
| 1522 | if (low != 0) { |
| 1523 | __ Sltiu(AT, dst_low, low); |
| 1524 | } |
| 1525 | } else { |
| 1526 | __ LoadConst32(TMP, low); |
| 1527 | __ Addu(dst_low, lhs_low, TMP); |
| 1528 | __ Sltu(AT, dst_low, TMP); |
| 1529 | } |
| 1530 | if (IsInt<16>(high)) { |
| 1531 | if (dst_high != lhs_high || high != 0) { |
| 1532 | __ Addiu(dst_high, lhs_high, high); |
| 1533 | } |
| 1534 | } else { |
| 1535 | if (high != low) { |
| 1536 | __ LoadConst32(TMP, high); |
| 1537 | } |
| 1538 | __ Addu(dst_high, lhs_high, TMP); |
| 1539 | } |
| 1540 | if (low != 0) { |
| 1541 | __ Addu(dst_high, dst_high, AT); |
| 1542 | } |
| 1543 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1544 | } |
| 1545 | break; |
| 1546 | } |
| 1547 | |
| 1548 | case Primitive::kPrimFloat: |
| 1549 | case Primitive::kPrimDouble: { |
| 1550 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 1551 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 1552 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 1553 | if (instruction->IsAdd()) { |
| 1554 | if (type == Primitive::kPrimFloat) { |
| 1555 | __ AddS(dst, lhs, rhs); |
| 1556 | } else { |
| 1557 | __ AddD(dst, lhs, rhs); |
| 1558 | } |
| 1559 | } else { |
| 1560 | DCHECK(instruction->IsSub()); |
| 1561 | if (type == Primitive::kPrimFloat) { |
| 1562 | __ SubS(dst, lhs, rhs); |
| 1563 | } else { |
| 1564 | __ SubD(dst, lhs, rhs); |
| 1565 | } |
| 1566 | } |
| 1567 | break; |
| 1568 | } |
| 1569 | |
| 1570 | default: |
| 1571 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 1572 | } |
| 1573 | } |
| 1574 | |
| 1575 | void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1576 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1577 | |
| 1578 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1579 | Primitive::Type type = instr->GetResultType(); |
| 1580 | switch (type) { |
| 1581 | case Primitive::kPrimInt: |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1582 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1583 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 1584 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1585 | break; |
| 1586 | case Primitive::kPrimLong: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1587 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1588 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 1589 | locations->SetOut(Location::RequiresRegister()); |
| 1590 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1591 | default: |
| 1592 | LOG(FATAL) << "Unexpected shift type " << type; |
| 1593 | } |
| 1594 | } |
| 1595 | |
| 1596 | static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte; |
| 1597 | |
| 1598 | void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1599 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1600 | LocationSummary* locations = instr->GetLocations(); |
| 1601 | Primitive::Type type = instr->GetType(); |
| 1602 | |
| 1603 | Location rhs_location = locations->InAt(1); |
| 1604 | bool use_imm = rhs_location.IsConstant(); |
| 1605 | Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>(); |
| 1606 | int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 1607 | const uint32_t shift_mask = |
| 1608 | (type == Primitive::kPrimInt) ? kMaxIntShiftDistance : kMaxLongShiftDistance; |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1609 | const uint32_t shift_value = rhs_imm & shift_mask; |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1610 | // Are the INS (Insert Bit Field) and ROTR instructions supported? |
| 1611 | bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1612 | |
| 1613 | switch (type) { |
| 1614 | case Primitive::kPrimInt: { |
| 1615 | Register dst = locations->Out().AsRegister<Register>(); |
| 1616 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 1617 | if (use_imm) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1618 | if (shift_value == 0) { |
| 1619 | if (dst != lhs) { |
| 1620 | __ Move(dst, lhs); |
| 1621 | } |
| 1622 | } else if (instr->IsShl()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1623 | __ Sll(dst, lhs, shift_value); |
| 1624 | } else if (instr->IsShr()) { |
| 1625 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1626 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1627 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1628 | } else { |
| 1629 | if (has_ins_rotr) { |
| 1630 | __ Rotr(dst, lhs, shift_value); |
| 1631 | } else { |
| 1632 | __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask); |
| 1633 | __ Srl(dst, lhs, shift_value); |
| 1634 | __ Or(dst, dst, TMP); |
| 1635 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1636 | } |
| 1637 | } else { |
| 1638 | if (instr->IsShl()) { |
| 1639 | __ Sllv(dst, lhs, rhs_reg); |
| 1640 | } else if (instr->IsShr()) { |
| 1641 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1642 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1643 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1644 | } else { |
| 1645 | if (has_ins_rotr) { |
| 1646 | __ Rotrv(dst, lhs, rhs_reg); |
| 1647 | } else { |
| 1648 | __ Subu(TMP, ZERO, rhs_reg); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1649 | // 32-bit shift instructions use the 5 least significant bits of the shift count, so |
| 1650 | // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case |
| 1651 | // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out |
| 1652 | // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`, |
| 1653 | // IOW, the OR'd values are equal. |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1654 | __ Sllv(TMP, lhs, TMP); |
| 1655 | __ Srlv(dst, lhs, rhs_reg); |
| 1656 | __ Or(dst, dst, TMP); |
| 1657 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1658 | } |
| 1659 | } |
| 1660 | break; |
| 1661 | } |
| 1662 | |
| 1663 | case Primitive::kPrimLong: { |
| 1664 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 1665 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 1666 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 1667 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 1668 | if (use_imm) { |
| 1669 | if (shift_value == 0) { |
| 1670 | codegen_->Move64(locations->Out(), locations->InAt(0)); |
| 1671 | } else if (shift_value < kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1672 | if (has_ins_rotr) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1673 | if (instr->IsShl()) { |
| 1674 | __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 1675 | __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value); |
| 1676 | __ Sll(dst_low, lhs_low, shift_value); |
| 1677 | } else if (instr->IsShr()) { |
| 1678 | __ Srl(dst_low, lhs_low, shift_value); |
| 1679 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 1680 | __ Sra(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1681 | } else if (instr->IsUShr()) { |
| 1682 | __ Srl(dst_low, lhs_low, shift_value); |
| 1683 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 1684 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1685 | } else { |
| 1686 | __ Srl(dst_low, lhs_low, shift_value); |
| 1687 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 1688 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1689 | __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1690 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1691 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1692 | if (instr->IsShl()) { |
| 1693 | __ Sll(dst_low, lhs_low, shift_value); |
| 1694 | __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value); |
| 1695 | __ Sll(dst_high, lhs_high, shift_value); |
| 1696 | __ Or(dst_high, dst_high, TMP); |
| 1697 | } else if (instr->IsShr()) { |
| 1698 | __ Sra(dst_high, lhs_high, shift_value); |
| 1699 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 1700 | __ Srl(dst_low, lhs_low, shift_value); |
| 1701 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1702 | } else if (instr->IsUShr()) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1703 | __ Srl(dst_high, lhs_high, shift_value); |
| 1704 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 1705 | __ Srl(dst_low, lhs_low, shift_value); |
| 1706 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1707 | } else { |
| 1708 | __ Srl(TMP, lhs_low, shift_value); |
| 1709 | __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value); |
| 1710 | __ Or(dst_low, dst_low, TMP); |
| 1711 | __ Srl(TMP, lhs_high, shift_value); |
| 1712 | __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 1713 | __ Or(dst_high, dst_high, TMP); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1714 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1715 | } |
| 1716 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1717 | const uint32_t shift_value_high = shift_value - kMipsBitsPerWord; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1718 | if (instr->IsShl()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1719 | __ Sll(dst_high, lhs_low, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1720 | __ Move(dst_low, ZERO); |
| 1721 | } else if (instr->IsShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1722 | __ Sra(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1723 | __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1724 | } else if (instr->IsUShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1725 | __ Srl(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1726 | __ Move(dst_high, ZERO); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1727 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1728 | if (shift_value == kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1729 | // 64-bit rotation by 32 is just a swap. |
| 1730 | __ Move(dst_low, lhs_high); |
| 1731 | __ Move(dst_high, lhs_low); |
| 1732 | } else { |
| 1733 | if (has_ins_rotr) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1734 | __ Srl(dst_low, lhs_high, shift_value_high); |
| 1735 | __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high); |
| 1736 | __ Srl(dst_high, lhs_low, shift_value_high); |
| 1737 | __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1738 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1739 | __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high); |
| 1740 | __ Srl(dst_low, lhs_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1741 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1742 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high); |
| 1743 | __ Srl(dst_high, lhs_low, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1744 | __ Or(dst_high, dst_high, TMP); |
| 1745 | } |
| 1746 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1747 | } |
| 1748 | } |
| 1749 | } else { |
| 1750 | MipsLabel done; |
| 1751 | if (instr->IsShl()) { |
| 1752 | __ Sllv(dst_low, lhs_low, rhs_reg); |
| 1753 | __ Nor(AT, ZERO, rhs_reg); |
| 1754 | __ Srl(TMP, lhs_low, 1); |
| 1755 | __ Srlv(TMP, TMP, AT); |
| 1756 | __ Sllv(dst_high, lhs_high, rhs_reg); |
| 1757 | __ Or(dst_high, dst_high, TMP); |
| 1758 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 1759 | __ Beqz(TMP, &done); |
| 1760 | __ Move(dst_high, dst_low); |
| 1761 | __ Move(dst_low, ZERO); |
| 1762 | } else if (instr->IsShr()) { |
| 1763 | __ Srav(dst_high, lhs_high, rhs_reg); |
| 1764 | __ Nor(AT, ZERO, rhs_reg); |
| 1765 | __ Sll(TMP, lhs_high, 1); |
| 1766 | __ Sllv(TMP, TMP, AT); |
| 1767 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 1768 | __ Or(dst_low, dst_low, TMP); |
| 1769 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 1770 | __ Beqz(TMP, &done); |
| 1771 | __ Move(dst_low, dst_high); |
| 1772 | __ Sra(dst_high, dst_high, 31); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1773 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1774 | __ Srlv(dst_high, lhs_high, rhs_reg); |
| 1775 | __ Nor(AT, ZERO, rhs_reg); |
| 1776 | __ Sll(TMP, lhs_high, 1); |
| 1777 | __ Sllv(TMP, TMP, AT); |
| 1778 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 1779 | __ Or(dst_low, dst_low, TMP); |
| 1780 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 1781 | __ Beqz(TMP, &done); |
| 1782 | __ Move(dst_low, dst_high); |
| 1783 | __ Move(dst_high, ZERO); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1784 | } else { |
| 1785 | __ Nor(AT, ZERO, rhs_reg); |
| 1786 | __ Srlv(TMP, lhs_low, rhs_reg); |
| 1787 | __ Sll(dst_low, lhs_high, 1); |
| 1788 | __ Sllv(dst_low, dst_low, AT); |
| 1789 | __ Or(dst_low, dst_low, TMP); |
| 1790 | __ Srlv(TMP, lhs_high, rhs_reg); |
| 1791 | __ Sll(dst_high, lhs_low, 1); |
| 1792 | __ Sllv(dst_high, dst_high, AT); |
| 1793 | __ Or(dst_high, dst_high, TMP); |
| 1794 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 1795 | __ Beqz(TMP, &done); |
| 1796 | __ Move(TMP, dst_high); |
| 1797 | __ Move(dst_high, dst_low); |
| 1798 | __ Move(dst_low, TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1799 | } |
| 1800 | __ Bind(&done); |
| 1801 | } |
| 1802 | break; |
| 1803 | } |
| 1804 | |
| 1805 | default: |
| 1806 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 1807 | } |
| 1808 | } |
| 1809 | |
| 1810 | void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) { |
| 1811 | HandleBinaryOp(instruction); |
| 1812 | } |
| 1813 | |
| 1814 | void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) { |
| 1815 | HandleBinaryOp(instruction); |
| 1816 | } |
| 1817 | |
| 1818 | void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) { |
| 1819 | HandleBinaryOp(instruction); |
| 1820 | } |
| 1821 | |
| 1822 | void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) { |
| 1823 | HandleBinaryOp(instruction); |
| 1824 | } |
| 1825 | |
| 1826 | void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) { |
| 1827 | LocationSummary* locations = |
| 1828 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1829 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1830 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1831 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 1832 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1833 | } else { |
| 1834 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1835 | } |
| 1836 | } |
| 1837 | |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1838 | auto InstructionCodeGeneratorMIPS::GetImplicitNullChecker(HInstruction* instruction) { |
| 1839 | auto null_checker = [this, instruction]() { |
| 1840 | this->codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1841 | }; |
| 1842 | return null_checker; |
| 1843 | } |
| 1844 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1845 | void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) { |
| 1846 | LocationSummary* locations = instruction->GetLocations(); |
| 1847 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 1848 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 1849 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1850 | auto null_checker = GetImplicitNullChecker(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1851 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 1852 | Primitive::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1853 | switch (type) { |
| 1854 | case Primitive::kPrimBoolean: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1855 | Register out = locations->Out().AsRegister<Register>(); |
| 1856 | if (index.IsConstant()) { |
| 1857 | size_t offset = |
| 1858 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1859 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1860 | } else { |
| 1861 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1862 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1863 | } |
| 1864 | break; |
| 1865 | } |
| 1866 | |
| 1867 | case Primitive::kPrimByte: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1868 | Register out = locations->Out().AsRegister<Register>(); |
| 1869 | if (index.IsConstant()) { |
| 1870 | size_t offset = |
| 1871 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1872 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1873 | } else { |
| 1874 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1875 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1876 | } |
| 1877 | break; |
| 1878 | } |
| 1879 | |
| 1880 | case Primitive::kPrimShort: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1881 | Register out = locations->Out().AsRegister<Register>(); |
| 1882 | if (index.IsConstant()) { |
| 1883 | size_t offset = |
| 1884 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1885 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1886 | } else { |
| 1887 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_2); |
| 1888 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1889 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1890 | } |
| 1891 | break; |
| 1892 | } |
| 1893 | |
| 1894 | case Primitive::kPrimChar: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1895 | Register out = locations->Out().AsRegister<Register>(); |
| 1896 | if (index.IsConstant()) { |
| 1897 | size_t offset = |
| 1898 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1899 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1900 | } else { |
| 1901 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_2); |
| 1902 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1903 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1904 | } |
| 1905 | break; |
| 1906 | } |
| 1907 | |
| 1908 | case Primitive::kPrimInt: |
| 1909 | case Primitive::kPrimNot: { |
| 1910 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1911 | Register out = locations->Out().AsRegister<Register>(); |
| 1912 | if (index.IsConstant()) { |
| 1913 | size_t offset = |
| 1914 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1915 | __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1916 | } else { |
| 1917 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_4); |
| 1918 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1919 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1920 | } |
| 1921 | break; |
| 1922 | } |
| 1923 | |
| 1924 | case Primitive::kPrimLong: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1925 | Register out = locations->Out().AsRegisterPairLow<Register>(); |
| 1926 | if (index.IsConstant()) { |
| 1927 | size_t offset = |
| 1928 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1929 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1930 | } else { |
| 1931 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_8); |
| 1932 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1933 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1934 | } |
| 1935 | break; |
| 1936 | } |
| 1937 | |
| 1938 | case Primitive::kPrimFloat: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1939 | FRegister out = locations->Out().AsFpuRegister<FRegister>(); |
| 1940 | if (index.IsConstant()) { |
| 1941 | size_t offset = |
| 1942 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1943 | __ LoadSFromOffset(out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1944 | } else { |
| 1945 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_4); |
| 1946 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1947 | __ LoadSFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1948 | } |
| 1949 | break; |
| 1950 | } |
| 1951 | |
| 1952 | case Primitive::kPrimDouble: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1953 | FRegister out = locations->Out().AsFpuRegister<FRegister>(); |
| 1954 | if (index.IsConstant()) { |
| 1955 | size_t offset = |
| 1956 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1957 | __ LoadDFromOffset(out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1958 | } else { |
| 1959 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_8); |
| 1960 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1961 | __ LoadDFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1962 | } |
| 1963 | break; |
| 1964 | } |
| 1965 | |
| 1966 | case Primitive::kPrimVoid: |
| 1967 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 1968 | UNREACHABLE(); |
| 1969 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) { |
| 1973 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1974 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1975 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1976 | } |
| 1977 | |
| 1978 | void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) { |
| 1979 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 1980 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1981 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 1982 | Register out = locations->Out().AsRegister<Register>(); |
| 1983 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 1984 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1985 | } |
| 1986 | |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1987 | Location LocationsBuilderMIPS::RegisterOrZeroConstant(HInstruction* instruction) { |
| 1988 | return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern()) |
| 1989 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 1990 | : Location::RequiresRegister(); |
| 1991 | } |
| 1992 | |
| 1993 | Location LocationsBuilderMIPS::FpuRegisterOrConstantForStore(HInstruction* instruction) { |
| 1994 | // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register. |
| 1995 | // We can store a non-zero float or double constant without first loading it into the FPU, |
| 1996 | // but we should only prefer this if the constant has a single use. |
| 1997 | if (instruction->IsConstant() && |
| 1998 | (instruction->AsConstant()->IsZeroBitPattern() || |
| 1999 | instruction->GetUses().HasExactlyOneElement())) { |
| 2000 | return Location::ConstantLocation(instruction->AsConstant()); |
| 2001 | // Otherwise fall through and require an FPU register for the constant. |
| 2002 | } |
| 2003 | return Location::RequiresFpuRegister(); |
| 2004 | } |
| 2005 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2006 | void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) { |
Pavle Batuta | 934808f | 2015-11-03 13:23:54 +0100 | [diff] [blame] | 2007 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2008 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2009 | instruction, |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2010 | needs_runtime_call ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); |
Pavle Batuta | 934808f | 2015-11-03 13:23:54 +0100 | [diff] [blame] | 2011 | if (needs_runtime_call) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2012 | InvokeRuntimeCallingConvention calling_convention; |
| 2013 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2014 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2015 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 2016 | } else { |
| 2017 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2018 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2019 | if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2020 | locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2021 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2022 | locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2023 | } |
| 2024 | } |
| 2025 | } |
| 2026 | |
| 2027 | void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) { |
| 2028 | LocationSummary* locations = instruction->GetLocations(); |
| 2029 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2030 | Location index = locations->InAt(1); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2031 | Location value_location = locations->InAt(2); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2032 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2033 | bool needs_runtime_call = locations->WillCall(); |
| 2034 | bool needs_write_barrier = |
| 2035 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2036 | auto null_checker = GetImplicitNullChecker(instruction); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2037 | Register base_reg = index.IsConstant() ? obj : TMP; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2038 | |
| 2039 | switch (value_type) { |
| 2040 | case Primitive::kPrimBoolean: |
| 2041 | case Primitive::kPrimByte: { |
| 2042 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2043 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2044 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2045 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2046 | __ Addu(base_reg, obj, index.AsRegister<Register>()); |
| 2047 | } |
| 2048 | if (value_location.IsConstant()) { |
| 2049 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2050 | __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker); |
| 2051 | } else { |
| 2052 | Register value = value_location.AsRegister<Register>(); |
| 2053 | __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2054 | } |
| 2055 | break; |
| 2056 | } |
| 2057 | |
| 2058 | case Primitive::kPrimShort: |
| 2059 | case Primitive::kPrimChar: { |
| 2060 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2061 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2062 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2063 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2064 | __ Sll(base_reg, index.AsRegister<Register>(), TIMES_2); |
| 2065 | __ Addu(base_reg, obj, base_reg); |
| 2066 | } |
| 2067 | if (value_location.IsConstant()) { |
| 2068 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2069 | __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker); |
| 2070 | } else { |
| 2071 | Register value = value_location.AsRegister<Register>(); |
| 2072 | __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2073 | } |
| 2074 | break; |
| 2075 | } |
| 2076 | |
| 2077 | case Primitive::kPrimInt: |
| 2078 | case Primitive::kPrimNot: { |
| 2079 | if (!needs_runtime_call) { |
| 2080 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2081 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2082 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2083 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2084 | __ Sll(base_reg, index.AsRegister<Register>(), TIMES_4); |
| 2085 | __ Addu(base_reg, obj, base_reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2086 | } |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2087 | if (value_location.IsConstant()) { |
| 2088 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2089 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2090 | DCHECK(!needs_write_barrier); |
| 2091 | } else { |
| 2092 | Register value = value_location.AsRegister<Register>(); |
| 2093 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2094 | if (needs_write_barrier) { |
| 2095 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 2096 | codegen_->MarkGCCard(obj, value, instruction->GetValueCanBeNull()); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2097 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2098 | } |
| 2099 | } else { |
| 2100 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 2101 | codegen_->InvokeRuntime(kQuickAputObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2102 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 2103 | } |
| 2104 | break; |
| 2105 | } |
| 2106 | |
| 2107 | case Primitive::kPrimLong: { |
| 2108 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2109 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2110 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2111 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2112 | __ Sll(base_reg, index.AsRegister<Register>(), TIMES_8); |
| 2113 | __ Addu(base_reg, obj, base_reg); |
| 2114 | } |
| 2115 | if (value_location.IsConstant()) { |
| 2116 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2117 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2118 | } else { |
| 2119 | Register value = value_location.AsRegisterPairLow<Register>(); |
| 2120 | __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2121 | } |
| 2122 | break; |
| 2123 | } |
| 2124 | |
| 2125 | case Primitive::kPrimFloat: { |
| 2126 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2127 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2128 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2129 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2130 | __ Sll(base_reg, index.AsRegister<Register>(), TIMES_4); |
| 2131 | __ Addu(base_reg, obj, base_reg); |
| 2132 | } |
| 2133 | if (value_location.IsConstant()) { |
| 2134 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2135 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2136 | } else { |
| 2137 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 2138 | __ StoreSToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2139 | } |
| 2140 | break; |
| 2141 | } |
| 2142 | |
| 2143 | case Primitive::kPrimDouble: { |
| 2144 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2145 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2146 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2147 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2148 | __ Sll(base_reg, index.AsRegister<Register>(), TIMES_8); |
| 2149 | __ Addu(base_reg, obj, base_reg); |
| 2150 | } |
| 2151 | if (value_location.IsConstant()) { |
| 2152 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2153 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2154 | } else { |
| 2155 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 2156 | __ StoreDToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2157 | } |
| 2158 | break; |
| 2159 | } |
| 2160 | |
| 2161 | case Primitive::kPrimVoid: |
| 2162 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2163 | UNREACHABLE(); |
| 2164 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2165 | } |
| 2166 | |
| 2167 | void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2168 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2169 | InvokeRuntimeCallingConvention calling_convention; |
| 2170 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2171 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2172 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2173 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2174 | locations->SetInAt(1, Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2178 | LocationSummary* locations = instruction->GetLocations(); |
| 2179 | BoundsCheckSlowPathMIPS* slow_path = |
| 2180 | new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS(instruction); |
| 2181 | codegen_->AddSlowPath(slow_path); |
| 2182 | |
| 2183 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 2184 | Register length = locations->InAt(1).AsRegister<Register>(); |
| 2185 | |
| 2186 | // length is limited by the maximum positive signed 32-bit integer. |
| 2187 | // Unsigned comparison of length and index checks for index < 0 |
| 2188 | // and for length <= index simultaneously. |
| 2189 | __ Bgeu(index, length, slow_path->GetEntryLabel()); |
| 2190 | } |
| 2191 | |
| 2192 | void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) { |
| 2193 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2194 | instruction, |
| 2195 | LocationSummary::kCallOnSlowPath); |
| 2196 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2197 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2198 | // Note that TypeCheckSlowPathMIPS uses this register too. |
| 2199 | locations->AddTemp(Location::RequiresRegister()); |
| 2200 | } |
| 2201 | |
| 2202 | void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) { |
| 2203 | LocationSummary* locations = instruction->GetLocations(); |
| 2204 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2205 | Register cls = locations->InAt(1).AsRegister<Register>(); |
| 2206 | Register obj_cls = locations->GetTemp(0).AsRegister<Register>(); |
| 2207 | |
| 2208 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction); |
| 2209 | codegen_->AddSlowPath(slow_path); |
| 2210 | |
| 2211 | // TODO: avoid this check if we know obj is not null. |
| 2212 | __ Beqz(obj, slow_path->GetExitLabel()); |
| 2213 | // Compare the class of `obj` with `cls`. |
| 2214 | __ LoadFromOffset(kLoadWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value()); |
| 2215 | __ Bne(obj_cls, cls, slow_path->GetEntryLabel()); |
| 2216 | __ Bind(slow_path->GetExitLabel()); |
| 2217 | } |
| 2218 | |
| 2219 | void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 2220 | LocationSummary* locations = |
| 2221 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2222 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2223 | if (check->HasUses()) { |
| 2224 | locations->SetOut(Location::SameAsFirstInput()); |
| 2225 | } |
| 2226 | } |
| 2227 | |
| 2228 | void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 2229 | // We assume the class is not null. |
| 2230 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS( |
| 2231 | check->GetLoadClass(), |
| 2232 | check, |
| 2233 | check->GetDexPc(), |
| 2234 | true); |
| 2235 | codegen_->AddSlowPath(slow_path); |
| 2236 | GenerateClassInitializationCheck(slow_path, |
| 2237 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
| 2238 | } |
| 2239 | |
| 2240 | void LocationsBuilderMIPS::VisitCompare(HCompare* compare) { |
| 2241 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 2242 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2243 | LocationSummary* locations = |
| 2244 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2245 | |
| 2246 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2247 | case Primitive::kPrimBoolean: |
| 2248 | case Primitive::kPrimByte: |
| 2249 | case Primitive::kPrimShort: |
| 2250 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2251 | case Primitive::kPrimInt: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 2252 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2253 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2254 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2255 | break; |
| 2256 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2257 | case Primitive::kPrimLong: |
| 2258 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2259 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2260 | // Output overlaps because it is written before doing the low comparison. |
| 2261 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2262 | break; |
| 2263 | |
| 2264 | case Primitive::kPrimFloat: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2265 | case Primitive::kPrimDouble: |
| 2266 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2267 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2268 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2269 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2270 | |
| 2271 | default: |
| 2272 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2273 | } |
| 2274 | } |
| 2275 | |
| 2276 | void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) { |
| 2277 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2278 | Register res = locations->Out().AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2279 | Primitive::Type in_type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2280 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2281 | |
| 2282 | // 0 if: left == right |
| 2283 | // 1 if: left > right |
| 2284 | // -1 if: left < right |
| 2285 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2286 | case Primitive::kPrimBoolean: |
| 2287 | case Primitive::kPrimByte: |
| 2288 | case Primitive::kPrimShort: |
| 2289 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2290 | case Primitive::kPrimInt: { |
| 2291 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2292 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 2293 | __ Slt(TMP, lhs, rhs); |
| 2294 | __ Slt(res, rhs, lhs); |
| 2295 | __ Subu(res, res, TMP); |
| 2296 | break; |
| 2297 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2298 | case Primitive::kPrimLong: { |
| 2299 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2300 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2301 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 2302 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 2303 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 2304 | // TODO: more efficient (direct) comparison with a constant. |
| 2305 | __ Slt(TMP, lhs_high, rhs_high); |
| 2306 | __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt. |
| 2307 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 2308 | __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal. |
| 2309 | __ Sltu(TMP, lhs_low, rhs_low); |
| 2310 | __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt. |
| 2311 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 2312 | __ Bind(&done); |
| 2313 | break; |
| 2314 | } |
| 2315 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2316 | case Primitive::kPrimFloat: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 2317 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2318 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2319 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2320 | MipsLabel done; |
| 2321 | if (isR6) { |
| 2322 | __ CmpEqS(FTMP, lhs, rhs); |
| 2323 | __ LoadConst32(res, 0); |
| 2324 | __ Bc1nez(FTMP, &done); |
| 2325 | if (gt_bias) { |
| 2326 | __ CmpLtS(FTMP, lhs, rhs); |
| 2327 | __ LoadConst32(res, -1); |
| 2328 | __ Bc1nez(FTMP, &done); |
| 2329 | __ LoadConst32(res, 1); |
| 2330 | } else { |
| 2331 | __ CmpLtS(FTMP, rhs, lhs); |
| 2332 | __ LoadConst32(res, 1); |
| 2333 | __ Bc1nez(FTMP, &done); |
| 2334 | __ LoadConst32(res, -1); |
| 2335 | } |
| 2336 | } else { |
| 2337 | if (gt_bias) { |
| 2338 | __ ColtS(0, lhs, rhs); |
| 2339 | __ LoadConst32(res, -1); |
| 2340 | __ Bc1t(0, &done); |
| 2341 | __ CeqS(0, lhs, rhs); |
| 2342 | __ LoadConst32(res, 1); |
| 2343 | __ Movt(res, ZERO, 0); |
| 2344 | } else { |
| 2345 | __ ColtS(0, rhs, lhs); |
| 2346 | __ LoadConst32(res, 1); |
| 2347 | __ Bc1t(0, &done); |
| 2348 | __ CeqS(0, lhs, rhs); |
| 2349 | __ LoadConst32(res, -1); |
| 2350 | __ Movt(res, ZERO, 0); |
| 2351 | } |
| 2352 | } |
| 2353 | __ Bind(&done); |
| 2354 | break; |
| 2355 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2356 | case Primitive::kPrimDouble: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 2357 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2358 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2359 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2360 | MipsLabel done; |
| 2361 | if (isR6) { |
| 2362 | __ CmpEqD(FTMP, lhs, rhs); |
| 2363 | __ LoadConst32(res, 0); |
| 2364 | __ Bc1nez(FTMP, &done); |
| 2365 | if (gt_bias) { |
| 2366 | __ CmpLtD(FTMP, lhs, rhs); |
| 2367 | __ LoadConst32(res, -1); |
| 2368 | __ Bc1nez(FTMP, &done); |
| 2369 | __ LoadConst32(res, 1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2370 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2371 | __ CmpLtD(FTMP, rhs, lhs); |
| 2372 | __ LoadConst32(res, 1); |
| 2373 | __ Bc1nez(FTMP, &done); |
| 2374 | __ LoadConst32(res, -1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2375 | } |
| 2376 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2377 | if (gt_bias) { |
| 2378 | __ ColtD(0, lhs, rhs); |
| 2379 | __ LoadConst32(res, -1); |
| 2380 | __ Bc1t(0, &done); |
| 2381 | __ CeqD(0, lhs, rhs); |
| 2382 | __ LoadConst32(res, 1); |
| 2383 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2384 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2385 | __ ColtD(0, rhs, lhs); |
| 2386 | __ LoadConst32(res, 1); |
| 2387 | __ Bc1t(0, &done); |
| 2388 | __ CeqD(0, lhs, rhs); |
| 2389 | __ LoadConst32(res, -1); |
| 2390 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2391 | } |
| 2392 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2393 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2394 | break; |
| 2395 | } |
| 2396 | |
| 2397 | default: |
| 2398 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2399 | } |
| 2400 | } |
| 2401 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2402 | void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2403 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2404 | switch (instruction->InputAt(0)->GetType()) { |
| 2405 | default: |
| 2406 | case Primitive::kPrimLong: |
| 2407 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2408 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2409 | break; |
| 2410 | |
| 2411 | case Primitive::kPrimFloat: |
| 2412 | case Primitive::kPrimDouble: |
| 2413 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2414 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2415 | break; |
| 2416 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2417 | if (!instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2418 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2419 | } |
| 2420 | } |
| 2421 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2422 | void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2423 | if (instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2424 | return; |
| 2425 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2426 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2427 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2428 | LocationSummary* locations = instruction->GetLocations(); |
| 2429 | Register dst = locations->Out().AsRegister<Register>(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2430 | MipsLabel true_label; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2431 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2432 | switch (type) { |
| 2433 | default: |
| 2434 | // Integer case. |
| 2435 | GenerateIntCompare(instruction->GetCondition(), locations); |
| 2436 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2437 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2438 | case Primitive::kPrimLong: |
| 2439 | // TODO: don't use branches. |
| 2440 | GenerateLongCompareAndBranch(instruction->GetCondition(), locations, &true_label); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2441 | break; |
| 2442 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2443 | case Primitive::kPrimFloat: |
| 2444 | case Primitive::kPrimDouble: |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 2445 | GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations); |
| 2446 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2447 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2448 | |
| 2449 | // Convert the branches into the result. |
| 2450 | MipsLabel done; |
| 2451 | |
| 2452 | // False case: result = 0. |
| 2453 | __ LoadConst32(dst, 0); |
| 2454 | __ B(&done); |
| 2455 | |
| 2456 | // True case: result = 1. |
| 2457 | __ Bind(&true_label); |
| 2458 | __ LoadConst32(dst, 1); |
| 2459 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2460 | } |
| 2461 | |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2462 | void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2463 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2464 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 2465 | |
| 2466 | LocationSummary* locations = instruction->GetLocations(); |
| 2467 | Location second = locations->InAt(1); |
| 2468 | DCHECK(second.IsConstant()); |
| 2469 | |
| 2470 | Register out = locations->Out().AsRegister<Register>(); |
| 2471 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2472 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2473 | DCHECK(imm == 1 || imm == -1); |
| 2474 | |
| 2475 | if (instruction->IsRem()) { |
| 2476 | __ Move(out, ZERO); |
| 2477 | } else { |
| 2478 | if (imm == -1) { |
| 2479 | __ Subu(out, ZERO, dividend); |
| 2480 | } else if (out != dividend) { |
| 2481 | __ Move(out, dividend); |
| 2482 | } |
| 2483 | } |
| 2484 | } |
| 2485 | |
| 2486 | void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2487 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2488 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 2489 | |
| 2490 | LocationSummary* locations = instruction->GetLocations(); |
| 2491 | Location second = locations->InAt(1); |
| 2492 | DCHECK(second.IsConstant()); |
| 2493 | |
| 2494 | Register out = locations->Out().AsRegister<Register>(); |
| 2495 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2496 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2497 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2498 | int ctz_imm = CTZ(abs_imm); |
| 2499 | |
| 2500 | if (instruction->IsDiv()) { |
| 2501 | if (ctz_imm == 1) { |
| 2502 | // Fast path for division by +/-2, which is very common. |
| 2503 | __ Srl(TMP, dividend, 31); |
| 2504 | } else { |
| 2505 | __ Sra(TMP, dividend, 31); |
| 2506 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 2507 | } |
| 2508 | __ Addu(out, dividend, TMP); |
| 2509 | __ Sra(out, out, ctz_imm); |
| 2510 | if (imm < 0) { |
| 2511 | __ Subu(out, ZERO, out); |
| 2512 | } |
| 2513 | } else { |
| 2514 | if (ctz_imm == 1) { |
| 2515 | // Fast path for modulo +/-2, which is very common. |
| 2516 | __ Sra(TMP, dividend, 31); |
| 2517 | __ Subu(out, dividend, TMP); |
| 2518 | __ Andi(out, out, 1); |
| 2519 | __ Addu(out, out, TMP); |
| 2520 | } else { |
| 2521 | __ Sra(TMP, dividend, 31); |
| 2522 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 2523 | __ Addu(out, dividend, TMP); |
| 2524 | if (IsUint<16>(abs_imm - 1)) { |
| 2525 | __ Andi(out, out, abs_imm - 1); |
| 2526 | } else { |
| 2527 | __ Sll(out, out, 32 - ctz_imm); |
| 2528 | __ Srl(out, out, 32 - ctz_imm); |
| 2529 | } |
| 2530 | __ Subu(out, out, TMP); |
| 2531 | } |
| 2532 | } |
| 2533 | } |
| 2534 | |
| 2535 | void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2536 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2537 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 2538 | |
| 2539 | LocationSummary* locations = instruction->GetLocations(); |
| 2540 | Location second = locations->InAt(1); |
| 2541 | DCHECK(second.IsConstant()); |
| 2542 | |
| 2543 | Register out = locations->Out().AsRegister<Register>(); |
| 2544 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2545 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2546 | |
| 2547 | int64_t magic; |
| 2548 | int shift; |
| 2549 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2550 | |
| 2551 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 2552 | |
| 2553 | __ LoadConst32(TMP, magic); |
| 2554 | if (isR6) { |
| 2555 | __ MuhR6(TMP, dividend, TMP); |
| 2556 | } else { |
| 2557 | __ MultR2(dividend, TMP); |
| 2558 | __ Mfhi(TMP); |
| 2559 | } |
| 2560 | if (imm > 0 && magic < 0) { |
| 2561 | __ Addu(TMP, TMP, dividend); |
| 2562 | } else if (imm < 0 && magic > 0) { |
| 2563 | __ Subu(TMP, TMP, dividend); |
| 2564 | } |
| 2565 | |
| 2566 | if (shift != 0) { |
| 2567 | __ Sra(TMP, TMP, shift); |
| 2568 | } |
| 2569 | |
| 2570 | if (instruction->IsDiv()) { |
| 2571 | __ Sra(out, TMP, 31); |
| 2572 | __ Subu(out, TMP, out); |
| 2573 | } else { |
| 2574 | __ Sra(AT, TMP, 31); |
| 2575 | __ Subu(AT, TMP, AT); |
| 2576 | __ LoadConst32(TMP, imm); |
| 2577 | if (isR6) { |
| 2578 | __ MulR6(TMP, AT, TMP); |
| 2579 | } else { |
| 2580 | __ MulR2(TMP, AT, TMP); |
| 2581 | } |
| 2582 | __ Subu(out, dividend, TMP); |
| 2583 | } |
| 2584 | } |
| 2585 | |
| 2586 | void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2587 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2588 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 2589 | |
| 2590 | LocationSummary* locations = instruction->GetLocations(); |
| 2591 | Register out = locations->Out().AsRegister<Register>(); |
| 2592 | Location second = locations->InAt(1); |
| 2593 | |
| 2594 | if (second.IsConstant()) { |
| 2595 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2596 | if (imm == 0) { |
| 2597 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2598 | } else if (imm == 1 || imm == -1) { |
| 2599 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2600 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2601 | DivRemByPowerOfTwo(instruction); |
| 2602 | } else { |
| 2603 | DCHECK(imm <= -2 || imm >= 2); |
| 2604 | GenerateDivRemWithAnyConstant(instruction); |
| 2605 | } |
| 2606 | } else { |
| 2607 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2608 | Register divisor = second.AsRegister<Register>(); |
| 2609 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 2610 | if (instruction->IsDiv()) { |
| 2611 | if (isR6) { |
| 2612 | __ DivR6(out, dividend, divisor); |
| 2613 | } else { |
| 2614 | __ DivR2(out, dividend, divisor); |
| 2615 | } |
| 2616 | } else { |
| 2617 | if (isR6) { |
| 2618 | __ ModR6(out, dividend, divisor); |
| 2619 | } else { |
| 2620 | __ ModR2(out, dividend, divisor); |
| 2621 | } |
| 2622 | } |
| 2623 | } |
| 2624 | } |
| 2625 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2626 | void LocationsBuilderMIPS::VisitDiv(HDiv* div) { |
| 2627 | Primitive::Type type = div->GetResultType(); |
| 2628 | LocationSummary::CallKind call_kind = (type == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2629 | ? LocationSummary::kCallOnMainOnly |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2630 | : LocationSummary::kNoCall; |
| 2631 | |
| 2632 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2633 | |
| 2634 | switch (type) { |
| 2635 | case Primitive::kPrimInt: |
| 2636 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2637 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2638 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2639 | break; |
| 2640 | |
| 2641 | case Primitive::kPrimLong: { |
| 2642 | InvokeRuntimeCallingConvention calling_convention; |
| 2643 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2644 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2645 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2646 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2647 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 2648 | break; |
| 2649 | } |
| 2650 | |
| 2651 | case Primitive::kPrimFloat: |
| 2652 | case Primitive::kPrimDouble: |
| 2653 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2654 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2655 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2656 | break; |
| 2657 | |
| 2658 | default: |
| 2659 | LOG(FATAL) << "Unexpected div type " << type; |
| 2660 | } |
| 2661 | } |
| 2662 | |
| 2663 | void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) { |
| 2664 | Primitive::Type type = instruction->GetType(); |
| 2665 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2666 | |
| 2667 | switch (type) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2668 | case Primitive::kPrimInt: |
| 2669 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2670 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2671 | case Primitive::kPrimLong: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 2672 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2673 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| 2674 | break; |
| 2675 | } |
| 2676 | case Primitive::kPrimFloat: |
| 2677 | case Primitive::kPrimDouble: { |
| 2678 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 2679 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2680 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2681 | if (type == Primitive::kPrimFloat) { |
| 2682 | __ DivS(dst, lhs, rhs); |
| 2683 | } else { |
| 2684 | __ DivD(dst, lhs, rhs); |
| 2685 | } |
| 2686 | break; |
| 2687 | } |
| 2688 | default: |
| 2689 | LOG(FATAL) << "Unexpected div type " << type; |
| 2690 | } |
| 2691 | } |
| 2692 | |
| 2693 | void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2694 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2695 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2696 | } |
| 2697 | |
| 2698 | void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2699 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS(instruction); |
| 2700 | codegen_->AddSlowPath(slow_path); |
| 2701 | Location value = instruction->GetLocations()->InAt(0); |
| 2702 | Primitive::Type type = instruction->GetType(); |
| 2703 | |
| 2704 | switch (type) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 2705 | case Primitive::kPrimBoolean: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2706 | case Primitive::kPrimByte: |
| 2707 | case Primitive::kPrimChar: |
| 2708 | case Primitive::kPrimShort: |
| 2709 | case Primitive::kPrimInt: { |
| 2710 | if (value.IsConstant()) { |
| 2711 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 2712 | __ B(slow_path->GetEntryLabel()); |
| 2713 | } else { |
| 2714 | // A division by a non-null constant is valid. We don't need to perform |
| 2715 | // any check, so simply fall through. |
| 2716 | } |
| 2717 | } else { |
| 2718 | DCHECK(value.IsRegister()) << value; |
| 2719 | __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 2720 | } |
| 2721 | break; |
| 2722 | } |
| 2723 | case Primitive::kPrimLong: { |
| 2724 | if (value.IsConstant()) { |
| 2725 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 2726 | __ B(slow_path->GetEntryLabel()); |
| 2727 | } else { |
| 2728 | // A division by a non-null constant is valid. We don't need to perform |
| 2729 | // any check, so simply fall through. |
| 2730 | } |
| 2731 | } else { |
| 2732 | DCHECK(value.IsRegisterPair()) << value; |
| 2733 | __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>()); |
| 2734 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 2735 | } |
| 2736 | break; |
| 2737 | } |
| 2738 | default: |
| 2739 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
| 2740 | } |
| 2741 | } |
| 2742 | |
| 2743 | void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2744 | LocationSummary* locations = |
| 2745 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2746 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2747 | } |
| 2748 | |
| 2749 | void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 2750 | // Will be generated at use site. |
| 2751 | } |
| 2752 | |
| 2753 | void LocationsBuilderMIPS::VisitExit(HExit* exit) { |
| 2754 | exit->SetLocations(nullptr); |
| 2755 | } |
| 2756 | |
| 2757 | void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 2758 | } |
| 2759 | |
| 2760 | void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) { |
| 2761 | LocationSummary* locations = |
| 2762 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2763 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2764 | } |
| 2765 | |
| 2766 | void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 2767 | // Will be generated at use site. |
| 2768 | } |
| 2769 | |
| 2770 | void LocationsBuilderMIPS::VisitGoto(HGoto* got) { |
| 2771 | got->SetLocations(nullptr); |
| 2772 | } |
| 2773 | |
| 2774 | void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| 2775 | DCHECK(!successor->IsExitBlock()); |
| 2776 | HBasicBlock* block = got->GetBlock(); |
| 2777 | HInstruction* previous = got->GetPrevious(); |
| 2778 | HLoopInformation* info = block->GetLoopInformation(); |
| 2779 | |
| 2780 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| 2781 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2782 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2783 | return; |
| 2784 | } |
| 2785 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2786 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2787 | } |
| 2788 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 2789 | __ B(codegen_->GetLabelOf(successor)); |
| 2790 | } |
| 2791 | } |
| 2792 | |
| 2793 | void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) { |
| 2794 | HandleGoto(got, got->GetSuccessor()); |
| 2795 | } |
| 2796 | |
| 2797 | void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2798 | try_boundary->SetLocations(nullptr); |
| 2799 | } |
| 2800 | |
| 2801 | void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2802 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2803 | if (!successor->IsExitBlock()) { |
| 2804 | HandleGoto(try_boundary, successor); |
| 2805 | } |
| 2806 | } |
| 2807 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2808 | void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond, |
| 2809 | LocationSummary* locations) { |
| 2810 | Register dst = locations->Out().AsRegister<Register>(); |
| 2811 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2812 | Location rhs_location = locations->InAt(1); |
| 2813 | Register rhs_reg = ZERO; |
| 2814 | int64_t rhs_imm = 0; |
| 2815 | bool use_imm = rhs_location.IsConstant(); |
| 2816 | if (use_imm) { |
| 2817 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 2818 | } else { |
| 2819 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 2820 | } |
| 2821 | |
| 2822 | switch (cond) { |
| 2823 | case kCondEQ: |
| 2824 | case kCondNE: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 2825 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 2826 | if (rhs_imm == 0) { |
| 2827 | if (cond == kCondEQ) { |
| 2828 | __ Sltiu(dst, lhs, 1); |
| 2829 | } else { |
| 2830 | __ Sltu(dst, ZERO, lhs); |
| 2831 | } |
| 2832 | } else { |
| 2833 | __ Addiu(dst, lhs, -rhs_imm); |
| 2834 | if (cond == kCondEQ) { |
| 2835 | __ Sltiu(dst, dst, 1); |
| 2836 | } else { |
| 2837 | __ Sltu(dst, ZERO, dst); |
| 2838 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2839 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2840 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 2841 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 2842 | __ Xori(dst, lhs, rhs_imm); |
| 2843 | } else { |
| 2844 | if (use_imm) { |
| 2845 | rhs_reg = TMP; |
| 2846 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2847 | } |
| 2848 | __ Xor(dst, lhs, rhs_reg); |
| 2849 | } |
| 2850 | if (cond == kCondEQ) { |
| 2851 | __ Sltiu(dst, dst, 1); |
| 2852 | } else { |
| 2853 | __ Sltu(dst, ZERO, dst); |
| 2854 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2855 | } |
| 2856 | break; |
| 2857 | |
| 2858 | case kCondLT: |
| 2859 | case kCondGE: |
| 2860 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 2861 | __ Slti(dst, lhs, rhs_imm); |
| 2862 | } else { |
| 2863 | if (use_imm) { |
| 2864 | rhs_reg = TMP; |
| 2865 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2866 | } |
| 2867 | __ Slt(dst, lhs, rhs_reg); |
| 2868 | } |
| 2869 | if (cond == kCondGE) { |
| 2870 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 2871 | // only the slt instruction but no sge. |
| 2872 | __ Xori(dst, dst, 1); |
| 2873 | } |
| 2874 | break; |
| 2875 | |
| 2876 | case kCondLE: |
| 2877 | case kCondGT: |
| 2878 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 2879 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 2880 | __ Slti(dst, lhs, rhs_imm + 1); |
| 2881 | if (cond == kCondGT) { |
| 2882 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 2883 | // only the slti instruction but no sgti. |
| 2884 | __ Xori(dst, dst, 1); |
| 2885 | } |
| 2886 | } else { |
| 2887 | if (use_imm) { |
| 2888 | rhs_reg = TMP; |
| 2889 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2890 | } |
| 2891 | __ Slt(dst, rhs_reg, lhs); |
| 2892 | if (cond == kCondLE) { |
| 2893 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 2894 | // only the slt instruction but no sle. |
| 2895 | __ Xori(dst, dst, 1); |
| 2896 | } |
| 2897 | } |
| 2898 | break; |
| 2899 | |
| 2900 | case kCondB: |
| 2901 | case kCondAE: |
| 2902 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 2903 | // Sltiu sign-extends its 16-bit immediate operand before |
| 2904 | // the comparison and thus lets us compare directly with |
| 2905 | // unsigned values in the ranges [0, 0x7fff] and |
| 2906 | // [0xffff8000, 0xffffffff]. |
| 2907 | __ Sltiu(dst, lhs, rhs_imm); |
| 2908 | } else { |
| 2909 | if (use_imm) { |
| 2910 | rhs_reg = TMP; |
| 2911 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2912 | } |
| 2913 | __ Sltu(dst, lhs, rhs_reg); |
| 2914 | } |
| 2915 | if (cond == kCondAE) { |
| 2916 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 2917 | // only the sltu instruction but no sgeu. |
| 2918 | __ Xori(dst, dst, 1); |
| 2919 | } |
| 2920 | break; |
| 2921 | |
| 2922 | case kCondBE: |
| 2923 | case kCondA: |
| 2924 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 2925 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 2926 | // Note that this only works if rhs + 1 does not overflow |
| 2927 | // to 0, hence the check above. |
| 2928 | // Sltiu sign-extends its 16-bit immediate operand before |
| 2929 | // the comparison and thus lets us compare directly with |
| 2930 | // unsigned values in the ranges [0, 0x7fff] and |
| 2931 | // [0xffff8000, 0xffffffff]. |
| 2932 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 2933 | if (cond == kCondA) { |
| 2934 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 2935 | // only the sltiu instruction but no sgtiu. |
| 2936 | __ Xori(dst, dst, 1); |
| 2937 | } |
| 2938 | } else { |
| 2939 | if (use_imm) { |
| 2940 | rhs_reg = TMP; |
| 2941 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2942 | } |
| 2943 | __ Sltu(dst, rhs_reg, lhs); |
| 2944 | if (cond == kCondBE) { |
| 2945 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 2946 | // only the sltu instruction but no sleu. |
| 2947 | __ Xori(dst, dst, 1); |
| 2948 | } |
| 2949 | } |
| 2950 | break; |
| 2951 | } |
| 2952 | } |
| 2953 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 2954 | bool InstructionCodeGeneratorMIPS::MaterializeIntCompare(IfCondition cond, |
| 2955 | LocationSummary* input_locations, |
| 2956 | Register dst) { |
| 2957 | Register lhs = input_locations->InAt(0).AsRegister<Register>(); |
| 2958 | Location rhs_location = input_locations->InAt(1); |
| 2959 | Register rhs_reg = ZERO; |
| 2960 | int64_t rhs_imm = 0; |
| 2961 | bool use_imm = rhs_location.IsConstant(); |
| 2962 | if (use_imm) { |
| 2963 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 2964 | } else { |
| 2965 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 2966 | } |
| 2967 | |
| 2968 | switch (cond) { |
| 2969 | case kCondEQ: |
| 2970 | case kCondNE: |
| 2971 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 2972 | __ Addiu(dst, lhs, -rhs_imm); |
| 2973 | } else if (use_imm && IsUint<16>(rhs_imm)) { |
| 2974 | __ Xori(dst, lhs, rhs_imm); |
| 2975 | } else { |
| 2976 | if (use_imm) { |
| 2977 | rhs_reg = TMP; |
| 2978 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2979 | } |
| 2980 | __ Xor(dst, lhs, rhs_reg); |
| 2981 | } |
| 2982 | return (cond == kCondEQ); |
| 2983 | |
| 2984 | case kCondLT: |
| 2985 | case kCondGE: |
| 2986 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 2987 | __ Slti(dst, lhs, rhs_imm); |
| 2988 | } else { |
| 2989 | if (use_imm) { |
| 2990 | rhs_reg = TMP; |
| 2991 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2992 | } |
| 2993 | __ Slt(dst, lhs, rhs_reg); |
| 2994 | } |
| 2995 | return (cond == kCondGE); |
| 2996 | |
| 2997 | case kCondLE: |
| 2998 | case kCondGT: |
| 2999 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 3000 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3001 | __ Slti(dst, lhs, rhs_imm + 1); |
| 3002 | return (cond == kCondGT); |
| 3003 | } else { |
| 3004 | if (use_imm) { |
| 3005 | rhs_reg = TMP; |
| 3006 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3007 | } |
| 3008 | __ Slt(dst, rhs_reg, lhs); |
| 3009 | return (cond == kCondLE); |
| 3010 | } |
| 3011 | |
| 3012 | case kCondB: |
| 3013 | case kCondAE: |
| 3014 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3015 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3016 | // the comparison and thus lets us compare directly with |
| 3017 | // unsigned values in the ranges [0, 0x7fff] and |
| 3018 | // [0xffff8000, 0xffffffff]. |
| 3019 | __ Sltiu(dst, lhs, rhs_imm); |
| 3020 | } else { |
| 3021 | if (use_imm) { |
| 3022 | rhs_reg = TMP; |
| 3023 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3024 | } |
| 3025 | __ Sltu(dst, lhs, rhs_reg); |
| 3026 | } |
| 3027 | return (cond == kCondAE); |
| 3028 | |
| 3029 | case kCondBE: |
| 3030 | case kCondA: |
| 3031 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 3032 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3033 | // Note that this only works if rhs + 1 does not overflow |
| 3034 | // to 0, hence the check above. |
| 3035 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3036 | // the comparison and thus lets us compare directly with |
| 3037 | // unsigned values in the ranges [0, 0x7fff] and |
| 3038 | // [0xffff8000, 0xffffffff]. |
| 3039 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 3040 | return (cond == kCondA); |
| 3041 | } else { |
| 3042 | if (use_imm) { |
| 3043 | rhs_reg = TMP; |
| 3044 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3045 | } |
| 3046 | __ Sltu(dst, rhs_reg, lhs); |
| 3047 | return (cond == kCondBE); |
| 3048 | } |
| 3049 | } |
| 3050 | } |
| 3051 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3052 | void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond, |
| 3053 | LocationSummary* locations, |
| 3054 | MipsLabel* label) { |
| 3055 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 3056 | Location rhs_location = locations->InAt(1); |
| 3057 | Register rhs_reg = ZERO; |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 3058 | int64_t rhs_imm = 0; |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3059 | bool use_imm = rhs_location.IsConstant(); |
| 3060 | if (use_imm) { |
| 3061 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3062 | } else { |
| 3063 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 3064 | } |
| 3065 | |
| 3066 | if (use_imm && rhs_imm == 0) { |
| 3067 | switch (cond) { |
| 3068 | case kCondEQ: |
| 3069 | case kCondBE: // <= 0 if zero |
| 3070 | __ Beqz(lhs, label); |
| 3071 | break; |
| 3072 | case kCondNE: |
| 3073 | case kCondA: // > 0 if non-zero |
| 3074 | __ Bnez(lhs, label); |
| 3075 | break; |
| 3076 | case kCondLT: |
| 3077 | __ Bltz(lhs, label); |
| 3078 | break; |
| 3079 | case kCondGE: |
| 3080 | __ Bgez(lhs, label); |
| 3081 | break; |
| 3082 | case kCondLE: |
| 3083 | __ Blez(lhs, label); |
| 3084 | break; |
| 3085 | case kCondGT: |
| 3086 | __ Bgtz(lhs, label); |
| 3087 | break; |
| 3088 | case kCondB: // always false |
| 3089 | break; |
| 3090 | case kCondAE: // always true |
| 3091 | __ B(label); |
| 3092 | break; |
| 3093 | } |
| 3094 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 3095 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3096 | if (isR6 || !use_imm) { |
| 3097 | if (use_imm) { |
| 3098 | rhs_reg = TMP; |
| 3099 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3100 | } |
| 3101 | switch (cond) { |
| 3102 | case kCondEQ: |
| 3103 | __ Beq(lhs, rhs_reg, label); |
| 3104 | break; |
| 3105 | case kCondNE: |
| 3106 | __ Bne(lhs, rhs_reg, label); |
| 3107 | break; |
| 3108 | case kCondLT: |
| 3109 | __ Blt(lhs, rhs_reg, label); |
| 3110 | break; |
| 3111 | case kCondGE: |
| 3112 | __ Bge(lhs, rhs_reg, label); |
| 3113 | break; |
| 3114 | case kCondLE: |
| 3115 | __ Bge(rhs_reg, lhs, label); |
| 3116 | break; |
| 3117 | case kCondGT: |
| 3118 | __ Blt(rhs_reg, lhs, label); |
| 3119 | break; |
| 3120 | case kCondB: |
| 3121 | __ Bltu(lhs, rhs_reg, label); |
| 3122 | break; |
| 3123 | case kCondAE: |
| 3124 | __ Bgeu(lhs, rhs_reg, label); |
| 3125 | break; |
| 3126 | case kCondBE: |
| 3127 | __ Bgeu(rhs_reg, lhs, label); |
| 3128 | break; |
| 3129 | case kCondA: |
| 3130 | __ Bltu(rhs_reg, lhs, label); |
| 3131 | break; |
| 3132 | } |
| 3133 | } else { |
| 3134 | // Special cases for more efficient comparison with constants on R2. |
| 3135 | switch (cond) { |
| 3136 | case kCondEQ: |
| 3137 | __ LoadConst32(TMP, rhs_imm); |
| 3138 | __ Beq(lhs, TMP, label); |
| 3139 | break; |
| 3140 | case kCondNE: |
| 3141 | __ LoadConst32(TMP, rhs_imm); |
| 3142 | __ Bne(lhs, TMP, label); |
| 3143 | break; |
| 3144 | case kCondLT: |
| 3145 | if (IsInt<16>(rhs_imm)) { |
| 3146 | __ Slti(TMP, lhs, rhs_imm); |
| 3147 | __ Bnez(TMP, label); |
| 3148 | } else { |
| 3149 | __ LoadConst32(TMP, rhs_imm); |
| 3150 | __ Blt(lhs, TMP, label); |
| 3151 | } |
| 3152 | break; |
| 3153 | case kCondGE: |
| 3154 | if (IsInt<16>(rhs_imm)) { |
| 3155 | __ Slti(TMP, lhs, rhs_imm); |
| 3156 | __ Beqz(TMP, label); |
| 3157 | } else { |
| 3158 | __ LoadConst32(TMP, rhs_imm); |
| 3159 | __ Bge(lhs, TMP, label); |
| 3160 | } |
| 3161 | break; |
| 3162 | case kCondLE: |
| 3163 | if (IsInt<16>(rhs_imm + 1)) { |
| 3164 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3165 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 3166 | __ Bnez(TMP, label); |
| 3167 | } else { |
| 3168 | __ LoadConst32(TMP, rhs_imm); |
| 3169 | __ Bge(TMP, lhs, label); |
| 3170 | } |
| 3171 | break; |
| 3172 | case kCondGT: |
| 3173 | if (IsInt<16>(rhs_imm + 1)) { |
| 3174 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 3175 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 3176 | __ Beqz(TMP, label); |
| 3177 | } else { |
| 3178 | __ LoadConst32(TMP, rhs_imm); |
| 3179 | __ Blt(TMP, lhs, label); |
| 3180 | } |
| 3181 | break; |
| 3182 | case kCondB: |
| 3183 | if (IsInt<16>(rhs_imm)) { |
| 3184 | __ Sltiu(TMP, lhs, rhs_imm); |
| 3185 | __ Bnez(TMP, label); |
| 3186 | } else { |
| 3187 | __ LoadConst32(TMP, rhs_imm); |
| 3188 | __ Bltu(lhs, TMP, label); |
| 3189 | } |
| 3190 | break; |
| 3191 | case kCondAE: |
| 3192 | if (IsInt<16>(rhs_imm)) { |
| 3193 | __ Sltiu(TMP, lhs, rhs_imm); |
| 3194 | __ Beqz(TMP, label); |
| 3195 | } else { |
| 3196 | __ LoadConst32(TMP, rhs_imm); |
| 3197 | __ Bgeu(lhs, TMP, label); |
| 3198 | } |
| 3199 | break; |
| 3200 | case kCondBE: |
| 3201 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 3202 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3203 | // Note that this only works if rhs + 1 does not overflow |
| 3204 | // to 0, hence the check above. |
| 3205 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 3206 | __ Bnez(TMP, label); |
| 3207 | } else { |
| 3208 | __ LoadConst32(TMP, rhs_imm); |
| 3209 | __ Bgeu(TMP, lhs, label); |
| 3210 | } |
| 3211 | break; |
| 3212 | case kCondA: |
| 3213 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 3214 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 3215 | // Note that this only works if rhs + 1 does not overflow |
| 3216 | // to 0, hence the check above. |
| 3217 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 3218 | __ Beqz(TMP, label); |
| 3219 | } else { |
| 3220 | __ LoadConst32(TMP, rhs_imm); |
| 3221 | __ Bltu(TMP, lhs, label); |
| 3222 | } |
| 3223 | break; |
| 3224 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3225 | } |
| 3226 | } |
| 3227 | } |
| 3228 | |
| 3229 | void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond, |
| 3230 | LocationSummary* locations, |
| 3231 | MipsLabel* label) { |
| 3232 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3233 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3234 | Location rhs_location = locations->InAt(1); |
| 3235 | Register rhs_high = ZERO; |
| 3236 | Register rhs_low = ZERO; |
| 3237 | int64_t imm = 0; |
| 3238 | uint32_t imm_high = 0; |
| 3239 | uint32_t imm_low = 0; |
| 3240 | bool use_imm = rhs_location.IsConstant(); |
| 3241 | if (use_imm) { |
| 3242 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); |
| 3243 | imm_high = High32Bits(imm); |
| 3244 | imm_low = Low32Bits(imm); |
| 3245 | } else { |
| 3246 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 3247 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 3248 | } |
| 3249 | |
| 3250 | if (use_imm && imm == 0) { |
| 3251 | switch (cond) { |
| 3252 | case kCondEQ: |
| 3253 | case kCondBE: // <= 0 if zero |
| 3254 | __ Or(TMP, lhs_high, lhs_low); |
| 3255 | __ Beqz(TMP, label); |
| 3256 | break; |
| 3257 | case kCondNE: |
| 3258 | case kCondA: // > 0 if non-zero |
| 3259 | __ Or(TMP, lhs_high, lhs_low); |
| 3260 | __ Bnez(TMP, label); |
| 3261 | break; |
| 3262 | case kCondLT: |
| 3263 | __ Bltz(lhs_high, label); |
| 3264 | break; |
| 3265 | case kCondGE: |
| 3266 | __ Bgez(lhs_high, label); |
| 3267 | break; |
| 3268 | case kCondLE: |
| 3269 | __ Or(TMP, lhs_high, lhs_low); |
| 3270 | __ Sra(AT, lhs_high, 31); |
| 3271 | __ Bgeu(AT, TMP, label); |
| 3272 | break; |
| 3273 | case kCondGT: |
| 3274 | __ Or(TMP, lhs_high, lhs_low); |
| 3275 | __ Sra(AT, lhs_high, 31); |
| 3276 | __ Bltu(AT, TMP, label); |
| 3277 | break; |
| 3278 | case kCondB: // always false |
| 3279 | break; |
| 3280 | case kCondAE: // always true |
| 3281 | __ B(label); |
| 3282 | break; |
| 3283 | } |
| 3284 | } else if (use_imm) { |
| 3285 | // TODO: more efficient comparison with constants without loading them into TMP/AT. |
| 3286 | switch (cond) { |
| 3287 | case kCondEQ: |
| 3288 | __ LoadConst32(TMP, imm_high); |
| 3289 | __ Xor(TMP, TMP, lhs_high); |
| 3290 | __ LoadConst32(AT, imm_low); |
| 3291 | __ Xor(AT, AT, lhs_low); |
| 3292 | __ Or(TMP, TMP, AT); |
| 3293 | __ Beqz(TMP, label); |
| 3294 | break; |
| 3295 | case kCondNE: |
| 3296 | __ LoadConst32(TMP, imm_high); |
| 3297 | __ Xor(TMP, TMP, lhs_high); |
| 3298 | __ LoadConst32(AT, imm_low); |
| 3299 | __ Xor(AT, AT, lhs_low); |
| 3300 | __ Or(TMP, TMP, AT); |
| 3301 | __ Bnez(TMP, label); |
| 3302 | break; |
| 3303 | case kCondLT: |
| 3304 | __ LoadConst32(TMP, imm_high); |
| 3305 | __ Blt(lhs_high, TMP, label); |
| 3306 | __ Slt(TMP, TMP, lhs_high); |
| 3307 | __ LoadConst32(AT, imm_low); |
| 3308 | __ Sltu(AT, lhs_low, AT); |
| 3309 | __ Blt(TMP, AT, label); |
| 3310 | break; |
| 3311 | case kCondGE: |
| 3312 | __ LoadConst32(TMP, imm_high); |
| 3313 | __ Blt(TMP, lhs_high, label); |
| 3314 | __ Slt(TMP, lhs_high, TMP); |
| 3315 | __ LoadConst32(AT, imm_low); |
| 3316 | __ Sltu(AT, lhs_low, AT); |
| 3317 | __ Or(TMP, TMP, AT); |
| 3318 | __ Beqz(TMP, label); |
| 3319 | break; |
| 3320 | case kCondLE: |
| 3321 | __ LoadConst32(TMP, imm_high); |
| 3322 | __ Blt(lhs_high, TMP, label); |
| 3323 | __ Slt(TMP, TMP, lhs_high); |
| 3324 | __ LoadConst32(AT, imm_low); |
| 3325 | __ Sltu(AT, AT, lhs_low); |
| 3326 | __ Or(TMP, TMP, AT); |
| 3327 | __ Beqz(TMP, label); |
| 3328 | break; |
| 3329 | case kCondGT: |
| 3330 | __ LoadConst32(TMP, imm_high); |
| 3331 | __ Blt(TMP, lhs_high, label); |
| 3332 | __ Slt(TMP, lhs_high, TMP); |
| 3333 | __ LoadConst32(AT, imm_low); |
| 3334 | __ Sltu(AT, AT, lhs_low); |
| 3335 | __ Blt(TMP, AT, label); |
| 3336 | break; |
| 3337 | case kCondB: |
| 3338 | __ LoadConst32(TMP, imm_high); |
| 3339 | __ Bltu(lhs_high, TMP, label); |
| 3340 | __ Sltu(TMP, TMP, lhs_high); |
| 3341 | __ LoadConst32(AT, imm_low); |
| 3342 | __ Sltu(AT, lhs_low, AT); |
| 3343 | __ Blt(TMP, AT, label); |
| 3344 | break; |
| 3345 | case kCondAE: |
| 3346 | __ LoadConst32(TMP, imm_high); |
| 3347 | __ Bltu(TMP, lhs_high, label); |
| 3348 | __ Sltu(TMP, lhs_high, TMP); |
| 3349 | __ LoadConst32(AT, imm_low); |
| 3350 | __ Sltu(AT, lhs_low, AT); |
| 3351 | __ Or(TMP, TMP, AT); |
| 3352 | __ Beqz(TMP, label); |
| 3353 | break; |
| 3354 | case kCondBE: |
| 3355 | __ LoadConst32(TMP, imm_high); |
| 3356 | __ Bltu(lhs_high, TMP, label); |
| 3357 | __ Sltu(TMP, TMP, lhs_high); |
| 3358 | __ LoadConst32(AT, imm_low); |
| 3359 | __ Sltu(AT, AT, lhs_low); |
| 3360 | __ Or(TMP, TMP, AT); |
| 3361 | __ Beqz(TMP, label); |
| 3362 | break; |
| 3363 | case kCondA: |
| 3364 | __ LoadConst32(TMP, imm_high); |
| 3365 | __ Bltu(TMP, lhs_high, label); |
| 3366 | __ Sltu(TMP, lhs_high, TMP); |
| 3367 | __ LoadConst32(AT, imm_low); |
| 3368 | __ Sltu(AT, AT, lhs_low); |
| 3369 | __ Blt(TMP, AT, label); |
| 3370 | break; |
| 3371 | } |
| 3372 | } else { |
| 3373 | switch (cond) { |
| 3374 | case kCondEQ: |
| 3375 | __ Xor(TMP, lhs_high, rhs_high); |
| 3376 | __ Xor(AT, lhs_low, rhs_low); |
| 3377 | __ Or(TMP, TMP, AT); |
| 3378 | __ Beqz(TMP, label); |
| 3379 | break; |
| 3380 | case kCondNE: |
| 3381 | __ Xor(TMP, lhs_high, rhs_high); |
| 3382 | __ Xor(AT, lhs_low, rhs_low); |
| 3383 | __ Or(TMP, TMP, AT); |
| 3384 | __ Bnez(TMP, label); |
| 3385 | break; |
| 3386 | case kCondLT: |
| 3387 | __ Blt(lhs_high, rhs_high, label); |
| 3388 | __ Slt(TMP, rhs_high, lhs_high); |
| 3389 | __ Sltu(AT, lhs_low, rhs_low); |
| 3390 | __ Blt(TMP, AT, label); |
| 3391 | break; |
| 3392 | case kCondGE: |
| 3393 | __ Blt(rhs_high, lhs_high, label); |
| 3394 | __ Slt(TMP, lhs_high, rhs_high); |
| 3395 | __ Sltu(AT, lhs_low, rhs_low); |
| 3396 | __ Or(TMP, TMP, AT); |
| 3397 | __ Beqz(TMP, label); |
| 3398 | break; |
| 3399 | case kCondLE: |
| 3400 | __ Blt(lhs_high, rhs_high, label); |
| 3401 | __ Slt(TMP, rhs_high, lhs_high); |
| 3402 | __ Sltu(AT, rhs_low, lhs_low); |
| 3403 | __ Or(TMP, TMP, AT); |
| 3404 | __ Beqz(TMP, label); |
| 3405 | break; |
| 3406 | case kCondGT: |
| 3407 | __ Blt(rhs_high, lhs_high, label); |
| 3408 | __ Slt(TMP, lhs_high, rhs_high); |
| 3409 | __ Sltu(AT, rhs_low, lhs_low); |
| 3410 | __ Blt(TMP, AT, label); |
| 3411 | break; |
| 3412 | case kCondB: |
| 3413 | __ Bltu(lhs_high, rhs_high, label); |
| 3414 | __ Sltu(TMP, rhs_high, lhs_high); |
| 3415 | __ Sltu(AT, lhs_low, rhs_low); |
| 3416 | __ Blt(TMP, AT, label); |
| 3417 | break; |
| 3418 | case kCondAE: |
| 3419 | __ Bltu(rhs_high, lhs_high, label); |
| 3420 | __ Sltu(TMP, lhs_high, rhs_high); |
| 3421 | __ Sltu(AT, lhs_low, rhs_low); |
| 3422 | __ Or(TMP, TMP, AT); |
| 3423 | __ Beqz(TMP, label); |
| 3424 | break; |
| 3425 | case kCondBE: |
| 3426 | __ Bltu(lhs_high, rhs_high, label); |
| 3427 | __ Sltu(TMP, rhs_high, lhs_high); |
| 3428 | __ Sltu(AT, rhs_low, lhs_low); |
| 3429 | __ Or(TMP, TMP, AT); |
| 3430 | __ Beqz(TMP, label); |
| 3431 | break; |
| 3432 | case kCondA: |
| 3433 | __ Bltu(rhs_high, lhs_high, label); |
| 3434 | __ Sltu(TMP, lhs_high, rhs_high); |
| 3435 | __ Sltu(AT, rhs_low, lhs_low); |
| 3436 | __ Blt(TMP, AT, label); |
| 3437 | break; |
| 3438 | } |
| 3439 | } |
| 3440 | } |
| 3441 | |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 3442 | void InstructionCodeGeneratorMIPS::GenerateFpCompare(IfCondition cond, |
| 3443 | bool gt_bias, |
| 3444 | Primitive::Type type, |
| 3445 | LocationSummary* locations) { |
| 3446 | Register dst = locations->Out().AsRegister<Register>(); |
| 3447 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3448 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3449 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3450 | if (type == Primitive::kPrimFloat) { |
| 3451 | if (isR6) { |
| 3452 | switch (cond) { |
| 3453 | case kCondEQ: |
| 3454 | __ CmpEqS(FTMP, lhs, rhs); |
| 3455 | __ Mfc1(dst, FTMP); |
| 3456 | __ Andi(dst, dst, 1); |
| 3457 | break; |
| 3458 | case kCondNE: |
| 3459 | __ CmpEqS(FTMP, lhs, rhs); |
| 3460 | __ Mfc1(dst, FTMP); |
| 3461 | __ Addiu(dst, dst, 1); |
| 3462 | break; |
| 3463 | case kCondLT: |
| 3464 | if (gt_bias) { |
| 3465 | __ CmpLtS(FTMP, lhs, rhs); |
| 3466 | } else { |
| 3467 | __ CmpUltS(FTMP, lhs, rhs); |
| 3468 | } |
| 3469 | __ Mfc1(dst, FTMP); |
| 3470 | __ Andi(dst, dst, 1); |
| 3471 | break; |
| 3472 | case kCondLE: |
| 3473 | if (gt_bias) { |
| 3474 | __ CmpLeS(FTMP, lhs, rhs); |
| 3475 | } else { |
| 3476 | __ CmpUleS(FTMP, lhs, rhs); |
| 3477 | } |
| 3478 | __ Mfc1(dst, FTMP); |
| 3479 | __ Andi(dst, dst, 1); |
| 3480 | break; |
| 3481 | case kCondGT: |
| 3482 | if (gt_bias) { |
| 3483 | __ CmpUltS(FTMP, rhs, lhs); |
| 3484 | } else { |
| 3485 | __ CmpLtS(FTMP, rhs, lhs); |
| 3486 | } |
| 3487 | __ Mfc1(dst, FTMP); |
| 3488 | __ Andi(dst, dst, 1); |
| 3489 | break; |
| 3490 | case kCondGE: |
| 3491 | if (gt_bias) { |
| 3492 | __ CmpUleS(FTMP, rhs, lhs); |
| 3493 | } else { |
| 3494 | __ CmpLeS(FTMP, rhs, lhs); |
| 3495 | } |
| 3496 | __ Mfc1(dst, FTMP); |
| 3497 | __ Andi(dst, dst, 1); |
| 3498 | break; |
| 3499 | default: |
| 3500 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3501 | UNREACHABLE(); |
| 3502 | } |
| 3503 | } else { |
| 3504 | switch (cond) { |
| 3505 | case kCondEQ: |
| 3506 | __ CeqS(0, lhs, rhs); |
| 3507 | __ LoadConst32(dst, 1); |
| 3508 | __ Movf(dst, ZERO, 0); |
| 3509 | break; |
| 3510 | case kCondNE: |
| 3511 | __ CeqS(0, lhs, rhs); |
| 3512 | __ LoadConst32(dst, 1); |
| 3513 | __ Movt(dst, ZERO, 0); |
| 3514 | break; |
| 3515 | case kCondLT: |
| 3516 | if (gt_bias) { |
| 3517 | __ ColtS(0, lhs, rhs); |
| 3518 | } else { |
| 3519 | __ CultS(0, lhs, rhs); |
| 3520 | } |
| 3521 | __ LoadConst32(dst, 1); |
| 3522 | __ Movf(dst, ZERO, 0); |
| 3523 | break; |
| 3524 | case kCondLE: |
| 3525 | if (gt_bias) { |
| 3526 | __ ColeS(0, lhs, rhs); |
| 3527 | } else { |
| 3528 | __ CuleS(0, lhs, rhs); |
| 3529 | } |
| 3530 | __ LoadConst32(dst, 1); |
| 3531 | __ Movf(dst, ZERO, 0); |
| 3532 | break; |
| 3533 | case kCondGT: |
| 3534 | if (gt_bias) { |
| 3535 | __ CultS(0, rhs, lhs); |
| 3536 | } else { |
| 3537 | __ ColtS(0, rhs, lhs); |
| 3538 | } |
| 3539 | __ LoadConst32(dst, 1); |
| 3540 | __ Movf(dst, ZERO, 0); |
| 3541 | break; |
| 3542 | case kCondGE: |
| 3543 | if (gt_bias) { |
| 3544 | __ CuleS(0, rhs, lhs); |
| 3545 | } else { |
| 3546 | __ ColeS(0, rhs, lhs); |
| 3547 | } |
| 3548 | __ LoadConst32(dst, 1); |
| 3549 | __ Movf(dst, ZERO, 0); |
| 3550 | break; |
| 3551 | default: |
| 3552 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3553 | UNREACHABLE(); |
| 3554 | } |
| 3555 | } |
| 3556 | } else { |
| 3557 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 3558 | if (isR6) { |
| 3559 | switch (cond) { |
| 3560 | case kCondEQ: |
| 3561 | __ CmpEqD(FTMP, lhs, rhs); |
| 3562 | __ Mfc1(dst, FTMP); |
| 3563 | __ Andi(dst, dst, 1); |
| 3564 | break; |
| 3565 | case kCondNE: |
| 3566 | __ CmpEqD(FTMP, lhs, rhs); |
| 3567 | __ Mfc1(dst, FTMP); |
| 3568 | __ Addiu(dst, dst, 1); |
| 3569 | break; |
| 3570 | case kCondLT: |
| 3571 | if (gt_bias) { |
| 3572 | __ CmpLtD(FTMP, lhs, rhs); |
| 3573 | } else { |
| 3574 | __ CmpUltD(FTMP, lhs, rhs); |
| 3575 | } |
| 3576 | __ Mfc1(dst, FTMP); |
| 3577 | __ Andi(dst, dst, 1); |
| 3578 | break; |
| 3579 | case kCondLE: |
| 3580 | if (gt_bias) { |
| 3581 | __ CmpLeD(FTMP, lhs, rhs); |
| 3582 | } else { |
| 3583 | __ CmpUleD(FTMP, lhs, rhs); |
| 3584 | } |
| 3585 | __ Mfc1(dst, FTMP); |
| 3586 | __ Andi(dst, dst, 1); |
| 3587 | break; |
| 3588 | case kCondGT: |
| 3589 | if (gt_bias) { |
| 3590 | __ CmpUltD(FTMP, rhs, lhs); |
| 3591 | } else { |
| 3592 | __ CmpLtD(FTMP, rhs, lhs); |
| 3593 | } |
| 3594 | __ Mfc1(dst, FTMP); |
| 3595 | __ Andi(dst, dst, 1); |
| 3596 | break; |
| 3597 | case kCondGE: |
| 3598 | if (gt_bias) { |
| 3599 | __ CmpUleD(FTMP, rhs, lhs); |
| 3600 | } else { |
| 3601 | __ CmpLeD(FTMP, rhs, lhs); |
| 3602 | } |
| 3603 | __ Mfc1(dst, FTMP); |
| 3604 | __ Andi(dst, dst, 1); |
| 3605 | break; |
| 3606 | default: |
| 3607 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3608 | UNREACHABLE(); |
| 3609 | } |
| 3610 | } else { |
| 3611 | switch (cond) { |
| 3612 | case kCondEQ: |
| 3613 | __ CeqD(0, lhs, rhs); |
| 3614 | __ LoadConst32(dst, 1); |
| 3615 | __ Movf(dst, ZERO, 0); |
| 3616 | break; |
| 3617 | case kCondNE: |
| 3618 | __ CeqD(0, lhs, rhs); |
| 3619 | __ LoadConst32(dst, 1); |
| 3620 | __ Movt(dst, ZERO, 0); |
| 3621 | break; |
| 3622 | case kCondLT: |
| 3623 | if (gt_bias) { |
| 3624 | __ ColtD(0, lhs, rhs); |
| 3625 | } else { |
| 3626 | __ CultD(0, lhs, rhs); |
| 3627 | } |
| 3628 | __ LoadConst32(dst, 1); |
| 3629 | __ Movf(dst, ZERO, 0); |
| 3630 | break; |
| 3631 | case kCondLE: |
| 3632 | if (gt_bias) { |
| 3633 | __ ColeD(0, lhs, rhs); |
| 3634 | } else { |
| 3635 | __ CuleD(0, lhs, rhs); |
| 3636 | } |
| 3637 | __ LoadConst32(dst, 1); |
| 3638 | __ Movf(dst, ZERO, 0); |
| 3639 | break; |
| 3640 | case kCondGT: |
| 3641 | if (gt_bias) { |
| 3642 | __ CultD(0, rhs, lhs); |
| 3643 | } else { |
| 3644 | __ ColtD(0, rhs, lhs); |
| 3645 | } |
| 3646 | __ LoadConst32(dst, 1); |
| 3647 | __ Movf(dst, ZERO, 0); |
| 3648 | break; |
| 3649 | case kCondGE: |
| 3650 | if (gt_bias) { |
| 3651 | __ CuleD(0, rhs, lhs); |
| 3652 | } else { |
| 3653 | __ ColeD(0, rhs, lhs); |
| 3654 | } |
| 3655 | __ LoadConst32(dst, 1); |
| 3656 | __ Movf(dst, ZERO, 0); |
| 3657 | break; |
| 3658 | default: |
| 3659 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3660 | UNREACHABLE(); |
| 3661 | } |
| 3662 | } |
| 3663 | } |
| 3664 | } |
| 3665 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 3666 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR2(IfCondition cond, |
| 3667 | bool gt_bias, |
| 3668 | Primitive::Type type, |
| 3669 | LocationSummary* input_locations, |
| 3670 | int cc) { |
| 3671 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3672 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3673 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
| 3674 | if (type == Primitive::kPrimFloat) { |
| 3675 | switch (cond) { |
| 3676 | case kCondEQ: |
| 3677 | __ CeqS(cc, lhs, rhs); |
| 3678 | return false; |
| 3679 | case kCondNE: |
| 3680 | __ CeqS(cc, lhs, rhs); |
| 3681 | return true; |
| 3682 | case kCondLT: |
| 3683 | if (gt_bias) { |
| 3684 | __ ColtS(cc, lhs, rhs); |
| 3685 | } else { |
| 3686 | __ CultS(cc, lhs, rhs); |
| 3687 | } |
| 3688 | return false; |
| 3689 | case kCondLE: |
| 3690 | if (gt_bias) { |
| 3691 | __ ColeS(cc, lhs, rhs); |
| 3692 | } else { |
| 3693 | __ CuleS(cc, lhs, rhs); |
| 3694 | } |
| 3695 | return false; |
| 3696 | case kCondGT: |
| 3697 | if (gt_bias) { |
| 3698 | __ CultS(cc, rhs, lhs); |
| 3699 | } else { |
| 3700 | __ ColtS(cc, rhs, lhs); |
| 3701 | } |
| 3702 | return false; |
| 3703 | case kCondGE: |
| 3704 | if (gt_bias) { |
| 3705 | __ CuleS(cc, rhs, lhs); |
| 3706 | } else { |
| 3707 | __ ColeS(cc, rhs, lhs); |
| 3708 | } |
| 3709 | return false; |
| 3710 | default: |
| 3711 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3712 | UNREACHABLE(); |
| 3713 | } |
| 3714 | } else { |
| 3715 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 3716 | switch (cond) { |
| 3717 | case kCondEQ: |
| 3718 | __ CeqD(cc, lhs, rhs); |
| 3719 | return false; |
| 3720 | case kCondNE: |
| 3721 | __ CeqD(cc, lhs, rhs); |
| 3722 | return true; |
| 3723 | case kCondLT: |
| 3724 | if (gt_bias) { |
| 3725 | __ ColtD(cc, lhs, rhs); |
| 3726 | } else { |
| 3727 | __ CultD(cc, lhs, rhs); |
| 3728 | } |
| 3729 | return false; |
| 3730 | case kCondLE: |
| 3731 | if (gt_bias) { |
| 3732 | __ ColeD(cc, lhs, rhs); |
| 3733 | } else { |
| 3734 | __ CuleD(cc, lhs, rhs); |
| 3735 | } |
| 3736 | return false; |
| 3737 | case kCondGT: |
| 3738 | if (gt_bias) { |
| 3739 | __ CultD(cc, rhs, lhs); |
| 3740 | } else { |
| 3741 | __ ColtD(cc, rhs, lhs); |
| 3742 | } |
| 3743 | return false; |
| 3744 | case kCondGE: |
| 3745 | if (gt_bias) { |
| 3746 | __ CuleD(cc, rhs, lhs); |
| 3747 | } else { |
| 3748 | __ ColeD(cc, rhs, lhs); |
| 3749 | } |
| 3750 | return false; |
| 3751 | default: |
| 3752 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3753 | UNREACHABLE(); |
| 3754 | } |
| 3755 | } |
| 3756 | } |
| 3757 | |
| 3758 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR6(IfCondition cond, |
| 3759 | bool gt_bias, |
| 3760 | Primitive::Type type, |
| 3761 | LocationSummary* input_locations, |
| 3762 | FRegister dst) { |
| 3763 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3764 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3765 | CHECK(codegen_->GetInstructionSetFeatures().IsR6()); |
| 3766 | if (type == Primitive::kPrimFloat) { |
| 3767 | switch (cond) { |
| 3768 | case kCondEQ: |
| 3769 | __ CmpEqS(dst, lhs, rhs); |
| 3770 | return false; |
| 3771 | case kCondNE: |
| 3772 | __ CmpEqS(dst, lhs, rhs); |
| 3773 | return true; |
| 3774 | case kCondLT: |
| 3775 | if (gt_bias) { |
| 3776 | __ CmpLtS(dst, lhs, rhs); |
| 3777 | } else { |
| 3778 | __ CmpUltS(dst, lhs, rhs); |
| 3779 | } |
| 3780 | return false; |
| 3781 | case kCondLE: |
| 3782 | if (gt_bias) { |
| 3783 | __ CmpLeS(dst, lhs, rhs); |
| 3784 | } else { |
| 3785 | __ CmpUleS(dst, lhs, rhs); |
| 3786 | } |
| 3787 | return false; |
| 3788 | case kCondGT: |
| 3789 | if (gt_bias) { |
| 3790 | __ CmpUltS(dst, rhs, lhs); |
| 3791 | } else { |
| 3792 | __ CmpLtS(dst, rhs, lhs); |
| 3793 | } |
| 3794 | return false; |
| 3795 | case kCondGE: |
| 3796 | if (gt_bias) { |
| 3797 | __ CmpUleS(dst, rhs, lhs); |
| 3798 | } else { |
| 3799 | __ CmpLeS(dst, rhs, lhs); |
| 3800 | } |
| 3801 | return false; |
| 3802 | default: |
| 3803 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3804 | UNREACHABLE(); |
| 3805 | } |
| 3806 | } else { |
| 3807 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 3808 | switch (cond) { |
| 3809 | case kCondEQ: |
| 3810 | __ CmpEqD(dst, lhs, rhs); |
| 3811 | return false; |
| 3812 | case kCondNE: |
| 3813 | __ CmpEqD(dst, lhs, rhs); |
| 3814 | return true; |
| 3815 | case kCondLT: |
| 3816 | if (gt_bias) { |
| 3817 | __ CmpLtD(dst, lhs, rhs); |
| 3818 | } else { |
| 3819 | __ CmpUltD(dst, lhs, rhs); |
| 3820 | } |
| 3821 | return false; |
| 3822 | case kCondLE: |
| 3823 | if (gt_bias) { |
| 3824 | __ CmpLeD(dst, lhs, rhs); |
| 3825 | } else { |
| 3826 | __ CmpUleD(dst, lhs, rhs); |
| 3827 | } |
| 3828 | return false; |
| 3829 | case kCondGT: |
| 3830 | if (gt_bias) { |
| 3831 | __ CmpUltD(dst, rhs, lhs); |
| 3832 | } else { |
| 3833 | __ CmpLtD(dst, rhs, lhs); |
| 3834 | } |
| 3835 | return false; |
| 3836 | case kCondGE: |
| 3837 | if (gt_bias) { |
| 3838 | __ CmpUleD(dst, rhs, lhs); |
| 3839 | } else { |
| 3840 | __ CmpLeD(dst, rhs, lhs); |
| 3841 | } |
| 3842 | return false; |
| 3843 | default: |
| 3844 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3845 | UNREACHABLE(); |
| 3846 | } |
| 3847 | } |
| 3848 | } |
| 3849 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3850 | void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond, |
| 3851 | bool gt_bias, |
| 3852 | Primitive::Type type, |
| 3853 | LocationSummary* locations, |
| 3854 | MipsLabel* label) { |
| 3855 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3856 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3857 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3858 | if (type == Primitive::kPrimFloat) { |
| 3859 | if (isR6) { |
| 3860 | switch (cond) { |
| 3861 | case kCondEQ: |
| 3862 | __ CmpEqS(FTMP, lhs, rhs); |
| 3863 | __ Bc1nez(FTMP, label); |
| 3864 | break; |
| 3865 | case kCondNE: |
| 3866 | __ CmpEqS(FTMP, lhs, rhs); |
| 3867 | __ Bc1eqz(FTMP, label); |
| 3868 | break; |
| 3869 | case kCondLT: |
| 3870 | if (gt_bias) { |
| 3871 | __ CmpLtS(FTMP, lhs, rhs); |
| 3872 | } else { |
| 3873 | __ CmpUltS(FTMP, lhs, rhs); |
| 3874 | } |
| 3875 | __ Bc1nez(FTMP, label); |
| 3876 | break; |
| 3877 | case kCondLE: |
| 3878 | if (gt_bias) { |
| 3879 | __ CmpLeS(FTMP, lhs, rhs); |
| 3880 | } else { |
| 3881 | __ CmpUleS(FTMP, lhs, rhs); |
| 3882 | } |
| 3883 | __ Bc1nez(FTMP, label); |
| 3884 | break; |
| 3885 | case kCondGT: |
| 3886 | if (gt_bias) { |
| 3887 | __ CmpUltS(FTMP, rhs, lhs); |
| 3888 | } else { |
| 3889 | __ CmpLtS(FTMP, rhs, lhs); |
| 3890 | } |
| 3891 | __ Bc1nez(FTMP, label); |
| 3892 | break; |
| 3893 | case kCondGE: |
| 3894 | if (gt_bias) { |
| 3895 | __ CmpUleS(FTMP, rhs, lhs); |
| 3896 | } else { |
| 3897 | __ CmpLeS(FTMP, rhs, lhs); |
| 3898 | } |
| 3899 | __ Bc1nez(FTMP, label); |
| 3900 | break; |
| 3901 | default: |
| 3902 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 3903 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3904 | } |
| 3905 | } else { |
| 3906 | switch (cond) { |
| 3907 | case kCondEQ: |
| 3908 | __ CeqS(0, lhs, rhs); |
| 3909 | __ Bc1t(0, label); |
| 3910 | break; |
| 3911 | case kCondNE: |
| 3912 | __ CeqS(0, lhs, rhs); |
| 3913 | __ Bc1f(0, label); |
| 3914 | break; |
| 3915 | case kCondLT: |
| 3916 | if (gt_bias) { |
| 3917 | __ ColtS(0, lhs, rhs); |
| 3918 | } else { |
| 3919 | __ CultS(0, lhs, rhs); |
| 3920 | } |
| 3921 | __ Bc1t(0, label); |
| 3922 | break; |
| 3923 | case kCondLE: |
| 3924 | if (gt_bias) { |
| 3925 | __ ColeS(0, lhs, rhs); |
| 3926 | } else { |
| 3927 | __ CuleS(0, lhs, rhs); |
| 3928 | } |
| 3929 | __ Bc1t(0, label); |
| 3930 | break; |
| 3931 | case kCondGT: |
| 3932 | if (gt_bias) { |
| 3933 | __ CultS(0, rhs, lhs); |
| 3934 | } else { |
| 3935 | __ ColtS(0, rhs, lhs); |
| 3936 | } |
| 3937 | __ Bc1t(0, label); |
| 3938 | break; |
| 3939 | case kCondGE: |
| 3940 | if (gt_bias) { |
| 3941 | __ CuleS(0, rhs, lhs); |
| 3942 | } else { |
| 3943 | __ ColeS(0, rhs, lhs); |
| 3944 | } |
| 3945 | __ Bc1t(0, label); |
| 3946 | break; |
| 3947 | default: |
| 3948 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 3949 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3950 | } |
| 3951 | } |
| 3952 | } else { |
| 3953 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 3954 | if (isR6) { |
| 3955 | switch (cond) { |
| 3956 | case kCondEQ: |
| 3957 | __ CmpEqD(FTMP, lhs, rhs); |
| 3958 | __ Bc1nez(FTMP, label); |
| 3959 | break; |
| 3960 | case kCondNE: |
| 3961 | __ CmpEqD(FTMP, lhs, rhs); |
| 3962 | __ Bc1eqz(FTMP, label); |
| 3963 | break; |
| 3964 | case kCondLT: |
| 3965 | if (gt_bias) { |
| 3966 | __ CmpLtD(FTMP, lhs, rhs); |
| 3967 | } else { |
| 3968 | __ CmpUltD(FTMP, lhs, rhs); |
| 3969 | } |
| 3970 | __ Bc1nez(FTMP, label); |
| 3971 | break; |
| 3972 | case kCondLE: |
| 3973 | if (gt_bias) { |
| 3974 | __ CmpLeD(FTMP, lhs, rhs); |
| 3975 | } else { |
| 3976 | __ CmpUleD(FTMP, lhs, rhs); |
| 3977 | } |
| 3978 | __ Bc1nez(FTMP, label); |
| 3979 | break; |
| 3980 | case kCondGT: |
| 3981 | if (gt_bias) { |
| 3982 | __ CmpUltD(FTMP, rhs, lhs); |
| 3983 | } else { |
| 3984 | __ CmpLtD(FTMP, rhs, lhs); |
| 3985 | } |
| 3986 | __ Bc1nez(FTMP, label); |
| 3987 | break; |
| 3988 | case kCondGE: |
| 3989 | if (gt_bias) { |
| 3990 | __ CmpUleD(FTMP, rhs, lhs); |
| 3991 | } else { |
| 3992 | __ CmpLeD(FTMP, rhs, lhs); |
| 3993 | } |
| 3994 | __ Bc1nez(FTMP, label); |
| 3995 | break; |
| 3996 | default: |
| 3997 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 3998 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3999 | } |
| 4000 | } else { |
| 4001 | switch (cond) { |
| 4002 | case kCondEQ: |
| 4003 | __ CeqD(0, lhs, rhs); |
| 4004 | __ Bc1t(0, label); |
| 4005 | break; |
| 4006 | case kCondNE: |
| 4007 | __ CeqD(0, lhs, rhs); |
| 4008 | __ Bc1f(0, label); |
| 4009 | break; |
| 4010 | case kCondLT: |
| 4011 | if (gt_bias) { |
| 4012 | __ ColtD(0, lhs, rhs); |
| 4013 | } else { |
| 4014 | __ CultD(0, lhs, rhs); |
| 4015 | } |
| 4016 | __ Bc1t(0, label); |
| 4017 | break; |
| 4018 | case kCondLE: |
| 4019 | if (gt_bias) { |
| 4020 | __ ColeD(0, lhs, rhs); |
| 4021 | } else { |
| 4022 | __ CuleD(0, lhs, rhs); |
| 4023 | } |
| 4024 | __ Bc1t(0, label); |
| 4025 | break; |
| 4026 | case kCondGT: |
| 4027 | if (gt_bias) { |
| 4028 | __ CultD(0, rhs, lhs); |
| 4029 | } else { |
| 4030 | __ ColtD(0, rhs, lhs); |
| 4031 | } |
| 4032 | __ Bc1t(0, label); |
| 4033 | break; |
| 4034 | case kCondGE: |
| 4035 | if (gt_bias) { |
| 4036 | __ CuleD(0, rhs, lhs); |
| 4037 | } else { |
| 4038 | __ ColeD(0, rhs, lhs); |
| 4039 | } |
| 4040 | __ Bc1t(0, label); |
| 4041 | break; |
| 4042 | default: |
| 4043 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4044 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4045 | } |
| 4046 | } |
| 4047 | } |
| 4048 | } |
| 4049 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4050 | void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4051 | size_t condition_input_index, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4052 | MipsLabel* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4053 | MipsLabel* false_target) { |
| 4054 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4055 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4056 | if (true_target == nullptr && false_target == nullptr) { |
| 4057 | // Nothing to do. The code always falls through. |
| 4058 | return; |
| 4059 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 4060 | // Constant condition, statically compared against "true" (integer value 1). |
| 4061 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4062 | if (true_target != nullptr) { |
| 4063 | __ B(true_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4064 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4065 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 4066 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4067 | if (false_target != nullptr) { |
| 4068 | __ B(false_target); |
| 4069 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4070 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4071 | return; |
| 4072 | } |
| 4073 | |
| 4074 | // The following code generates these patterns: |
| 4075 | // (1) true_target == nullptr && false_target != nullptr |
| 4076 | // - opposite condition true => branch to false_target |
| 4077 | // (2) true_target != nullptr && false_target == nullptr |
| 4078 | // - condition true => branch to true_target |
| 4079 | // (3) true_target != nullptr && false_target != nullptr |
| 4080 | // - condition true => branch to true_target |
| 4081 | // - branch to false_target |
| 4082 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4083 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4084 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4085 | DCHECK(cond_val.IsRegister()); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4086 | if (true_target == nullptr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4087 | __ Beqz(cond_val.AsRegister<Register>(), false_target); |
| 4088 | } else { |
| 4089 | __ Bnez(cond_val.AsRegister<Register>(), true_target); |
| 4090 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4091 | } else { |
| 4092 | // The condition instruction has not been materialized, use its inputs as |
| 4093 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4094 | HCondition* condition = cond->AsCondition(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4095 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 4096 | LocationSummary* locations = cond->GetLocations(); |
| 4097 | IfCondition if_cond = condition->GetCondition(); |
| 4098 | MipsLabel* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4099 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4100 | if (true_target == nullptr) { |
| 4101 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4102 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4103 | } |
| 4104 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4105 | switch (type) { |
| 4106 | default: |
| 4107 | GenerateIntCompareAndBranch(if_cond, locations, branch_target); |
| 4108 | break; |
| 4109 | case Primitive::kPrimLong: |
| 4110 | GenerateLongCompareAndBranch(if_cond, locations, branch_target); |
| 4111 | break; |
| 4112 | case Primitive::kPrimFloat: |
| 4113 | case Primitive::kPrimDouble: |
| 4114 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 4115 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4116 | } |
| 4117 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4118 | |
| 4119 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 4120 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 4121 | if (true_target != nullptr && false_target != nullptr) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4122 | __ B(false_target); |
| 4123 | } |
| 4124 | } |
| 4125 | |
| 4126 | void LocationsBuilderMIPS::VisitIf(HIf* if_instr) { |
| 4127 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4128 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4129 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4130 | } |
| 4131 | } |
| 4132 | |
| 4133 | void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4134 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 4135 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 4136 | MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 4137 | nullptr : codegen_->GetLabelOf(true_successor); |
| 4138 | MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 4139 | nullptr : codegen_->GetLabelOf(false_successor); |
| 4140 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4141 | } |
| 4142 | |
| 4143 | void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 4144 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 4145 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4146 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4147 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4148 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4149 | } |
| 4150 | } |
| 4151 | |
| 4152 | void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 4153 | SlowPathCodeMIPS* slow_path = |
| 4154 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4155 | GenerateTestAndBranch(deoptimize, |
| 4156 | /* condition_input_index */ 0, |
| 4157 | slow_path->GetEntryLabel(), |
| 4158 | /* false_target */ nullptr); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4159 | } |
| 4160 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4161 | // This function returns true if a conditional move can be generated for HSelect. |
| 4162 | // Otherwise it returns false and HSelect must be implemented in terms of conditonal |
| 4163 | // branches and regular moves. |
| 4164 | // |
| 4165 | // If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect. |
| 4166 | // |
| 4167 | // While determining feasibility of a conditional move and setting inputs/outputs |
| 4168 | // are two distinct tasks, this function does both because they share quite a bit |
| 4169 | // of common logic. |
| 4170 | static bool CanMoveConditionally(HSelect* select, bool is_r6, LocationSummary* locations_to_set) { |
| 4171 | bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition()); |
| 4172 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4173 | HCondition* condition = cond->AsCondition(); |
| 4174 | |
| 4175 | Primitive::Type cond_type = materialized ? Primitive::kPrimInt : condition->InputAt(0)->GetType(); |
| 4176 | Primitive::Type dst_type = select->GetType(); |
| 4177 | |
| 4178 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 4179 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 4180 | bool is_true_value_zero_constant = |
| 4181 | (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern()); |
| 4182 | bool is_false_value_zero_constant = |
| 4183 | (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern()); |
| 4184 | |
| 4185 | bool can_move_conditionally = false; |
| 4186 | bool use_const_for_false_in = false; |
| 4187 | bool use_const_for_true_in = false; |
| 4188 | |
| 4189 | if (!cond->IsConstant()) { |
| 4190 | switch (cond_type) { |
| 4191 | default: |
| 4192 | switch (dst_type) { |
| 4193 | default: |
| 4194 | // Moving int on int condition. |
| 4195 | if (is_r6) { |
| 4196 | if (is_true_value_zero_constant) { |
| 4197 | // seleqz out_reg, false_reg, cond_reg |
| 4198 | can_move_conditionally = true; |
| 4199 | use_const_for_true_in = true; |
| 4200 | } else if (is_false_value_zero_constant) { |
| 4201 | // selnez out_reg, true_reg, cond_reg |
| 4202 | can_move_conditionally = true; |
| 4203 | use_const_for_false_in = true; |
| 4204 | } else if (materialized) { |
| 4205 | // Not materializing unmaterialized int conditions |
| 4206 | // to keep the instruction count low. |
| 4207 | // selnez AT, true_reg, cond_reg |
| 4208 | // seleqz TMP, false_reg, cond_reg |
| 4209 | // or out_reg, AT, TMP |
| 4210 | can_move_conditionally = true; |
| 4211 | } |
| 4212 | } else { |
| 4213 | // movn out_reg, true_reg/ZERO, cond_reg |
| 4214 | can_move_conditionally = true; |
| 4215 | use_const_for_true_in = is_true_value_zero_constant; |
| 4216 | } |
| 4217 | break; |
| 4218 | case Primitive::kPrimLong: |
| 4219 | // Moving long on int condition. |
| 4220 | if (is_r6) { |
| 4221 | if (is_true_value_zero_constant) { |
| 4222 | // seleqz out_reg_lo, false_reg_lo, cond_reg |
| 4223 | // seleqz out_reg_hi, false_reg_hi, cond_reg |
| 4224 | can_move_conditionally = true; |
| 4225 | use_const_for_true_in = true; |
| 4226 | } else if (is_false_value_zero_constant) { |
| 4227 | // selnez out_reg_lo, true_reg_lo, cond_reg |
| 4228 | // selnez out_reg_hi, true_reg_hi, cond_reg |
| 4229 | can_move_conditionally = true; |
| 4230 | use_const_for_false_in = true; |
| 4231 | } |
| 4232 | // Other long conditional moves would generate 6+ instructions, |
| 4233 | // which is too many. |
| 4234 | } else { |
| 4235 | // movn out_reg_lo, true_reg_lo/ZERO, cond_reg |
| 4236 | // movn out_reg_hi, true_reg_hi/ZERO, cond_reg |
| 4237 | can_move_conditionally = true; |
| 4238 | use_const_for_true_in = is_true_value_zero_constant; |
| 4239 | } |
| 4240 | break; |
| 4241 | case Primitive::kPrimFloat: |
| 4242 | case Primitive::kPrimDouble: |
| 4243 | // Moving float/double on int condition. |
| 4244 | if (is_r6) { |
| 4245 | if (materialized) { |
| 4246 | // Not materializing unmaterialized int conditions |
| 4247 | // to keep the instruction count low. |
| 4248 | can_move_conditionally = true; |
| 4249 | if (is_true_value_zero_constant) { |
| 4250 | // sltu TMP, ZERO, cond_reg |
| 4251 | // mtc1 TMP, temp_cond_reg |
| 4252 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 4253 | use_const_for_true_in = true; |
| 4254 | } else if (is_false_value_zero_constant) { |
| 4255 | // sltu TMP, ZERO, cond_reg |
| 4256 | // mtc1 TMP, temp_cond_reg |
| 4257 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 4258 | use_const_for_false_in = true; |
| 4259 | } else { |
| 4260 | // sltu TMP, ZERO, cond_reg |
| 4261 | // mtc1 TMP, temp_cond_reg |
| 4262 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 4263 | // mov.fmt out_reg, temp_cond_reg |
| 4264 | } |
| 4265 | } |
| 4266 | } else { |
| 4267 | // movn.fmt out_reg, true_reg, cond_reg |
| 4268 | can_move_conditionally = true; |
| 4269 | } |
| 4270 | break; |
| 4271 | } |
| 4272 | break; |
| 4273 | case Primitive::kPrimLong: |
| 4274 | // We don't materialize long comparison now |
| 4275 | // and use conditional branches instead. |
| 4276 | break; |
| 4277 | case Primitive::kPrimFloat: |
| 4278 | case Primitive::kPrimDouble: |
| 4279 | switch (dst_type) { |
| 4280 | default: |
| 4281 | // Moving int on float/double condition. |
| 4282 | if (is_r6) { |
| 4283 | if (is_true_value_zero_constant) { |
| 4284 | // mfc1 TMP, temp_cond_reg |
| 4285 | // seleqz out_reg, false_reg, TMP |
| 4286 | can_move_conditionally = true; |
| 4287 | use_const_for_true_in = true; |
| 4288 | } else if (is_false_value_zero_constant) { |
| 4289 | // mfc1 TMP, temp_cond_reg |
| 4290 | // selnez out_reg, true_reg, TMP |
| 4291 | can_move_conditionally = true; |
| 4292 | use_const_for_false_in = true; |
| 4293 | } else { |
| 4294 | // mfc1 TMP, temp_cond_reg |
| 4295 | // selnez AT, true_reg, TMP |
| 4296 | // seleqz TMP, false_reg, TMP |
| 4297 | // or out_reg, AT, TMP |
| 4298 | can_move_conditionally = true; |
| 4299 | } |
| 4300 | } else { |
| 4301 | // movt out_reg, true_reg/ZERO, cc |
| 4302 | can_move_conditionally = true; |
| 4303 | use_const_for_true_in = is_true_value_zero_constant; |
| 4304 | } |
| 4305 | break; |
| 4306 | case Primitive::kPrimLong: |
| 4307 | // Moving long on float/double condition. |
| 4308 | if (is_r6) { |
| 4309 | if (is_true_value_zero_constant) { |
| 4310 | // mfc1 TMP, temp_cond_reg |
| 4311 | // seleqz out_reg_lo, false_reg_lo, TMP |
| 4312 | // seleqz out_reg_hi, false_reg_hi, TMP |
| 4313 | can_move_conditionally = true; |
| 4314 | use_const_for_true_in = true; |
| 4315 | } else if (is_false_value_zero_constant) { |
| 4316 | // mfc1 TMP, temp_cond_reg |
| 4317 | // selnez out_reg_lo, true_reg_lo, TMP |
| 4318 | // selnez out_reg_hi, true_reg_hi, TMP |
| 4319 | can_move_conditionally = true; |
| 4320 | use_const_for_false_in = true; |
| 4321 | } |
| 4322 | // Other long conditional moves would generate 6+ instructions, |
| 4323 | // which is too many. |
| 4324 | } else { |
| 4325 | // movt out_reg_lo, true_reg_lo/ZERO, cc |
| 4326 | // movt out_reg_hi, true_reg_hi/ZERO, cc |
| 4327 | can_move_conditionally = true; |
| 4328 | use_const_for_true_in = is_true_value_zero_constant; |
| 4329 | } |
| 4330 | break; |
| 4331 | case Primitive::kPrimFloat: |
| 4332 | case Primitive::kPrimDouble: |
| 4333 | // Moving float/double on float/double condition. |
| 4334 | if (is_r6) { |
| 4335 | can_move_conditionally = true; |
| 4336 | if (is_true_value_zero_constant) { |
| 4337 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 4338 | use_const_for_true_in = true; |
| 4339 | } else if (is_false_value_zero_constant) { |
| 4340 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 4341 | use_const_for_false_in = true; |
| 4342 | } else { |
| 4343 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 4344 | // mov.fmt out_reg, temp_cond_reg |
| 4345 | } |
| 4346 | } else { |
| 4347 | // movt.fmt out_reg, true_reg, cc |
| 4348 | can_move_conditionally = true; |
| 4349 | } |
| 4350 | break; |
| 4351 | } |
| 4352 | break; |
| 4353 | } |
| 4354 | } |
| 4355 | |
| 4356 | if (can_move_conditionally) { |
| 4357 | DCHECK(!use_const_for_false_in || !use_const_for_true_in); |
| 4358 | } else { |
| 4359 | DCHECK(!use_const_for_false_in); |
| 4360 | DCHECK(!use_const_for_true_in); |
| 4361 | } |
| 4362 | |
| 4363 | if (locations_to_set != nullptr) { |
| 4364 | if (use_const_for_false_in) { |
| 4365 | locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value)); |
| 4366 | } else { |
| 4367 | locations_to_set->SetInAt(0, |
| 4368 | Primitive::IsFloatingPointType(dst_type) |
| 4369 | ? Location::RequiresFpuRegister() |
| 4370 | : Location::RequiresRegister()); |
| 4371 | } |
| 4372 | if (use_const_for_true_in) { |
| 4373 | locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value)); |
| 4374 | } else { |
| 4375 | locations_to_set->SetInAt(1, |
| 4376 | Primitive::IsFloatingPointType(dst_type) |
| 4377 | ? Location::RequiresFpuRegister() |
| 4378 | : Location::RequiresRegister()); |
| 4379 | } |
| 4380 | if (materialized) { |
| 4381 | locations_to_set->SetInAt(2, Location::RequiresRegister()); |
| 4382 | } |
| 4383 | // On R6 we don't require the output to be the same as the |
| 4384 | // first input for conditional moves unlike on R2. |
| 4385 | bool is_out_same_as_first_in = !can_move_conditionally || !is_r6; |
| 4386 | if (is_out_same_as_first_in) { |
| 4387 | locations_to_set->SetOut(Location::SameAsFirstInput()); |
| 4388 | } else { |
| 4389 | locations_to_set->SetOut(Primitive::IsFloatingPointType(dst_type) |
| 4390 | ? Location::RequiresFpuRegister() |
| 4391 | : Location::RequiresRegister()); |
| 4392 | } |
| 4393 | } |
| 4394 | |
| 4395 | return can_move_conditionally; |
| 4396 | } |
| 4397 | |
| 4398 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR2(HSelect* select) { |
| 4399 | LocationSummary* locations = select->GetLocations(); |
| 4400 | Location dst = locations->Out(); |
| 4401 | Location src = locations->InAt(1); |
| 4402 | Register src_reg = ZERO; |
| 4403 | Register src_reg_high = ZERO; |
| 4404 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4405 | Register cond_reg = TMP; |
| 4406 | int cond_cc = 0; |
| 4407 | Primitive::Type cond_type = Primitive::kPrimInt; |
| 4408 | bool cond_inverted = false; |
| 4409 | Primitive::Type dst_type = select->GetType(); |
| 4410 | |
| 4411 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 4412 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 4413 | } else { |
| 4414 | HCondition* condition = cond->AsCondition(); |
| 4415 | LocationSummary* cond_locations = cond->GetLocations(); |
| 4416 | IfCondition if_cond = condition->GetCondition(); |
| 4417 | cond_type = condition->InputAt(0)->GetType(); |
| 4418 | switch (cond_type) { |
| 4419 | default: |
| 4420 | DCHECK_NE(cond_type, Primitive::kPrimLong); |
| 4421 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 4422 | break; |
| 4423 | case Primitive::kPrimFloat: |
| 4424 | case Primitive::kPrimDouble: |
| 4425 | cond_inverted = MaterializeFpCompareR2(if_cond, |
| 4426 | condition->IsGtBias(), |
| 4427 | cond_type, |
| 4428 | cond_locations, |
| 4429 | cond_cc); |
| 4430 | break; |
| 4431 | } |
| 4432 | } |
| 4433 | |
| 4434 | DCHECK(dst.Equals(locations->InAt(0))); |
| 4435 | if (src.IsRegister()) { |
| 4436 | src_reg = src.AsRegister<Register>(); |
| 4437 | } else if (src.IsRegisterPair()) { |
| 4438 | src_reg = src.AsRegisterPairLow<Register>(); |
| 4439 | src_reg_high = src.AsRegisterPairHigh<Register>(); |
| 4440 | } else if (src.IsConstant()) { |
| 4441 | DCHECK(src.GetConstant()->IsZeroBitPattern()); |
| 4442 | } |
| 4443 | |
| 4444 | switch (cond_type) { |
| 4445 | default: |
| 4446 | switch (dst_type) { |
| 4447 | default: |
| 4448 | if (cond_inverted) { |
| 4449 | __ Movz(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 4450 | } else { |
| 4451 | __ Movn(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 4452 | } |
| 4453 | break; |
| 4454 | case Primitive::kPrimLong: |
| 4455 | if (cond_inverted) { |
| 4456 | __ Movz(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 4457 | __ Movz(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 4458 | } else { |
| 4459 | __ Movn(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 4460 | __ Movn(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 4461 | } |
| 4462 | break; |
| 4463 | case Primitive::kPrimFloat: |
| 4464 | if (cond_inverted) { |
| 4465 | __ MovzS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 4466 | } else { |
| 4467 | __ MovnS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 4468 | } |
| 4469 | break; |
| 4470 | case Primitive::kPrimDouble: |
| 4471 | if (cond_inverted) { |
| 4472 | __ MovzD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 4473 | } else { |
| 4474 | __ MovnD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 4475 | } |
| 4476 | break; |
| 4477 | } |
| 4478 | break; |
| 4479 | case Primitive::kPrimLong: |
| 4480 | LOG(FATAL) << "Unreachable"; |
| 4481 | UNREACHABLE(); |
| 4482 | case Primitive::kPrimFloat: |
| 4483 | case Primitive::kPrimDouble: |
| 4484 | switch (dst_type) { |
| 4485 | default: |
| 4486 | if (cond_inverted) { |
| 4487 | __ Movf(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 4488 | } else { |
| 4489 | __ Movt(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 4490 | } |
| 4491 | break; |
| 4492 | case Primitive::kPrimLong: |
| 4493 | if (cond_inverted) { |
| 4494 | __ Movf(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 4495 | __ Movf(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 4496 | } else { |
| 4497 | __ Movt(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 4498 | __ Movt(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 4499 | } |
| 4500 | break; |
| 4501 | case Primitive::kPrimFloat: |
| 4502 | if (cond_inverted) { |
| 4503 | __ MovfS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 4504 | } else { |
| 4505 | __ MovtS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 4506 | } |
| 4507 | break; |
| 4508 | case Primitive::kPrimDouble: |
| 4509 | if (cond_inverted) { |
| 4510 | __ MovfD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 4511 | } else { |
| 4512 | __ MovtD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 4513 | } |
| 4514 | break; |
| 4515 | } |
| 4516 | break; |
| 4517 | } |
| 4518 | } |
| 4519 | |
| 4520 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR6(HSelect* select) { |
| 4521 | LocationSummary* locations = select->GetLocations(); |
| 4522 | Location dst = locations->Out(); |
| 4523 | Location false_src = locations->InAt(0); |
| 4524 | Location true_src = locations->InAt(1); |
| 4525 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4526 | Register cond_reg = TMP; |
| 4527 | FRegister fcond_reg = FTMP; |
| 4528 | Primitive::Type cond_type = Primitive::kPrimInt; |
| 4529 | bool cond_inverted = false; |
| 4530 | Primitive::Type dst_type = select->GetType(); |
| 4531 | |
| 4532 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 4533 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 4534 | } else { |
| 4535 | HCondition* condition = cond->AsCondition(); |
| 4536 | LocationSummary* cond_locations = cond->GetLocations(); |
| 4537 | IfCondition if_cond = condition->GetCondition(); |
| 4538 | cond_type = condition->InputAt(0)->GetType(); |
| 4539 | switch (cond_type) { |
| 4540 | default: |
| 4541 | DCHECK_NE(cond_type, Primitive::kPrimLong); |
| 4542 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 4543 | break; |
| 4544 | case Primitive::kPrimFloat: |
| 4545 | case Primitive::kPrimDouble: |
| 4546 | cond_inverted = MaterializeFpCompareR6(if_cond, |
| 4547 | condition->IsGtBias(), |
| 4548 | cond_type, |
| 4549 | cond_locations, |
| 4550 | fcond_reg); |
| 4551 | break; |
| 4552 | } |
| 4553 | } |
| 4554 | |
| 4555 | if (true_src.IsConstant()) { |
| 4556 | DCHECK(true_src.GetConstant()->IsZeroBitPattern()); |
| 4557 | } |
| 4558 | if (false_src.IsConstant()) { |
| 4559 | DCHECK(false_src.GetConstant()->IsZeroBitPattern()); |
| 4560 | } |
| 4561 | |
| 4562 | switch (dst_type) { |
| 4563 | default: |
| 4564 | if (Primitive::IsFloatingPointType(cond_type)) { |
| 4565 | __ Mfc1(cond_reg, fcond_reg); |
| 4566 | } |
| 4567 | if (true_src.IsConstant()) { |
| 4568 | if (cond_inverted) { |
| 4569 | __ Selnez(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 4570 | } else { |
| 4571 | __ Seleqz(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 4572 | } |
| 4573 | } else if (false_src.IsConstant()) { |
| 4574 | if (cond_inverted) { |
| 4575 | __ Seleqz(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 4576 | } else { |
| 4577 | __ Selnez(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 4578 | } |
| 4579 | } else { |
| 4580 | DCHECK_NE(cond_reg, AT); |
| 4581 | if (cond_inverted) { |
| 4582 | __ Seleqz(AT, true_src.AsRegister<Register>(), cond_reg); |
| 4583 | __ Selnez(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 4584 | } else { |
| 4585 | __ Selnez(AT, true_src.AsRegister<Register>(), cond_reg); |
| 4586 | __ Seleqz(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 4587 | } |
| 4588 | __ Or(dst.AsRegister<Register>(), AT, TMP); |
| 4589 | } |
| 4590 | break; |
| 4591 | case Primitive::kPrimLong: { |
| 4592 | if (Primitive::IsFloatingPointType(cond_type)) { |
| 4593 | __ Mfc1(cond_reg, fcond_reg); |
| 4594 | } |
| 4595 | Register dst_lo = dst.AsRegisterPairLow<Register>(); |
| 4596 | Register dst_hi = dst.AsRegisterPairHigh<Register>(); |
| 4597 | if (true_src.IsConstant()) { |
| 4598 | Register src_lo = false_src.AsRegisterPairLow<Register>(); |
| 4599 | Register src_hi = false_src.AsRegisterPairHigh<Register>(); |
| 4600 | if (cond_inverted) { |
| 4601 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 4602 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 4603 | } else { |
| 4604 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 4605 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 4606 | } |
| 4607 | } else { |
| 4608 | DCHECK(false_src.IsConstant()); |
| 4609 | Register src_lo = true_src.AsRegisterPairLow<Register>(); |
| 4610 | Register src_hi = true_src.AsRegisterPairHigh<Register>(); |
| 4611 | if (cond_inverted) { |
| 4612 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 4613 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 4614 | } else { |
| 4615 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 4616 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 4617 | } |
| 4618 | } |
| 4619 | break; |
| 4620 | } |
| 4621 | case Primitive::kPrimFloat: { |
| 4622 | if (!Primitive::IsFloatingPointType(cond_type)) { |
| 4623 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 4624 | __ Sltu(TMP, ZERO, cond_reg); |
| 4625 | __ Mtc1(TMP, fcond_reg); |
| 4626 | } |
| 4627 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 4628 | if (true_src.IsConstant()) { |
| 4629 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 4630 | if (cond_inverted) { |
| 4631 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 4632 | } else { |
| 4633 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 4634 | } |
| 4635 | } else if (false_src.IsConstant()) { |
| 4636 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 4637 | if (cond_inverted) { |
| 4638 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 4639 | } else { |
| 4640 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 4641 | } |
| 4642 | } else { |
| 4643 | if (cond_inverted) { |
| 4644 | __ SelS(fcond_reg, |
| 4645 | true_src.AsFpuRegister<FRegister>(), |
| 4646 | false_src.AsFpuRegister<FRegister>()); |
| 4647 | } else { |
| 4648 | __ SelS(fcond_reg, |
| 4649 | false_src.AsFpuRegister<FRegister>(), |
| 4650 | true_src.AsFpuRegister<FRegister>()); |
| 4651 | } |
| 4652 | __ MovS(dst_reg, fcond_reg); |
| 4653 | } |
| 4654 | break; |
| 4655 | } |
| 4656 | case Primitive::kPrimDouble: { |
| 4657 | if (!Primitive::IsFloatingPointType(cond_type)) { |
| 4658 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 4659 | __ Sltu(TMP, ZERO, cond_reg); |
| 4660 | __ Mtc1(TMP, fcond_reg); |
| 4661 | } |
| 4662 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 4663 | if (true_src.IsConstant()) { |
| 4664 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 4665 | if (cond_inverted) { |
| 4666 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 4667 | } else { |
| 4668 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 4669 | } |
| 4670 | } else if (false_src.IsConstant()) { |
| 4671 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 4672 | if (cond_inverted) { |
| 4673 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 4674 | } else { |
| 4675 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 4676 | } |
| 4677 | } else { |
| 4678 | if (cond_inverted) { |
| 4679 | __ SelD(fcond_reg, |
| 4680 | true_src.AsFpuRegister<FRegister>(), |
| 4681 | false_src.AsFpuRegister<FRegister>()); |
| 4682 | } else { |
| 4683 | __ SelD(fcond_reg, |
| 4684 | false_src.AsFpuRegister<FRegister>(), |
| 4685 | true_src.AsFpuRegister<FRegister>()); |
| 4686 | } |
| 4687 | __ MovD(dst_reg, fcond_reg); |
| 4688 | } |
| 4689 | break; |
| 4690 | } |
| 4691 | } |
| 4692 | } |
| 4693 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 4694 | void LocationsBuilderMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 4695 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 4696 | LocationSummary(flag, LocationSummary::kNoCall); |
| 4697 | locations->SetOut(Location::RequiresRegister()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 4698 | } |
| 4699 | |
Goran Jakovljevic | c641842 | 2016-12-05 16:31:55 +0100 | [diff] [blame] | 4700 | void InstructionCodeGeneratorMIPS::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 4701 | __ LoadFromOffset(kLoadWord, |
| 4702 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 4703 | SP, |
| 4704 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 4705 | } |
| 4706 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4707 | void LocationsBuilderMIPS::VisitSelect(HSelect* select) { |
| 4708 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4709 | CanMoveConditionally(select, codegen_->GetInstructionSetFeatures().IsR6(), locations); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4710 | } |
| 4711 | |
| 4712 | void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4713 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4714 | if (CanMoveConditionally(select, is_r6, /* locations_to_set */ nullptr)) { |
| 4715 | if (is_r6) { |
| 4716 | GenConditionalMoveR6(select); |
| 4717 | } else { |
| 4718 | GenConditionalMoveR2(select); |
| 4719 | } |
| 4720 | } else { |
| 4721 | LocationSummary* locations = select->GetLocations(); |
| 4722 | MipsLabel false_target; |
| 4723 | GenerateTestAndBranch(select, |
| 4724 | /* condition_input_index */ 2, |
| 4725 | /* true_target */ nullptr, |
| 4726 | &false_target); |
| 4727 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 4728 | __ Bind(&false_target); |
| 4729 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4730 | } |
| 4731 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4732 | void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 4733 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 4734 | } |
| 4735 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 4736 | void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 4737 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 4738 | } |
| 4739 | |
| 4740 | void CodeGeneratorMIPS::GenerateNop() { |
| 4741 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4742 | } |
| 4743 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4744 | void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4745 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4746 | bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble); |
| 4747 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
| 4748 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4749 | instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4750 | |
| 4751 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4752 | if (generate_volatile) { |
| 4753 | InvokeRuntimeCallingConvention calling_convention; |
| 4754 | // need A0 to hold base + offset |
| 4755 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4756 | if (field_type == Primitive::kPrimLong) { |
| 4757 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimLong)); |
| 4758 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4759 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 4760 | locations->SetOut(Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4761 | // Need some temp core regs since FP results are returned in core registers |
| 4762 | Location reg = calling_convention.GetReturnLocation(Primitive::kPrimLong); |
| 4763 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>())); |
| 4764 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>())); |
| 4765 | } |
| 4766 | } else { |
| 4767 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4768 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4769 | } else { |
| 4770 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4771 | } |
| 4772 | } |
| 4773 | } |
| 4774 | |
| 4775 | void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction, |
| 4776 | const FieldInfo& field_info, |
| 4777 | uint32_t dex_pc) { |
| 4778 | Primitive::Type type = field_info.GetFieldType(); |
| 4779 | LocationSummary* locations = instruction->GetLocations(); |
| 4780 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4781 | LoadOperandType load_type = kLoadUnsignedByte; |
| 4782 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 4783 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4784 | auto null_checker = GetImplicitNullChecker(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4785 | |
| 4786 | switch (type) { |
| 4787 | case Primitive::kPrimBoolean: |
| 4788 | load_type = kLoadUnsignedByte; |
| 4789 | break; |
| 4790 | case Primitive::kPrimByte: |
| 4791 | load_type = kLoadSignedByte; |
| 4792 | break; |
| 4793 | case Primitive::kPrimShort: |
| 4794 | load_type = kLoadSignedHalfword; |
| 4795 | break; |
| 4796 | case Primitive::kPrimChar: |
| 4797 | load_type = kLoadUnsignedHalfword; |
| 4798 | break; |
| 4799 | case Primitive::kPrimInt: |
| 4800 | case Primitive::kPrimFloat: |
| 4801 | case Primitive::kPrimNot: |
| 4802 | load_type = kLoadWord; |
| 4803 | break; |
| 4804 | case Primitive::kPrimLong: |
| 4805 | case Primitive::kPrimDouble: |
| 4806 | load_type = kLoadDoubleword; |
| 4807 | break; |
| 4808 | case Primitive::kPrimVoid: |
| 4809 | LOG(FATAL) << "Unreachable type " << type; |
| 4810 | UNREACHABLE(); |
| 4811 | } |
| 4812 | |
| 4813 | if (is_volatile && load_type == kLoadDoubleword) { |
| 4814 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 4815 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4816 | // Do implicit Null check |
| 4817 | __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0); |
| 4818 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 4819 | codegen_->InvokeRuntime(kQuickA64Load, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4820 | CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>(); |
| 4821 | if (type == Primitive::kPrimDouble) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4822 | // FP results are returned in core registers. Need to move them. |
| 4823 | Location out = locations->Out(); |
| 4824 | if (out.IsFpuRegister()) { |
| 4825 | __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), out.AsFpuRegister<FRegister>()); |
| 4826 | __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
| 4827 | out.AsFpuRegister<FRegister>()); |
| 4828 | } else { |
| 4829 | DCHECK(out.IsDoubleStackSlot()); |
| 4830 | __ StoreToOffset(kStoreWord, |
| 4831 | locations->GetTemp(1).AsRegister<Register>(), |
| 4832 | SP, |
| 4833 | out.GetStackIndex()); |
| 4834 | __ StoreToOffset(kStoreWord, |
| 4835 | locations->GetTemp(2).AsRegister<Register>(), |
| 4836 | SP, |
| 4837 | out.GetStackIndex() + 4); |
| 4838 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4839 | } |
| 4840 | } else { |
| 4841 | if (!Primitive::IsFloatingPointType(type)) { |
| 4842 | Register dst; |
| 4843 | if (type == Primitive::kPrimLong) { |
| 4844 | DCHECK(locations->Out().IsRegisterPair()); |
| 4845 | dst = locations->Out().AsRegisterPairLow<Register>(); |
| 4846 | } else { |
| 4847 | DCHECK(locations->Out().IsRegister()); |
| 4848 | dst = locations->Out().AsRegister<Register>(); |
| 4849 | } |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4850 | __ LoadFromOffset(load_type, dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4851 | } else { |
| 4852 | DCHECK(locations->Out().IsFpuRegister()); |
| 4853 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 4854 | if (type == Primitive::kPrimFloat) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4855 | __ LoadSFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4856 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4857 | __ LoadDFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4858 | } |
| 4859 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4860 | } |
| 4861 | |
| 4862 | if (is_volatile) { |
| 4863 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4864 | } |
| 4865 | } |
| 4866 | |
| 4867 | void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4868 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4869 | bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble); |
| 4870 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
| 4871 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4872 | instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4873 | |
| 4874 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4875 | if (generate_volatile) { |
| 4876 | InvokeRuntimeCallingConvention calling_convention; |
| 4877 | // need A0 to hold base + offset |
| 4878 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4879 | if (field_type == Primitive::kPrimLong) { |
| 4880 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4881 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4882 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4883 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 4884 | locations->SetInAt(1, Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4885 | // Pass FP parameters in core registers. |
| 4886 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 4887 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3))); |
| 4888 | } |
| 4889 | } else { |
| 4890 | if (Primitive::IsFloatingPointType(field_type)) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4891 | locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4892 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4893 | locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4894 | } |
| 4895 | } |
| 4896 | } |
| 4897 | |
| 4898 | void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction, |
| 4899 | const FieldInfo& field_info, |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 4900 | uint32_t dex_pc, |
| 4901 | bool value_can_be_null) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4902 | Primitive::Type type = field_info.GetFieldType(); |
| 4903 | LocationSummary* locations = instruction->GetLocations(); |
| 4904 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4905 | Location value_location = locations->InAt(1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4906 | StoreOperandType store_type = kStoreByte; |
| 4907 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 4908 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4909 | auto null_checker = GetImplicitNullChecker(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4910 | |
| 4911 | switch (type) { |
| 4912 | case Primitive::kPrimBoolean: |
| 4913 | case Primitive::kPrimByte: |
| 4914 | store_type = kStoreByte; |
| 4915 | break; |
| 4916 | case Primitive::kPrimShort: |
| 4917 | case Primitive::kPrimChar: |
| 4918 | store_type = kStoreHalfword; |
| 4919 | break; |
| 4920 | case Primitive::kPrimInt: |
| 4921 | case Primitive::kPrimFloat: |
| 4922 | case Primitive::kPrimNot: |
| 4923 | store_type = kStoreWord; |
| 4924 | break; |
| 4925 | case Primitive::kPrimLong: |
| 4926 | case Primitive::kPrimDouble: |
| 4927 | store_type = kStoreDoubleword; |
| 4928 | break; |
| 4929 | case Primitive::kPrimVoid: |
| 4930 | LOG(FATAL) << "Unreachable type " << type; |
| 4931 | UNREACHABLE(); |
| 4932 | } |
| 4933 | |
| 4934 | if (is_volatile) { |
| 4935 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 4936 | } |
| 4937 | |
| 4938 | if (is_volatile && store_type == kStoreDoubleword) { |
| 4939 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 4940 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4941 | // Do implicit Null check. |
| 4942 | __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0); |
| 4943 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4944 | if (type == Primitive::kPrimDouble) { |
| 4945 | // Pass FP parameters in core registers. |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4946 | if (value_location.IsFpuRegister()) { |
| 4947 | __ Mfc1(locations->GetTemp(1).AsRegister<Register>(), |
| 4948 | value_location.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4949 | __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4950 | value_location.AsFpuRegister<FRegister>()); |
| 4951 | } else if (value_location.IsDoubleStackSlot()) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4952 | __ LoadFromOffset(kLoadWord, |
| 4953 | locations->GetTemp(1).AsRegister<Register>(), |
| 4954 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4955 | value_location.GetStackIndex()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4956 | __ LoadFromOffset(kLoadWord, |
| 4957 | locations->GetTemp(2).AsRegister<Register>(), |
| 4958 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4959 | value_location.GetStackIndex() + 4); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4960 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4961 | DCHECK(value_location.IsConstant()); |
| 4962 | DCHECK(value_location.GetConstant()->IsDoubleConstant()); |
| 4963 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4964 | __ LoadConst64(locations->GetTemp(2).AsRegister<Register>(), |
| 4965 | locations->GetTemp(1).AsRegister<Register>(), |
| 4966 | value); |
| 4967 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4968 | } |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 4969 | codegen_->InvokeRuntime(kQuickA64Store, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4970 | CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>(); |
| 4971 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4972 | if (value_location.IsConstant()) { |
| 4973 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 4974 | __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker); |
| 4975 | } else if (!Primitive::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4976 | Register src; |
| 4977 | if (type == Primitive::kPrimLong) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4978 | src = value_location.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4979 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4980 | src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4981 | } |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4982 | __ StoreToOffset(store_type, src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4983 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4984 | FRegister src = value_location.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4985 | if (type == Primitive::kPrimFloat) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4986 | __ StoreSToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4987 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4988 | __ StoreDToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4989 | } |
| 4990 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4991 | } |
| 4992 | |
| 4993 | // TODO: memory barriers? |
| 4994 | if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4995 | Register src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 4996 | codegen_->MarkGCCard(obj, src, value_can_be_null); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4997 | } |
| 4998 | |
| 4999 | if (is_volatile) { |
| 5000 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 5001 | } |
| 5002 | } |
| 5003 | |
| 5004 | void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5005 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5006 | } |
| 5007 | |
| 5008 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5009 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 5010 | } |
| 5011 | |
| 5012 | void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5013 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5014 | } |
| 5015 | |
| 5016 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 5017 | HandleFieldSet(instruction, |
| 5018 | instruction->GetFieldInfo(), |
| 5019 | instruction->GetDexPc(), |
| 5020 | instruction->GetValueCanBeNull()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5021 | } |
| 5022 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5023 | void InstructionCodeGeneratorMIPS::GenerateGcRootFieldLoad( |
| 5024 | HInstruction* instruction ATTRIBUTE_UNUSED, |
| 5025 | Location root, |
| 5026 | Register obj, |
| 5027 | uint32_t offset) { |
| 5028 | Register root_reg = root.AsRegister<Register>(); |
| 5029 | if (kEmitCompilerReadBarrier) { |
| 5030 | UNIMPLEMENTED(FATAL) << "for read barrier"; |
| 5031 | } else { |
| 5032 | // Plain GC root load with no read barrier. |
| 5033 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5034 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 5035 | // Note that GC roots are not affected by heap poisoning, thus we |
| 5036 | // do not have to unpoison `root_reg` here. |
| 5037 | } |
| 5038 | } |
| 5039 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5040 | void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
| 5041 | LocationSummary::CallKind call_kind = |
| 5042 | instruction->IsExactCheck() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath; |
| 5043 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5044 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5045 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5046 | // The output does overlap inputs. |
| 5047 | // Note that TypeCheckSlowPathMIPS uses this register too. |
| 5048 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5049 | } |
| 5050 | |
| 5051 | void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
| 5052 | LocationSummary* locations = instruction->GetLocations(); |
| 5053 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5054 | Register cls = locations->InAt(1).AsRegister<Register>(); |
| 5055 | Register out = locations->Out().AsRegister<Register>(); |
| 5056 | |
| 5057 | MipsLabel done; |
| 5058 | |
| 5059 | // Return 0 if `obj` is null. |
| 5060 | // TODO: Avoid this check if we know `obj` is not null. |
| 5061 | __ Move(out, ZERO); |
| 5062 | __ Beqz(obj, &done); |
| 5063 | |
| 5064 | // Compare the class of `obj` with `cls`. |
| 5065 | __ LoadFromOffset(kLoadWord, out, obj, mirror::Object::ClassOffset().Int32Value()); |
| 5066 | if (instruction->IsExactCheck()) { |
| 5067 | // Classes must be equal for the instanceof to succeed. |
| 5068 | __ Xor(out, out, cls); |
| 5069 | __ Sltiu(out, out, 1); |
| 5070 | } else { |
| 5071 | // If the classes are not equal, we go into a slow path. |
| 5072 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5073 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction); |
| 5074 | codegen_->AddSlowPath(slow_path); |
| 5075 | __ Bne(out, cls, slow_path->GetEntryLabel()); |
| 5076 | __ LoadConst32(out, 1); |
| 5077 | __ Bind(slow_path->GetExitLabel()); |
| 5078 | } |
| 5079 | |
| 5080 | __ Bind(&done); |
| 5081 | } |
| 5082 | |
| 5083 | void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) { |
| 5084 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5085 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5086 | } |
| 5087 | |
| 5088 | void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 5089 | // Will be generated at use site. |
| 5090 | } |
| 5091 | |
| 5092 | void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) { |
| 5093 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5094 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5095 | } |
| 5096 | |
| 5097 | void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 5098 | // Will be generated at use site. |
| 5099 | } |
| 5100 | |
| 5101 | void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) { |
| 5102 | InvokeDexCallingConventionVisitorMIPS calling_convention_visitor; |
| 5103 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 5104 | } |
| 5105 | |
| 5106 | void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 5107 | HandleInvoke(invoke); |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 5108 | // 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] | 5109 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 5110 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T7)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5111 | } |
| 5112 | |
| 5113 | void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 5114 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 5115 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5116 | Location receiver = invoke->GetLocations()->InAt(0); |
| 5117 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5118 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5119 | |
| 5120 | // Set the hidden argument. |
| 5121 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(), |
| 5122 | invoke->GetDexMethodIndex()); |
| 5123 | |
| 5124 | // temp = object->GetClass(); |
| 5125 | if (receiver.IsStackSlot()) { |
| 5126 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 5127 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 5128 | } else { |
| 5129 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
| 5130 | } |
| 5131 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 5132 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 5133 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
| 5134 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 5135 | invoke->GetImtIndex(), kMipsPointerSize)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5136 | // temp = temp->GetImtEntryAt(method_offset); |
| 5137 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 5138 | // T9 = temp->GetEntryPoint(); |
| 5139 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 5140 | // T9(); |
| 5141 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 5142 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5143 | DCHECK(!codegen_->IsLeafMethod()); |
| 5144 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 5145 | } |
| 5146 | |
| 5147 | void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 5148 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 5149 | if (intrinsic.TryDispatch(invoke)) { |
| 5150 | return; |
| 5151 | } |
| 5152 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5153 | HandleInvoke(invoke); |
| 5154 | } |
| 5155 | |
| 5156 | void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5157 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5158 | // art::PrepareForRegisterAllocation. |
| 5159 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5160 | |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 5161 | bool has_extra_input = invoke->HasPcRelativeDexCache(); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5162 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 5163 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 5164 | if (intrinsic.TryDispatch(invoke)) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5165 | if (invoke->GetLocations()->CanCall() && has_extra_input) { |
| 5166 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 5167 | } |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 5168 | return; |
| 5169 | } |
| 5170 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5171 | HandleInvoke(invoke); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5172 | |
| 5173 | // Add the extra input register if either the dex cache array base register |
| 5174 | // or the PC-relative base register for accessing literals is needed. |
| 5175 | if (has_extra_input) { |
| 5176 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 5177 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5178 | } |
| 5179 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 5180 | void LocationsBuilderMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 5181 | HandleInvoke(invoke); |
| 5182 | } |
| 5183 | |
| 5184 | void InstructionCodeGeneratorMIPS::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 5185 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 5186 | } |
| 5187 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 5188 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5189 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 5190 | IntrinsicCodeGeneratorMIPS intrinsic(codegen); |
| 5191 | intrinsic.Dispatch(invoke); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5192 | return true; |
| 5193 | } |
| 5194 | return false; |
| 5195 | } |
| 5196 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5197 | HLoadString::LoadKind CodeGeneratorMIPS::GetSupportedLoadStringKind( |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5198 | HLoadString::LoadKind desired_string_load_kind) { |
| 5199 | if (kEmitCompilerReadBarrier) { |
| 5200 | UNIMPLEMENTED(FATAL) << "for read barrier"; |
| 5201 | } |
| 5202 | // We disable PC-relative load when there is an irreducible loop, as the optimization |
| 5203 | // is incompatible with it. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5204 | // TODO: Create as many MipsDexCacheArraysBase instructions as needed for methods |
| 5205 | // with irreducible loops. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5206 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
| 5207 | bool fallback_load = has_irreducible_loops; |
| 5208 | switch (desired_string_load_kind) { |
| 5209 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5210 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5211 | break; |
| 5212 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5213 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5214 | break; |
| 5215 | case HLoadString::LoadKind::kBootImageAddress: |
| 5216 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5217 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5218 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5219 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5220 | case HLoadString::LoadKind::kJitTableAddress: |
| 5221 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5222 | // TODO: implement. |
| 5223 | fallback_load = true; |
| 5224 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5225 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5226 | fallback_load = false; |
| 5227 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5228 | } |
| 5229 | if (fallback_load) { |
| 5230 | desired_string_load_kind = HLoadString::LoadKind::kDexCacheViaMethod; |
| 5231 | } |
| 5232 | return desired_string_load_kind; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5233 | } |
| 5234 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5235 | HLoadClass::LoadKind CodeGeneratorMIPS::GetSupportedLoadClassKind( |
| 5236 | HLoadClass::LoadKind desired_class_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5237 | if (kEmitCompilerReadBarrier) { |
| 5238 | UNIMPLEMENTED(FATAL) << "for read barrier"; |
| 5239 | } |
| 5240 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5241 | // is incompatible with it. |
| 5242 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
| 5243 | bool fallback_load = has_irreducible_loops; |
| 5244 | switch (desired_class_load_kind) { |
| 5245 | case HLoadClass::LoadKind::kReferrersClass: |
| 5246 | fallback_load = false; |
| 5247 | break; |
| 5248 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5249 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5250 | break; |
| 5251 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5252 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5253 | break; |
| 5254 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5255 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5256 | case HLoadClass::LoadKind::kBssEntry: |
| 5257 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5258 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5259 | case HLoadClass::LoadKind::kJitTableAddress: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5260 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5261 | fallback_load = true; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5262 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5263 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5264 | fallback_load = false; |
| 5265 | break; |
| 5266 | } |
| 5267 | if (fallback_load) { |
| 5268 | desired_class_load_kind = HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5269 | } |
| 5270 | return desired_class_load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5271 | } |
| 5272 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5273 | Register CodeGeneratorMIPS::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 5274 | Register temp) { |
| 5275 | CHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 5276 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 5277 | if (!invoke->GetLocations()->Intrinsified()) { |
| 5278 | return location.AsRegister<Register>(); |
| 5279 | } |
| 5280 | // For intrinsics we allow any location, so it may be on the stack. |
| 5281 | if (!location.IsRegister()) { |
| 5282 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 5283 | return temp; |
| 5284 | } |
| 5285 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 5286 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 5287 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 5288 | // simple and more robust approach rather that trying to determine if that's the case. |
| 5289 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 5290 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 5291 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 5292 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 5293 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 5294 | return temp; |
| 5295 | } |
| 5296 | return location.AsRegister<Register>(); |
| 5297 | } |
| 5298 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5299 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch( |
| 5300 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5301 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5302 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 5303 | // We disable PC-relative load when there is an irreducible loop, as the optimization |
| 5304 | // is incompatible with it. |
| 5305 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
| 5306 | bool fallback_load = true; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5307 | switch (dispatch_info.method_load_kind) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5308 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5309 | fallback_load = has_irreducible_loops; |
| 5310 | break; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5311 | default: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5312 | fallback_load = false; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5313 | break; |
| 5314 | } |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5315 | if (fallback_load) { |
| 5316 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 5317 | dispatch_info.method_load_data = 0; |
| 5318 | } |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5319 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5320 | } |
| 5321 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5322 | void CodeGeneratorMIPS::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 5323 | // 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] | 5324 | 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] | 5325 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 5326 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 5327 | Register base_reg = invoke->HasPcRelativeDexCache() |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5328 | ? GetInvokeStaticOrDirectExtraParameter(invoke, temp.AsRegister<Register>()) |
| 5329 | : ZERO; |
| 5330 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5331 | switch (method_load_kind) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5332 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5333 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5334 | uint32_t offset = |
| 5335 | GetThreadOffset<kMipsPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5336 | __ LoadFromOffset(kLoadWord, |
| 5337 | temp.AsRegister<Register>(), |
| 5338 | TR, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5339 | offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5340 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5341 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5342 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 5343 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5344 | break; |
| 5345 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 5346 | __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 5347 | break; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5348 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 5349 | HMipsDexCacheArraysBase* base = |
| 5350 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsMipsDexCacheArraysBase(); |
| 5351 | int32_t offset = |
| 5352 | invoke->GetDexCacheArrayOffset() - base->GetElementOffset() - kDexCacheArrayLwOffset; |
| 5353 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 5354 | break; |
| 5355 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5356 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 5357 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5358 | Register reg = temp.AsRegister<Register>(); |
| 5359 | Register method_reg; |
| 5360 | if (current_method.IsRegister()) { |
| 5361 | method_reg = current_method.AsRegister<Register>(); |
| 5362 | } else { |
| 5363 | // TODO: use the appropriate DCHECK() here if possible. |
| 5364 | // DCHECK(invoke->GetLocations()->Intrinsified()); |
| 5365 | DCHECK(!current_method.IsValid()); |
| 5366 | method_reg = reg; |
| 5367 | __ Lw(reg, SP, kCurrentMethodStackOffset); |
| 5368 | } |
| 5369 | |
| 5370 | // temp = temp->dex_cache_resolved_methods_; |
| 5371 | __ LoadFromOffset(kLoadWord, |
| 5372 | reg, |
| 5373 | method_reg, |
| 5374 | ArtMethod::DexCacheResolvedMethodsOffset(kMipsPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 5375 | // temp = temp[index_in_cache]; |
| 5376 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 5377 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5378 | __ LoadFromOffset(kLoadWord, |
| 5379 | reg, |
| 5380 | reg, |
| 5381 | CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 5382 | break; |
| 5383 | } |
| 5384 | } |
| 5385 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5386 | switch (code_ptr_location) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5387 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5388 | __ Bal(&frame_entry_label_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5389 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5390 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 5391 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
Goran Jakovljevic | 1a87837 | 2015-10-26 14:28:52 +0100 | [diff] [blame] | 5392 | __ LoadFromOffset(kLoadWord, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5393 | T9, |
| 5394 | callee_method.AsRegister<Register>(), |
| 5395 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5396 | kMipsPointerSize).Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5397 | // T9() |
| 5398 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 5399 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5400 | break; |
| 5401 | } |
| 5402 | DCHECK(!IsLeafMethod()); |
| 5403 | } |
| 5404 | |
| 5405 | void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5406 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5407 | // art::PrepareForRegisterAllocation. |
| 5408 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5409 | |
| 5410 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 5411 | return; |
| 5412 | } |
| 5413 | |
| 5414 | LocationSummary* locations = invoke->GetLocations(); |
| 5415 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 5416 | locations->HasTemps() |
| 5417 | ? locations->GetTemp(0) |
| 5418 | : Location::NoLocation()); |
| 5419 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 5420 | } |
| 5421 | |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 5422 | void CodeGeneratorMIPS::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 5423 | // Use the calling convention instead of the location of the receiver, as |
| 5424 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 5425 | // slow path, the arguments have been moved to the right place, so here we are |
| 5426 | // guaranteed that the receiver is the first register of the calling convention. |
| 5427 | InvokeDexCallingConvention calling_convention; |
| 5428 | Register receiver = calling_convention.GetRegisterAt(0); |
| 5429 | |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 5430 | Register temp = temp_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5431 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 5432 | invoke->GetVTableIndex(), kMipsPointerSize).SizeValue(); |
| 5433 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5434 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5435 | |
| 5436 | // temp = object->GetClass(); |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 5437 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 5438 | MaybeRecordImplicitNullCheck(invoke); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5439 | // temp = temp->GetMethodAt(method_offset); |
| 5440 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 5441 | // T9 = temp->GetEntryPoint(); |
| 5442 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 5443 | // T9(); |
| 5444 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 5445 | __ NopIfNoReordering(); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 5446 | } |
| 5447 | |
| 5448 | void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 5449 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 5450 | return; |
| 5451 | } |
| 5452 | |
| 5453 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5454 | DCHECK(!codegen_->IsLeafMethod()); |
| 5455 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 5456 | } |
| 5457 | |
| 5458 | void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5459 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5460 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5461 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5462 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5463 | cls, |
| 5464 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5465 | Location::RegisterLocation(V0)); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5466 | return; |
| 5467 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5468 | DCHECK(!cls->NeedsAccessCheck()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5469 | |
| 5470 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier) |
| 5471 | ? LocationSummary::kCallOnSlowPath |
| 5472 | : LocationSummary::kNoCall; |
| 5473 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5474 | switch (load_kind) { |
| 5475 | // We need an extra register for PC-relative literals on R2. |
| 5476 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5477 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5478 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5479 | case HLoadClass::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5480 | if (codegen_->GetInstructionSetFeatures().IsR6()) { |
| 5481 | break; |
| 5482 | } |
| 5483 | FALLTHROUGH_INTENDED; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5484 | case HLoadClass::LoadKind::kReferrersClass: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5485 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5486 | break; |
| 5487 | default: |
| 5488 | break; |
| 5489 | } |
| 5490 | locations->SetOut(Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5491 | } |
| 5492 | |
| 5493 | void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5494 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5495 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 5496 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 5497 | return; |
| 5498 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5499 | DCHECK(!cls->NeedsAccessCheck()); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 5500 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5501 | LocationSummary* locations = cls->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5502 | Location out_loc = locations->Out(); |
| 5503 | Register out = out_loc.AsRegister<Register>(); |
| 5504 | Register base_or_current_method_reg; |
| 5505 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 5506 | switch (load_kind) { |
| 5507 | // We need an extra register for PC-relative literals on R2. |
| 5508 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5509 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5510 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5511 | case HLoadClass::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5512 | base_or_current_method_reg = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>(); |
| 5513 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5514 | case HLoadClass::LoadKind::kReferrersClass: |
| 5515 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5516 | base_or_current_method_reg = locations->InAt(0).AsRegister<Register>(); |
| 5517 | break; |
| 5518 | default: |
| 5519 | base_or_current_method_reg = ZERO; |
| 5520 | break; |
| 5521 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5522 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5523 | bool generate_null_check = false; |
| 5524 | switch (load_kind) { |
| 5525 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5526 | DCHECK(!cls->CanCallRuntime()); |
| 5527 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5528 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5529 | GenerateGcRootFieldLoad(cls, |
| 5530 | out_loc, |
| 5531 | base_or_current_method_reg, |
| 5532 | ArtMethod::DeclaringClassOffset().Int32Value()); |
| 5533 | break; |
| 5534 | } |
| 5535 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5536 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5537 | __ LoadLiteral(out, |
| 5538 | base_or_current_method_reg, |
| 5539 | codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 5540 | cls->GetTypeIndex())); |
| 5541 | break; |
| 5542 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5543 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5544 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
| 5545 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5546 | codegen_->EmitPcRelativeAddressPlaceholder(info, out, base_or_current_method_reg); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5547 | break; |
| 5548 | } |
| 5549 | case HLoadClass::LoadKind::kBootImageAddress: { |
| 5550 | DCHECK(!kEmitCompilerReadBarrier); |
| 5551 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5552 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5553 | __ LoadLiteral(out, |
| 5554 | base_or_current_method_reg, |
| 5555 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5556 | break; |
| 5557 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5558 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5559 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame^] | 5560 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5561 | codegen_->EmitPcRelativeAddressPlaceholder(info, out, base_or_current_method_reg); |
| 5562 | __ LoadFromOffset(kLoadWord, out, out, 0); |
| 5563 | generate_null_check = true; |
| 5564 | break; |
| 5565 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5566 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5567 | LOG(FATAL) << "Unimplemented"; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5568 | break; |
| 5569 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5570 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5571 | LOG(FATAL) << "UNREACHABLE"; |
| 5572 | UNREACHABLE(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5573 | } |
| 5574 | |
| 5575 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5576 | DCHECK(cls->CanCallRuntime()); |
| 5577 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS( |
| 5578 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5579 | codegen_->AddSlowPath(slow_path); |
| 5580 | if (generate_null_check) { |
| 5581 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 5582 | } |
| 5583 | if (cls->MustGenerateClinitCheck()) { |
| 5584 | GenerateClassInitializationCheck(slow_path, out); |
| 5585 | } else { |
| 5586 | __ Bind(slow_path->GetExitLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5587 | } |
| 5588 | } |
| 5589 | } |
| 5590 | |
| 5591 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5592 | return Thread::ExceptionOffset<kMipsPointerSize>().Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5593 | } |
| 5594 | |
| 5595 | void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) { |
| 5596 | LocationSummary* locations = |
| 5597 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5598 | locations->SetOut(Location::RequiresRegister()); |
| 5599 | } |
| 5600 | |
| 5601 | void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) { |
| 5602 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
| 5603 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 5604 | } |
| 5605 | |
| 5606 | void LocationsBuilderMIPS::VisitClearException(HClearException* clear) { |
| 5607 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5608 | } |
| 5609 | |
| 5610 | void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5611 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
| 5612 | } |
| 5613 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5614 | void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) { |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 5615 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5616 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5617 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 5618 | switch (load_kind) { |
| 5619 | // We need an extra register for PC-relative literals on R2. |
| 5620 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5621 | case HLoadString::LoadKind::kBootImageAddress: |
| 5622 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5623 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5624 | if (codegen_->GetInstructionSetFeatures().IsR6()) { |
| 5625 | break; |
| 5626 | } |
| 5627 | FALLTHROUGH_INTENDED; |
| 5628 | // We need an extra register for PC-relative dex cache accesses. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5629 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5630 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5631 | break; |
| 5632 | default: |
| 5633 | break; |
| 5634 | } |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 5635 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 5636 | InvokeRuntimeCallingConvention calling_convention; |
| 5637 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5638 | } else { |
| 5639 | locations->SetOut(Location::RequiresRegister()); |
| 5640 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5641 | } |
| 5642 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5643 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5644 | // move. |
| 5645 | void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5646 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5647 | LocationSummary* locations = load->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5648 | Location out_loc = locations->Out(); |
| 5649 | Register out = out_loc.AsRegister<Register>(); |
| 5650 | Register base_or_current_method_reg; |
| 5651 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 5652 | switch (load_kind) { |
| 5653 | // We need an extra register for PC-relative literals on R2. |
| 5654 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5655 | case HLoadString::LoadKind::kBootImageAddress: |
| 5656 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5657 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5658 | base_or_current_method_reg = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>(); |
| 5659 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5660 | default: |
| 5661 | base_or_current_method_reg = ZERO; |
| 5662 | break; |
| 5663 | } |
| 5664 | |
| 5665 | switch (load_kind) { |
| 5666 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5667 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5668 | __ LoadLiteral(out, |
| 5669 | base_or_current_method_reg, |
| 5670 | codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 5671 | load->GetStringIndex())); |
| 5672 | return; // No dex cache slow path. |
| 5673 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5674 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5675 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5676 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5677 | codegen_->EmitPcRelativeAddressPlaceholder(info, out, base_or_current_method_reg); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5678 | return; // No dex cache slow path. |
| 5679 | } |
| 5680 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5681 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5682 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5683 | DCHECK_NE(address, 0u); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5684 | __ LoadLiteral(out, |
| 5685 | base_or_current_method_reg, |
| 5686 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5687 | return; // No dex cache slow path. |
| 5688 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5689 | case HLoadString::LoadKind::kBssEntry: { |
| 5690 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 5691 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5692 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5693 | codegen_->EmitPcRelativeAddressPlaceholder(info, out, base_or_current_method_reg); |
| 5694 | __ LoadFromOffset(kLoadWord, out, out, 0); |
| 5695 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS(load); |
| 5696 | codegen_->AddSlowPath(slow_path); |
| 5697 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 5698 | __ Bind(slow_path->GetExitLabel()); |
| 5699 | return; |
| 5700 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5701 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5702 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5703 | } |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5704 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5705 | // 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] | 5706 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 5707 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5708 | __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5709 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5710 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5711 | } |
| 5712 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5713 | void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) { |
| 5714 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5715 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5716 | } |
| 5717 | |
| 5718 | void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 5719 | // Will be generated at use site. |
| 5720 | } |
| 5721 | |
| 5722 | void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5723 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5724 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5725 | InvokeRuntimeCallingConvention calling_convention; |
| 5726 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5727 | } |
| 5728 | |
| 5729 | void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5730 | if (instruction->IsEnter()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 5731 | codegen_->InvokeRuntime(kQuickLockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5732 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5733 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 5734 | codegen_->InvokeRuntime(kQuickUnlockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5735 | } |
| 5736 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5737 | } |
| 5738 | |
| 5739 | void LocationsBuilderMIPS::VisitMul(HMul* mul) { |
| 5740 | LocationSummary* locations = |
| 5741 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 5742 | switch (mul->GetResultType()) { |
| 5743 | case Primitive::kPrimInt: |
| 5744 | case Primitive::kPrimLong: |
| 5745 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5746 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5747 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5748 | break; |
| 5749 | |
| 5750 | case Primitive::kPrimFloat: |
| 5751 | case Primitive::kPrimDouble: |
| 5752 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5753 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5754 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5755 | break; |
| 5756 | |
| 5757 | default: |
| 5758 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5759 | } |
| 5760 | } |
| 5761 | |
| 5762 | void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) { |
| 5763 | Primitive::Type type = instruction->GetType(); |
| 5764 | LocationSummary* locations = instruction->GetLocations(); |
| 5765 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 5766 | |
| 5767 | switch (type) { |
| 5768 | case Primitive::kPrimInt: { |
| 5769 | Register dst = locations->Out().AsRegister<Register>(); |
| 5770 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 5771 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 5772 | |
| 5773 | if (isR6) { |
| 5774 | __ MulR6(dst, lhs, rhs); |
| 5775 | } else { |
| 5776 | __ MulR2(dst, lhs, rhs); |
| 5777 | } |
| 5778 | break; |
| 5779 | } |
| 5780 | case Primitive::kPrimLong: { |
| 5781 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 5782 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 5783 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 5784 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 5785 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 5786 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 5787 | |
| 5788 | // Extra checks to protect caused by the existance of A1_A2. |
| 5789 | // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo: |
| 5790 | // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2). |
| 5791 | DCHECK_NE(dst_high, lhs_low); |
| 5792 | DCHECK_NE(dst_high, rhs_low); |
| 5793 | |
| 5794 | // A_B * C_D |
| 5795 | // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ] |
| 5796 | // dst_lo: [ low(B*D) ] |
| 5797 | // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result. |
| 5798 | |
| 5799 | if (isR6) { |
| 5800 | __ MulR6(TMP, lhs_high, rhs_low); |
| 5801 | __ MulR6(dst_high, lhs_low, rhs_high); |
| 5802 | __ Addu(dst_high, dst_high, TMP); |
| 5803 | __ MuhuR6(TMP, lhs_low, rhs_low); |
| 5804 | __ Addu(dst_high, dst_high, TMP); |
| 5805 | __ MulR6(dst_low, lhs_low, rhs_low); |
| 5806 | } else { |
| 5807 | __ MulR2(TMP, lhs_high, rhs_low); |
| 5808 | __ MulR2(dst_high, lhs_low, rhs_high); |
| 5809 | __ Addu(dst_high, dst_high, TMP); |
| 5810 | __ MultuR2(lhs_low, rhs_low); |
| 5811 | __ Mfhi(TMP); |
| 5812 | __ Addu(dst_high, dst_high, TMP); |
| 5813 | __ Mflo(dst_low); |
| 5814 | } |
| 5815 | break; |
| 5816 | } |
| 5817 | case Primitive::kPrimFloat: |
| 5818 | case Primitive::kPrimDouble: { |
| 5819 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 5820 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5821 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5822 | if (type == Primitive::kPrimFloat) { |
| 5823 | __ MulS(dst, lhs, rhs); |
| 5824 | } else { |
| 5825 | __ MulD(dst, lhs, rhs); |
| 5826 | } |
| 5827 | break; |
| 5828 | } |
| 5829 | default: |
| 5830 | LOG(FATAL) << "Unexpected mul type " << type; |
| 5831 | } |
| 5832 | } |
| 5833 | |
| 5834 | void LocationsBuilderMIPS::VisitNeg(HNeg* neg) { |
| 5835 | LocationSummary* locations = |
| 5836 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 5837 | switch (neg->GetResultType()) { |
| 5838 | case Primitive::kPrimInt: |
| 5839 | case Primitive::kPrimLong: |
| 5840 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5841 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5842 | break; |
| 5843 | |
| 5844 | case Primitive::kPrimFloat: |
| 5845 | case Primitive::kPrimDouble: |
| 5846 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5847 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5848 | break; |
| 5849 | |
| 5850 | default: |
| 5851 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5852 | } |
| 5853 | } |
| 5854 | |
| 5855 | void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) { |
| 5856 | Primitive::Type type = instruction->GetType(); |
| 5857 | LocationSummary* locations = instruction->GetLocations(); |
| 5858 | |
| 5859 | switch (type) { |
| 5860 | case Primitive::kPrimInt: { |
| 5861 | Register dst = locations->Out().AsRegister<Register>(); |
| 5862 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 5863 | __ Subu(dst, ZERO, src); |
| 5864 | break; |
| 5865 | } |
| 5866 | case Primitive::kPrimLong: { |
| 5867 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 5868 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 5869 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 5870 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 5871 | __ Subu(dst_low, ZERO, src_low); |
| 5872 | __ Sltu(TMP, ZERO, dst_low); |
| 5873 | __ Subu(dst_high, ZERO, src_high); |
| 5874 | __ Subu(dst_high, dst_high, TMP); |
| 5875 | break; |
| 5876 | } |
| 5877 | case Primitive::kPrimFloat: |
| 5878 | case Primitive::kPrimDouble: { |
| 5879 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 5880 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5881 | if (type == Primitive::kPrimFloat) { |
| 5882 | __ NegS(dst, src); |
| 5883 | } else { |
| 5884 | __ NegD(dst, src); |
| 5885 | } |
| 5886 | break; |
| 5887 | } |
| 5888 | default: |
| 5889 | LOG(FATAL) << "Unexpected neg type " << type; |
| 5890 | } |
| 5891 | } |
| 5892 | |
| 5893 | void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) { |
| 5894 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5895 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5896 | InvokeRuntimeCallingConvention calling_convention; |
| 5897 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5898 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 5899 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 5900 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5901 | } |
| 5902 | |
| 5903 | void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) { |
| 5904 | InvokeRuntimeCallingConvention calling_convention; |
| 5905 | Register current_method_register = calling_convention.GetRegisterAt(2); |
| 5906 | __ Lw(current_method_register, SP, kCurrentMethodStackOffset); |
| 5907 | // Move an uint16_t value to a register. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5908 | __ LoadConst32(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex().index_); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 5909 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5910 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, |
| 5911 | void*, uint32_t, int32_t, ArtMethod*>(); |
| 5912 | } |
| 5913 | |
| 5914 | void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) { |
| 5915 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5916 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5917 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5918 | if (instruction->IsStringAlloc()) { |
| 5919 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 5920 | } else { |
| 5921 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5922 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5923 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 5924 | } |
| 5925 | |
| 5926 | void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5927 | if (instruction->IsStringAlloc()) { |
| 5928 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5929 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5930 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5931 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 5932 | __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value()); |
| 5933 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 5934 | __ NopIfNoReordering(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5935 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5936 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 5937 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 5938 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5939 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5940 | } |
| 5941 | |
| 5942 | void LocationsBuilderMIPS::VisitNot(HNot* instruction) { |
| 5943 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5944 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5945 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5946 | } |
| 5947 | |
| 5948 | void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) { |
| 5949 | Primitive::Type type = instruction->GetType(); |
| 5950 | LocationSummary* locations = instruction->GetLocations(); |
| 5951 | |
| 5952 | switch (type) { |
| 5953 | case Primitive::kPrimInt: { |
| 5954 | Register dst = locations->Out().AsRegister<Register>(); |
| 5955 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 5956 | __ Nor(dst, src, ZERO); |
| 5957 | break; |
| 5958 | } |
| 5959 | |
| 5960 | case Primitive::kPrimLong: { |
| 5961 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 5962 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 5963 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 5964 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 5965 | __ Nor(dst_high, src_high, ZERO); |
| 5966 | __ Nor(dst_low, src_low, ZERO); |
| 5967 | break; |
| 5968 | } |
| 5969 | |
| 5970 | default: |
| 5971 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5972 | } |
| 5973 | } |
| 5974 | |
| 5975 | void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
| 5976 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5977 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5978 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5979 | } |
| 5980 | |
| 5981 | void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
| 5982 | LocationSummary* locations = instruction->GetLocations(); |
| 5983 | __ Xori(locations->Out().AsRegister<Register>(), |
| 5984 | locations->InAt(0).AsRegister<Register>(), |
| 5985 | 1); |
| 5986 | } |
| 5987 | |
| 5988 | void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5989 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5990 | locations->SetInAt(0, Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5991 | } |
| 5992 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5993 | void CodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5994 | if (CanMoveNullCheckToUser(instruction)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5995 | return; |
| 5996 | } |
| 5997 | Location obj = instruction->GetLocations()->InAt(0); |
| 5998 | |
| 5999 | __ Lw(ZERO, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6000 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6001 | } |
| 6002 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6003 | void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6004 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6005 | AddSlowPath(slow_path); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6006 | |
| 6007 | Location obj = instruction->GetLocations()->InAt(0); |
| 6008 | |
| 6009 | __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 6010 | } |
| 6011 | |
| 6012 | void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6013 | codegen_->GenerateNullCheck(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6014 | } |
| 6015 | |
| 6016 | void LocationsBuilderMIPS::VisitOr(HOr* instruction) { |
| 6017 | HandleBinaryOp(instruction); |
| 6018 | } |
| 6019 | |
| 6020 | void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) { |
| 6021 | HandleBinaryOp(instruction); |
| 6022 | } |
| 6023 | |
| 6024 | void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 6025 | LOG(FATAL) << "Unreachable"; |
| 6026 | } |
| 6027 | |
| 6028 | void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) { |
| 6029 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6030 | } |
| 6031 | |
| 6032 | void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) { |
| 6033 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 6034 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 6035 | if (location.IsStackSlot()) { |
| 6036 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 6037 | } else if (location.IsDoubleStackSlot()) { |
| 6038 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 6039 | } |
| 6040 | locations->SetOut(location); |
| 6041 | } |
| 6042 | |
| 6043 | void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction |
| 6044 | ATTRIBUTE_UNUSED) { |
| 6045 | // Nothing to do, the parameter is already at its location. |
| 6046 | } |
| 6047 | |
| 6048 | void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 6049 | LocationSummary* locations = |
| 6050 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6051 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 6052 | } |
| 6053 | |
| 6054 | void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction |
| 6055 | ATTRIBUTE_UNUSED) { |
| 6056 | // Nothing to do, the method is already at its location. |
| 6057 | } |
| 6058 | |
| 6059 | void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) { |
| 6060 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6061 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6062 | locations->SetInAt(i, Location::Any()); |
| 6063 | } |
| 6064 | locations->SetOut(Location::Any()); |
| 6065 | } |
| 6066 | |
| 6067 | void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 6068 | LOG(FATAL) << "Unreachable"; |
| 6069 | } |
| 6070 | |
| 6071 | void LocationsBuilderMIPS::VisitRem(HRem* rem) { |
| 6072 | Primitive::Type type = rem->GetResultType(); |
| 6073 | LocationSummary::CallKind call_kind = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6074 | (type == Primitive::kPrimInt) ? LocationSummary::kNoCall : LocationSummary::kCallOnMainOnly; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6075 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 6076 | |
| 6077 | switch (type) { |
| 6078 | case Primitive::kPrimInt: |
| 6079 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 6080 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6081 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6082 | break; |
| 6083 | |
| 6084 | case Primitive::kPrimLong: { |
| 6085 | InvokeRuntimeCallingConvention calling_convention; |
| 6086 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 6087 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 6088 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 6089 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 6090 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 6091 | break; |
| 6092 | } |
| 6093 | |
| 6094 | case Primitive::kPrimFloat: |
| 6095 | case Primitive::kPrimDouble: { |
| 6096 | InvokeRuntimeCallingConvention calling_convention; |
| 6097 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 6098 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 6099 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 6100 | break; |
| 6101 | } |
| 6102 | |
| 6103 | default: |
| 6104 | LOG(FATAL) << "Unexpected rem type " << type; |
| 6105 | } |
| 6106 | } |
| 6107 | |
| 6108 | void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) { |
| 6109 | Primitive::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6110 | |
| 6111 | switch (type) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 6112 | case Primitive::kPrimInt: |
| 6113 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6114 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6115 | case Primitive::kPrimLong: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6116 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6117 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 6118 | break; |
| 6119 | } |
| 6120 | case Primitive::kPrimFloat: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6121 | codegen_->InvokeRuntime(kQuickFmodf, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6122 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6123 | break; |
| 6124 | } |
| 6125 | case Primitive::kPrimDouble: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6126 | codegen_->InvokeRuntime(kQuickFmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6127 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6128 | break; |
| 6129 | } |
| 6130 | default: |
| 6131 | LOG(FATAL) << "Unexpected rem type " << type; |
| 6132 | } |
| 6133 | } |
| 6134 | |
| 6135 | void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 6136 | memory_barrier->SetLocations(nullptr); |
| 6137 | } |
| 6138 | |
| 6139 | void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 6140 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 6141 | } |
| 6142 | |
| 6143 | void LocationsBuilderMIPS::VisitReturn(HReturn* ret) { |
| 6144 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret); |
| 6145 | Primitive::Type return_type = ret->InputAt(0)->GetType(); |
| 6146 | locations->SetInAt(0, MipsReturnLocation(return_type)); |
| 6147 | } |
| 6148 | |
| 6149 | void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 6150 | codegen_->GenerateFrameExit(); |
| 6151 | } |
| 6152 | |
| 6153 | void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) { |
| 6154 | ret->SetLocations(nullptr); |
| 6155 | } |
| 6156 | |
| 6157 | void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 6158 | codegen_->GenerateFrameExit(); |
| 6159 | } |
| 6160 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 6161 | void LocationsBuilderMIPS::VisitRor(HRor* ror) { |
| 6162 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6163 | } |
| 6164 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 6165 | void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) { |
| 6166 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6167 | } |
| 6168 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6169 | void LocationsBuilderMIPS::VisitShl(HShl* shl) { |
| 6170 | HandleShift(shl); |
| 6171 | } |
| 6172 | |
| 6173 | void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) { |
| 6174 | HandleShift(shl); |
| 6175 | } |
| 6176 | |
| 6177 | void LocationsBuilderMIPS::VisitShr(HShr* shr) { |
| 6178 | HandleShift(shr); |
| 6179 | } |
| 6180 | |
| 6181 | void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) { |
| 6182 | HandleShift(shr); |
| 6183 | } |
| 6184 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6185 | void LocationsBuilderMIPS::VisitSub(HSub* instruction) { |
| 6186 | HandleBinaryOp(instruction); |
| 6187 | } |
| 6188 | |
| 6189 | void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) { |
| 6190 | HandleBinaryOp(instruction); |
| 6191 | } |
| 6192 | |
| 6193 | void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6194 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6195 | } |
| 6196 | |
| 6197 | void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6198 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 6199 | } |
| 6200 | |
| 6201 | void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6202 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6203 | } |
| 6204 | |
| 6205 | void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 6206 | HandleFieldSet(instruction, |
| 6207 | instruction->GetFieldInfo(), |
| 6208 | instruction->GetDexPc(), |
| 6209 | instruction->GetValueCanBeNull()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6210 | } |
| 6211 | |
| 6212 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet( |
| 6213 | HUnresolvedInstanceFieldGet* instruction) { |
| 6214 | FieldAccessCallingConventionMIPS calling_convention; |
| 6215 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 6216 | instruction->GetFieldType(), |
| 6217 | calling_convention); |
| 6218 | } |
| 6219 | |
| 6220 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet( |
| 6221 | HUnresolvedInstanceFieldGet* instruction) { |
| 6222 | FieldAccessCallingConventionMIPS calling_convention; |
| 6223 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6224 | instruction->GetFieldType(), |
| 6225 | instruction->GetFieldIndex(), |
| 6226 | instruction->GetDexPc(), |
| 6227 | calling_convention); |
| 6228 | } |
| 6229 | |
| 6230 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet( |
| 6231 | HUnresolvedInstanceFieldSet* instruction) { |
| 6232 | FieldAccessCallingConventionMIPS calling_convention; |
| 6233 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 6234 | instruction->GetFieldType(), |
| 6235 | calling_convention); |
| 6236 | } |
| 6237 | |
| 6238 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet( |
| 6239 | HUnresolvedInstanceFieldSet* instruction) { |
| 6240 | FieldAccessCallingConventionMIPS calling_convention; |
| 6241 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6242 | instruction->GetFieldType(), |
| 6243 | instruction->GetFieldIndex(), |
| 6244 | instruction->GetDexPc(), |
| 6245 | calling_convention); |
| 6246 | } |
| 6247 | |
| 6248 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet( |
| 6249 | HUnresolvedStaticFieldGet* instruction) { |
| 6250 | FieldAccessCallingConventionMIPS calling_convention; |
| 6251 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 6252 | instruction->GetFieldType(), |
| 6253 | calling_convention); |
| 6254 | } |
| 6255 | |
| 6256 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet( |
| 6257 | HUnresolvedStaticFieldGet* instruction) { |
| 6258 | FieldAccessCallingConventionMIPS calling_convention; |
| 6259 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6260 | instruction->GetFieldType(), |
| 6261 | instruction->GetFieldIndex(), |
| 6262 | instruction->GetDexPc(), |
| 6263 | calling_convention); |
| 6264 | } |
| 6265 | |
| 6266 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet( |
| 6267 | HUnresolvedStaticFieldSet* instruction) { |
| 6268 | FieldAccessCallingConventionMIPS calling_convention; |
| 6269 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 6270 | instruction->GetFieldType(), |
| 6271 | calling_convention); |
| 6272 | } |
| 6273 | |
| 6274 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet( |
| 6275 | HUnresolvedStaticFieldSet* instruction) { |
| 6276 | FieldAccessCallingConventionMIPS calling_convention; |
| 6277 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6278 | instruction->GetFieldType(), |
| 6279 | instruction->GetFieldIndex(), |
| 6280 | instruction->GetDexPc(), |
| 6281 | calling_convention); |
| 6282 | } |
| 6283 | |
| 6284 | void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6285 | LocationSummary* locations = |
| 6286 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6287 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6288 | } |
| 6289 | |
| 6290 | void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 6291 | HBasicBlock* block = instruction->GetBlock(); |
| 6292 | if (block->GetLoopInformation() != nullptr) { |
| 6293 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6294 | // The back edge will generate the suspend check. |
| 6295 | return; |
| 6296 | } |
| 6297 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6298 | // The goto will generate the suspend check. |
| 6299 | return; |
| 6300 | } |
| 6301 | GenerateSuspendCheck(instruction, nullptr); |
| 6302 | } |
| 6303 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6304 | void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) { |
| 6305 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6306 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6307 | InvokeRuntimeCallingConvention calling_convention; |
| 6308 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6309 | } |
| 6310 | |
| 6311 | void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6312 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6313 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 6314 | } |
| 6315 | |
| 6316 | void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
| 6317 | Primitive::Type input_type = conversion->GetInputType(); |
| 6318 | Primitive::Type result_type = conversion->GetResultType(); |
| 6319 | DCHECK_NE(input_type, result_type); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6320 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6321 | |
| 6322 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 6323 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 6324 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 6325 | } |
| 6326 | |
| 6327 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6328 | if (!isR6 && |
| 6329 | ((Primitive::IsFloatingPointType(result_type) && input_type == Primitive::kPrimLong) || |
| 6330 | (result_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(input_type)))) { |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6331 | call_kind = LocationSummary::kCallOnMainOnly; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6332 | } |
| 6333 | |
| 6334 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 6335 | |
| 6336 | if (call_kind == LocationSummary::kNoCall) { |
| 6337 | if (Primitive::IsFloatingPointType(input_type)) { |
| 6338 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6339 | } else { |
| 6340 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6341 | } |
| 6342 | |
| 6343 | if (Primitive::IsFloatingPointType(result_type)) { |
| 6344 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6345 | } else { |
| 6346 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6347 | } |
| 6348 | } else { |
| 6349 | InvokeRuntimeCallingConvention calling_convention; |
| 6350 | |
| 6351 | if (Primitive::IsFloatingPointType(input_type)) { |
| 6352 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 6353 | } else { |
| 6354 | DCHECK_EQ(input_type, Primitive::kPrimLong); |
| 6355 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 6356 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 6357 | } |
| 6358 | |
| 6359 | locations->SetOut(calling_convention.GetReturnLocation(result_type)); |
| 6360 | } |
| 6361 | } |
| 6362 | |
| 6363 | void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
| 6364 | LocationSummary* locations = conversion->GetLocations(); |
| 6365 | Primitive::Type result_type = conversion->GetResultType(); |
| 6366 | Primitive::Type input_type = conversion->GetInputType(); |
| 6367 | bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6368 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6369 | |
| 6370 | DCHECK_NE(input_type, result_type); |
| 6371 | |
| 6372 | if (result_type == Primitive::kPrimLong && Primitive::IsIntegralType(input_type)) { |
| 6373 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 6374 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 6375 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 6376 | |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 6377 | if (dst_low != src) { |
| 6378 | __ Move(dst_low, src); |
| 6379 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6380 | __ Sra(dst_high, src, 31); |
| 6381 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
| 6382 | Register dst = locations->Out().AsRegister<Register>(); |
| 6383 | Register src = (input_type == Primitive::kPrimLong) |
| 6384 | ? locations->InAt(0).AsRegisterPairLow<Register>() |
| 6385 | : locations->InAt(0).AsRegister<Register>(); |
| 6386 | |
| 6387 | switch (result_type) { |
| 6388 | case Primitive::kPrimChar: |
| 6389 | __ Andi(dst, src, 0xFFFF); |
| 6390 | break; |
| 6391 | case Primitive::kPrimByte: |
| 6392 | if (has_sign_extension) { |
| 6393 | __ Seb(dst, src); |
| 6394 | } else { |
| 6395 | __ Sll(dst, src, 24); |
| 6396 | __ Sra(dst, dst, 24); |
| 6397 | } |
| 6398 | break; |
| 6399 | case Primitive::kPrimShort: |
| 6400 | if (has_sign_extension) { |
| 6401 | __ Seh(dst, src); |
| 6402 | } else { |
| 6403 | __ Sll(dst, src, 16); |
| 6404 | __ Sra(dst, dst, 16); |
| 6405 | } |
| 6406 | break; |
| 6407 | case Primitive::kPrimInt: |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 6408 | if (dst != src) { |
| 6409 | __ Move(dst, src); |
| 6410 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6411 | break; |
| 6412 | |
| 6413 | default: |
| 6414 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 6415 | << " to " << result_type; |
| 6416 | } |
| 6417 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6418 | if (input_type == Primitive::kPrimLong) { |
| 6419 | if (isR6) { |
| 6420 | // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 6421 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 6422 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 6423 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 6424 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 6425 | __ Mtc1(src_low, FTMP); |
| 6426 | __ Mthc1(src_high, FTMP); |
| 6427 | if (result_type == Primitive::kPrimFloat) { |
| 6428 | __ Cvtsl(dst, FTMP); |
| 6429 | } else { |
| 6430 | __ Cvtdl(dst, FTMP); |
| 6431 | } |
| 6432 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6433 | QuickEntrypointEnum entrypoint = (result_type == Primitive::kPrimFloat) ? kQuickL2f |
| 6434 | : kQuickL2d; |
| 6435 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6436 | if (result_type == Primitive::kPrimFloat) { |
| 6437 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 6438 | } else { |
| 6439 | CheckEntrypointTypes<kQuickL2d, double, int64_t>(); |
| 6440 | } |
| 6441 | } |
| 6442 | } else { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6443 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 6444 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 6445 | __ Mtc1(src, FTMP); |
| 6446 | if (result_type == Primitive::kPrimFloat) { |
| 6447 | __ Cvtsw(dst, FTMP); |
| 6448 | } else { |
| 6449 | __ Cvtdw(dst, FTMP); |
| 6450 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6451 | } |
| 6452 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
| 6453 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6454 | if (result_type == Primitive::kPrimLong) { |
| 6455 | if (isR6) { |
| 6456 | // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 6457 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 6458 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 6459 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 6460 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 6461 | MipsLabel truncate; |
| 6462 | MipsLabel done; |
| 6463 | |
| 6464 | // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive |
| 6465 | // value when the input is either a NaN or is outside of the range of the output type |
| 6466 | // after the truncation. IOW, the three special cases (NaN, too small, too big) produce |
| 6467 | // the same result. |
| 6468 | // |
| 6469 | // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum |
| 6470 | // value of the output type if the input is outside of the range after the truncation or |
| 6471 | // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct |
| 6472 | // results. This matches the desired float/double-to-int/long conversion exactly. |
| 6473 | // |
| 6474 | // So, NAN2008 affects handling of negative values and NaNs by the truncate instruction. |
| 6475 | // |
| 6476 | // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate |
| 6477 | // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6, |
| 6478 | // even though it must be NAN2008=1 on R6. |
| 6479 | // |
| 6480 | // The code takes care of the different behaviors by first comparing the input to the |
| 6481 | // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int). |
| 6482 | // If the input is greater than or equal to the minimum, it procedes to the truncate |
| 6483 | // instruction, which will handle such an input the same way irrespective of NAN2008. |
| 6484 | // Otherwise the input is compared to itself to determine whether it is a NaN or not |
| 6485 | // in order to return either zero or the minimum value. |
| 6486 | // |
| 6487 | // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the |
| 6488 | // truncate instruction for MIPS64R6. |
| 6489 | if (input_type == Primitive::kPrimFloat) { |
| 6490 | uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int64_t>::min()); |
| 6491 | __ LoadConst32(TMP, min_val); |
| 6492 | __ Mtc1(TMP, FTMP); |
| 6493 | __ CmpLeS(FTMP, FTMP, src); |
| 6494 | } else { |
| 6495 | uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int64_t>::min()); |
| 6496 | __ LoadConst32(TMP, High32Bits(min_val)); |
| 6497 | __ Mtc1(ZERO, FTMP); |
| 6498 | __ Mthc1(TMP, FTMP); |
| 6499 | __ CmpLeD(FTMP, FTMP, src); |
| 6500 | } |
| 6501 | |
| 6502 | __ Bc1nez(FTMP, &truncate); |
| 6503 | |
| 6504 | if (input_type == Primitive::kPrimFloat) { |
| 6505 | __ CmpEqS(FTMP, src, src); |
| 6506 | } else { |
| 6507 | __ CmpEqD(FTMP, src, src); |
| 6508 | } |
| 6509 | __ Move(dst_low, ZERO); |
| 6510 | __ LoadConst32(dst_high, std::numeric_limits<int32_t>::min()); |
| 6511 | __ Mfc1(TMP, FTMP); |
| 6512 | __ And(dst_high, dst_high, TMP); |
| 6513 | |
| 6514 | __ B(&done); |
| 6515 | |
| 6516 | __ Bind(&truncate); |
| 6517 | |
| 6518 | if (input_type == Primitive::kPrimFloat) { |
| 6519 | __ TruncLS(FTMP, src); |
| 6520 | } else { |
| 6521 | __ TruncLD(FTMP, src); |
| 6522 | } |
| 6523 | __ Mfc1(dst_low, FTMP); |
| 6524 | __ Mfhc1(dst_high, FTMP); |
| 6525 | |
| 6526 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6527 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6528 | QuickEntrypointEnum entrypoint = (input_type == Primitive::kPrimFloat) ? kQuickF2l |
| 6529 | : kQuickD2l; |
| 6530 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6531 | if (input_type == Primitive::kPrimFloat) { |
| 6532 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 6533 | } else { |
| 6534 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 6535 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6536 | } |
| 6537 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6538 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 6539 | Register dst = locations->Out().AsRegister<Register>(); |
| 6540 | MipsLabel truncate; |
| 6541 | MipsLabel done; |
| 6542 | |
| 6543 | // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate |
| 6544 | // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6, |
| 6545 | // even though it must be NAN2008=1 on R6. |
| 6546 | // |
| 6547 | // For details see the large comment above for the truncation of float/double to long on R6. |
| 6548 | // |
| 6549 | // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the |
| 6550 | // truncate instruction for MIPS64R6. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6551 | if (input_type == Primitive::kPrimFloat) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6552 | uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min()); |
| 6553 | __ LoadConst32(TMP, min_val); |
| 6554 | __ Mtc1(TMP, FTMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6555 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6556 | uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min()); |
| 6557 | __ LoadConst32(TMP, High32Bits(min_val)); |
| 6558 | __ Mtc1(ZERO, FTMP); |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 6559 | __ MoveToFpuHigh(TMP, FTMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6560 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6561 | |
| 6562 | if (isR6) { |
| 6563 | if (input_type == Primitive::kPrimFloat) { |
| 6564 | __ CmpLeS(FTMP, FTMP, src); |
| 6565 | } else { |
| 6566 | __ CmpLeD(FTMP, FTMP, src); |
| 6567 | } |
| 6568 | __ Bc1nez(FTMP, &truncate); |
| 6569 | |
| 6570 | if (input_type == Primitive::kPrimFloat) { |
| 6571 | __ CmpEqS(FTMP, src, src); |
| 6572 | } else { |
| 6573 | __ CmpEqD(FTMP, src, src); |
| 6574 | } |
| 6575 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); |
| 6576 | __ Mfc1(TMP, FTMP); |
| 6577 | __ And(dst, dst, TMP); |
| 6578 | } else { |
| 6579 | if (input_type == Primitive::kPrimFloat) { |
| 6580 | __ ColeS(0, FTMP, src); |
| 6581 | } else { |
| 6582 | __ ColeD(0, FTMP, src); |
| 6583 | } |
| 6584 | __ Bc1t(0, &truncate); |
| 6585 | |
| 6586 | if (input_type == Primitive::kPrimFloat) { |
| 6587 | __ CeqS(0, src, src); |
| 6588 | } else { |
| 6589 | __ CeqD(0, src, src); |
| 6590 | } |
| 6591 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); |
| 6592 | __ Movf(dst, ZERO, 0); |
| 6593 | } |
| 6594 | |
| 6595 | __ B(&done); |
| 6596 | |
| 6597 | __ Bind(&truncate); |
| 6598 | |
| 6599 | if (input_type == Primitive::kPrimFloat) { |
| 6600 | __ TruncWS(FTMP, src); |
| 6601 | } else { |
| 6602 | __ TruncWD(FTMP, src); |
| 6603 | } |
| 6604 | __ Mfc1(dst, FTMP); |
| 6605 | |
| 6606 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6607 | } |
| 6608 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 6609 | Primitive::IsFloatingPointType(input_type)) { |
| 6610 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 6611 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 6612 | if (result_type == Primitive::kPrimFloat) { |
| 6613 | __ Cvtsd(dst, src); |
| 6614 | } else { |
| 6615 | __ Cvtds(dst, src); |
| 6616 | } |
| 6617 | } else { |
| 6618 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 6619 | << " to " << result_type; |
| 6620 | } |
| 6621 | } |
| 6622 | |
| 6623 | void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) { |
| 6624 | HandleShift(ushr); |
| 6625 | } |
| 6626 | |
| 6627 | void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) { |
| 6628 | HandleShift(ushr); |
| 6629 | } |
| 6630 | |
| 6631 | void LocationsBuilderMIPS::VisitXor(HXor* instruction) { |
| 6632 | HandleBinaryOp(instruction); |
| 6633 | } |
| 6634 | |
| 6635 | void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) { |
| 6636 | HandleBinaryOp(instruction); |
| 6637 | } |
| 6638 | |
| 6639 | void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 6640 | // Nothing to do, this should be removed during prepare for register allocator. |
| 6641 | LOG(FATAL) << "Unreachable"; |
| 6642 | } |
| 6643 | |
| 6644 | void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 6645 | // Nothing to do, this should be removed during prepare for register allocator. |
| 6646 | LOG(FATAL) << "Unreachable"; |
| 6647 | } |
| 6648 | |
| 6649 | void LocationsBuilderMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6650 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6651 | } |
| 6652 | |
| 6653 | void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6654 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6655 | } |
| 6656 | |
| 6657 | void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6658 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6659 | } |
| 6660 | |
| 6661 | void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6662 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6663 | } |
| 6664 | |
| 6665 | void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6666 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6667 | } |
| 6668 | |
| 6669 | void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6670 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6671 | } |
| 6672 | |
| 6673 | void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6674 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6675 | } |
| 6676 | |
| 6677 | void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6678 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6679 | } |
| 6680 | |
| 6681 | void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6682 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6683 | } |
| 6684 | |
| 6685 | void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6686 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6687 | } |
| 6688 | |
| 6689 | void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6690 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6691 | } |
| 6692 | |
| 6693 | void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6694 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6695 | } |
| 6696 | |
| 6697 | void LocationsBuilderMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6698 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6699 | } |
| 6700 | |
| 6701 | void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6702 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6703 | } |
| 6704 | |
| 6705 | void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6706 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6707 | } |
| 6708 | |
| 6709 | void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6710 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6711 | } |
| 6712 | |
| 6713 | void LocationsBuilderMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6714 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6715 | } |
| 6716 | |
| 6717 | void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6718 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6719 | } |
| 6720 | |
| 6721 | void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6722 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6723 | } |
| 6724 | |
| 6725 | void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6726 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6727 | } |
| 6728 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6729 | void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6730 | LocationSummary* locations = |
| 6731 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6732 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6733 | } |
| 6734 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 6735 | void InstructionCodeGeneratorMIPS::GenPackedSwitchWithCompares(Register value_reg, |
| 6736 | int32_t lower_bound, |
| 6737 | uint32_t num_entries, |
| 6738 | HBasicBlock* switch_block, |
| 6739 | HBasicBlock* default_block) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6740 | // Create a set of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6741 | Register temp_reg = TMP; |
| 6742 | __ Addiu32(temp_reg, value_reg, -lower_bound); |
| 6743 | // Jump to default if index is negative |
| 6744 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 6745 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 6746 | __ Bltz(temp_reg, codegen_->GetLabelOf(default_block)); |
| 6747 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 6748 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6749 | // Jump to successors[0] if value == lower_bound. |
| 6750 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 6751 | int32_t last_index = 0; |
| 6752 | for (; num_entries - last_index > 2; last_index += 2) { |
| 6753 | __ Addiu(temp_reg, temp_reg, -2); |
| 6754 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 6755 | __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 6756 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 6757 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 6758 | } |
| 6759 | if (num_entries - last_index == 2) { |
| 6760 | // The last missing case_value. |
| 6761 | __ Addiu(temp_reg, temp_reg, -1); |
| 6762 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6763 | } |
| 6764 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6765 | // And the default for any other value. |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 6766 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6767 | __ B(codegen_->GetLabelOf(default_block)); |
| 6768 | } |
| 6769 | } |
| 6770 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 6771 | void InstructionCodeGeneratorMIPS::GenTableBasedPackedSwitch(Register value_reg, |
| 6772 | Register constant_area, |
| 6773 | int32_t lower_bound, |
| 6774 | uint32_t num_entries, |
| 6775 | HBasicBlock* switch_block, |
| 6776 | HBasicBlock* default_block) { |
| 6777 | // Create a jump table. |
| 6778 | std::vector<MipsLabel*> labels(num_entries); |
| 6779 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 6780 | for (uint32_t i = 0; i < num_entries; i++) { |
| 6781 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 6782 | } |
| 6783 | JumpTable* table = __ CreateJumpTable(std::move(labels)); |
| 6784 | |
| 6785 | // Is the value in range? |
| 6786 | __ Addiu32(TMP, value_reg, -lower_bound); |
| 6787 | if (IsInt<16>(static_cast<int32_t>(num_entries))) { |
| 6788 | __ Sltiu(AT, TMP, num_entries); |
| 6789 | __ Beqz(AT, codegen_->GetLabelOf(default_block)); |
| 6790 | } else { |
| 6791 | __ LoadConst32(AT, num_entries); |
| 6792 | __ Bgeu(TMP, AT, codegen_->GetLabelOf(default_block)); |
| 6793 | } |
| 6794 | |
| 6795 | // We are in the range of the table. |
| 6796 | // Load the target address from the jump table, indexing by the value. |
| 6797 | __ LoadLabelAddress(AT, constant_area, table->GetLabel()); |
| 6798 | __ Sll(TMP, TMP, 2); |
| 6799 | __ Addu(TMP, TMP, AT); |
| 6800 | __ Lw(TMP, TMP, 0); |
| 6801 | // Compute the absolute target address by adding the table start address |
| 6802 | // (the table contains offsets to targets relative to its start). |
| 6803 | __ Addu(TMP, TMP, AT); |
| 6804 | // And jump. |
| 6805 | __ Jr(TMP); |
| 6806 | __ NopIfNoReordering(); |
| 6807 | } |
| 6808 | |
| 6809 | void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6810 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 6811 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 6812 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6813 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6814 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 6815 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6816 | |
| 6817 | if (codegen_->GetInstructionSetFeatures().IsR6() && |
| 6818 | num_entries > kPackedSwitchJumpTableThreshold) { |
| 6819 | // R6 uses PC-relative addressing to access the jump table. |
| 6820 | // R2, OTOH, requires an HMipsComputeBaseMethodAddress input to access |
| 6821 | // the jump table and it is implemented by changing HPackedSwitch to |
| 6822 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress. |
| 6823 | // See VisitMipsPackedSwitch() for the table-based implementation on R2. |
| 6824 | GenTableBasedPackedSwitch(value_reg, |
| 6825 | ZERO, |
| 6826 | lower_bound, |
| 6827 | num_entries, |
| 6828 | switch_block, |
| 6829 | default_block); |
| 6830 | } else { |
| 6831 | GenPackedSwitchWithCompares(value_reg, |
| 6832 | lower_bound, |
| 6833 | num_entries, |
| 6834 | switch_block, |
| 6835 | default_block); |
| 6836 | } |
| 6837 | } |
| 6838 | |
| 6839 | void LocationsBuilderMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 6840 | LocationSummary* locations = |
| 6841 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6842 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6843 | // Constant area pointer (HMipsComputeBaseMethodAddress). |
| 6844 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6845 | } |
| 6846 | |
| 6847 | void InstructionCodeGeneratorMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 6848 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 6849 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 6850 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6851 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6852 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 6853 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 6854 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6855 | |
| 6856 | // This is an R2-only path. HPackedSwitch has been changed to |
| 6857 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress |
| 6858 | // required to address the jump table relative to PC. |
| 6859 | GenTableBasedPackedSwitch(value_reg, |
| 6860 | constant_area, |
| 6861 | lower_bound, |
| 6862 | num_entries, |
| 6863 | switch_block, |
| 6864 | default_block); |
| 6865 | } |
| 6866 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6867 | void LocationsBuilderMIPS::VisitMipsComputeBaseMethodAddress( |
| 6868 | HMipsComputeBaseMethodAddress* insn) { |
| 6869 | LocationSummary* locations = |
| 6870 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 6871 | locations->SetOut(Location::RequiresRegister()); |
| 6872 | } |
| 6873 | |
| 6874 | void InstructionCodeGeneratorMIPS::VisitMipsComputeBaseMethodAddress( |
| 6875 | HMipsComputeBaseMethodAddress* insn) { |
| 6876 | LocationSummary* locations = insn->GetLocations(); |
| 6877 | Register reg = locations->Out().AsRegister<Register>(); |
| 6878 | |
| 6879 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
| 6880 | |
| 6881 | // Generate a dummy PC-relative call to obtain PC. |
| 6882 | __ Nal(); |
| 6883 | // Grab the return address off RA. |
| 6884 | __ Move(reg, RA); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6885 | // TODO: Can we share this code with that of VisitMipsDexCacheArraysBase()? |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6886 | |
| 6887 | // Remember this offset (the obtained PC value) for later use with constant area. |
| 6888 | __ BindPcRelBaseLabel(); |
| 6889 | } |
| 6890 | |
| 6891 | void LocationsBuilderMIPS::VisitMipsDexCacheArraysBase(HMipsDexCacheArraysBase* base) { |
| 6892 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 6893 | locations->SetOut(Location::RequiresRegister()); |
| 6894 | } |
| 6895 | |
| 6896 | void InstructionCodeGeneratorMIPS::VisitMipsDexCacheArraysBase(HMipsDexCacheArraysBase* base) { |
| 6897 | Register reg = base->GetLocations()->Out().AsRegister<Register>(); |
| 6898 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
| 6899 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6900 | // TODO: Reuse MipsComputeBaseMethodAddress on R2 instead of passing ZERO to force emitting NAL. |
| 6901 | codegen_->EmitPcRelativeAddressPlaceholder(info, reg, ZERO); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6902 | } |
| 6903 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6904 | void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 6905 | // The trampoline uses the same calling convention as dex calling conventions, |
| 6906 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 6907 | // the method_idx. |
| 6908 | HandleInvoke(invoke); |
| 6909 | } |
| 6910 | |
| 6911 | void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 6912 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 6913 | } |
| 6914 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 6915 | void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 6916 | LocationSummary* locations = |
| 6917 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6918 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6919 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6920 | } |
| 6921 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 6922 | void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 6923 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6924 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6925 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 6926 | instruction->GetIndex(), kMipsPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6927 | __ LoadFromOffset(kLoadWord, |
| 6928 | locations->Out().AsRegister<Register>(), |
| 6929 | locations->InAt(0).AsRegister<Register>(), |
| 6930 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 6931 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6932 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6933 | instruction->GetIndex(), kMipsPointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6934 | __ LoadFromOffset(kLoadWord, |
| 6935 | locations->Out().AsRegister<Register>(), |
| 6936 | locations->InAt(0).AsRegister<Register>(), |
| 6937 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6938 | __ LoadFromOffset(kLoadWord, |
| 6939 | locations->Out().AsRegister<Register>(), |
| 6940 | locations->Out().AsRegister<Register>(), |
| 6941 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 6942 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6943 | } |
| 6944 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6945 | #undef __ |
| 6946 | #undef QUICK_ENTRY_POINT |
| 6947 | |
| 6948 | } // namespace mips |
| 6949 | } // namespace art |