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()) { |
| 102 | if (calling_convention.GetRegisterAt(gp_index) == A1) { |
| 103 | gp_index_++; // Skip A1, and use A2_A3 instead. |
| 104 | gp_index++; |
| 105 | } |
| 106 | Register low_even = calling_convention.GetRegisterAt(gp_index); |
| 107 | Register high_odd = calling_convention.GetRegisterAt(gp_index + 1); |
| 108 | DCHECK_EQ(low_even + 1, high_odd); |
| 109 | next_location = Location::RegisterPairLocation(low_even, high_odd); |
| 110 | } else { |
| 111 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
| 112 | next_location = Location::DoubleStackSlot(stack_offset); |
| 113 | } |
| 114 | break; |
| 115 | } |
| 116 | |
| 117 | // Note: both float and double types are stored in even FPU registers. On 32 bit FPU, double |
| 118 | // will take up the even/odd pair, while floats are stored in even regs only. |
| 119 | // On 64 bit FPU, both double and float are stored in even registers only. |
| 120 | case Primitive::kPrimFloat: |
| 121 | case Primitive::kPrimDouble: { |
| 122 | uint32_t float_index = float_index_++; |
| 123 | if (float_index < calling_convention.GetNumberOfFpuRegisters()) { |
| 124 | next_location = Location::FpuRegisterLocation( |
| 125 | calling_convention.GetFpuRegisterAt(float_index)); |
| 126 | } else { |
| 127 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
| 128 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 129 | : Location::StackSlot(stack_offset); |
| 130 | } |
| 131 | break; |
| 132 | } |
| 133 | |
| 134 | case Primitive::kPrimVoid: |
| 135 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 136 | break; |
| 137 | } |
| 138 | |
| 139 | // Space on the stack is reserved for all arguments. |
| 140 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
| 141 | |
| 142 | return next_location; |
| 143 | } |
| 144 | |
| 145 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type type) { |
| 146 | return MipsReturnLocation(type); |
| 147 | } |
| 148 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 149 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 150 | #define __ down_cast<CodeGeneratorMIPS*>(codegen)->GetAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 151 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value() |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 152 | |
| 153 | class BoundsCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 154 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 155 | explicit BoundsCheckSlowPathMIPS(HBoundsCheck* instruction) : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 156 | |
| 157 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 158 | LocationSummary* locations = instruction_->GetLocations(); |
| 159 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 160 | __ Bind(GetEntryLabel()); |
| 161 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 162 | // Live registers will be restored in the catch block if caught. |
| 163 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 164 | } |
| 165 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 166 | // move resolver. |
| 167 | InvokeRuntimeCallingConvention calling_convention; |
| 168 | codegen->EmitParallelMoves(locations->InAt(0), |
| 169 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 170 | Primitive::kPrimInt, |
| 171 | locations->InAt(1), |
| 172 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 173 | Primitive::kPrimInt); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 174 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 175 | ? kQuickThrowStringBounds |
| 176 | : kQuickThrowArrayBounds; |
| 177 | mips_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 178 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 179 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 180 | } |
| 181 | |
| 182 | bool IsFatal() const OVERRIDE { return true; } |
| 183 | |
| 184 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS"; } |
| 185 | |
| 186 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 187 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS); |
| 188 | }; |
| 189 | |
| 190 | class DivZeroCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 191 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 192 | explicit DivZeroCheckSlowPathMIPS(HDivZeroCheck* instruction) : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 193 | |
| 194 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 195 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 196 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 197 | mips_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 198 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 199 | } |
| 200 | |
| 201 | bool IsFatal() const OVERRIDE { return true; } |
| 202 | |
| 203 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS"; } |
| 204 | |
| 205 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 206 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS); |
| 207 | }; |
| 208 | |
| 209 | class LoadClassSlowPathMIPS : public SlowPathCodeMIPS { |
| 210 | public: |
| 211 | LoadClassSlowPathMIPS(HLoadClass* cls, |
| 212 | HInstruction* at, |
| 213 | uint32_t dex_pc, |
| 214 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 215 | : SlowPathCodeMIPS(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 216 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 217 | } |
| 218 | |
| 219 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 220 | LocationSummary* locations = at_->GetLocations(); |
| 221 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 222 | |
| 223 | __ Bind(GetEntryLabel()); |
| 224 | SaveLiveRegisters(codegen, locations); |
| 225 | |
| 226 | InvokeRuntimeCallingConvention calling_convention; |
| 227 | __ LoadConst32(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex()); |
| 228 | |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 229 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 230 | : kQuickInitializeType; |
| 231 | mips_codegen->InvokeRuntime(entrypoint, at_, dex_pc_, this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 232 | if (do_clinit_) { |
| 233 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 234 | } else { |
| 235 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 236 | } |
| 237 | |
| 238 | // Move the class to the desired location. |
| 239 | Location out = locations->Out(); |
| 240 | if (out.IsValid()) { |
| 241 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 242 | Primitive::Type type = at_->GetType(); |
| 243 | mips_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
| 244 | } |
| 245 | |
| 246 | RestoreLiveRegisters(codegen, locations); |
| 247 | __ B(GetExitLabel()); |
| 248 | } |
| 249 | |
| 250 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS"; } |
| 251 | |
| 252 | private: |
| 253 | // The class this slow path will load. |
| 254 | HLoadClass* const cls_; |
| 255 | |
| 256 | // The instruction where this slow path is happening. |
| 257 | // (Might be the load class or an initialization check). |
| 258 | HInstruction* const at_; |
| 259 | |
| 260 | // The dex PC of `at_`. |
| 261 | const uint32_t dex_pc_; |
| 262 | |
| 263 | // Whether to initialize the class. |
| 264 | const bool do_clinit_; |
| 265 | |
| 266 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS); |
| 267 | }; |
| 268 | |
| 269 | class LoadStringSlowPathMIPS : public SlowPathCodeMIPS { |
| 270 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 271 | explicit LoadStringSlowPathMIPS(HLoadString* instruction) : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 272 | |
| 273 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 274 | LocationSummary* locations = instruction_->GetLocations(); |
| 275 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 276 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 277 | |
| 278 | __ Bind(GetEntryLabel()); |
| 279 | SaveLiveRegisters(codegen, locations); |
| 280 | |
| 281 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 282 | HLoadString* load = instruction_->AsLoadString(); |
| 283 | const uint32_t string_index = load->GetStringIndex(); |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 284 | __ LoadConst32(calling_convention.GetRegisterAt(0), string_index); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 285 | mips_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 286 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 287 | Primitive::Type type = instruction_->GetType(); |
| 288 | mips_codegen->MoveLocation(locations->Out(), |
| 289 | calling_convention.GetReturnLocation(type), |
| 290 | type); |
| 291 | |
| 292 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 293 | |
| 294 | // Store the resolved String to the BSS entry. |
| 295 | // TODO: Change art_quick_resolve_string to kSaveEverything and use a temporary for the |
| 296 | // .bss entry address in the fast path, so that we can avoid another calculation here. |
| 297 | bool isR6 = mips_codegen->GetInstructionSetFeatures().IsR6(); |
| 298 | Register base = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>(); |
| 299 | Register out = locations->Out().AsRegister<Register>(); |
| 300 | DCHECK_NE(out, AT); |
| 301 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
| 302 | mips_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index); |
| 303 | mips_codegen->EmitPcRelativeAddressPlaceholder(info, TMP, base); |
| 304 | __ StoreToOffset(kStoreWord, out, TMP, 0); |
| 305 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 306 | __ B(GetExitLabel()); |
| 307 | } |
| 308 | |
| 309 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS"; } |
| 310 | |
| 311 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 312 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS); |
| 313 | }; |
| 314 | |
| 315 | class NullCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 316 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 317 | explicit NullCheckSlowPathMIPS(HNullCheck* instr) : SlowPathCodeMIPS(instr) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 318 | |
| 319 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 320 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 321 | __ Bind(GetEntryLabel()); |
| 322 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 323 | // Live registers will be restored in the catch block if caught. |
| 324 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 325 | } |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 326 | mips_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 327 | instruction_, |
| 328 | instruction_->GetDexPc(), |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 329 | this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 330 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 331 | } |
| 332 | |
| 333 | bool IsFatal() const OVERRIDE { return true; } |
| 334 | |
| 335 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS"; } |
| 336 | |
| 337 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 338 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS); |
| 339 | }; |
| 340 | |
| 341 | class SuspendCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 342 | public: |
| 343 | SuspendCheckSlowPathMIPS(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 344 | : SlowPathCodeMIPS(instruction), successor_(successor) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 345 | |
| 346 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 347 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 348 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 349 | mips_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 350 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 351 | if (successor_ == nullptr) { |
| 352 | __ B(GetReturnLabel()); |
| 353 | } else { |
| 354 | __ B(mips_codegen->GetLabelOf(successor_)); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | MipsLabel* GetReturnLabel() { |
| 359 | DCHECK(successor_ == nullptr); |
| 360 | return &return_label_; |
| 361 | } |
| 362 | |
| 363 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS"; } |
| 364 | |
| 365 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 366 | // If not null, the block to branch to after the suspend check. |
| 367 | HBasicBlock* const successor_; |
| 368 | |
| 369 | // If `successor_` is null, the label to branch to after the suspend check. |
| 370 | MipsLabel return_label_; |
| 371 | |
| 372 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS); |
| 373 | }; |
| 374 | |
| 375 | class TypeCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 376 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 377 | explicit TypeCheckSlowPathMIPS(HInstruction* instruction) : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 378 | |
| 379 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 380 | LocationSummary* locations = instruction_->GetLocations(); |
| 381 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) : locations->Out(); |
| 382 | uint32_t dex_pc = instruction_->GetDexPc(); |
| 383 | DCHECK(instruction_->IsCheckCast() |
| 384 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 385 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 386 | |
| 387 | __ Bind(GetEntryLabel()); |
| 388 | SaveLiveRegisters(codegen, locations); |
| 389 | |
| 390 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 391 | // move resolver. |
| 392 | InvokeRuntimeCallingConvention calling_convention; |
| 393 | codegen->EmitParallelMoves(locations->InAt(1), |
| 394 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 395 | Primitive::kPrimNot, |
| 396 | object_class, |
| 397 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 398 | Primitive::kPrimNot); |
| 399 | |
| 400 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 401 | mips_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 402 | CheckEntrypointTypes< |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 403 | kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 404 | Primitive::Type ret_type = instruction_->GetType(); |
| 405 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 406 | mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 407 | } else { |
| 408 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 409 | mips_codegen->InvokeRuntime(kQuickCheckCast, instruction_, dex_pc, this); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 410 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
| 411 | } |
| 412 | |
| 413 | RestoreLiveRegisters(codegen, locations); |
| 414 | __ B(GetExitLabel()); |
| 415 | } |
| 416 | |
| 417 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; } |
| 418 | |
| 419 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 420 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS); |
| 421 | }; |
| 422 | |
| 423 | class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS { |
| 424 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 425 | explicit DeoptimizationSlowPathMIPS(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 426 | : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 427 | |
| 428 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 429 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 430 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 431 | mips_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 432 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; } |
| 436 | |
| 437 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 438 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS); |
| 439 | }; |
| 440 | |
| 441 | CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph, |
| 442 | const MipsInstructionSetFeatures& isa_features, |
| 443 | const CompilerOptions& compiler_options, |
| 444 | OptimizingCompilerStats* stats) |
| 445 | : CodeGenerator(graph, |
| 446 | kNumberOfCoreRegisters, |
| 447 | kNumberOfFRegisters, |
| 448 | kNumberOfRegisterPairs, |
| 449 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 450 | arraysize(kCoreCalleeSaves)), |
| 451 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 452 | arraysize(kFpuCalleeSaves)), |
| 453 | compiler_options, |
| 454 | stats), |
| 455 | block_labels_(nullptr), |
| 456 | location_builder_(graph, this), |
| 457 | instruction_visitor_(graph, this), |
| 458 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 459 | assembler_(graph->GetArena(), &isa_features), |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 460 | isa_features_(isa_features), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 461 | uint32_literals_(std::less<uint32_t>(), |
| 462 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 463 | method_patches_(MethodReferenceComparator(), |
| 464 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 465 | call_patches_(MethodReferenceComparator(), |
| 466 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 467 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 468 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 469 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 470 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 471 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 472 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 473 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 474 | boot_image_address_patches_(std::less<uint32_t>(), |
| 475 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 476 | clobbered_ra_(false) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 477 | // Save RA (containing the return address) to mimic Quick. |
| 478 | AddAllocatedRegister(Location::RegisterLocation(RA)); |
| 479 | } |
| 480 | |
| 481 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 482 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 483 | #define __ down_cast<MipsAssembler*>(GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 484 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value() |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 485 | |
| 486 | void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) { |
| 487 | // Ensure that we fix up branches. |
| 488 | __ FinalizeCode(); |
| 489 | |
| 490 | // Adjust native pc offsets in stack maps. |
| 491 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
| 492 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; |
| 493 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 494 | DCHECK_GE(new_position, old_position); |
| 495 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 496 | } |
| 497 | |
| 498 | // Adjust pc offsets for the disassembly information. |
| 499 | if (disasm_info_ != nullptr) { |
| 500 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 501 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 502 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 503 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 504 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 505 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 506 | } |
| 507 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 508 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 509 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | CodeGenerator::Finalize(allocator); |
| 514 | } |
| 515 | |
| 516 | MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const { |
| 517 | return codegen_->GetAssembler(); |
| 518 | } |
| 519 | |
| 520 | void ParallelMoveResolverMIPS::EmitMove(size_t index) { |
| 521 | DCHECK_LT(index, moves_.size()); |
| 522 | MoveOperands* move = moves_[index]; |
| 523 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); |
| 524 | } |
| 525 | |
| 526 | void ParallelMoveResolverMIPS::EmitSwap(size_t index) { |
| 527 | DCHECK_LT(index, moves_.size()); |
| 528 | MoveOperands* move = moves_[index]; |
| 529 | Primitive::Type type = move->GetType(); |
| 530 | Location loc1 = move->GetDestination(); |
| 531 | Location loc2 = move->GetSource(); |
| 532 | |
| 533 | DCHECK(!loc1.IsConstant()); |
| 534 | DCHECK(!loc2.IsConstant()); |
| 535 | |
| 536 | if (loc1.Equals(loc2)) { |
| 537 | return; |
| 538 | } |
| 539 | |
| 540 | if (loc1.IsRegister() && loc2.IsRegister()) { |
| 541 | // Swap 2 GPRs. |
| 542 | Register r1 = loc1.AsRegister<Register>(); |
| 543 | Register r2 = loc2.AsRegister<Register>(); |
| 544 | __ Move(TMP, r2); |
| 545 | __ Move(r2, r1); |
| 546 | __ Move(r1, TMP); |
| 547 | } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) { |
| 548 | FRegister f1 = loc1.AsFpuRegister<FRegister>(); |
| 549 | FRegister f2 = loc2.AsFpuRegister<FRegister>(); |
| 550 | if (type == Primitive::kPrimFloat) { |
| 551 | __ MovS(FTMP, f2); |
| 552 | __ MovS(f2, f1); |
| 553 | __ MovS(f1, FTMP); |
| 554 | } else { |
| 555 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 556 | __ MovD(FTMP, f2); |
| 557 | __ MovD(f2, f1); |
| 558 | __ MovD(f1, FTMP); |
| 559 | } |
| 560 | } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) || |
| 561 | (loc1.IsFpuRegister() && loc2.IsRegister())) { |
| 562 | // Swap FPR and GPR. |
| 563 | DCHECK_EQ(type, Primitive::kPrimFloat); // Can only swap a float. |
| 564 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 565 | : loc2.AsFpuRegister<FRegister>(); |
| 566 | Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>() |
| 567 | : loc2.AsRegister<Register>(); |
| 568 | __ Move(TMP, r2); |
| 569 | __ Mfc1(r2, f1); |
| 570 | __ Mtc1(TMP, f1); |
| 571 | } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) { |
| 572 | // Swap 2 GPR register pairs. |
| 573 | Register r1 = loc1.AsRegisterPairLow<Register>(); |
| 574 | Register r2 = loc2.AsRegisterPairLow<Register>(); |
| 575 | __ Move(TMP, r2); |
| 576 | __ Move(r2, r1); |
| 577 | __ Move(r1, TMP); |
| 578 | r1 = loc1.AsRegisterPairHigh<Register>(); |
| 579 | r2 = loc2.AsRegisterPairHigh<Register>(); |
| 580 | __ Move(TMP, r2); |
| 581 | __ Move(r2, r1); |
| 582 | __ Move(r1, TMP); |
| 583 | } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) || |
| 584 | (loc1.IsFpuRegister() && loc2.IsRegisterPair())) { |
| 585 | // Swap FPR and GPR register pair. |
| 586 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 587 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 588 | : loc2.AsFpuRegister<FRegister>(); |
| 589 | Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 590 | : loc2.AsRegisterPairLow<Register>(); |
| 591 | Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 592 | : loc2.AsRegisterPairHigh<Register>(); |
| 593 | // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and |
| 594 | // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR |
| 595 | // unpredictable and the following mfch1 will fail. |
| 596 | __ Mfc1(TMP, f1); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 597 | __ MoveFromFpuHigh(AT, f1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 598 | __ Mtc1(r2_l, f1); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 599 | __ MoveToFpuHigh(r2_h, f1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 600 | __ Move(r2_l, TMP); |
| 601 | __ Move(r2_h, AT); |
| 602 | } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) { |
| 603 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false); |
| 604 | } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) { |
| 605 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 606 | } else if ((loc1.IsRegister() && loc2.IsStackSlot()) || |
| 607 | (loc1.IsStackSlot() && loc2.IsRegister())) { |
| 608 | Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>() |
| 609 | : loc2.AsRegister<Register>(); |
| 610 | intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex() |
| 611 | : loc2.GetStackIndex(); |
| 612 | __ Move(TMP, reg); |
| 613 | __ LoadFromOffset(kLoadWord, reg, SP, offset); |
| 614 | __ StoreToOffset(kStoreWord, TMP, SP, offset); |
| 615 | } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) || |
| 616 | (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) { |
| 617 | Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 618 | : loc2.AsRegisterPairLow<Register>(); |
| 619 | Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 620 | : loc2.AsRegisterPairHigh<Register>(); |
| 621 | intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex() |
| 622 | : loc2.GetStackIndex(); |
| 623 | intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize) |
| 624 | : loc2.GetHighStackIndex(kMipsWordSize); |
| 625 | __ Move(TMP, reg_l); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 626 | __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 627 | __ StoreToOffset(kStoreWord, TMP, SP, offset_l); |
David Brazdil | 04d3e87 | 2016-01-29 09:50:09 +0000 | [diff] [blame] | 628 | __ Move(TMP, reg_h); |
| 629 | __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h); |
| 630 | __ StoreToOffset(kStoreWord, TMP, SP, offset_h); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 631 | } else { |
| 632 | LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported"; |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | void ParallelMoveResolverMIPS::RestoreScratch(int reg) { |
| 637 | __ Pop(static_cast<Register>(reg)); |
| 638 | } |
| 639 | |
| 640 | void ParallelMoveResolverMIPS::SpillScratch(int reg) { |
| 641 | __ Push(static_cast<Register>(reg)); |
| 642 | } |
| 643 | |
| 644 | void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) { |
| 645 | // Allocate a scratch register other than TMP, if available. |
| 646 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be |
| 647 | // automatically unspilled when the scratch scope object is destroyed). |
| 648 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); |
| 649 | // If V0 spills onto the stack, SP-relative offsets need to be adjusted. |
| 650 | int stack_offset = ensure_scratch.IsSpilled() ? kMipsWordSize : 0; |
| 651 | for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) { |
| 652 | __ LoadFromOffset(kLoadWord, |
| 653 | Register(ensure_scratch.GetRegister()), |
| 654 | SP, |
| 655 | index1 + stack_offset); |
| 656 | __ LoadFromOffset(kLoadWord, |
| 657 | TMP, |
| 658 | SP, |
| 659 | index2 + stack_offset); |
| 660 | __ StoreToOffset(kStoreWord, |
| 661 | Register(ensure_scratch.GetRegister()), |
| 662 | SP, |
| 663 | index2 + stack_offset); |
| 664 | __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset); |
| 665 | } |
| 666 | } |
| 667 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 668 | void CodeGeneratorMIPS::ComputeSpillMask() { |
| 669 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 670 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 671 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 672 | // If there're FPU callee-saved registers and there's an odd number of GPR callee-saved |
| 673 | // registers, include the ZERO register to force alignment of FPU callee-saved registers |
| 674 | // within the stack frame. |
| 675 | if ((fpu_spill_mask_ != 0) && (POPCOUNT(core_spill_mask_) % 2 != 0)) { |
| 676 | core_spill_mask_ |= (1 << ZERO); |
| 677 | } |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | bool CodeGeneratorMIPS::HasAllocatedCalleeSaveRegisters() const { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 681 | // 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] | 682 | // (this can happen in leaf methods), force CodeGenerator::InitializeCodeGeneration() |
| 683 | // into the path that creates a stack frame so that RA can be explicitly saved and restored. |
| 684 | // 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] | 685 | // TODO: Can this be improved? It causes creation of a stack frame (while RA might be |
| 686 | // saved in an unused temporary register) and saving of RA and the current method pointer |
| 687 | // in the frame. |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 688 | return CodeGenerator::HasAllocatedCalleeSaveRegisters() || clobbered_ra_; |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 689 | } |
| 690 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 691 | static dwarf::Reg DWARFReg(Register reg) { |
| 692 | return dwarf::Reg::MipsCore(static_cast<int>(reg)); |
| 693 | } |
| 694 | |
| 695 | // TODO: mapping of floating-point registers to DWARF. |
| 696 | |
| 697 | void CodeGeneratorMIPS::GenerateFrameEntry() { |
| 698 | __ Bind(&frame_entry_label_); |
| 699 | |
| 700 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips) || !IsLeafMethod(); |
| 701 | |
| 702 | if (do_overflow_check) { |
| 703 | __ LoadFromOffset(kLoadWord, |
| 704 | ZERO, |
| 705 | SP, |
| 706 | -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips))); |
| 707 | RecordPcInfo(nullptr, 0); |
| 708 | } |
| 709 | |
| 710 | if (HasEmptyFrame()) { |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 711 | CHECK_EQ(fpu_spill_mask_, 0u); |
| 712 | CHECK_EQ(core_spill_mask_, 1u << RA); |
| 713 | CHECK(!clobbered_ra_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 714 | return; |
| 715 | } |
| 716 | |
| 717 | // Make sure the frame size isn't unreasonably large. |
| 718 | if (GetFrameSize() > GetStackOverflowReservedBytes(kMips)) { |
| 719 | LOG(FATAL) << "Stack frame larger than " << GetStackOverflowReservedBytes(kMips) << " bytes"; |
| 720 | } |
| 721 | |
| 722 | // Spill callee-saved registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 723 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 724 | uint32_t ofs = GetFrameSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 725 | __ IncreaseFrameSize(ofs); |
| 726 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 727 | for (uint32_t mask = core_spill_mask_; mask != 0; ) { |
| 728 | Register reg = static_cast<Register>(MostSignificantBit(mask)); |
| 729 | mask ^= 1u << reg; |
| 730 | ofs -= kMipsWordSize; |
| 731 | // The ZERO register is only included for alignment. |
| 732 | if (reg != ZERO) { |
| 733 | __ StoreToOffset(kStoreWord, reg, SP, ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 734 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 735 | } |
| 736 | } |
| 737 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 738 | for (uint32_t mask = fpu_spill_mask_; mask != 0; ) { |
| 739 | FRegister reg = static_cast<FRegister>(MostSignificantBit(mask)); |
| 740 | mask ^= 1u << reg; |
| 741 | ofs -= kMipsDoublewordSize; |
| 742 | __ StoreDToOffset(reg, SP, ofs); |
| 743 | // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 744 | } |
| 745 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 746 | // Save the current method if we need it. Note that we do not |
| 747 | // do this in HCurrentMethod, as the instruction might have been removed |
| 748 | // in the SSA graph. |
| 749 | if (RequiresCurrentMethod()) { |
| 750 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
| 751 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | void CodeGeneratorMIPS::GenerateFrameExit() { |
| 755 | __ cfi().RememberState(); |
| 756 | |
| 757 | if (!HasEmptyFrame()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 758 | // Restore callee-saved registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 759 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 760 | // For better instruction scheduling restore RA before other registers. |
| 761 | uint32_t ofs = GetFrameSize(); |
| 762 | for (uint32_t mask = core_spill_mask_; mask != 0; ) { |
| 763 | Register reg = static_cast<Register>(MostSignificantBit(mask)); |
| 764 | mask ^= 1u << reg; |
| 765 | ofs -= kMipsWordSize; |
| 766 | // The ZERO register is only included for alignment. |
| 767 | if (reg != ZERO) { |
| 768 | __ LoadFromOffset(kLoadWord, reg, SP, ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 769 | __ cfi().Restore(DWARFReg(reg)); |
| 770 | } |
| 771 | } |
| 772 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 773 | for (uint32_t mask = fpu_spill_mask_; mask != 0; ) { |
| 774 | FRegister reg = static_cast<FRegister>(MostSignificantBit(mask)); |
| 775 | mask ^= 1u << reg; |
| 776 | ofs -= kMipsDoublewordSize; |
| 777 | __ LoadDFromOffset(reg, SP, ofs); |
| 778 | // TODO: __ cfi().Restore(DWARFReg(reg)); |
| 779 | } |
| 780 | |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 781 | size_t frame_size = GetFrameSize(); |
| 782 | // Adjust the stack pointer in the delay slot if doing so doesn't break CFI. |
| 783 | bool exchange = IsInt<16>(static_cast<int32_t>(frame_size)); |
| 784 | bool reordering = __ SetReorder(false); |
| 785 | if (exchange) { |
| 786 | __ Jr(RA); |
| 787 | __ DecreaseFrameSize(frame_size); // Single instruction in delay slot. |
| 788 | } else { |
| 789 | __ DecreaseFrameSize(frame_size); |
| 790 | __ Jr(RA); |
| 791 | __ Nop(); // In delay slot. |
| 792 | } |
| 793 | __ SetReorder(reordering); |
| 794 | } else { |
| 795 | __ Jr(RA); |
| 796 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 797 | } |
| 798 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 799 | __ cfi().RestoreState(); |
| 800 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 801 | } |
| 802 | |
| 803 | void CodeGeneratorMIPS::Bind(HBasicBlock* block) { |
| 804 | __ Bind(GetLabelOf(block)); |
| 805 | } |
| 806 | |
| 807 | void CodeGeneratorMIPS::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
| 808 | if (src.Equals(dst)) { |
| 809 | return; |
| 810 | } |
| 811 | |
| 812 | if (src.IsConstant()) { |
| 813 | MoveConstant(dst, src.GetConstant()); |
| 814 | } else { |
| 815 | if (Primitive::Is64BitType(dst_type)) { |
| 816 | Move64(dst, src); |
| 817 | } else { |
| 818 | Move32(dst, src); |
| 819 | } |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | void CodeGeneratorMIPS::Move32(Location destination, Location source) { |
| 824 | if (source.Equals(destination)) { |
| 825 | return; |
| 826 | } |
| 827 | |
| 828 | if (destination.IsRegister()) { |
| 829 | if (source.IsRegister()) { |
| 830 | __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 831 | } else if (source.IsFpuRegister()) { |
| 832 | __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>()); |
| 833 | } else { |
| 834 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 835 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
| 836 | } |
| 837 | } else if (destination.IsFpuRegister()) { |
| 838 | if (source.IsRegister()) { |
| 839 | __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>()); |
| 840 | } else if (source.IsFpuRegister()) { |
| 841 | __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 842 | } else { |
| 843 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 844 | __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 845 | } |
| 846 | } else { |
| 847 | DCHECK(destination.IsStackSlot()) << destination; |
| 848 | if (source.IsRegister()) { |
| 849 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
| 850 | } else if (source.IsFpuRegister()) { |
| 851 | __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex()); |
| 852 | } else { |
| 853 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 854 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 855 | __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex()); |
| 856 | } |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | void CodeGeneratorMIPS::Move64(Location destination, Location source) { |
| 861 | if (source.Equals(destination)) { |
| 862 | return; |
| 863 | } |
| 864 | |
| 865 | if (destination.IsRegisterPair()) { |
| 866 | if (source.IsRegisterPair()) { |
| 867 | __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 868 | __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 869 | } else if (source.IsFpuRegister()) { |
| 870 | Register dst_high = destination.AsRegisterPairHigh<Register>(); |
| 871 | Register dst_low = destination.AsRegisterPairLow<Register>(); |
| 872 | FRegister src = source.AsFpuRegister<FRegister>(); |
| 873 | __ Mfc1(dst_low, src); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 874 | __ MoveFromFpuHigh(dst_high, src); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 875 | } else { |
| 876 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 877 | int32_t off = source.GetStackIndex(); |
| 878 | Register r = destination.AsRegisterPairLow<Register>(); |
| 879 | __ LoadFromOffset(kLoadDoubleword, r, SP, off); |
| 880 | } |
| 881 | } else if (destination.IsFpuRegister()) { |
| 882 | if (source.IsRegisterPair()) { |
| 883 | FRegister dst = destination.AsFpuRegister<FRegister>(); |
| 884 | Register src_high = source.AsRegisterPairHigh<Register>(); |
| 885 | Register src_low = source.AsRegisterPairLow<Register>(); |
| 886 | __ Mtc1(src_low, dst); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 887 | __ MoveToFpuHigh(src_high, dst); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 888 | } else if (source.IsFpuRegister()) { |
| 889 | __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 890 | } else { |
| 891 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 892 | __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 893 | } |
| 894 | } else { |
| 895 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 896 | int32_t off = destination.GetStackIndex(); |
| 897 | if (source.IsRegisterPair()) { |
| 898 | __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, off); |
| 899 | } else if (source.IsFpuRegister()) { |
| 900 | __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, off); |
| 901 | } else { |
| 902 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 903 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 904 | __ StoreToOffset(kStoreWord, TMP, SP, off); |
| 905 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4); |
| 906 | __ StoreToOffset(kStoreWord, TMP, SP, off + 4); |
| 907 | } |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) { |
| 912 | if (c->IsIntConstant() || c->IsNullConstant()) { |
| 913 | // Move 32 bit constant. |
| 914 | int32_t value = GetInt32ValueOf(c); |
| 915 | if (destination.IsRegister()) { |
| 916 | Register dst = destination.AsRegister<Register>(); |
| 917 | __ LoadConst32(dst, value); |
| 918 | } else { |
| 919 | DCHECK(destination.IsStackSlot()) |
| 920 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 921 | __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 922 | } |
| 923 | } else if (c->IsLongConstant()) { |
| 924 | // Move 64 bit constant. |
| 925 | int64_t value = GetInt64ValueOf(c); |
| 926 | if (destination.IsRegisterPair()) { |
| 927 | Register r_h = destination.AsRegisterPairHigh<Register>(); |
| 928 | Register r_l = destination.AsRegisterPairLow<Register>(); |
| 929 | __ LoadConst64(r_h, r_l, value); |
| 930 | } else { |
| 931 | DCHECK(destination.IsDoubleStackSlot()) |
| 932 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 933 | __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 934 | } |
| 935 | } else if (c->IsFloatConstant()) { |
| 936 | // Move 32 bit float constant. |
| 937 | int32_t value = GetInt32ValueOf(c); |
| 938 | if (destination.IsFpuRegister()) { |
| 939 | __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP); |
| 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 { |
| 946 | // Move 64 bit double constant. |
| 947 | DCHECK(c->IsDoubleConstant()) << c->DebugName(); |
| 948 | int64_t value = GetInt64ValueOf(c); |
| 949 | if (destination.IsFpuRegister()) { |
| 950 | FRegister fd = destination.AsFpuRegister<FRegister>(); |
| 951 | __ LoadDConst64(fd, value, TMP); |
| 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 | } |
| 958 | } |
| 959 | |
| 960 | void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) { |
| 961 | DCHECK(destination.IsRegister()); |
| 962 | Register dst = destination.AsRegister<Register>(); |
| 963 | __ LoadConst32(dst, value); |
| 964 | } |
| 965 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 966 | void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 967 | if (location.IsRegister()) { |
| 968 | locations->AddTemp(location); |
Alexey Frunze | c9e94f3 | 2015-10-26 16:11:39 -0700 | [diff] [blame] | 969 | } else if (location.IsRegisterPair()) { |
| 970 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 971 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 972 | } else { |
| 973 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 974 | } |
| 975 | } |
| 976 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 977 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 978 | inline void CodeGeneratorMIPS::EmitPcRelativeLinkerPatches( |
| 979 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 980 | ArenaVector<LinkerPatch>* linker_patches) { |
| 981 | for (const PcRelativePatchInfo& info : infos) { |
| 982 | const DexFile& dex_file = info.target_dex_file; |
| 983 | size_t offset_or_index = info.offset_or_index; |
| 984 | DCHECK(info.high_label.IsBound()); |
| 985 | uint32_t high_offset = __ GetLabelLocation(&info.high_label); |
| 986 | // On R2 we use HMipsComputeBaseMethodAddress and patch relative to |
| 987 | // the assembler's base label used for PC-relative addressing. |
| 988 | uint32_t pc_rel_offset = info.pc_rel_label.IsBound() |
| 989 | ? __ GetLabelLocation(&info.pc_rel_label) |
| 990 | : __ GetPcRelBaseLabelLocation(); |
| 991 | linker_patches->push_back(Factory(high_offset, &dex_file, pc_rel_offset, offset_or_index)); |
| 992 | } |
| 993 | } |
| 994 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 995 | void CodeGeneratorMIPS::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 996 | DCHECK(linker_patches->empty()); |
| 997 | size_t size = |
| 998 | method_patches_.size() + |
| 999 | call_patches_.size() + |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1000 | pc_relative_dex_cache_patches_.size() + |
| 1001 | pc_relative_string_patches_.size() + |
| 1002 | pc_relative_type_patches_.size() + |
| 1003 | boot_image_string_patches_.size() + |
| 1004 | boot_image_type_patches_.size() + |
| 1005 | boot_image_address_patches_.size(); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1006 | linker_patches->reserve(size); |
| 1007 | for (const auto& entry : method_patches_) { |
| 1008 | const MethodReference& target_method = entry.first; |
| 1009 | Literal* literal = entry.second; |
| 1010 | DCHECK(literal->GetLabel()->IsBound()); |
| 1011 | uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel()); |
| 1012 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 1013 | target_method.dex_file, |
| 1014 | target_method.dex_method_index)); |
| 1015 | } |
| 1016 | for (const auto& entry : call_patches_) { |
| 1017 | const MethodReference& target_method = entry.first; |
| 1018 | Literal* literal = entry.second; |
| 1019 | DCHECK(literal->GetLabel()->IsBound()); |
| 1020 | uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel()); |
| 1021 | linker_patches->push_back(LinkerPatch::CodePatch(literal_offset, |
| 1022 | target_method.dex_file, |
| 1023 | target_method.dex_method_index)); |
| 1024 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1025 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 1026 | linker_patches); |
| 1027 | if (!GetCompilerOptions().IsBootImage()) { |
| 1028 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 1029 | linker_patches); |
| 1030 | } else { |
| 1031 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 1032 | linker_patches); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1033 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1034 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 1035 | linker_patches); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1036 | for (const auto& entry : boot_image_string_patches_) { |
| 1037 | const StringReference& target_string = entry.first; |
| 1038 | Literal* literal = entry.second; |
| 1039 | DCHECK(literal->GetLabel()->IsBound()); |
| 1040 | uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel()); |
| 1041 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 1042 | target_string.dex_file, |
| 1043 | target_string.string_index)); |
| 1044 | } |
| 1045 | for (const auto& entry : boot_image_type_patches_) { |
| 1046 | const TypeReference& target_type = entry.first; |
| 1047 | Literal* literal = entry.second; |
| 1048 | DCHECK(literal->GetLabel()->IsBound()); |
| 1049 | uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel()); |
| 1050 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 1051 | target_type.dex_file, |
| 1052 | target_type.type_index)); |
| 1053 | } |
| 1054 | for (const auto& entry : boot_image_address_patches_) { |
| 1055 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
| 1056 | Literal* literal = entry.second; |
| 1057 | DCHECK(literal->GetLabel()->IsBound()); |
| 1058 | uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel()); |
| 1059 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeStringPatch( |
| 1064 | const DexFile& dex_file, uint32_t string_index) { |
| 1065 | return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_); |
| 1066 | } |
| 1067 | |
| 1068 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeTypePatch( |
| 1069 | const DexFile& dex_file, uint32_t type_index) { |
| 1070 | return NewPcRelativePatch(dex_file, type_index, &pc_relative_type_patches_); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeDexCacheArrayPatch( |
| 1074 | const DexFile& dex_file, uint32_t element_offset) { |
| 1075 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 1076 | } |
| 1077 | |
| 1078 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativePatch( |
| 1079 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 1080 | patches->emplace_back(dex_file, offset_or_index); |
| 1081 | return &patches->back(); |
| 1082 | } |
| 1083 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1084 | Literal* CodeGeneratorMIPS::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 1085 | return map->GetOrCreate( |
| 1086 | value, |
| 1087 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
| 1088 | } |
| 1089 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1090 | Literal* CodeGeneratorMIPS::DeduplicateMethodLiteral(MethodReference target_method, |
| 1091 | MethodToLiteralMap* map) { |
| 1092 | return map->GetOrCreate( |
| 1093 | target_method, |
| 1094 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1095 | } |
| 1096 | |
| 1097 | Literal* CodeGeneratorMIPS::DeduplicateMethodAddressLiteral(MethodReference target_method) { |
| 1098 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 1099 | } |
| 1100 | |
| 1101 | Literal* CodeGeneratorMIPS::DeduplicateMethodCodeLiteral(MethodReference target_method) { |
| 1102 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 1103 | } |
| 1104 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1105 | Literal* CodeGeneratorMIPS::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
| 1106 | uint32_t string_index) { |
| 1107 | return boot_image_string_patches_.GetOrCreate( |
| 1108 | StringReference(&dex_file, string_index), |
| 1109 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1110 | } |
| 1111 | |
| 1112 | Literal* CodeGeneratorMIPS::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
| 1113 | uint32_t type_index) { |
| 1114 | return boot_image_type_patches_.GetOrCreate( |
| 1115 | TypeReference(&dex_file, type_index), |
| 1116 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1117 | } |
| 1118 | |
| 1119 | Literal* CodeGeneratorMIPS::DeduplicateBootImageAddressLiteral(uint32_t address) { |
| 1120 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 1121 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 1122 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 1123 | } |
| 1124 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1125 | void CodeGeneratorMIPS::EmitPcRelativeAddressPlaceholder( |
| 1126 | PcRelativePatchInfo* info, Register out, Register base) { |
| 1127 | bool reordering = __ SetReorder(false); |
| 1128 | if (GetInstructionSetFeatures().IsR6()) { |
| 1129 | DCHECK_EQ(base, ZERO); |
| 1130 | __ Bind(&info->high_label); |
| 1131 | __ Bind(&info->pc_rel_label); |
| 1132 | // Add a 32-bit offset to PC. |
| 1133 | __ Auipc(out, /* placeholder */ 0x1234); |
| 1134 | __ Addiu(out, out, /* placeholder */ 0x5678); |
| 1135 | } else { |
| 1136 | // If base is ZERO, emit NAL to obtain the actual base. |
| 1137 | if (base == ZERO) { |
| 1138 | // Generate a dummy PC-relative call to obtain PC. |
| 1139 | __ Nal(); |
| 1140 | } |
| 1141 | __ Bind(&info->high_label); |
| 1142 | __ Lui(out, /* placeholder */ 0x1234); |
| 1143 | // If we emitted the NAL, bind the pc_rel_label, otherwise base is a register holding |
| 1144 | // the HMipsComputeBaseMethodAddress which has its own label stored in MipsAssembler. |
| 1145 | if (base == ZERO) { |
| 1146 | __ Bind(&info->pc_rel_label); |
| 1147 | } |
| 1148 | __ Ori(out, out, /* placeholder */ 0x5678); |
| 1149 | // Add a 32-bit offset to PC. |
| 1150 | __ Addu(out, out, (base == ZERO) ? RA : base); |
| 1151 | } |
| 1152 | __ SetReorder(reordering); |
| 1153 | } |
| 1154 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1155 | void CodeGeneratorMIPS::MarkGCCard(Register object, Register value) { |
| 1156 | MipsLabel done; |
| 1157 | Register card = AT; |
| 1158 | Register temp = TMP; |
| 1159 | __ Beqz(value, &done); |
| 1160 | __ LoadFromOffset(kLoadWord, |
| 1161 | card, |
| 1162 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1163 | Thread::CardTableOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1164 | __ Srl(temp, object, gc::accounting::CardTable::kCardShift); |
| 1165 | __ Addu(temp, card, temp); |
| 1166 | __ Sb(card, temp, 0); |
| 1167 | __ Bind(&done); |
| 1168 | } |
| 1169 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1170 | void CodeGeneratorMIPS::SetupBlockedRegisters() const { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1171 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1172 | blocked_core_registers_[ZERO] = true; |
| 1173 | blocked_core_registers_[K0] = true; |
| 1174 | blocked_core_registers_[K1] = true; |
| 1175 | blocked_core_registers_[GP] = true; |
| 1176 | blocked_core_registers_[SP] = true; |
| 1177 | blocked_core_registers_[RA] = true; |
| 1178 | |
| 1179 | // AT and TMP(T8) are used as temporary/scratch registers |
| 1180 | // (similar to how AT is used by MIPS assemblers). |
| 1181 | blocked_core_registers_[AT] = true; |
| 1182 | blocked_core_registers_[TMP] = true; |
| 1183 | blocked_fpu_registers_[FTMP] = true; |
| 1184 | |
| 1185 | // Reserve suspend and thread registers. |
| 1186 | blocked_core_registers_[S0] = true; |
| 1187 | blocked_core_registers_[TR] = true; |
| 1188 | |
| 1189 | // Reserve T9 for function calls |
| 1190 | blocked_core_registers_[T9] = true; |
| 1191 | |
| 1192 | // Reserve odd-numbered FPU registers. |
| 1193 | for (size_t i = 1; i < kNumberOfFRegisters; i += 2) { |
| 1194 | blocked_fpu_registers_[i] = true; |
| 1195 | } |
| 1196 | |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 1197 | if (GetGraph()->IsDebuggable()) { |
| 1198 | // Stubs do not save callee-save floating point registers. If the graph |
| 1199 | // is debuggable, we need to deal with these registers differently. For |
| 1200 | // now, just block them. |
| 1201 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1202 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1203 | } |
| 1204 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1205 | } |
| 1206 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1207 | size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1208 | __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index); |
| 1209 | return kMipsWordSize; |
| 1210 | } |
| 1211 | |
| 1212 | size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1213 | __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index); |
| 1214 | return kMipsWordSize; |
| 1215 | } |
| 1216 | |
| 1217 | size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1218 | __ StoreDToOffset(FRegister(reg_id), SP, stack_index); |
| 1219 | return kMipsDoublewordSize; |
| 1220 | } |
| 1221 | |
| 1222 | size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1223 | __ LoadDFromOffset(FRegister(reg_id), SP, stack_index); |
| 1224 | return kMipsDoublewordSize; |
| 1225 | } |
| 1226 | |
| 1227 | void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1228 | stream << Register(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1232 | stream << FRegister(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1233 | } |
| 1234 | |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1235 | constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16; |
| 1236 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1237 | void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1238 | HInstruction* instruction, |
| 1239 | uint32_t dex_pc, |
| 1240 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1241 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1242 | bool reordering = __ SetReorder(false); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1243 | __ LoadFromOffset(kLoadWord, T9, TR, GetThreadOffset<kMipsPointerSize>(entrypoint).Int32Value()); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1244 | __ Jalr(T9); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1245 | if (IsDirectEntrypoint(entrypoint)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1246 | // Reserve argument space on stack (for $a0-$a3) for |
| 1247 | // entrypoints that directly reference native implementations. |
| 1248 | // Called function may use this space to store $a0-$a3 regs. |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1249 | __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1250 | __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1251 | } else { |
| 1252 | __ Nop(); // In delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1253 | } |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1254 | __ SetReorder(reordering); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1255 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1256 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1257 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path, |
| 1261 | Register class_reg) { |
| 1262 | __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 1263 | __ LoadConst32(AT, mirror::Class::kStatusInitialized); |
| 1264 | __ Blt(TMP, AT, slow_path->GetEntryLabel()); |
| 1265 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 1266 | __ Sync(0); |
| 1267 | __ Bind(slow_path->GetExitLabel()); |
| 1268 | } |
| 1269 | |
| 1270 | void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1271 | __ Sync(0); // Only stype 0 is supported. |
| 1272 | } |
| 1273 | |
| 1274 | void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1275 | HBasicBlock* successor) { |
| 1276 | SuspendCheckSlowPathMIPS* slow_path = |
| 1277 | new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS(instruction, successor); |
| 1278 | codegen_->AddSlowPath(slow_path); |
| 1279 | |
| 1280 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1281 | TMP, |
| 1282 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1283 | Thread::ThreadFlagsOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1284 | if (successor == nullptr) { |
| 1285 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
| 1286 | __ Bind(slow_path->GetReturnLabel()); |
| 1287 | } else { |
| 1288 | __ Beqz(TMP, codegen_->GetLabelOf(successor)); |
| 1289 | __ B(slow_path->GetEntryLabel()); |
| 1290 | // slow_path will return to GetLabelOf(successor). |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph, |
| 1295 | CodeGeneratorMIPS* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1296 | : InstructionCodeGenerator(graph, codegen), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1297 | assembler_(codegen->GetAssembler()), |
| 1298 | codegen_(codegen) {} |
| 1299 | |
| 1300 | void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1301 | DCHECK_EQ(instruction->InputCount(), 2U); |
| 1302 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1303 | Primitive::Type type = instruction->GetResultType(); |
| 1304 | switch (type) { |
| 1305 | case Primitive::kPrimInt: { |
| 1306 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1307 | HInstruction* right = instruction->InputAt(1); |
| 1308 | bool can_use_imm = false; |
| 1309 | if (right->IsConstant()) { |
| 1310 | int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant()); |
| 1311 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 1312 | can_use_imm = IsUint<16>(imm); |
| 1313 | } else if (instruction->IsAdd()) { |
| 1314 | can_use_imm = IsInt<16>(imm); |
| 1315 | } else { |
| 1316 | DCHECK(instruction->IsSub()); |
| 1317 | can_use_imm = IsInt<16>(-imm); |
| 1318 | } |
| 1319 | } |
| 1320 | if (can_use_imm) |
| 1321 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 1322 | else |
| 1323 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1324 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1325 | break; |
| 1326 | } |
| 1327 | |
| 1328 | case Primitive::kPrimLong: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1329 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1330 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1331 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1332 | break; |
| 1333 | } |
| 1334 | |
| 1335 | case Primitive::kPrimFloat: |
| 1336 | case Primitive::kPrimDouble: |
| 1337 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 1338 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1339 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1340 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1341 | break; |
| 1342 | |
| 1343 | default: |
| 1344 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1349 | Primitive::Type type = instruction->GetType(); |
| 1350 | LocationSummary* locations = instruction->GetLocations(); |
| 1351 | |
| 1352 | switch (type) { |
| 1353 | case Primitive::kPrimInt: { |
| 1354 | Register dst = locations->Out().AsRegister<Register>(); |
| 1355 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 1356 | Location rhs_location = locations->InAt(1); |
| 1357 | |
| 1358 | Register rhs_reg = ZERO; |
| 1359 | int32_t rhs_imm = 0; |
| 1360 | bool use_imm = rhs_location.IsConstant(); |
| 1361 | if (use_imm) { |
| 1362 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 1363 | } else { |
| 1364 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 1365 | } |
| 1366 | |
| 1367 | if (instruction->IsAnd()) { |
| 1368 | if (use_imm) |
| 1369 | __ Andi(dst, lhs, rhs_imm); |
| 1370 | else |
| 1371 | __ And(dst, lhs, rhs_reg); |
| 1372 | } else if (instruction->IsOr()) { |
| 1373 | if (use_imm) |
| 1374 | __ Ori(dst, lhs, rhs_imm); |
| 1375 | else |
| 1376 | __ Or(dst, lhs, rhs_reg); |
| 1377 | } else if (instruction->IsXor()) { |
| 1378 | if (use_imm) |
| 1379 | __ Xori(dst, lhs, rhs_imm); |
| 1380 | else |
| 1381 | __ Xor(dst, lhs, rhs_reg); |
| 1382 | } else if (instruction->IsAdd()) { |
| 1383 | if (use_imm) |
| 1384 | __ Addiu(dst, lhs, rhs_imm); |
| 1385 | else |
| 1386 | __ Addu(dst, lhs, rhs_reg); |
| 1387 | } else { |
| 1388 | DCHECK(instruction->IsSub()); |
| 1389 | if (use_imm) |
| 1390 | __ Addiu(dst, lhs, -rhs_imm); |
| 1391 | else |
| 1392 | __ Subu(dst, lhs, rhs_reg); |
| 1393 | } |
| 1394 | break; |
| 1395 | } |
| 1396 | |
| 1397 | case Primitive::kPrimLong: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1398 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 1399 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 1400 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 1401 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1402 | Location rhs_location = locations->InAt(1); |
| 1403 | bool use_imm = rhs_location.IsConstant(); |
| 1404 | if (!use_imm) { |
| 1405 | Register rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 1406 | Register rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 1407 | if (instruction->IsAnd()) { |
| 1408 | __ And(dst_low, lhs_low, rhs_low); |
| 1409 | __ And(dst_high, lhs_high, rhs_high); |
| 1410 | } else if (instruction->IsOr()) { |
| 1411 | __ Or(dst_low, lhs_low, rhs_low); |
| 1412 | __ Or(dst_high, lhs_high, rhs_high); |
| 1413 | } else if (instruction->IsXor()) { |
| 1414 | __ Xor(dst_low, lhs_low, rhs_low); |
| 1415 | __ Xor(dst_high, lhs_high, rhs_high); |
| 1416 | } else if (instruction->IsAdd()) { |
| 1417 | if (lhs_low == rhs_low) { |
| 1418 | // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs. |
| 1419 | __ Slt(TMP, lhs_low, ZERO); |
| 1420 | __ Addu(dst_low, lhs_low, rhs_low); |
| 1421 | } else { |
| 1422 | __ Addu(dst_low, lhs_low, rhs_low); |
| 1423 | // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged. |
| 1424 | __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low); |
| 1425 | } |
| 1426 | __ Addu(dst_high, lhs_high, rhs_high); |
| 1427 | __ Addu(dst_high, dst_high, TMP); |
| 1428 | } else { |
| 1429 | DCHECK(instruction->IsSub()); |
| 1430 | __ Sltu(TMP, lhs_low, rhs_low); |
| 1431 | __ Subu(dst_low, lhs_low, rhs_low); |
| 1432 | __ Subu(dst_high, lhs_high, rhs_high); |
| 1433 | __ Subu(dst_high, dst_high, TMP); |
| 1434 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1435 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1436 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 1437 | if (instruction->IsOr()) { |
| 1438 | uint32_t low = Low32Bits(value); |
| 1439 | uint32_t high = High32Bits(value); |
| 1440 | if (IsUint<16>(low)) { |
| 1441 | if (dst_low != lhs_low || low != 0) { |
| 1442 | __ Ori(dst_low, lhs_low, low); |
| 1443 | } |
| 1444 | } else { |
| 1445 | __ LoadConst32(TMP, low); |
| 1446 | __ Or(dst_low, lhs_low, TMP); |
| 1447 | } |
| 1448 | if (IsUint<16>(high)) { |
| 1449 | if (dst_high != lhs_high || high != 0) { |
| 1450 | __ Ori(dst_high, lhs_high, high); |
| 1451 | } |
| 1452 | } else { |
| 1453 | if (high != low) { |
| 1454 | __ LoadConst32(TMP, high); |
| 1455 | } |
| 1456 | __ Or(dst_high, lhs_high, TMP); |
| 1457 | } |
| 1458 | } else if (instruction->IsXor()) { |
| 1459 | uint32_t low = Low32Bits(value); |
| 1460 | uint32_t high = High32Bits(value); |
| 1461 | if (IsUint<16>(low)) { |
| 1462 | if (dst_low != lhs_low || low != 0) { |
| 1463 | __ Xori(dst_low, lhs_low, low); |
| 1464 | } |
| 1465 | } else { |
| 1466 | __ LoadConst32(TMP, low); |
| 1467 | __ Xor(dst_low, lhs_low, TMP); |
| 1468 | } |
| 1469 | if (IsUint<16>(high)) { |
| 1470 | if (dst_high != lhs_high || high != 0) { |
| 1471 | __ Xori(dst_high, lhs_high, high); |
| 1472 | } |
| 1473 | } else { |
| 1474 | if (high != low) { |
| 1475 | __ LoadConst32(TMP, high); |
| 1476 | } |
| 1477 | __ Xor(dst_high, lhs_high, TMP); |
| 1478 | } |
| 1479 | } else if (instruction->IsAnd()) { |
| 1480 | uint32_t low = Low32Bits(value); |
| 1481 | uint32_t high = High32Bits(value); |
| 1482 | if (IsUint<16>(low)) { |
| 1483 | __ Andi(dst_low, lhs_low, low); |
| 1484 | } else if (low != 0xFFFFFFFF) { |
| 1485 | __ LoadConst32(TMP, low); |
| 1486 | __ And(dst_low, lhs_low, TMP); |
| 1487 | } else if (dst_low != lhs_low) { |
| 1488 | __ Move(dst_low, lhs_low); |
| 1489 | } |
| 1490 | if (IsUint<16>(high)) { |
| 1491 | __ Andi(dst_high, lhs_high, high); |
| 1492 | } else if (high != 0xFFFFFFFF) { |
| 1493 | if (high != low) { |
| 1494 | __ LoadConst32(TMP, high); |
| 1495 | } |
| 1496 | __ And(dst_high, lhs_high, TMP); |
| 1497 | } else if (dst_high != lhs_high) { |
| 1498 | __ Move(dst_high, lhs_high); |
| 1499 | } |
| 1500 | } else { |
| 1501 | if (instruction->IsSub()) { |
| 1502 | value = -value; |
| 1503 | } else { |
| 1504 | DCHECK(instruction->IsAdd()); |
| 1505 | } |
| 1506 | int32_t low = Low32Bits(value); |
| 1507 | int32_t high = High32Bits(value); |
| 1508 | if (IsInt<16>(low)) { |
| 1509 | if (dst_low != lhs_low || low != 0) { |
| 1510 | __ Addiu(dst_low, lhs_low, low); |
| 1511 | } |
| 1512 | if (low != 0) { |
| 1513 | __ Sltiu(AT, dst_low, low); |
| 1514 | } |
| 1515 | } else { |
| 1516 | __ LoadConst32(TMP, low); |
| 1517 | __ Addu(dst_low, lhs_low, TMP); |
| 1518 | __ Sltu(AT, dst_low, TMP); |
| 1519 | } |
| 1520 | if (IsInt<16>(high)) { |
| 1521 | if (dst_high != lhs_high || high != 0) { |
| 1522 | __ Addiu(dst_high, lhs_high, high); |
| 1523 | } |
| 1524 | } else { |
| 1525 | if (high != low) { |
| 1526 | __ LoadConst32(TMP, high); |
| 1527 | } |
| 1528 | __ Addu(dst_high, lhs_high, TMP); |
| 1529 | } |
| 1530 | if (low != 0) { |
| 1531 | __ Addu(dst_high, dst_high, AT); |
| 1532 | } |
| 1533 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1534 | } |
| 1535 | break; |
| 1536 | } |
| 1537 | |
| 1538 | case Primitive::kPrimFloat: |
| 1539 | case Primitive::kPrimDouble: { |
| 1540 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 1541 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 1542 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 1543 | if (instruction->IsAdd()) { |
| 1544 | if (type == Primitive::kPrimFloat) { |
| 1545 | __ AddS(dst, lhs, rhs); |
| 1546 | } else { |
| 1547 | __ AddD(dst, lhs, rhs); |
| 1548 | } |
| 1549 | } else { |
| 1550 | DCHECK(instruction->IsSub()); |
| 1551 | if (type == Primitive::kPrimFloat) { |
| 1552 | __ SubS(dst, lhs, rhs); |
| 1553 | } else { |
| 1554 | __ SubD(dst, lhs, rhs); |
| 1555 | } |
| 1556 | } |
| 1557 | break; |
| 1558 | } |
| 1559 | |
| 1560 | default: |
| 1561 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 1562 | } |
| 1563 | } |
| 1564 | |
| 1565 | void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1566 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1567 | |
| 1568 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1569 | Primitive::Type type = instr->GetResultType(); |
| 1570 | switch (type) { |
| 1571 | case Primitive::kPrimInt: |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1572 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1573 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 1574 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1575 | break; |
| 1576 | case Primitive::kPrimLong: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1577 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1578 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 1579 | locations->SetOut(Location::RequiresRegister()); |
| 1580 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1581 | default: |
| 1582 | LOG(FATAL) << "Unexpected shift type " << type; |
| 1583 | } |
| 1584 | } |
| 1585 | |
| 1586 | static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte; |
| 1587 | |
| 1588 | void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1589 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1590 | LocationSummary* locations = instr->GetLocations(); |
| 1591 | Primitive::Type type = instr->GetType(); |
| 1592 | |
| 1593 | Location rhs_location = locations->InAt(1); |
| 1594 | bool use_imm = rhs_location.IsConstant(); |
| 1595 | Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>(); |
| 1596 | int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 1597 | const uint32_t shift_mask = |
| 1598 | (type == Primitive::kPrimInt) ? kMaxIntShiftDistance : kMaxLongShiftDistance; |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1599 | const uint32_t shift_value = rhs_imm & shift_mask; |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1600 | // Are the INS (Insert Bit Field) and ROTR instructions supported? |
| 1601 | bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1602 | |
| 1603 | switch (type) { |
| 1604 | case Primitive::kPrimInt: { |
| 1605 | Register dst = locations->Out().AsRegister<Register>(); |
| 1606 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 1607 | if (use_imm) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1608 | if (shift_value == 0) { |
| 1609 | if (dst != lhs) { |
| 1610 | __ Move(dst, lhs); |
| 1611 | } |
| 1612 | } else if (instr->IsShl()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1613 | __ Sll(dst, lhs, shift_value); |
| 1614 | } else if (instr->IsShr()) { |
| 1615 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1616 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1617 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1618 | } else { |
| 1619 | if (has_ins_rotr) { |
| 1620 | __ Rotr(dst, lhs, shift_value); |
| 1621 | } else { |
| 1622 | __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask); |
| 1623 | __ Srl(dst, lhs, shift_value); |
| 1624 | __ Or(dst, dst, TMP); |
| 1625 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1626 | } |
| 1627 | } else { |
| 1628 | if (instr->IsShl()) { |
| 1629 | __ Sllv(dst, lhs, rhs_reg); |
| 1630 | } else if (instr->IsShr()) { |
| 1631 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1632 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1633 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1634 | } else { |
| 1635 | if (has_ins_rotr) { |
| 1636 | __ Rotrv(dst, lhs, rhs_reg); |
| 1637 | } else { |
| 1638 | __ Subu(TMP, ZERO, rhs_reg); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1639 | // 32-bit shift instructions use the 5 least significant bits of the shift count, so |
| 1640 | // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case |
| 1641 | // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out |
| 1642 | // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`, |
| 1643 | // IOW, the OR'd values are equal. |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1644 | __ Sllv(TMP, lhs, TMP); |
| 1645 | __ Srlv(dst, lhs, rhs_reg); |
| 1646 | __ Or(dst, dst, TMP); |
| 1647 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1648 | } |
| 1649 | } |
| 1650 | break; |
| 1651 | } |
| 1652 | |
| 1653 | case Primitive::kPrimLong: { |
| 1654 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 1655 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 1656 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 1657 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 1658 | if (use_imm) { |
| 1659 | if (shift_value == 0) { |
| 1660 | codegen_->Move64(locations->Out(), locations->InAt(0)); |
| 1661 | } else if (shift_value < kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1662 | if (has_ins_rotr) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1663 | if (instr->IsShl()) { |
| 1664 | __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 1665 | __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value); |
| 1666 | __ Sll(dst_low, lhs_low, shift_value); |
| 1667 | } else if (instr->IsShr()) { |
| 1668 | __ Srl(dst_low, lhs_low, shift_value); |
| 1669 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 1670 | __ Sra(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1671 | } else if (instr->IsUShr()) { |
| 1672 | __ Srl(dst_low, lhs_low, shift_value); |
| 1673 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 1674 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1675 | } else { |
| 1676 | __ Srl(dst_low, lhs_low, shift_value); |
| 1677 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 1678 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1679 | __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1680 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1681 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1682 | if (instr->IsShl()) { |
| 1683 | __ Sll(dst_low, lhs_low, shift_value); |
| 1684 | __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value); |
| 1685 | __ Sll(dst_high, lhs_high, shift_value); |
| 1686 | __ Or(dst_high, dst_high, TMP); |
| 1687 | } else if (instr->IsShr()) { |
| 1688 | __ Sra(dst_high, lhs_high, shift_value); |
| 1689 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 1690 | __ Srl(dst_low, lhs_low, shift_value); |
| 1691 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1692 | } else if (instr->IsUShr()) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1693 | __ Srl(dst_high, lhs_high, shift_value); |
| 1694 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 1695 | __ Srl(dst_low, lhs_low, shift_value); |
| 1696 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1697 | } else { |
| 1698 | __ Srl(TMP, lhs_low, shift_value); |
| 1699 | __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value); |
| 1700 | __ Or(dst_low, dst_low, TMP); |
| 1701 | __ Srl(TMP, lhs_high, shift_value); |
| 1702 | __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 1703 | __ Or(dst_high, dst_high, TMP); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1704 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1705 | } |
| 1706 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1707 | const uint32_t shift_value_high = shift_value - kMipsBitsPerWord; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1708 | if (instr->IsShl()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1709 | __ Sll(dst_high, lhs_low, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1710 | __ Move(dst_low, ZERO); |
| 1711 | } else if (instr->IsShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1712 | __ Sra(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1713 | __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1714 | } else if (instr->IsUShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1715 | __ Srl(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1716 | __ Move(dst_high, ZERO); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1717 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1718 | if (shift_value == kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1719 | // 64-bit rotation by 32 is just a swap. |
| 1720 | __ Move(dst_low, lhs_high); |
| 1721 | __ Move(dst_high, lhs_low); |
| 1722 | } else { |
| 1723 | if (has_ins_rotr) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1724 | __ Srl(dst_low, lhs_high, shift_value_high); |
| 1725 | __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high); |
| 1726 | __ Srl(dst_high, lhs_low, shift_value_high); |
| 1727 | __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1728 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1729 | __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high); |
| 1730 | __ Srl(dst_low, lhs_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1731 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1732 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high); |
| 1733 | __ Srl(dst_high, lhs_low, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1734 | __ Or(dst_high, dst_high, TMP); |
| 1735 | } |
| 1736 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1737 | } |
| 1738 | } |
| 1739 | } else { |
| 1740 | MipsLabel done; |
| 1741 | if (instr->IsShl()) { |
| 1742 | __ Sllv(dst_low, lhs_low, rhs_reg); |
| 1743 | __ Nor(AT, ZERO, rhs_reg); |
| 1744 | __ Srl(TMP, lhs_low, 1); |
| 1745 | __ Srlv(TMP, TMP, AT); |
| 1746 | __ Sllv(dst_high, lhs_high, rhs_reg); |
| 1747 | __ Or(dst_high, dst_high, TMP); |
| 1748 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 1749 | __ Beqz(TMP, &done); |
| 1750 | __ Move(dst_high, dst_low); |
| 1751 | __ Move(dst_low, ZERO); |
| 1752 | } else if (instr->IsShr()) { |
| 1753 | __ Srav(dst_high, lhs_high, rhs_reg); |
| 1754 | __ Nor(AT, ZERO, rhs_reg); |
| 1755 | __ Sll(TMP, lhs_high, 1); |
| 1756 | __ Sllv(TMP, TMP, AT); |
| 1757 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 1758 | __ Or(dst_low, dst_low, TMP); |
| 1759 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 1760 | __ Beqz(TMP, &done); |
| 1761 | __ Move(dst_low, dst_high); |
| 1762 | __ Sra(dst_high, dst_high, 31); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1763 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1764 | __ Srlv(dst_high, lhs_high, rhs_reg); |
| 1765 | __ Nor(AT, ZERO, rhs_reg); |
| 1766 | __ Sll(TMP, lhs_high, 1); |
| 1767 | __ Sllv(TMP, TMP, AT); |
| 1768 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 1769 | __ Or(dst_low, dst_low, TMP); |
| 1770 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 1771 | __ Beqz(TMP, &done); |
| 1772 | __ Move(dst_low, dst_high); |
| 1773 | __ Move(dst_high, ZERO); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1774 | } else { |
| 1775 | __ Nor(AT, ZERO, rhs_reg); |
| 1776 | __ Srlv(TMP, lhs_low, rhs_reg); |
| 1777 | __ Sll(dst_low, lhs_high, 1); |
| 1778 | __ Sllv(dst_low, dst_low, AT); |
| 1779 | __ Or(dst_low, dst_low, TMP); |
| 1780 | __ Srlv(TMP, lhs_high, rhs_reg); |
| 1781 | __ Sll(dst_high, lhs_low, 1); |
| 1782 | __ Sllv(dst_high, dst_high, AT); |
| 1783 | __ Or(dst_high, dst_high, TMP); |
| 1784 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 1785 | __ Beqz(TMP, &done); |
| 1786 | __ Move(TMP, dst_high); |
| 1787 | __ Move(dst_high, dst_low); |
| 1788 | __ Move(dst_low, TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1789 | } |
| 1790 | __ Bind(&done); |
| 1791 | } |
| 1792 | break; |
| 1793 | } |
| 1794 | |
| 1795 | default: |
| 1796 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 1797 | } |
| 1798 | } |
| 1799 | |
| 1800 | void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) { |
| 1801 | HandleBinaryOp(instruction); |
| 1802 | } |
| 1803 | |
| 1804 | void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) { |
| 1805 | HandleBinaryOp(instruction); |
| 1806 | } |
| 1807 | |
| 1808 | void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) { |
| 1809 | HandleBinaryOp(instruction); |
| 1810 | } |
| 1811 | |
| 1812 | void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) { |
| 1813 | HandleBinaryOp(instruction); |
| 1814 | } |
| 1815 | |
| 1816 | void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) { |
| 1817 | LocationSummary* locations = |
| 1818 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1819 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1820 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1821 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 1822 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1823 | } else { |
| 1824 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1825 | } |
| 1826 | } |
| 1827 | |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1828 | auto InstructionCodeGeneratorMIPS::GetImplicitNullChecker(HInstruction* instruction) { |
| 1829 | auto null_checker = [this, instruction]() { |
| 1830 | this->codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1831 | }; |
| 1832 | return null_checker; |
| 1833 | } |
| 1834 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1835 | void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) { |
| 1836 | LocationSummary* locations = instruction->GetLocations(); |
| 1837 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 1838 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 1839 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1840 | auto null_checker = GetImplicitNullChecker(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1841 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 1842 | Primitive::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1843 | switch (type) { |
| 1844 | case Primitive::kPrimBoolean: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1845 | Register out = locations->Out().AsRegister<Register>(); |
| 1846 | if (index.IsConstant()) { |
| 1847 | size_t offset = |
| 1848 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1849 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1850 | } else { |
| 1851 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1852 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1853 | } |
| 1854 | break; |
| 1855 | } |
| 1856 | |
| 1857 | case Primitive::kPrimByte: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1858 | Register out = locations->Out().AsRegister<Register>(); |
| 1859 | if (index.IsConstant()) { |
| 1860 | size_t offset = |
| 1861 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1862 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1863 | } else { |
| 1864 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1865 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1866 | } |
| 1867 | break; |
| 1868 | } |
| 1869 | |
| 1870 | case Primitive::kPrimShort: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1871 | Register out = locations->Out().AsRegister<Register>(); |
| 1872 | if (index.IsConstant()) { |
| 1873 | size_t offset = |
| 1874 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1875 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1876 | } else { |
| 1877 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_2); |
| 1878 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1879 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1880 | } |
| 1881 | break; |
| 1882 | } |
| 1883 | |
| 1884 | case Primitive::kPrimChar: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1885 | Register out = locations->Out().AsRegister<Register>(); |
| 1886 | if (index.IsConstant()) { |
| 1887 | size_t offset = |
| 1888 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1889 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1890 | } else { |
| 1891 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_2); |
| 1892 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1893 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1894 | } |
| 1895 | break; |
| 1896 | } |
| 1897 | |
| 1898 | case Primitive::kPrimInt: |
| 1899 | case Primitive::kPrimNot: { |
| 1900 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1901 | Register out = locations->Out().AsRegister<Register>(); |
| 1902 | if (index.IsConstant()) { |
| 1903 | size_t offset = |
| 1904 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1905 | __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1906 | } else { |
| 1907 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_4); |
| 1908 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1909 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1910 | } |
| 1911 | break; |
| 1912 | } |
| 1913 | |
| 1914 | case Primitive::kPrimLong: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1915 | Register out = locations->Out().AsRegisterPairLow<Register>(); |
| 1916 | if (index.IsConstant()) { |
| 1917 | size_t offset = |
| 1918 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1919 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1920 | } else { |
| 1921 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_8); |
| 1922 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1923 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1924 | } |
| 1925 | break; |
| 1926 | } |
| 1927 | |
| 1928 | case Primitive::kPrimFloat: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1929 | FRegister out = locations->Out().AsFpuRegister<FRegister>(); |
| 1930 | if (index.IsConstant()) { |
| 1931 | size_t offset = |
| 1932 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1933 | __ LoadSFromOffset(out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1934 | } else { |
| 1935 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_4); |
| 1936 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1937 | __ LoadSFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1938 | } |
| 1939 | break; |
| 1940 | } |
| 1941 | |
| 1942 | case Primitive::kPrimDouble: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1943 | FRegister out = locations->Out().AsFpuRegister<FRegister>(); |
| 1944 | if (index.IsConstant()) { |
| 1945 | size_t offset = |
| 1946 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1947 | __ LoadDFromOffset(out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1948 | } else { |
| 1949 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_8); |
| 1950 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1951 | __ LoadDFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1952 | } |
| 1953 | break; |
| 1954 | } |
| 1955 | |
| 1956 | case Primitive::kPrimVoid: |
| 1957 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 1958 | UNREACHABLE(); |
| 1959 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) { |
| 1963 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1964 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1965 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1966 | } |
| 1967 | |
| 1968 | void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) { |
| 1969 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 1970 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1971 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 1972 | Register out = locations->Out().AsRegister<Register>(); |
| 1973 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 1974 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1975 | } |
| 1976 | |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1977 | Location LocationsBuilderMIPS::RegisterOrZeroConstant(HInstruction* instruction) { |
| 1978 | return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern()) |
| 1979 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 1980 | : Location::RequiresRegister(); |
| 1981 | } |
| 1982 | |
| 1983 | Location LocationsBuilderMIPS::FpuRegisterOrConstantForStore(HInstruction* instruction) { |
| 1984 | // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register. |
| 1985 | // We can store a non-zero float or double constant without first loading it into the FPU, |
| 1986 | // but we should only prefer this if the constant has a single use. |
| 1987 | if (instruction->IsConstant() && |
| 1988 | (instruction->AsConstant()->IsZeroBitPattern() || |
| 1989 | instruction->GetUses().HasExactlyOneElement())) { |
| 1990 | return Location::ConstantLocation(instruction->AsConstant()); |
| 1991 | // Otherwise fall through and require an FPU register for the constant. |
| 1992 | } |
| 1993 | return Location::RequiresFpuRegister(); |
| 1994 | } |
| 1995 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1996 | void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) { |
Pavle Batuta | 934808f | 2015-11-03 13:23:54 +0100 | [diff] [blame] | 1997 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1998 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 1999 | instruction, |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2000 | needs_runtime_call ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); |
Pavle Batuta | 934808f | 2015-11-03 13:23:54 +0100 | [diff] [blame] | 2001 | if (needs_runtime_call) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2002 | InvokeRuntimeCallingConvention calling_convention; |
| 2003 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2004 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2005 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 2006 | } else { |
| 2007 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2008 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2009 | if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2010 | locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2011 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2012 | locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2013 | } |
| 2014 | } |
| 2015 | } |
| 2016 | |
| 2017 | void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) { |
| 2018 | LocationSummary* locations = instruction->GetLocations(); |
| 2019 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2020 | Location index = locations->InAt(1); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2021 | Location value_location = locations->InAt(2); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2022 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2023 | bool needs_runtime_call = locations->WillCall(); |
| 2024 | bool needs_write_barrier = |
| 2025 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2026 | auto null_checker = GetImplicitNullChecker(instruction); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2027 | Register base_reg = index.IsConstant() ? obj : TMP; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2028 | |
| 2029 | switch (value_type) { |
| 2030 | case Primitive::kPrimBoolean: |
| 2031 | case Primitive::kPrimByte: { |
| 2032 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2033 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2034 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2035 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2036 | __ Addu(base_reg, obj, index.AsRegister<Register>()); |
| 2037 | } |
| 2038 | if (value_location.IsConstant()) { |
| 2039 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2040 | __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker); |
| 2041 | } else { |
| 2042 | Register value = value_location.AsRegister<Register>(); |
| 2043 | __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2044 | } |
| 2045 | break; |
| 2046 | } |
| 2047 | |
| 2048 | case Primitive::kPrimShort: |
| 2049 | case Primitive::kPrimChar: { |
| 2050 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2051 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2052 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2053 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2054 | __ Sll(base_reg, index.AsRegister<Register>(), TIMES_2); |
| 2055 | __ Addu(base_reg, obj, base_reg); |
| 2056 | } |
| 2057 | if (value_location.IsConstant()) { |
| 2058 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2059 | __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker); |
| 2060 | } else { |
| 2061 | Register value = value_location.AsRegister<Register>(); |
| 2062 | __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2063 | } |
| 2064 | break; |
| 2065 | } |
| 2066 | |
| 2067 | case Primitive::kPrimInt: |
| 2068 | case Primitive::kPrimNot: { |
| 2069 | if (!needs_runtime_call) { |
| 2070 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2071 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2072 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2073 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2074 | __ Sll(base_reg, index.AsRegister<Register>(), TIMES_4); |
| 2075 | __ Addu(base_reg, obj, base_reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2076 | } |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2077 | if (value_location.IsConstant()) { |
| 2078 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2079 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2080 | DCHECK(!needs_write_barrier); |
| 2081 | } else { |
| 2082 | Register value = value_location.AsRegister<Register>(); |
| 2083 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2084 | if (needs_write_barrier) { |
| 2085 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 2086 | codegen_->MarkGCCard(obj, value); |
| 2087 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2088 | } |
| 2089 | } else { |
| 2090 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 2091 | codegen_->InvokeRuntime(kQuickAputObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2092 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 2093 | } |
| 2094 | break; |
| 2095 | } |
| 2096 | |
| 2097 | case Primitive::kPrimLong: { |
| 2098 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2099 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2100 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2101 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2102 | __ Sll(base_reg, index.AsRegister<Register>(), TIMES_8); |
| 2103 | __ Addu(base_reg, obj, base_reg); |
| 2104 | } |
| 2105 | if (value_location.IsConstant()) { |
| 2106 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2107 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2108 | } else { |
| 2109 | Register value = value_location.AsRegisterPairLow<Register>(); |
| 2110 | __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2111 | } |
| 2112 | break; |
| 2113 | } |
| 2114 | |
| 2115 | case Primitive::kPrimFloat: { |
| 2116 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2117 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2118 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2119 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2120 | __ Sll(base_reg, index.AsRegister<Register>(), TIMES_4); |
| 2121 | __ Addu(base_reg, obj, base_reg); |
| 2122 | } |
| 2123 | if (value_location.IsConstant()) { |
| 2124 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2125 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2126 | } else { |
| 2127 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 2128 | __ StoreSToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2129 | } |
| 2130 | break; |
| 2131 | } |
| 2132 | |
| 2133 | case Primitive::kPrimDouble: { |
| 2134 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2135 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2136 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2137 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2138 | __ Sll(base_reg, index.AsRegister<Register>(), TIMES_8); |
| 2139 | __ Addu(base_reg, obj, base_reg); |
| 2140 | } |
| 2141 | if (value_location.IsConstant()) { |
| 2142 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2143 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2144 | } else { |
| 2145 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 2146 | __ StoreDToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2147 | } |
| 2148 | break; |
| 2149 | } |
| 2150 | |
| 2151 | case Primitive::kPrimVoid: |
| 2152 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2153 | UNREACHABLE(); |
| 2154 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2155 | } |
| 2156 | |
| 2157 | void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2158 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2159 | InvokeRuntimeCallingConvention calling_convention; |
| 2160 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2161 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2162 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2163 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2164 | locations->SetInAt(1, Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2165 | } |
| 2166 | |
| 2167 | void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2168 | LocationSummary* locations = instruction->GetLocations(); |
| 2169 | BoundsCheckSlowPathMIPS* slow_path = |
| 2170 | new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS(instruction); |
| 2171 | codegen_->AddSlowPath(slow_path); |
| 2172 | |
| 2173 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 2174 | Register length = locations->InAt(1).AsRegister<Register>(); |
| 2175 | |
| 2176 | // length is limited by the maximum positive signed 32-bit integer. |
| 2177 | // Unsigned comparison of length and index checks for index < 0 |
| 2178 | // and for length <= index simultaneously. |
| 2179 | __ Bgeu(index, length, slow_path->GetEntryLabel()); |
| 2180 | } |
| 2181 | |
| 2182 | void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) { |
| 2183 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2184 | instruction, |
| 2185 | LocationSummary::kCallOnSlowPath); |
| 2186 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2187 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2188 | // Note that TypeCheckSlowPathMIPS uses this register too. |
| 2189 | locations->AddTemp(Location::RequiresRegister()); |
| 2190 | } |
| 2191 | |
| 2192 | void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) { |
| 2193 | LocationSummary* locations = instruction->GetLocations(); |
| 2194 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2195 | Register cls = locations->InAt(1).AsRegister<Register>(); |
| 2196 | Register obj_cls = locations->GetTemp(0).AsRegister<Register>(); |
| 2197 | |
| 2198 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction); |
| 2199 | codegen_->AddSlowPath(slow_path); |
| 2200 | |
| 2201 | // TODO: avoid this check if we know obj is not null. |
| 2202 | __ Beqz(obj, slow_path->GetExitLabel()); |
| 2203 | // Compare the class of `obj` with `cls`. |
| 2204 | __ LoadFromOffset(kLoadWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value()); |
| 2205 | __ Bne(obj_cls, cls, slow_path->GetEntryLabel()); |
| 2206 | __ Bind(slow_path->GetExitLabel()); |
| 2207 | } |
| 2208 | |
| 2209 | void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 2210 | LocationSummary* locations = |
| 2211 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2212 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2213 | if (check->HasUses()) { |
| 2214 | locations->SetOut(Location::SameAsFirstInput()); |
| 2215 | } |
| 2216 | } |
| 2217 | |
| 2218 | void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 2219 | // We assume the class is not null. |
| 2220 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS( |
| 2221 | check->GetLoadClass(), |
| 2222 | check, |
| 2223 | check->GetDexPc(), |
| 2224 | true); |
| 2225 | codegen_->AddSlowPath(slow_path); |
| 2226 | GenerateClassInitializationCheck(slow_path, |
| 2227 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
| 2228 | } |
| 2229 | |
| 2230 | void LocationsBuilderMIPS::VisitCompare(HCompare* compare) { |
| 2231 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 2232 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2233 | LocationSummary* locations = |
| 2234 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2235 | |
| 2236 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2237 | case Primitive::kPrimBoolean: |
| 2238 | case Primitive::kPrimByte: |
| 2239 | case Primitive::kPrimShort: |
| 2240 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2241 | case Primitive::kPrimInt: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 2242 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2243 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2244 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2245 | break; |
| 2246 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2247 | case Primitive::kPrimLong: |
| 2248 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2249 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2250 | // Output overlaps because it is written before doing the low comparison. |
| 2251 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2252 | break; |
| 2253 | |
| 2254 | case Primitive::kPrimFloat: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2255 | case Primitive::kPrimDouble: |
| 2256 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2257 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2258 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2259 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2260 | |
| 2261 | default: |
| 2262 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2263 | } |
| 2264 | } |
| 2265 | |
| 2266 | void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) { |
| 2267 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2268 | Register res = locations->Out().AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2269 | Primitive::Type in_type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2270 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2271 | |
| 2272 | // 0 if: left == right |
| 2273 | // 1 if: left > right |
| 2274 | // -1 if: left < right |
| 2275 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2276 | case Primitive::kPrimBoolean: |
| 2277 | case Primitive::kPrimByte: |
| 2278 | case Primitive::kPrimShort: |
| 2279 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2280 | case Primitive::kPrimInt: { |
| 2281 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2282 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 2283 | __ Slt(TMP, lhs, rhs); |
| 2284 | __ Slt(res, rhs, lhs); |
| 2285 | __ Subu(res, res, TMP); |
| 2286 | break; |
| 2287 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2288 | case Primitive::kPrimLong: { |
| 2289 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2290 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2291 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 2292 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 2293 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 2294 | // TODO: more efficient (direct) comparison with a constant. |
| 2295 | __ Slt(TMP, lhs_high, rhs_high); |
| 2296 | __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt. |
| 2297 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 2298 | __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal. |
| 2299 | __ Sltu(TMP, lhs_low, rhs_low); |
| 2300 | __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt. |
| 2301 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 2302 | __ Bind(&done); |
| 2303 | break; |
| 2304 | } |
| 2305 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2306 | case Primitive::kPrimFloat: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 2307 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2308 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2309 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2310 | MipsLabel done; |
| 2311 | if (isR6) { |
| 2312 | __ CmpEqS(FTMP, lhs, rhs); |
| 2313 | __ LoadConst32(res, 0); |
| 2314 | __ Bc1nez(FTMP, &done); |
| 2315 | if (gt_bias) { |
| 2316 | __ CmpLtS(FTMP, lhs, rhs); |
| 2317 | __ LoadConst32(res, -1); |
| 2318 | __ Bc1nez(FTMP, &done); |
| 2319 | __ LoadConst32(res, 1); |
| 2320 | } else { |
| 2321 | __ CmpLtS(FTMP, rhs, lhs); |
| 2322 | __ LoadConst32(res, 1); |
| 2323 | __ Bc1nez(FTMP, &done); |
| 2324 | __ LoadConst32(res, -1); |
| 2325 | } |
| 2326 | } else { |
| 2327 | if (gt_bias) { |
| 2328 | __ ColtS(0, lhs, rhs); |
| 2329 | __ LoadConst32(res, -1); |
| 2330 | __ Bc1t(0, &done); |
| 2331 | __ CeqS(0, lhs, rhs); |
| 2332 | __ LoadConst32(res, 1); |
| 2333 | __ Movt(res, ZERO, 0); |
| 2334 | } else { |
| 2335 | __ ColtS(0, rhs, lhs); |
| 2336 | __ LoadConst32(res, 1); |
| 2337 | __ Bc1t(0, &done); |
| 2338 | __ CeqS(0, lhs, rhs); |
| 2339 | __ LoadConst32(res, -1); |
| 2340 | __ Movt(res, ZERO, 0); |
| 2341 | } |
| 2342 | } |
| 2343 | __ Bind(&done); |
| 2344 | break; |
| 2345 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2346 | case Primitive::kPrimDouble: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 2347 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2348 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2349 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2350 | MipsLabel done; |
| 2351 | if (isR6) { |
| 2352 | __ CmpEqD(FTMP, lhs, rhs); |
| 2353 | __ LoadConst32(res, 0); |
| 2354 | __ Bc1nez(FTMP, &done); |
| 2355 | if (gt_bias) { |
| 2356 | __ CmpLtD(FTMP, lhs, rhs); |
| 2357 | __ LoadConst32(res, -1); |
| 2358 | __ Bc1nez(FTMP, &done); |
| 2359 | __ LoadConst32(res, 1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2360 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2361 | __ CmpLtD(FTMP, rhs, lhs); |
| 2362 | __ LoadConst32(res, 1); |
| 2363 | __ Bc1nez(FTMP, &done); |
| 2364 | __ LoadConst32(res, -1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2365 | } |
| 2366 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2367 | if (gt_bias) { |
| 2368 | __ ColtD(0, lhs, rhs); |
| 2369 | __ LoadConst32(res, -1); |
| 2370 | __ Bc1t(0, &done); |
| 2371 | __ CeqD(0, lhs, rhs); |
| 2372 | __ LoadConst32(res, 1); |
| 2373 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2374 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2375 | __ ColtD(0, rhs, lhs); |
| 2376 | __ LoadConst32(res, 1); |
| 2377 | __ Bc1t(0, &done); |
| 2378 | __ CeqD(0, lhs, rhs); |
| 2379 | __ LoadConst32(res, -1); |
| 2380 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2381 | } |
| 2382 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2383 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2384 | break; |
| 2385 | } |
| 2386 | |
| 2387 | default: |
| 2388 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2389 | } |
| 2390 | } |
| 2391 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2392 | void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2393 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2394 | switch (instruction->InputAt(0)->GetType()) { |
| 2395 | default: |
| 2396 | case Primitive::kPrimLong: |
| 2397 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2398 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2399 | break; |
| 2400 | |
| 2401 | case Primitive::kPrimFloat: |
| 2402 | case Primitive::kPrimDouble: |
| 2403 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2404 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2405 | break; |
| 2406 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2407 | if (!instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2408 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2409 | } |
| 2410 | } |
| 2411 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2412 | void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2413 | if (instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2414 | return; |
| 2415 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2416 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2417 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2418 | LocationSummary* locations = instruction->GetLocations(); |
| 2419 | Register dst = locations->Out().AsRegister<Register>(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2420 | MipsLabel true_label; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2421 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2422 | switch (type) { |
| 2423 | default: |
| 2424 | // Integer case. |
| 2425 | GenerateIntCompare(instruction->GetCondition(), locations); |
| 2426 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2427 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2428 | case Primitive::kPrimLong: |
| 2429 | // TODO: don't use branches. |
| 2430 | GenerateLongCompareAndBranch(instruction->GetCondition(), locations, &true_label); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2431 | break; |
| 2432 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2433 | case Primitive::kPrimFloat: |
| 2434 | case Primitive::kPrimDouble: |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 2435 | GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, 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 | |
| 2439 | // Convert the branches into the result. |
| 2440 | MipsLabel done; |
| 2441 | |
| 2442 | // False case: result = 0. |
| 2443 | __ LoadConst32(dst, 0); |
| 2444 | __ B(&done); |
| 2445 | |
| 2446 | // True case: result = 1. |
| 2447 | __ Bind(&true_label); |
| 2448 | __ LoadConst32(dst, 1); |
| 2449 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2450 | } |
| 2451 | |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2452 | void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2453 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2454 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 2455 | |
| 2456 | LocationSummary* locations = instruction->GetLocations(); |
| 2457 | Location second = locations->InAt(1); |
| 2458 | DCHECK(second.IsConstant()); |
| 2459 | |
| 2460 | Register out = locations->Out().AsRegister<Register>(); |
| 2461 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2462 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2463 | DCHECK(imm == 1 || imm == -1); |
| 2464 | |
| 2465 | if (instruction->IsRem()) { |
| 2466 | __ Move(out, ZERO); |
| 2467 | } else { |
| 2468 | if (imm == -1) { |
| 2469 | __ Subu(out, ZERO, dividend); |
| 2470 | } else if (out != dividend) { |
| 2471 | __ Move(out, dividend); |
| 2472 | } |
| 2473 | } |
| 2474 | } |
| 2475 | |
| 2476 | void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2477 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2478 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 2479 | |
| 2480 | LocationSummary* locations = instruction->GetLocations(); |
| 2481 | Location second = locations->InAt(1); |
| 2482 | DCHECK(second.IsConstant()); |
| 2483 | |
| 2484 | Register out = locations->Out().AsRegister<Register>(); |
| 2485 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2486 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2487 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2488 | int ctz_imm = CTZ(abs_imm); |
| 2489 | |
| 2490 | if (instruction->IsDiv()) { |
| 2491 | if (ctz_imm == 1) { |
| 2492 | // Fast path for division by +/-2, which is very common. |
| 2493 | __ Srl(TMP, dividend, 31); |
| 2494 | } else { |
| 2495 | __ Sra(TMP, dividend, 31); |
| 2496 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 2497 | } |
| 2498 | __ Addu(out, dividend, TMP); |
| 2499 | __ Sra(out, out, ctz_imm); |
| 2500 | if (imm < 0) { |
| 2501 | __ Subu(out, ZERO, out); |
| 2502 | } |
| 2503 | } else { |
| 2504 | if (ctz_imm == 1) { |
| 2505 | // Fast path for modulo +/-2, which is very common. |
| 2506 | __ Sra(TMP, dividend, 31); |
| 2507 | __ Subu(out, dividend, TMP); |
| 2508 | __ Andi(out, out, 1); |
| 2509 | __ Addu(out, out, TMP); |
| 2510 | } else { |
| 2511 | __ Sra(TMP, dividend, 31); |
| 2512 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 2513 | __ Addu(out, dividend, TMP); |
| 2514 | if (IsUint<16>(abs_imm - 1)) { |
| 2515 | __ Andi(out, out, abs_imm - 1); |
| 2516 | } else { |
| 2517 | __ Sll(out, out, 32 - ctz_imm); |
| 2518 | __ Srl(out, out, 32 - ctz_imm); |
| 2519 | } |
| 2520 | __ Subu(out, out, TMP); |
| 2521 | } |
| 2522 | } |
| 2523 | } |
| 2524 | |
| 2525 | void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2526 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2527 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 2528 | |
| 2529 | LocationSummary* locations = instruction->GetLocations(); |
| 2530 | Location second = locations->InAt(1); |
| 2531 | DCHECK(second.IsConstant()); |
| 2532 | |
| 2533 | Register out = locations->Out().AsRegister<Register>(); |
| 2534 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2535 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2536 | |
| 2537 | int64_t magic; |
| 2538 | int shift; |
| 2539 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2540 | |
| 2541 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 2542 | |
| 2543 | __ LoadConst32(TMP, magic); |
| 2544 | if (isR6) { |
| 2545 | __ MuhR6(TMP, dividend, TMP); |
| 2546 | } else { |
| 2547 | __ MultR2(dividend, TMP); |
| 2548 | __ Mfhi(TMP); |
| 2549 | } |
| 2550 | if (imm > 0 && magic < 0) { |
| 2551 | __ Addu(TMP, TMP, dividend); |
| 2552 | } else if (imm < 0 && magic > 0) { |
| 2553 | __ Subu(TMP, TMP, dividend); |
| 2554 | } |
| 2555 | |
| 2556 | if (shift != 0) { |
| 2557 | __ Sra(TMP, TMP, shift); |
| 2558 | } |
| 2559 | |
| 2560 | if (instruction->IsDiv()) { |
| 2561 | __ Sra(out, TMP, 31); |
| 2562 | __ Subu(out, TMP, out); |
| 2563 | } else { |
| 2564 | __ Sra(AT, TMP, 31); |
| 2565 | __ Subu(AT, TMP, AT); |
| 2566 | __ LoadConst32(TMP, imm); |
| 2567 | if (isR6) { |
| 2568 | __ MulR6(TMP, AT, TMP); |
| 2569 | } else { |
| 2570 | __ MulR2(TMP, AT, TMP); |
| 2571 | } |
| 2572 | __ Subu(out, dividend, TMP); |
| 2573 | } |
| 2574 | } |
| 2575 | |
| 2576 | void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2577 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2578 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 2579 | |
| 2580 | LocationSummary* locations = instruction->GetLocations(); |
| 2581 | Register out = locations->Out().AsRegister<Register>(); |
| 2582 | Location second = locations->InAt(1); |
| 2583 | |
| 2584 | if (second.IsConstant()) { |
| 2585 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2586 | if (imm == 0) { |
| 2587 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2588 | } else if (imm == 1 || imm == -1) { |
| 2589 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2590 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2591 | DivRemByPowerOfTwo(instruction); |
| 2592 | } else { |
| 2593 | DCHECK(imm <= -2 || imm >= 2); |
| 2594 | GenerateDivRemWithAnyConstant(instruction); |
| 2595 | } |
| 2596 | } else { |
| 2597 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2598 | Register divisor = second.AsRegister<Register>(); |
| 2599 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 2600 | if (instruction->IsDiv()) { |
| 2601 | if (isR6) { |
| 2602 | __ DivR6(out, dividend, divisor); |
| 2603 | } else { |
| 2604 | __ DivR2(out, dividend, divisor); |
| 2605 | } |
| 2606 | } else { |
| 2607 | if (isR6) { |
| 2608 | __ ModR6(out, dividend, divisor); |
| 2609 | } else { |
| 2610 | __ ModR2(out, dividend, divisor); |
| 2611 | } |
| 2612 | } |
| 2613 | } |
| 2614 | } |
| 2615 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2616 | void LocationsBuilderMIPS::VisitDiv(HDiv* div) { |
| 2617 | Primitive::Type type = div->GetResultType(); |
| 2618 | LocationSummary::CallKind call_kind = (type == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2619 | ? LocationSummary::kCallOnMainOnly |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2620 | : LocationSummary::kNoCall; |
| 2621 | |
| 2622 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2623 | |
| 2624 | switch (type) { |
| 2625 | case Primitive::kPrimInt: |
| 2626 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2627 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2628 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2629 | break; |
| 2630 | |
| 2631 | case Primitive::kPrimLong: { |
| 2632 | InvokeRuntimeCallingConvention calling_convention; |
| 2633 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2634 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2635 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2636 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2637 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 2638 | break; |
| 2639 | } |
| 2640 | |
| 2641 | case Primitive::kPrimFloat: |
| 2642 | case Primitive::kPrimDouble: |
| 2643 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2644 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2645 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2646 | break; |
| 2647 | |
| 2648 | default: |
| 2649 | LOG(FATAL) << "Unexpected div type " << type; |
| 2650 | } |
| 2651 | } |
| 2652 | |
| 2653 | void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) { |
| 2654 | Primitive::Type type = instruction->GetType(); |
| 2655 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2656 | |
| 2657 | switch (type) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2658 | case Primitive::kPrimInt: |
| 2659 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2660 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2661 | case Primitive::kPrimLong: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 2662 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2663 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| 2664 | break; |
| 2665 | } |
| 2666 | case Primitive::kPrimFloat: |
| 2667 | case Primitive::kPrimDouble: { |
| 2668 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 2669 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2670 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2671 | if (type == Primitive::kPrimFloat) { |
| 2672 | __ DivS(dst, lhs, rhs); |
| 2673 | } else { |
| 2674 | __ DivD(dst, lhs, rhs); |
| 2675 | } |
| 2676 | break; |
| 2677 | } |
| 2678 | default: |
| 2679 | LOG(FATAL) << "Unexpected div type " << type; |
| 2680 | } |
| 2681 | } |
| 2682 | |
| 2683 | void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2684 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2685 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2686 | } |
| 2687 | |
| 2688 | void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2689 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS(instruction); |
| 2690 | codegen_->AddSlowPath(slow_path); |
| 2691 | Location value = instruction->GetLocations()->InAt(0); |
| 2692 | Primitive::Type type = instruction->GetType(); |
| 2693 | |
| 2694 | switch (type) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 2695 | case Primitive::kPrimBoolean: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2696 | case Primitive::kPrimByte: |
| 2697 | case Primitive::kPrimChar: |
| 2698 | case Primitive::kPrimShort: |
| 2699 | case Primitive::kPrimInt: { |
| 2700 | if (value.IsConstant()) { |
| 2701 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 2702 | __ B(slow_path->GetEntryLabel()); |
| 2703 | } else { |
| 2704 | // A division by a non-null constant is valid. We don't need to perform |
| 2705 | // any check, so simply fall through. |
| 2706 | } |
| 2707 | } else { |
| 2708 | DCHECK(value.IsRegister()) << value; |
| 2709 | __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 2710 | } |
| 2711 | break; |
| 2712 | } |
| 2713 | case Primitive::kPrimLong: { |
| 2714 | if (value.IsConstant()) { |
| 2715 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 2716 | __ B(slow_path->GetEntryLabel()); |
| 2717 | } else { |
| 2718 | // A division by a non-null constant is valid. We don't need to perform |
| 2719 | // any check, so simply fall through. |
| 2720 | } |
| 2721 | } else { |
| 2722 | DCHECK(value.IsRegisterPair()) << value; |
| 2723 | __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>()); |
| 2724 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 2725 | } |
| 2726 | break; |
| 2727 | } |
| 2728 | default: |
| 2729 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
| 2730 | } |
| 2731 | } |
| 2732 | |
| 2733 | void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2734 | LocationSummary* locations = |
| 2735 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2736 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2737 | } |
| 2738 | |
| 2739 | void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 2740 | // Will be generated at use site. |
| 2741 | } |
| 2742 | |
| 2743 | void LocationsBuilderMIPS::VisitExit(HExit* exit) { |
| 2744 | exit->SetLocations(nullptr); |
| 2745 | } |
| 2746 | |
| 2747 | void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 2748 | } |
| 2749 | |
| 2750 | void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) { |
| 2751 | LocationSummary* locations = |
| 2752 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2753 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2754 | } |
| 2755 | |
| 2756 | void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 2757 | // Will be generated at use site. |
| 2758 | } |
| 2759 | |
| 2760 | void LocationsBuilderMIPS::VisitGoto(HGoto* got) { |
| 2761 | got->SetLocations(nullptr); |
| 2762 | } |
| 2763 | |
| 2764 | void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| 2765 | DCHECK(!successor->IsExitBlock()); |
| 2766 | HBasicBlock* block = got->GetBlock(); |
| 2767 | HInstruction* previous = got->GetPrevious(); |
| 2768 | HLoopInformation* info = block->GetLoopInformation(); |
| 2769 | |
| 2770 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| 2771 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2772 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2773 | return; |
| 2774 | } |
| 2775 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2776 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2777 | } |
| 2778 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 2779 | __ B(codegen_->GetLabelOf(successor)); |
| 2780 | } |
| 2781 | } |
| 2782 | |
| 2783 | void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) { |
| 2784 | HandleGoto(got, got->GetSuccessor()); |
| 2785 | } |
| 2786 | |
| 2787 | void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2788 | try_boundary->SetLocations(nullptr); |
| 2789 | } |
| 2790 | |
| 2791 | void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2792 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2793 | if (!successor->IsExitBlock()) { |
| 2794 | HandleGoto(try_boundary, successor); |
| 2795 | } |
| 2796 | } |
| 2797 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2798 | void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond, |
| 2799 | LocationSummary* locations) { |
| 2800 | Register dst = locations->Out().AsRegister<Register>(); |
| 2801 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2802 | Location rhs_location = locations->InAt(1); |
| 2803 | Register rhs_reg = ZERO; |
| 2804 | int64_t rhs_imm = 0; |
| 2805 | bool use_imm = rhs_location.IsConstant(); |
| 2806 | if (use_imm) { |
| 2807 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 2808 | } else { |
| 2809 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 2810 | } |
| 2811 | |
| 2812 | switch (cond) { |
| 2813 | case kCondEQ: |
| 2814 | case kCondNE: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 2815 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 2816 | if (rhs_imm == 0) { |
| 2817 | if (cond == kCondEQ) { |
| 2818 | __ Sltiu(dst, lhs, 1); |
| 2819 | } else { |
| 2820 | __ Sltu(dst, ZERO, lhs); |
| 2821 | } |
| 2822 | } else { |
| 2823 | __ Addiu(dst, lhs, -rhs_imm); |
| 2824 | if (cond == kCondEQ) { |
| 2825 | __ Sltiu(dst, dst, 1); |
| 2826 | } else { |
| 2827 | __ Sltu(dst, ZERO, dst); |
| 2828 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2829 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2830 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 2831 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 2832 | __ Xori(dst, lhs, rhs_imm); |
| 2833 | } else { |
| 2834 | if (use_imm) { |
| 2835 | rhs_reg = TMP; |
| 2836 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2837 | } |
| 2838 | __ Xor(dst, lhs, rhs_reg); |
| 2839 | } |
| 2840 | if (cond == kCondEQ) { |
| 2841 | __ Sltiu(dst, dst, 1); |
| 2842 | } else { |
| 2843 | __ Sltu(dst, ZERO, dst); |
| 2844 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2845 | } |
| 2846 | break; |
| 2847 | |
| 2848 | case kCondLT: |
| 2849 | case kCondGE: |
| 2850 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 2851 | __ Slti(dst, lhs, rhs_imm); |
| 2852 | } else { |
| 2853 | if (use_imm) { |
| 2854 | rhs_reg = TMP; |
| 2855 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2856 | } |
| 2857 | __ Slt(dst, lhs, rhs_reg); |
| 2858 | } |
| 2859 | if (cond == kCondGE) { |
| 2860 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 2861 | // only the slt instruction but no sge. |
| 2862 | __ Xori(dst, dst, 1); |
| 2863 | } |
| 2864 | break; |
| 2865 | |
| 2866 | case kCondLE: |
| 2867 | case kCondGT: |
| 2868 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 2869 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 2870 | __ Slti(dst, lhs, rhs_imm + 1); |
| 2871 | if (cond == kCondGT) { |
| 2872 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 2873 | // only the slti instruction but no sgti. |
| 2874 | __ Xori(dst, dst, 1); |
| 2875 | } |
| 2876 | } else { |
| 2877 | if (use_imm) { |
| 2878 | rhs_reg = TMP; |
| 2879 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2880 | } |
| 2881 | __ Slt(dst, rhs_reg, lhs); |
| 2882 | if (cond == kCondLE) { |
| 2883 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 2884 | // only the slt instruction but no sle. |
| 2885 | __ Xori(dst, dst, 1); |
| 2886 | } |
| 2887 | } |
| 2888 | break; |
| 2889 | |
| 2890 | case kCondB: |
| 2891 | case kCondAE: |
| 2892 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 2893 | // Sltiu sign-extends its 16-bit immediate operand before |
| 2894 | // the comparison and thus lets us compare directly with |
| 2895 | // unsigned values in the ranges [0, 0x7fff] and |
| 2896 | // [0xffff8000, 0xffffffff]. |
| 2897 | __ Sltiu(dst, lhs, rhs_imm); |
| 2898 | } else { |
| 2899 | if (use_imm) { |
| 2900 | rhs_reg = TMP; |
| 2901 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2902 | } |
| 2903 | __ Sltu(dst, lhs, rhs_reg); |
| 2904 | } |
| 2905 | if (cond == kCondAE) { |
| 2906 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 2907 | // only the sltu instruction but no sgeu. |
| 2908 | __ Xori(dst, dst, 1); |
| 2909 | } |
| 2910 | break; |
| 2911 | |
| 2912 | case kCondBE: |
| 2913 | case kCondA: |
| 2914 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 2915 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 2916 | // Note that this only works if rhs + 1 does not overflow |
| 2917 | // to 0, hence the check above. |
| 2918 | // Sltiu sign-extends its 16-bit immediate operand before |
| 2919 | // the comparison and thus lets us compare directly with |
| 2920 | // unsigned values in the ranges [0, 0x7fff] and |
| 2921 | // [0xffff8000, 0xffffffff]. |
| 2922 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 2923 | if (cond == kCondA) { |
| 2924 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 2925 | // only the sltiu instruction but no sgtiu. |
| 2926 | __ Xori(dst, dst, 1); |
| 2927 | } |
| 2928 | } else { |
| 2929 | if (use_imm) { |
| 2930 | rhs_reg = TMP; |
| 2931 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2932 | } |
| 2933 | __ Sltu(dst, rhs_reg, lhs); |
| 2934 | if (cond == kCondBE) { |
| 2935 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 2936 | // only the sltu instruction but no sleu. |
| 2937 | __ Xori(dst, dst, 1); |
| 2938 | } |
| 2939 | } |
| 2940 | break; |
| 2941 | } |
| 2942 | } |
| 2943 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 2944 | bool InstructionCodeGeneratorMIPS::MaterializeIntCompare(IfCondition cond, |
| 2945 | LocationSummary* input_locations, |
| 2946 | Register dst) { |
| 2947 | Register lhs = input_locations->InAt(0).AsRegister<Register>(); |
| 2948 | Location rhs_location = input_locations->InAt(1); |
| 2949 | Register rhs_reg = ZERO; |
| 2950 | int64_t rhs_imm = 0; |
| 2951 | bool use_imm = rhs_location.IsConstant(); |
| 2952 | if (use_imm) { |
| 2953 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 2954 | } else { |
| 2955 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 2956 | } |
| 2957 | |
| 2958 | switch (cond) { |
| 2959 | case kCondEQ: |
| 2960 | case kCondNE: |
| 2961 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 2962 | __ Addiu(dst, lhs, -rhs_imm); |
| 2963 | } else if (use_imm && IsUint<16>(rhs_imm)) { |
| 2964 | __ Xori(dst, lhs, rhs_imm); |
| 2965 | } else { |
| 2966 | if (use_imm) { |
| 2967 | rhs_reg = TMP; |
| 2968 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2969 | } |
| 2970 | __ Xor(dst, lhs, rhs_reg); |
| 2971 | } |
| 2972 | return (cond == kCondEQ); |
| 2973 | |
| 2974 | case kCondLT: |
| 2975 | case kCondGE: |
| 2976 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 2977 | __ Slti(dst, lhs, rhs_imm); |
| 2978 | } else { |
| 2979 | if (use_imm) { |
| 2980 | rhs_reg = TMP; |
| 2981 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2982 | } |
| 2983 | __ Slt(dst, lhs, rhs_reg); |
| 2984 | } |
| 2985 | return (cond == kCondGE); |
| 2986 | |
| 2987 | case kCondLE: |
| 2988 | case kCondGT: |
| 2989 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 2990 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 2991 | __ Slti(dst, lhs, rhs_imm + 1); |
| 2992 | return (cond == kCondGT); |
| 2993 | } else { |
| 2994 | if (use_imm) { |
| 2995 | rhs_reg = TMP; |
| 2996 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2997 | } |
| 2998 | __ Slt(dst, rhs_reg, lhs); |
| 2999 | return (cond == kCondLE); |
| 3000 | } |
| 3001 | |
| 3002 | case kCondB: |
| 3003 | case kCondAE: |
| 3004 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3005 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3006 | // the comparison and thus lets us compare directly with |
| 3007 | // unsigned values in the ranges [0, 0x7fff] and |
| 3008 | // [0xffff8000, 0xffffffff]. |
| 3009 | __ Sltiu(dst, lhs, rhs_imm); |
| 3010 | } else { |
| 3011 | if (use_imm) { |
| 3012 | rhs_reg = TMP; |
| 3013 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3014 | } |
| 3015 | __ Sltu(dst, lhs, rhs_reg); |
| 3016 | } |
| 3017 | return (cond == kCondAE); |
| 3018 | |
| 3019 | case kCondBE: |
| 3020 | case kCondA: |
| 3021 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 3022 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3023 | // Note that this only works if rhs + 1 does not overflow |
| 3024 | // to 0, hence the check above. |
| 3025 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3026 | // the comparison and thus lets us compare directly with |
| 3027 | // unsigned values in the ranges [0, 0x7fff] and |
| 3028 | // [0xffff8000, 0xffffffff]. |
| 3029 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 3030 | return (cond == kCondA); |
| 3031 | } else { |
| 3032 | if (use_imm) { |
| 3033 | rhs_reg = TMP; |
| 3034 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3035 | } |
| 3036 | __ Sltu(dst, rhs_reg, lhs); |
| 3037 | return (cond == kCondBE); |
| 3038 | } |
| 3039 | } |
| 3040 | } |
| 3041 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3042 | void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond, |
| 3043 | LocationSummary* locations, |
| 3044 | MipsLabel* label) { |
| 3045 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 3046 | Location rhs_location = locations->InAt(1); |
| 3047 | Register rhs_reg = ZERO; |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 3048 | int64_t rhs_imm = 0; |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3049 | bool use_imm = rhs_location.IsConstant(); |
| 3050 | if (use_imm) { |
| 3051 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3052 | } else { |
| 3053 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 3054 | } |
| 3055 | |
| 3056 | if (use_imm && rhs_imm == 0) { |
| 3057 | switch (cond) { |
| 3058 | case kCondEQ: |
| 3059 | case kCondBE: // <= 0 if zero |
| 3060 | __ Beqz(lhs, label); |
| 3061 | break; |
| 3062 | case kCondNE: |
| 3063 | case kCondA: // > 0 if non-zero |
| 3064 | __ Bnez(lhs, label); |
| 3065 | break; |
| 3066 | case kCondLT: |
| 3067 | __ Bltz(lhs, label); |
| 3068 | break; |
| 3069 | case kCondGE: |
| 3070 | __ Bgez(lhs, label); |
| 3071 | break; |
| 3072 | case kCondLE: |
| 3073 | __ Blez(lhs, label); |
| 3074 | break; |
| 3075 | case kCondGT: |
| 3076 | __ Bgtz(lhs, label); |
| 3077 | break; |
| 3078 | case kCondB: // always false |
| 3079 | break; |
| 3080 | case kCondAE: // always true |
| 3081 | __ B(label); |
| 3082 | break; |
| 3083 | } |
| 3084 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 3085 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3086 | if (isR6 || !use_imm) { |
| 3087 | if (use_imm) { |
| 3088 | rhs_reg = TMP; |
| 3089 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3090 | } |
| 3091 | switch (cond) { |
| 3092 | case kCondEQ: |
| 3093 | __ Beq(lhs, rhs_reg, label); |
| 3094 | break; |
| 3095 | case kCondNE: |
| 3096 | __ Bne(lhs, rhs_reg, label); |
| 3097 | break; |
| 3098 | case kCondLT: |
| 3099 | __ Blt(lhs, rhs_reg, label); |
| 3100 | break; |
| 3101 | case kCondGE: |
| 3102 | __ Bge(lhs, rhs_reg, label); |
| 3103 | break; |
| 3104 | case kCondLE: |
| 3105 | __ Bge(rhs_reg, lhs, label); |
| 3106 | break; |
| 3107 | case kCondGT: |
| 3108 | __ Blt(rhs_reg, lhs, label); |
| 3109 | break; |
| 3110 | case kCondB: |
| 3111 | __ Bltu(lhs, rhs_reg, label); |
| 3112 | break; |
| 3113 | case kCondAE: |
| 3114 | __ Bgeu(lhs, rhs_reg, label); |
| 3115 | break; |
| 3116 | case kCondBE: |
| 3117 | __ Bgeu(rhs_reg, lhs, label); |
| 3118 | break; |
| 3119 | case kCondA: |
| 3120 | __ Bltu(rhs_reg, lhs, label); |
| 3121 | break; |
| 3122 | } |
| 3123 | } else { |
| 3124 | // Special cases for more efficient comparison with constants on R2. |
| 3125 | switch (cond) { |
| 3126 | case kCondEQ: |
| 3127 | __ LoadConst32(TMP, rhs_imm); |
| 3128 | __ Beq(lhs, TMP, label); |
| 3129 | break; |
| 3130 | case kCondNE: |
| 3131 | __ LoadConst32(TMP, rhs_imm); |
| 3132 | __ Bne(lhs, TMP, label); |
| 3133 | break; |
| 3134 | case kCondLT: |
| 3135 | if (IsInt<16>(rhs_imm)) { |
| 3136 | __ Slti(TMP, lhs, rhs_imm); |
| 3137 | __ Bnez(TMP, label); |
| 3138 | } else { |
| 3139 | __ LoadConst32(TMP, rhs_imm); |
| 3140 | __ Blt(lhs, TMP, label); |
| 3141 | } |
| 3142 | break; |
| 3143 | case kCondGE: |
| 3144 | if (IsInt<16>(rhs_imm)) { |
| 3145 | __ Slti(TMP, lhs, rhs_imm); |
| 3146 | __ Beqz(TMP, label); |
| 3147 | } else { |
| 3148 | __ LoadConst32(TMP, rhs_imm); |
| 3149 | __ Bge(lhs, TMP, label); |
| 3150 | } |
| 3151 | break; |
| 3152 | case kCondLE: |
| 3153 | if (IsInt<16>(rhs_imm + 1)) { |
| 3154 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3155 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 3156 | __ Bnez(TMP, label); |
| 3157 | } else { |
| 3158 | __ LoadConst32(TMP, rhs_imm); |
| 3159 | __ Bge(TMP, lhs, label); |
| 3160 | } |
| 3161 | break; |
| 3162 | case kCondGT: |
| 3163 | if (IsInt<16>(rhs_imm + 1)) { |
| 3164 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 3165 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 3166 | __ Beqz(TMP, label); |
| 3167 | } else { |
| 3168 | __ LoadConst32(TMP, rhs_imm); |
| 3169 | __ Blt(TMP, lhs, label); |
| 3170 | } |
| 3171 | break; |
| 3172 | case kCondB: |
| 3173 | if (IsInt<16>(rhs_imm)) { |
| 3174 | __ Sltiu(TMP, lhs, rhs_imm); |
| 3175 | __ Bnez(TMP, label); |
| 3176 | } else { |
| 3177 | __ LoadConst32(TMP, rhs_imm); |
| 3178 | __ Bltu(lhs, TMP, label); |
| 3179 | } |
| 3180 | break; |
| 3181 | case kCondAE: |
| 3182 | if (IsInt<16>(rhs_imm)) { |
| 3183 | __ Sltiu(TMP, lhs, rhs_imm); |
| 3184 | __ Beqz(TMP, label); |
| 3185 | } else { |
| 3186 | __ LoadConst32(TMP, rhs_imm); |
| 3187 | __ Bgeu(lhs, TMP, label); |
| 3188 | } |
| 3189 | break; |
| 3190 | case kCondBE: |
| 3191 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 3192 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3193 | // Note that this only works if rhs + 1 does not overflow |
| 3194 | // to 0, hence the check above. |
| 3195 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 3196 | __ Bnez(TMP, label); |
| 3197 | } else { |
| 3198 | __ LoadConst32(TMP, rhs_imm); |
| 3199 | __ Bgeu(TMP, lhs, label); |
| 3200 | } |
| 3201 | break; |
| 3202 | case kCondA: |
| 3203 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 3204 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 3205 | // Note that this only works if rhs + 1 does not overflow |
| 3206 | // to 0, hence the check above. |
| 3207 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 3208 | __ Beqz(TMP, label); |
| 3209 | } else { |
| 3210 | __ LoadConst32(TMP, rhs_imm); |
| 3211 | __ Bltu(TMP, lhs, label); |
| 3212 | } |
| 3213 | break; |
| 3214 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3215 | } |
| 3216 | } |
| 3217 | } |
| 3218 | |
| 3219 | void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond, |
| 3220 | LocationSummary* locations, |
| 3221 | MipsLabel* label) { |
| 3222 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3223 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3224 | Location rhs_location = locations->InAt(1); |
| 3225 | Register rhs_high = ZERO; |
| 3226 | Register rhs_low = ZERO; |
| 3227 | int64_t imm = 0; |
| 3228 | uint32_t imm_high = 0; |
| 3229 | uint32_t imm_low = 0; |
| 3230 | bool use_imm = rhs_location.IsConstant(); |
| 3231 | if (use_imm) { |
| 3232 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); |
| 3233 | imm_high = High32Bits(imm); |
| 3234 | imm_low = Low32Bits(imm); |
| 3235 | } else { |
| 3236 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 3237 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 3238 | } |
| 3239 | |
| 3240 | if (use_imm && imm == 0) { |
| 3241 | switch (cond) { |
| 3242 | case kCondEQ: |
| 3243 | case kCondBE: // <= 0 if zero |
| 3244 | __ Or(TMP, lhs_high, lhs_low); |
| 3245 | __ Beqz(TMP, label); |
| 3246 | break; |
| 3247 | case kCondNE: |
| 3248 | case kCondA: // > 0 if non-zero |
| 3249 | __ Or(TMP, lhs_high, lhs_low); |
| 3250 | __ Bnez(TMP, label); |
| 3251 | break; |
| 3252 | case kCondLT: |
| 3253 | __ Bltz(lhs_high, label); |
| 3254 | break; |
| 3255 | case kCondGE: |
| 3256 | __ Bgez(lhs_high, label); |
| 3257 | break; |
| 3258 | case kCondLE: |
| 3259 | __ Or(TMP, lhs_high, lhs_low); |
| 3260 | __ Sra(AT, lhs_high, 31); |
| 3261 | __ Bgeu(AT, TMP, label); |
| 3262 | break; |
| 3263 | case kCondGT: |
| 3264 | __ Or(TMP, lhs_high, lhs_low); |
| 3265 | __ Sra(AT, lhs_high, 31); |
| 3266 | __ Bltu(AT, TMP, label); |
| 3267 | break; |
| 3268 | case kCondB: // always false |
| 3269 | break; |
| 3270 | case kCondAE: // always true |
| 3271 | __ B(label); |
| 3272 | break; |
| 3273 | } |
| 3274 | } else if (use_imm) { |
| 3275 | // TODO: more efficient comparison with constants without loading them into TMP/AT. |
| 3276 | switch (cond) { |
| 3277 | case kCondEQ: |
| 3278 | __ LoadConst32(TMP, imm_high); |
| 3279 | __ Xor(TMP, TMP, lhs_high); |
| 3280 | __ LoadConst32(AT, imm_low); |
| 3281 | __ Xor(AT, AT, lhs_low); |
| 3282 | __ Or(TMP, TMP, AT); |
| 3283 | __ Beqz(TMP, label); |
| 3284 | break; |
| 3285 | case kCondNE: |
| 3286 | __ LoadConst32(TMP, imm_high); |
| 3287 | __ Xor(TMP, TMP, lhs_high); |
| 3288 | __ LoadConst32(AT, imm_low); |
| 3289 | __ Xor(AT, AT, lhs_low); |
| 3290 | __ Or(TMP, TMP, AT); |
| 3291 | __ Bnez(TMP, label); |
| 3292 | break; |
| 3293 | case kCondLT: |
| 3294 | __ LoadConst32(TMP, imm_high); |
| 3295 | __ Blt(lhs_high, TMP, label); |
| 3296 | __ Slt(TMP, TMP, lhs_high); |
| 3297 | __ LoadConst32(AT, imm_low); |
| 3298 | __ Sltu(AT, lhs_low, AT); |
| 3299 | __ Blt(TMP, AT, label); |
| 3300 | break; |
| 3301 | case kCondGE: |
| 3302 | __ LoadConst32(TMP, imm_high); |
| 3303 | __ Blt(TMP, lhs_high, label); |
| 3304 | __ Slt(TMP, lhs_high, TMP); |
| 3305 | __ LoadConst32(AT, imm_low); |
| 3306 | __ Sltu(AT, lhs_low, AT); |
| 3307 | __ Or(TMP, TMP, AT); |
| 3308 | __ Beqz(TMP, label); |
| 3309 | break; |
| 3310 | case kCondLE: |
| 3311 | __ LoadConst32(TMP, imm_high); |
| 3312 | __ Blt(lhs_high, TMP, label); |
| 3313 | __ Slt(TMP, TMP, lhs_high); |
| 3314 | __ LoadConst32(AT, imm_low); |
| 3315 | __ Sltu(AT, AT, lhs_low); |
| 3316 | __ Or(TMP, TMP, AT); |
| 3317 | __ Beqz(TMP, label); |
| 3318 | break; |
| 3319 | case kCondGT: |
| 3320 | __ LoadConst32(TMP, imm_high); |
| 3321 | __ Blt(TMP, lhs_high, label); |
| 3322 | __ Slt(TMP, lhs_high, TMP); |
| 3323 | __ LoadConst32(AT, imm_low); |
| 3324 | __ Sltu(AT, AT, lhs_low); |
| 3325 | __ Blt(TMP, AT, label); |
| 3326 | break; |
| 3327 | case kCondB: |
| 3328 | __ LoadConst32(TMP, imm_high); |
| 3329 | __ Bltu(lhs_high, TMP, label); |
| 3330 | __ Sltu(TMP, TMP, lhs_high); |
| 3331 | __ LoadConst32(AT, imm_low); |
| 3332 | __ Sltu(AT, lhs_low, AT); |
| 3333 | __ Blt(TMP, AT, label); |
| 3334 | break; |
| 3335 | case kCondAE: |
| 3336 | __ LoadConst32(TMP, imm_high); |
| 3337 | __ Bltu(TMP, lhs_high, label); |
| 3338 | __ Sltu(TMP, lhs_high, TMP); |
| 3339 | __ LoadConst32(AT, imm_low); |
| 3340 | __ Sltu(AT, lhs_low, AT); |
| 3341 | __ Or(TMP, TMP, AT); |
| 3342 | __ Beqz(TMP, label); |
| 3343 | break; |
| 3344 | case kCondBE: |
| 3345 | __ LoadConst32(TMP, imm_high); |
| 3346 | __ Bltu(lhs_high, TMP, label); |
| 3347 | __ Sltu(TMP, TMP, lhs_high); |
| 3348 | __ LoadConst32(AT, imm_low); |
| 3349 | __ Sltu(AT, AT, lhs_low); |
| 3350 | __ Or(TMP, TMP, AT); |
| 3351 | __ Beqz(TMP, label); |
| 3352 | break; |
| 3353 | case kCondA: |
| 3354 | __ LoadConst32(TMP, imm_high); |
| 3355 | __ Bltu(TMP, lhs_high, label); |
| 3356 | __ Sltu(TMP, lhs_high, TMP); |
| 3357 | __ LoadConst32(AT, imm_low); |
| 3358 | __ Sltu(AT, AT, lhs_low); |
| 3359 | __ Blt(TMP, AT, label); |
| 3360 | break; |
| 3361 | } |
| 3362 | } else { |
| 3363 | switch (cond) { |
| 3364 | case kCondEQ: |
| 3365 | __ Xor(TMP, lhs_high, rhs_high); |
| 3366 | __ Xor(AT, lhs_low, rhs_low); |
| 3367 | __ Or(TMP, TMP, AT); |
| 3368 | __ Beqz(TMP, label); |
| 3369 | break; |
| 3370 | case kCondNE: |
| 3371 | __ Xor(TMP, lhs_high, rhs_high); |
| 3372 | __ Xor(AT, lhs_low, rhs_low); |
| 3373 | __ Or(TMP, TMP, AT); |
| 3374 | __ Bnez(TMP, label); |
| 3375 | break; |
| 3376 | case kCondLT: |
| 3377 | __ Blt(lhs_high, rhs_high, label); |
| 3378 | __ Slt(TMP, rhs_high, lhs_high); |
| 3379 | __ Sltu(AT, lhs_low, rhs_low); |
| 3380 | __ Blt(TMP, AT, label); |
| 3381 | break; |
| 3382 | case kCondGE: |
| 3383 | __ Blt(rhs_high, lhs_high, label); |
| 3384 | __ Slt(TMP, lhs_high, rhs_high); |
| 3385 | __ Sltu(AT, lhs_low, rhs_low); |
| 3386 | __ Or(TMP, TMP, AT); |
| 3387 | __ Beqz(TMP, label); |
| 3388 | break; |
| 3389 | case kCondLE: |
| 3390 | __ Blt(lhs_high, rhs_high, label); |
| 3391 | __ Slt(TMP, rhs_high, lhs_high); |
| 3392 | __ Sltu(AT, rhs_low, lhs_low); |
| 3393 | __ Or(TMP, TMP, AT); |
| 3394 | __ Beqz(TMP, label); |
| 3395 | break; |
| 3396 | case kCondGT: |
| 3397 | __ Blt(rhs_high, lhs_high, label); |
| 3398 | __ Slt(TMP, lhs_high, rhs_high); |
| 3399 | __ Sltu(AT, rhs_low, lhs_low); |
| 3400 | __ Blt(TMP, AT, label); |
| 3401 | break; |
| 3402 | case kCondB: |
| 3403 | __ Bltu(lhs_high, rhs_high, label); |
| 3404 | __ Sltu(TMP, rhs_high, lhs_high); |
| 3405 | __ Sltu(AT, lhs_low, rhs_low); |
| 3406 | __ Blt(TMP, AT, label); |
| 3407 | break; |
| 3408 | case kCondAE: |
| 3409 | __ Bltu(rhs_high, lhs_high, label); |
| 3410 | __ Sltu(TMP, lhs_high, rhs_high); |
| 3411 | __ Sltu(AT, lhs_low, rhs_low); |
| 3412 | __ Or(TMP, TMP, AT); |
| 3413 | __ Beqz(TMP, label); |
| 3414 | break; |
| 3415 | case kCondBE: |
| 3416 | __ Bltu(lhs_high, rhs_high, label); |
| 3417 | __ Sltu(TMP, rhs_high, lhs_high); |
| 3418 | __ Sltu(AT, rhs_low, lhs_low); |
| 3419 | __ Or(TMP, TMP, AT); |
| 3420 | __ Beqz(TMP, label); |
| 3421 | break; |
| 3422 | case kCondA: |
| 3423 | __ Bltu(rhs_high, lhs_high, label); |
| 3424 | __ Sltu(TMP, lhs_high, rhs_high); |
| 3425 | __ Sltu(AT, rhs_low, lhs_low); |
| 3426 | __ Blt(TMP, AT, label); |
| 3427 | break; |
| 3428 | } |
| 3429 | } |
| 3430 | } |
| 3431 | |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 3432 | void InstructionCodeGeneratorMIPS::GenerateFpCompare(IfCondition cond, |
| 3433 | bool gt_bias, |
| 3434 | Primitive::Type type, |
| 3435 | LocationSummary* locations) { |
| 3436 | Register dst = locations->Out().AsRegister<Register>(); |
| 3437 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3438 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3439 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3440 | if (type == Primitive::kPrimFloat) { |
| 3441 | if (isR6) { |
| 3442 | switch (cond) { |
| 3443 | case kCondEQ: |
| 3444 | __ CmpEqS(FTMP, lhs, rhs); |
| 3445 | __ Mfc1(dst, FTMP); |
| 3446 | __ Andi(dst, dst, 1); |
| 3447 | break; |
| 3448 | case kCondNE: |
| 3449 | __ CmpEqS(FTMP, lhs, rhs); |
| 3450 | __ Mfc1(dst, FTMP); |
| 3451 | __ Addiu(dst, dst, 1); |
| 3452 | break; |
| 3453 | case kCondLT: |
| 3454 | if (gt_bias) { |
| 3455 | __ CmpLtS(FTMP, lhs, rhs); |
| 3456 | } else { |
| 3457 | __ CmpUltS(FTMP, lhs, rhs); |
| 3458 | } |
| 3459 | __ Mfc1(dst, FTMP); |
| 3460 | __ Andi(dst, dst, 1); |
| 3461 | break; |
| 3462 | case kCondLE: |
| 3463 | if (gt_bias) { |
| 3464 | __ CmpLeS(FTMP, lhs, rhs); |
| 3465 | } else { |
| 3466 | __ CmpUleS(FTMP, lhs, rhs); |
| 3467 | } |
| 3468 | __ Mfc1(dst, FTMP); |
| 3469 | __ Andi(dst, dst, 1); |
| 3470 | break; |
| 3471 | case kCondGT: |
| 3472 | if (gt_bias) { |
| 3473 | __ CmpUltS(FTMP, rhs, lhs); |
| 3474 | } else { |
| 3475 | __ CmpLtS(FTMP, rhs, lhs); |
| 3476 | } |
| 3477 | __ Mfc1(dst, FTMP); |
| 3478 | __ Andi(dst, dst, 1); |
| 3479 | break; |
| 3480 | case kCondGE: |
| 3481 | if (gt_bias) { |
| 3482 | __ CmpUleS(FTMP, rhs, lhs); |
| 3483 | } else { |
| 3484 | __ CmpLeS(FTMP, rhs, lhs); |
| 3485 | } |
| 3486 | __ Mfc1(dst, FTMP); |
| 3487 | __ Andi(dst, dst, 1); |
| 3488 | break; |
| 3489 | default: |
| 3490 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3491 | UNREACHABLE(); |
| 3492 | } |
| 3493 | } else { |
| 3494 | switch (cond) { |
| 3495 | case kCondEQ: |
| 3496 | __ CeqS(0, lhs, rhs); |
| 3497 | __ LoadConst32(dst, 1); |
| 3498 | __ Movf(dst, ZERO, 0); |
| 3499 | break; |
| 3500 | case kCondNE: |
| 3501 | __ CeqS(0, lhs, rhs); |
| 3502 | __ LoadConst32(dst, 1); |
| 3503 | __ Movt(dst, ZERO, 0); |
| 3504 | break; |
| 3505 | case kCondLT: |
| 3506 | if (gt_bias) { |
| 3507 | __ ColtS(0, lhs, rhs); |
| 3508 | } else { |
| 3509 | __ CultS(0, lhs, rhs); |
| 3510 | } |
| 3511 | __ LoadConst32(dst, 1); |
| 3512 | __ Movf(dst, ZERO, 0); |
| 3513 | break; |
| 3514 | case kCondLE: |
| 3515 | if (gt_bias) { |
| 3516 | __ ColeS(0, lhs, rhs); |
| 3517 | } else { |
| 3518 | __ CuleS(0, lhs, rhs); |
| 3519 | } |
| 3520 | __ LoadConst32(dst, 1); |
| 3521 | __ Movf(dst, ZERO, 0); |
| 3522 | break; |
| 3523 | case kCondGT: |
| 3524 | if (gt_bias) { |
| 3525 | __ CultS(0, rhs, lhs); |
| 3526 | } else { |
| 3527 | __ ColtS(0, rhs, lhs); |
| 3528 | } |
| 3529 | __ LoadConst32(dst, 1); |
| 3530 | __ Movf(dst, ZERO, 0); |
| 3531 | break; |
| 3532 | case kCondGE: |
| 3533 | if (gt_bias) { |
| 3534 | __ CuleS(0, rhs, lhs); |
| 3535 | } else { |
| 3536 | __ ColeS(0, rhs, lhs); |
| 3537 | } |
| 3538 | __ LoadConst32(dst, 1); |
| 3539 | __ Movf(dst, ZERO, 0); |
| 3540 | break; |
| 3541 | default: |
| 3542 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3543 | UNREACHABLE(); |
| 3544 | } |
| 3545 | } |
| 3546 | } else { |
| 3547 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 3548 | if (isR6) { |
| 3549 | switch (cond) { |
| 3550 | case kCondEQ: |
| 3551 | __ CmpEqD(FTMP, lhs, rhs); |
| 3552 | __ Mfc1(dst, FTMP); |
| 3553 | __ Andi(dst, dst, 1); |
| 3554 | break; |
| 3555 | case kCondNE: |
| 3556 | __ CmpEqD(FTMP, lhs, rhs); |
| 3557 | __ Mfc1(dst, FTMP); |
| 3558 | __ Addiu(dst, dst, 1); |
| 3559 | break; |
| 3560 | case kCondLT: |
| 3561 | if (gt_bias) { |
| 3562 | __ CmpLtD(FTMP, lhs, rhs); |
| 3563 | } else { |
| 3564 | __ CmpUltD(FTMP, lhs, rhs); |
| 3565 | } |
| 3566 | __ Mfc1(dst, FTMP); |
| 3567 | __ Andi(dst, dst, 1); |
| 3568 | break; |
| 3569 | case kCondLE: |
| 3570 | if (gt_bias) { |
| 3571 | __ CmpLeD(FTMP, lhs, rhs); |
| 3572 | } else { |
| 3573 | __ CmpUleD(FTMP, lhs, rhs); |
| 3574 | } |
| 3575 | __ Mfc1(dst, FTMP); |
| 3576 | __ Andi(dst, dst, 1); |
| 3577 | break; |
| 3578 | case kCondGT: |
| 3579 | if (gt_bias) { |
| 3580 | __ CmpUltD(FTMP, rhs, lhs); |
| 3581 | } else { |
| 3582 | __ CmpLtD(FTMP, rhs, lhs); |
| 3583 | } |
| 3584 | __ Mfc1(dst, FTMP); |
| 3585 | __ Andi(dst, dst, 1); |
| 3586 | break; |
| 3587 | case kCondGE: |
| 3588 | if (gt_bias) { |
| 3589 | __ CmpUleD(FTMP, rhs, lhs); |
| 3590 | } else { |
| 3591 | __ CmpLeD(FTMP, rhs, lhs); |
| 3592 | } |
| 3593 | __ Mfc1(dst, FTMP); |
| 3594 | __ Andi(dst, dst, 1); |
| 3595 | break; |
| 3596 | default: |
| 3597 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3598 | UNREACHABLE(); |
| 3599 | } |
| 3600 | } else { |
| 3601 | switch (cond) { |
| 3602 | case kCondEQ: |
| 3603 | __ CeqD(0, lhs, rhs); |
| 3604 | __ LoadConst32(dst, 1); |
| 3605 | __ Movf(dst, ZERO, 0); |
| 3606 | break; |
| 3607 | case kCondNE: |
| 3608 | __ CeqD(0, lhs, rhs); |
| 3609 | __ LoadConst32(dst, 1); |
| 3610 | __ Movt(dst, ZERO, 0); |
| 3611 | break; |
| 3612 | case kCondLT: |
| 3613 | if (gt_bias) { |
| 3614 | __ ColtD(0, lhs, rhs); |
| 3615 | } else { |
| 3616 | __ CultD(0, lhs, rhs); |
| 3617 | } |
| 3618 | __ LoadConst32(dst, 1); |
| 3619 | __ Movf(dst, ZERO, 0); |
| 3620 | break; |
| 3621 | case kCondLE: |
| 3622 | if (gt_bias) { |
| 3623 | __ ColeD(0, lhs, rhs); |
| 3624 | } else { |
| 3625 | __ CuleD(0, lhs, rhs); |
| 3626 | } |
| 3627 | __ LoadConst32(dst, 1); |
| 3628 | __ Movf(dst, ZERO, 0); |
| 3629 | break; |
| 3630 | case kCondGT: |
| 3631 | if (gt_bias) { |
| 3632 | __ CultD(0, rhs, lhs); |
| 3633 | } else { |
| 3634 | __ ColtD(0, rhs, lhs); |
| 3635 | } |
| 3636 | __ LoadConst32(dst, 1); |
| 3637 | __ Movf(dst, ZERO, 0); |
| 3638 | break; |
| 3639 | case kCondGE: |
| 3640 | if (gt_bias) { |
| 3641 | __ CuleD(0, rhs, lhs); |
| 3642 | } else { |
| 3643 | __ ColeD(0, rhs, lhs); |
| 3644 | } |
| 3645 | __ LoadConst32(dst, 1); |
| 3646 | __ Movf(dst, ZERO, 0); |
| 3647 | break; |
| 3648 | default: |
| 3649 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3650 | UNREACHABLE(); |
| 3651 | } |
| 3652 | } |
| 3653 | } |
| 3654 | } |
| 3655 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 3656 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR2(IfCondition cond, |
| 3657 | bool gt_bias, |
| 3658 | Primitive::Type type, |
| 3659 | LocationSummary* input_locations, |
| 3660 | int cc) { |
| 3661 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3662 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3663 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
| 3664 | if (type == Primitive::kPrimFloat) { |
| 3665 | switch (cond) { |
| 3666 | case kCondEQ: |
| 3667 | __ CeqS(cc, lhs, rhs); |
| 3668 | return false; |
| 3669 | case kCondNE: |
| 3670 | __ CeqS(cc, lhs, rhs); |
| 3671 | return true; |
| 3672 | case kCondLT: |
| 3673 | if (gt_bias) { |
| 3674 | __ ColtS(cc, lhs, rhs); |
| 3675 | } else { |
| 3676 | __ CultS(cc, lhs, rhs); |
| 3677 | } |
| 3678 | return false; |
| 3679 | case kCondLE: |
| 3680 | if (gt_bias) { |
| 3681 | __ ColeS(cc, lhs, rhs); |
| 3682 | } else { |
| 3683 | __ CuleS(cc, lhs, rhs); |
| 3684 | } |
| 3685 | return false; |
| 3686 | case kCondGT: |
| 3687 | if (gt_bias) { |
| 3688 | __ CultS(cc, rhs, lhs); |
| 3689 | } else { |
| 3690 | __ ColtS(cc, rhs, lhs); |
| 3691 | } |
| 3692 | return false; |
| 3693 | case kCondGE: |
| 3694 | if (gt_bias) { |
| 3695 | __ CuleS(cc, rhs, lhs); |
| 3696 | } else { |
| 3697 | __ ColeS(cc, rhs, lhs); |
| 3698 | } |
| 3699 | return false; |
| 3700 | default: |
| 3701 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3702 | UNREACHABLE(); |
| 3703 | } |
| 3704 | } else { |
| 3705 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 3706 | switch (cond) { |
| 3707 | case kCondEQ: |
| 3708 | __ CeqD(cc, lhs, rhs); |
| 3709 | return false; |
| 3710 | case kCondNE: |
| 3711 | __ CeqD(cc, lhs, rhs); |
| 3712 | return true; |
| 3713 | case kCondLT: |
| 3714 | if (gt_bias) { |
| 3715 | __ ColtD(cc, lhs, rhs); |
| 3716 | } else { |
| 3717 | __ CultD(cc, lhs, rhs); |
| 3718 | } |
| 3719 | return false; |
| 3720 | case kCondLE: |
| 3721 | if (gt_bias) { |
| 3722 | __ ColeD(cc, lhs, rhs); |
| 3723 | } else { |
| 3724 | __ CuleD(cc, lhs, rhs); |
| 3725 | } |
| 3726 | return false; |
| 3727 | case kCondGT: |
| 3728 | if (gt_bias) { |
| 3729 | __ CultD(cc, rhs, lhs); |
| 3730 | } else { |
| 3731 | __ ColtD(cc, rhs, lhs); |
| 3732 | } |
| 3733 | return false; |
| 3734 | case kCondGE: |
| 3735 | if (gt_bias) { |
| 3736 | __ CuleD(cc, rhs, lhs); |
| 3737 | } else { |
| 3738 | __ ColeD(cc, rhs, lhs); |
| 3739 | } |
| 3740 | return false; |
| 3741 | default: |
| 3742 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3743 | UNREACHABLE(); |
| 3744 | } |
| 3745 | } |
| 3746 | } |
| 3747 | |
| 3748 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR6(IfCondition cond, |
| 3749 | bool gt_bias, |
| 3750 | Primitive::Type type, |
| 3751 | LocationSummary* input_locations, |
| 3752 | FRegister dst) { |
| 3753 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3754 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3755 | CHECK(codegen_->GetInstructionSetFeatures().IsR6()); |
| 3756 | if (type == Primitive::kPrimFloat) { |
| 3757 | switch (cond) { |
| 3758 | case kCondEQ: |
| 3759 | __ CmpEqS(dst, lhs, rhs); |
| 3760 | return false; |
| 3761 | case kCondNE: |
| 3762 | __ CmpEqS(dst, lhs, rhs); |
| 3763 | return true; |
| 3764 | case kCondLT: |
| 3765 | if (gt_bias) { |
| 3766 | __ CmpLtS(dst, lhs, rhs); |
| 3767 | } else { |
| 3768 | __ CmpUltS(dst, lhs, rhs); |
| 3769 | } |
| 3770 | return false; |
| 3771 | case kCondLE: |
| 3772 | if (gt_bias) { |
| 3773 | __ CmpLeS(dst, lhs, rhs); |
| 3774 | } else { |
| 3775 | __ CmpUleS(dst, lhs, rhs); |
| 3776 | } |
| 3777 | return false; |
| 3778 | case kCondGT: |
| 3779 | if (gt_bias) { |
| 3780 | __ CmpUltS(dst, rhs, lhs); |
| 3781 | } else { |
| 3782 | __ CmpLtS(dst, rhs, lhs); |
| 3783 | } |
| 3784 | return false; |
| 3785 | case kCondGE: |
| 3786 | if (gt_bias) { |
| 3787 | __ CmpUleS(dst, rhs, lhs); |
| 3788 | } else { |
| 3789 | __ CmpLeS(dst, rhs, lhs); |
| 3790 | } |
| 3791 | return false; |
| 3792 | default: |
| 3793 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3794 | UNREACHABLE(); |
| 3795 | } |
| 3796 | } else { |
| 3797 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 3798 | switch (cond) { |
| 3799 | case kCondEQ: |
| 3800 | __ CmpEqD(dst, lhs, rhs); |
| 3801 | return false; |
| 3802 | case kCondNE: |
| 3803 | __ CmpEqD(dst, lhs, rhs); |
| 3804 | return true; |
| 3805 | case kCondLT: |
| 3806 | if (gt_bias) { |
| 3807 | __ CmpLtD(dst, lhs, rhs); |
| 3808 | } else { |
| 3809 | __ CmpUltD(dst, lhs, rhs); |
| 3810 | } |
| 3811 | return false; |
| 3812 | case kCondLE: |
| 3813 | if (gt_bias) { |
| 3814 | __ CmpLeD(dst, lhs, rhs); |
| 3815 | } else { |
| 3816 | __ CmpUleD(dst, lhs, rhs); |
| 3817 | } |
| 3818 | return false; |
| 3819 | case kCondGT: |
| 3820 | if (gt_bias) { |
| 3821 | __ CmpUltD(dst, rhs, lhs); |
| 3822 | } else { |
| 3823 | __ CmpLtD(dst, rhs, lhs); |
| 3824 | } |
| 3825 | return false; |
| 3826 | case kCondGE: |
| 3827 | if (gt_bias) { |
| 3828 | __ CmpUleD(dst, rhs, lhs); |
| 3829 | } else { |
| 3830 | __ CmpLeD(dst, rhs, lhs); |
| 3831 | } |
| 3832 | return false; |
| 3833 | default: |
| 3834 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3835 | UNREACHABLE(); |
| 3836 | } |
| 3837 | } |
| 3838 | } |
| 3839 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3840 | void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond, |
| 3841 | bool gt_bias, |
| 3842 | Primitive::Type type, |
| 3843 | LocationSummary* locations, |
| 3844 | MipsLabel* label) { |
| 3845 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3846 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3847 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3848 | if (type == Primitive::kPrimFloat) { |
| 3849 | if (isR6) { |
| 3850 | switch (cond) { |
| 3851 | case kCondEQ: |
| 3852 | __ CmpEqS(FTMP, lhs, rhs); |
| 3853 | __ Bc1nez(FTMP, label); |
| 3854 | break; |
| 3855 | case kCondNE: |
| 3856 | __ CmpEqS(FTMP, lhs, rhs); |
| 3857 | __ Bc1eqz(FTMP, label); |
| 3858 | break; |
| 3859 | case kCondLT: |
| 3860 | if (gt_bias) { |
| 3861 | __ CmpLtS(FTMP, lhs, rhs); |
| 3862 | } else { |
| 3863 | __ CmpUltS(FTMP, lhs, rhs); |
| 3864 | } |
| 3865 | __ Bc1nez(FTMP, label); |
| 3866 | break; |
| 3867 | case kCondLE: |
| 3868 | if (gt_bias) { |
| 3869 | __ CmpLeS(FTMP, lhs, rhs); |
| 3870 | } else { |
| 3871 | __ CmpUleS(FTMP, lhs, rhs); |
| 3872 | } |
| 3873 | __ Bc1nez(FTMP, label); |
| 3874 | break; |
| 3875 | case kCondGT: |
| 3876 | if (gt_bias) { |
| 3877 | __ CmpUltS(FTMP, rhs, lhs); |
| 3878 | } else { |
| 3879 | __ CmpLtS(FTMP, rhs, lhs); |
| 3880 | } |
| 3881 | __ Bc1nez(FTMP, label); |
| 3882 | break; |
| 3883 | case kCondGE: |
| 3884 | if (gt_bias) { |
| 3885 | __ CmpUleS(FTMP, rhs, lhs); |
| 3886 | } else { |
| 3887 | __ CmpLeS(FTMP, rhs, lhs); |
| 3888 | } |
| 3889 | __ Bc1nez(FTMP, label); |
| 3890 | break; |
| 3891 | default: |
| 3892 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 3893 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3894 | } |
| 3895 | } else { |
| 3896 | switch (cond) { |
| 3897 | case kCondEQ: |
| 3898 | __ CeqS(0, lhs, rhs); |
| 3899 | __ Bc1t(0, label); |
| 3900 | break; |
| 3901 | case kCondNE: |
| 3902 | __ CeqS(0, lhs, rhs); |
| 3903 | __ Bc1f(0, label); |
| 3904 | break; |
| 3905 | case kCondLT: |
| 3906 | if (gt_bias) { |
| 3907 | __ ColtS(0, lhs, rhs); |
| 3908 | } else { |
| 3909 | __ CultS(0, lhs, rhs); |
| 3910 | } |
| 3911 | __ Bc1t(0, label); |
| 3912 | break; |
| 3913 | case kCondLE: |
| 3914 | if (gt_bias) { |
| 3915 | __ ColeS(0, lhs, rhs); |
| 3916 | } else { |
| 3917 | __ CuleS(0, lhs, rhs); |
| 3918 | } |
| 3919 | __ Bc1t(0, label); |
| 3920 | break; |
| 3921 | case kCondGT: |
| 3922 | if (gt_bias) { |
| 3923 | __ CultS(0, rhs, lhs); |
| 3924 | } else { |
| 3925 | __ ColtS(0, rhs, lhs); |
| 3926 | } |
| 3927 | __ Bc1t(0, label); |
| 3928 | break; |
| 3929 | case kCondGE: |
| 3930 | if (gt_bias) { |
| 3931 | __ CuleS(0, rhs, lhs); |
| 3932 | } else { |
| 3933 | __ ColeS(0, rhs, lhs); |
| 3934 | } |
| 3935 | __ Bc1t(0, label); |
| 3936 | break; |
| 3937 | default: |
| 3938 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 3939 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3940 | } |
| 3941 | } |
| 3942 | } else { |
| 3943 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 3944 | if (isR6) { |
| 3945 | switch (cond) { |
| 3946 | case kCondEQ: |
| 3947 | __ CmpEqD(FTMP, lhs, rhs); |
| 3948 | __ Bc1nez(FTMP, label); |
| 3949 | break; |
| 3950 | case kCondNE: |
| 3951 | __ CmpEqD(FTMP, lhs, rhs); |
| 3952 | __ Bc1eqz(FTMP, label); |
| 3953 | break; |
| 3954 | case kCondLT: |
| 3955 | if (gt_bias) { |
| 3956 | __ CmpLtD(FTMP, lhs, rhs); |
| 3957 | } else { |
| 3958 | __ CmpUltD(FTMP, lhs, rhs); |
| 3959 | } |
| 3960 | __ Bc1nez(FTMP, label); |
| 3961 | break; |
| 3962 | case kCondLE: |
| 3963 | if (gt_bias) { |
| 3964 | __ CmpLeD(FTMP, lhs, rhs); |
| 3965 | } else { |
| 3966 | __ CmpUleD(FTMP, lhs, rhs); |
| 3967 | } |
| 3968 | __ Bc1nez(FTMP, label); |
| 3969 | break; |
| 3970 | case kCondGT: |
| 3971 | if (gt_bias) { |
| 3972 | __ CmpUltD(FTMP, rhs, lhs); |
| 3973 | } else { |
| 3974 | __ CmpLtD(FTMP, rhs, lhs); |
| 3975 | } |
| 3976 | __ Bc1nez(FTMP, label); |
| 3977 | break; |
| 3978 | case kCondGE: |
| 3979 | if (gt_bias) { |
| 3980 | __ CmpUleD(FTMP, rhs, lhs); |
| 3981 | } else { |
| 3982 | __ CmpLeD(FTMP, rhs, lhs); |
| 3983 | } |
| 3984 | __ Bc1nez(FTMP, label); |
| 3985 | break; |
| 3986 | default: |
| 3987 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 3988 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3989 | } |
| 3990 | } else { |
| 3991 | switch (cond) { |
| 3992 | case kCondEQ: |
| 3993 | __ CeqD(0, lhs, rhs); |
| 3994 | __ Bc1t(0, label); |
| 3995 | break; |
| 3996 | case kCondNE: |
| 3997 | __ CeqD(0, lhs, rhs); |
| 3998 | __ Bc1f(0, label); |
| 3999 | break; |
| 4000 | case kCondLT: |
| 4001 | if (gt_bias) { |
| 4002 | __ ColtD(0, lhs, rhs); |
| 4003 | } else { |
| 4004 | __ CultD(0, lhs, rhs); |
| 4005 | } |
| 4006 | __ Bc1t(0, label); |
| 4007 | break; |
| 4008 | case kCondLE: |
| 4009 | if (gt_bias) { |
| 4010 | __ ColeD(0, lhs, rhs); |
| 4011 | } else { |
| 4012 | __ CuleD(0, lhs, rhs); |
| 4013 | } |
| 4014 | __ Bc1t(0, label); |
| 4015 | break; |
| 4016 | case kCondGT: |
| 4017 | if (gt_bias) { |
| 4018 | __ CultD(0, rhs, lhs); |
| 4019 | } else { |
| 4020 | __ ColtD(0, rhs, lhs); |
| 4021 | } |
| 4022 | __ Bc1t(0, label); |
| 4023 | break; |
| 4024 | case kCondGE: |
| 4025 | if (gt_bias) { |
| 4026 | __ CuleD(0, rhs, lhs); |
| 4027 | } else { |
| 4028 | __ ColeD(0, rhs, lhs); |
| 4029 | } |
| 4030 | __ Bc1t(0, label); |
| 4031 | break; |
| 4032 | default: |
| 4033 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4034 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4035 | } |
| 4036 | } |
| 4037 | } |
| 4038 | } |
| 4039 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4040 | void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4041 | size_t condition_input_index, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4042 | MipsLabel* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4043 | MipsLabel* false_target) { |
| 4044 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4045 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4046 | if (true_target == nullptr && false_target == nullptr) { |
| 4047 | // Nothing to do. The code always falls through. |
| 4048 | return; |
| 4049 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 4050 | // Constant condition, statically compared against "true" (integer value 1). |
| 4051 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4052 | if (true_target != nullptr) { |
| 4053 | __ B(true_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4054 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4055 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 4056 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4057 | if (false_target != nullptr) { |
| 4058 | __ B(false_target); |
| 4059 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4060 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4061 | return; |
| 4062 | } |
| 4063 | |
| 4064 | // The following code generates these patterns: |
| 4065 | // (1) true_target == nullptr && false_target != nullptr |
| 4066 | // - opposite condition true => branch to false_target |
| 4067 | // (2) true_target != nullptr && false_target == nullptr |
| 4068 | // - condition true => branch to true_target |
| 4069 | // (3) true_target != nullptr && false_target != nullptr |
| 4070 | // - condition true => branch to true_target |
| 4071 | // - branch to false_target |
| 4072 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4073 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4074 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4075 | DCHECK(cond_val.IsRegister()); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4076 | if (true_target == nullptr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4077 | __ Beqz(cond_val.AsRegister<Register>(), false_target); |
| 4078 | } else { |
| 4079 | __ Bnez(cond_val.AsRegister<Register>(), true_target); |
| 4080 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4081 | } else { |
| 4082 | // The condition instruction has not been materialized, use its inputs as |
| 4083 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4084 | HCondition* condition = cond->AsCondition(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4085 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 4086 | LocationSummary* locations = cond->GetLocations(); |
| 4087 | IfCondition if_cond = condition->GetCondition(); |
| 4088 | MipsLabel* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4089 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4090 | if (true_target == nullptr) { |
| 4091 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4092 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4093 | } |
| 4094 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4095 | switch (type) { |
| 4096 | default: |
| 4097 | GenerateIntCompareAndBranch(if_cond, locations, branch_target); |
| 4098 | break; |
| 4099 | case Primitive::kPrimLong: |
| 4100 | GenerateLongCompareAndBranch(if_cond, locations, branch_target); |
| 4101 | break; |
| 4102 | case Primitive::kPrimFloat: |
| 4103 | case Primitive::kPrimDouble: |
| 4104 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 4105 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4106 | } |
| 4107 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4108 | |
| 4109 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 4110 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 4111 | if (true_target != nullptr && false_target != nullptr) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4112 | __ B(false_target); |
| 4113 | } |
| 4114 | } |
| 4115 | |
| 4116 | void LocationsBuilderMIPS::VisitIf(HIf* if_instr) { |
| 4117 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4118 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4119 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4120 | } |
| 4121 | } |
| 4122 | |
| 4123 | void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4124 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 4125 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 4126 | MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 4127 | nullptr : codegen_->GetLabelOf(true_successor); |
| 4128 | MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 4129 | nullptr : codegen_->GetLabelOf(false_successor); |
| 4130 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4131 | } |
| 4132 | |
| 4133 | void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 4134 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 4135 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4136 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4137 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4138 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4139 | } |
| 4140 | } |
| 4141 | |
| 4142 | void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 4143 | SlowPathCodeMIPS* slow_path = |
| 4144 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4145 | GenerateTestAndBranch(deoptimize, |
| 4146 | /* condition_input_index */ 0, |
| 4147 | slow_path->GetEntryLabel(), |
| 4148 | /* false_target */ nullptr); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4149 | } |
| 4150 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4151 | // This function returns true if a conditional move can be generated for HSelect. |
| 4152 | // Otherwise it returns false and HSelect must be implemented in terms of conditonal |
| 4153 | // branches and regular moves. |
| 4154 | // |
| 4155 | // If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect. |
| 4156 | // |
| 4157 | // While determining feasibility of a conditional move and setting inputs/outputs |
| 4158 | // are two distinct tasks, this function does both because they share quite a bit |
| 4159 | // of common logic. |
| 4160 | static bool CanMoveConditionally(HSelect* select, bool is_r6, LocationSummary* locations_to_set) { |
| 4161 | bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition()); |
| 4162 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4163 | HCondition* condition = cond->AsCondition(); |
| 4164 | |
| 4165 | Primitive::Type cond_type = materialized ? Primitive::kPrimInt : condition->InputAt(0)->GetType(); |
| 4166 | Primitive::Type dst_type = select->GetType(); |
| 4167 | |
| 4168 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 4169 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 4170 | bool is_true_value_zero_constant = |
| 4171 | (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern()); |
| 4172 | bool is_false_value_zero_constant = |
| 4173 | (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern()); |
| 4174 | |
| 4175 | bool can_move_conditionally = false; |
| 4176 | bool use_const_for_false_in = false; |
| 4177 | bool use_const_for_true_in = false; |
| 4178 | |
| 4179 | if (!cond->IsConstant()) { |
| 4180 | switch (cond_type) { |
| 4181 | default: |
| 4182 | switch (dst_type) { |
| 4183 | default: |
| 4184 | // Moving int on int condition. |
| 4185 | if (is_r6) { |
| 4186 | if (is_true_value_zero_constant) { |
| 4187 | // seleqz out_reg, false_reg, cond_reg |
| 4188 | can_move_conditionally = true; |
| 4189 | use_const_for_true_in = true; |
| 4190 | } else if (is_false_value_zero_constant) { |
| 4191 | // selnez out_reg, true_reg, cond_reg |
| 4192 | can_move_conditionally = true; |
| 4193 | use_const_for_false_in = true; |
| 4194 | } else if (materialized) { |
| 4195 | // Not materializing unmaterialized int conditions |
| 4196 | // to keep the instruction count low. |
| 4197 | // selnez AT, true_reg, cond_reg |
| 4198 | // seleqz TMP, false_reg, cond_reg |
| 4199 | // or out_reg, AT, TMP |
| 4200 | can_move_conditionally = true; |
| 4201 | } |
| 4202 | } else { |
| 4203 | // movn out_reg, true_reg/ZERO, cond_reg |
| 4204 | can_move_conditionally = true; |
| 4205 | use_const_for_true_in = is_true_value_zero_constant; |
| 4206 | } |
| 4207 | break; |
| 4208 | case Primitive::kPrimLong: |
| 4209 | // Moving long on int condition. |
| 4210 | if (is_r6) { |
| 4211 | if (is_true_value_zero_constant) { |
| 4212 | // seleqz out_reg_lo, false_reg_lo, cond_reg |
| 4213 | // seleqz out_reg_hi, false_reg_hi, cond_reg |
| 4214 | can_move_conditionally = true; |
| 4215 | use_const_for_true_in = true; |
| 4216 | } else if (is_false_value_zero_constant) { |
| 4217 | // selnez out_reg_lo, true_reg_lo, cond_reg |
| 4218 | // selnez out_reg_hi, true_reg_hi, cond_reg |
| 4219 | can_move_conditionally = true; |
| 4220 | use_const_for_false_in = true; |
| 4221 | } |
| 4222 | // Other long conditional moves would generate 6+ instructions, |
| 4223 | // which is too many. |
| 4224 | } else { |
| 4225 | // movn out_reg_lo, true_reg_lo/ZERO, cond_reg |
| 4226 | // movn out_reg_hi, true_reg_hi/ZERO, cond_reg |
| 4227 | can_move_conditionally = true; |
| 4228 | use_const_for_true_in = is_true_value_zero_constant; |
| 4229 | } |
| 4230 | break; |
| 4231 | case Primitive::kPrimFloat: |
| 4232 | case Primitive::kPrimDouble: |
| 4233 | // Moving float/double on int condition. |
| 4234 | if (is_r6) { |
| 4235 | if (materialized) { |
| 4236 | // Not materializing unmaterialized int conditions |
| 4237 | // to keep the instruction count low. |
| 4238 | can_move_conditionally = true; |
| 4239 | if (is_true_value_zero_constant) { |
| 4240 | // sltu TMP, ZERO, cond_reg |
| 4241 | // mtc1 TMP, temp_cond_reg |
| 4242 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 4243 | use_const_for_true_in = true; |
| 4244 | } else if (is_false_value_zero_constant) { |
| 4245 | // sltu TMP, ZERO, cond_reg |
| 4246 | // mtc1 TMP, temp_cond_reg |
| 4247 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 4248 | use_const_for_false_in = true; |
| 4249 | } else { |
| 4250 | // sltu TMP, ZERO, cond_reg |
| 4251 | // mtc1 TMP, temp_cond_reg |
| 4252 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 4253 | // mov.fmt out_reg, temp_cond_reg |
| 4254 | } |
| 4255 | } |
| 4256 | } else { |
| 4257 | // movn.fmt out_reg, true_reg, cond_reg |
| 4258 | can_move_conditionally = true; |
| 4259 | } |
| 4260 | break; |
| 4261 | } |
| 4262 | break; |
| 4263 | case Primitive::kPrimLong: |
| 4264 | // We don't materialize long comparison now |
| 4265 | // and use conditional branches instead. |
| 4266 | break; |
| 4267 | case Primitive::kPrimFloat: |
| 4268 | case Primitive::kPrimDouble: |
| 4269 | switch (dst_type) { |
| 4270 | default: |
| 4271 | // Moving int on float/double condition. |
| 4272 | if (is_r6) { |
| 4273 | if (is_true_value_zero_constant) { |
| 4274 | // mfc1 TMP, temp_cond_reg |
| 4275 | // seleqz out_reg, false_reg, TMP |
| 4276 | can_move_conditionally = true; |
| 4277 | use_const_for_true_in = true; |
| 4278 | } else if (is_false_value_zero_constant) { |
| 4279 | // mfc1 TMP, temp_cond_reg |
| 4280 | // selnez out_reg, true_reg, TMP |
| 4281 | can_move_conditionally = true; |
| 4282 | use_const_for_false_in = true; |
| 4283 | } else { |
| 4284 | // mfc1 TMP, temp_cond_reg |
| 4285 | // selnez AT, true_reg, TMP |
| 4286 | // seleqz TMP, false_reg, TMP |
| 4287 | // or out_reg, AT, TMP |
| 4288 | can_move_conditionally = true; |
| 4289 | } |
| 4290 | } else { |
| 4291 | // movt out_reg, true_reg/ZERO, cc |
| 4292 | can_move_conditionally = true; |
| 4293 | use_const_for_true_in = is_true_value_zero_constant; |
| 4294 | } |
| 4295 | break; |
| 4296 | case Primitive::kPrimLong: |
| 4297 | // Moving long on float/double condition. |
| 4298 | if (is_r6) { |
| 4299 | if (is_true_value_zero_constant) { |
| 4300 | // mfc1 TMP, temp_cond_reg |
| 4301 | // seleqz out_reg_lo, false_reg_lo, TMP |
| 4302 | // seleqz out_reg_hi, false_reg_hi, TMP |
| 4303 | can_move_conditionally = true; |
| 4304 | use_const_for_true_in = true; |
| 4305 | } else if (is_false_value_zero_constant) { |
| 4306 | // mfc1 TMP, temp_cond_reg |
| 4307 | // selnez out_reg_lo, true_reg_lo, TMP |
| 4308 | // selnez out_reg_hi, true_reg_hi, TMP |
| 4309 | can_move_conditionally = true; |
| 4310 | use_const_for_false_in = true; |
| 4311 | } |
| 4312 | // Other long conditional moves would generate 6+ instructions, |
| 4313 | // which is too many. |
| 4314 | } else { |
| 4315 | // movt out_reg_lo, true_reg_lo/ZERO, cc |
| 4316 | // movt out_reg_hi, true_reg_hi/ZERO, cc |
| 4317 | can_move_conditionally = true; |
| 4318 | use_const_for_true_in = is_true_value_zero_constant; |
| 4319 | } |
| 4320 | break; |
| 4321 | case Primitive::kPrimFloat: |
| 4322 | case Primitive::kPrimDouble: |
| 4323 | // Moving float/double on float/double condition. |
| 4324 | if (is_r6) { |
| 4325 | can_move_conditionally = true; |
| 4326 | if (is_true_value_zero_constant) { |
| 4327 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 4328 | use_const_for_true_in = true; |
| 4329 | } else if (is_false_value_zero_constant) { |
| 4330 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 4331 | use_const_for_false_in = true; |
| 4332 | } else { |
| 4333 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 4334 | // mov.fmt out_reg, temp_cond_reg |
| 4335 | } |
| 4336 | } else { |
| 4337 | // movt.fmt out_reg, true_reg, cc |
| 4338 | can_move_conditionally = true; |
| 4339 | } |
| 4340 | break; |
| 4341 | } |
| 4342 | break; |
| 4343 | } |
| 4344 | } |
| 4345 | |
| 4346 | if (can_move_conditionally) { |
| 4347 | DCHECK(!use_const_for_false_in || !use_const_for_true_in); |
| 4348 | } else { |
| 4349 | DCHECK(!use_const_for_false_in); |
| 4350 | DCHECK(!use_const_for_true_in); |
| 4351 | } |
| 4352 | |
| 4353 | if (locations_to_set != nullptr) { |
| 4354 | if (use_const_for_false_in) { |
| 4355 | locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value)); |
| 4356 | } else { |
| 4357 | locations_to_set->SetInAt(0, |
| 4358 | Primitive::IsFloatingPointType(dst_type) |
| 4359 | ? Location::RequiresFpuRegister() |
| 4360 | : Location::RequiresRegister()); |
| 4361 | } |
| 4362 | if (use_const_for_true_in) { |
| 4363 | locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value)); |
| 4364 | } else { |
| 4365 | locations_to_set->SetInAt(1, |
| 4366 | Primitive::IsFloatingPointType(dst_type) |
| 4367 | ? Location::RequiresFpuRegister() |
| 4368 | : Location::RequiresRegister()); |
| 4369 | } |
| 4370 | if (materialized) { |
| 4371 | locations_to_set->SetInAt(2, Location::RequiresRegister()); |
| 4372 | } |
| 4373 | // On R6 we don't require the output to be the same as the |
| 4374 | // first input for conditional moves unlike on R2. |
| 4375 | bool is_out_same_as_first_in = !can_move_conditionally || !is_r6; |
| 4376 | if (is_out_same_as_first_in) { |
| 4377 | locations_to_set->SetOut(Location::SameAsFirstInput()); |
| 4378 | } else { |
| 4379 | locations_to_set->SetOut(Primitive::IsFloatingPointType(dst_type) |
| 4380 | ? Location::RequiresFpuRegister() |
| 4381 | : Location::RequiresRegister()); |
| 4382 | } |
| 4383 | } |
| 4384 | |
| 4385 | return can_move_conditionally; |
| 4386 | } |
| 4387 | |
| 4388 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR2(HSelect* select) { |
| 4389 | LocationSummary* locations = select->GetLocations(); |
| 4390 | Location dst = locations->Out(); |
| 4391 | Location src = locations->InAt(1); |
| 4392 | Register src_reg = ZERO; |
| 4393 | Register src_reg_high = ZERO; |
| 4394 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4395 | Register cond_reg = TMP; |
| 4396 | int cond_cc = 0; |
| 4397 | Primitive::Type cond_type = Primitive::kPrimInt; |
| 4398 | bool cond_inverted = false; |
| 4399 | Primitive::Type dst_type = select->GetType(); |
| 4400 | |
| 4401 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 4402 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 4403 | } else { |
| 4404 | HCondition* condition = cond->AsCondition(); |
| 4405 | LocationSummary* cond_locations = cond->GetLocations(); |
| 4406 | IfCondition if_cond = condition->GetCondition(); |
| 4407 | cond_type = condition->InputAt(0)->GetType(); |
| 4408 | switch (cond_type) { |
| 4409 | default: |
| 4410 | DCHECK_NE(cond_type, Primitive::kPrimLong); |
| 4411 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 4412 | break; |
| 4413 | case Primitive::kPrimFloat: |
| 4414 | case Primitive::kPrimDouble: |
| 4415 | cond_inverted = MaterializeFpCompareR2(if_cond, |
| 4416 | condition->IsGtBias(), |
| 4417 | cond_type, |
| 4418 | cond_locations, |
| 4419 | cond_cc); |
| 4420 | break; |
| 4421 | } |
| 4422 | } |
| 4423 | |
| 4424 | DCHECK(dst.Equals(locations->InAt(0))); |
| 4425 | if (src.IsRegister()) { |
| 4426 | src_reg = src.AsRegister<Register>(); |
| 4427 | } else if (src.IsRegisterPair()) { |
| 4428 | src_reg = src.AsRegisterPairLow<Register>(); |
| 4429 | src_reg_high = src.AsRegisterPairHigh<Register>(); |
| 4430 | } else if (src.IsConstant()) { |
| 4431 | DCHECK(src.GetConstant()->IsZeroBitPattern()); |
| 4432 | } |
| 4433 | |
| 4434 | switch (cond_type) { |
| 4435 | default: |
| 4436 | switch (dst_type) { |
| 4437 | default: |
| 4438 | if (cond_inverted) { |
| 4439 | __ Movz(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 4440 | } else { |
| 4441 | __ Movn(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 4442 | } |
| 4443 | break; |
| 4444 | case Primitive::kPrimLong: |
| 4445 | if (cond_inverted) { |
| 4446 | __ Movz(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 4447 | __ Movz(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 4448 | } else { |
| 4449 | __ Movn(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 4450 | __ Movn(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 4451 | } |
| 4452 | break; |
| 4453 | case Primitive::kPrimFloat: |
| 4454 | if (cond_inverted) { |
| 4455 | __ MovzS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 4456 | } else { |
| 4457 | __ MovnS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 4458 | } |
| 4459 | break; |
| 4460 | case Primitive::kPrimDouble: |
| 4461 | if (cond_inverted) { |
| 4462 | __ MovzD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 4463 | } else { |
| 4464 | __ MovnD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 4465 | } |
| 4466 | break; |
| 4467 | } |
| 4468 | break; |
| 4469 | case Primitive::kPrimLong: |
| 4470 | LOG(FATAL) << "Unreachable"; |
| 4471 | UNREACHABLE(); |
| 4472 | case Primitive::kPrimFloat: |
| 4473 | case Primitive::kPrimDouble: |
| 4474 | switch (dst_type) { |
| 4475 | default: |
| 4476 | if (cond_inverted) { |
| 4477 | __ Movf(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 4478 | } else { |
| 4479 | __ Movt(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 4480 | } |
| 4481 | break; |
| 4482 | case Primitive::kPrimLong: |
| 4483 | if (cond_inverted) { |
| 4484 | __ Movf(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 4485 | __ Movf(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 4486 | } else { |
| 4487 | __ Movt(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 4488 | __ Movt(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 4489 | } |
| 4490 | break; |
| 4491 | case Primitive::kPrimFloat: |
| 4492 | if (cond_inverted) { |
| 4493 | __ MovfS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 4494 | } else { |
| 4495 | __ MovtS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 4496 | } |
| 4497 | break; |
| 4498 | case Primitive::kPrimDouble: |
| 4499 | if (cond_inverted) { |
| 4500 | __ MovfD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 4501 | } else { |
| 4502 | __ MovtD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 4503 | } |
| 4504 | break; |
| 4505 | } |
| 4506 | break; |
| 4507 | } |
| 4508 | } |
| 4509 | |
| 4510 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR6(HSelect* select) { |
| 4511 | LocationSummary* locations = select->GetLocations(); |
| 4512 | Location dst = locations->Out(); |
| 4513 | Location false_src = locations->InAt(0); |
| 4514 | Location true_src = locations->InAt(1); |
| 4515 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4516 | Register cond_reg = TMP; |
| 4517 | FRegister fcond_reg = FTMP; |
| 4518 | Primitive::Type cond_type = Primitive::kPrimInt; |
| 4519 | bool cond_inverted = false; |
| 4520 | Primitive::Type dst_type = select->GetType(); |
| 4521 | |
| 4522 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 4523 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 4524 | } else { |
| 4525 | HCondition* condition = cond->AsCondition(); |
| 4526 | LocationSummary* cond_locations = cond->GetLocations(); |
| 4527 | IfCondition if_cond = condition->GetCondition(); |
| 4528 | cond_type = condition->InputAt(0)->GetType(); |
| 4529 | switch (cond_type) { |
| 4530 | default: |
| 4531 | DCHECK_NE(cond_type, Primitive::kPrimLong); |
| 4532 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 4533 | break; |
| 4534 | case Primitive::kPrimFloat: |
| 4535 | case Primitive::kPrimDouble: |
| 4536 | cond_inverted = MaterializeFpCompareR6(if_cond, |
| 4537 | condition->IsGtBias(), |
| 4538 | cond_type, |
| 4539 | cond_locations, |
| 4540 | fcond_reg); |
| 4541 | break; |
| 4542 | } |
| 4543 | } |
| 4544 | |
| 4545 | if (true_src.IsConstant()) { |
| 4546 | DCHECK(true_src.GetConstant()->IsZeroBitPattern()); |
| 4547 | } |
| 4548 | if (false_src.IsConstant()) { |
| 4549 | DCHECK(false_src.GetConstant()->IsZeroBitPattern()); |
| 4550 | } |
| 4551 | |
| 4552 | switch (dst_type) { |
| 4553 | default: |
| 4554 | if (Primitive::IsFloatingPointType(cond_type)) { |
| 4555 | __ Mfc1(cond_reg, fcond_reg); |
| 4556 | } |
| 4557 | if (true_src.IsConstant()) { |
| 4558 | if (cond_inverted) { |
| 4559 | __ Selnez(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 4560 | } else { |
| 4561 | __ Seleqz(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 4562 | } |
| 4563 | } else if (false_src.IsConstant()) { |
| 4564 | if (cond_inverted) { |
| 4565 | __ Seleqz(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 4566 | } else { |
| 4567 | __ Selnez(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 4568 | } |
| 4569 | } else { |
| 4570 | DCHECK_NE(cond_reg, AT); |
| 4571 | if (cond_inverted) { |
| 4572 | __ Seleqz(AT, true_src.AsRegister<Register>(), cond_reg); |
| 4573 | __ Selnez(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 4574 | } else { |
| 4575 | __ Selnez(AT, true_src.AsRegister<Register>(), cond_reg); |
| 4576 | __ Seleqz(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 4577 | } |
| 4578 | __ Or(dst.AsRegister<Register>(), AT, TMP); |
| 4579 | } |
| 4580 | break; |
| 4581 | case Primitive::kPrimLong: { |
| 4582 | if (Primitive::IsFloatingPointType(cond_type)) { |
| 4583 | __ Mfc1(cond_reg, fcond_reg); |
| 4584 | } |
| 4585 | Register dst_lo = dst.AsRegisterPairLow<Register>(); |
| 4586 | Register dst_hi = dst.AsRegisterPairHigh<Register>(); |
| 4587 | if (true_src.IsConstant()) { |
| 4588 | Register src_lo = false_src.AsRegisterPairLow<Register>(); |
| 4589 | Register src_hi = false_src.AsRegisterPairHigh<Register>(); |
| 4590 | if (cond_inverted) { |
| 4591 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 4592 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 4593 | } else { |
| 4594 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 4595 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 4596 | } |
| 4597 | } else { |
| 4598 | DCHECK(false_src.IsConstant()); |
| 4599 | Register src_lo = true_src.AsRegisterPairLow<Register>(); |
| 4600 | Register src_hi = true_src.AsRegisterPairHigh<Register>(); |
| 4601 | if (cond_inverted) { |
| 4602 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 4603 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 4604 | } else { |
| 4605 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 4606 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 4607 | } |
| 4608 | } |
| 4609 | break; |
| 4610 | } |
| 4611 | case Primitive::kPrimFloat: { |
| 4612 | if (!Primitive::IsFloatingPointType(cond_type)) { |
| 4613 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 4614 | __ Sltu(TMP, ZERO, cond_reg); |
| 4615 | __ Mtc1(TMP, fcond_reg); |
| 4616 | } |
| 4617 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 4618 | if (true_src.IsConstant()) { |
| 4619 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 4620 | if (cond_inverted) { |
| 4621 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 4622 | } else { |
| 4623 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 4624 | } |
| 4625 | } else if (false_src.IsConstant()) { |
| 4626 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 4627 | if (cond_inverted) { |
| 4628 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 4629 | } else { |
| 4630 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 4631 | } |
| 4632 | } else { |
| 4633 | if (cond_inverted) { |
| 4634 | __ SelS(fcond_reg, |
| 4635 | true_src.AsFpuRegister<FRegister>(), |
| 4636 | false_src.AsFpuRegister<FRegister>()); |
| 4637 | } else { |
| 4638 | __ SelS(fcond_reg, |
| 4639 | false_src.AsFpuRegister<FRegister>(), |
| 4640 | true_src.AsFpuRegister<FRegister>()); |
| 4641 | } |
| 4642 | __ MovS(dst_reg, fcond_reg); |
| 4643 | } |
| 4644 | break; |
| 4645 | } |
| 4646 | case Primitive::kPrimDouble: { |
| 4647 | if (!Primitive::IsFloatingPointType(cond_type)) { |
| 4648 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 4649 | __ Sltu(TMP, ZERO, cond_reg); |
| 4650 | __ Mtc1(TMP, fcond_reg); |
| 4651 | } |
| 4652 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 4653 | if (true_src.IsConstant()) { |
| 4654 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 4655 | if (cond_inverted) { |
| 4656 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 4657 | } else { |
| 4658 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 4659 | } |
| 4660 | } else if (false_src.IsConstant()) { |
| 4661 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 4662 | if (cond_inverted) { |
| 4663 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 4664 | } else { |
| 4665 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 4666 | } |
| 4667 | } else { |
| 4668 | if (cond_inverted) { |
| 4669 | __ SelD(fcond_reg, |
| 4670 | true_src.AsFpuRegister<FRegister>(), |
| 4671 | false_src.AsFpuRegister<FRegister>()); |
| 4672 | } else { |
| 4673 | __ SelD(fcond_reg, |
| 4674 | false_src.AsFpuRegister<FRegister>(), |
| 4675 | true_src.AsFpuRegister<FRegister>()); |
| 4676 | } |
| 4677 | __ MovD(dst_reg, fcond_reg); |
| 4678 | } |
| 4679 | break; |
| 4680 | } |
| 4681 | } |
| 4682 | } |
| 4683 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4684 | void LocationsBuilderMIPS::VisitSelect(HSelect* select) { |
| 4685 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4686 | CanMoveConditionally(select, codegen_->GetInstructionSetFeatures().IsR6(), locations); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4687 | } |
| 4688 | |
| 4689 | void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4690 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4691 | if (CanMoveConditionally(select, is_r6, /* locations_to_set */ nullptr)) { |
| 4692 | if (is_r6) { |
| 4693 | GenConditionalMoveR6(select); |
| 4694 | } else { |
| 4695 | GenConditionalMoveR2(select); |
| 4696 | } |
| 4697 | } else { |
| 4698 | LocationSummary* locations = select->GetLocations(); |
| 4699 | MipsLabel false_target; |
| 4700 | GenerateTestAndBranch(select, |
| 4701 | /* condition_input_index */ 2, |
| 4702 | /* true_target */ nullptr, |
| 4703 | &false_target); |
| 4704 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 4705 | __ Bind(&false_target); |
| 4706 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4707 | } |
| 4708 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4709 | void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 4710 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 4711 | } |
| 4712 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 4713 | void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 4714 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 4715 | } |
| 4716 | |
| 4717 | void CodeGeneratorMIPS::GenerateNop() { |
| 4718 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4719 | } |
| 4720 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4721 | void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4722 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4723 | bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble); |
| 4724 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
| 4725 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4726 | instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4727 | |
| 4728 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4729 | if (generate_volatile) { |
| 4730 | InvokeRuntimeCallingConvention calling_convention; |
| 4731 | // need A0 to hold base + offset |
| 4732 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4733 | if (field_type == Primitive::kPrimLong) { |
| 4734 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimLong)); |
| 4735 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4736 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 4737 | locations->SetOut(Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4738 | // Need some temp core regs since FP results are returned in core registers |
| 4739 | Location reg = calling_convention.GetReturnLocation(Primitive::kPrimLong); |
| 4740 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>())); |
| 4741 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>())); |
| 4742 | } |
| 4743 | } else { |
| 4744 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4745 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4746 | } else { |
| 4747 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4748 | } |
| 4749 | } |
| 4750 | } |
| 4751 | |
| 4752 | void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction, |
| 4753 | const FieldInfo& field_info, |
| 4754 | uint32_t dex_pc) { |
| 4755 | Primitive::Type type = field_info.GetFieldType(); |
| 4756 | LocationSummary* locations = instruction->GetLocations(); |
| 4757 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4758 | LoadOperandType load_type = kLoadUnsignedByte; |
| 4759 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 4760 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4761 | auto null_checker = GetImplicitNullChecker(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4762 | |
| 4763 | switch (type) { |
| 4764 | case Primitive::kPrimBoolean: |
| 4765 | load_type = kLoadUnsignedByte; |
| 4766 | break; |
| 4767 | case Primitive::kPrimByte: |
| 4768 | load_type = kLoadSignedByte; |
| 4769 | break; |
| 4770 | case Primitive::kPrimShort: |
| 4771 | load_type = kLoadSignedHalfword; |
| 4772 | break; |
| 4773 | case Primitive::kPrimChar: |
| 4774 | load_type = kLoadUnsignedHalfword; |
| 4775 | break; |
| 4776 | case Primitive::kPrimInt: |
| 4777 | case Primitive::kPrimFloat: |
| 4778 | case Primitive::kPrimNot: |
| 4779 | load_type = kLoadWord; |
| 4780 | break; |
| 4781 | case Primitive::kPrimLong: |
| 4782 | case Primitive::kPrimDouble: |
| 4783 | load_type = kLoadDoubleword; |
| 4784 | break; |
| 4785 | case Primitive::kPrimVoid: |
| 4786 | LOG(FATAL) << "Unreachable type " << type; |
| 4787 | UNREACHABLE(); |
| 4788 | } |
| 4789 | |
| 4790 | if (is_volatile && load_type == kLoadDoubleword) { |
| 4791 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 4792 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4793 | // Do implicit Null check |
| 4794 | __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0); |
| 4795 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 4796 | codegen_->InvokeRuntime(kQuickA64Load, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4797 | CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>(); |
| 4798 | if (type == Primitive::kPrimDouble) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4799 | // FP results are returned in core registers. Need to move them. |
| 4800 | Location out = locations->Out(); |
| 4801 | if (out.IsFpuRegister()) { |
| 4802 | __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), out.AsFpuRegister<FRegister>()); |
| 4803 | __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
| 4804 | out.AsFpuRegister<FRegister>()); |
| 4805 | } else { |
| 4806 | DCHECK(out.IsDoubleStackSlot()); |
| 4807 | __ StoreToOffset(kStoreWord, |
| 4808 | locations->GetTemp(1).AsRegister<Register>(), |
| 4809 | SP, |
| 4810 | out.GetStackIndex()); |
| 4811 | __ StoreToOffset(kStoreWord, |
| 4812 | locations->GetTemp(2).AsRegister<Register>(), |
| 4813 | SP, |
| 4814 | out.GetStackIndex() + 4); |
| 4815 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4816 | } |
| 4817 | } else { |
| 4818 | if (!Primitive::IsFloatingPointType(type)) { |
| 4819 | Register dst; |
| 4820 | if (type == Primitive::kPrimLong) { |
| 4821 | DCHECK(locations->Out().IsRegisterPair()); |
| 4822 | dst = locations->Out().AsRegisterPairLow<Register>(); |
| 4823 | } else { |
| 4824 | DCHECK(locations->Out().IsRegister()); |
| 4825 | dst = locations->Out().AsRegister<Register>(); |
| 4826 | } |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4827 | __ LoadFromOffset(load_type, dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4828 | } else { |
| 4829 | DCHECK(locations->Out().IsFpuRegister()); |
| 4830 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 4831 | if (type == Primitive::kPrimFloat) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4832 | __ LoadSFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4833 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4834 | __ LoadDFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4835 | } |
| 4836 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4837 | } |
| 4838 | |
| 4839 | if (is_volatile) { |
| 4840 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4841 | } |
| 4842 | } |
| 4843 | |
| 4844 | void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4845 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4846 | bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble); |
| 4847 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
| 4848 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4849 | instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4850 | |
| 4851 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4852 | if (generate_volatile) { |
| 4853 | InvokeRuntimeCallingConvention calling_convention; |
| 4854 | // need A0 to hold base + offset |
| 4855 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4856 | if (field_type == Primitive::kPrimLong) { |
| 4857 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4858 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4859 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4860 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 4861 | locations->SetInAt(1, Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4862 | // Pass FP parameters in core registers. |
| 4863 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 4864 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3))); |
| 4865 | } |
| 4866 | } else { |
| 4867 | if (Primitive::IsFloatingPointType(field_type)) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4868 | locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4869 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4870 | locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4871 | } |
| 4872 | } |
| 4873 | } |
| 4874 | |
| 4875 | void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction, |
| 4876 | const FieldInfo& field_info, |
| 4877 | uint32_t dex_pc) { |
| 4878 | Primitive::Type type = field_info.GetFieldType(); |
| 4879 | LocationSummary* locations = instruction->GetLocations(); |
| 4880 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4881 | Location value_location = locations->InAt(1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4882 | StoreOperandType store_type = kStoreByte; |
| 4883 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 4884 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4885 | auto null_checker = GetImplicitNullChecker(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4886 | |
| 4887 | switch (type) { |
| 4888 | case Primitive::kPrimBoolean: |
| 4889 | case Primitive::kPrimByte: |
| 4890 | store_type = kStoreByte; |
| 4891 | break; |
| 4892 | case Primitive::kPrimShort: |
| 4893 | case Primitive::kPrimChar: |
| 4894 | store_type = kStoreHalfword; |
| 4895 | break; |
| 4896 | case Primitive::kPrimInt: |
| 4897 | case Primitive::kPrimFloat: |
| 4898 | case Primitive::kPrimNot: |
| 4899 | store_type = kStoreWord; |
| 4900 | break; |
| 4901 | case Primitive::kPrimLong: |
| 4902 | case Primitive::kPrimDouble: |
| 4903 | store_type = kStoreDoubleword; |
| 4904 | break; |
| 4905 | case Primitive::kPrimVoid: |
| 4906 | LOG(FATAL) << "Unreachable type " << type; |
| 4907 | UNREACHABLE(); |
| 4908 | } |
| 4909 | |
| 4910 | if (is_volatile) { |
| 4911 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 4912 | } |
| 4913 | |
| 4914 | if (is_volatile && store_type == kStoreDoubleword) { |
| 4915 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 4916 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4917 | // Do implicit Null check. |
| 4918 | __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0); |
| 4919 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4920 | if (type == Primitive::kPrimDouble) { |
| 4921 | // Pass FP parameters in core registers. |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4922 | if (value_location.IsFpuRegister()) { |
| 4923 | __ Mfc1(locations->GetTemp(1).AsRegister<Register>(), |
| 4924 | value_location.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4925 | __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4926 | value_location.AsFpuRegister<FRegister>()); |
| 4927 | } else if (value_location.IsDoubleStackSlot()) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4928 | __ LoadFromOffset(kLoadWord, |
| 4929 | locations->GetTemp(1).AsRegister<Register>(), |
| 4930 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4931 | value_location.GetStackIndex()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4932 | __ LoadFromOffset(kLoadWord, |
| 4933 | locations->GetTemp(2).AsRegister<Register>(), |
| 4934 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4935 | value_location.GetStackIndex() + 4); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4936 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4937 | DCHECK(value_location.IsConstant()); |
| 4938 | DCHECK(value_location.GetConstant()->IsDoubleConstant()); |
| 4939 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4940 | __ LoadConst64(locations->GetTemp(2).AsRegister<Register>(), |
| 4941 | locations->GetTemp(1).AsRegister<Register>(), |
| 4942 | value); |
| 4943 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4944 | } |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 4945 | codegen_->InvokeRuntime(kQuickA64Store, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4946 | CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>(); |
| 4947 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4948 | if (value_location.IsConstant()) { |
| 4949 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 4950 | __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker); |
| 4951 | } else if (!Primitive::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4952 | Register src; |
| 4953 | if (type == Primitive::kPrimLong) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4954 | src = value_location.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4955 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4956 | src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4957 | } |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4958 | __ StoreToOffset(store_type, src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4959 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4960 | FRegister src = value_location.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4961 | if (type == Primitive::kPrimFloat) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4962 | __ StoreSToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4963 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4964 | __ StoreDToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4965 | } |
| 4966 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4967 | } |
| 4968 | |
| 4969 | // TODO: memory barriers? |
| 4970 | if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4971 | Register src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4972 | codegen_->MarkGCCard(obj, src); |
| 4973 | } |
| 4974 | |
| 4975 | if (is_volatile) { |
| 4976 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 4977 | } |
| 4978 | } |
| 4979 | |
| 4980 | void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4981 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4982 | } |
| 4983 | |
| 4984 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4985 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 4986 | } |
| 4987 | |
| 4988 | void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4989 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4990 | } |
| 4991 | |
| 4992 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4993 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 4994 | } |
| 4995 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 4996 | void InstructionCodeGeneratorMIPS::GenerateGcRootFieldLoad( |
| 4997 | HInstruction* instruction ATTRIBUTE_UNUSED, |
| 4998 | Location root, |
| 4999 | Register obj, |
| 5000 | uint32_t offset) { |
| 5001 | Register root_reg = root.AsRegister<Register>(); |
| 5002 | if (kEmitCompilerReadBarrier) { |
| 5003 | UNIMPLEMENTED(FATAL) << "for read barrier"; |
| 5004 | } else { |
| 5005 | // Plain GC root load with no read barrier. |
| 5006 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5007 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 5008 | // Note that GC roots are not affected by heap poisoning, thus we |
| 5009 | // do not have to unpoison `root_reg` here. |
| 5010 | } |
| 5011 | } |
| 5012 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5013 | void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
| 5014 | LocationSummary::CallKind call_kind = |
| 5015 | instruction->IsExactCheck() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath; |
| 5016 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5017 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5018 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5019 | // The output does overlap inputs. |
| 5020 | // Note that TypeCheckSlowPathMIPS uses this register too. |
| 5021 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5022 | } |
| 5023 | |
| 5024 | void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
| 5025 | LocationSummary* locations = instruction->GetLocations(); |
| 5026 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5027 | Register cls = locations->InAt(1).AsRegister<Register>(); |
| 5028 | Register out = locations->Out().AsRegister<Register>(); |
| 5029 | |
| 5030 | MipsLabel done; |
| 5031 | |
| 5032 | // Return 0 if `obj` is null. |
| 5033 | // TODO: Avoid this check if we know `obj` is not null. |
| 5034 | __ Move(out, ZERO); |
| 5035 | __ Beqz(obj, &done); |
| 5036 | |
| 5037 | // Compare the class of `obj` with `cls`. |
| 5038 | __ LoadFromOffset(kLoadWord, out, obj, mirror::Object::ClassOffset().Int32Value()); |
| 5039 | if (instruction->IsExactCheck()) { |
| 5040 | // Classes must be equal for the instanceof to succeed. |
| 5041 | __ Xor(out, out, cls); |
| 5042 | __ Sltiu(out, out, 1); |
| 5043 | } else { |
| 5044 | // If the classes are not equal, we go into a slow path. |
| 5045 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5046 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction); |
| 5047 | codegen_->AddSlowPath(slow_path); |
| 5048 | __ Bne(out, cls, slow_path->GetEntryLabel()); |
| 5049 | __ LoadConst32(out, 1); |
| 5050 | __ Bind(slow_path->GetExitLabel()); |
| 5051 | } |
| 5052 | |
| 5053 | __ Bind(&done); |
| 5054 | } |
| 5055 | |
| 5056 | void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) { |
| 5057 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5058 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5059 | } |
| 5060 | |
| 5061 | void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 5062 | // Will be generated at use site. |
| 5063 | } |
| 5064 | |
| 5065 | void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) { |
| 5066 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5067 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5068 | } |
| 5069 | |
| 5070 | void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 5071 | // Will be generated at use site. |
| 5072 | } |
| 5073 | |
| 5074 | void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) { |
| 5075 | InvokeDexCallingConventionVisitorMIPS calling_convention_visitor; |
| 5076 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 5077 | } |
| 5078 | |
| 5079 | void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 5080 | HandleInvoke(invoke); |
| 5081 | // The register T0 is required to be used for the hidden argument in |
| 5082 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
| 5083 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0)); |
| 5084 | } |
| 5085 | |
| 5086 | void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 5087 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 5088 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5089 | Location receiver = invoke->GetLocations()->InAt(0); |
| 5090 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5091 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5092 | |
| 5093 | // Set the hidden argument. |
| 5094 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(), |
| 5095 | invoke->GetDexMethodIndex()); |
| 5096 | |
| 5097 | // temp = object->GetClass(); |
| 5098 | if (receiver.IsStackSlot()) { |
| 5099 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 5100 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 5101 | } else { |
| 5102 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
| 5103 | } |
| 5104 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 5105 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 5106 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
| 5107 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 5108 | invoke->GetImtIndex(), kMipsPointerSize)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5109 | // temp = temp->GetImtEntryAt(method_offset); |
| 5110 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 5111 | // T9 = temp->GetEntryPoint(); |
| 5112 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 5113 | // T9(); |
| 5114 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 5115 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5116 | DCHECK(!codegen_->IsLeafMethod()); |
| 5117 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 5118 | } |
| 5119 | |
| 5120 | void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 5121 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 5122 | if (intrinsic.TryDispatch(invoke)) { |
| 5123 | return; |
| 5124 | } |
| 5125 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5126 | HandleInvoke(invoke); |
| 5127 | } |
| 5128 | |
| 5129 | void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5130 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5131 | // art::PrepareForRegisterAllocation. |
| 5132 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5133 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5134 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 5135 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
| 5136 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 5137 | |
| 5138 | // kDirectAddressWithFixup and kCallDirectWithFixup need no extra input on R6 because |
| 5139 | // R6 has PC-relative addressing. |
| 5140 | bool has_extra_input = !isR6 && |
| 5141 | ((method_load_kind == HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) || |
| 5142 | (code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup)); |
| 5143 | |
| 5144 | if (invoke->HasPcRelativeDexCache()) { |
| 5145 | // kDexCachePcRelative is mutually exclusive with |
| 5146 | // kDirectAddressWithFixup/kCallDirectWithFixup. |
| 5147 | CHECK(!has_extra_input); |
| 5148 | has_extra_input = true; |
| 5149 | } |
| 5150 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 5151 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 5152 | if (intrinsic.TryDispatch(invoke)) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5153 | if (invoke->GetLocations()->CanCall() && has_extra_input) { |
| 5154 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 5155 | } |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 5156 | return; |
| 5157 | } |
| 5158 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5159 | HandleInvoke(invoke); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5160 | |
| 5161 | // Add the extra input register if either the dex cache array base register |
| 5162 | // or the PC-relative base register for accessing literals is needed. |
| 5163 | if (has_extra_input) { |
| 5164 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 5165 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5166 | } |
| 5167 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 5168 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5169 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 5170 | IntrinsicCodeGeneratorMIPS intrinsic(codegen); |
| 5171 | intrinsic.Dispatch(invoke); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5172 | return true; |
| 5173 | } |
| 5174 | return false; |
| 5175 | } |
| 5176 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5177 | HLoadString::LoadKind CodeGeneratorMIPS::GetSupportedLoadStringKind( |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5178 | HLoadString::LoadKind desired_string_load_kind) { |
| 5179 | if (kEmitCompilerReadBarrier) { |
| 5180 | UNIMPLEMENTED(FATAL) << "for read barrier"; |
| 5181 | } |
| 5182 | // We disable PC-relative load when there is an irreducible loop, as the optimization |
| 5183 | // is incompatible with it. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5184 | // TODO: Create as many MipsDexCacheArraysBase instructions as needed for methods |
| 5185 | // with irreducible loops. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5186 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
| 5187 | bool fallback_load = has_irreducible_loops; |
| 5188 | switch (desired_string_load_kind) { |
| 5189 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5190 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5191 | break; |
| 5192 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5193 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5194 | break; |
| 5195 | case HLoadString::LoadKind::kBootImageAddress: |
| 5196 | break; |
| 5197 | case HLoadString::LoadKind::kDexCacheAddress: |
| 5198 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5199 | fallback_load = false; |
| 5200 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5201 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5202 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5203 | break; |
| 5204 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5205 | fallback_load = false; |
| 5206 | break; |
| 5207 | } |
| 5208 | if (fallback_load) { |
| 5209 | desired_string_load_kind = HLoadString::LoadKind::kDexCacheViaMethod; |
| 5210 | } |
| 5211 | return desired_string_load_kind; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5212 | } |
| 5213 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5214 | HLoadClass::LoadKind CodeGeneratorMIPS::GetSupportedLoadClassKind( |
| 5215 | HLoadClass::LoadKind desired_class_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5216 | if (kEmitCompilerReadBarrier) { |
| 5217 | UNIMPLEMENTED(FATAL) << "for read barrier"; |
| 5218 | } |
| 5219 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5220 | // is incompatible with it. |
| 5221 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
| 5222 | bool fallback_load = has_irreducible_loops; |
| 5223 | switch (desired_class_load_kind) { |
| 5224 | case HLoadClass::LoadKind::kReferrersClass: |
| 5225 | fallback_load = false; |
| 5226 | break; |
| 5227 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5228 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5229 | break; |
| 5230 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5231 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5232 | break; |
| 5233 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5234 | break; |
| 5235 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 5236 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5237 | fallback_load = false; |
| 5238 | break; |
| 5239 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5240 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5241 | // TODO: Create as many MipsDexCacheArraysBase instructions as needed for methods |
| 5242 | // with irreducible loops. |
| 5243 | break; |
| 5244 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5245 | fallback_load = false; |
| 5246 | break; |
| 5247 | } |
| 5248 | if (fallback_load) { |
| 5249 | desired_class_load_kind = HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5250 | } |
| 5251 | return desired_class_load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5252 | } |
| 5253 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5254 | Register CodeGeneratorMIPS::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 5255 | Register temp) { |
| 5256 | CHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 5257 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 5258 | if (!invoke->GetLocations()->Intrinsified()) { |
| 5259 | return location.AsRegister<Register>(); |
| 5260 | } |
| 5261 | // For intrinsics we allow any location, so it may be on the stack. |
| 5262 | if (!location.IsRegister()) { |
| 5263 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 5264 | return temp; |
| 5265 | } |
| 5266 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 5267 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 5268 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 5269 | // simple and more robust approach rather that trying to determine if that's the case. |
| 5270 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 5271 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 5272 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 5273 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 5274 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 5275 | return temp; |
| 5276 | } |
| 5277 | return location.AsRegister<Register>(); |
| 5278 | } |
| 5279 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5280 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch( |
| 5281 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5282 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5283 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 5284 | // We disable PC-relative load when there is an irreducible loop, as the optimization |
| 5285 | // is incompatible with it. |
| 5286 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
| 5287 | bool fallback_load = true; |
| 5288 | bool fallback_call = true; |
| 5289 | switch (dispatch_info.method_load_kind) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5290 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 5291 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5292 | fallback_load = has_irreducible_loops; |
| 5293 | break; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5294 | default: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5295 | fallback_load = false; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5296 | break; |
| 5297 | } |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5298 | switch (dispatch_info.code_ptr_location) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5299 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5300 | fallback_call = has_irreducible_loops; |
| 5301 | break; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5302 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5303 | // TODO: Implement this type. |
| 5304 | break; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5305 | default: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5306 | fallback_call = false; |
| 5307 | break; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5308 | } |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5309 | if (fallback_load) { |
| 5310 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 5311 | dispatch_info.method_load_data = 0; |
| 5312 | } |
| 5313 | if (fallback_call) { |
| 5314 | dispatch_info.code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; |
| 5315 | dispatch_info.direct_code_ptr = 0; |
| 5316 | } |
| 5317 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5318 | } |
| 5319 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5320 | void CodeGeneratorMIPS::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 5321 | // 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] | 5322 | 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] | 5323 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 5324 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
| 5325 | bool isR6 = isa_features_.IsR6(); |
| 5326 | // kDirectAddressWithFixup and kCallDirectWithFixup have no extra input on R6 because |
| 5327 | // R6 has PC-relative addressing. |
| 5328 | bool has_extra_input = invoke->HasPcRelativeDexCache() || |
| 5329 | (!isR6 && |
| 5330 | ((method_load_kind == HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) || |
| 5331 | (code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup))); |
| 5332 | Register base_reg = has_extra_input |
| 5333 | ? GetInvokeStaticOrDirectExtraParameter(invoke, temp.AsRegister<Register>()) |
| 5334 | : ZERO; |
| 5335 | |
| 5336 | // For better instruction scheduling we load the direct code pointer before the method pointer. |
| 5337 | switch (code_ptr_location) { |
| 5338 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 5339 | // T9 = invoke->GetDirectCodePtr(); |
| 5340 | __ LoadConst32(T9, invoke->GetDirectCodePtr()); |
| 5341 | break; |
| 5342 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 5343 | // T9 = code address from literal pool with link-time patch. |
| 5344 | __ LoadLiteral(T9, base_reg, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
| 5345 | break; |
| 5346 | default: |
| 5347 | break; |
| 5348 | } |
| 5349 | |
| 5350 | switch (method_load_kind) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5351 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5352 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5353 | uint32_t offset = |
| 5354 | GetThreadOffset<kMipsPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5355 | __ LoadFromOffset(kLoadWord, |
| 5356 | temp.AsRegister<Register>(), |
| 5357 | TR, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5358 | offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5359 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5360 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5361 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 5362 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5363 | break; |
| 5364 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 5365 | __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 5366 | break; |
| 5367 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5368 | __ LoadLiteral(temp.AsRegister<Register>(), |
| 5369 | base_reg, |
| 5370 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 5371 | break; |
| 5372 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 5373 | HMipsDexCacheArraysBase* base = |
| 5374 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsMipsDexCacheArraysBase(); |
| 5375 | int32_t offset = |
| 5376 | invoke->GetDexCacheArrayOffset() - base->GetElementOffset() - kDexCacheArrayLwOffset; |
| 5377 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 5378 | break; |
| 5379 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5380 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 5381 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5382 | Register reg = temp.AsRegister<Register>(); |
| 5383 | Register method_reg; |
| 5384 | if (current_method.IsRegister()) { |
| 5385 | method_reg = current_method.AsRegister<Register>(); |
| 5386 | } else { |
| 5387 | // TODO: use the appropriate DCHECK() here if possible. |
| 5388 | // DCHECK(invoke->GetLocations()->Intrinsified()); |
| 5389 | DCHECK(!current_method.IsValid()); |
| 5390 | method_reg = reg; |
| 5391 | __ Lw(reg, SP, kCurrentMethodStackOffset); |
| 5392 | } |
| 5393 | |
| 5394 | // temp = temp->dex_cache_resolved_methods_; |
| 5395 | __ LoadFromOffset(kLoadWord, |
| 5396 | reg, |
| 5397 | method_reg, |
| 5398 | ArtMethod::DexCacheResolvedMethodsOffset(kMipsPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 5399 | // temp = temp[index_in_cache]; |
| 5400 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 5401 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5402 | __ LoadFromOffset(kLoadWord, |
| 5403 | reg, |
| 5404 | reg, |
| 5405 | CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 5406 | break; |
| 5407 | } |
| 5408 | } |
| 5409 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5410 | switch (code_ptr_location) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5411 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5412 | __ Bal(&frame_entry_label_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5413 | break; |
| 5414 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5415 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 5416 | // T9 prepared above for better instruction scheduling. |
| 5417 | // T9() |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5418 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 5419 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5420 | break; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5421 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5422 | // TODO: Implement this type. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5423 | // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 5424 | LOG(FATAL) << "Unsupported"; |
| 5425 | UNREACHABLE(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5426 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 5427 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
Goran Jakovljevic | 1a87837 | 2015-10-26 14:28:52 +0100 | [diff] [blame] | 5428 | __ LoadFromOffset(kLoadWord, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5429 | T9, |
| 5430 | callee_method.AsRegister<Register>(), |
| 5431 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5432 | kMipsPointerSize).Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5433 | // T9() |
| 5434 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 5435 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5436 | break; |
| 5437 | } |
| 5438 | DCHECK(!IsLeafMethod()); |
| 5439 | } |
| 5440 | |
| 5441 | void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5442 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5443 | // art::PrepareForRegisterAllocation. |
| 5444 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5445 | |
| 5446 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 5447 | return; |
| 5448 | } |
| 5449 | |
| 5450 | LocationSummary* locations = invoke->GetLocations(); |
| 5451 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 5452 | locations->HasTemps() |
| 5453 | ? locations->GetTemp(0) |
| 5454 | : Location::NoLocation()); |
| 5455 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 5456 | } |
| 5457 | |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 5458 | void CodeGeneratorMIPS::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 5459 | // Use the calling convention instead of the location of the receiver, as |
| 5460 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 5461 | // slow path, the arguments have been moved to the right place, so here we are |
| 5462 | // guaranteed that the receiver is the first register of the calling convention. |
| 5463 | InvokeDexCallingConvention calling_convention; |
| 5464 | Register receiver = calling_convention.GetRegisterAt(0); |
| 5465 | |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 5466 | Register temp = temp_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5467 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 5468 | invoke->GetVTableIndex(), kMipsPointerSize).SizeValue(); |
| 5469 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5470 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5471 | |
| 5472 | // temp = object->GetClass(); |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 5473 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 5474 | MaybeRecordImplicitNullCheck(invoke); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5475 | // temp = temp->GetMethodAt(method_offset); |
| 5476 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 5477 | // T9 = temp->GetEntryPoint(); |
| 5478 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 5479 | // T9(); |
| 5480 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 5481 | __ NopIfNoReordering(); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 5482 | } |
| 5483 | |
| 5484 | void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 5485 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 5486 | return; |
| 5487 | } |
| 5488 | |
| 5489 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5490 | DCHECK(!codegen_->IsLeafMethod()); |
| 5491 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 5492 | } |
| 5493 | |
| 5494 | void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5495 | if (cls->NeedsAccessCheck()) { |
| 5496 | InvokeRuntimeCallingConvention calling_convention; |
| 5497 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5498 | cls, |
| 5499 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 5500 | Location::RegisterLocation(V0), |
| 5501 | /* code_generator_supports_read_barrier */ false); // TODO: revisit this bool. |
| 5502 | return; |
| 5503 | } |
| 5504 | |
| 5505 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier) |
| 5506 | ? LocationSummary::kCallOnSlowPath |
| 5507 | : LocationSummary::kNoCall; |
| 5508 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
| 5509 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5510 | switch (load_kind) { |
| 5511 | // We need an extra register for PC-relative literals on R2. |
| 5512 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5513 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5514 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5515 | if (codegen_->GetInstructionSetFeatures().IsR6()) { |
| 5516 | break; |
| 5517 | } |
| 5518 | FALLTHROUGH_INTENDED; |
| 5519 | // We need an extra register for PC-relative dex cache accesses. |
| 5520 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5521 | case HLoadClass::LoadKind::kReferrersClass: |
| 5522 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5523 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5524 | break; |
| 5525 | default: |
| 5526 | break; |
| 5527 | } |
| 5528 | locations->SetOut(Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5529 | } |
| 5530 | |
| 5531 | void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) { |
| 5532 | LocationSummary* locations = cls->GetLocations(); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 5533 | if (cls->NeedsAccessCheck()) { |
| 5534 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 5535 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5536 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 5537 | return; |
| 5538 | } |
| 5539 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5540 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5541 | Location out_loc = locations->Out(); |
| 5542 | Register out = out_loc.AsRegister<Register>(); |
| 5543 | Register base_or_current_method_reg; |
| 5544 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 5545 | switch (load_kind) { |
| 5546 | // We need an extra register for PC-relative literals on R2. |
| 5547 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5548 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5549 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5550 | base_or_current_method_reg = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>(); |
| 5551 | break; |
| 5552 | // We need an extra register for PC-relative dex cache accesses. |
| 5553 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5554 | case HLoadClass::LoadKind::kReferrersClass: |
| 5555 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5556 | base_or_current_method_reg = locations->InAt(0).AsRegister<Register>(); |
| 5557 | break; |
| 5558 | default: |
| 5559 | base_or_current_method_reg = ZERO; |
| 5560 | break; |
| 5561 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5562 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5563 | bool generate_null_check = false; |
| 5564 | switch (load_kind) { |
| 5565 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5566 | DCHECK(!cls->CanCallRuntime()); |
| 5567 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5568 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5569 | GenerateGcRootFieldLoad(cls, |
| 5570 | out_loc, |
| 5571 | base_or_current_method_reg, |
| 5572 | ArtMethod::DeclaringClassOffset().Int32Value()); |
| 5573 | break; |
| 5574 | } |
| 5575 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5576 | DCHECK(!kEmitCompilerReadBarrier); |
| 5577 | __ LoadLiteral(out, |
| 5578 | base_or_current_method_reg, |
| 5579 | codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 5580 | cls->GetTypeIndex())); |
| 5581 | break; |
| 5582 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
| 5583 | DCHECK(!kEmitCompilerReadBarrier); |
| 5584 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
| 5585 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5586 | codegen_->EmitPcRelativeAddressPlaceholder(info, out, base_or_current_method_reg); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5587 | break; |
| 5588 | } |
| 5589 | case HLoadClass::LoadKind::kBootImageAddress: { |
| 5590 | DCHECK(!kEmitCompilerReadBarrier); |
| 5591 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5592 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5593 | __ LoadLiteral(out, |
| 5594 | base_or_current_method_reg, |
| 5595 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5596 | break; |
| 5597 | } |
| 5598 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 5599 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5600 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5601 | static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes."); |
| 5602 | DCHECK_ALIGNED(cls->GetAddress(), 4u); |
| 5603 | int16_t offset = Low16Bits(address); |
| 5604 | uint32_t base_address = address - offset; // This accounts for offset sign extension. |
| 5605 | __ Lui(out, High16Bits(base_address)); |
| 5606 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) |
| 5607 | GenerateGcRootFieldLoad(cls, out_loc, out, offset); |
| 5608 | generate_null_check = !cls->IsInDexCache(); |
| 5609 | break; |
| 5610 | } |
| 5611 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 5612 | HMipsDexCacheArraysBase* base = cls->InputAt(0)->AsMipsDexCacheArraysBase(); |
| 5613 | int32_t offset = |
| 5614 | cls->GetDexCacheElementOffset() - base->GetElementOffset() - kDexCacheArrayLwOffset; |
| 5615 | // /* GcRoot<mirror::Class> */ out = *(dex_cache_arrays_base + offset) |
| 5616 | GenerateGcRootFieldLoad(cls, out_loc, base_or_current_method_reg, offset); |
| 5617 | generate_null_check = !cls->IsInDexCache(); |
| 5618 | break; |
| 5619 | } |
| 5620 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 5621 | // /* GcRoot<mirror::Class>[] */ out = |
| 5622 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5623 | __ LoadFromOffset(kLoadWord, |
| 5624 | out, |
| 5625 | base_or_current_method_reg, |
| 5626 | ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value()); |
| 5627 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5628 | size_t offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex()); |
| 5629 | GenerateGcRootFieldLoad(cls, out_loc, out, offset); |
| 5630 | generate_null_check = !cls->IsInDexCache(); |
| 5631 | } |
| 5632 | } |
| 5633 | |
| 5634 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5635 | DCHECK(cls->CanCallRuntime()); |
| 5636 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS( |
| 5637 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5638 | codegen_->AddSlowPath(slow_path); |
| 5639 | if (generate_null_check) { |
| 5640 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 5641 | } |
| 5642 | if (cls->MustGenerateClinitCheck()) { |
| 5643 | GenerateClassInitializationCheck(slow_path, out); |
| 5644 | } else { |
| 5645 | __ Bind(slow_path->GetExitLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5646 | } |
| 5647 | } |
| 5648 | } |
| 5649 | |
| 5650 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5651 | return Thread::ExceptionOffset<kMipsPointerSize>().Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5652 | } |
| 5653 | |
| 5654 | void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) { |
| 5655 | LocationSummary* locations = |
| 5656 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5657 | locations->SetOut(Location::RequiresRegister()); |
| 5658 | } |
| 5659 | |
| 5660 | void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) { |
| 5661 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
| 5662 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 5663 | } |
| 5664 | |
| 5665 | void LocationsBuilderMIPS::VisitClearException(HClearException* clear) { |
| 5666 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5667 | } |
| 5668 | |
| 5669 | void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5670 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
| 5671 | } |
| 5672 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5673 | void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5674 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5675 | ? ((load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) |
| 5676 | ? LocationSummary::kCallOnMainOnly |
| 5677 | : LocationSummary::kCallOnSlowPath) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5678 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5679 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5680 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 5681 | switch (load_kind) { |
| 5682 | // We need an extra register for PC-relative literals on R2. |
| 5683 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5684 | case HLoadString::LoadKind::kBootImageAddress: |
| 5685 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5686 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5687 | if (codegen_->GetInstructionSetFeatures().IsR6()) { |
| 5688 | break; |
| 5689 | } |
| 5690 | FALLTHROUGH_INTENDED; |
| 5691 | // We need an extra register for PC-relative dex cache accesses. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5692 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5693 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5694 | break; |
| 5695 | default: |
| 5696 | break; |
| 5697 | } |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame^] | 5698 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 5699 | InvokeRuntimeCallingConvention calling_convention; |
| 5700 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5701 | } else { |
| 5702 | locations->SetOut(Location::RequiresRegister()); |
| 5703 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5704 | } |
| 5705 | |
| 5706 | void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5707 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5708 | LocationSummary* locations = load->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5709 | Location out_loc = locations->Out(); |
| 5710 | Register out = out_loc.AsRegister<Register>(); |
| 5711 | Register base_or_current_method_reg; |
| 5712 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 5713 | switch (load_kind) { |
| 5714 | // We need an extra register for PC-relative literals on R2. |
| 5715 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5716 | case HLoadString::LoadKind::kBootImageAddress: |
| 5717 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5718 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5719 | base_or_current_method_reg = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>(); |
| 5720 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5721 | default: |
| 5722 | base_or_current_method_reg = ZERO; |
| 5723 | break; |
| 5724 | } |
| 5725 | |
| 5726 | switch (load_kind) { |
| 5727 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5728 | DCHECK(!kEmitCompilerReadBarrier); |
| 5729 | __ LoadLiteral(out, |
| 5730 | base_or_current_method_reg, |
| 5731 | codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 5732 | load->GetStringIndex())); |
| 5733 | return; // No dex cache slow path. |
| 5734 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 5735 | DCHECK(!kEmitCompilerReadBarrier); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5736 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5737 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
| 5738 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5739 | codegen_->EmitPcRelativeAddressPlaceholder(info, out, base_or_current_method_reg); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5740 | return; // No dex cache slow path. |
| 5741 | } |
| 5742 | case HLoadString::LoadKind::kBootImageAddress: { |
| 5743 | DCHECK(!kEmitCompilerReadBarrier); |
| 5744 | DCHECK_NE(load->GetAddress(), 0u); |
| 5745 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 5746 | __ LoadLiteral(out, |
| 5747 | base_or_current_method_reg, |
| 5748 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5749 | return; // No dex cache slow path. |
| 5750 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5751 | case HLoadString::LoadKind::kBssEntry: { |
| 5752 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 5753 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
| 5754 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
| 5755 | codegen_->EmitPcRelativeAddressPlaceholder(info, out, base_or_current_method_reg); |
| 5756 | __ LoadFromOffset(kLoadWord, out, out, 0); |
| 5757 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS(load); |
| 5758 | codegen_->AddSlowPath(slow_path); |
| 5759 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 5760 | __ Bind(slow_path->GetExitLabel()); |
| 5761 | return; |
| 5762 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5763 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5764 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5765 | } |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5766 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5767 | // 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] | 5768 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 5769 | InvokeRuntimeCallingConvention calling_convention; |
| 5770 | __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex()); |
| 5771 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5772 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5773 | } |
| 5774 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5775 | void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) { |
| 5776 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5777 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5778 | } |
| 5779 | |
| 5780 | void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 5781 | // Will be generated at use site. |
| 5782 | } |
| 5783 | |
| 5784 | void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5785 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5786 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5787 | InvokeRuntimeCallingConvention calling_convention; |
| 5788 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5789 | } |
| 5790 | |
| 5791 | void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5792 | if (instruction->IsEnter()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 5793 | codegen_->InvokeRuntime(kQuickLockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5794 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5795 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 5796 | codegen_->InvokeRuntime(kQuickUnlockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5797 | } |
| 5798 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5799 | } |
| 5800 | |
| 5801 | void LocationsBuilderMIPS::VisitMul(HMul* mul) { |
| 5802 | LocationSummary* locations = |
| 5803 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 5804 | switch (mul->GetResultType()) { |
| 5805 | case Primitive::kPrimInt: |
| 5806 | case Primitive::kPrimLong: |
| 5807 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5808 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5809 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5810 | break; |
| 5811 | |
| 5812 | case Primitive::kPrimFloat: |
| 5813 | case Primitive::kPrimDouble: |
| 5814 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5815 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5816 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5817 | break; |
| 5818 | |
| 5819 | default: |
| 5820 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5821 | } |
| 5822 | } |
| 5823 | |
| 5824 | void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) { |
| 5825 | Primitive::Type type = instruction->GetType(); |
| 5826 | LocationSummary* locations = instruction->GetLocations(); |
| 5827 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 5828 | |
| 5829 | switch (type) { |
| 5830 | case Primitive::kPrimInt: { |
| 5831 | Register dst = locations->Out().AsRegister<Register>(); |
| 5832 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 5833 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 5834 | |
| 5835 | if (isR6) { |
| 5836 | __ MulR6(dst, lhs, rhs); |
| 5837 | } else { |
| 5838 | __ MulR2(dst, lhs, rhs); |
| 5839 | } |
| 5840 | break; |
| 5841 | } |
| 5842 | case Primitive::kPrimLong: { |
| 5843 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 5844 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 5845 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 5846 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 5847 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 5848 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 5849 | |
| 5850 | // Extra checks to protect caused by the existance of A1_A2. |
| 5851 | // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo: |
| 5852 | // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2). |
| 5853 | DCHECK_NE(dst_high, lhs_low); |
| 5854 | DCHECK_NE(dst_high, rhs_low); |
| 5855 | |
| 5856 | // A_B * C_D |
| 5857 | // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ] |
| 5858 | // dst_lo: [ low(B*D) ] |
| 5859 | // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result. |
| 5860 | |
| 5861 | if (isR6) { |
| 5862 | __ MulR6(TMP, lhs_high, rhs_low); |
| 5863 | __ MulR6(dst_high, lhs_low, rhs_high); |
| 5864 | __ Addu(dst_high, dst_high, TMP); |
| 5865 | __ MuhuR6(TMP, lhs_low, rhs_low); |
| 5866 | __ Addu(dst_high, dst_high, TMP); |
| 5867 | __ MulR6(dst_low, lhs_low, rhs_low); |
| 5868 | } else { |
| 5869 | __ MulR2(TMP, lhs_high, rhs_low); |
| 5870 | __ MulR2(dst_high, lhs_low, rhs_high); |
| 5871 | __ Addu(dst_high, dst_high, TMP); |
| 5872 | __ MultuR2(lhs_low, rhs_low); |
| 5873 | __ Mfhi(TMP); |
| 5874 | __ Addu(dst_high, dst_high, TMP); |
| 5875 | __ Mflo(dst_low); |
| 5876 | } |
| 5877 | break; |
| 5878 | } |
| 5879 | case Primitive::kPrimFloat: |
| 5880 | case Primitive::kPrimDouble: { |
| 5881 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 5882 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5883 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5884 | if (type == Primitive::kPrimFloat) { |
| 5885 | __ MulS(dst, lhs, rhs); |
| 5886 | } else { |
| 5887 | __ MulD(dst, lhs, rhs); |
| 5888 | } |
| 5889 | break; |
| 5890 | } |
| 5891 | default: |
| 5892 | LOG(FATAL) << "Unexpected mul type " << type; |
| 5893 | } |
| 5894 | } |
| 5895 | |
| 5896 | void LocationsBuilderMIPS::VisitNeg(HNeg* neg) { |
| 5897 | LocationSummary* locations = |
| 5898 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 5899 | switch (neg->GetResultType()) { |
| 5900 | case Primitive::kPrimInt: |
| 5901 | case Primitive::kPrimLong: |
| 5902 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5903 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5904 | break; |
| 5905 | |
| 5906 | case Primitive::kPrimFloat: |
| 5907 | case Primitive::kPrimDouble: |
| 5908 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5909 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5910 | break; |
| 5911 | |
| 5912 | default: |
| 5913 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5914 | } |
| 5915 | } |
| 5916 | |
| 5917 | void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) { |
| 5918 | Primitive::Type type = instruction->GetType(); |
| 5919 | LocationSummary* locations = instruction->GetLocations(); |
| 5920 | |
| 5921 | switch (type) { |
| 5922 | case Primitive::kPrimInt: { |
| 5923 | Register dst = locations->Out().AsRegister<Register>(); |
| 5924 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 5925 | __ Subu(dst, ZERO, src); |
| 5926 | break; |
| 5927 | } |
| 5928 | case Primitive::kPrimLong: { |
| 5929 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 5930 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 5931 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 5932 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 5933 | __ Subu(dst_low, ZERO, src_low); |
| 5934 | __ Sltu(TMP, ZERO, dst_low); |
| 5935 | __ Subu(dst_high, ZERO, src_high); |
| 5936 | __ Subu(dst_high, dst_high, TMP); |
| 5937 | break; |
| 5938 | } |
| 5939 | case Primitive::kPrimFloat: |
| 5940 | case Primitive::kPrimDouble: { |
| 5941 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 5942 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5943 | if (type == Primitive::kPrimFloat) { |
| 5944 | __ NegS(dst, src); |
| 5945 | } else { |
| 5946 | __ NegD(dst, src); |
| 5947 | } |
| 5948 | break; |
| 5949 | } |
| 5950 | default: |
| 5951 | LOG(FATAL) << "Unexpected neg type " << type; |
| 5952 | } |
| 5953 | } |
| 5954 | |
| 5955 | void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) { |
| 5956 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5957 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5958 | InvokeRuntimeCallingConvention calling_convention; |
| 5959 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5960 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 5961 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 5962 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5963 | } |
| 5964 | |
| 5965 | void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) { |
| 5966 | InvokeRuntimeCallingConvention calling_convention; |
| 5967 | Register current_method_register = calling_convention.GetRegisterAt(2); |
| 5968 | __ Lw(current_method_register, SP, kCurrentMethodStackOffset); |
| 5969 | // Move an uint16_t value to a register. |
| 5970 | __ LoadConst32(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 5971 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5972 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, |
| 5973 | void*, uint32_t, int32_t, ArtMethod*>(); |
| 5974 | } |
| 5975 | |
| 5976 | void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) { |
| 5977 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5978 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5979 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5980 | if (instruction->IsStringAlloc()) { |
| 5981 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 5982 | } else { |
| 5983 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5984 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5985 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5986 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 5987 | } |
| 5988 | |
| 5989 | void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5990 | if (instruction->IsStringAlloc()) { |
| 5991 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5992 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5993 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5994 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 5995 | __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value()); |
| 5996 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 5997 | __ NopIfNoReordering(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5998 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5999 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6000 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6001 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 6002 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6003 | } |
| 6004 | |
| 6005 | void LocationsBuilderMIPS::VisitNot(HNot* instruction) { |
| 6006 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 6007 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6008 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6009 | } |
| 6010 | |
| 6011 | void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) { |
| 6012 | Primitive::Type type = instruction->GetType(); |
| 6013 | LocationSummary* locations = instruction->GetLocations(); |
| 6014 | |
| 6015 | switch (type) { |
| 6016 | case Primitive::kPrimInt: { |
| 6017 | Register dst = locations->Out().AsRegister<Register>(); |
| 6018 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 6019 | __ Nor(dst, src, ZERO); |
| 6020 | break; |
| 6021 | } |
| 6022 | |
| 6023 | case Primitive::kPrimLong: { |
| 6024 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 6025 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 6026 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 6027 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 6028 | __ Nor(dst_high, src_high, ZERO); |
| 6029 | __ Nor(dst_low, src_low, ZERO); |
| 6030 | break; |
| 6031 | } |
| 6032 | |
| 6033 | default: |
| 6034 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 6035 | } |
| 6036 | } |
| 6037 | |
| 6038 | void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
| 6039 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 6040 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6041 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6042 | } |
| 6043 | |
| 6044 | void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
| 6045 | LocationSummary* locations = instruction->GetLocations(); |
| 6046 | __ Xori(locations->Out().AsRegister<Register>(), |
| 6047 | locations->InAt(0).AsRegister<Register>(), |
| 6048 | 1); |
| 6049 | } |
| 6050 | |
| 6051 | void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6052 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 6053 | locations->SetInAt(0, Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6054 | } |
| 6055 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6056 | void CodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 6057 | if (CanMoveNullCheckToUser(instruction)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6058 | return; |
| 6059 | } |
| 6060 | Location obj = instruction->GetLocations()->InAt(0); |
| 6061 | |
| 6062 | __ Lw(ZERO, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6063 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6064 | } |
| 6065 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6066 | void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6067 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6068 | AddSlowPath(slow_path); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6069 | |
| 6070 | Location obj = instruction->GetLocations()->InAt(0); |
| 6071 | |
| 6072 | __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 6073 | } |
| 6074 | |
| 6075 | void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6076 | codegen_->GenerateNullCheck(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6077 | } |
| 6078 | |
| 6079 | void LocationsBuilderMIPS::VisitOr(HOr* instruction) { |
| 6080 | HandleBinaryOp(instruction); |
| 6081 | } |
| 6082 | |
| 6083 | void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) { |
| 6084 | HandleBinaryOp(instruction); |
| 6085 | } |
| 6086 | |
| 6087 | void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 6088 | LOG(FATAL) << "Unreachable"; |
| 6089 | } |
| 6090 | |
| 6091 | void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) { |
| 6092 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6093 | } |
| 6094 | |
| 6095 | void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) { |
| 6096 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 6097 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 6098 | if (location.IsStackSlot()) { |
| 6099 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 6100 | } else if (location.IsDoubleStackSlot()) { |
| 6101 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 6102 | } |
| 6103 | locations->SetOut(location); |
| 6104 | } |
| 6105 | |
| 6106 | void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction |
| 6107 | ATTRIBUTE_UNUSED) { |
| 6108 | // Nothing to do, the parameter is already at its location. |
| 6109 | } |
| 6110 | |
| 6111 | void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 6112 | LocationSummary* locations = |
| 6113 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6114 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 6115 | } |
| 6116 | |
| 6117 | void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction |
| 6118 | ATTRIBUTE_UNUSED) { |
| 6119 | // Nothing to do, the method is already at its location. |
| 6120 | } |
| 6121 | |
| 6122 | void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) { |
| 6123 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6124 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6125 | locations->SetInAt(i, Location::Any()); |
| 6126 | } |
| 6127 | locations->SetOut(Location::Any()); |
| 6128 | } |
| 6129 | |
| 6130 | void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 6131 | LOG(FATAL) << "Unreachable"; |
| 6132 | } |
| 6133 | |
| 6134 | void LocationsBuilderMIPS::VisitRem(HRem* rem) { |
| 6135 | Primitive::Type type = rem->GetResultType(); |
| 6136 | LocationSummary::CallKind call_kind = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6137 | (type == Primitive::kPrimInt) ? LocationSummary::kNoCall : LocationSummary::kCallOnMainOnly; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6138 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 6139 | |
| 6140 | switch (type) { |
| 6141 | case Primitive::kPrimInt: |
| 6142 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 6143 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6144 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6145 | break; |
| 6146 | |
| 6147 | case Primitive::kPrimLong: { |
| 6148 | InvokeRuntimeCallingConvention calling_convention; |
| 6149 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 6150 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 6151 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 6152 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 6153 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 6154 | break; |
| 6155 | } |
| 6156 | |
| 6157 | case Primitive::kPrimFloat: |
| 6158 | case Primitive::kPrimDouble: { |
| 6159 | InvokeRuntimeCallingConvention calling_convention; |
| 6160 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 6161 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 6162 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 6163 | break; |
| 6164 | } |
| 6165 | |
| 6166 | default: |
| 6167 | LOG(FATAL) << "Unexpected rem type " << type; |
| 6168 | } |
| 6169 | } |
| 6170 | |
| 6171 | void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) { |
| 6172 | Primitive::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6173 | |
| 6174 | switch (type) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 6175 | case Primitive::kPrimInt: |
| 6176 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6177 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6178 | case Primitive::kPrimLong: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6179 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6180 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 6181 | break; |
| 6182 | } |
| 6183 | case Primitive::kPrimFloat: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6184 | codegen_->InvokeRuntime(kQuickFmodf, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6185 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6186 | break; |
| 6187 | } |
| 6188 | case Primitive::kPrimDouble: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6189 | codegen_->InvokeRuntime(kQuickFmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6190 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6191 | break; |
| 6192 | } |
| 6193 | default: |
| 6194 | LOG(FATAL) << "Unexpected rem type " << type; |
| 6195 | } |
| 6196 | } |
| 6197 | |
| 6198 | void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 6199 | memory_barrier->SetLocations(nullptr); |
| 6200 | } |
| 6201 | |
| 6202 | void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 6203 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 6204 | } |
| 6205 | |
| 6206 | void LocationsBuilderMIPS::VisitReturn(HReturn* ret) { |
| 6207 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret); |
| 6208 | Primitive::Type return_type = ret->InputAt(0)->GetType(); |
| 6209 | locations->SetInAt(0, MipsReturnLocation(return_type)); |
| 6210 | } |
| 6211 | |
| 6212 | void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 6213 | codegen_->GenerateFrameExit(); |
| 6214 | } |
| 6215 | |
| 6216 | void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) { |
| 6217 | ret->SetLocations(nullptr); |
| 6218 | } |
| 6219 | |
| 6220 | void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 6221 | codegen_->GenerateFrameExit(); |
| 6222 | } |
| 6223 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 6224 | void LocationsBuilderMIPS::VisitRor(HRor* ror) { |
| 6225 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6226 | } |
| 6227 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 6228 | void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) { |
| 6229 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6230 | } |
| 6231 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6232 | void LocationsBuilderMIPS::VisitShl(HShl* shl) { |
| 6233 | HandleShift(shl); |
| 6234 | } |
| 6235 | |
| 6236 | void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) { |
| 6237 | HandleShift(shl); |
| 6238 | } |
| 6239 | |
| 6240 | void LocationsBuilderMIPS::VisitShr(HShr* shr) { |
| 6241 | HandleShift(shr); |
| 6242 | } |
| 6243 | |
| 6244 | void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) { |
| 6245 | HandleShift(shr); |
| 6246 | } |
| 6247 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6248 | void LocationsBuilderMIPS::VisitSub(HSub* instruction) { |
| 6249 | HandleBinaryOp(instruction); |
| 6250 | } |
| 6251 | |
| 6252 | void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) { |
| 6253 | HandleBinaryOp(instruction); |
| 6254 | } |
| 6255 | |
| 6256 | void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6257 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6258 | } |
| 6259 | |
| 6260 | void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6261 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 6262 | } |
| 6263 | |
| 6264 | void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6265 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6266 | } |
| 6267 | |
| 6268 | void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6269 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 6270 | } |
| 6271 | |
| 6272 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet( |
| 6273 | HUnresolvedInstanceFieldGet* instruction) { |
| 6274 | FieldAccessCallingConventionMIPS calling_convention; |
| 6275 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 6276 | instruction->GetFieldType(), |
| 6277 | calling_convention); |
| 6278 | } |
| 6279 | |
| 6280 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet( |
| 6281 | HUnresolvedInstanceFieldGet* instruction) { |
| 6282 | FieldAccessCallingConventionMIPS calling_convention; |
| 6283 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6284 | instruction->GetFieldType(), |
| 6285 | instruction->GetFieldIndex(), |
| 6286 | instruction->GetDexPc(), |
| 6287 | calling_convention); |
| 6288 | } |
| 6289 | |
| 6290 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet( |
| 6291 | HUnresolvedInstanceFieldSet* instruction) { |
| 6292 | FieldAccessCallingConventionMIPS calling_convention; |
| 6293 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 6294 | instruction->GetFieldType(), |
| 6295 | calling_convention); |
| 6296 | } |
| 6297 | |
| 6298 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet( |
| 6299 | HUnresolvedInstanceFieldSet* instruction) { |
| 6300 | FieldAccessCallingConventionMIPS calling_convention; |
| 6301 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6302 | instruction->GetFieldType(), |
| 6303 | instruction->GetFieldIndex(), |
| 6304 | instruction->GetDexPc(), |
| 6305 | calling_convention); |
| 6306 | } |
| 6307 | |
| 6308 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet( |
| 6309 | HUnresolvedStaticFieldGet* instruction) { |
| 6310 | FieldAccessCallingConventionMIPS calling_convention; |
| 6311 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 6312 | instruction->GetFieldType(), |
| 6313 | calling_convention); |
| 6314 | } |
| 6315 | |
| 6316 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet( |
| 6317 | HUnresolvedStaticFieldGet* instruction) { |
| 6318 | FieldAccessCallingConventionMIPS calling_convention; |
| 6319 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6320 | instruction->GetFieldType(), |
| 6321 | instruction->GetFieldIndex(), |
| 6322 | instruction->GetDexPc(), |
| 6323 | calling_convention); |
| 6324 | } |
| 6325 | |
| 6326 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet( |
| 6327 | HUnresolvedStaticFieldSet* instruction) { |
| 6328 | FieldAccessCallingConventionMIPS calling_convention; |
| 6329 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 6330 | instruction->GetFieldType(), |
| 6331 | calling_convention); |
| 6332 | } |
| 6333 | |
| 6334 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet( |
| 6335 | HUnresolvedStaticFieldSet* instruction) { |
| 6336 | FieldAccessCallingConventionMIPS calling_convention; |
| 6337 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6338 | instruction->GetFieldType(), |
| 6339 | instruction->GetFieldIndex(), |
| 6340 | instruction->GetDexPc(), |
| 6341 | calling_convention); |
| 6342 | } |
| 6343 | |
| 6344 | void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6345 | LocationSummary* locations = |
| 6346 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6347 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6348 | } |
| 6349 | |
| 6350 | void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 6351 | HBasicBlock* block = instruction->GetBlock(); |
| 6352 | if (block->GetLoopInformation() != nullptr) { |
| 6353 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6354 | // The back edge will generate the suspend check. |
| 6355 | return; |
| 6356 | } |
| 6357 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6358 | // The goto will generate the suspend check. |
| 6359 | return; |
| 6360 | } |
| 6361 | GenerateSuspendCheck(instruction, nullptr); |
| 6362 | } |
| 6363 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6364 | void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) { |
| 6365 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6366 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6367 | InvokeRuntimeCallingConvention calling_convention; |
| 6368 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6369 | } |
| 6370 | |
| 6371 | void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6372 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6373 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 6374 | } |
| 6375 | |
| 6376 | void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
| 6377 | Primitive::Type input_type = conversion->GetInputType(); |
| 6378 | Primitive::Type result_type = conversion->GetResultType(); |
| 6379 | DCHECK_NE(input_type, result_type); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6380 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6381 | |
| 6382 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 6383 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 6384 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 6385 | } |
| 6386 | |
| 6387 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6388 | if (!isR6 && |
| 6389 | ((Primitive::IsFloatingPointType(result_type) && input_type == Primitive::kPrimLong) || |
| 6390 | (result_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(input_type)))) { |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6391 | call_kind = LocationSummary::kCallOnMainOnly; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6392 | } |
| 6393 | |
| 6394 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 6395 | |
| 6396 | if (call_kind == LocationSummary::kNoCall) { |
| 6397 | if (Primitive::IsFloatingPointType(input_type)) { |
| 6398 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6399 | } else { |
| 6400 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6401 | } |
| 6402 | |
| 6403 | if (Primitive::IsFloatingPointType(result_type)) { |
| 6404 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6405 | } else { |
| 6406 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6407 | } |
| 6408 | } else { |
| 6409 | InvokeRuntimeCallingConvention calling_convention; |
| 6410 | |
| 6411 | if (Primitive::IsFloatingPointType(input_type)) { |
| 6412 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 6413 | } else { |
| 6414 | DCHECK_EQ(input_type, Primitive::kPrimLong); |
| 6415 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 6416 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 6417 | } |
| 6418 | |
| 6419 | locations->SetOut(calling_convention.GetReturnLocation(result_type)); |
| 6420 | } |
| 6421 | } |
| 6422 | |
| 6423 | void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
| 6424 | LocationSummary* locations = conversion->GetLocations(); |
| 6425 | Primitive::Type result_type = conversion->GetResultType(); |
| 6426 | Primitive::Type input_type = conversion->GetInputType(); |
| 6427 | bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6428 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6429 | |
| 6430 | DCHECK_NE(input_type, result_type); |
| 6431 | |
| 6432 | if (result_type == Primitive::kPrimLong && Primitive::IsIntegralType(input_type)) { |
| 6433 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 6434 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 6435 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 6436 | |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 6437 | if (dst_low != src) { |
| 6438 | __ Move(dst_low, src); |
| 6439 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6440 | __ Sra(dst_high, src, 31); |
| 6441 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
| 6442 | Register dst = locations->Out().AsRegister<Register>(); |
| 6443 | Register src = (input_type == Primitive::kPrimLong) |
| 6444 | ? locations->InAt(0).AsRegisterPairLow<Register>() |
| 6445 | : locations->InAt(0).AsRegister<Register>(); |
| 6446 | |
| 6447 | switch (result_type) { |
| 6448 | case Primitive::kPrimChar: |
| 6449 | __ Andi(dst, src, 0xFFFF); |
| 6450 | break; |
| 6451 | case Primitive::kPrimByte: |
| 6452 | if (has_sign_extension) { |
| 6453 | __ Seb(dst, src); |
| 6454 | } else { |
| 6455 | __ Sll(dst, src, 24); |
| 6456 | __ Sra(dst, dst, 24); |
| 6457 | } |
| 6458 | break; |
| 6459 | case Primitive::kPrimShort: |
| 6460 | if (has_sign_extension) { |
| 6461 | __ Seh(dst, src); |
| 6462 | } else { |
| 6463 | __ Sll(dst, src, 16); |
| 6464 | __ Sra(dst, dst, 16); |
| 6465 | } |
| 6466 | break; |
| 6467 | case Primitive::kPrimInt: |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 6468 | if (dst != src) { |
| 6469 | __ Move(dst, src); |
| 6470 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6471 | break; |
| 6472 | |
| 6473 | default: |
| 6474 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 6475 | << " to " << result_type; |
| 6476 | } |
| 6477 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6478 | if (input_type == Primitive::kPrimLong) { |
| 6479 | if (isR6) { |
| 6480 | // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 6481 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 6482 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 6483 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 6484 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 6485 | __ Mtc1(src_low, FTMP); |
| 6486 | __ Mthc1(src_high, FTMP); |
| 6487 | if (result_type == Primitive::kPrimFloat) { |
| 6488 | __ Cvtsl(dst, FTMP); |
| 6489 | } else { |
| 6490 | __ Cvtdl(dst, FTMP); |
| 6491 | } |
| 6492 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6493 | QuickEntrypointEnum entrypoint = (result_type == Primitive::kPrimFloat) ? kQuickL2f |
| 6494 | : kQuickL2d; |
| 6495 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6496 | if (result_type == Primitive::kPrimFloat) { |
| 6497 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 6498 | } else { |
| 6499 | CheckEntrypointTypes<kQuickL2d, double, int64_t>(); |
| 6500 | } |
| 6501 | } |
| 6502 | } else { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6503 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 6504 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 6505 | __ Mtc1(src, FTMP); |
| 6506 | if (result_type == Primitive::kPrimFloat) { |
| 6507 | __ Cvtsw(dst, FTMP); |
| 6508 | } else { |
| 6509 | __ Cvtdw(dst, FTMP); |
| 6510 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6511 | } |
| 6512 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
| 6513 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6514 | if (result_type == Primitive::kPrimLong) { |
| 6515 | if (isR6) { |
| 6516 | // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 6517 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 6518 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 6519 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 6520 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 6521 | MipsLabel truncate; |
| 6522 | MipsLabel done; |
| 6523 | |
| 6524 | // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive |
| 6525 | // value when the input is either a NaN or is outside of the range of the output type |
| 6526 | // after the truncation. IOW, the three special cases (NaN, too small, too big) produce |
| 6527 | // the same result. |
| 6528 | // |
| 6529 | // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum |
| 6530 | // value of the output type if the input is outside of the range after the truncation or |
| 6531 | // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct |
| 6532 | // results. This matches the desired float/double-to-int/long conversion exactly. |
| 6533 | // |
| 6534 | // So, NAN2008 affects handling of negative values and NaNs by the truncate instruction. |
| 6535 | // |
| 6536 | // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate |
| 6537 | // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6, |
| 6538 | // even though it must be NAN2008=1 on R6. |
| 6539 | // |
| 6540 | // The code takes care of the different behaviors by first comparing the input to the |
| 6541 | // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int). |
| 6542 | // If the input is greater than or equal to the minimum, it procedes to the truncate |
| 6543 | // instruction, which will handle such an input the same way irrespective of NAN2008. |
| 6544 | // Otherwise the input is compared to itself to determine whether it is a NaN or not |
| 6545 | // in order to return either zero or the minimum value. |
| 6546 | // |
| 6547 | // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the |
| 6548 | // truncate instruction for MIPS64R6. |
| 6549 | if (input_type == Primitive::kPrimFloat) { |
| 6550 | uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int64_t>::min()); |
| 6551 | __ LoadConst32(TMP, min_val); |
| 6552 | __ Mtc1(TMP, FTMP); |
| 6553 | __ CmpLeS(FTMP, FTMP, src); |
| 6554 | } else { |
| 6555 | uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int64_t>::min()); |
| 6556 | __ LoadConst32(TMP, High32Bits(min_val)); |
| 6557 | __ Mtc1(ZERO, FTMP); |
| 6558 | __ Mthc1(TMP, FTMP); |
| 6559 | __ CmpLeD(FTMP, FTMP, src); |
| 6560 | } |
| 6561 | |
| 6562 | __ Bc1nez(FTMP, &truncate); |
| 6563 | |
| 6564 | if (input_type == Primitive::kPrimFloat) { |
| 6565 | __ CmpEqS(FTMP, src, src); |
| 6566 | } else { |
| 6567 | __ CmpEqD(FTMP, src, src); |
| 6568 | } |
| 6569 | __ Move(dst_low, ZERO); |
| 6570 | __ LoadConst32(dst_high, std::numeric_limits<int32_t>::min()); |
| 6571 | __ Mfc1(TMP, FTMP); |
| 6572 | __ And(dst_high, dst_high, TMP); |
| 6573 | |
| 6574 | __ B(&done); |
| 6575 | |
| 6576 | __ Bind(&truncate); |
| 6577 | |
| 6578 | if (input_type == Primitive::kPrimFloat) { |
| 6579 | __ TruncLS(FTMP, src); |
| 6580 | } else { |
| 6581 | __ TruncLD(FTMP, src); |
| 6582 | } |
| 6583 | __ Mfc1(dst_low, FTMP); |
| 6584 | __ Mfhc1(dst_high, FTMP); |
| 6585 | |
| 6586 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6587 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6588 | QuickEntrypointEnum entrypoint = (input_type == Primitive::kPrimFloat) ? kQuickF2l |
| 6589 | : kQuickD2l; |
| 6590 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6591 | if (input_type == Primitive::kPrimFloat) { |
| 6592 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 6593 | } else { |
| 6594 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 6595 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6596 | } |
| 6597 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6598 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 6599 | Register dst = locations->Out().AsRegister<Register>(); |
| 6600 | MipsLabel truncate; |
| 6601 | MipsLabel done; |
| 6602 | |
| 6603 | // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate |
| 6604 | // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6, |
| 6605 | // even though it must be NAN2008=1 on R6. |
| 6606 | // |
| 6607 | // For details see the large comment above for the truncation of float/double to long on R6. |
| 6608 | // |
| 6609 | // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the |
| 6610 | // truncate instruction for MIPS64R6. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6611 | if (input_type == Primitive::kPrimFloat) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6612 | uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min()); |
| 6613 | __ LoadConst32(TMP, min_val); |
| 6614 | __ Mtc1(TMP, FTMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6615 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6616 | uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min()); |
| 6617 | __ LoadConst32(TMP, High32Bits(min_val)); |
| 6618 | __ Mtc1(ZERO, FTMP); |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 6619 | __ MoveToFpuHigh(TMP, FTMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6620 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6621 | |
| 6622 | if (isR6) { |
| 6623 | if (input_type == Primitive::kPrimFloat) { |
| 6624 | __ CmpLeS(FTMP, FTMP, src); |
| 6625 | } else { |
| 6626 | __ CmpLeD(FTMP, FTMP, src); |
| 6627 | } |
| 6628 | __ Bc1nez(FTMP, &truncate); |
| 6629 | |
| 6630 | if (input_type == Primitive::kPrimFloat) { |
| 6631 | __ CmpEqS(FTMP, src, src); |
| 6632 | } else { |
| 6633 | __ CmpEqD(FTMP, src, src); |
| 6634 | } |
| 6635 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); |
| 6636 | __ Mfc1(TMP, FTMP); |
| 6637 | __ And(dst, dst, TMP); |
| 6638 | } else { |
| 6639 | if (input_type == Primitive::kPrimFloat) { |
| 6640 | __ ColeS(0, FTMP, src); |
| 6641 | } else { |
| 6642 | __ ColeD(0, FTMP, src); |
| 6643 | } |
| 6644 | __ Bc1t(0, &truncate); |
| 6645 | |
| 6646 | if (input_type == Primitive::kPrimFloat) { |
| 6647 | __ CeqS(0, src, src); |
| 6648 | } else { |
| 6649 | __ CeqD(0, src, src); |
| 6650 | } |
| 6651 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); |
| 6652 | __ Movf(dst, ZERO, 0); |
| 6653 | } |
| 6654 | |
| 6655 | __ B(&done); |
| 6656 | |
| 6657 | __ Bind(&truncate); |
| 6658 | |
| 6659 | if (input_type == Primitive::kPrimFloat) { |
| 6660 | __ TruncWS(FTMP, src); |
| 6661 | } else { |
| 6662 | __ TruncWD(FTMP, src); |
| 6663 | } |
| 6664 | __ Mfc1(dst, FTMP); |
| 6665 | |
| 6666 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6667 | } |
| 6668 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 6669 | Primitive::IsFloatingPointType(input_type)) { |
| 6670 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 6671 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 6672 | if (result_type == Primitive::kPrimFloat) { |
| 6673 | __ Cvtsd(dst, src); |
| 6674 | } else { |
| 6675 | __ Cvtds(dst, src); |
| 6676 | } |
| 6677 | } else { |
| 6678 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 6679 | << " to " << result_type; |
| 6680 | } |
| 6681 | } |
| 6682 | |
| 6683 | void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) { |
| 6684 | HandleShift(ushr); |
| 6685 | } |
| 6686 | |
| 6687 | void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) { |
| 6688 | HandleShift(ushr); |
| 6689 | } |
| 6690 | |
| 6691 | void LocationsBuilderMIPS::VisitXor(HXor* instruction) { |
| 6692 | HandleBinaryOp(instruction); |
| 6693 | } |
| 6694 | |
| 6695 | void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) { |
| 6696 | HandleBinaryOp(instruction); |
| 6697 | } |
| 6698 | |
| 6699 | void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 6700 | // Nothing to do, this should be removed during prepare for register allocator. |
| 6701 | LOG(FATAL) << "Unreachable"; |
| 6702 | } |
| 6703 | |
| 6704 | void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 6705 | // Nothing to do, this should be removed during prepare for register allocator. |
| 6706 | LOG(FATAL) << "Unreachable"; |
| 6707 | } |
| 6708 | |
| 6709 | void LocationsBuilderMIPS::VisitEqual(HEqual* 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 InstructionCodeGeneratorMIPS::VisitEqual(HEqual* 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 LocationsBuilderMIPS::VisitNotEqual(HNotEqual* 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 InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* 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 LocationsBuilderMIPS::VisitLessThan(HLessThan* 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 | |
| 6729 | void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6730 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6731 | } |
| 6732 | |
| 6733 | void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6734 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6735 | } |
| 6736 | |
| 6737 | void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6738 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6739 | } |
| 6740 | |
| 6741 | void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6742 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6743 | } |
| 6744 | |
| 6745 | void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6746 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6747 | } |
| 6748 | |
| 6749 | void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6750 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6751 | } |
| 6752 | |
| 6753 | void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6754 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6755 | } |
| 6756 | |
| 6757 | void LocationsBuilderMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6758 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6759 | } |
| 6760 | |
| 6761 | void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6762 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6763 | } |
| 6764 | |
| 6765 | void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6766 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6767 | } |
| 6768 | |
| 6769 | void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6770 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6771 | } |
| 6772 | |
| 6773 | void LocationsBuilderMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6774 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6775 | } |
| 6776 | |
| 6777 | void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6778 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6779 | } |
| 6780 | |
| 6781 | void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6782 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6783 | } |
| 6784 | |
| 6785 | void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6786 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6787 | } |
| 6788 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6789 | void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6790 | LocationSummary* locations = |
| 6791 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6792 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6793 | } |
| 6794 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 6795 | void InstructionCodeGeneratorMIPS::GenPackedSwitchWithCompares(Register value_reg, |
| 6796 | int32_t lower_bound, |
| 6797 | uint32_t num_entries, |
| 6798 | HBasicBlock* switch_block, |
| 6799 | HBasicBlock* default_block) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6800 | // Create a set of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6801 | Register temp_reg = TMP; |
| 6802 | __ Addiu32(temp_reg, value_reg, -lower_bound); |
| 6803 | // Jump to default if index is negative |
| 6804 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 6805 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 6806 | __ Bltz(temp_reg, codegen_->GetLabelOf(default_block)); |
| 6807 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 6808 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6809 | // Jump to successors[0] if value == lower_bound. |
| 6810 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 6811 | int32_t last_index = 0; |
| 6812 | for (; num_entries - last_index > 2; last_index += 2) { |
| 6813 | __ Addiu(temp_reg, temp_reg, -2); |
| 6814 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 6815 | __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 6816 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 6817 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 6818 | } |
| 6819 | if (num_entries - last_index == 2) { |
| 6820 | // The last missing case_value. |
| 6821 | __ Addiu(temp_reg, temp_reg, -1); |
| 6822 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6823 | } |
| 6824 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6825 | // And the default for any other value. |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 6826 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6827 | __ B(codegen_->GetLabelOf(default_block)); |
| 6828 | } |
| 6829 | } |
| 6830 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 6831 | void InstructionCodeGeneratorMIPS::GenTableBasedPackedSwitch(Register value_reg, |
| 6832 | Register constant_area, |
| 6833 | int32_t lower_bound, |
| 6834 | uint32_t num_entries, |
| 6835 | HBasicBlock* switch_block, |
| 6836 | HBasicBlock* default_block) { |
| 6837 | // Create a jump table. |
| 6838 | std::vector<MipsLabel*> labels(num_entries); |
| 6839 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 6840 | for (uint32_t i = 0; i < num_entries; i++) { |
| 6841 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 6842 | } |
| 6843 | JumpTable* table = __ CreateJumpTable(std::move(labels)); |
| 6844 | |
| 6845 | // Is the value in range? |
| 6846 | __ Addiu32(TMP, value_reg, -lower_bound); |
| 6847 | if (IsInt<16>(static_cast<int32_t>(num_entries))) { |
| 6848 | __ Sltiu(AT, TMP, num_entries); |
| 6849 | __ Beqz(AT, codegen_->GetLabelOf(default_block)); |
| 6850 | } else { |
| 6851 | __ LoadConst32(AT, num_entries); |
| 6852 | __ Bgeu(TMP, AT, codegen_->GetLabelOf(default_block)); |
| 6853 | } |
| 6854 | |
| 6855 | // We are in the range of the table. |
| 6856 | // Load the target address from the jump table, indexing by the value. |
| 6857 | __ LoadLabelAddress(AT, constant_area, table->GetLabel()); |
| 6858 | __ Sll(TMP, TMP, 2); |
| 6859 | __ Addu(TMP, TMP, AT); |
| 6860 | __ Lw(TMP, TMP, 0); |
| 6861 | // Compute the absolute target address by adding the table start address |
| 6862 | // (the table contains offsets to targets relative to its start). |
| 6863 | __ Addu(TMP, TMP, AT); |
| 6864 | // And jump. |
| 6865 | __ Jr(TMP); |
| 6866 | __ NopIfNoReordering(); |
| 6867 | } |
| 6868 | |
| 6869 | void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6870 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 6871 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 6872 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6873 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6874 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 6875 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6876 | |
| 6877 | if (codegen_->GetInstructionSetFeatures().IsR6() && |
| 6878 | num_entries > kPackedSwitchJumpTableThreshold) { |
| 6879 | // R6 uses PC-relative addressing to access the jump table. |
| 6880 | // R2, OTOH, requires an HMipsComputeBaseMethodAddress input to access |
| 6881 | // the jump table and it is implemented by changing HPackedSwitch to |
| 6882 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress. |
| 6883 | // See VisitMipsPackedSwitch() for the table-based implementation on R2. |
| 6884 | GenTableBasedPackedSwitch(value_reg, |
| 6885 | ZERO, |
| 6886 | lower_bound, |
| 6887 | num_entries, |
| 6888 | switch_block, |
| 6889 | default_block); |
| 6890 | } else { |
| 6891 | GenPackedSwitchWithCompares(value_reg, |
| 6892 | lower_bound, |
| 6893 | num_entries, |
| 6894 | switch_block, |
| 6895 | default_block); |
| 6896 | } |
| 6897 | } |
| 6898 | |
| 6899 | void LocationsBuilderMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 6900 | LocationSummary* locations = |
| 6901 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6902 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6903 | // Constant area pointer (HMipsComputeBaseMethodAddress). |
| 6904 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6905 | } |
| 6906 | |
| 6907 | void InstructionCodeGeneratorMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 6908 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 6909 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 6910 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6911 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6912 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 6913 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 6914 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6915 | |
| 6916 | // This is an R2-only path. HPackedSwitch has been changed to |
| 6917 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress |
| 6918 | // required to address the jump table relative to PC. |
| 6919 | GenTableBasedPackedSwitch(value_reg, |
| 6920 | constant_area, |
| 6921 | lower_bound, |
| 6922 | num_entries, |
| 6923 | switch_block, |
| 6924 | default_block); |
| 6925 | } |
| 6926 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6927 | void LocationsBuilderMIPS::VisitMipsComputeBaseMethodAddress( |
| 6928 | HMipsComputeBaseMethodAddress* insn) { |
| 6929 | LocationSummary* locations = |
| 6930 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 6931 | locations->SetOut(Location::RequiresRegister()); |
| 6932 | } |
| 6933 | |
| 6934 | void InstructionCodeGeneratorMIPS::VisitMipsComputeBaseMethodAddress( |
| 6935 | HMipsComputeBaseMethodAddress* insn) { |
| 6936 | LocationSummary* locations = insn->GetLocations(); |
| 6937 | Register reg = locations->Out().AsRegister<Register>(); |
| 6938 | |
| 6939 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
| 6940 | |
| 6941 | // Generate a dummy PC-relative call to obtain PC. |
| 6942 | __ Nal(); |
| 6943 | // Grab the return address off RA. |
| 6944 | __ Move(reg, RA); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6945 | // TODO: Can we share this code with that of VisitMipsDexCacheArraysBase()? |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6946 | |
| 6947 | // Remember this offset (the obtained PC value) for later use with constant area. |
| 6948 | __ BindPcRelBaseLabel(); |
| 6949 | } |
| 6950 | |
| 6951 | void LocationsBuilderMIPS::VisitMipsDexCacheArraysBase(HMipsDexCacheArraysBase* base) { |
| 6952 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 6953 | locations->SetOut(Location::RequiresRegister()); |
| 6954 | } |
| 6955 | |
| 6956 | void InstructionCodeGeneratorMIPS::VisitMipsDexCacheArraysBase(HMipsDexCacheArraysBase* base) { |
| 6957 | Register reg = base->GetLocations()->Out().AsRegister<Register>(); |
| 6958 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
| 6959 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6960 | // TODO: Reuse MipsComputeBaseMethodAddress on R2 instead of passing ZERO to force emitting NAL. |
| 6961 | codegen_->EmitPcRelativeAddressPlaceholder(info, reg, ZERO); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6962 | } |
| 6963 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6964 | void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 6965 | // The trampoline uses the same calling convention as dex calling conventions, |
| 6966 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 6967 | // the method_idx. |
| 6968 | HandleInvoke(invoke); |
| 6969 | } |
| 6970 | |
| 6971 | void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 6972 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 6973 | } |
| 6974 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 6975 | void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 6976 | LocationSummary* locations = |
| 6977 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6978 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6979 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6980 | } |
| 6981 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 6982 | void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 6983 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6984 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6985 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 6986 | instruction->GetIndex(), kMipsPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6987 | __ LoadFromOffset(kLoadWord, |
| 6988 | locations->Out().AsRegister<Register>(), |
| 6989 | locations->InAt(0).AsRegister<Register>(), |
| 6990 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 6991 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6992 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6993 | instruction->GetIndex(), kMipsPointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6994 | __ LoadFromOffset(kLoadWord, |
| 6995 | locations->Out().AsRegister<Register>(), |
| 6996 | locations->InAt(0).AsRegister<Register>(), |
| 6997 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6998 | __ LoadFromOffset(kLoadWord, |
| 6999 | locations->Out().AsRegister<Register>(), |
| 7000 | locations->Out().AsRegister<Register>(), |
| 7001 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 7002 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7003 | } |
| 7004 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7005 | #undef __ |
| 7006 | #undef QUICK_ENTRY_POINT |
| 7007 | |
| 7008 | } // namespace mips |
| 7009 | } // namespace art |