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(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 381 | uint32_t dex_pc = instruction_->GetDexPc(); |
| 382 | DCHECK(instruction_->IsCheckCast() |
| 383 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 384 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 385 | |
| 386 | __ Bind(GetEntryLabel()); |
| 387 | SaveLiveRegisters(codegen, locations); |
| 388 | |
| 389 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 390 | // move resolver. |
| 391 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 392 | codegen->EmitParallelMoves(locations->InAt(0), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 393 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 394 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 395 | locations->InAt(1), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 396 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 397 | Primitive::kPrimNot); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 398 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 399 | mips_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 400 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 401 | Primitive::Type ret_type = instruction_->GetType(); |
| 402 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 403 | mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 404 | } else { |
| 405 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 406 | mips_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 407 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | RestoreLiveRegisters(codegen, locations); |
| 411 | __ B(GetExitLabel()); |
| 412 | } |
| 413 | |
| 414 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; } |
| 415 | |
| 416 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 417 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS); |
| 418 | }; |
| 419 | |
| 420 | class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS { |
| 421 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 422 | explicit DeoptimizationSlowPathMIPS(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 423 | : SlowPathCodeMIPS(instruction) {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 424 | |
| 425 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 426 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 427 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 428 | mips_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 429 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; } |
| 433 | |
| 434 | private: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 435 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS); |
| 436 | }; |
| 437 | |
| 438 | CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph, |
| 439 | const MipsInstructionSetFeatures& isa_features, |
| 440 | const CompilerOptions& compiler_options, |
| 441 | OptimizingCompilerStats* stats) |
| 442 | : CodeGenerator(graph, |
| 443 | kNumberOfCoreRegisters, |
| 444 | kNumberOfFRegisters, |
| 445 | kNumberOfRegisterPairs, |
| 446 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 447 | arraysize(kCoreCalleeSaves)), |
| 448 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 449 | arraysize(kFpuCalleeSaves)), |
| 450 | compiler_options, |
| 451 | stats), |
| 452 | block_labels_(nullptr), |
| 453 | location_builder_(graph, this), |
| 454 | instruction_visitor_(graph, this), |
| 455 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 456 | assembler_(graph->GetArena(), &isa_features), |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 457 | isa_features_(isa_features), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 458 | uint32_literals_(std::less<uint32_t>(), |
| 459 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 460 | method_patches_(MethodReferenceComparator(), |
| 461 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 462 | call_patches_(MethodReferenceComparator(), |
| 463 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 464 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 465 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 466 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 467 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 468 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 469 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 470 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 471 | boot_image_address_patches_(std::less<uint32_t>(), |
| 472 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 473 | clobbered_ra_(false) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 474 | // Save RA (containing the return address) to mimic Quick. |
| 475 | AddAllocatedRegister(Location::RegisterLocation(RA)); |
| 476 | } |
| 477 | |
| 478 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 479 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 480 | #define __ down_cast<MipsAssembler*>(GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 481 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value() |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 482 | |
| 483 | void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) { |
| 484 | // Ensure that we fix up branches. |
| 485 | __ FinalizeCode(); |
| 486 | |
| 487 | // Adjust native pc offsets in stack maps. |
| 488 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
| 489 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; |
| 490 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 491 | DCHECK_GE(new_position, old_position); |
| 492 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 493 | } |
| 494 | |
| 495 | // Adjust pc offsets for the disassembly information. |
| 496 | if (disasm_info_ != nullptr) { |
| 497 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 498 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 499 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 500 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 501 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 502 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 503 | } |
| 504 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 505 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 506 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | CodeGenerator::Finalize(allocator); |
| 511 | } |
| 512 | |
| 513 | MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const { |
| 514 | return codegen_->GetAssembler(); |
| 515 | } |
| 516 | |
| 517 | void ParallelMoveResolverMIPS::EmitMove(size_t index) { |
| 518 | DCHECK_LT(index, moves_.size()); |
| 519 | MoveOperands* move = moves_[index]; |
| 520 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); |
| 521 | } |
| 522 | |
| 523 | void ParallelMoveResolverMIPS::EmitSwap(size_t index) { |
| 524 | DCHECK_LT(index, moves_.size()); |
| 525 | MoveOperands* move = moves_[index]; |
| 526 | Primitive::Type type = move->GetType(); |
| 527 | Location loc1 = move->GetDestination(); |
| 528 | Location loc2 = move->GetSource(); |
| 529 | |
| 530 | DCHECK(!loc1.IsConstant()); |
| 531 | DCHECK(!loc2.IsConstant()); |
| 532 | |
| 533 | if (loc1.Equals(loc2)) { |
| 534 | return; |
| 535 | } |
| 536 | |
| 537 | if (loc1.IsRegister() && loc2.IsRegister()) { |
| 538 | // Swap 2 GPRs. |
| 539 | Register r1 = loc1.AsRegister<Register>(); |
| 540 | Register r2 = loc2.AsRegister<Register>(); |
| 541 | __ Move(TMP, r2); |
| 542 | __ Move(r2, r1); |
| 543 | __ Move(r1, TMP); |
| 544 | } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) { |
| 545 | FRegister f1 = loc1.AsFpuRegister<FRegister>(); |
| 546 | FRegister f2 = loc2.AsFpuRegister<FRegister>(); |
| 547 | if (type == Primitive::kPrimFloat) { |
| 548 | __ MovS(FTMP, f2); |
| 549 | __ MovS(f2, f1); |
| 550 | __ MovS(f1, FTMP); |
| 551 | } else { |
| 552 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 553 | __ MovD(FTMP, f2); |
| 554 | __ MovD(f2, f1); |
| 555 | __ MovD(f1, FTMP); |
| 556 | } |
| 557 | } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) || |
| 558 | (loc1.IsFpuRegister() && loc2.IsRegister())) { |
| 559 | // Swap FPR and GPR. |
| 560 | DCHECK_EQ(type, Primitive::kPrimFloat); // Can only swap a float. |
| 561 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 562 | : loc2.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 563 | Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 564 | __ Move(TMP, r2); |
| 565 | __ Mfc1(r2, f1); |
| 566 | __ Mtc1(TMP, f1); |
| 567 | } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) { |
| 568 | // Swap 2 GPR register pairs. |
| 569 | Register r1 = loc1.AsRegisterPairLow<Register>(); |
| 570 | Register r2 = loc2.AsRegisterPairLow<Register>(); |
| 571 | __ Move(TMP, r2); |
| 572 | __ Move(r2, r1); |
| 573 | __ Move(r1, TMP); |
| 574 | r1 = loc1.AsRegisterPairHigh<Register>(); |
| 575 | r2 = loc2.AsRegisterPairHigh<Register>(); |
| 576 | __ Move(TMP, r2); |
| 577 | __ Move(r2, r1); |
| 578 | __ Move(r1, TMP); |
| 579 | } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) || |
| 580 | (loc1.IsFpuRegister() && loc2.IsRegisterPair())) { |
| 581 | // Swap FPR and GPR register pair. |
| 582 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 583 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 584 | : loc2.AsFpuRegister<FRegister>(); |
| 585 | Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 586 | : loc2.AsRegisterPairLow<Register>(); |
| 587 | Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 588 | : loc2.AsRegisterPairHigh<Register>(); |
| 589 | // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and |
| 590 | // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR |
| 591 | // unpredictable and the following mfch1 will fail. |
| 592 | __ Mfc1(TMP, f1); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 593 | __ MoveFromFpuHigh(AT, f1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 594 | __ Mtc1(r2_l, f1); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 595 | __ MoveToFpuHigh(r2_h, f1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 596 | __ Move(r2_l, TMP); |
| 597 | __ Move(r2_h, AT); |
| 598 | } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) { |
| 599 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false); |
| 600 | } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) { |
| 601 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 602 | } else if ((loc1.IsRegister() && loc2.IsStackSlot()) || |
| 603 | (loc1.IsStackSlot() && loc2.IsRegister())) { |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 604 | Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>() : loc2.AsRegister<Register>(); |
| 605 | intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex(); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 606 | __ Move(TMP, reg); |
| 607 | __ LoadFromOffset(kLoadWord, reg, SP, offset); |
| 608 | __ StoreToOffset(kStoreWord, TMP, SP, offset); |
| 609 | } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) || |
| 610 | (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) { |
| 611 | Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 612 | : loc2.AsRegisterPairLow<Register>(); |
| 613 | Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 614 | : loc2.AsRegisterPairHigh<Register>(); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 615 | intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex() : loc2.GetStackIndex(); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 616 | intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize) |
| 617 | : loc2.GetHighStackIndex(kMipsWordSize); |
| 618 | __ Move(TMP, reg_l); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 619 | __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l); |
David Brazdil | cc0f311 | 2016-01-28 17:14:52 +0000 | [diff] [blame] | 620 | __ StoreToOffset(kStoreWord, TMP, SP, offset_l); |
David Brazdil | 04d3e87 | 2016-01-29 09:50:09 +0000 | [diff] [blame] | 621 | __ Move(TMP, reg_h); |
| 622 | __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h); |
| 623 | __ StoreToOffset(kStoreWord, TMP, SP, offset_h); |
Goran Jakovljevic | 35dfcaa | 2016-09-22 09:26:01 +0200 | [diff] [blame] | 624 | } else if (loc1.IsFpuRegister() || loc2.IsFpuRegister()) { |
| 625 | FRegister reg = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 626 | : loc2.AsFpuRegister<FRegister>(); |
| 627 | intptr_t offset = loc1.IsFpuRegister() ? loc2.GetStackIndex() : loc1.GetStackIndex(); |
| 628 | if (type == Primitive::kPrimFloat) { |
| 629 | __ MovS(FTMP, reg); |
| 630 | __ LoadSFromOffset(reg, SP, offset); |
| 631 | __ StoreSToOffset(FTMP, SP, offset); |
| 632 | } else { |
| 633 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 634 | __ MovD(FTMP, reg); |
| 635 | __ LoadDFromOffset(reg, SP, offset); |
| 636 | __ StoreDToOffset(FTMP, SP, offset); |
| 637 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 638 | } else { |
| 639 | LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported"; |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | void ParallelMoveResolverMIPS::RestoreScratch(int reg) { |
| 644 | __ Pop(static_cast<Register>(reg)); |
| 645 | } |
| 646 | |
| 647 | void ParallelMoveResolverMIPS::SpillScratch(int reg) { |
| 648 | __ Push(static_cast<Register>(reg)); |
| 649 | } |
| 650 | |
| 651 | void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) { |
| 652 | // Allocate a scratch register other than TMP, if available. |
| 653 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be |
| 654 | // automatically unspilled when the scratch scope object is destroyed). |
| 655 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); |
| 656 | // If V0 spills onto the stack, SP-relative offsets need to be adjusted. |
| 657 | int stack_offset = ensure_scratch.IsSpilled() ? kMipsWordSize : 0; |
| 658 | for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) { |
| 659 | __ LoadFromOffset(kLoadWord, |
| 660 | Register(ensure_scratch.GetRegister()), |
| 661 | SP, |
| 662 | index1 + stack_offset); |
| 663 | __ LoadFromOffset(kLoadWord, |
| 664 | TMP, |
| 665 | SP, |
| 666 | index2 + stack_offset); |
| 667 | __ StoreToOffset(kStoreWord, |
| 668 | Register(ensure_scratch.GetRegister()), |
| 669 | SP, |
| 670 | index2 + stack_offset); |
| 671 | __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset); |
| 672 | } |
| 673 | } |
| 674 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 675 | void CodeGeneratorMIPS::ComputeSpillMask() { |
| 676 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 677 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 678 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 679 | // If there're FPU callee-saved registers and there's an odd number of GPR callee-saved |
| 680 | // registers, include the ZERO register to force alignment of FPU callee-saved registers |
| 681 | // within the stack frame. |
| 682 | if ((fpu_spill_mask_ != 0) && (POPCOUNT(core_spill_mask_) % 2 != 0)) { |
| 683 | core_spill_mask_ |= (1 << ZERO); |
| 684 | } |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | bool CodeGeneratorMIPS::HasAllocatedCalleeSaveRegisters() const { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 688 | // 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] | 689 | // (this can happen in leaf methods), force CodeGenerator::InitializeCodeGeneration() |
| 690 | // into the path that creates a stack frame so that RA can be explicitly saved and restored. |
| 691 | // 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] | 692 | // TODO: Can this be improved? It causes creation of a stack frame (while RA might be |
| 693 | // saved in an unused temporary register) and saving of RA and the current method pointer |
| 694 | // in the frame. |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 695 | return CodeGenerator::HasAllocatedCalleeSaveRegisters() || clobbered_ra_; |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 696 | } |
| 697 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 698 | static dwarf::Reg DWARFReg(Register reg) { |
| 699 | return dwarf::Reg::MipsCore(static_cast<int>(reg)); |
| 700 | } |
| 701 | |
| 702 | // TODO: mapping of floating-point registers to DWARF. |
| 703 | |
| 704 | void CodeGeneratorMIPS::GenerateFrameEntry() { |
| 705 | __ Bind(&frame_entry_label_); |
| 706 | |
| 707 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips) || !IsLeafMethod(); |
| 708 | |
| 709 | if (do_overflow_check) { |
| 710 | __ LoadFromOffset(kLoadWord, |
| 711 | ZERO, |
| 712 | SP, |
| 713 | -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips))); |
| 714 | RecordPcInfo(nullptr, 0); |
| 715 | } |
| 716 | |
| 717 | if (HasEmptyFrame()) { |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 718 | CHECK_EQ(fpu_spill_mask_, 0u); |
| 719 | CHECK_EQ(core_spill_mask_, 1u << RA); |
| 720 | CHECK(!clobbered_ra_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 721 | return; |
| 722 | } |
| 723 | |
| 724 | // Make sure the frame size isn't unreasonably large. |
| 725 | if (GetFrameSize() > GetStackOverflowReservedBytes(kMips)) { |
| 726 | LOG(FATAL) << "Stack frame larger than " << GetStackOverflowReservedBytes(kMips) << " bytes"; |
| 727 | } |
| 728 | |
| 729 | // Spill callee-saved registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 730 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 731 | uint32_t ofs = GetFrameSize(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 732 | __ IncreaseFrameSize(ofs); |
| 733 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 734 | for (uint32_t mask = core_spill_mask_; mask != 0; ) { |
| 735 | Register reg = static_cast<Register>(MostSignificantBit(mask)); |
| 736 | mask ^= 1u << reg; |
| 737 | ofs -= kMipsWordSize; |
| 738 | // The ZERO register is only included for alignment. |
| 739 | if (reg != ZERO) { |
| 740 | __ StoreToOffset(kStoreWord, reg, SP, ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 741 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 742 | } |
| 743 | } |
| 744 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 745 | for (uint32_t mask = fpu_spill_mask_; mask != 0; ) { |
| 746 | FRegister reg = static_cast<FRegister>(MostSignificantBit(mask)); |
| 747 | mask ^= 1u << reg; |
| 748 | ofs -= kMipsDoublewordSize; |
| 749 | __ StoreDToOffset(reg, SP, ofs); |
| 750 | // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 751 | } |
| 752 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 753 | // Save the current method if we need it. Note that we do not |
| 754 | // do this in HCurrentMethod, as the instruction might have been removed |
| 755 | // in the SSA graph. |
| 756 | if (RequiresCurrentMethod()) { |
| 757 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
| 758 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | void CodeGeneratorMIPS::GenerateFrameExit() { |
| 762 | __ cfi().RememberState(); |
| 763 | |
| 764 | if (!HasEmptyFrame()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 765 | // Restore callee-saved registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 766 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 767 | // For better instruction scheduling restore RA before other registers. |
| 768 | uint32_t ofs = GetFrameSize(); |
| 769 | for (uint32_t mask = core_spill_mask_; mask != 0; ) { |
| 770 | Register reg = static_cast<Register>(MostSignificantBit(mask)); |
| 771 | mask ^= 1u << reg; |
| 772 | ofs -= kMipsWordSize; |
| 773 | // The ZERO register is only included for alignment. |
| 774 | if (reg != ZERO) { |
| 775 | __ LoadFromOffset(kLoadWord, reg, SP, ofs); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 776 | __ cfi().Restore(DWARFReg(reg)); |
| 777 | } |
| 778 | } |
| 779 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 780 | for (uint32_t mask = fpu_spill_mask_; mask != 0; ) { |
| 781 | FRegister reg = static_cast<FRegister>(MostSignificantBit(mask)); |
| 782 | mask ^= 1u << reg; |
| 783 | ofs -= kMipsDoublewordSize; |
| 784 | __ LoadDFromOffset(reg, SP, ofs); |
| 785 | // TODO: __ cfi().Restore(DWARFReg(reg)); |
| 786 | } |
| 787 | |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 788 | size_t frame_size = GetFrameSize(); |
| 789 | // Adjust the stack pointer in the delay slot if doing so doesn't break CFI. |
| 790 | bool exchange = IsInt<16>(static_cast<int32_t>(frame_size)); |
| 791 | bool reordering = __ SetReorder(false); |
| 792 | if (exchange) { |
| 793 | __ Jr(RA); |
| 794 | __ DecreaseFrameSize(frame_size); // Single instruction in delay slot. |
| 795 | } else { |
| 796 | __ DecreaseFrameSize(frame_size); |
| 797 | __ Jr(RA); |
| 798 | __ Nop(); // In delay slot. |
| 799 | } |
| 800 | __ SetReorder(reordering); |
| 801 | } else { |
| 802 | __ Jr(RA); |
| 803 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 804 | } |
| 805 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 806 | __ cfi().RestoreState(); |
| 807 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 808 | } |
| 809 | |
| 810 | void CodeGeneratorMIPS::Bind(HBasicBlock* block) { |
| 811 | __ Bind(GetLabelOf(block)); |
| 812 | } |
| 813 | |
| 814 | void CodeGeneratorMIPS::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
| 815 | if (src.Equals(dst)) { |
| 816 | return; |
| 817 | } |
| 818 | |
| 819 | if (src.IsConstant()) { |
| 820 | MoveConstant(dst, src.GetConstant()); |
| 821 | } else { |
| 822 | if (Primitive::Is64BitType(dst_type)) { |
| 823 | Move64(dst, src); |
| 824 | } else { |
| 825 | Move32(dst, src); |
| 826 | } |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | void CodeGeneratorMIPS::Move32(Location destination, Location source) { |
| 831 | if (source.Equals(destination)) { |
| 832 | return; |
| 833 | } |
| 834 | |
| 835 | if (destination.IsRegister()) { |
| 836 | if (source.IsRegister()) { |
| 837 | __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 838 | } else if (source.IsFpuRegister()) { |
| 839 | __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>()); |
| 840 | } else { |
| 841 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 842 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
| 843 | } |
| 844 | } else if (destination.IsFpuRegister()) { |
| 845 | if (source.IsRegister()) { |
| 846 | __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>()); |
| 847 | } else if (source.IsFpuRegister()) { |
| 848 | __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 849 | } else { |
| 850 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 851 | __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 852 | } |
| 853 | } else { |
| 854 | DCHECK(destination.IsStackSlot()) << destination; |
| 855 | if (source.IsRegister()) { |
| 856 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
| 857 | } else if (source.IsFpuRegister()) { |
| 858 | __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex()); |
| 859 | } else { |
| 860 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 861 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 862 | __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex()); |
| 863 | } |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | void CodeGeneratorMIPS::Move64(Location destination, Location source) { |
| 868 | if (source.Equals(destination)) { |
| 869 | return; |
| 870 | } |
| 871 | |
| 872 | if (destination.IsRegisterPair()) { |
| 873 | if (source.IsRegisterPair()) { |
| 874 | __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 875 | __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 876 | } else if (source.IsFpuRegister()) { |
| 877 | Register dst_high = destination.AsRegisterPairHigh<Register>(); |
| 878 | Register dst_low = destination.AsRegisterPairLow<Register>(); |
| 879 | FRegister src = source.AsFpuRegister<FRegister>(); |
| 880 | __ Mfc1(dst_low, src); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 881 | __ MoveFromFpuHigh(dst_high, src); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 882 | } else { |
| 883 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 884 | int32_t off = source.GetStackIndex(); |
| 885 | Register r = destination.AsRegisterPairLow<Register>(); |
| 886 | __ LoadFromOffset(kLoadDoubleword, r, SP, off); |
| 887 | } |
| 888 | } else if (destination.IsFpuRegister()) { |
| 889 | if (source.IsRegisterPair()) { |
| 890 | FRegister dst = destination.AsFpuRegister<FRegister>(); |
| 891 | Register src_high = source.AsRegisterPairHigh<Register>(); |
| 892 | Register src_low = source.AsRegisterPairLow<Register>(); |
| 893 | __ Mtc1(src_low, dst); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 894 | __ MoveToFpuHigh(src_high, dst); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 895 | } else if (source.IsFpuRegister()) { |
| 896 | __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 897 | } else { |
| 898 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 899 | __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 900 | } |
| 901 | } else { |
| 902 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 903 | int32_t off = destination.GetStackIndex(); |
| 904 | if (source.IsRegisterPair()) { |
| 905 | __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, off); |
| 906 | } else if (source.IsFpuRegister()) { |
| 907 | __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, off); |
| 908 | } else { |
| 909 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 910 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 911 | __ StoreToOffset(kStoreWord, TMP, SP, off); |
| 912 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4); |
| 913 | __ StoreToOffset(kStoreWord, TMP, SP, off + 4); |
| 914 | } |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) { |
| 919 | if (c->IsIntConstant() || c->IsNullConstant()) { |
| 920 | // Move 32 bit constant. |
| 921 | int32_t value = GetInt32ValueOf(c); |
| 922 | if (destination.IsRegister()) { |
| 923 | Register dst = destination.AsRegister<Register>(); |
| 924 | __ LoadConst32(dst, value); |
| 925 | } else { |
| 926 | DCHECK(destination.IsStackSlot()) |
| 927 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 928 | __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 929 | } |
| 930 | } else if (c->IsLongConstant()) { |
| 931 | // Move 64 bit constant. |
| 932 | int64_t value = GetInt64ValueOf(c); |
| 933 | if (destination.IsRegisterPair()) { |
| 934 | Register r_h = destination.AsRegisterPairHigh<Register>(); |
| 935 | Register r_l = destination.AsRegisterPairLow<Register>(); |
| 936 | __ LoadConst64(r_h, r_l, value); |
| 937 | } else { |
| 938 | DCHECK(destination.IsDoubleStackSlot()) |
| 939 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 940 | __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 941 | } |
| 942 | } else if (c->IsFloatConstant()) { |
| 943 | // Move 32 bit float constant. |
| 944 | int32_t value = GetInt32ValueOf(c); |
| 945 | if (destination.IsFpuRegister()) { |
| 946 | __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP); |
| 947 | } else { |
| 948 | DCHECK(destination.IsStackSlot()) |
| 949 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 950 | __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 951 | } |
| 952 | } else { |
| 953 | // Move 64 bit double constant. |
| 954 | DCHECK(c->IsDoubleConstant()) << c->DebugName(); |
| 955 | int64_t value = GetInt64ValueOf(c); |
| 956 | if (destination.IsFpuRegister()) { |
| 957 | FRegister fd = destination.AsFpuRegister<FRegister>(); |
| 958 | __ LoadDConst64(fd, value, TMP); |
| 959 | } else { |
| 960 | DCHECK(destination.IsDoubleStackSlot()) |
| 961 | << "Cannot move " << c->DebugName() << " to " << destination; |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 962 | __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 963 | } |
| 964 | } |
| 965 | } |
| 966 | |
| 967 | void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) { |
| 968 | DCHECK(destination.IsRegister()); |
| 969 | Register dst = destination.AsRegister<Register>(); |
| 970 | __ LoadConst32(dst, value); |
| 971 | } |
| 972 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 973 | void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 974 | if (location.IsRegister()) { |
| 975 | locations->AddTemp(location); |
Alexey Frunze | c9e94f3 | 2015-10-26 16:11:39 -0700 | [diff] [blame] | 976 | } else if (location.IsRegisterPair()) { |
| 977 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 978 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 979 | } else { |
| 980 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 981 | } |
| 982 | } |
| 983 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 984 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 985 | inline void CodeGeneratorMIPS::EmitPcRelativeLinkerPatches( |
| 986 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 987 | ArenaVector<LinkerPatch>* linker_patches) { |
| 988 | for (const PcRelativePatchInfo& info : infos) { |
| 989 | const DexFile& dex_file = info.target_dex_file; |
| 990 | size_t offset_or_index = info.offset_or_index; |
| 991 | DCHECK(info.high_label.IsBound()); |
| 992 | uint32_t high_offset = __ GetLabelLocation(&info.high_label); |
| 993 | // On R2 we use HMipsComputeBaseMethodAddress and patch relative to |
| 994 | // the assembler's base label used for PC-relative addressing. |
| 995 | uint32_t pc_rel_offset = info.pc_rel_label.IsBound() |
| 996 | ? __ GetLabelLocation(&info.pc_rel_label) |
| 997 | : __ GetPcRelBaseLabelLocation(); |
| 998 | linker_patches->push_back(Factory(high_offset, &dex_file, pc_rel_offset, offset_or_index)); |
| 999 | } |
| 1000 | } |
| 1001 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1002 | void CodeGeneratorMIPS::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 1003 | DCHECK(linker_patches->empty()); |
| 1004 | size_t size = |
| 1005 | method_patches_.size() + |
| 1006 | call_patches_.size() + |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1007 | pc_relative_dex_cache_patches_.size() + |
| 1008 | pc_relative_string_patches_.size() + |
| 1009 | pc_relative_type_patches_.size() + |
| 1010 | boot_image_string_patches_.size() + |
| 1011 | boot_image_type_patches_.size() + |
| 1012 | boot_image_address_patches_.size(); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1013 | linker_patches->reserve(size); |
| 1014 | for (const auto& entry : method_patches_) { |
| 1015 | const MethodReference& target_method = entry.first; |
| 1016 | Literal* literal = entry.second; |
| 1017 | DCHECK(literal->GetLabel()->IsBound()); |
| 1018 | uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel()); |
| 1019 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 1020 | target_method.dex_file, |
| 1021 | target_method.dex_method_index)); |
| 1022 | } |
| 1023 | for (const auto& entry : call_patches_) { |
| 1024 | const MethodReference& target_method = entry.first; |
| 1025 | Literal* literal = entry.second; |
| 1026 | DCHECK(literal->GetLabel()->IsBound()); |
| 1027 | uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel()); |
| 1028 | linker_patches->push_back(LinkerPatch::CodePatch(literal_offset, |
| 1029 | target_method.dex_file, |
| 1030 | target_method.dex_method_index)); |
| 1031 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1032 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 1033 | linker_patches); |
| 1034 | if (!GetCompilerOptions().IsBootImage()) { |
| 1035 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 1036 | linker_patches); |
| 1037 | } else { |
| 1038 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 1039 | linker_patches); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1040 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1041 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 1042 | linker_patches); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1043 | for (const auto& entry : boot_image_string_patches_) { |
| 1044 | const StringReference& target_string = entry.first; |
| 1045 | Literal* literal = entry.second; |
| 1046 | DCHECK(literal->GetLabel()->IsBound()); |
| 1047 | uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel()); |
| 1048 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 1049 | target_string.dex_file, |
| 1050 | target_string.string_index)); |
| 1051 | } |
| 1052 | for (const auto& entry : boot_image_type_patches_) { |
| 1053 | const TypeReference& target_type = entry.first; |
| 1054 | Literal* literal = entry.second; |
| 1055 | DCHECK(literal->GetLabel()->IsBound()); |
| 1056 | uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel()); |
| 1057 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 1058 | target_type.dex_file, |
| 1059 | target_type.type_index)); |
| 1060 | } |
| 1061 | for (const auto& entry : boot_image_address_patches_) { |
| 1062 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
| 1063 | Literal* literal = entry.second; |
| 1064 | DCHECK(literal->GetLabel()->IsBound()); |
| 1065 | uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel()); |
| 1066 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeStringPatch( |
| 1071 | const DexFile& dex_file, uint32_t string_index) { |
| 1072 | return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_); |
| 1073 | } |
| 1074 | |
| 1075 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeTypePatch( |
| 1076 | const DexFile& dex_file, uint32_t type_index) { |
| 1077 | return NewPcRelativePatch(dex_file, type_index, &pc_relative_type_patches_); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeDexCacheArrayPatch( |
| 1081 | const DexFile& dex_file, uint32_t element_offset) { |
| 1082 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 1083 | } |
| 1084 | |
| 1085 | CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativePatch( |
| 1086 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 1087 | patches->emplace_back(dex_file, offset_or_index); |
| 1088 | return &patches->back(); |
| 1089 | } |
| 1090 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1091 | Literal* CodeGeneratorMIPS::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 1092 | return map->GetOrCreate( |
| 1093 | value, |
| 1094 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
| 1095 | } |
| 1096 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1097 | Literal* CodeGeneratorMIPS::DeduplicateMethodLiteral(MethodReference target_method, |
| 1098 | MethodToLiteralMap* map) { |
| 1099 | return map->GetOrCreate( |
| 1100 | target_method, |
| 1101 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1102 | } |
| 1103 | |
| 1104 | Literal* CodeGeneratorMIPS::DeduplicateMethodAddressLiteral(MethodReference target_method) { |
| 1105 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 1106 | } |
| 1107 | |
| 1108 | Literal* CodeGeneratorMIPS::DeduplicateMethodCodeLiteral(MethodReference target_method) { |
| 1109 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 1110 | } |
| 1111 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1112 | Literal* CodeGeneratorMIPS::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
| 1113 | uint32_t string_index) { |
| 1114 | return boot_image_string_patches_.GetOrCreate( |
| 1115 | StringReference(&dex_file, string_index), |
| 1116 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1117 | } |
| 1118 | |
| 1119 | Literal* CodeGeneratorMIPS::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
| 1120 | uint32_t type_index) { |
| 1121 | return boot_image_type_patches_.GetOrCreate( |
| 1122 | TypeReference(&dex_file, type_index), |
| 1123 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 1124 | } |
| 1125 | |
| 1126 | Literal* CodeGeneratorMIPS::DeduplicateBootImageAddressLiteral(uint32_t address) { |
| 1127 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 1128 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 1129 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 1130 | } |
| 1131 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1132 | void CodeGeneratorMIPS::EmitPcRelativeAddressPlaceholder( |
| 1133 | PcRelativePatchInfo* info, Register out, Register base) { |
| 1134 | bool reordering = __ SetReorder(false); |
| 1135 | if (GetInstructionSetFeatures().IsR6()) { |
| 1136 | DCHECK_EQ(base, ZERO); |
| 1137 | __ Bind(&info->high_label); |
| 1138 | __ Bind(&info->pc_rel_label); |
| 1139 | // Add a 32-bit offset to PC. |
| 1140 | __ Auipc(out, /* placeholder */ 0x1234); |
| 1141 | __ Addiu(out, out, /* placeholder */ 0x5678); |
| 1142 | } else { |
| 1143 | // If base is ZERO, emit NAL to obtain the actual base. |
| 1144 | if (base == ZERO) { |
| 1145 | // Generate a dummy PC-relative call to obtain PC. |
| 1146 | __ Nal(); |
| 1147 | } |
| 1148 | __ Bind(&info->high_label); |
| 1149 | __ Lui(out, /* placeholder */ 0x1234); |
| 1150 | // If we emitted the NAL, bind the pc_rel_label, otherwise base is a register holding |
| 1151 | // the HMipsComputeBaseMethodAddress which has its own label stored in MipsAssembler. |
| 1152 | if (base == ZERO) { |
| 1153 | __ Bind(&info->pc_rel_label); |
| 1154 | } |
| 1155 | __ Ori(out, out, /* placeholder */ 0x5678); |
| 1156 | // Add a 32-bit offset to PC. |
| 1157 | __ Addu(out, out, (base == ZERO) ? RA : base); |
| 1158 | } |
| 1159 | __ SetReorder(reordering); |
| 1160 | } |
| 1161 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1162 | void CodeGeneratorMIPS::MarkGCCard(Register object, Register value) { |
| 1163 | MipsLabel done; |
| 1164 | Register card = AT; |
| 1165 | Register temp = TMP; |
| 1166 | __ Beqz(value, &done); |
| 1167 | __ LoadFromOffset(kLoadWord, |
| 1168 | card, |
| 1169 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1170 | Thread::CardTableOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1171 | __ Srl(temp, object, gc::accounting::CardTable::kCardShift); |
| 1172 | __ Addu(temp, card, temp); |
| 1173 | __ Sb(card, temp, 0); |
| 1174 | __ Bind(&done); |
| 1175 | } |
| 1176 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1177 | void CodeGeneratorMIPS::SetupBlockedRegisters() const { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1178 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1179 | blocked_core_registers_[ZERO] = true; |
| 1180 | blocked_core_registers_[K0] = true; |
| 1181 | blocked_core_registers_[K1] = true; |
| 1182 | blocked_core_registers_[GP] = true; |
| 1183 | blocked_core_registers_[SP] = true; |
| 1184 | blocked_core_registers_[RA] = true; |
| 1185 | |
| 1186 | // AT and TMP(T8) are used as temporary/scratch registers |
| 1187 | // (similar to how AT is used by MIPS assemblers). |
| 1188 | blocked_core_registers_[AT] = true; |
| 1189 | blocked_core_registers_[TMP] = true; |
| 1190 | blocked_fpu_registers_[FTMP] = true; |
| 1191 | |
| 1192 | // Reserve suspend and thread registers. |
| 1193 | blocked_core_registers_[S0] = true; |
| 1194 | blocked_core_registers_[TR] = true; |
| 1195 | |
| 1196 | // Reserve T9 for function calls |
| 1197 | blocked_core_registers_[T9] = true; |
| 1198 | |
| 1199 | // Reserve odd-numbered FPU registers. |
| 1200 | for (size_t i = 1; i < kNumberOfFRegisters; i += 2) { |
| 1201 | blocked_fpu_registers_[i] = true; |
| 1202 | } |
| 1203 | |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 1204 | if (GetGraph()->IsDebuggable()) { |
| 1205 | // Stubs do not save callee-save floating point registers. If the graph |
| 1206 | // is debuggable, we need to deal with these registers differently. For |
| 1207 | // now, just block them. |
| 1208 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1209 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1210 | } |
| 1211 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1212 | } |
| 1213 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1214 | size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1215 | __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index); |
| 1216 | return kMipsWordSize; |
| 1217 | } |
| 1218 | |
| 1219 | size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1220 | __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index); |
| 1221 | return kMipsWordSize; |
| 1222 | } |
| 1223 | |
| 1224 | size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1225 | __ StoreDToOffset(FRegister(reg_id), SP, stack_index); |
| 1226 | return kMipsDoublewordSize; |
| 1227 | } |
| 1228 | |
| 1229 | size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1230 | __ LoadDFromOffset(FRegister(reg_id), SP, stack_index); |
| 1231 | return kMipsDoublewordSize; |
| 1232 | } |
| 1233 | |
| 1234 | void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1235 | stream << Register(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
Vladimir Marko | 623a7a2 | 2016-02-02 18:14:52 +0000 | [diff] [blame] | 1239 | stream << FRegister(reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1240 | } |
| 1241 | |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1242 | constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16; |
| 1243 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1244 | void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1245 | HInstruction* instruction, |
| 1246 | uint32_t dex_pc, |
| 1247 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1248 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1249 | bool reordering = __ SetReorder(false); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1250 | __ LoadFromOffset(kLoadWord, T9, TR, GetThreadOffset<kMipsPointerSize>(entrypoint).Int32Value()); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1251 | __ Jalr(T9); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1252 | if (IsDirectEntrypoint(entrypoint)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1253 | // Reserve argument space on stack (for $a0-$a3) for |
| 1254 | // entrypoints that directly reference native implementations. |
| 1255 | // Called function may use this space to store $a0-$a3 regs. |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1256 | __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1257 | __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1258 | } else { |
| 1259 | __ Nop(); // In delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1260 | } |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1261 | __ SetReorder(reordering); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 1262 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1263 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1264 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path, |
| 1268 | Register class_reg) { |
| 1269 | __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 1270 | __ LoadConst32(AT, mirror::Class::kStatusInitialized); |
| 1271 | __ Blt(TMP, AT, slow_path->GetEntryLabel()); |
| 1272 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 1273 | __ Sync(0); |
| 1274 | __ Bind(slow_path->GetExitLabel()); |
| 1275 | } |
| 1276 | |
| 1277 | void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1278 | __ Sync(0); // Only stype 0 is supported. |
| 1279 | } |
| 1280 | |
| 1281 | void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1282 | HBasicBlock* successor) { |
| 1283 | SuspendCheckSlowPathMIPS* slow_path = |
| 1284 | new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS(instruction, successor); |
| 1285 | codegen_->AddSlowPath(slow_path); |
| 1286 | |
| 1287 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1288 | TMP, |
| 1289 | TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1290 | Thread::ThreadFlagsOffset<kMipsPointerSize>().Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1291 | if (successor == nullptr) { |
| 1292 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
| 1293 | __ Bind(slow_path->GetReturnLabel()); |
| 1294 | } else { |
| 1295 | __ Beqz(TMP, codegen_->GetLabelOf(successor)); |
| 1296 | __ B(slow_path->GetEntryLabel()); |
| 1297 | // slow_path will return to GetLabelOf(successor). |
| 1298 | } |
| 1299 | } |
| 1300 | |
| 1301 | InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph, |
| 1302 | CodeGeneratorMIPS* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1303 | : InstructionCodeGenerator(graph, codegen), |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1304 | assembler_(codegen->GetAssembler()), |
| 1305 | codegen_(codegen) {} |
| 1306 | |
| 1307 | void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1308 | DCHECK_EQ(instruction->InputCount(), 2U); |
| 1309 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1310 | Primitive::Type type = instruction->GetResultType(); |
| 1311 | switch (type) { |
| 1312 | case Primitive::kPrimInt: { |
| 1313 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1314 | HInstruction* right = instruction->InputAt(1); |
| 1315 | bool can_use_imm = false; |
| 1316 | if (right->IsConstant()) { |
| 1317 | int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant()); |
| 1318 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 1319 | can_use_imm = IsUint<16>(imm); |
| 1320 | } else if (instruction->IsAdd()) { |
| 1321 | can_use_imm = IsInt<16>(imm); |
| 1322 | } else { |
| 1323 | DCHECK(instruction->IsSub()); |
| 1324 | can_use_imm = IsInt<16>(-imm); |
| 1325 | } |
| 1326 | } |
| 1327 | if (can_use_imm) |
| 1328 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 1329 | else |
| 1330 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1331 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1332 | break; |
| 1333 | } |
| 1334 | |
| 1335 | case Primitive::kPrimLong: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1336 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1337 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1338 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1339 | break; |
| 1340 | } |
| 1341 | |
| 1342 | case Primitive::kPrimFloat: |
| 1343 | case Primitive::kPrimDouble: |
| 1344 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 1345 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1346 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1347 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1348 | break; |
| 1349 | |
| 1350 | default: |
| 1351 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 1352 | } |
| 1353 | } |
| 1354 | |
| 1355 | void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1356 | Primitive::Type type = instruction->GetType(); |
| 1357 | LocationSummary* locations = instruction->GetLocations(); |
| 1358 | |
| 1359 | switch (type) { |
| 1360 | case Primitive::kPrimInt: { |
| 1361 | Register dst = locations->Out().AsRegister<Register>(); |
| 1362 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 1363 | Location rhs_location = locations->InAt(1); |
| 1364 | |
| 1365 | Register rhs_reg = ZERO; |
| 1366 | int32_t rhs_imm = 0; |
| 1367 | bool use_imm = rhs_location.IsConstant(); |
| 1368 | if (use_imm) { |
| 1369 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 1370 | } else { |
| 1371 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 1372 | } |
| 1373 | |
| 1374 | if (instruction->IsAnd()) { |
| 1375 | if (use_imm) |
| 1376 | __ Andi(dst, lhs, rhs_imm); |
| 1377 | else |
| 1378 | __ And(dst, lhs, rhs_reg); |
| 1379 | } else if (instruction->IsOr()) { |
| 1380 | if (use_imm) |
| 1381 | __ Ori(dst, lhs, rhs_imm); |
| 1382 | else |
| 1383 | __ Or(dst, lhs, rhs_reg); |
| 1384 | } else if (instruction->IsXor()) { |
| 1385 | if (use_imm) |
| 1386 | __ Xori(dst, lhs, rhs_imm); |
| 1387 | else |
| 1388 | __ Xor(dst, lhs, rhs_reg); |
| 1389 | } else if (instruction->IsAdd()) { |
| 1390 | if (use_imm) |
| 1391 | __ Addiu(dst, lhs, rhs_imm); |
| 1392 | else |
| 1393 | __ Addu(dst, lhs, rhs_reg); |
| 1394 | } else { |
| 1395 | DCHECK(instruction->IsSub()); |
| 1396 | if (use_imm) |
| 1397 | __ Addiu(dst, lhs, -rhs_imm); |
| 1398 | else |
| 1399 | __ Subu(dst, lhs, rhs_reg); |
| 1400 | } |
| 1401 | break; |
| 1402 | } |
| 1403 | |
| 1404 | case Primitive::kPrimLong: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1405 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 1406 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 1407 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 1408 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1409 | Location rhs_location = locations->InAt(1); |
| 1410 | bool use_imm = rhs_location.IsConstant(); |
| 1411 | if (!use_imm) { |
| 1412 | Register rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 1413 | Register rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 1414 | if (instruction->IsAnd()) { |
| 1415 | __ And(dst_low, lhs_low, rhs_low); |
| 1416 | __ And(dst_high, lhs_high, rhs_high); |
| 1417 | } else if (instruction->IsOr()) { |
| 1418 | __ Or(dst_low, lhs_low, rhs_low); |
| 1419 | __ Or(dst_high, lhs_high, rhs_high); |
| 1420 | } else if (instruction->IsXor()) { |
| 1421 | __ Xor(dst_low, lhs_low, rhs_low); |
| 1422 | __ Xor(dst_high, lhs_high, rhs_high); |
| 1423 | } else if (instruction->IsAdd()) { |
| 1424 | if (lhs_low == rhs_low) { |
| 1425 | // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs. |
| 1426 | __ Slt(TMP, lhs_low, ZERO); |
| 1427 | __ Addu(dst_low, lhs_low, rhs_low); |
| 1428 | } else { |
| 1429 | __ Addu(dst_low, lhs_low, rhs_low); |
| 1430 | // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged. |
| 1431 | __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low); |
| 1432 | } |
| 1433 | __ Addu(dst_high, lhs_high, rhs_high); |
| 1434 | __ Addu(dst_high, dst_high, TMP); |
| 1435 | } else { |
| 1436 | DCHECK(instruction->IsSub()); |
| 1437 | __ Sltu(TMP, lhs_low, rhs_low); |
| 1438 | __ Subu(dst_low, lhs_low, rhs_low); |
| 1439 | __ Subu(dst_high, lhs_high, rhs_high); |
| 1440 | __ Subu(dst_high, dst_high, TMP); |
| 1441 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1442 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1443 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 1444 | if (instruction->IsOr()) { |
| 1445 | uint32_t low = Low32Bits(value); |
| 1446 | uint32_t high = High32Bits(value); |
| 1447 | if (IsUint<16>(low)) { |
| 1448 | if (dst_low != lhs_low || low != 0) { |
| 1449 | __ Ori(dst_low, lhs_low, low); |
| 1450 | } |
| 1451 | } else { |
| 1452 | __ LoadConst32(TMP, low); |
| 1453 | __ Or(dst_low, lhs_low, TMP); |
| 1454 | } |
| 1455 | if (IsUint<16>(high)) { |
| 1456 | if (dst_high != lhs_high || high != 0) { |
| 1457 | __ Ori(dst_high, lhs_high, high); |
| 1458 | } |
| 1459 | } else { |
| 1460 | if (high != low) { |
| 1461 | __ LoadConst32(TMP, high); |
| 1462 | } |
| 1463 | __ Or(dst_high, lhs_high, TMP); |
| 1464 | } |
| 1465 | } else if (instruction->IsXor()) { |
| 1466 | uint32_t low = Low32Bits(value); |
| 1467 | uint32_t high = High32Bits(value); |
| 1468 | if (IsUint<16>(low)) { |
| 1469 | if (dst_low != lhs_low || low != 0) { |
| 1470 | __ Xori(dst_low, lhs_low, low); |
| 1471 | } |
| 1472 | } else { |
| 1473 | __ LoadConst32(TMP, low); |
| 1474 | __ Xor(dst_low, lhs_low, TMP); |
| 1475 | } |
| 1476 | if (IsUint<16>(high)) { |
| 1477 | if (dst_high != lhs_high || high != 0) { |
| 1478 | __ Xori(dst_high, lhs_high, high); |
| 1479 | } |
| 1480 | } else { |
| 1481 | if (high != low) { |
| 1482 | __ LoadConst32(TMP, high); |
| 1483 | } |
| 1484 | __ Xor(dst_high, lhs_high, TMP); |
| 1485 | } |
| 1486 | } else if (instruction->IsAnd()) { |
| 1487 | uint32_t low = Low32Bits(value); |
| 1488 | uint32_t high = High32Bits(value); |
| 1489 | if (IsUint<16>(low)) { |
| 1490 | __ Andi(dst_low, lhs_low, low); |
| 1491 | } else if (low != 0xFFFFFFFF) { |
| 1492 | __ LoadConst32(TMP, low); |
| 1493 | __ And(dst_low, lhs_low, TMP); |
| 1494 | } else if (dst_low != lhs_low) { |
| 1495 | __ Move(dst_low, lhs_low); |
| 1496 | } |
| 1497 | if (IsUint<16>(high)) { |
| 1498 | __ Andi(dst_high, lhs_high, high); |
| 1499 | } else if (high != 0xFFFFFFFF) { |
| 1500 | if (high != low) { |
| 1501 | __ LoadConst32(TMP, high); |
| 1502 | } |
| 1503 | __ And(dst_high, lhs_high, TMP); |
| 1504 | } else if (dst_high != lhs_high) { |
| 1505 | __ Move(dst_high, lhs_high); |
| 1506 | } |
| 1507 | } else { |
| 1508 | if (instruction->IsSub()) { |
| 1509 | value = -value; |
| 1510 | } else { |
| 1511 | DCHECK(instruction->IsAdd()); |
| 1512 | } |
| 1513 | int32_t low = Low32Bits(value); |
| 1514 | int32_t high = High32Bits(value); |
| 1515 | if (IsInt<16>(low)) { |
| 1516 | if (dst_low != lhs_low || low != 0) { |
| 1517 | __ Addiu(dst_low, lhs_low, low); |
| 1518 | } |
| 1519 | if (low != 0) { |
| 1520 | __ Sltiu(AT, dst_low, low); |
| 1521 | } |
| 1522 | } else { |
| 1523 | __ LoadConst32(TMP, low); |
| 1524 | __ Addu(dst_low, lhs_low, TMP); |
| 1525 | __ Sltu(AT, dst_low, TMP); |
| 1526 | } |
| 1527 | if (IsInt<16>(high)) { |
| 1528 | if (dst_high != lhs_high || high != 0) { |
| 1529 | __ Addiu(dst_high, lhs_high, high); |
| 1530 | } |
| 1531 | } else { |
| 1532 | if (high != low) { |
| 1533 | __ LoadConst32(TMP, high); |
| 1534 | } |
| 1535 | __ Addu(dst_high, lhs_high, TMP); |
| 1536 | } |
| 1537 | if (low != 0) { |
| 1538 | __ Addu(dst_high, dst_high, AT); |
| 1539 | } |
| 1540 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1541 | } |
| 1542 | break; |
| 1543 | } |
| 1544 | |
| 1545 | case Primitive::kPrimFloat: |
| 1546 | case Primitive::kPrimDouble: { |
| 1547 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 1548 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 1549 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 1550 | if (instruction->IsAdd()) { |
| 1551 | if (type == Primitive::kPrimFloat) { |
| 1552 | __ AddS(dst, lhs, rhs); |
| 1553 | } else { |
| 1554 | __ AddD(dst, lhs, rhs); |
| 1555 | } |
| 1556 | } else { |
| 1557 | DCHECK(instruction->IsSub()); |
| 1558 | if (type == Primitive::kPrimFloat) { |
| 1559 | __ SubS(dst, lhs, rhs); |
| 1560 | } else { |
| 1561 | __ SubD(dst, lhs, rhs); |
| 1562 | } |
| 1563 | } |
| 1564 | break; |
| 1565 | } |
| 1566 | |
| 1567 | default: |
| 1568 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 1569 | } |
| 1570 | } |
| 1571 | |
| 1572 | void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1573 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1574 | |
| 1575 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1576 | Primitive::Type type = instr->GetResultType(); |
| 1577 | switch (type) { |
| 1578 | case Primitive::kPrimInt: |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1579 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1580 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 1581 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1582 | break; |
| 1583 | case Primitive::kPrimLong: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1584 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1585 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 1586 | locations->SetOut(Location::RequiresRegister()); |
| 1587 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1588 | default: |
| 1589 | LOG(FATAL) << "Unexpected shift type " << type; |
| 1590 | } |
| 1591 | } |
| 1592 | |
| 1593 | static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte; |
| 1594 | |
| 1595 | void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1596 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1597 | LocationSummary* locations = instr->GetLocations(); |
| 1598 | Primitive::Type type = instr->GetType(); |
| 1599 | |
| 1600 | Location rhs_location = locations->InAt(1); |
| 1601 | bool use_imm = rhs_location.IsConstant(); |
| 1602 | Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>(); |
| 1603 | int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 1604 | const uint32_t shift_mask = |
| 1605 | (type == Primitive::kPrimInt) ? kMaxIntShiftDistance : kMaxLongShiftDistance; |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1606 | const uint32_t shift_value = rhs_imm & shift_mask; |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1607 | // Are the INS (Insert Bit Field) and ROTR instructions supported? |
| 1608 | bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1609 | |
| 1610 | switch (type) { |
| 1611 | case Primitive::kPrimInt: { |
| 1612 | Register dst = locations->Out().AsRegister<Register>(); |
| 1613 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 1614 | if (use_imm) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1615 | if (shift_value == 0) { |
| 1616 | if (dst != lhs) { |
| 1617 | __ Move(dst, lhs); |
| 1618 | } |
| 1619 | } else if (instr->IsShl()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1620 | __ Sll(dst, lhs, shift_value); |
| 1621 | } else if (instr->IsShr()) { |
| 1622 | __ Sra(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1623 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1624 | __ Srl(dst, lhs, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1625 | } else { |
| 1626 | if (has_ins_rotr) { |
| 1627 | __ Rotr(dst, lhs, shift_value); |
| 1628 | } else { |
| 1629 | __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask); |
| 1630 | __ Srl(dst, lhs, shift_value); |
| 1631 | __ Or(dst, dst, TMP); |
| 1632 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1633 | } |
| 1634 | } else { |
| 1635 | if (instr->IsShl()) { |
| 1636 | __ Sllv(dst, lhs, rhs_reg); |
| 1637 | } else if (instr->IsShr()) { |
| 1638 | __ Srav(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1639 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1640 | __ Srlv(dst, lhs, rhs_reg); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1641 | } else { |
| 1642 | if (has_ins_rotr) { |
| 1643 | __ Rotrv(dst, lhs, rhs_reg); |
| 1644 | } else { |
| 1645 | __ Subu(TMP, ZERO, rhs_reg); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1646 | // 32-bit shift instructions use the 5 least significant bits of the shift count, so |
| 1647 | // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case |
| 1648 | // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out |
| 1649 | // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`, |
| 1650 | // IOW, the OR'd values are equal. |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1651 | __ Sllv(TMP, lhs, TMP); |
| 1652 | __ Srlv(dst, lhs, rhs_reg); |
| 1653 | __ Or(dst, dst, TMP); |
| 1654 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1655 | } |
| 1656 | } |
| 1657 | break; |
| 1658 | } |
| 1659 | |
| 1660 | case Primitive::kPrimLong: { |
| 1661 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 1662 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 1663 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 1664 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 1665 | if (use_imm) { |
| 1666 | if (shift_value == 0) { |
| 1667 | codegen_->Move64(locations->Out(), locations->InAt(0)); |
| 1668 | } else if (shift_value < kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1669 | if (has_ins_rotr) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1670 | if (instr->IsShl()) { |
| 1671 | __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 1672 | __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value); |
| 1673 | __ Sll(dst_low, lhs_low, shift_value); |
| 1674 | } else if (instr->IsShr()) { |
| 1675 | __ Srl(dst_low, lhs_low, shift_value); |
| 1676 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 1677 | __ Sra(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1678 | } else if (instr->IsUShr()) { |
| 1679 | __ Srl(dst_low, lhs_low, shift_value); |
| 1680 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 1681 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1682 | } else { |
| 1683 | __ Srl(dst_low, lhs_low, shift_value); |
| 1684 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 1685 | __ Srl(dst_high, lhs_high, shift_value); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1686 | __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1687 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1688 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1689 | if (instr->IsShl()) { |
| 1690 | __ Sll(dst_low, lhs_low, shift_value); |
| 1691 | __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value); |
| 1692 | __ Sll(dst_high, lhs_high, shift_value); |
| 1693 | __ Or(dst_high, dst_high, TMP); |
| 1694 | } else if (instr->IsShr()) { |
| 1695 | __ Sra(dst_high, lhs_high, shift_value); |
| 1696 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 1697 | __ Srl(dst_low, lhs_low, shift_value); |
| 1698 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1699 | } else if (instr->IsUShr()) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1700 | __ Srl(dst_high, lhs_high, shift_value); |
| 1701 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 1702 | __ Srl(dst_low, lhs_low, shift_value); |
| 1703 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1704 | } else { |
| 1705 | __ Srl(TMP, lhs_low, shift_value); |
| 1706 | __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value); |
| 1707 | __ Or(dst_low, dst_low, TMP); |
| 1708 | __ Srl(TMP, lhs_high, shift_value); |
| 1709 | __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 1710 | __ Or(dst_high, dst_high, TMP); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1711 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1712 | } |
| 1713 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1714 | const uint32_t shift_value_high = shift_value - kMipsBitsPerWord; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1715 | if (instr->IsShl()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1716 | __ Sll(dst_high, lhs_low, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1717 | __ Move(dst_low, ZERO); |
| 1718 | } else if (instr->IsShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1719 | __ Sra(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1720 | __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1721 | } else if (instr->IsUShr()) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1722 | __ Srl(dst_low, lhs_high, shift_value_high); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1723 | __ Move(dst_high, ZERO); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1724 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1725 | if (shift_value == kMipsBitsPerWord) { |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1726 | // 64-bit rotation by 32 is just a swap. |
| 1727 | __ Move(dst_low, lhs_high); |
| 1728 | __ Move(dst_high, lhs_low); |
| 1729 | } else { |
| 1730 | if (has_ins_rotr) { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1731 | __ Srl(dst_low, lhs_high, shift_value_high); |
| 1732 | __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high); |
| 1733 | __ Srl(dst_high, lhs_low, shift_value_high); |
| 1734 | __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1735 | } else { |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1736 | __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high); |
| 1737 | __ Srl(dst_low, lhs_high, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1738 | __ Or(dst_low, dst_low, TMP); |
Alexey Frunze | 0d9150b | 2016-01-13 16:24:25 -0800 | [diff] [blame] | 1739 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high); |
| 1740 | __ Srl(dst_high, lhs_low, shift_value_high); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1741 | __ Or(dst_high, dst_high, TMP); |
| 1742 | } |
| 1743 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1744 | } |
| 1745 | } |
| 1746 | } else { |
| 1747 | MipsLabel done; |
| 1748 | if (instr->IsShl()) { |
| 1749 | __ Sllv(dst_low, lhs_low, rhs_reg); |
| 1750 | __ Nor(AT, ZERO, rhs_reg); |
| 1751 | __ Srl(TMP, lhs_low, 1); |
| 1752 | __ Srlv(TMP, TMP, AT); |
| 1753 | __ Sllv(dst_high, lhs_high, rhs_reg); |
| 1754 | __ Or(dst_high, dst_high, TMP); |
| 1755 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 1756 | __ Beqz(TMP, &done); |
| 1757 | __ Move(dst_high, dst_low); |
| 1758 | __ Move(dst_low, ZERO); |
| 1759 | } else if (instr->IsShr()) { |
| 1760 | __ Srav(dst_high, lhs_high, rhs_reg); |
| 1761 | __ Nor(AT, ZERO, rhs_reg); |
| 1762 | __ Sll(TMP, lhs_high, 1); |
| 1763 | __ Sllv(TMP, TMP, AT); |
| 1764 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 1765 | __ Or(dst_low, dst_low, TMP); |
| 1766 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 1767 | __ Beqz(TMP, &done); |
| 1768 | __ Move(dst_low, dst_high); |
| 1769 | __ Sra(dst_high, dst_high, 31); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1770 | } else if (instr->IsUShr()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1771 | __ Srlv(dst_high, lhs_high, rhs_reg); |
| 1772 | __ Nor(AT, ZERO, rhs_reg); |
| 1773 | __ Sll(TMP, lhs_high, 1); |
| 1774 | __ Sllv(TMP, TMP, AT); |
| 1775 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 1776 | __ Or(dst_low, dst_low, TMP); |
| 1777 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 1778 | __ Beqz(TMP, &done); |
| 1779 | __ Move(dst_low, dst_high); |
| 1780 | __ Move(dst_high, ZERO); |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 1781 | } else { |
| 1782 | __ Nor(AT, ZERO, rhs_reg); |
| 1783 | __ Srlv(TMP, lhs_low, rhs_reg); |
| 1784 | __ Sll(dst_low, lhs_high, 1); |
| 1785 | __ Sllv(dst_low, dst_low, AT); |
| 1786 | __ Or(dst_low, dst_low, TMP); |
| 1787 | __ Srlv(TMP, lhs_high, rhs_reg); |
| 1788 | __ Sll(dst_high, lhs_low, 1); |
| 1789 | __ Sllv(dst_high, dst_high, AT); |
| 1790 | __ Or(dst_high, dst_high, TMP); |
| 1791 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 1792 | __ Beqz(TMP, &done); |
| 1793 | __ Move(TMP, dst_high); |
| 1794 | __ Move(dst_high, dst_low); |
| 1795 | __ Move(dst_low, TMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1796 | } |
| 1797 | __ Bind(&done); |
| 1798 | } |
| 1799 | break; |
| 1800 | } |
| 1801 | |
| 1802 | default: |
| 1803 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 1804 | } |
| 1805 | } |
| 1806 | |
| 1807 | void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) { |
| 1808 | HandleBinaryOp(instruction); |
| 1809 | } |
| 1810 | |
| 1811 | void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) { |
| 1812 | HandleBinaryOp(instruction); |
| 1813 | } |
| 1814 | |
| 1815 | void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) { |
| 1816 | HandleBinaryOp(instruction); |
| 1817 | } |
| 1818 | |
| 1819 | void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) { |
| 1820 | HandleBinaryOp(instruction); |
| 1821 | } |
| 1822 | |
| 1823 | void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) { |
| 1824 | LocationSummary* locations = |
| 1825 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1826 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1827 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1828 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 1829 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1830 | } else { |
| 1831 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1832 | } |
| 1833 | } |
| 1834 | |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1835 | auto InstructionCodeGeneratorMIPS::GetImplicitNullChecker(HInstruction* instruction) { |
| 1836 | auto null_checker = [this, instruction]() { |
| 1837 | this->codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1838 | }; |
| 1839 | return null_checker; |
| 1840 | } |
| 1841 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1842 | void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) { |
| 1843 | LocationSummary* locations = instruction->GetLocations(); |
| 1844 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 1845 | Location index = locations->InAt(1); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 1846 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1847 | auto null_checker = GetImplicitNullChecker(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1848 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 1849 | Primitive::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1850 | switch (type) { |
| 1851 | case Primitive::kPrimBoolean: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1852 | Register out = locations->Out().AsRegister<Register>(); |
| 1853 | if (index.IsConstant()) { |
| 1854 | size_t offset = |
| 1855 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1856 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1857 | } else { |
| 1858 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1859 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1860 | } |
| 1861 | break; |
| 1862 | } |
| 1863 | |
| 1864 | case Primitive::kPrimByte: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1865 | Register out = locations->Out().AsRegister<Register>(); |
| 1866 | if (index.IsConstant()) { |
| 1867 | size_t offset = |
| 1868 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1869 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1870 | } else { |
| 1871 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1872 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1873 | } |
| 1874 | break; |
| 1875 | } |
| 1876 | |
| 1877 | case Primitive::kPrimShort: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1878 | Register out = locations->Out().AsRegister<Register>(); |
| 1879 | if (index.IsConstant()) { |
| 1880 | size_t offset = |
| 1881 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1882 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1883 | } else { |
| 1884 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_2); |
| 1885 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1886 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1887 | } |
| 1888 | break; |
| 1889 | } |
| 1890 | |
| 1891 | case Primitive::kPrimChar: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1892 | Register out = locations->Out().AsRegister<Register>(); |
| 1893 | if (index.IsConstant()) { |
| 1894 | size_t offset = |
| 1895 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1896 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1897 | } else { |
| 1898 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_2); |
| 1899 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1900 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1901 | } |
| 1902 | break; |
| 1903 | } |
| 1904 | |
| 1905 | case Primitive::kPrimInt: |
| 1906 | case Primitive::kPrimNot: { |
| 1907 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1908 | Register out = locations->Out().AsRegister<Register>(); |
| 1909 | if (index.IsConstant()) { |
| 1910 | size_t offset = |
| 1911 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1912 | __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1913 | } else { |
| 1914 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_4); |
| 1915 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1916 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1917 | } |
| 1918 | break; |
| 1919 | } |
| 1920 | |
| 1921 | case Primitive::kPrimLong: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1922 | Register out = locations->Out().AsRegisterPairLow<Register>(); |
| 1923 | if (index.IsConstant()) { |
| 1924 | size_t offset = |
| 1925 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1926 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1927 | } else { |
| 1928 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_8); |
| 1929 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1930 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1931 | } |
| 1932 | break; |
| 1933 | } |
| 1934 | |
| 1935 | case Primitive::kPrimFloat: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1936 | FRegister out = locations->Out().AsFpuRegister<FRegister>(); |
| 1937 | if (index.IsConstant()) { |
| 1938 | size_t offset = |
| 1939 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1940 | __ LoadSFromOffset(out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1941 | } else { |
| 1942 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_4); |
| 1943 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1944 | __ LoadSFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1945 | } |
| 1946 | break; |
| 1947 | } |
| 1948 | |
| 1949 | case Primitive::kPrimDouble: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1950 | FRegister out = locations->Out().AsFpuRegister<FRegister>(); |
| 1951 | if (index.IsConstant()) { |
| 1952 | size_t offset = |
| 1953 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1954 | __ LoadDFromOffset(out, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1955 | } else { |
| 1956 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_8); |
| 1957 | __ Addu(TMP, obj, TMP); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 1958 | __ LoadDFromOffset(out, TMP, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1959 | } |
| 1960 | break; |
| 1961 | } |
| 1962 | |
| 1963 | case Primitive::kPrimVoid: |
| 1964 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 1965 | UNREACHABLE(); |
| 1966 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) { |
| 1970 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1971 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1972 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1973 | } |
| 1974 | |
| 1975 | void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) { |
| 1976 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 1977 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1978 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 1979 | Register out = locations->Out().AsRegister<Register>(); |
| 1980 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 1981 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1982 | } |
| 1983 | |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 1984 | Location LocationsBuilderMIPS::RegisterOrZeroConstant(HInstruction* instruction) { |
| 1985 | return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern()) |
| 1986 | ? Location::ConstantLocation(instruction->AsConstant()) |
| 1987 | : Location::RequiresRegister(); |
| 1988 | } |
| 1989 | |
| 1990 | Location LocationsBuilderMIPS::FpuRegisterOrConstantForStore(HInstruction* instruction) { |
| 1991 | // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register. |
| 1992 | // We can store a non-zero float or double constant without first loading it into the FPU, |
| 1993 | // but we should only prefer this if the constant has a single use. |
| 1994 | if (instruction->IsConstant() && |
| 1995 | (instruction->AsConstant()->IsZeroBitPattern() || |
| 1996 | instruction->GetUses().HasExactlyOneElement())) { |
| 1997 | return Location::ConstantLocation(instruction->AsConstant()); |
| 1998 | // Otherwise fall through and require an FPU register for the constant. |
| 1999 | } |
| 2000 | return Location::RequiresFpuRegister(); |
| 2001 | } |
| 2002 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2003 | void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) { |
Pavle Batuta | 934808f | 2015-11-03 13:23:54 +0100 | [diff] [blame] | 2004 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2005 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2006 | instruction, |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2007 | needs_runtime_call ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); |
Pavle Batuta | 934808f | 2015-11-03 13:23:54 +0100 | [diff] [blame] | 2008 | if (needs_runtime_call) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2009 | InvokeRuntimeCallingConvention calling_convention; |
| 2010 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2011 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2012 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 2013 | } else { |
| 2014 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2015 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2016 | if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2017 | locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2018 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2019 | locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2020 | } |
| 2021 | } |
| 2022 | } |
| 2023 | |
| 2024 | void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) { |
| 2025 | LocationSummary* locations = instruction->GetLocations(); |
| 2026 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2027 | Location index = locations->InAt(1); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2028 | Location value_location = locations->InAt(2); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2029 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2030 | bool needs_runtime_call = locations->WillCall(); |
| 2031 | bool needs_write_barrier = |
| 2032 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 2033 | auto null_checker = GetImplicitNullChecker(instruction); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2034 | Register base_reg = index.IsConstant() ? obj : TMP; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2035 | |
| 2036 | switch (value_type) { |
| 2037 | case Primitive::kPrimBoolean: |
| 2038 | case Primitive::kPrimByte: { |
| 2039 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2040 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2041 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2042 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2043 | __ Addu(base_reg, obj, index.AsRegister<Register>()); |
| 2044 | } |
| 2045 | if (value_location.IsConstant()) { |
| 2046 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2047 | __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker); |
| 2048 | } else { |
| 2049 | Register value = value_location.AsRegister<Register>(); |
| 2050 | __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2051 | } |
| 2052 | break; |
| 2053 | } |
| 2054 | |
| 2055 | case Primitive::kPrimShort: |
| 2056 | case Primitive::kPrimChar: { |
| 2057 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2058 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2059 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2060 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2061 | __ Sll(base_reg, index.AsRegister<Register>(), TIMES_2); |
| 2062 | __ Addu(base_reg, obj, base_reg); |
| 2063 | } |
| 2064 | if (value_location.IsConstant()) { |
| 2065 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2066 | __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker); |
| 2067 | } else { |
| 2068 | Register value = value_location.AsRegister<Register>(); |
| 2069 | __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2070 | } |
| 2071 | break; |
| 2072 | } |
| 2073 | |
| 2074 | case Primitive::kPrimInt: |
| 2075 | case Primitive::kPrimNot: { |
| 2076 | if (!needs_runtime_call) { |
| 2077 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2078 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2079 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2080 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2081 | __ Sll(base_reg, index.AsRegister<Register>(), TIMES_4); |
| 2082 | __ Addu(base_reg, obj, base_reg); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2083 | } |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2084 | if (value_location.IsConstant()) { |
| 2085 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2086 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2087 | DCHECK(!needs_write_barrier); |
| 2088 | } else { |
| 2089 | Register value = value_location.AsRegister<Register>(); |
| 2090 | __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker); |
| 2091 | if (needs_write_barrier) { |
| 2092 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 2093 | codegen_->MarkGCCard(obj, value); |
| 2094 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2095 | } |
| 2096 | } else { |
| 2097 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 2098 | codegen_->InvokeRuntime(kQuickAputObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2099 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 2100 | } |
| 2101 | break; |
| 2102 | } |
| 2103 | |
| 2104 | case Primitive::kPrimLong: { |
| 2105 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2106 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2107 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2108 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2109 | __ Sll(base_reg, index.AsRegister<Register>(), TIMES_8); |
| 2110 | __ Addu(base_reg, obj, base_reg); |
| 2111 | } |
| 2112 | if (value_location.IsConstant()) { |
| 2113 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2114 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2115 | } else { |
| 2116 | Register value = value_location.AsRegisterPairLow<Register>(); |
| 2117 | __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2118 | } |
| 2119 | break; |
| 2120 | } |
| 2121 | |
| 2122 | case Primitive::kPrimFloat: { |
| 2123 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2124 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2125 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2126 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2127 | __ Sll(base_reg, index.AsRegister<Register>(), TIMES_4); |
| 2128 | __ Addu(base_reg, obj, base_reg); |
| 2129 | } |
| 2130 | if (value_location.IsConstant()) { |
| 2131 | int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant()); |
| 2132 | __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker); |
| 2133 | } else { |
| 2134 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 2135 | __ StoreSToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2136 | } |
| 2137 | break; |
| 2138 | } |
| 2139 | |
| 2140 | case Primitive::kPrimDouble: { |
| 2141 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2142 | if (index.IsConstant()) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2143 | data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2144 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 2145 | __ Sll(base_reg, index.AsRegister<Register>(), TIMES_8); |
| 2146 | __ Addu(base_reg, obj, base_reg); |
| 2147 | } |
| 2148 | if (value_location.IsConstant()) { |
| 2149 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 2150 | __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker); |
| 2151 | } else { |
| 2152 | FRegister value = value_location.AsFpuRegister<FRegister>(); |
| 2153 | __ StoreDToOffset(value, base_reg, data_offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2154 | } |
| 2155 | break; |
| 2156 | } |
| 2157 | |
| 2158 | case Primitive::kPrimVoid: |
| 2159 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2160 | UNREACHABLE(); |
| 2161 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2165 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2166 | InvokeRuntimeCallingConvention calling_convention; |
| 2167 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2168 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2169 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2170 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2171 | locations->SetInAt(1, Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2172 | } |
| 2173 | |
| 2174 | void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2175 | LocationSummary* locations = instruction->GetLocations(); |
| 2176 | BoundsCheckSlowPathMIPS* slow_path = |
| 2177 | new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS(instruction); |
| 2178 | codegen_->AddSlowPath(slow_path); |
| 2179 | |
| 2180 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 2181 | Register length = locations->InAt(1).AsRegister<Register>(); |
| 2182 | |
| 2183 | // length is limited by the maximum positive signed 32-bit integer. |
| 2184 | // Unsigned comparison of length and index checks for index < 0 |
| 2185 | // and for length <= index simultaneously. |
| 2186 | __ Bgeu(index, length, slow_path->GetEntryLabel()); |
| 2187 | } |
| 2188 | |
| 2189 | void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) { |
| 2190 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2191 | instruction, |
| 2192 | LocationSummary::kCallOnSlowPath); |
| 2193 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2194 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2195 | // Note that TypeCheckSlowPathMIPS uses this register too. |
| 2196 | locations->AddTemp(Location::RequiresRegister()); |
| 2197 | } |
| 2198 | |
| 2199 | void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) { |
| 2200 | LocationSummary* locations = instruction->GetLocations(); |
| 2201 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2202 | Register cls = locations->InAt(1).AsRegister<Register>(); |
| 2203 | Register obj_cls = locations->GetTemp(0).AsRegister<Register>(); |
| 2204 | |
| 2205 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction); |
| 2206 | codegen_->AddSlowPath(slow_path); |
| 2207 | |
| 2208 | // TODO: avoid this check if we know obj is not null. |
| 2209 | __ Beqz(obj, slow_path->GetExitLabel()); |
| 2210 | // Compare the class of `obj` with `cls`. |
| 2211 | __ LoadFromOffset(kLoadWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value()); |
| 2212 | __ Bne(obj_cls, cls, slow_path->GetEntryLabel()); |
| 2213 | __ Bind(slow_path->GetExitLabel()); |
| 2214 | } |
| 2215 | |
| 2216 | void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 2217 | LocationSummary* locations = |
| 2218 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2219 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2220 | if (check->HasUses()) { |
| 2221 | locations->SetOut(Location::SameAsFirstInput()); |
| 2222 | } |
| 2223 | } |
| 2224 | |
| 2225 | void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 2226 | // We assume the class is not null. |
| 2227 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS( |
| 2228 | check->GetLoadClass(), |
| 2229 | check, |
| 2230 | check->GetDexPc(), |
| 2231 | true); |
| 2232 | codegen_->AddSlowPath(slow_path); |
| 2233 | GenerateClassInitializationCheck(slow_path, |
| 2234 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
| 2235 | } |
| 2236 | |
| 2237 | void LocationsBuilderMIPS::VisitCompare(HCompare* compare) { |
| 2238 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 2239 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2240 | LocationSummary* locations = |
| 2241 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2242 | |
| 2243 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2244 | case Primitive::kPrimBoolean: |
| 2245 | case Primitive::kPrimByte: |
| 2246 | case Primitive::kPrimShort: |
| 2247 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2248 | case Primitive::kPrimInt: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 2249 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2250 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2251 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2252 | break; |
| 2253 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2254 | case Primitive::kPrimLong: |
| 2255 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2256 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2257 | // Output overlaps because it is written before doing the low comparison. |
| 2258 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2259 | break; |
| 2260 | |
| 2261 | case Primitive::kPrimFloat: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2262 | case Primitive::kPrimDouble: |
| 2263 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2264 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2265 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2266 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2267 | |
| 2268 | default: |
| 2269 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2270 | } |
| 2271 | } |
| 2272 | |
| 2273 | void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) { |
| 2274 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2275 | Register res = locations->Out().AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2276 | Primitive::Type in_type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2277 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2278 | |
| 2279 | // 0 if: left == right |
| 2280 | // 1 if: left > right |
| 2281 | // -1 if: left < right |
| 2282 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2283 | case Primitive::kPrimBoolean: |
| 2284 | case Primitive::kPrimByte: |
| 2285 | case Primitive::kPrimShort: |
| 2286 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2287 | case Primitive::kPrimInt: { |
| 2288 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2289 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 2290 | __ Slt(TMP, lhs, rhs); |
| 2291 | __ Slt(res, rhs, lhs); |
| 2292 | __ Subu(res, res, TMP); |
| 2293 | break; |
| 2294 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2295 | case Primitive::kPrimLong: { |
| 2296 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2297 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2298 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 2299 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 2300 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 2301 | // TODO: more efficient (direct) comparison with a constant. |
| 2302 | __ Slt(TMP, lhs_high, rhs_high); |
| 2303 | __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt. |
| 2304 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 2305 | __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal. |
| 2306 | __ Sltu(TMP, lhs_low, rhs_low); |
| 2307 | __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt. |
| 2308 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 2309 | __ Bind(&done); |
| 2310 | break; |
| 2311 | } |
| 2312 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2313 | case Primitive::kPrimFloat: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 2314 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2315 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2316 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2317 | MipsLabel done; |
| 2318 | if (isR6) { |
| 2319 | __ CmpEqS(FTMP, lhs, rhs); |
| 2320 | __ LoadConst32(res, 0); |
| 2321 | __ Bc1nez(FTMP, &done); |
| 2322 | if (gt_bias) { |
| 2323 | __ CmpLtS(FTMP, lhs, rhs); |
| 2324 | __ LoadConst32(res, -1); |
| 2325 | __ Bc1nez(FTMP, &done); |
| 2326 | __ LoadConst32(res, 1); |
| 2327 | } else { |
| 2328 | __ CmpLtS(FTMP, rhs, lhs); |
| 2329 | __ LoadConst32(res, 1); |
| 2330 | __ Bc1nez(FTMP, &done); |
| 2331 | __ LoadConst32(res, -1); |
| 2332 | } |
| 2333 | } else { |
| 2334 | if (gt_bias) { |
| 2335 | __ ColtS(0, lhs, rhs); |
| 2336 | __ LoadConst32(res, -1); |
| 2337 | __ Bc1t(0, &done); |
| 2338 | __ CeqS(0, lhs, rhs); |
| 2339 | __ LoadConst32(res, 1); |
| 2340 | __ Movt(res, ZERO, 0); |
| 2341 | } else { |
| 2342 | __ ColtS(0, rhs, lhs); |
| 2343 | __ LoadConst32(res, 1); |
| 2344 | __ Bc1t(0, &done); |
| 2345 | __ CeqS(0, lhs, rhs); |
| 2346 | __ LoadConst32(res, -1); |
| 2347 | __ Movt(res, ZERO, 0); |
| 2348 | } |
| 2349 | } |
| 2350 | __ Bind(&done); |
| 2351 | break; |
| 2352 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2353 | case Primitive::kPrimDouble: { |
Roland Levillain | 32ca375 | 2016-02-17 16:49:37 +0000 | [diff] [blame] | 2354 | bool gt_bias = instruction->IsGtBias(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2355 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2356 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2357 | MipsLabel done; |
| 2358 | if (isR6) { |
| 2359 | __ CmpEqD(FTMP, lhs, rhs); |
| 2360 | __ LoadConst32(res, 0); |
| 2361 | __ Bc1nez(FTMP, &done); |
| 2362 | if (gt_bias) { |
| 2363 | __ CmpLtD(FTMP, lhs, rhs); |
| 2364 | __ LoadConst32(res, -1); |
| 2365 | __ Bc1nez(FTMP, &done); |
| 2366 | __ LoadConst32(res, 1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2367 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2368 | __ CmpLtD(FTMP, rhs, lhs); |
| 2369 | __ LoadConst32(res, 1); |
| 2370 | __ Bc1nez(FTMP, &done); |
| 2371 | __ LoadConst32(res, -1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2372 | } |
| 2373 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2374 | if (gt_bias) { |
| 2375 | __ ColtD(0, lhs, rhs); |
| 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 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2382 | __ ColtD(0, rhs, lhs); |
| 2383 | __ LoadConst32(res, 1); |
| 2384 | __ Bc1t(0, &done); |
| 2385 | __ CeqD(0, lhs, rhs); |
| 2386 | __ LoadConst32(res, -1); |
| 2387 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2388 | } |
| 2389 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2390 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2391 | break; |
| 2392 | } |
| 2393 | |
| 2394 | default: |
| 2395 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2396 | } |
| 2397 | } |
| 2398 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2399 | void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2400 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2401 | switch (instruction->InputAt(0)->GetType()) { |
| 2402 | default: |
| 2403 | case Primitive::kPrimLong: |
| 2404 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2405 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2406 | break; |
| 2407 | |
| 2408 | case Primitive::kPrimFloat: |
| 2409 | case Primitive::kPrimDouble: |
| 2410 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2411 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2412 | break; |
| 2413 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2414 | if (!instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2415 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2416 | } |
| 2417 | } |
| 2418 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2419 | void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2420 | if (instruction->IsEmittedAtUseSite()) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2421 | return; |
| 2422 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2423 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2424 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2425 | LocationSummary* locations = instruction->GetLocations(); |
| 2426 | Register dst = locations->Out().AsRegister<Register>(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2427 | MipsLabel true_label; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2428 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2429 | switch (type) { |
| 2430 | default: |
| 2431 | // Integer case. |
| 2432 | GenerateIntCompare(instruction->GetCondition(), locations); |
| 2433 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2434 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2435 | case Primitive::kPrimLong: |
| 2436 | // TODO: don't use branches. |
| 2437 | GenerateLongCompareAndBranch(instruction->GetCondition(), locations, &true_label); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2438 | break; |
| 2439 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2440 | case Primitive::kPrimFloat: |
| 2441 | case Primitive::kPrimDouble: |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 2442 | GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations); |
| 2443 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2444 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2445 | |
| 2446 | // Convert the branches into the result. |
| 2447 | MipsLabel done; |
| 2448 | |
| 2449 | // False case: result = 0. |
| 2450 | __ LoadConst32(dst, 0); |
| 2451 | __ B(&done); |
| 2452 | |
| 2453 | // True case: result = 1. |
| 2454 | __ Bind(&true_label); |
| 2455 | __ LoadConst32(dst, 1); |
| 2456 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2457 | } |
| 2458 | |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2459 | void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2460 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2461 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 2462 | |
| 2463 | LocationSummary* locations = instruction->GetLocations(); |
| 2464 | Location second = locations->InAt(1); |
| 2465 | DCHECK(second.IsConstant()); |
| 2466 | |
| 2467 | Register out = locations->Out().AsRegister<Register>(); |
| 2468 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2469 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2470 | DCHECK(imm == 1 || imm == -1); |
| 2471 | |
| 2472 | if (instruction->IsRem()) { |
| 2473 | __ Move(out, ZERO); |
| 2474 | } else { |
| 2475 | if (imm == -1) { |
| 2476 | __ Subu(out, ZERO, dividend); |
| 2477 | } else if (out != dividend) { |
| 2478 | __ Move(out, dividend); |
| 2479 | } |
| 2480 | } |
| 2481 | } |
| 2482 | |
| 2483 | void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2484 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2485 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 2486 | |
| 2487 | LocationSummary* locations = instruction->GetLocations(); |
| 2488 | Location second = locations->InAt(1); |
| 2489 | DCHECK(second.IsConstant()); |
| 2490 | |
| 2491 | Register out = locations->Out().AsRegister<Register>(); |
| 2492 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2493 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2494 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2495 | int ctz_imm = CTZ(abs_imm); |
| 2496 | |
| 2497 | if (instruction->IsDiv()) { |
| 2498 | if (ctz_imm == 1) { |
| 2499 | // Fast path for division by +/-2, which is very common. |
| 2500 | __ Srl(TMP, dividend, 31); |
| 2501 | } else { |
| 2502 | __ Sra(TMP, dividend, 31); |
| 2503 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 2504 | } |
| 2505 | __ Addu(out, dividend, TMP); |
| 2506 | __ Sra(out, out, ctz_imm); |
| 2507 | if (imm < 0) { |
| 2508 | __ Subu(out, ZERO, out); |
| 2509 | } |
| 2510 | } else { |
| 2511 | if (ctz_imm == 1) { |
| 2512 | // Fast path for modulo +/-2, which is very common. |
| 2513 | __ Sra(TMP, dividend, 31); |
| 2514 | __ Subu(out, dividend, TMP); |
| 2515 | __ Andi(out, out, 1); |
| 2516 | __ Addu(out, out, TMP); |
| 2517 | } else { |
| 2518 | __ Sra(TMP, dividend, 31); |
| 2519 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 2520 | __ Addu(out, dividend, TMP); |
| 2521 | if (IsUint<16>(abs_imm - 1)) { |
| 2522 | __ Andi(out, out, abs_imm - 1); |
| 2523 | } else { |
| 2524 | __ Sll(out, out, 32 - ctz_imm); |
| 2525 | __ Srl(out, out, 32 - ctz_imm); |
| 2526 | } |
| 2527 | __ Subu(out, out, TMP); |
| 2528 | } |
| 2529 | } |
| 2530 | } |
| 2531 | |
| 2532 | void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2533 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2534 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 2535 | |
| 2536 | LocationSummary* locations = instruction->GetLocations(); |
| 2537 | Location second = locations->InAt(1); |
| 2538 | DCHECK(second.IsConstant()); |
| 2539 | |
| 2540 | Register out = locations->Out().AsRegister<Register>(); |
| 2541 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2542 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2543 | |
| 2544 | int64_t magic; |
| 2545 | int shift; |
| 2546 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2547 | |
| 2548 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 2549 | |
| 2550 | __ LoadConst32(TMP, magic); |
| 2551 | if (isR6) { |
| 2552 | __ MuhR6(TMP, dividend, TMP); |
| 2553 | } else { |
| 2554 | __ MultR2(dividend, TMP); |
| 2555 | __ Mfhi(TMP); |
| 2556 | } |
| 2557 | if (imm > 0 && magic < 0) { |
| 2558 | __ Addu(TMP, TMP, dividend); |
| 2559 | } else if (imm < 0 && magic > 0) { |
| 2560 | __ Subu(TMP, TMP, dividend); |
| 2561 | } |
| 2562 | |
| 2563 | if (shift != 0) { |
| 2564 | __ Sra(TMP, TMP, shift); |
| 2565 | } |
| 2566 | |
| 2567 | if (instruction->IsDiv()) { |
| 2568 | __ Sra(out, TMP, 31); |
| 2569 | __ Subu(out, TMP, out); |
| 2570 | } else { |
| 2571 | __ Sra(AT, TMP, 31); |
| 2572 | __ Subu(AT, TMP, AT); |
| 2573 | __ LoadConst32(TMP, imm); |
| 2574 | if (isR6) { |
| 2575 | __ MulR6(TMP, AT, TMP); |
| 2576 | } else { |
| 2577 | __ MulR2(TMP, AT, TMP); |
| 2578 | } |
| 2579 | __ Subu(out, dividend, TMP); |
| 2580 | } |
| 2581 | } |
| 2582 | |
| 2583 | void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2584 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2585 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 2586 | |
| 2587 | LocationSummary* locations = instruction->GetLocations(); |
| 2588 | Register out = locations->Out().AsRegister<Register>(); |
| 2589 | Location second = locations->InAt(1); |
| 2590 | |
| 2591 | if (second.IsConstant()) { |
| 2592 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2593 | if (imm == 0) { |
| 2594 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2595 | } else if (imm == 1 || imm == -1) { |
| 2596 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2597 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2598 | DivRemByPowerOfTwo(instruction); |
| 2599 | } else { |
| 2600 | DCHECK(imm <= -2 || imm >= 2); |
| 2601 | GenerateDivRemWithAnyConstant(instruction); |
| 2602 | } |
| 2603 | } else { |
| 2604 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2605 | Register divisor = second.AsRegister<Register>(); |
| 2606 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 2607 | if (instruction->IsDiv()) { |
| 2608 | if (isR6) { |
| 2609 | __ DivR6(out, dividend, divisor); |
| 2610 | } else { |
| 2611 | __ DivR2(out, dividend, divisor); |
| 2612 | } |
| 2613 | } else { |
| 2614 | if (isR6) { |
| 2615 | __ ModR6(out, dividend, divisor); |
| 2616 | } else { |
| 2617 | __ ModR2(out, dividend, divisor); |
| 2618 | } |
| 2619 | } |
| 2620 | } |
| 2621 | } |
| 2622 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2623 | void LocationsBuilderMIPS::VisitDiv(HDiv* div) { |
| 2624 | Primitive::Type type = div->GetResultType(); |
| 2625 | LocationSummary::CallKind call_kind = (type == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2626 | ? LocationSummary::kCallOnMainOnly |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2627 | : LocationSummary::kNoCall; |
| 2628 | |
| 2629 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2630 | |
| 2631 | switch (type) { |
| 2632 | case Primitive::kPrimInt: |
| 2633 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2634 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2635 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2636 | break; |
| 2637 | |
| 2638 | case Primitive::kPrimLong: { |
| 2639 | InvokeRuntimeCallingConvention calling_convention; |
| 2640 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2641 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2642 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2643 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2644 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 2645 | break; |
| 2646 | } |
| 2647 | |
| 2648 | case Primitive::kPrimFloat: |
| 2649 | case Primitive::kPrimDouble: |
| 2650 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2651 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2652 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2653 | break; |
| 2654 | |
| 2655 | default: |
| 2656 | LOG(FATAL) << "Unexpected div type " << type; |
| 2657 | } |
| 2658 | } |
| 2659 | |
| 2660 | void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) { |
| 2661 | Primitive::Type type = instruction->GetType(); |
| 2662 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2663 | |
| 2664 | switch (type) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2665 | case Primitive::kPrimInt: |
| 2666 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2667 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2668 | case Primitive::kPrimLong: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 2669 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2670 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| 2671 | break; |
| 2672 | } |
| 2673 | case Primitive::kPrimFloat: |
| 2674 | case Primitive::kPrimDouble: { |
| 2675 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 2676 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2677 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2678 | if (type == Primitive::kPrimFloat) { |
| 2679 | __ DivS(dst, lhs, rhs); |
| 2680 | } else { |
| 2681 | __ DivD(dst, lhs, rhs); |
| 2682 | } |
| 2683 | break; |
| 2684 | } |
| 2685 | default: |
| 2686 | LOG(FATAL) << "Unexpected div type " << type; |
| 2687 | } |
| 2688 | } |
| 2689 | |
| 2690 | void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2691 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2692 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2693 | } |
| 2694 | |
| 2695 | void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2696 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS(instruction); |
| 2697 | codegen_->AddSlowPath(slow_path); |
| 2698 | Location value = instruction->GetLocations()->InAt(0); |
| 2699 | Primitive::Type type = instruction->GetType(); |
| 2700 | |
| 2701 | switch (type) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 2702 | case Primitive::kPrimBoolean: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2703 | case Primitive::kPrimByte: |
| 2704 | case Primitive::kPrimChar: |
| 2705 | case Primitive::kPrimShort: |
| 2706 | case Primitive::kPrimInt: { |
| 2707 | if (value.IsConstant()) { |
| 2708 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 2709 | __ B(slow_path->GetEntryLabel()); |
| 2710 | } else { |
| 2711 | // A division by a non-null constant is valid. We don't need to perform |
| 2712 | // any check, so simply fall through. |
| 2713 | } |
| 2714 | } else { |
| 2715 | DCHECK(value.IsRegister()) << value; |
| 2716 | __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 2717 | } |
| 2718 | break; |
| 2719 | } |
| 2720 | case Primitive::kPrimLong: { |
| 2721 | if (value.IsConstant()) { |
| 2722 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 2723 | __ B(slow_path->GetEntryLabel()); |
| 2724 | } else { |
| 2725 | // A division by a non-null constant is valid. We don't need to perform |
| 2726 | // any check, so simply fall through. |
| 2727 | } |
| 2728 | } else { |
| 2729 | DCHECK(value.IsRegisterPair()) << value; |
| 2730 | __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>()); |
| 2731 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 2732 | } |
| 2733 | break; |
| 2734 | } |
| 2735 | default: |
| 2736 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
| 2737 | } |
| 2738 | } |
| 2739 | |
| 2740 | void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2741 | LocationSummary* locations = |
| 2742 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2743 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2744 | } |
| 2745 | |
| 2746 | void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 2747 | // Will be generated at use site. |
| 2748 | } |
| 2749 | |
| 2750 | void LocationsBuilderMIPS::VisitExit(HExit* exit) { |
| 2751 | exit->SetLocations(nullptr); |
| 2752 | } |
| 2753 | |
| 2754 | void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 2755 | } |
| 2756 | |
| 2757 | void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) { |
| 2758 | LocationSummary* locations = |
| 2759 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2760 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2761 | } |
| 2762 | |
| 2763 | void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 2764 | // Will be generated at use site. |
| 2765 | } |
| 2766 | |
| 2767 | void LocationsBuilderMIPS::VisitGoto(HGoto* got) { |
| 2768 | got->SetLocations(nullptr); |
| 2769 | } |
| 2770 | |
| 2771 | void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| 2772 | DCHECK(!successor->IsExitBlock()); |
| 2773 | HBasicBlock* block = got->GetBlock(); |
| 2774 | HInstruction* previous = got->GetPrevious(); |
| 2775 | HLoopInformation* info = block->GetLoopInformation(); |
| 2776 | |
| 2777 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| 2778 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2779 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2780 | return; |
| 2781 | } |
| 2782 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2783 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2784 | } |
| 2785 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 2786 | __ B(codegen_->GetLabelOf(successor)); |
| 2787 | } |
| 2788 | } |
| 2789 | |
| 2790 | void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) { |
| 2791 | HandleGoto(got, got->GetSuccessor()); |
| 2792 | } |
| 2793 | |
| 2794 | void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2795 | try_boundary->SetLocations(nullptr); |
| 2796 | } |
| 2797 | |
| 2798 | void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2799 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2800 | if (!successor->IsExitBlock()) { |
| 2801 | HandleGoto(try_boundary, successor); |
| 2802 | } |
| 2803 | } |
| 2804 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2805 | void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond, |
| 2806 | LocationSummary* locations) { |
| 2807 | Register dst = locations->Out().AsRegister<Register>(); |
| 2808 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2809 | Location rhs_location = locations->InAt(1); |
| 2810 | Register rhs_reg = ZERO; |
| 2811 | int64_t rhs_imm = 0; |
| 2812 | bool use_imm = rhs_location.IsConstant(); |
| 2813 | if (use_imm) { |
| 2814 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 2815 | } else { |
| 2816 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 2817 | } |
| 2818 | |
| 2819 | switch (cond) { |
| 2820 | case kCondEQ: |
| 2821 | case kCondNE: |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 2822 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 2823 | if (rhs_imm == 0) { |
| 2824 | if (cond == kCondEQ) { |
| 2825 | __ Sltiu(dst, lhs, 1); |
| 2826 | } else { |
| 2827 | __ Sltu(dst, ZERO, lhs); |
| 2828 | } |
| 2829 | } else { |
| 2830 | __ Addiu(dst, lhs, -rhs_imm); |
| 2831 | if (cond == kCondEQ) { |
| 2832 | __ Sltiu(dst, dst, 1); |
| 2833 | } else { |
| 2834 | __ Sltu(dst, ZERO, dst); |
| 2835 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2836 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2837 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 2838 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 2839 | __ Xori(dst, lhs, rhs_imm); |
| 2840 | } else { |
| 2841 | if (use_imm) { |
| 2842 | rhs_reg = TMP; |
| 2843 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2844 | } |
| 2845 | __ Xor(dst, lhs, rhs_reg); |
| 2846 | } |
| 2847 | if (cond == kCondEQ) { |
| 2848 | __ Sltiu(dst, dst, 1); |
| 2849 | } else { |
| 2850 | __ Sltu(dst, ZERO, dst); |
| 2851 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2852 | } |
| 2853 | break; |
| 2854 | |
| 2855 | case kCondLT: |
| 2856 | case kCondGE: |
| 2857 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 2858 | __ Slti(dst, lhs, rhs_imm); |
| 2859 | } else { |
| 2860 | if (use_imm) { |
| 2861 | rhs_reg = TMP; |
| 2862 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2863 | } |
| 2864 | __ Slt(dst, lhs, rhs_reg); |
| 2865 | } |
| 2866 | if (cond == kCondGE) { |
| 2867 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 2868 | // only the slt instruction but no sge. |
| 2869 | __ Xori(dst, dst, 1); |
| 2870 | } |
| 2871 | break; |
| 2872 | |
| 2873 | case kCondLE: |
| 2874 | case kCondGT: |
| 2875 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 2876 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 2877 | __ Slti(dst, lhs, rhs_imm + 1); |
| 2878 | if (cond == kCondGT) { |
| 2879 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 2880 | // only the slti instruction but no sgti. |
| 2881 | __ Xori(dst, dst, 1); |
| 2882 | } |
| 2883 | } else { |
| 2884 | if (use_imm) { |
| 2885 | rhs_reg = TMP; |
| 2886 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2887 | } |
| 2888 | __ Slt(dst, rhs_reg, lhs); |
| 2889 | if (cond == kCondLE) { |
| 2890 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 2891 | // only the slt instruction but no sle. |
| 2892 | __ Xori(dst, dst, 1); |
| 2893 | } |
| 2894 | } |
| 2895 | break; |
| 2896 | |
| 2897 | case kCondB: |
| 2898 | case kCondAE: |
| 2899 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 2900 | // Sltiu sign-extends its 16-bit immediate operand before |
| 2901 | // the comparison and thus lets us compare directly with |
| 2902 | // unsigned values in the ranges [0, 0x7fff] and |
| 2903 | // [0xffff8000, 0xffffffff]. |
| 2904 | __ Sltiu(dst, lhs, rhs_imm); |
| 2905 | } else { |
| 2906 | if (use_imm) { |
| 2907 | rhs_reg = TMP; |
| 2908 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2909 | } |
| 2910 | __ Sltu(dst, lhs, rhs_reg); |
| 2911 | } |
| 2912 | if (cond == kCondAE) { |
| 2913 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 2914 | // only the sltu instruction but no sgeu. |
| 2915 | __ Xori(dst, dst, 1); |
| 2916 | } |
| 2917 | break; |
| 2918 | |
| 2919 | case kCondBE: |
| 2920 | case kCondA: |
| 2921 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 2922 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 2923 | // Note that this only works if rhs + 1 does not overflow |
| 2924 | // to 0, hence the check above. |
| 2925 | // Sltiu sign-extends its 16-bit immediate operand before |
| 2926 | // the comparison and thus lets us compare directly with |
| 2927 | // unsigned values in the ranges [0, 0x7fff] and |
| 2928 | // [0xffff8000, 0xffffffff]. |
| 2929 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 2930 | if (cond == kCondA) { |
| 2931 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 2932 | // only the sltiu instruction but no sgtiu. |
| 2933 | __ Xori(dst, dst, 1); |
| 2934 | } |
| 2935 | } else { |
| 2936 | if (use_imm) { |
| 2937 | rhs_reg = TMP; |
| 2938 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2939 | } |
| 2940 | __ Sltu(dst, rhs_reg, lhs); |
| 2941 | if (cond == kCondBE) { |
| 2942 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 2943 | // only the sltu instruction but no sleu. |
| 2944 | __ Xori(dst, dst, 1); |
| 2945 | } |
| 2946 | } |
| 2947 | break; |
| 2948 | } |
| 2949 | } |
| 2950 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 2951 | bool InstructionCodeGeneratorMIPS::MaterializeIntCompare(IfCondition cond, |
| 2952 | LocationSummary* input_locations, |
| 2953 | Register dst) { |
| 2954 | Register lhs = input_locations->InAt(0).AsRegister<Register>(); |
| 2955 | Location rhs_location = input_locations->InAt(1); |
| 2956 | Register rhs_reg = ZERO; |
| 2957 | int64_t rhs_imm = 0; |
| 2958 | bool use_imm = rhs_location.IsConstant(); |
| 2959 | if (use_imm) { |
| 2960 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 2961 | } else { |
| 2962 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 2963 | } |
| 2964 | |
| 2965 | switch (cond) { |
| 2966 | case kCondEQ: |
| 2967 | case kCondNE: |
| 2968 | if (use_imm && IsInt<16>(-rhs_imm)) { |
| 2969 | __ Addiu(dst, lhs, -rhs_imm); |
| 2970 | } else if (use_imm && IsUint<16>(rhs_imm)) { |
| 2971 | __ Xori(dst, lhs, rhs_imm); |
| 2972 | } else { |
| 2973 | if (use_imm) { |
| 2974 | rhs_reg = TMP; |
| 2975 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2976 | } |
| 2977 | __ Xor(dst, lhs, rhs_reg); |
| 2978 | } |
| 2979 | return (cond == kCondEQ); |
| 2980 | |
| 2981 | case kCondLT: |
| 2982 | case kCondGE: |
| 2983 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 2984 | __ Slti(dst, lhs, rhs_imm); |
| 2985 | } else { |
| 2986 | if (use_imm) { |
| 2987 | rhs_reg = TMP; |
| 2988 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2989 | } |
| 2990 | __ Slt(dst, lhs, rhs_reg); |
| 2991 | } |
| 2992 | return (cond == kCondGE); |
| 2993 | |
| 2994 | case kCondLE: |
| 2995 | case kCondGT: |
| 2996 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 2997 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 2998 | __ Slti(dst, lhs, rhs_imm + 1); |
| 2999 | return (cond == kCondGT); |
| 3000 | } else { |
| 3001 | if (use_imm) { |
| 3002 | rhs_reg = TMP; |
| 3003 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3004 | } |
| 3005 | __ Slt(dst, rhs_reg, lhs); |
| 3006 | return (cond == kCondLE); |
| 3007 | } |
| 3008 | |
| 3009 | case kCondB: |
| 3010 | case kCondAE: |
| 3011 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 3012 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3013 | // the comparison and thus lets us compare directly with |
| 3014 | // unsigned values in the ranges [0, 0x7fff] and |
| 3015 | // [0xffff8000, 0xffffffff]. |
| 3016 | __ Sltiu(dst, lhs, rhs_imm); |
| 3017 | } else { |
| 3018 | if (use_imm) { |
| 3019 | rhs_reg = TMP; |
| 3020 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3021 | } |
| 3022 | __ Sltu(dst, lhs, rhs_reg); |
| 3023 | } |
| 3024 | return (cond == kCondAE); |
| 3025 | |
| 3026 | case kCondBE: |
| 3027 | case kCondA: |
| 3028 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 3029 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3030 | // Note that this only works if rhs + 1 does not overflow |
| 3031 | // to 0, hence the check above. |
| 3032 | // Sltiu sign-extends its 16-bit immediate operand before |
| 3033 | // the comparison and thus lets us compare directly with |
| 3034 | // unsigned values in the ranges [0, 0x7fff] and |
| 3035 | // [0xffff8000, 0xffffffff]. |
| 3036 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 3037 | return (cond == kCondA); |
| 3038 | } else { |
| 3039 | if (use_imm) { |
| 3040 | rhs_reg = TMP; |
| 3041 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3042 | } |
| 3043 | __ Sltu(dst, rhs_reg, lhs); |
| 3044 | return (cond == kCondBE); |
| 3045 | } |
| 3046 | } |
| 3047 | } |
| 3048 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3049 | void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond, |
| 3050 | LocationSummary* locations, |
| 3051 | MipsLabel* label) { |
| 3052 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 3053 | Location rhs_location = locations->InAt(1); |
| 3054 | Register rhs_reg = ZERO; |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 3055 | int64_t rhs_imm = 0; |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3056 | bool use_imm = rhs_location.IsConstant(); |
| 3057 | if (use_imm) { |
| 3058 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 3059 | } else { |
| 3060 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 3061 | } |
| 3062 | |
| 3063 | if (use_imm && rhs_imm == 0) { |
| 3064 | switch (cond) { |
| 3065 | case kCondEQ: |
| 3066 | case kCondBE: // <= 0 if zero |
| 3067 | __ Beqz(lhs, label); |
| 3068 | break; |
| 3069 | case kCondNE: |
| 3070 | case kCondA: // > 0 if non-zero |
| 3071 | __ Bnez(lhs, label); |
| 3072 | break; |
| 3073 | case kCondLT: |
| 3074 | __ Bltz(lhs, label); |
| 3075 | break; |
| 3076 | case kCondGE: |
| 3077 | __ Bgez(lhs, label); |
| 3078 | break; |
| 3079 | case kCondLE: |
| 3080 | __ Blez(lhs, label); |
| 3081 | break; |
| 3082 | case kCondGT: |
| 3083 | __ Bgtz(lhs, label); |
| 3084 | break; |
| 3085 | case kCondB: // always false |
| 3086 | break; |
| 3087 | case kCondAE: // always true |
| 3088 | __ B(label); |
| 3089 | break; |
| 3090 | } |
| 3091 | } else { |
Alexey Frunze | e769771 | 2016-09-15 21:37:49 -0700 | [diff] [blame] | 3092 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3093 | if (isR6 || !use_imm) { |
| 3094 | if (use_imm) { |
| 3095 | rhs_reg = TMP; |
| 3096 | __ LoadConst32(rhs_reg, rhs_imm); |
| 3097 | } |
| 3098 | switch (cond) { |
| 3099 | case kCondEQ: |
| 3100 | __ Beq(lhs, rhs_reg, label); |
| 3101 | break; |
| 3102 | case kCondNE: |
| 3103 | __ Bne(lhs, rhs_reg, label); |
| 3104 | break; |
| 3105 | case kCondLT: |
| 3106 | __ Blt(lhs, rhs_reg, label); |
| 3107 | break; |
| 3108 | case kCondGE: |
| 3109 | __ Bge(lhs, rhs_reg, label); |
| 3110 | break; |
| 3111 | case kCondLE: |
| 3112 | __ Bge(rhs_reg, lhs, label); |
| 3113 | break; |
| 3114 | case kCondGT: |
| 3115 | __ Blt(rhs_reg, lhs, label); |
| 3116 | break; |
| 3117 | case kCondB: |
| 3118 | __ Bltu(lhs, rhs_reg, label); |
| 3119 | break; |
| 3120 | case kCondAE: |
| 3121 | __ Bgeu(lhs, rhs_reg, label); |
| 3122 | break; |
| 3123 | case kCondBE: |
| 3124 | __ Bgeu(rhs_reg, lhs, label); |
| 3125 | break; |
| 3126 | case kCondA: |
| 3127 | __ Bltu(rhs_reg, lhs, label); |
| 3128 | break; |
| 3129 | } |
| 3130 | } else { |
| 3131 | // Special cases for more efficient comparison with constants on R2. |
| 3132 | switch (cond) { |
| 3133 | case kCondEQ: |
| 3134 | __ LoadConst32(TMP, rhs_imm); |
| 3135 | __ Beq(lhs, TMP, label); |
| 3136 | break; |
| 3137 | case kCondNE: |
| 3138 | __ LoadConst32(TMP, rhs_imm); |
| 3139 | __ Bne(lhs, TMP, label); |
| 3140 | break; |
| 3141 | case kCondLT: |
| 3142 | if (IsInt<16>(rhs_imm)) { |
| 3143 | __ Slti(TMP, lhs, rhs_imm); |
| 3144 | __ Bnez(TMP, label); |
| 3145 | } else { |
| 3146 | __ LoadConst32(TMP, rhs_imm); |
| 3147 | __ Blt(lhs, TMP, label); |
| 3148 | } |
| 3149 | break; |
| 3150 | case kCondGE: |
| 3151 | if (IsInt<16>(rhs_imm)) { |
| 3152 | __ Slti(TMP, lhs, rhs_imm); |
| 3153 | __ Beqz(TMP, label); |
| 3154 | } else { |
| 3155 | __ LoadConst32(TMP, rhs_imm); |
| 3156 | __ Bge(lhs, TMP, label); |
| 3157 | } |
| 3158 | break; |
| 3159 | case kCondLE: |
| 3160 | if (IsInt<16>(rhs_imm + 1)) { |
| 3161 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3162 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 3163 | __ Bnez(TMP, label); |
| 3164 | } else { |
| 3165 | __ LoadConst32(TMP, rhs_imm); |
| 3166 | __ Bge(TMP, lhs, label); |
| 3167 | } |
| 3168 | break; |
| 3169 | case kCondGT: |
| 3170 | if (IsInt<16>(rhs_imm + 1)) { |
| 3171 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 3172 | __ Slti(TMP, lhs, rhs_imm + 1); |
| 3173 | __ Beqz(TMP, label); |
| 3174 | } else { |
| 3175 | __ LoadConst32(TMP, rhs_imm); |
| 3176 | __ Blt(TMP, lhs, label); |
| 3177 | } |
| 3178 | break; |
| 3179 | case kCondB: |
| 3180 | if (IsInt<16>(rhs_imm)) { |
| 3181 | __ Sltiu(TMP, lhs, rhs_imm); |
| 3182 | __ Bnez(TMP, label); |
| 3183 | } else { |
| 3184 | __ LoadConst32(TMP, rhs_imm); |
| 3185 | __ Bltu(lhs, TMP, label); |
| 3186 | } |
| 3187 | break; |
| 3188 | case kCondAE: |
| 3189 | if (IsInt<16>(rhs_imm)) { |
| 3190 | __ Sltiu(TMP, lhs, rhs_imm); |
| 3191 | __ Beqz(TMP, label); |
| 3192 | } else { |
| 3193 | __ LoadConst32(TMP, rhs_imm); |
| 3194 | __ Bgeu(lhs, TMP, label); |
| 3195 | } |
| 3196 | break; |
| 3197 | case kCondBE: |
| 3198 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 3199 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 3200 | // Note that this only works if rhs + 1 does not overflow |
| 3201 | // to 0, hence the check above. |
| 3202 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 3203 | __ Bnez(TMP, label); |
| 3204 | } else { |
| 3205 | __ LoadConst32(TMP, rhs_imm); |
| 3206 | __ Bgeu(TMP, lhs, label); |
| 3207 | } |
| 3208 | break; |
| 3209 | case kCondA: |
| 3210 | if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 3211 | // Simulate lhs > rhs via !(lhs < rhs + 1). |
| 3212 | // Note that this only works if rhs + 1 does not overflow |
| 3213 | // to 0, hence the check above. |
| 3214 | __ Sltiu(TMP, lhs, rhs_imm + 1); |
| 3215 | __ Beqz(TMP, label); |
| 3216 | } else { |
| 3217 | __ LoadConst32(TMP, rhs_imm); |
| 3218 | __ Bltu(TMP, lhs, label); |
| 3219 | } |
| 3220 | break; |
| 3221 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3222 | } |
| 3223 | } |
| 3224 | } |
| 3225 | |
| 3226 | void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond, |
| 3227 | LocationSummary* locations, |
| 3228 | MipsLabel* label) { |
| 3229 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3230 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3231 | Location rhs_location = locations->InAt(1); |
| 3232 | Register rhs_high = ZERO; |
| 3233 | Register rhs_low = ZERO; |
| 3234 | int64_t imm = 0; |
| 3235 | uint32_t imm_high = 0; |
| 3236 | uint32_t imm_low = 0; |
| 3237 | bool use_imm = rhs_location.IsConstant(); |
| 3238 | if (use_imm) { |
| 3239 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); |
| 3240 | imm_high = High32Bits(imm); |
| 3241 | imm_low = Low32Bits(imm); |
| 3242 | } else { |
| 3243 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 3244 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 3245 | } |
| 3246 | |
| 3247 | if (use_imm && imm == 0) { |
| 3248 | switch (cond) { |
| 3249 | case kCondEQ: |
| 3250 | case kCondBE: // <= 0 if zero |
| 3251 | __ Or(TMP, lhs_high, lhs_low); |
| 3252 | __ Beqz(TMP, label); |
| 3253 | break; |
| 3254 | case kCondNE: |
| 3255 | case kCondA: // > 0 if non-zero |
| 3256 | __ Or(TMP, lhs_high, lhs_low); |
| 3257 | __ Bnez(TMP, label); |
| 3258 | break; |
| 3259 | case kCondLT: |
| 3260 | __ Bltz(lhs_high, label); |
| 3261 | break; |
| 3262 | case kCondGE: |
| 3263 | __ Bgez(lhs_high, label); |
| 3264 | break; |
| 3265 | case kCondLE: |
| 3266 | __ Or(TMP, lhs_high, lhs_low); |
| 3267 | __ Sra(AT, lhs_high, 31); |
| 3268 | __ Bgeu(AT, TMP, label); |
| 3269 | break; |
| 3270 | case kCondGT: |
| 3271 | __ Or(TMP, lhs_high, lhs_low); |
| 3272 | __ Sra(AT, lhs_high, 31); |
| 3273 | __ Bltu(AT, TMP, label); |
| 3274 | break; |
| 3275 | case kCondB: // always false |
| 3276 | break; |
| 3277 | case kCondAE: // always true |
| 3278 | __ B(label); |
| 3279 | break; |
| 3280 | } |
| 3281 | } else if (use_imm) { |
| 3282 | // TODO: more efficient comparison with constants without loading them into TMP/AT. |
| 3283 | switch (cond) { |
| 3284 | case kCondEQ: |
| 3285 | __ LoadConst32(TMP, imm_high); |
| 3286 | __ Xor(TMP, TMP, lhs_high); |
| 3287 | __ LoadConst32(AT, imm_low); |
| 3288 | __ Xor(AT, AT, lhs_low); |
| 3289 | __ Or(TMP, TMP, AT); |
| 3290 | __ Beqz(TMP, label); |
| 3291 | break; |
| 3292 | case kCondNE: |
| 3293 | __ LoadConst32(TMP, imm_high); |
| 3294 | __ Xor(TMP, TMP, lhs_high); |
| 3295 | __ LoadConst32(AT, imm_low); |
| 3296 | __ Xor(AT, AT, lhs_low); |
| 3297 | __ Or(TMP, TMP, AT); |
| 3298 | __ Bnez(TMP, label); |
| 3299 | break; |
| 3300 | case kCondLT: |
| 3301 | __ LoadConst32(TMP, imm_high); |
| 3302 | __ Blt(lhs_high, TMP, label); |
| 3303 | __ Slt(TMP, TMP, lhs_high); |
| 3304 | __ LoadConst32(AT, imm_low); |
| 3305 | __ Sltu(AT, lhs_low, AT); |
| 3306 | __ Blt(TMP, AT, label); |
| 3307 | break; |
| 3308 | case kCondGE: |
| 3309 | __ LoadConst32(TMP, imm_high); |
| 3310 | __ Blt(TMP, lhs_high, label); |
| 3311 | __ Slt(TMP, lhs_high, TMP); |
| 3312 | __ LoadConst32(AT, imm_low); |
| 3313 | __ Sltu(AT, lhs_low, AT); |
| 3314 | __ Or(TMP, TMP, AT); |
| 3315 | __ Beqz(TMP, label); |
| 3316 | break; |
| 3317 | case kCondLE: |
| 3318 | __ LoadConst32(TMP, imm_high); |
| 3319 | __ Blt(lhs_high, TMP, label); |
| 3320 | __ Slt(TMP, TMP, lhs_high); |
| 3321 | __ LoadConst32(AT, imm_low); |
| 3322 | __ Sltu(AT, AT, lhs_low); |
| 3323 | __ Or(TMP, TMP, AT); |
| 3324 | __ Beqz(TMP, label); |
| 3325 | break; |
| 3326 | case kCondGT: |
| 3327 | __ LoadConst32(TMP, imm_high); |
| 3328 | __ Blt(TMP, lhs_high, label); |
| 3329 | __ Slt(TMP, lhs_high, TMP); |
| 3330 | __ LoadConst32(AT, imm_low); |
| 3331 | __ Sltu(AT, AT, lhs_low); |
| 3332 | __ Blt(TMP, AT, label); |
| 3333 | break; |
| 3334 | case kCondB: |
| 3335 | __ LoadConst32(TMP, imm_high); |
| 3336 | __ Bltu(lhs_high, TMP, label); |
| 3337 | __ Sltu(TMP, TMP, lhs_high); |
| 3338 | __ LoadConst32(AT, imm_low); |
| 3339 | __ Sltu(AT, lhs_low, AT); |
| 3340 | __ Blt(TMP, AT, label); |
| 3341 | break; |
| 3342 | case kCondAE: |
| 3343 | __ LoadConst32(TMP, imm_high); |
| 3344 | __ Bltu(TMP, lhs_high, label); |
| 3345 | __ Sltu(TMP, lhs_high, TMP); |
| 3346 | __ LoadConst32(AT, imm_low); |
| 3347 | __ Sltu(AT, lhs_low, AT); |
| 3348 | __ Or(TMP, TMP, AT); |
| 3349 | __ Beqz(TMP, label); |
| 3350 | break; |
| 3351 | case kCondBE: |
| 3352 | __ LoadConst32(TMP, imm_high); |
| 3353 | __ Bltu(lhs_high, TMP, label); |
| 3354 | __ Sltu(TMP, TMP, lhs_high); |
| 3355 | __ LoadConst32(AT, imm_low); |
| 3356 | __ Sltu(AT, AT, lhs_low); |
| 3357 | __ Or(TMP, TMP, AT); |
| 3358 | __ Beqz(TMP, label); |
| 3359 | break; |
| 3360 | case kCondA: |
| 3361 | __ LoadConst32(TMP, imm_high); |
| 3362 | __ Bltu(TMP, lhs_high, label); |
| 3363 | __ Sltu(TMP, lhs_high, TMP); |
| 3364 | __ LoadConst32(AT, imm_low); |
| 3365 | __ Sltu(AT, AT, lhs_low); |
| 3366 | __ Blt(TMP, AT, label); |
| 3367 | break; |
| 3368 | } |
| 3369 | } else { |
| 3370 | switch (cond) { |
| 3371 | case kCondEQ: |
| 3372 | __ Xor(TMP, lhs_high, rhs_high); |
| 3373 | __ Xor(AT, lhs_low, rhs_low); |
| 3374 | __ Or(TMP, TMP, AT); |
| 3375 | __ Beqz(TMP, label); |
| 3376 | break; |
| 3377 | case kCondNE: |
| 3378 | __ Xor(TMP, lhs_high, rhs_high); |
| 3379 | __ Xor(AT, lhs_low, rhs_low); |
| 3380 | __ Or(TMP, TMP, AT); |
| 3381 | __ Bnez(TMP, label); |
| 3382 | break; |
| 3383 | case kCondLT: |
| 3384 | __ Blt(lhs_high, rhs_high, label); |
| 3385 | __ Slt(TMP, rhs_high, lhs_high); |
| 3386 | __ Sltu(AT, lhs_low, rhs_low); |
| 3387 | __ Blt(TMP, AT, label); |
| 3388 | break; |
| 3389 | case kCondGE: |
| 3390 | __ Blt(rhs_high, lhs_high, label); |
| 3391 | __ Slt(TMP, lhs_high, rhs_high); |
| 3392 | __ Sltu(AT, lhs_low, rhs_low); |
| 3393 | __ Or(TMP, TMP, AT); |
| 3394 | __ Beqz(TMP, label); |
| 3395 | break; |
| 3396 | case kCondLE: |
| 3397 | __ Blt(lhs_high, rhs_high, label); |
| 3398 | __ Slt(TMP, rhs_high, lhs_high); |
| 3399 | __ Sltu(AT, rhs_low, lhs_low); |
| 3400 | __ Or(TMP, TMP, AT); |
| 3401 | __ Beqz(TMP, label); |
| 3402 | break; |
| 3403 | case kCondGT: |
| 3404 | __ Blt(rhs_high, lhs_high, label); |
| 3405 | __ Slt(TMP, lhs_high, rhs_high); |
| 3406 | __ Sltu(AT, rhs_low, lhs_low); |
| 3407 | __ Blt(TMP, AT, label); |
| 3408 | break; |
| 3409 | case kCondB: |
| 3410 | __ Bltu(lhs_high, rhs_high, label); |
| 3411 | __ Sltu(TMP, rhs_high, lhs_high); |
| 3412 | __ Sltu(AT, lhs_low, rhs_low); |
| 3413 | __ Blt(TMP, AT, label); |
| 3414 | break; |
| 3415 | case kCondAE: |
| 3416 | __ Bltu(rhs_high, lhs_high, label); |
| 3417 | __ Sltu(TMP, lhs_high, rhs_high); |
| 3418 | __ Sltu(AT, lhs_low, rhs_low); |
| 3419 | __ Or(TMP, TMP, AT); |
| 3420 | __ Beqz(TMP, label); |
| 3421 | break; |
| 3422 | case kCondBE: |
| 3423 | __ Bltu(lhs_high, rhs_high, label); |
| 3424 | __ Sltu(TMP, rhs_high, lhs_high); |
| 3425 | __ Sltu(AT, rhs_low, lhs_low); |
| 3426 | __ Or(TMP, TMP, AT); |
| 3427 | __ Beqz(TMP, label); |
| 3428 | break; |
| 3429 | case kCondA: |
| 3430 | __ Bltu(rhs_high, lhs_high, label); |
| 3431 | __ Sltu(TMP, lhs_high, rhs_high); |
| 3432 | __ Sltu(AT, rhs_low, lhs_low); |
| 3433 | __ Blt(TMP, AT, label); |
| 3434 | break; |
| 3435 | } |
| 3436 | } |
| 3437 | } |
| 3438 | |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 3439 | void InstructionCodeGeneratorMIPS::GenerateFpCompare(IfCondition cond, |
| 3440 | bool gt_bias, |
| 3441 | Primitive::Type type, |
| 3442 | LocationSummary* locations) { |
| 3443 | Register dst = locations->Out().AsRegister<Register>(); |
| 3444 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3445 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3446 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3447 | if (type == Primitive::kPrimFloat) { |
| 3448 | if (isR6) { |
| 3449 | switch (cond) { |
| 3450 | case kCondEQ: |
| 3451 | __ CmpEqS(FTMP, lhs, rhs); |
| 3452 | __ Mfc1(dst, FTMP); |
| 3453 | __ Andi(dst, dst, 1); |
| 3454 | break; |
| 3455 | case kCondNE: |
| 3456 | __ CmpEqS(FTMP, lhs, rhs); |
| 3457 | __ Mfc1(dst, FTMP); |
| 3458 | __ Addiu(dst, dst, 1); |
| 3459 | break; |
| 3460 | case kCondLT: |
| 3461 | if (gt_bias) { |
| 3462 | __ CmpLtS(FTMP, lhs, rhs); |
| 3463 | } else { |
| 3464 | __ CmpUltS(FTMP, lhs, rhs); |
| 3465 | } |
| 3466 | __ Mfc1(dst, FTMP); |
| 3467 | __ Andi(dst, dst, 1); |
| 3468 | break; |
| 3469 | case kCondLE: |
| 3470 | if (gt_bias) { |
| 3471 | __ CmpLeS(FTMP, lhs, rhs); |
| 3472 | } else { |
| 3473 | __ CmpUleS(FTMP, lhs, rhs); |
| 3474 | } |
| 3475 | __ Mfc1(dst, FTMP); |
| 3476 | __ Andi(dst, dst, 1); |
| 3477 | break; |
| 3478 | case kCondGT: |
| 3479 | if (gt_bias) { |
| 3480 | __ CmpUltS(FTMP, rhs, lhs); |
| 3481 | } else { |
| 3482 | __ CmpLtS(FTMP, rhs, lhs); |
| 3483 | } |
| 3484 | __ Mfc1(dst, FTMP); |
| 3485 | __ Andi(dst, dst, 1); |
| 3486 | break; |
| 3487 | case kCondGE: |
| 3488 | if (gt_bias) { |
| 3489 | __ CmpUleS(FTMP, rhs, lhs); |
| 3490 | } else { |
| 3491 | __ CmpLeS(FTMP, rhs, lhs); |
| 3492 | } |
| 3493 | __ Mfc1(dst, FTMP); |
| 3494 | __ Andi(dst, dst, 1); |
| 3495 | break; |
| 3496 | default: |
| 3497 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3498 | UNREACHABLE(); |
| 3499 | } |
| 3500 | } else { |
| 3501 | switch (cond) { |
| 3502 | case kCondEQ: |
| 3503 | __ CeqS(0, lhs, rhs); |
| 3504 | __ LoadConst32(dst, 1); |
| 3505 | __ Movf(dst, ZERO, 0); |
| 3506 | break; |
| 3507 | case kCondNE: |
| 3508 | __ CeqS(0, lhs, rhs); |
| 3509 | __ LoadConst32(dst, 1); |
| 3510 | __ Movt(dst, ZERO, 0); |
| 3511 | break; |
| 3512 | case kCondLT: |
| 3513 | if (gt_bias) { |
| 3514 | __ ColtS(0, lhs, rhs); |
| 3515 | } else { |
| 3516 | __ CultS(0, lhs, rhs); |
| 3517 | } |
| 3518 | __ LoadConst32(dst, 1); |
| 3519 | __ Movf(dst, ZERO, 0); |
| 3520 | break; |
| 3521 | case kCondLE: |
| 3522 | if (gt_bias) { |
| 3523 | __ ColeS(0, lhs, rhs); |
| 3524 | } else { |
| 3525 | __ CuleS(0, lhs, rhs); |
| 3526 | } |
| 3527 | __ LoadConst32(dst, 1); |
| 3528 | __ Movf(dst, ZERO, 0); |
| 3529 | break; |
| 3530 | case kCondGT: |
| 3531 | if (gt_bias) { |
| 3532 | __ CultS(0, rhs, lhs); |
| 3533 | } else { |
| 3534 | __ ColtS(0, rhs, lhs); |
| 3535 | } |
| 3536 | __ LoadConst32(dst, 1); |
| 3537 | __ Movf(dst, ZERO, 0); |
| 3538 | break; |
| 3539 | case kCondGE: |
| 3540 | if (gt_bias) { |
| 3541 | __ CuleS(0, rhs, lhs); |
| 3542 | } else { |
| 3543 | __ ColeS(0, rhs, lhs); |
| 3544 | } |
| 3545 | __ LoadConst32(dst, 1); |
| 3546 | __ Movf(dst, ZERO, 0); |
| 3547 | break; |
| 3548 | default: |
| 3549 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3550 | UNREACHABLE(); |
| 3551 | } |
| 3552 | } |
| 3553 | } else { |
| 3554 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 3555 | if (isR6) { |
| 3556 | switch (cond) { |
| 3557 | case kCondEQ: |
| 3558 | __ CmpEqD(FTMP, lhs, rhs); |
| 3559 | __ Mfc1(dst, FTMP); |
| 3560 | __ Andi(dst, dst, 1); |
| 3561 | break; |
| 3562 | case kCondNE: |
| 3563 | __ CmpEqD(FTMP, lhs, rhs); |
| 3564 | __ Mfc1(dst, FTMP); |
| 3565 | __ Addiu(dst, dst, 1); |
| 3566 | break; |
| 3567 | case kCondLT: |
| 3568 | if (gt_bias) { |
| 3569 | __ CmpLtD(FTMP, lhs, rhs); |
| 3570 | } else { |
| 3571 | __ CmpUltD(FTMP, lhs, rhs); |
| 3572 | } |
| 3573 | __ Mfc1(dst, FTMP); |
| 3574 | __ Andi(dst, dst, 1); |
| 3575 | break; |
| 3576 | case kCondLE: |
| 3577 | if (gt_bias) { |
| 3578 | __ CmpLeD(FTMP, lhs, rhs); |
| 3579 | } else { |
| 3580 | __ CmpUleD(FTMP, lhs, rhs); |
| 3581 | } |
| 3582 | __ Mfc1(dst, FTMP); |
| 3583 | __ Andi(dst, dst, 1); |
| 3584 | break; |
| 3585 | case kCondGT: |
| 3586 | if (gt_bias) { |
| 3587 | __ CmpUltD(FTMP, rhs, lhs); |
| 3588 | } else { |
| 3589 | __ CmpLtD(FTMP, rhs, lhs); |
| 3590 | } |
| 3591 | __ Mfc1(dst, FTMP); |
| 3592 | __ Andi(dst, dst, 1); |
| 3593 | break; |
| 3594 | case kCondGE: |
| 3595 | if (gt_bias) { |
| 3596 | __ CmpUleD(FTMP, rhs, lhs); |
| 3597 | } else { |
| 3598 | __ CmpLeD(FTMP, rhs, lhs); |
| 3599 | } |
| 3600 | __ Mfc1(dst, FTMP); |
| 3601 | __ Andi(dst, dst, 1); |
| 3602 | break; |
| 3603 | default: |
| 3604 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3605 | UNREACHABLE(); |
| 3606 | } |
| 3607 | } else { |
| 3608 | switch (cond) { |
| 3609 | case kCondEQ: |
| 3610 | __ CeqD(0, lhs, rhs); |
| 3611 | __ LoadConst32(dst, 1); |
| 3612 | __ Movf(dst, ZERO, 0); |
| 3613 | break; |
| 3614 | case kCondNE: |
| 3615 | __ CeqD(0, lhs, rhs); |
| 3616 | __ LoadConst32(dst, 1); |
| 3617 | __ Movt(dst, ZERO, 0); |
| 3618 | break; |
| 3619 | case kCondLT: |
| 3620 | if (gt_bias) { |
| 3621 | __ ColtD(0, lhs, rhs); |
| 3622 | } else { |
| 3623 | __ CultD(0, lhs, rhs); |
| 3624 | } |
| 3625 | __ LoadConst32(dst, 1); |
| 3626 | __ Movf(dst, ZERO, 0); |
| 3627 | break; |
| 3628 | case kCondLE: |
| 3629 | if (gt_bias) { |
| 3630 | __ ColeD(0, lhs, rhs); |
| 3631 | } else { |
| 3632 | __ CuleD(0, lhs, rhs); |
| 3633 | } |
| 3634 | __ LoadConst32(dst, 1); |
| 3635 | __ Movf(dst, ZERO, 0); |
| 3636 | break; |
| 3637 | case kCondGT: |
| 3638 | if (gt_bias) { |
| 3639 | __ CultD(0, rhs, lhs); |
| 3640 | } else { |
| 3641 | __ ColtD(0, rhs, lhs); |
| 3642 | } |
| 3643 | __ LoadConst32(dst, 1); |
| 3644 | __ Movf(dst, ZERO, 0); |
| 3645 | break; |
| 3646 | case kCondGE: |
| 3647 | if (gt_bias) { |
| 3648 | __ CuleD(0, rhs, lhs); |
| 3649 | } else { |
| 3650 | __ ColeD(0, rhs, lhs); |
| 3651 | } |
| 3652 | __ LoadConst32(dst, 1); |
| 3653 | __ Movf(dst, ZERO, 0); |
| 3654 | break; |
| 3655 | default: |
| 3656 | LOG(FATAL) << "Unexpected non-floating-point condition " << cond; |
| 3657 | UNREACHABLE(); |
| 3658 | } |
| 3659 | } |
| 3660 | } |
| 3661 | } |
| 3662 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 3663 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR2(IfCondition cond, |
| 3664 | bool gt_bias, |
| 3665 | Primitive::Type type, |
| 3666 | LocationSummary* input_locations, |
| 3667 | int cc) { |
| 3668 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3669 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3670 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
| 3671 | if (type == Primitive::kPrimFloat) { |
| 3672 | switch (cond) { |
| 3673 | case kCondEQ: |
| 3674 | __ CeqS(cc, lhs, rhs); |
| 3675 | return false; |
| 3676 | case kCondNE: |
| 3677 | __ CeqS(cc, lhs, rhs); |
| 3678 | return true; |
| 3679 | case kCondLT: |
| 3680 | if (gt_bias) { |
| 3681 | __ ColtS(cc, lhs, rhs); |
| 3682 | } else { |
| 3683 | __ CultS(cc, lhs, rhs); |
| 3684 | } |
| 3685 | return false; |
| 3686 | case kCondLE: |
| 3687 | if (gt_bias) { |
| 3688 | __ ColeS(cc, lhs, rhs); |
| 3689 | } else { |
| 3690 | __ CuleS(cc, lhs, rhs); |
| 3691 | } |
| 3692 | return false; |
| 3693 | case kCondGT: |
| 3694 | if (gt_bias) { |
| 3695 | __ CultS(cc, rhs, lhs); |
| 3696 | } else { |
| 3697 | __ ColtS(cc, rhs, lhs); |
| 3698 | } |
| 3699 | return false; |
| 3700 | case kCondGE: |
| 3701 | if (gt_bias) { |
| 3702 | __ CuleS(cc, rhs, lhs); |
| 3703 | } else { |
| 3704 | __ ColeS(cc, rhs, lhs); |
| 3705 | } |
| 3706 | return false; |
| 3707 | default: |
| 3708 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3709 | UNREACHABLE(); |
| 3710 | } |
| 3711 | } else { |
| 3712 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 3713 | switch (cond) { |
| 3714 | case kCondEQ: |
| 3715 | __ CeqD(cc, lhs, rhs); |
| 3716 | return false; |
| 3717 | case kCondNE: |
| 3718 | __ CeqD(cc, lhs, rhs); |
| 3719 | return true; |
| 3720 | case kCondLT: |
| 3721 | if (gt_bias) { |
| 3722 | __ ColtD(cc, lhs, rhs); |
| 3723 | } else { |
| 3724 | __ CultD(cc, lhs, rhs); |
| 3725 | } |
| 3726 | return false; |
| 3727 | case kCondLE: |
| 3728 | if (gt_bias) { |
| 3729 | __ ColeD(cc, lhs, rhs); |
| 3730 | } else { |
| 3731 | __ CuleD(cc, lhs, rhs); |
| 3732 | } |
| 3733 | return false; |
| 3734 | case kCondGT: |
| 3735 | if (gt_bias) { |
| 3736 | __ CultD(cc, rhs, lhs); |
| 3737 | } else { |
| 3738 | __ ColtD(cc, rhs, lhs); |
| 3739 | } |
| 3740 | return false; |
| 3741 | case kCondGE: |
| 3742 | if (gt_bias) { |
| 3743 | __ CuleD(cc, rhs, lhs); |
| 3744 | } else { |
| 3745 | __ ColeD(cc, rhs, lhs); |
| 3746 | } |
| 3747 | return false; |
| 3748 | default: |
| 3749 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3750 | UNREACHABLE(); |
| 3751 | } |
| 3752 | } |
| 3753 | } |
| 3754 | |
| 3755 | bool InstructionCodeGeneratorMIPS::MaterializeFpCompareR6(IfCondition cond, |
| 3756 | bool gt_bias, |
| 3757 | Primitive::Type type, |
| 3758 | LocationSummary* input_locations, |
| 3759 | FRegister dst) { |
| 3760 | FRegister lhs = input_locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3761 | FRegister rhs = input_locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3762 | CHECK(codegen_->GetInstructionSetFeatures().IsR6()); |
| 3763 | if (type == Primitive::kPrimFloat) { |
| 3764 | switch (cond) { |
| 3765 | case kCondEQ: |
| 3766 | __ CmpEqS(dst, lhs, rhs); |
| 3767 | return false; |
| 3768 | case kCondNE: |
| 3769 | __ CmpEqS(dst, lhs, rhs); |
| 3770 | return true; |
| 3771 | case kCondLT: |
| 3772 | if (gt_bias) { |
| 3773 | __ CmpLtS(dst, lhs, rhs); |
| 3774 | } else { |
| 3775 | __ CmpUltS(dst, lhs, rhs); |
| 3776 | } |
| 3777 | return false; |
| 3778 | case kCondLE: |
| 3779 | if (gt_bias) { |
| 3780 | __ CmpLeS(dst, lhs, rhs); |
| 3781 | } else { |
| 3782 | __ CmpUleS(dst, lhs, rhs); |
| 3783 | } |
| 3784 | return false; |
| 3785 | case kCondGT: |
| 3786 | if (gt_bias) { |
| 3787 | __ CmpUltS(dst, rhs, lhs); |
| 3788 | } else { |
| 3789 | __ CmpLtS(dst, rhs, lhs); |
| 3790 | } |
| 3791 | return false; |
| 3792 | case kCondGE: |
| 3793 | if (gt_bias) { |
| 3794 | __ CmpUleS(dst, rhs, lhs); |
| 3795 | } else { |
| 3796 | __ CmpLeS(dst, rhs, lhs); |
| 3797 | } |
| 3798 | return false; |
| 3799 | default: |
| 3800 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3801 | UNREACHABLE(); |
| 3802 | } |
| 3803 | } else { |
| 3804 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 3805 | switch (cond) { |
| 3806 | case kCondEQ: |
| 3807 | __ CmpEqD(dst, lhs, rhs); |
| 3808 | return false; |
| 3809 | case kCondNE: |
| 3810 | __ CmpEqD(dst, lhs, rhs); |
| 3811 | return true; |
| 3812 | case kCondLT: |
| 3813 | if (gt_bias) { |
| 3814 | __ CmpLtD(dst, lhs, rhs); |
| 3815 | } else { |
| 3816 | __ CmpUltD(dst, lhs, rhs); |
| 3817 | } |
| 3818 | return false; |
| 3819 | case kCondLE: |
| 3820 | if (gt_bias) { |
| 3821 | __ CmpLeD(dst, lhs, rhs); |
| 3822 | } else { |
| 3823 | __ CmpUleD(dst, lhs, rhs); |
| 3824 | } |
| 3825 | return false; |
| 3826 | case kCondGT: |
| 3827 | if (gt_bias) { |
| 3828 | __ CmpUltD(dst, rhs, lhs); |
| 3829 | } else { |
| 3830 | __ CmpLtD(dst, rhs, lhs); |
| 3831 | } |
| 3832 | return false; |
| 3833 | case kCondGE: |
| 3834 | if (gt_bias) { |
| 3835 | __ CmpUleD(dst, rhs, lhs); |
| 3836 | } else { |
| 3837 | __ CmpLeD(dst, rhs, lhs); |
| 3838 | } |
| 3839 | return false; |
| 3840 | default: |
| 3841 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3842 | UNREACHABLE(); |
| 3843 | } |
| 3844 | } |
| 3845 | } |
| 3846 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3847 | void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond, |
| 3848 | bool gt_bias, |
| 3849 | Primitive::Type type, |
| 3850 | LocationSummary* locations, |
| 3851 | MipsLabel* label) { |
| 3852 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3853 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3854 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3855 | if (type == Primitive::kPrimFloat) { |
| 3856 | if (isR6) { |
| 3857 | switch (cond) { |
| 3858 | case kCondEQ: |
| 3859 | __ CmpEqS(FTMP, lhs, rhs); |
| 3860 | __ Bc1nez(FTMP, label); |
| 3861 | break; |
| 3862 | case kCondNE: |
| 3863 | __ CmpEqS(FTMP, lhs, rhs); |
| 3864 | __ Bc1eqz(FTMP, label); |
| 3865 | break; |
| 3866 | case kCondLT: |
| 3867 | if (gt_bias) { |
| 3868 | __ CmpLtS(FTMP, lhs, rhs); |
| 3869 | } else { |
| 3870 | __ CmpUltS(FTMP, lhs, rhs); |
| 3871 | } |
| 3872 | __ Bc1nez(FTMP, label); |
| 3873 | break; |
| 3874 | case kCondLE: |
| 3875 | if (gt_bias) { |
| 3876 | __ CmpLeS(FTMP, lhs, rhs); |
| 3877 | } else { |
| 3878 | __ CmpUleS(FTMP, lhs, rhs); |
| 3879 | } |
| 3880 | __ Bc1nez(FTMP, label); |
| 3881 | break; |
| 3882 | case kCondGT: |
| 3883 | if (gt_bias) { |
| 3884 | __ CmpUltS(FTMP, rhs, lhs); |
| 3885 | } else { |
| 3886 | __ CmpLtS(FTMP, rhs, lhs); |
| 3887 | } |
| 3888 | __ Bc1nez(FTMP, label); |
| 3889 | break; |
| 3890 | case kCondGE: |
| 3891 | if (gt_bias) { |
| 3892 | __ CmpUleS(FTMP, rhs, lhs); |
| 3893 | } else { |
| 3894 | __ CmpLeS(FTMP, rhs, lhs); |
| 3895 | } |
| 3896 | __ Bc1nez(FTMP, label); |
| 3897 | break; |
| 3898 | default: |
| 3899 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 3900 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3901 | } |
| 3902 | } else { |
| 3903 | switch (cond) { |
| 3904 | case kCondEQ: |
| 3905 | __ CeqS(0, lhs, rhs); |
| 3906 | __ Bc1t(0, label); |
| 3907 | break; |
| 3908 | case kCondNE: |
| 3909 | __ CeqS(0, lhs, rhs); |
| 3910 | __ Bc1f(0, label); |
| 3911 | break; |
| 3912 | case kCondLT: |
| 3913 | if (gt_bias) { |
| 3914 | __ ColtS(0, lhs, rhs); |
| 3915 | } else { |
| 3916 | __ CultS(0, lhs, rhs); |
| 3917 | } |
| 3918 | __ Bc1t(0, label); |
| 3919 | break; |
| 3920 | case kCondLE: |
| 3921 | if (gt_bias) { |
| 3922 | __ ColeS(0, lhs, rhs); |
| 3923 | } else { |
| 3924 | __ CuleS(0, lhs, rhs); |
| 3925 | } |
| 3926 | __ Bc1t(0, label); |
| 3927 | break; |
| 3928 | case kCondGT: |
| 3929 | if (gt_bias) { |
| 3930 | __ CultS(0, rhs, lhs); |
| 3931 | } else { |
| 3932 | __ ColtS(0, rhs, lhs); |
| 3933 | } |
| 3934 | __ Bc1t(0, label); |
| 3935 | break; |
| 3936 | case kCondGE: |
| 3937 | if (gt_bias) { |
| 3938 | __ CuleS(0, rhs, lhs); |
| 3939 | } else { |
| 3940 | __ ColeS(0, rhs, lhs); |
| 3941 | } |
| 3942 | __ Bc1t(0, label); |
| 3943 | break; |
| 3944 | default: |
| 3945 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 3946 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3947 | } |
| 3948 | } |
| 3949 | } else { |
| 3950 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 3951 | if (isR6) { |
| 3952 | switch (cond) { |
| 3953 | case kCondEQ: |
| 3954 | __ CmpEqD(FTMP, lhs, rhs); |
| 3955 | __ Bc1nez(FTMP, label); |
| 3956 | break; |
| 3957 | case kCondNE: |
| 3958 | __ CmpEqD(FTMP, lhs, rhs); |
| 3959 | __ Bc1eqz(FTMP, label); |
| 3960 | break; |
| 3961 | case kCondLT: |
| 3962 | if (gt_bias) { |
| 3963 | __ CmpLtD(FTMP, lhs, rhs); |
| 3964 | } else { |
| 3965 | __ CmpUltD(FTMP, lhs, rhs); |
| 3966 | } |
| 3967 | __ Bc1nez(FTMP, label); |
| 3968 | break; |
| 3969 | case kCondLE: |
| 3970 | if (gt_bias) { |
| 3971 | __ CmpLeD(FTMP, lhs, rhs); |
| 3972 | } else { |
| 3973 | __ CmpUleD(FTMP, lhs, rhs); |
| 3974 | } |
| 3975 | __ Bc1nez(FTMP, label); |
| 3976 | break; |
| 3977 | case kCondGT: |
| 3978 | if (gt_bias) { |
| 3979 | __ CmpUltD(FTMP, rhs, lhs); |
| 3980 | } else { |
| 3981 | __ CmpLtD(FTMP, rhs, lhs); |
| 3982 | } |
| 3983 | __ Bc1nez(FTMP, label); |
| 3984 | break; |
| 3985 | case kCondGE: |
| 3986 | if (gt_bias) { |
| 3987 | __ CmpUleD(FTMP, rhs, lhs); |
| 3988 | } else { |
| 3989 | __ CmpLeD(FTMP, rhs, lhs); |
| 3990 | } |
| 3991 | __ Bc1nez(FTMP, label); |
| 3992 | break; |
| 3993 | default: |
| 3994 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 3995 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3996 | } |
| 3997 | } else { |
| 3998 | switch (cond) { |
| 3999 | case kCondEQ: |
| 4000 | __ CeqD(0, lhs, rhs); |
| 4001 | __ Bc1t(0, label); |
| 4002 | break; |
| 4003 | case kCondNE: |
| 4004 | __ CeqD(0, lhs, rhs); |
| 4005 | __ Bc1f(0, label); |
| 4006 | break; |
| 4007 | case kCondLT: |
| 4008 | if (gt_bias) { |
| 4009 | __ ColtD(0, lhs, rhs); |
| 4010 | } else { |
| 4011 | __ CultD(0, lhs, rhs); |
| 4012 | } |
| 4013 | __ Bc1t(0, label); |
| 4014 | break; |
| 4015 | case kCondLE: |
| 4016 | if (gt_bias) { |
| 4017 | __ ColeD(0, lhs, rhs); |
| 4018 | } else { |
| 4019 | __ CuleD(0, lhs, rhs); |
| 4020 | } |
| 4021 | __ Bc1t(0, label); |
| 4022 | break; |
| 4023 | case kCondGT: |
| 4024 | if (gt_bias) { |
| 4025 | __ CultD(0, rhs, lhs); |
| 4026 | } else { |
| 4027 | __ ColtD(0, rhs, lhs); |
| 4028 | } |
| 4029 | __ Bc1t(0, label); |
| 4030 | break; |
| 4031 | case kCondGE: |
| 4032 | if (gt_bias) { |
| 4033 | __ CuleD(0, rhs, lhs); |
| 4034 | } else { |
| 4035 | __ ColeD(0, rhs, lhs); |
| 4036 | } |
| 4037 | __ Bc1t(0, label); |
| 4038 | break; |
| 4039 | default: |
| 4040 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4041 | UNREACHABLE(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4042 | } |
| 4043 | } |
| 4044 | } |
| 4045 | } |
| 4046 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4047 | void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4048 | size_t condition_input_index, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4049 | MipsLabel* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4050 | MipsLabel* false_target) { |
| 4051 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4052 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4053 | if (true_target == nullptr && false_target == nullptr) { |
| 4054 | // Nothing to do. The code always falls through. |
| 4055 | return; |
| 4056 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 4057 | // Constant condition, statically compared against "true" (integer value 1). |
| 4058 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4059 | if (true_target != nullptr) { |
| 4060 | __ B(true_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4061 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4062 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 4063 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4064 | if (false_target != nullptr) { |
| 4065 | __ B(false_target); |
| 4066 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4067 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4068 | return; |
| 4069 | } |
| 4070 | |
| 4071 | // The following code generates these patterns: |
| 4072 | // (1) true_target == nullptr && false_target != nullptr |
| 4073 | // - opposite condition true => branch to false_target |
| 4074 | // (2) true_target != nullptr && false_target == nullptr |
| 4075 | // - condition true => branch to true_target |
| 4076 | // (3) true_target != nullptr && false_target != nullptr |
| 4077 | // - condition true => branch to true_target |
| 4078 | // - branch to false_target |
| 4079 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4080 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4081 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4082 | DCHECK(cond_val.IsRegister()); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4083 | if (true_target == nullptr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4084 | __ Beqz(cond_val.AsRegister<Register>(), false_target); |
| 4085 | } else { |
| 4086 | __ Bnez(cond_val.AsRegister<Register>(), true_target); |
| 4087 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4088 | } else { |
| 4089 | // The condition instruction has not been materialized, use its inputs as |
| 4090 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4091 | HCondition* condition = cond->AsCondition(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4092 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 4093 | LocationSummary* locations = cond->GetLocations(); |
| 4094 | IfCondition if_cond = condition->GetCondition(); |
| 4095 | MipsLabel* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4096 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4097 | if (true_target == nullptr) { |
| 4098 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4099 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4100 | } |
| 4101 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 4102 | switch (type) { |
| 4103 | default: |
| 4104 | GenerateIntCompareAndBranch(if_cond, locations, branch_target); |
| 4105 | break; |
| 4106 | case Primitive::kPrimLong: |
| 4107 | GenerateLongCompareAndBranch(if_cond, locations, branch_target); |
| 4108 | break; |
| 4109 | case Primitive::kPrimFloat: |
| 4110 | case Primitive::kPrimDouble: |
| 4111 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 4112 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4113 | } |
| 4114 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4115 | |
| 4116 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 4117 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 4118 | if (true_target != nullptr && false_target != nullptr) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4119 | __ B(false_target); |
| 4120 | } |
| 4121 | } |
| 4122 | |
| 4123 | void LocationsBuilderMIPS::VisitIf(HIf* if_instr) { |
| 4124 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4125 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4126 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4127 | } |
| 4128 | } |
| 4129 | |
| 4130 | void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4131 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 4132 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 4133 | MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 4134 | nullptr : codegen_->GetLabelOf(true_successor); |
| 4135 | MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 4136 | nullptr : codegen_->GetLabelOf(false_successor); |
| 4137 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4138 | } |
| 4139 | |
| 4140 | void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 4141 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 4142 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4143 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4144 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4145 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4146 | } |
| 4147 | } |
| 4148 | |
| 4149 | void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 4150 | SlowPathCodeMIPS* slow_path = |
| 4151 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 4152 | GenerateTestAndBranch(deoptimize, |
| 4153 | /* condition_input_index */ 0, |
| 4154 | slow_path->GetEntryLabel(), |
| 4155 | /* false_target */ nullptr); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4156 | } |
| 4157 | |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4158 | // This function returns true if a conditional move can be generated for HSelect. |
| 4159 | // Otherwise it returns false and HSelect must be implemented in terms of conditonal |
| 4160 | // branches and regular moves. |
| 4161 | // |
| 4162 | // If `locations_to_set` isn't nullptr, its inputs and outputs are set for HSelect. |
| 4163 | // |
| 4164 | // While determining feasibility of a conditional move and setting inputs/outputs |
| 4165 | // are two distinct tasks, this function does both because they share quite a bit |
| 4166 | // of common logic. |
| 4167 | static bool CanMoveConditionally(HSelect* select, bool is_r6, LocationSummary* locations_to_set) { |
| 4168 | bool materialized = IsBooleanValueOrMaterializedCondition(select->GetCondition()); |
| 4169 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4170 | HCondition* condition = cond->AsCondition(); |
| 4171 | |
| 4172 | Primitive::Type cond_type = materialized ? Primitive::kPrimInt : condition->InputAt(0)->GetType(); |
| 4173 | Primitive::Type dst_type = select->GetType(); |
| 4174 | |
| 4175 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 4176 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 4177 | bool is_true_value_zero_constant = |
| 4178 | (cst_true_value != nullptr && cst_true_value->IsZeroBitPattern()); |
| 4179 | bool is_false_value_zero_constant = |
| 4180 | (cst_false_value != nullptr && cst_false_value->IsZeroBitPattern()); |
| 4181 | |
| 4182 | bool can_move_conditionally = false; |
| 4183 | bool use_const_for_false_in = false; |
| 4184 | bool use_const_for_true_in = false; |
| 4185 | |
| 4186 | if (!cond->IsConstant()) { |
| 4187 | switch (cond_type) { |
| 4188 | default: |
| 4189 | switch (dst_type) { |
| 4190 | default: |
| 4191 | // Moving int on int condition. |
| 4192 | if (is_r6) { |
| 4193 | if (is_true_value_zero_constant) { |
| 4194 | // seleqz out_reg, false_reg, cond_reg |
| 4195 | can_move_conditionally = true; |
| 4196 | use_const_for_true_in = true; |
| 4197 | } else if (is_false_value_zero_constant) { |
| 4198 | // selnez out_reg, true_reg, cond_reg |
| 4199 | can_move_conditionally = true; |
| 4200 | use_const_for_false_in = true; |
| 4201 | } else if (materialized) { |
| 4202 | // Not materializing unmaterialized int conditions |
| 4203 | // to keep the instruction count low. |
| 4204 | // selnez AT, true_reg, cond_reg |
| 4205 | // seleqz TMP, false_reg, cond_reg |
| 4206 | // or out_reg, AT, TMP |
| 4207 | can_move_conditionally = true; |
| 4208 | } |
| 4209 | } else { |
| 4210 | // movn out_reg, true_reg/ZERO, cond_reg |
| 4211 | can_move_conditionally = true; |
| 4212 | use_const_for_true_in = is_true_value_zero_constant; |
| 4213 | } |
| 4214 | break; |
| 4215 | case Primitive::kPrimLong: |
| 4216 | // Moving long on int condition. |
| 4217 | if (is_r6) { |
| 4218 | if (is_true_value_zero_constant) { |
| 4219 | // seleqz out_reg_lo, false_reg_lo, cond_reg |
| 4220 | // seleqz out_reg_hi, false_reg_hi, cond_reg |
| 4221 | can_move_conditionally = true; |
| 4222 | use_const_for_true_in = true; |
| 4223 | } else if (is_false_value_zero_constant) { |
| 4224 | // selnez out_reg_lo, true_reg_lo, cond_reg |
| 4225 | // selnez out_reg_hi, true_reg_hi, cond_reg |
| 4226 | can_move_conditionally = true; |
| 4227 | use_const_for_false_in = true; |
| 4228 | } |
| 4229 | // Other long conditional moves would generate 6+ instructions, |
| 4230 | // which is too many. |
| 4231 | } else { |
| 4232 | // movn out_reg_lo, true_reg_lo/ZERO, cond_reg |
| 4233 | // movn out_reg_hi, true_reg_hi/ZERO, cond_reg |
| 4234 | can_move_conditionally = true; |
| 4235 | use_const_for_true_in = is_true_value_zero_constant; |
| 4236 | } |
| 4237 | break; |
| 4238 | case Primitive::kPrimFloat: |
| 4239 | case Primitive::kPrimDouble: |
| 4240 | // Moving float/double on int condition. |
| 4241 | if (is_r6) { |
| 4242 | if (materialized) { |
| 4243 | // Not materializing unmaterialized int conditions |
| 4244 | // to keep the instruction count low. |
| 4245 | can_move_conditionally = true; |
| 4246 | if (is_true_value_zero_constant) { |
| 4247 | // sltu TMP, ZERO, cond_reg |
| 4248 | // mtc1 TMP, temp_cond_reg |
| 4249 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 4250 | use_const_for_true_in = true; |
| 4251 | } else if (is_false_value_zero_constant) { |
| 4252 | // sltu TMP, ZERO, cond_reg |
| 4253 | // mtc1 TMP, temp_cond_reg |
| 4254 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 4255 | use_const_for_false_in = true; |
| 4256 | } else { |
| 4257 | // sltu TMP, ZERO, cond_reg |
| 4258 | // mtc1 TMP, temp_cond_reg |
| 4259 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 4260 | // mov.fmt out_reg, temp_cond_reg |
| 4261 | } |
| 4262 | } |
| 4263 | } else { |
| 4264 | // movn.fmt out_reg, true_reg, cond_reg |
| 4265 | can_move_conditionally = true; |
| 4266 | } |
| 4267 | break; |
| 4268 | } |
| 4269 | break; |
| 4270 | case Primitive::kPrimLong: |
| 4271 | // We don't materialize long comparison now |
| 4272 | // and use conditional branches instead. |
| 4273 | break; |
| 4274 | case Primitive::kPrimFloat: |
| 4275 | case Primitive::kPrimDouble: |
| 4276 | switch (dst_type) { |
| 4277 | default: |
| 4278 | // Moving int on float/double condition. |
| 4279 | if (is_r6) { |
| 4280 | if (is_true_value_zero_constant) { |
| 4281 | // mfc1 TMP, temp_cond_reg |
| 4282 | // seleqz out_reg, false_reg, TMP |
| 4283 | can_move_conditionally = true; |
| 4284 | use_const_for_true_in = true; |
| 4285 | } else if (is_false_value_zero_constant) { |
| 4286 | // mfc1 TMP, temp_cond_reg |
| 4287 | // selnez out_reg, true_reg, TMP |
| 4288 | can_move_conditionally = true; |
| 4289 | use_const_for_false_in = true; |
| 4290 | } else { |
| 4291 | // mfc1 TMP, temp_cond_reg |
| 4292 | // selnez AT, true_reg, TMP |
| 4293 | // seleqz TMP, false_reg, TMP |
| 4294 | // or out_reg, AT, TMP |
| 4295 | can_move_conditionally = true; |
| 4296 | } |
| 4297 | } else { |
| 4298 | // movt out_reg, true_reg/ZERO, cc |
| 4299 | can_move_conditionally = true; |
| 4300 | use_const_for_true_in = is_true_value_zero_constant; |
| 4301 | } |
| 4302 | break; |
| 4303 | case Primitive::kPrimLong: |
| 4304 | // Moving long on float/double condition. |
| 4305 | if (is_r6) { |
| 4306 | if (is_true_value_zero_constant) { |
| 4307 | // mfc1 TMP, temp_cond_reg |
| 4308 | // seleqz out_reg_lo, false_reg_lo, TMP |
| 4309 | // seleqz out_reg_hi, false_reg_hi, TMP |
| 4310 | can_move_conditionally = true; |
| 4311 | use_const_for_true_in = true; |
| 4312 | } else if (is_false_value_zero_constant) { |
| 4313 | // mfc1 TMP, temp_cond_reg |
| 4314 | // selnez out_reg_lo, true_reg_lo, TMP |
| 4315 | // selnez out_reg_hi, true_reg_hi, TMP |
| 4316 | can_move_conditionally = true; |
| 4317 | use_const_for_false_in = true; |
| 4318 | } |
| 4319 | // Other long conditional moves would generate 6+ instructions, |
| 4320 | // which is too many. |
| 4321 | } else { |
| 4322 | // movt out_reg_lo, true_reg_lo/ZERO, cc |
| 4323 | // movt out_reg_hi, true_reg_hi/ZERO, cc |
| 4324 | can_move_conditionally = true; |
| 4325 | use_const_for_true_in = is_true_value_zero_constant; |
| 4326 | } |
| 4327 | break; |
| 4328 | case Primitive::kPrimFloat: |
| 4329 | case Primitive::kPrimDouble: |
| 4330 | // Moving float/double on float/double condition. |
| 4331 | if (is_r6) { |
| 4332 | can_move_conditionally = true; |
| 4333 | if (is_true_value_zero_constant) { |
| 4334 | // seleqz.fmt out_reg, false_reg, temp_cond_reg |
| 4335 | use_const_for_true_in = true; |
| 4336 | } else if (is_false_value_zero_constant) { |
| 4337 | // selnez.fmt out_reg, true_reg, temp_cond_reg |
| 4338 | use_const_for_false_in = true; |
| 4339 | } else { |
| 4340 | // sel.fmt temp_cond_reg, false_reg, true_reg |
| 4341 | // mov.fmt out_reg, temp_cond_reg |
| 4342 | } |
| 4343 | } else { |
| 4344 | // movt.fmt out_reg, true_reg, cc |
| 4345 | can_move_conditionally = true; |
| 4346 | } |
| 4347 | break; |
| 4348 | } |
| 4349 | break; |
| 4350 | } |
| 4351 | } |
| 4352 | |
| 4353 | if (can_move_conditionally) { |
| 4354 | DCHECK(!use_const_for_false_in || !use_const_for_true_in); |
| 4355 | } else { |
| 4356 | DCHECK(!use_const_for_false_in); |
| 4357 | DCHECK(!use_const_for_true_in); |
| 4358 | } |
| 4359 | |
| 4360 | if (locations_to_set != nullptr) { |
| 4361 | if (use_const_for_false_in) { |
| 4362 | locations_to_set->SetInAt(0, Location::ConstantLocation(cst_false_value)); |
| 4363 | } else { |
| 4364 | locations_to_set->SetInAt(0, |
| 4365 | Primitive::IsFloatingPointType(dst_type) |
| 4366 | ? Location::RequiresFpuRegister() |
| 4367 | : Location::RequiresRegister()); |
| 4368 | } |
| 4369 | if (use_const_for_true_in) { |
| 4370 | locations_to_set->SetInAt(1, Location::ConstantLocation(cst_true_value)); |
| 4371 | } else { |
| 4372 | locations_to_set->SetInAt(1, |
| 4373 | Primitive::IsFloatingPointType(dst_type) |
| 4374 | ? Location::RequiresFpuRegister() |
| 4375 | : Location::RequiresRegister()); |
| 4376 | } |
| 4377 | if (materialized) { |
| 4378 | locations_to_set->SetInAt(2, Location::RequiresRegister()); |
| 4379 | } |
| 4380 | // On R6 we don't require the output to be the same as the |
| 4381 | // first input for conditional moves unlike on R2. |
| 4382 | bool is_out_same_as_first_in = !can_move_conditionally || !is_r6; |
| 4383 | if (is_out_same_as_first_in) { |
| 4384 | locations_to_set->SetOut(Location::SameAsFirstInput()); |
| 4385 | } else { |
| 4386 | locations_to_set->SetOut(Primitive::IsFloatingPointType(dst_type) |
| 4387 | ? Location::RequiresFpuRegister() |
| 4388 | : Location::RequiresRegister()); |
| 4389 | } |
| 4390 | } |
| 4391 | |
| 4392 | return can_move_conditionally; |
| 4393 | } |
| 4394 | |
| 4395 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR2(HSelect* select) { |
| 4396 | LocationSummary* locations = select->GetLocations(); |
| 4397 | Location dst = locations->Out(); |
| 4398 | Location src = locations->InAt(1); |
| 4399 | Register src_reg = ZERO; |
| 4400 | Register src_reg_high = ZERO; |
| 4401 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4402 | Register cond_reg = TMP; |
| 4403 | int cond_cc = 0; |
| 4404 | Primitive::Type cond_type = Primitive::kPrimInt; |
| 4405 | bool cond_inverted = false; |
| 4406 | Primitive::Type dst_type = select->GetType(); |
| 4407 | |
| 4408 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 4409 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 4410 | } else { |
| 4411 | HCondition* condition = cond->AsCondition(); |
| 4412 | LocationSummary* cond_locations = cond->GetLocations(); |
| 4413 | IfCondition if_cond = condition->GetCondition(); |
| 4414 | cond_type = condition->InputAt(0)->GetType(); |
| 4415 | switch (cond_type) { |
| 4416 | default: |
| 4417 | DCHECK_NE(cond_type, Primitive::kPrimLong); |
| 4418 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 4419 | break; |
| 4420 | case Primitive::kPrimFloat: |
| 4421 | case Primitive::kPrimDouble: |
| 4422 | cond_inverted = MaterializeFpCompareR2(if_cond, |
| 4423 | condition->IsGtBias(), |
| 4424 | cond_type, |
| 4425 | cond_locations, |
| 4426 | cond_cc); |
| 4427 | break; |
| 4428 | } |
| 4429 | } |
| 4430 | |
| 4431 | DCHECK(dst.Equals(locations->InAt(0))); |
| 4432 | if (src.IsRegister()) { |
| 4433 | src_reg = src.AsRegister<Register>(); |
| 4434 | } else if (src.IsRegisterPair()) { |
| 4435 | src_reg = src.AsRegisterPairLow<Register>(); |
| 4436 | src_reg_high = src.AsRegisterPairHigh<Register>(); |
| 4437 | } else if (src.IsConstant()) { |
| 4438 | DCHECK(src.GetConstant()->IsZeroBitPattern()); |
| 4439 | } |
| 4440 | |
| 4441 | switch (cond_type) { |
| 4442 | default: |
| 4443 | switch (dst_type) { |
| 4444 | default: |
| 4445 | if (cond_inverted) { |
| 4446 | __ Movz(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 4447 | } else { |
| 4448 | __ Movn(dst.AsRegister<Register>(), src_reg, cond_reg); |
| 4449 | } |
| 4450 | break; |
| 4451 | case Primitive::kPrimLong: |
| 4452 | if (cond_inverted) { |
| 4453 | __ Movz(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 4454 | __ Movz(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 4455 | } else { |
| 4456 | __ Movn(dst.AsRegisterPairLow<Register>(), src_reg, cond_reg); |
| 4457 | __ Movn(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_reg); |
| 4458 | } |
| 4459 | break; |
| 4460 | case Primitive::kPrimFloat: |
| 4461 | if (cond_inverted) { |
| 4462 | __ MovzS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 4463 | } else { |
| 4464 | __ MovnS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 4465 | } |
| 4466 | break; |
| 4467 | case Primitive::kPrimDouble: |
| 4468 | if (cond_inverted) { |
| 4469 | __ MovzD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 4470 | } else { |
| 4471 | __ MovnD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_reg); |
| 4472 | } |
| 4473 | break; |
| 4474 | } |
| 4475 | break; |
| 4476 | case Primitive::kPrimLong: |
| 4477 | LOG(FATAL) << "Unreachable"; |
| 4478 | UNREACHABLE(); |
| 4479 | case Primitive::kPrimFloat: |
| 4480 | case Primitive::kPrimDouble: |
| 4481 | switch (dst_type) { |
| 4482 | default: |
| 4483 | if (cond_inverted) { |
| 4484 | __ Movf(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 4485 | } else { |
| 4486 | __ Movt(dst.AsRegister<Register>(), src_reg, cond_cc); |
| 4487 | } |
| 4488 | break; |
| 4489 | case Primitive::kPrimLong: |
| 4490 | if (cond_inverted) { |
| 4491 | __ Movf(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 4492 | __ Movf(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 4493 | } else { |
| 4494 | __ Movt(dst.AsRegisterPairLow<Register>(), src_reg, cond_cc); |
| 4495 | __ Movt(dst.AsRegisterPairHigh<Register>(), src_reg_high, cond_cc); |
| 4496 | } |
| 4497 | break; |
| 4498 | case Primitive::kPrimFloat: |
| 4499 | if (cond_inverted) { |
| 4500 | __ MovfS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 4501 | } else { |
| 4502 | __ MovtS(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 4503 | } |
| 4504 | break; |
| 4505 | case Primitive::kPrimDouble: |
| 4506 | if (cond_inverted) { |
| 4507 | __ MovfD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 4508 | } else { |
| 4509 | __ MovtD(dst.AsFpuRegister<FRegister>(), src.AsFpuRegister<FRegister>(), cond_cc); |
| 4510 | } |
| 4511 | break; |
| 4512 | } |
| 4513 | break; |
| 4514 | } |
| 4515 | } |
| 4516 | |
| 4517 | void InstructionCodeGeneratorMIPS::GenConditionalMoveR6(HSelect* select) { |
| 4518 | LocationSummary* locations = select->GetLocations(); |
| 4519 | Location dst = locations->Out(); |
| 4520 | Location false_src = locations->InAt(0); |
| 4521 | Location true_src = locations->InAt(1); |
| 4522 | HInstruction* cond = select->InputAt(/* condition_input_index */ 2); |
| 4523 | Register cond_reg = TMP; |
| 4524 | FRegister fcond_reg = FTMP; |
| 4525 | Primitive::Type cond_type = Primitive::kPrimInt; |
| 4526 | bool cond_inverted = false; |
| 4527 | Primitive::Type dst_type = select->GetType(); |
| 4528 | |
| 4529 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 4530 | cond_reg = locations->InAt(/* condition_input_index */ 2).AsRegister<Register>(); |
| 4531 | } else { |
| 4532 | HCondition* condition = cond->AsCondition(); |
| 4533 | LocationSummary* cond_locations = cond->GetLocations(); |
| 4534 | IfCondition if_cond = condition->GetCondition(); |
| 4535 | cond_type = condition->InputAt(0)->GetType(); |
| 4536 | switch (cond_type) { |
| 4537 | default: |
| 4538 | DCHECK_NE(cond_type, Primitive::kPrimLong); |
| 4539 | cond_inverted = MaterializeIntCompare(if_cond, cond_locations, cond_reg); |
| 4540 | break; |
| 4541 | case Primitive::kPrimFloat: |
| 4542 | case Primitive::kPrimDouble: |
| 4543 | cond_inverted = MaterializeFpCompareR6(if_cond, |
| 4544 | condition->IsGtBias(), |
| 4545 | cond_type, |
| 4546 | cond_locations, |
| 4547 | fcond_reg); |
| 4548 | break; |
| 4549 | } |
| 4550 | } |
| 4551 | |
| 4552 | if (true_src.IsConstant()) { |
| 4553 | DCHECK(true_src.GetConstant()->IsZeroBitPattern()); |
| 4554 | } |
| 4555 | if (false_src.IsConstant()) { |
| 4556 | DCHECK(false_src.GetConstant()->IsZeroBitPattern()); |
| 4557 | } |
| 4558 | |
| 4559 | switch (dst_type) { |
| 4560 | default: |
| 4561 | if (Primitive::IsFloatingPointType(cond_type)) { |
| 4562 | __ Mfc1(cond_reg, fcond_reg); |
| 4563 | } |
| 4564 | if (true_src.IsConstant()) { |
| 4565 | if (cond_inverted) { |
| 4566 | __ Selnez(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 4567 | } else { |
| 4568 | __ Seleqz(dst.AsRegister<Register>(), false_src.AsRegister<Register>(), cond_reg); |
| 4569 | } |
| 4570 | } else if (false_src.IsConstant()) { |
| 4571 | if (cond_inverted) { |
| 4572 | __ Seleqz(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 4573 | } else { |
| 4574 | __ Selnez(dst.AsRegister<Register>(), true_src.AsRegister<Register>(), cond_reg); |
| 4575 | } |
| 4576 | } else { |
| 4577 | DCHECK_NE(cond_reg, AT); |
| 4578 | if (cond_inverted) { |
| 4579 | __ Seleqz(AT, true_src.AsRegister<Register>(), cond_reg); |
| 4580 | __ Selnez(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 4581 | } else { |
| 4582 | __ Selnez(AT, true_src.AsRegister<Register>(), cond_reg); |
| 4583 | __ Seleqz(TMP, false_src.AsRegister<Register>(), cond_reg); |
| 4584 | } |
| 4585 | __ Or(dst.AsRegister<Register>(), AT, TMP); |
| 4586 | } |
| 4587 | break; |
| 4588 | case Primitive::kPrimLong: { |
| 4589 | if (Primitive::IsFloatingPointType(cond_type)) { |
| 4590 | __ Mfc1(cond_reg, fcond_reg); |
| 4591 | } |
| 4592 | Register dst_lo = dst.AsRegisterPairLow<Register>(); |
| 4593 | Register dst_hi = dst.AsRegisterPairHigh<Register>(); |
| 4594 | if (true_src.IsConstant()) { |
| 4595 | Register src_lo = false_src.AsRegisterPairLow<Register>(); |
| 4596 | Register src_hi = false_src.AsRegisterPairHigh<Register>(); |
| 4597 | if (cond_inverted) { |
| 4598 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 4599 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 4600 | } else { |
| 4601 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 4602 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 4603 | } |
| 4604 | } else { |
| 4605 | DCHECK(false_src.IsConstant()); |
| 4606 | Register src_lo = true_src.AsRegisterPairLow<Register>(); |
| 4607 | Register src_hi = true_src.AsRegisterPairHigh<Register>(); |
| 4608 | if (cond_inverted) { |
| 4609 | __ Seleqz(dst_lo, src_lo, cond_reg); |
| 4610 | __ Seleqz(dst_hi, src_hi, cond_reg); |
| 4611 | } else { |
| 4612 | __ Selnez(dst_lo, src_lo, cond_reg); |
| 4613 | __ Selnez(dst_hi, src_hi, cond_reg); |
| 4614 | } |
| 4615 | } |
| 4616 | break; |
| 4617 | } |
| 4618 | case Primitive::kPrimFloat: { |
| 4619 | if (!Primitive::IsFloatingPointType(cond_type)) { |
| 4620 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 4621 | __ Sltu(TMP, ZERO, cond_reg); |
| 4622 | __ Mtc1(TMP, fcond_reg); |
| 4623 | } |
| 4624 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 4625 | if (true_src.IsConstant()) { |
| 4626 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 4627 | if (cond_inverted) { |
| 4628 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 4629 | } else { |
| 4630 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 4631 | } |
| 4632 | } else if (false_src.IsConstant()) { |
| 4633 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 4634 | if (cond_inverted) { |
| 4635 | __ SeleqzS(dst_reg, src_reg, fcond_reg); |
| 4636 | } else { |
| 4637 | __ SelnezS(dst_reg, src_reg, fcond_reg); |
| 4638 | } |
| 4639 | } else { |
| 4640 | if (cond_inverted) { |
| 4641 | __ SelS(fcond_reg, |
| 4642 | true_src.AsFpuRegister<FRegister>(), |
| 4643 | false_src.AsFpuRegister<FRegister>()); |
| 4644 | } else { |
| 4645 | __ SelS(fcond_reg, |
| 4646 | false_src.AsFpuRegister<FRegister>(), |
| 4647 | true_src.AsFpuRegister<FRegister>()); |
| 4648 | } |
| 4649 | __ MovS(dst_reg, fcond_reg); |
| 4650 | } |
| 4651 | break; |
| 4652 | } |
| 4653 | case Primitive::kPrimDouble: { |
| 4654 | if (!Primitive::IsFloatingPointType(cond_type)) { |
| 4655 | // sel*.fmt tests bit 0 of the condition register, account for that. |
| 4656 | __ Sltu(TMP, ZERO, cond_reg); |
| 4657 | __ Mtc1(TMP, fcond_reg); |
| 4658 | } |
| 4659 | FRegister dst_reg = dst.AsFpuRegister<FRegister>(); |
| 4660 | if (true_src.IsConstant()) { |
| 4661 | FRegister src_reg = false_src.AsFpuRegister<FRegister>(); |
| 4662 | if (cond_inverted) { |
| 4663 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 4664 | } else { |
| 4665 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 4666 | } |
| 4667 | } else if (false_src.IsConstant()) { |
| 4668 | FRegister src_reg = true_src.AsFpuRegister<FRegister>(); |
| 4669 | if (cond_inverted) { |
| 4670 | __ SeleqzD(dst_reg, src_reg, fcond_reg); |
| 4671 | } else { |
| 4672 | __ SelnezD(dst_reg, src_reg, fcond_reg); |
| 4673 | } |
| 4674 | } else { |
| 4675 | if (cond_inverted) { |
| 4676 | __ SelD(fcond_reg, |
| 4677 | true_src.AsFpuRegister<FRegister>(), |
| 4678 | false_src.AsFpuRegister<FRegister>()); |
| 4679 | } else { |
| 4680 | __ SelD(fcond_reg, |
| 4681 | false_src.AsFpuRegister<FRegister>(), |
| 4682 | true_src.AsFpuRegister<FRegister>()); |
| 4683 | } |
| 4684 | __ MovD(dst_reg, fcond_reg); |
| 4685 | } |
| 4686 | break; |
| 4687 | } |
| 4688 | } |
| 4689 | } |
| 4690 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4691 | void LocationsBuilderMIPS::VisitSelect(HSelect* select) { |
| 4692 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4693 | CanMoveConditionally(select, codegen_->GetInstructionSetFeatures().IsR6(), locations); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4694 | } |
| 4695 | |
| 4696 | void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 4697 | bool is_r6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4698 | if (CanMoveConditionally(select, is_r6, /* locations_to_set */ nullptr)) { |
| 4699 | if (is_r6) { |
| 4700 | GenConditionalMoveR6(select); |
| 4701 | } else { |
| 4702 | GenConditionalMoveR2(select); |
| 4703 | } |
| 4704 | } else { |
| 4705 | LocationSummary* locations = select->GetLocations(); |
| 4706 | MipsLabel false_target; |
| 4707 | GenerateTestAndBranch(select, |
| 4708 | /* condition_input_index */ 2, |
| 4709 | /* true_target */ nullptr, |
| 4710 | &false_target); |
| 4711 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 4712 | __ Bind(&false_target); |
| 4713 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4714 | } |
| 4715 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4716 | void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 4717 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 4718 | } |
| 4719 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 4720 | void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 4721 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 4722 | } |
| 4723 | |
| 4724 | void CodeGeneratorMIPS::GenerateNop() { |
| 4725 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4726 | } |
| 4727 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4728 | void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4729 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4730 | bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble); |
| 4731 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
| 4732 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4733 | instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4734 | |
| 4735 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4736 | if (generate_volatile) { |
| 4737 | InvokeRuntimeCallingConvention calling_convention; |
| 4738 | // need A0 to hold base + offset |
| 4739 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4740 | if (field_type == Primitive::kPrimLong) { |
| 4741 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimLong)); |
| 4742 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4743 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 4744 | locations->SetOut(Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4745 | // Need some temp core regs since FP results are returned in core registers |
| 4746 | Location reg = calling_convention.GetReturnLocation(Primitive::kPrimLong); |
| 4747 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>())); |
| 4748 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>())); |
| 4749 | } |
| 4750 | } else { |
| 4751 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4752 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4753 | } else { |
| 4754 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4755 | } |
| 4756 | } |
| 4757 | } |
| 4758 | |
| 4759 | void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction, |
| 4760 | const FieldInfo& field_info, |
| 4761 | uint32_t dex_pc) { |
| 4762 | Primitive::Type type = field_info.GetFieldType(); |
| 4763 | LocationSummary* locations = instruction->GetLocations(); |
| 4764 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4765 | LoadOperandType load_type = kLoadUnsignedByte; |
| 4766 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 4767 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4768 | auto null_checker = GetImplicitNullChecker(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4769 | |
| 4770 | switch (type) { |
| 4771 | case Primitive::kPrimBoolean: |
| 4772 | load_type = kLoadUnsignedByte; |
| 4773 | break; |
| 4774 | case Primitive::kPrimByte: |
| 4775 | load_type = kLoadSignedByte; |
| 4776 | break; |
| 4777 | case Primitive::kPrimShort: |
| 4778 | load_type = kLoadSignedHalfword; |
| 4779 | break; |
| 4780 | case Primitive::kPrimChar: |
| 4781 | load_type = kLoadUnsignedHalfword; |
| 4782 | break; |
| 4783 | case Primitive::kPrimInt: |
| 4784 | case Primitive::kPrimFloat: |
| 4785 | case Primitive::kPrimNot: |
| 4786 | load_type = kLoadWord; |
| 4787 | break; |
| 4788 | case Primitive::kPrimLong: |
| 4789 | case Primitive::kPrimDouble: |
| 4790 | load_type = kLoadDoubleword; |
| 4791 | break; |
| 4792 | case Primitive::kPrimVoid: |
| 4793 | LOG(FATAL) << "Unreachable type " << type; |
| 4794 | UNREACHABLE(); |
| 4795 | } |
| 4796 | |
| 4797 | if (is_volatile && load_type == kLoadDoubleword) { |
| 4798 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 4799 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4800 | // Do implicit Null check |
| 4801 | __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0); |
| 4802 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 4803 | codegen_->InvokeRuntime(kQuickA64Load, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4804 | CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>(); |
| 4805 | if (type == Primitive::kPrimDouble) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4806 | // FP results are returned in core registers. Need to move them. |
| 4807 | Location out = locations->Out(); |
| 4808 | if (out.IsFpuRegister()) { |
| 4809 | __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), out.AsFpuRegister<FRegister>()); |
| 4810 | __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
| 4811 | out.AsFpuRegister<FRegister>()); |
| 4812 | } else { |
| 4813 | DCHECK(out.IsDoubleStackSlot()); |
| 4814 | __ StoreToOffset(kStoreWord, |
| 4815 | locations->GetTemp(1).AsRegister<Register>(), |
| 4816 | SP, |
| 4817 | out.GetStackIndex()); |
| 4818 | __ StoreToOffset(kStoreWord, |
| 4819 | locations->GetTemp(2).AsRegister<Register>(), |
| 4820 | SP, |
| 4821 | out.GetStackIndex() + 4); |
| 4822 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4823 | } |
| 4824 | } else { |
| 4825 | if (!Primitive::IsFloatingPointType(type)) { |
| 4826 | Register dst; |
| 4827 | if (type == Primitive::kPrimLong) { |
| 4828 | DCHECK(locations->Out().IsRegisterPair()); |
| 4829 | dst = locations->Out().AsRegisterPairLow<Register>(); |
| 4830 | } else { |
| 4831 | DCHECK(locations->Out().IsRegister()); |
| 4832 | dst = locations->Out().AsRegister<Register>(); |
| 4833 | } |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4834 | __ LoadFromOffset(load_type, dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4835 | } else { |
| 4836 | DCHECK(locations->Out().IsFpuRegister()); |
| 4837 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 4838 | if (type == Primitive::kPrimFloat) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4839 | __ LoadSFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4840 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4841 | __ LoadDFromOffset(dst, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4842 | } |
| 4843 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4844 | } |
| 4845 | |
| 4846 | if (is_volatile) { |
| 4847 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4848 | } |
| 4849 | } |
| 4850 | |
| 4851 | void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4852 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4853 | bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble); |
| 4854 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
| 4855 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4856 | instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4857 | |
| 4858 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4859 | if (generate_volatile) { |
| 4860 | InvokeRuntimeCallingConvention calling_convention; |
| 4861 | // need A0 to hold base + offset |
| 4862 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4863 | if (field_type == Primitive::kPrimLong) { |
| 4864 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4865 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4866 | } else { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4867 | // Use Location::Any() to prevent situations when running out of available fp registers. |
| 4868 | locations->SetInAt(1, Location::Any()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4869 | // Pass FP parameters in core registers. |
| 4870 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 4871 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3))); |
| 4872 | } |
| 4873 | } else { |
| 4874 | if (Primitive::IsFloatingPointType(field_type)) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4875 | locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4876 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4877 | locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4878 | } |
| 4879 | } |
| 4880 | } |
| 4881 | |
| 4882 | void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction, |
| 4883 | const FieldInfo& field_info, |
| 4884 | uint32_t dex_pc) { |
| 4885 | Primitive::Type type = field_info.GetFieldType(); |
| 4886 | LocationSummary* locations = instruction->GetLocations(); |
| 4887 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4888 | Location value_location = locations->InAt(1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4889 | StoreOperandType store_type = kStoreByte; |
| 4890 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 4891 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4892 | auto null_checker = GetImplicitNullChecker(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4893 | |
| 4894 | switch (type) { |
| 4895 | case Primitive::kPrimBoolean: |
| 4896 | case Primitive::kPrimByte: |
| 4897 | store_type = kStoreByte; |
| 4898 | break; |
| 4899 | case Primitive::kPrimShort: |
| 4900 | case Primitive::kPrimChar: |
| 4901 | store_type = kStoreHalfword; |
| 4902 | break; |
| 4903 | case Primitive::kPrimInt: |
| 4904 | case Primitive::kPrimFloat: |
| 4905 | case Primitive::kPrimNot: |
| 4906 | store_type = kStoreWord; |
| 4907 | break; |
| 4908 | case Primitive::kPrimLong: |
| 4909 | case Primitive::kPrimDouble: |
| 4910 | store_type = kStoreDoubleword; |
| 4911 | break; |
| 4912 | case Primitive::kPrimVoid: |
| 4913 | LOG(FATAL) << "Unreachable type " << type; |
| 4914 | UNREACHABLE(); |
| 4915 | } |
| 4916 | |
| 4917 | if (is_volatile) { |
| 4918 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 4919 | } |
| 4920 | |
| 4921 | if (is_volatile && store_type == kStoreDoubleword) { |
| 4922 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 4923 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4924 | // Do implicit Null check. |
| 4925 | __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0); |
| 4926 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4927 | if (type == Primitive::kPrimDouble) { |
| 4928 | // Pass FP parameters in core registers. |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4929 | if (value_location.IsFpuRegister()) { |
| 4930 | __ Mfc1(locations->GetTemp(1).AsRegister<Register>(), |
| 4931 | value_location.AsFpuRegister<FRegister>()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4932 | __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(), |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4933 | value_location.AsFpuRegister<FRegister>()); |
| 4934 | } else if (value_location.IsDoubleStackSlot()) { |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4935 | __ LoadFromOffset(kLoadWord, |
| 4936 | locations->GetTemp(1).AsRegister<Register>(), |
| 4937 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4938 | value_location.GetStackIndex()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4939 | __ LoadFromOffset(kLoadWord, |
| 4940 | locations->GetTemp(2).AsRegister<Register>(), |
| 4941 | SP, |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4942 | value_location.GetStackIndex() + 4); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4943 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4944 | DCHECK(value_location.IsConstant()); |
| 4945 | DCHECK(value_location.GetConstant()->IsDoubleConstant()); |
| 4946 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
Goran Jakovljevic | cdd822f | 2016-07-22 09:46:43 +0200 | [diff] [blame] | 4947 | __ LoadConst64(locations->GetTemp(2).AsRegister<Register>(), |
| 4948 | locations->GetTemp(1).AsRegister<Register>(), |
| 4949 | value); |
| 4950 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4951 | } |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 4952 | codegen_->InvokeRuntime(kQuickA64Store, instruction, dex_pc); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4953 | CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>(); |
| 4954 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4955 | if (value_location.IsConstant()) { |
| 4956 | int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant()); |
| 4957 | __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker); |
| 4958 | } else if (!Primitive::IsFloatingPointType(type)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4959 | Register src; |
| 4960 | if (type == Primitive::kPrimLong) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4961 | src = value_location.AsRegisterPairLow<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4962 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4963 | src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4964 | } |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4965 | __ StoreToOffset(store_type, src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4966 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4967 | FRegister src = value_location.AsFpuRegister<FRegister>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4968 | if (type == Primitive::kPrimFloat) { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4969 | __ StoreSToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4970 | } else { |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 4971 | __ StoreDToOffset(src, obj, offset, null_checker); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4972 | } |
| 4973 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4974 | } |
| 4975 | |
| 4976 | // TODO: memory barriers? |
| 4977 | if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 4978 | Register src = value_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4979 | codegen_->MarkGCCard(obj, src); |
| 4980 | } |
| 4981 | |
| 4982 | if (is_volatile) { |
| 4983 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 4984 | } |
| 4985 | } |
| 4986 | |
| 4987 | void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4988 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4989 | } |
| 4990 | |
| 4991 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4992 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 4993 | } |
| 4994 | |
| 4995 | void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4996 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4997 | } |
| 4998 | |
| 4999 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5000 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 5001 | } |
| 5002 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5003 | void InstructionCodeGeneratorMIPS::GenerateGcRootFieldLoad( |
| 5004 | HInstruction* instruction ATTRIBUTE_UNUSED, |
| 5005 | Location root, |
| 5006 | Register obj, |
| 5007 | uint32_t offset) { |
| 5008 | Register root_reg = root.AsRegister<Register>(); |
| 5009 | if (kEmitCompilerReadBarrier) { |
| 5010 | UNIMPLEMENTED(FATAL) << "for read barrier"; |
| 5011 | } else { |
| 5012 | // Plain GC root load with no read barrier. |
| 5013 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5014 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 5015 | // Note that GC roots are not affected by heap poisoning, thus we |
| 5016 | // do not have to unpoison `root_reg` here. |
| 5017 | } |
| 5018 | } |
| 5019 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5020 | void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
| 5021 | LocationSummary::CallKind call_kind = |
| 5022 | instruction->IsExactCheck() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath; |
| 5023 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5024 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5025 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5026 | // The output does overlap inputs. |
| 5027 | // Note that TypeCheckSlowPathMIPS uses this register too. |
| 5028 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5029 | } |
| 5030 | |
| 5031 | void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
| 5032 | LocationSummary* locations = instruction->GetLocations(); |
| 5033 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5034 | Register cls = locations->InAt(1).AsRegister<Register>(); |
| 5035 | Register out = locations->Out().AsRegister<Register>(); |
| 5036 | |
| 5037 | MipsLabel done; |
| 5038 | |
| 5039 | // Return 0 if `obj` is null. |
| 5040 | // TODO: Avoid this check if we know `obj` is not null. |
| 5041 | __ Move(out, ZERO); |
| 5042 | __ Beqz(obj, &done); |
| 5043 | |
| 5044 | // Compare the class of `obj` with `cls`. |
| 5045 | __ LoadFromOffset(kLoadWord, out, obj, mirror::Object::ClassOffset().Int32Value()); |
| 5046 | if (instruction->IsExactCheck()) { |
| 5047 | // Classes must be equal for the instanceof to succeed. |
| 5048 | __ Xor(out, out, cls); |
| 5049 | __ Sltiu(out, out, 1); |
| 5050 | } else { |
| 5051 | // If the classes are not equal, we go into a slow path. |
| 5052 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5053 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction); |
| 5054 | codegen_->AddSlowPath(slow_path); |
| 5055 | __ Bne(out, cls, slow_path->GetEntryLabel()); |
| 5056 | __ LoadConst32(out, 1); |
| 5057 | __ Bind(slow_path->GetExitLabel()); |
| 5058 | } |
| 5059 | |
| 5060 | __ Bind(&done); |
| 5061 | } |
| 5062 | |
| 5063 | void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) { |
| 5064 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5065 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5066 | } |
| 5067 | |
| 5068 | void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 5069 | // Will be generated at use site. |
| 5070 | } |
| 5071 | |
| 5072 | void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) { |
| 5073 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5074 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5075 | } |
| 5076 | |
| 5077 | void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 5078 | // Will be generated at use site. |
| 5079 | } |
| 5080 | |
| 5081 | void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) { |
| 5082 | InvokeDexCallingConventionVisitorMIPS calling_convention_visitor; |
| 5083 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 5084 | } |
| 5085 | |
| 5086 | void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 5087 | HandleInvoke(invoke); |
| 5088 | // The register T0 is required to be used for the hidden argument in |
| 5089 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
| 5090 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0)); |
| 5091 | } |
| 5092 | |
| 5093 | void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 5094 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 5095 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5096 | Location receiver = invoke->GetLocations()->InAt(0); |
| 5097 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5098 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5099 | |
| 5100 | // Set the hidden argument. |
| 5101 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(), |
| 5102 | invoke->GetDexMethodIndex()); |
| 5103 | |
| 5104 | // temp = object->GetClass(); |
| 5105 | if (receiver.IsStackSlot()) { |
| 5106 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 5107 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 5108 | } else { |
| 5109 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
| 5110 | } |
| 5111 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 5112 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 5113 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
| 5114 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 5115 | invoke->GetImtIndex(), kMipsPointerSize)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5116 | // temp = temp->GetImtEntryAt(method_offset); |
| 5117 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 5118 | // T9 = temp->GetEntryPoint(); |
| 5119 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 5120 | // T9(); |
| 5121 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 5122 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5123 | DCHECK(!codegen_->IsLeafMethod()); |
| 5124 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 5125 | } |
| 5126 | |
| 5127 | void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 5128 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 5129 | if (intrinsic.TryDispatch(invoke)) { |
| 5130 | return; |
| 5131 | } |
| 5132 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5133 | HandleInvoke(invoke); |
| 5134 | } |
| 5135 | |
| 5136 | void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5137 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5138 | // art::PrepareForRegisterAllocation. |
| 5139 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5140 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5141 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 5142 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
| 5143 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 5144 | |
| 5145 | // kDirectAddressWithFixup and kCallDirectWithFixup need no extra input on R6 because |
| 5146 | // R6 has PC-relative addressing. |
| 5147 | bool has_extra_input = !isR6 && |
| 5148 | ((method_load_kind == HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) || |
| 5149 | (code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup)); |
| 5150 | |
| 5151 | if (invoke->HasPcRelativeDexCache()) { |
| 5152 | // kDexCachePcRelative is mutually exclusive with |
| 5153 | // kDirectAddressWithFixup/kCallDirectWithFixup. |
| 5154 | CHECK(!has_extra_input); |
| 5155 | has_extra_input = true; |
| 5156 | } |
| 5157 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 5158 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 5159 | if (intrinsic.TryDispatch(invoke)) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5160 | if (invoke->GetLocations()->CanCall() && has_extra_input) { |
| 5161 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 5162 | } |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 5163 | return; |
| 5164 | } |
| 5165 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5166 | HandleInvoke(invoke); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5167 | |
| 5168 | // Add the extra input register if either the dex cache array base register |
| 5169 | // or the PC-relative base register for accessing literals is needed. |
| 5170 | if (has_extra_input) { |
| 5171 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 5172 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5173 | } |
| 5174 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 5175 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5176 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 5177 | IntrinsicCodeGeneratorMIPS intrinsic(codegen); |
| 5178 | intrinsic.Dispatch(invoke); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5179 | return true; |
| 5180 | } |
| 5181 | return false; |
| 5182 | } |
| 5183 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5184 | HLoadString::LoadKind CodeGeneratorMIPS::GetSupportedLoadStringKind( |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5185 | HLoadString::LoadKind desired_string_load_kind) { |
| 5186 | if (kEmitCompilerReadBarrier) { |
| 5187 | UNIMPLEMENTED(FATAL) << "for read barrier"; |
| 5188 | } |
| 5189 | // We disable PC-relative load when there is an irreducible loop, as the optimization |
| 5190 | // is incompatible with it. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5191 | // TODO: Create as many MipsDexCacheArraysBase instructions as needed for methods |
| 5192 | // with irreducible loops. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5193 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
| 5194 | bool fallback_load = has_irreducible_loops; |
| 5195 | switch (desired_string_load_kind) { |
| 5196 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5197 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5198 | break; |
| 5199 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5200 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5201 | break; |
| 5202 | case HLoadString::LoadKind::kBootImageAddress: |
| 5203 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5204 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5205 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5206 | break; |
| 5207 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5208 | fallback_load = false; |
| 5209 | break; |
| 5210 | } |
| 5211 | if (fallback_load) { |
| 5212 | desired_string_load_kind = HLoadString::LoadKind::kDexCacheViaMethod; |
| 5213 | } |
| 5214 | return desired_string_load_kind; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5215 | } |
| 5216 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5217 | HLoadClass::LoadKind CodeGeneratorMIPS::GetSupportedLoadClassKind( |
| 5218 | HLoadClass::LoadKind desired_class_load_kind) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5219 | if (kEmitCompilerReadBarrier) { |
| 5220 | UNIMPLEMENTED(FATAL) << "for read barrier"; |
| 5221 | } |
| 5222 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5223 | // is incompatible with it. |
| 5224 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
| 5225 | bool fallback_load = has_irreducible_loops; |
| 5226 | switch (desired_class_load_kind) { |
| 5227 | case HLoadClass::LoadKind::kReferrersClass: |
| 5228 | fallback_load = false; |
| 5229 | break; |
| 5230 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5231 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5232 | break; |
| 5233 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5234 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5235 | break; |
| 5236 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5237 | break; |
| 5238 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 5239 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5240 | fallback_load = false; |
| 5241 | break; |
| 5242 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5243 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5244 | // TODO: Create as many MipsDexCacheArraysBase instructions as needed for methods |
| 5245 | // with irreducible loops. |
| 5246 | break; |
| 5247 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5248 | fallback_load = false; |
| 5249 | break; |
| 5250 | } |
| 5251 | if (fallback_load) { |
| 5252 | desired_class_load_kind = HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5253 | } |
| 5254 | return desired_class_load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5255 | } |
| 5256 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5257 | Register CodeGeneratorMIPS::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 5258 | Register temp) { |
| 5259 | CHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 5260 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 5261 | if (!invoke->GetLocations()->Intrinsified()) { |
| 5262 | return location.AsRegister<Register>(); |
| 5263 | } |
| 5264 | // For intrinsics we allow any location, so it may be on the stack. |
| 5265 | if (!location.IsRegister()) { |
| 5266 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 5267 | return temp; |
| 5268 | } |
| 5269 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 5270 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 5271 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 5272 | // simple and more robust approach rather that trying to determine if that's the case. |
| 5273 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 5274 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 5275 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 5276 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 5277 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 5278 | return temp; |
| 5279 | } |
| 5280 | return location.AsRegister<Register>(); |
| 5281 | } |
| 5282 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5283 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch( |
| 5284 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5285 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5286 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 5287 | // We disable PC-relative load when there is an irreducible loop, as the optimization |
| 5288 | // is incompatible with it. |
| 5289 | bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops(); |
| 5290 | bool fallback_load = true; |
| 5291 | bool fallback_call = true; |
| 5292 | switch (dispatch_info.method_load_kind) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5293 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 5294 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5295 | fallback_load = has_irreducible_loops; |
| 5296 | break; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5297 | default: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5298 | fallback_load = false; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5299 | break; |
| 5300 | } |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5301 | switch (dispatch_info.code_ptr_location) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5302 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5303 | fallback_call = has_irreducible_loops; |
| 5304 | break; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5305 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5306 | // TODO: Implement this type. |
| 5307 | break; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5308 | default: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5309 | fallback_call = false; |
| 5310 | break; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5311 | } |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5312 | if (fallback_load) { |
| 5313 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 5314 | dispatch_info.method_load_data = 0; |
| 5315 | } |
| 5316 | if (fallback_call) { |
| 5317 | dispatch_info.code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; |
| 5318 | dispatch_info.direct_code_ptr = 0; |
| 5319 | } |
| 5320 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5321 | } |
| 5322 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5323 | void CodeGeneratorMIPS::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 5324 | // 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] | 5325 | 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] | 5326 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind(); |
| 5327 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation(); |
| 5328 | bool isR6 = isa_features_.IsR6(); |
| 5329 | // kDirectAddressWithFixup and kCallDirectWithFixup have no extra input on R6 because |
| 5330 | // R6 has PC-relative addressing. |
| 5331 | bool has_extra_input = invoke->HasPcRelativeDexCache() || |
| 5332 | (!isR6 && |
| 5333 | ((method_load_kind == HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) || |
| 5334 | (code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup))); |
| 5335 | Register base_reg = has_extra_input |
| 5336 | ? GetInvokeStaticOrDirectExtraParameter(invoke, temp.AsRegister<Register>()) |
| 5337 | : ZERO; |
| 5338 | |
| 5339 | // For better instruction scheduling we load the direct code pointer before the method pointer. |
| 5340 | switch (code_ptr_location) { |
| 5341 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 5342 | // T9 = invoke->GetDirectCodePtr(); |
| 5343 | __ LoadConst32(T9, invoke->GetDirectCodePtr()); |
| 5344 | break; |
| 5345 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 5346 | // T9 = code address from literal pool with link-time patch. |
| 5347 | __ LoadLiteral(T9, base_reg, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
| 5348 | break; |
| 5349 | default: |
| 5350 | break; |
| 5351 | } |
| 5352 | |
| 5353 | switch (method_load_kind) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5354 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5355 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5356 | uint32_t offset = |
| 5357 | GetThreadOffset<kMipsPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5358 | __ LoadFromOffset(kLoadWord, |
| 5359 | temp.AsRegister<Register>(), |
| 5360 | TR, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5361 | offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5362 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5363 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5364 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 5365 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5366 | break; |
| 5367 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 5368 | __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 5369 | break; |
| 5370 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5371 | __ LoadLiteral(temp.AsRegister<Register>(), |
| 5372 | base_reg, |
| 5373 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 5374 | break; |
| 5375 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 5376 | HMipsDexCacheArraysBase* base = |
| 5377 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsMipsDexCacheArraysBase(); |
| 5378 | int32_t offset = |
| 5379 | invoke->GetDexCacheArrayOffset() - base->GetElementOffset() - kDexCacheArrayLwOffset; |
| 5380 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 5381 | break; |
| 5382 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5383 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 5384 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5385 | Register reg = temp.AsRegister<Register>(); |
| 5386 | Register method_reg; |
| 5387 | if (current_method.IsRegister()) { |
| 5388 | method_reg = current_method.AsRegister<Register>(); |
| 5389 | } else { |
| 5390 | // TODO: use the appropriate DCHECK() here if possible. |
| 5391 | // DCHECK(invoke->GetLocations()->Intrinsified()); |
| 5392 | DCHECK(!current_method.IsValid()); |
| 5393 | method_reg = reg; |
| 5394 | __ Lw(reg, SP, kCurrentMethodStackOffset); |
| 5395 | } |
| 5396 | |
| 5397 | // temp = temp->dex_cache_resolved_methods_; |
| 5398 | __ LoadFromOffset(kLoadWord, |
| 5399 | reg, |
| 5400 | method_reg, |
| 5401 | ArtMethod::DexCacheResolvedMethodsOffset(kMipsPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 5402 | // temp = temp[index_in_cache]; |
| 5403 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 5404 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5405 | __ LoadFromOffset(kLoadWord, |
| 5406 | reg, |
| 5407 | reg, |
| 5408 | CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 5409 | break; |
| 5410 | } |
| 5411 | } |
| 5412 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5413 | switch (code_ptr_location) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5414 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5415 | __ Bal(&frame_entry_label_); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5416 | break; |
| 5417 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5418 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 5419 | // T9 prepared above for better instruction scheduling. |
| 5420 | // T9() |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5421 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 5422 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5423 | break; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5424 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 5425 | // TODO: Implement this type. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5426 | // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 5427 | LOG(FATAL) << "Unsupported"; |
| 5428 | UNREACHABLE(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5429 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 5430 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
Goran Jakovljevic | 1a87837 | 2015-10-26 14:28:52 +0100 | [diff] [blame] | 5431 | __ LoadFromOffset(kLoadWord, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5432 | T9, |
| 5433 | callee_method.AsRegister<Register>(), |
| 5434 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5435 | kMipsPointerSize).Int32Value()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5436 | // T9() |
| 5437 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 5438 | __ NopIfNoReordering(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5439 | break; |
| 5440 | } |
| 5441 | DCHECK(!IsLeafMethod()); |
| 5442 | } |
| 5443 | |
| 5444 | void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5445 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5446 | // art::PrepareForRegisterAllocation. |
| 5447 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5448 | |
| 5449 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 5450 | return; |
| 5451 | } |
| 5452 | |
| 5453 | LocationSummary* locations = invoke->GetLocations(); |
| 5454 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 5455 | locations->HasTemps() |
| 5456 | ? locations->GetTemp(0) |
| 5457 | : Location::NoLocation()); |
| 5458 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 5459 | } |
| 5460 | |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 5461 | void CodeGeneratorMIPS::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 5462 | // Use the calling convention instead of the location of the receiver, as |
| 5463 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 5464 | // slow path, the arguments have been moved to the right place, so here we are |
| 5465 | // guaranteed that the receiver is the first register of the calling convention. |
| 5466 | InvokeDexCallingConvention calling_convention; |
| 5467 | Register receiver = calling_convention.GetRegisterAt(0); |
| 5468 | |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 5469 | Register temp = temp_location.AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5470 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 5471 | invoke->GetVTableIndex(), kMipsPointerSize).SizeValue(); |
| 5472 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5473 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5474 | |
| 5475 | // temp = object->GetClass(); |
Goran Jakovljevic | e919b07 | 2016-10-04 10:17:34 +0200 | [diff] [blame] | 5476 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 5477 | MaybeRecordImplicitNullCheck(invoke); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5478 | // temp = temp->GetMethodAt(method_offset); |
| 5479 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 5480 | // T9 = temp->GetEntryPoint(); |
| 5481 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 5482 | // T9(); |
| 5483 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 5484 | __ NopIfNoReordering(); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 5485 | } |
| 5486 | |
| 5487 | void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 5488 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 5489 | return; |
| 5490 | } |
| 5491 | |
| 5492 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5493 | DCHECK(!codegen_->IsLeafMethod()); |
| 5494 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 5495 | } |
| 5496 | |
| 5497 | void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5498 | if (cls->NeedsAccessCheck()) { |
| 5499 | InvokeRuntimeCallingConvention calling_convention; |
| 5500 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5501 | cls, |
| 5502 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 5503 | Location::RegisterLocation(V0), |
| 5504 | /* code_generator_supports_read_barrier */ false); // TODO: revisit this bool. |
| 5505 | return; |
| 5506 | } |
| 5507 | |
| 5508 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier) |
| 5509 | ? LocationSummary::kCallOnSlowPath |
| 5510 | : LocationSummary::kNoCall; |
| 5511 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
| 5512 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5513 | switch (load_kind) { |
| 5514 | // We need an extra register for PC-relative literals on R2. |
| 5515 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5516 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5517 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5518 | if (codegen_->GetInstructionSetFeatures().IsR6()) { |
| 5519 | break; |
| 5520 | } |
| 5521 | FALLTHROUGH_INTENDED; |
| 5522 | // We need an extra register for PC-relative dex cache accesses. |
| 5523 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5524 | case HLoadClass::LoadKind::kReferrersClass: |
| 5525 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5526 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5527 | break; |
| 5528 | default: |
| 5529 | break; |
| 5530 | } |
| 5531 | locations->SetOut(Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5532 | } |
| 5533 | |
| 5534 | void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) { |
| 5535 | LocationSummary* locations = cls->GetLocations(); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 5536 | if (cls->NeedsAccessCheck()) { |
| 5537 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 5538 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5539 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 5540 | return; |
| 5541 | } |
| 5542 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5543 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5544 | Location out_loc = locations->Out(); |
| 5545 | Register out = out_loc.AsRegister<Register>(); |
| 5546 | Register base_or_current_method_reg; |
| 5547 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 5548 | switch (load_kind) { |
| 5549 | // We need an extra register for PC-relative literals on R2. |
| 5550 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5551 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5552 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5553 | base_or_current_method_reg = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>(); |
| 5554 | break; |
| 5555 | // We need an extra register for PC-relative dex cache accesses. |
| 5556 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5557 | case HLoadClass::LoadKind::kReferrersClass: |
| 5558 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5559 | base_or_current_method_reg = locations->InAt(0).AsRegister<Register>(); |
| 5560 | break; |
| 5561 | default: |
| 5562 | base_or_current_method_reg = ZERO; |
| 5563 | break; |
| 5564 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5565 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5566 | bool generate_null_check = false; |
| 5567 | switch (load_kind) { |
| 5568 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5569 | DCHECK(!cls->CanCallRuntime()); |
| 5570 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5571 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5572 | GenerateGcRootFieldLoad(cls, |
| 5573 | out_loc, |
| 5574 | base_or_current_method_reg, |
| 5575 | ArtMethod::DeclaringClassOffset().Int32Value()); |
| 5576 | break; |
| 5577 | } |
| 5578 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5579 | DCHECK(!kEmitCompilerReadBarrier); |
| 5580 | __ LoadLiteral(out, |
| 5581 | base_or_current_method_reg, |
| 5582 | codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 5583 | cls->GetTypeIndex())); |
| 5584 | break; |
| 5585 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
| 5586 | DCHECK(!kEmitCompilerReadBarrier); |
| 5587 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
| 5588 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5589 | codegen_->EmitPcRelativeAddressPlaceholder(info, out, base_or_current_method_reg); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5590 | break; |
| 5591 | } |
| 5592 | case HLoadClass::LoadKind::kBootImageAddress: { |
| 5593 | DCHECK(!kEmitCompilerReadBarrier); |
| 5594 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5595 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5596 | __ LoadLiteral(out, |
| 5597 | base_or_current_method_reg, |
| 5598 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5599 | break; |
| 5600 | } |
| 5601 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 5602 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5603 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5604 | static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes."); |
| 5605 | DCHECK_ALIGNED(cls->GetAddress(), 4u); |
| 5606 | int16_t offset = Low16Bits(address); |
| 5607 | uint32_t base_address = address - offset; // This accounts for offset sign extension. |
| 5608 | __ Lui(out, High16Bits(base_address)); |
| 5609 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) |
| 5610 | GenerateGcRootFieldLoad(cls, out_loc, out, offset); |
| 5611 | generate_null_check = !cls->IsInDexCache(); |
| 5612 | break; |
| 5613 | } |
| 5614 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 5615 | HMipsDexCacheArraysBase* base = cls->InputAt(0)->AsMipsDexCacheArraysBase(); |
| 5616 | int32_t offset = |
| 5617 | cls->GetDexCacheElementOffset() - base->GetElementOffset() - kDexCacheArrayLwOffset; |
| 5618 | // /* GcRoot<mirror::Class> */ out = *(dex_cache_arrays_base + offset) |
| 5619 | GenerateGcRootFieldLoad(cls, out_loc, base_or_current_method_reg, offset); |
| 5620 | generate_null_check = !cls->IsInDexCache(); |
| 5621 | break; |
| 5622 | } |
| 5623 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 5624 | // /* GcRoot<mirror::Class>[] */ out = |
| 5625 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5626 | __ LoadFromOffset(kLoadWord, |
| 5627 | out, |
| 5628 | base_or_current_method_reg, |
| 5629 | ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value()); |
| 5630 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5631 | size_t offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex()); |
| 5632 | GenerateGcRootFieldLoad(cls, out_loc, out, offset); |
| 5633 | generate_null_check = !cls->IsInDexCache(); |
| 5634 | } |
| 5635 | } |
| 5636 | |
| 5637 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5638 | DCHECK(cls->CanCallRuntime()); |
| 5639 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS( |
| 5640 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5641 | codegen_->AddSlowPath(slow_path); |
| 5642 | if (generate_null_check) { |
| 5643 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 5644 | } |
| 5645 | if (cls->MustGenerateClinitCheck()) { |
| 5646 | GenerateClassInitializationCheck(slow_path, out); |
| 5647 | } else { |
| 5648 | __ Bind(slow_path->GetExitLabel()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5649 | } |
| 5650 | } |
| 5651 | } |
| 5652 | |
| 5653 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5654 | return Thread::ExceptionOffset<kMipsPointerSize>().Int32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5655 | } |
| 5656 | |
| 5657 | void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) { |
| 5658 | LocationSummary* locations = |
| 5659 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5660 | locations->SetOut(Location::RequiresRegister()); |
| 5661 | } |
| 5662 | |
| 5663 | void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) { |
| 5664 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
| 5665 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 5666 | } |
| 5667 | |
| 5668 | void LocationsBuilderMIPS::VisitClearException(HClearException* clear) { |
| 5669 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5670 | } |
| 5671 | |
| 5672 | void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5673 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
| 5674 | } |
| 5675 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5676 | void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5677 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5678 | ? ((load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) |
| 5679 | ? LocationSummary::kCallOnMainOnly |
| 5680 | : LocationSummary::kCallOnSlowPath) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5681 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5682 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5683 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 5684 | switch (load_kind) { |
| 5685 | // We need an extra register for PC-relative literals on R2. |
| 5686 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5687 | case HLoadString::LoadKind::kBootImageAddress: |
| 5688 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5689 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5690 | if (codegen_->GetInstructionSetFeatures().IsR6()) { |
| 5691 | break; |
| 5692 | } |
| 5693 | FALLTHROUGH_INTENDED; |
| 5694 | // We need an extra register for PC-relative dex cache accesses. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5695 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5696 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5697 | break; |
| 5698 | default: |
| 5699 | break; |
| 5700 | } |
Alexey Frunze | bb51df8 | 2016-11-01 16:07:32 -0700 | [diff] [blame] | 5701 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 5702 | InvokeRuntimeCallingConvention calling_convention; |
| 5703 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5704 | } else { |
| 5705 | locations->SetOut(Location::RequiresRegister()); |
| 5706 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5707 | } |
| 5708 | |
| 5709 | void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5710 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5711 | LocationSummary* locations = load->GetLocations(); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5712 | Location out_loc = locations->Out(); |
| 5713 | Register out = out_loc.AsRegister<Register>(); |
| 5714 | Register base_or_current_method_reg; |
| 5715 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 5716 | switch (load_kind) { |
| 5717 | // We need an extra register for PC-relative literals on R2. |
| 5718 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5719 | case HLoadString::LoadKind::kBootImageAddress: |
| 5720 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5721 | case HLoadString::LoadKind::kBssEntry: |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5722 | base_or_current_method_reg = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>(); |
| 5723 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5724 | default: |
| 5725 | base_or_current_method_reg = ZERO; |
| 5726 | break; |
| 5727 | } |
| 5728 | |
| 5729 | switch (load_kind) { |
| 5730 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5731 | DCHECK(!kEmitCompilerReadBarrier); |
| 5732 | __ LoadLiteral(out, |
| 5733 | base_or_current_method_reg, |
| 5734 | codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 5735 | load->GetStringIndex())); |
| 5736 | return; // No dex cache slow path. |
| 5737 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 5738 | DCHECK(!kEmitCompilerReadBarrier); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5739 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5740 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
| 5741 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5742 | codegen_->EmitPcRelativeAddressPlaceholder(info, out, base_or_current_method_reg); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5743 | return; // No dex cache slow path. |
| 5744 | } |
| 5745 | case HLoadString::LoadKind::kBootImageAddress: { |
| 5746 | DCHECK(!kEmitCompilerReadBarrier); |
| 5747 | DCHECK_NE(load->GetAddress(), 0u); |
| 5748 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 5749 | __ LoadLiteral(out, |
| 5750 | base_or_current_method_reg, |
| 5751 | codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5752 | return; // No dex cache slow path. |
| 5753 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5754 | case HLoadString::LoadKind::kBssEntry: { |
| 5755 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 5756 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
| 5757 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
| 5758 | codegen_->EmitPcRelativeAddressPlaceholder(info, out, base_or_current_method_reg); |
| 5759 | __ LoadFromOffset(kLoadWord, out, out, 0); |
| 5760 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS(load); |
| 5761 | codegen_->AddSlowPath(slow_path); |
| 5762 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 5763 | __ Bind(slow_path->GetExitLabel()); |
| 5764 | return; |
| 5765 | } |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5766 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5767 | break; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5768 | } |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5769 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5770 | // 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] | 5771 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 5772 | InvokeRuntimeCallingConvention calling_convention; |
| 5773 | __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex()); |
| 5774 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5775 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5776 | } |
| 5777 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5778 | void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) { |
| 5779 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5780 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5781 | } |
| 5782 | |
| 5783 | void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 5784 | // Will be generated at use site. |
| 5785 | } |
| 5786 | |
| 5787 | void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5788 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5789 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5790 | InvokeRuntimeCallingConvention calling_convention; |
| 5791 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5792 | } |
| 5793 | |
| 5794 | void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5795 | if (instruction->IsEnter()) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 5796 | codegen_->InvokeRuntime(kQuickLockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5797 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5798 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 5799 | codegen_->InvokeRuntime(kQuickUnlockObject, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5800 | } |
| 5801 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5802 | } |
| 5803 | |
| 5804 | void LocationsBuilderMIPS::VisitMul(HMul* mul) { |
| 5805 | LocationSummary* locations = |
| 5806 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 5807 | switch (mul->GetResultType()) { |
| 5808 | case Primitive::kPrimInt: |
| 5809 | case Primitive::kPrimLong: |
| 5810 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5811 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5812 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5813 | break; |
| 5814 | |
| 5815 | case Primitive::kPrimFloat: |
| 5816 | case Primitive::kPrimDouble: |
| 5817 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5818 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5819 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5820 | break; |
| 5821 | |
| 5822 | default: |
| 5823 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5824 | } |
| 5825 | } |
| 5826 | |
| 5827 | void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) { |
| 5828 | Primitive::Type type = instruction->GetType(); |
| 5829 | LocationSummary* locations = instruction->GetLocations(); |
| 5830 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 5831 | |
| 5832 | switch (type) { |
| 5833 | case Primitive::kPrimInt: { |
| 5834 | Register dst = locations->Out().AsRegister<Register>(); |
| 5835 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 5836 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 5837 | |
| 5838 | if (isR6) { |
| 5839 | __ MulR6(dst, lhs, rhs); |
| 5840 | } else { |
| 5841 | __ MulR2(dst, lhs, rhs); |
| 5842 | } |
| 5843 | break; |
| 5844 | } |
| 5845 | case Primitive::kPrimLong: { |
| 5846 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 5847 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 5848 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 5849 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 5850 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 5851 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 5852 | |
| 5853 | // Extra checks to protect caused by the existance of A1_A2. |
| 5854 | // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo: |
| 5855 | // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2). |
| 5856 | DCHECK_NE(dst_high, lhs_low); |
| 5857 | DCHECK_NE(dst_high, rhs_low); |
| 5858 | |
| 5859 | // A_B * C_D |
| 5860 | // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ] |
| 5861 | // dst_lo: [ low(B*D) ] |
| 5862 | // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result. |
| 5863 | |
| 5864 | if (isR6) { |
| 5865 | __ MulR6(TMP, lhs_high, rhs_low); |
| 5866 | __ MulR6(dst_high, lhs_low, rhs_high); |
| 5867 | __ Addu(dst_high, dst_high, TMP); |
| 5868 | __ MuhuR6(TMP, lhs_low, rhs_low); |
| 5869 | __ Addu(dst_high, dst_high, TMP); |
| 5870 | __ MulR6(dst_low, lhs_low, rhs_low); |
| 5871 | } else { |
| 5872 | __ MulR2(TMP, lhs_high, rhs_low); |
| 5873 | __ MulR2(dst_high, lhs_low, rhs_high); |
| 5874 | __ Addu(dst_high, dst_high, TMP); |
| 5875 | __ MultuR2(lhs_low, rhs_low); |
| 5876 | __ Mfhi(TMP); |
| 5877 | __ Addu(dst_high, dst_high, TMP); |
| 5878 | __ Mflo(dst_low); |
| 5879 | } |
| 5880 | break; |
| 5881 | } |
| 5882 | case Primitive::kPrimFloat: |
| 5883 | case Primitive::kPrimDouble: { |
| 5884 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 5885 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5886 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 5887 | if (type == Primitive::kPrimFloat) { |
| 5888 | __ MulS(dst, lhs, rhs); |
| 5889 | } else { |
| 5890 | __ MulD(dst, lhs, rhs); |
| 5891 | } |
| 5892 | break; |
| 5893 | } |
| 5894 | default: |
| 5895 | LOG(FATAL) << "Unexpected mul type " << type; |
| 5896 | } |
| 5897 | } |
| 5898 | |
| 5899 | void LocationsBuilderMIPS::VisitNeg(HNeg* neg) { |
| 5900 | LocationSummary* locations = |
| 5901 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 5902 | switch (neg->GetResultType()) { |
| 5903 | case Primitive::kPrimInt: |
| 5904 | case Primitive::kPrimLong: |
| 5905 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5906 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5907 | break; |
| 5908 | |
| 5909 | case Primitive::kPrimFloat: |
| 5910 | case Primitive::kPrimDouble: |
| 5911 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5912 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5913 | break; |
| 5914 | |
| 5915 | default: |
| 5916 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5917 | } |
| 5918 | } |
| 5919 | |
| 5920 | void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) { |
| 5921 | Primitive::Type type = instruction->GetType(); |
| 5922 | LocationSummary* locations = instruction->GetLocations(); |
| 5923 | |
| 5924 | switch (type) { |
| 5925 | case Primitive::kPrimInt: { |
| 5926 | Register dst = locations->Out().AsRegister<Register>(); |
| 5927 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 5928 | __ Subu(dst, ZERO, src); |
| 5929 | break; |
| 5930 | } |
| 5931 | case Primitive::kPrimLong: { |
| 5932 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 5933 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 5934 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 5935 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 5936 | __ Subu(dst_low, ZERO, src_low); |
| 5937 | __ Sltu(TMP, ZERO, dst_low); |
| 5938 | __ Subu(dst_high, ZERO, src_high); |
| 5939 | __ Subu(dst_high, dst_high, TMP); |
| 5940 | break; |
| 5941 | } |
| 5942 | case Primitive::kPrimFloat: |
| 5943 | case Primitive::kPrimDouble: { |
| 5944 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 5945 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 5946 | if (type == Primitive::kPrimFloat) { |
| 5947 | __ NegS(dst, src); |
| 5948 | } else { |
| 5949 | __ NegD(dst, src); |
| 5950 | } |
| 5951 | break; |
| 5952 | } |
| 5953 | default: |
| 5954 | LOG(FATAL) << "Unexpected neg type " << type; |
| 5955 | } |
| 5956 | } |
| 5957 | |
| 5958 | void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) { |
| 5959 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5960 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5961 | InvokeRuntimeCallingConvention calling_convention; |
| 5962 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5963 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 5964 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 5965 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5966 | } |
| 5967 | |
| 5968 | void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) { |
| 5969 | InvokeRuntimeCallingConvention calling_convention; |
| 5970 | Register current_method_register = calling_convention.GetRegisterAt(2); |
| 5971 | __ Lw(current_method_register, SP, kCurrentMethodStackOffset); |
| 5972 | // Move an uint16_t value to a register. |
| 5973 | __ LoadConst32(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 5974 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5975 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, |
| 5976 | void*, uint32_t, int32_t, ArtMethod*>(); |
| 5977 | } |
| 5978 | |
| 5979 | void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) { |
| 5980 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5981 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5982 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5983 | if (instruction->IsStringAlloc()) { |
| 5984 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 5985 | } else { |
| 5986 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5987 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5988 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5989 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 5990 | } |
| 5991 | |
| 5992 | void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5993 | if (instruction->IsStringAlloc()) { |
| 5994 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5995 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5996 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5997 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 5998 | __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value()); |
| 5999 | __ Jalr(T9); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 6000 | __ NopIfNoReordering(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6001 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 6002 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6003 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 6004 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 6005 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6006 | } |
| 6007 | |
| 6008 | void LocationsBuilderMIPS::VisitNot(HNot* instruction) { |
| 6009 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 6010 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6011 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6012 | } |
| 6013 | |
| 6014 | void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) { |
| 6015 | Primitive::Type type = instruction->GetType(); |
| 6016 | LocationSummary* locations = instruction->GetLocations(); |
| 6017 | |
| 6018 | switch (type) { |
| 6019 | case Primitive::kPrimInt: { |
| 6020 | Register dst = locations->Out().AsRegister<Register>(); |
| 6021 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 6022 | __ Nor(dst, src, ZERO); |
| 6023 | break; |
| 6024 | } |
| 6025 | |
| 6026 | case Primitive::kPrimLong: { |
| 6027 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 6028 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 6029 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 6030 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 6031 | __ Nor(dst_high, src_high, ZERO); |
| 6032 | __ Nor(dst_low, src_low, ZERO); |
| 6033 | break; |
| 6034 | } |
| 6035 | |
| 6036 | default: |
| 6037 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 6038 | } |
| 6039 | } |
| 6040 | |
| 6041 | void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
| 6042 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 6043 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6044 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6045 | } |
| 6046 | |
| 6047 | void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
| 6048 | LocationSummary* locations = instruction->GetLocations(); |
| 6049 | __ Xori(locations->Out().AsRegister<Register>(), |
| 6050 | locations->InAt(0).AsRegister<Register>(), |
| 6051 | 1); |
| 6052 | } |
| 6053 | |
| 6054 | void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6055 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 6056 | locations->SetInAt(0, Location::RequiresRegister()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6057 | } |
| 6058 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6059 | void CodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 6060 | if (CanMoveNullCheckToUser(instruction)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6061 | return; |
| 6062 | } |
| 6063 | Location obj = instruction->GetLocations()->InAt(0); |
| 6064 | |
| 6065 | __ Lw(ZERO, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6066 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6067 | } |
| 6068 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6069 | void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6070 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6071 | AddSlowPath(slow_path); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6072 | |
| 6073 | Location obj = instruction->GetLocations()->InAt(0); |
| 6074 | |
| 6075 | __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 6076 | } |
| 6077 | |
| 6078 | void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6079 | codegen_->GenerateNullCheck(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6080 | } |
| 6081 | |
| 6082 | void LocationsBuilderMIPS::VisitOr(HOr* instruction) { |
| 6083 | HandleBinaryOp(instruction); |
| 6084 | } |
| 6085 | |
| 6086 | void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) { |
| 6087 | HandleBinaryOp(instruction); |
| 6088 | } |
| 6089 | |
| 6090 | void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 6091 | LOG(FATAL) << "Unreachable"; |
| 6092 | } |
| 6093 | |
| 6094 | void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) { |
| 6095 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6096 | } |
| 6097 | |
| 6098 | void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) { |
| 6099 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 6100 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 6101 | if (location.IsStackSlot()) { |
| 6102 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 6103 | } else if (location.IsDoubleStackSlot()) { |
| 6104 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 6105 | } |
| 6106 | locations->SetOut(location); |
| 6107 | } |
| 6108 | |
| 6109 | void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction |
| 6110 | ATTRIBUTE_UNUSED) { |
| 6111 | // Nothing to do, the parameter is already at its location. |
| 6112 | } |
| 6113 | |
| 6114 | void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 6115 | LocationSummary* locations = |
| 6116 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6117 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 6118 | } |
| 6119 | |
| 6120 | void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction |
| 6121 | ATTRIBUTE_UNUSED) { |
| 6122 | // Nothing to do, the method is already at its location. |
| 6123 | } |
| 6124 | |
| 6125 | void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) { |
| 6126 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6127 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6128 | locations->SetInAt(i, Location::Any()); |
| 6129 | } |
| 6130 | locations->SetOut(Location::Any()); |
| 6131 | } |
| 6132 | |
| 6133 | void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 6134 | LOG(FATAL) << "Unreachable"; |
| 6135 | } |
| 6136 | |
| 6137 | void LocationsBuilderMIPS::VisitRem(HRem* rem) { |
| 6138 | Primitive::Type type = rem->GetResultType(); |
| 6139 | LocationSummary::CallKind call_kind = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6140 | (type == Primitive::kPrimInt) ? LocationSummary::kNoCall : LocationSummary::kCallOnMainOnly; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6141 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 6142 | |
| 6143 | switch (type) { |
| 6144 | case Primitive::kPrimInt: |
| 6145 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 6146 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6147 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6148 | break; |
| 6149 | |
| 6150 | case Primitive::kPrimLong: { |
| 6151 | InvokeRuntimeCallingConvention calling_convention; |
| 6152 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 6153 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 6154 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 6155 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 6156 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 6157 | break; |
| 6158 | } |
| 6159 | |
| 6160 | case Primitive::kPrimFloat: |
| 6161 | case Primitive::kPrimDouble: { |
| 6162 | InvokeRuntimeCallingConvention calling_convention; |
| 6163 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 6164 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 6165 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 6166 | break; |
| 6167 | } |
| 6168 | |
| 6169 | default: |
| 6170 | LOG(FATAL) << "Unexpected rem type " << type; |
| 6171 | } |
| 6172 | } |
| 6173 | |
| 6174 | void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) { |
| 6175 | Primitive::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6176 | |
| 6177 | switch (type) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 6178 | case Primitive::kPrimInt: |
| 6179 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6180 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6181 | case Primitive::kPrimLong: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6182 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6183 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 6184 | break; |
| 6185 | } |
| 6186 | case Primitive::kPrimFloat: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6187 | codegen_->InvokeRuntime(kQuickFmodf, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6188 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6189 | break; |
| 6190 | } |
| 6191 | case Primitive::kPrimDouble: { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6192 | codegen_->InvokeRuntime(kQuickFmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6193 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6194 | break; |
| 6195 | } |
| 6196 | default: |
| 6197 | LOG(FATAL) << "Unexpected rem type " << type; |
| 6198 | } |
| 6199 | } |
| 6200 | |
| 6201 | void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 6202 | memory_barrier->SetLocations(nullptr); |
| 6203 | } |
| 6204 | |
| 6205 | void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 6206 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 6207 | } |
| 6208 | |
| 6209 | void LocationsBuilderMIPS::VisitReturn(HReturn* ret) { |
| 6210 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret); |
| 6211 | Primitive::Type return_type = ret->InputAt(0)->GetType(); |
| 6212 | locations->SetInAt(0, MipsReturnLocation(return_type)); |
| 6213 | } |
| 6214 | |
| 6215 | void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 6216 | codegen_->GenerateFrameExit(); |
| 6217 | } |
| 6218 | |
| 6219 | void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) { |
| 6220 | ret->SetLocations(nullptr); |
| 6221 | } |
| 6222 | |
| 6223 | void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 6224 | codegen_->GenerateFrameExit(); |
| 6225 | } |
| 6226 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 6227 | void LocationsBuilderMIPS::VisitRor(HRor* ror) { |
| 6228 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6229 | } |
| 6230 | |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 6231 | void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) { |
| 6232 | HandleShift(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6233 | } |
| 6234 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6235 | void LocationsBuilderMIPS::VisitShl(HShl* shl) { |
| 6236 | HandleShift(shl); |
| 6237 | } |
| 6238 | |
| 6239 | void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) { |
| 6240 | HandleShift(shl); |
| 6241 | } |
| 6242 | |
| 6243 | void LocationsBuilderMIPS::VisitShr(HShr* shr) { |
| 6244 | HandleShift(shr); |
| 6245 | } |
| 6246 | |
| 6247 | void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) { |
| 6248 | HandleShift(shr); |
| 6249 | } |
| 6250 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6251 | void LocationsBuilderMIPS::VisitSub(HSub* instruction) { |
| 6252 | HandleBinaryOp(instruction); |
| 6253 | } |
| 6254 | |
| 6255 | void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) { |
| 6256 | HandleBinaryOp(instruction); |
| 6257 | } |
| 6258 | |
| 6259 | void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6260 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6261 | } |
| 6262 | |
| 6263 | void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6264 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 6265 | } |
| 6266 | |
| 6267 | void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6268 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6269 | } |
| 6270 | |
| 6271 | void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6272 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 6273 | } |
| 6274 | |
| 6275 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet( |
| 6276 | HUnresolvedInstanceFieldGet* instruction) { |
| 6277 | FieldAccessCallingConventionMIPS calling_convention; |
| 6278 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 6279 | instruction->GetFieldType(), |
| 6280 | calling_convention); |
| 6281 | } |
| 6282 | |
| 6283 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet( |
| 6284 | HUnresolvedInstanceFieldGet* instruction) { |
| 6285 | FieldAccessCallingConventionMIPS calling_convention; |
| 6286 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6287 | instruction->GetFieldType(), |
| 6288 | instruction->GetFieldIndex(), |
| 6289 | instruction->GetDexPc(), |
| 6290 | calling_convention); |
| 6291 | } |
| 6292 | |
| 6293 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet( |
| 6294 | HUnresolvedInstanceFieldSet* instruction) { |
| 6295 | FieldAccessCallingConventionMIPS calling_convention; |
| 6296 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 6297 | instruction->GetFieldType(), |
| 6298 | calling_convention); |
| 6299 | } |
| 6300 | |
| 6301 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet( |
| 6302 | HUnresolvedInstanceFieldSet* instruction) { |
| 6303 | FieldAccessCallingConventionMIPS calling_convention; |
| 6304 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6305 | instruction->GetFieldType(), |
| 6306 | instruction->GetFieldIndex(), |
| 6307 | instruction->GetDexPc(), |
| 6308 | calling_convention); |
| 6309 | } |
| 6310 | |
| 6311 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet( |
| 6312 | HUnresolvedStaticFieldGet* instruction) { |
| 6313 | FieldAccessCallingConventionMIPS calling_convention; |
| 6314 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 6315 | instruction->GetFieldType(), |
| 6316 | calling_convention); |
| 6317 | } |
| 6318 | |
| 6319 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet( |
| 6320 | HUnresolvedStaticFieldGet* instruction) { |
| 6321 | FieldAccessCallingConventionMIPS calling_convention; |
| 6322 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6323 | instruction->GetFieldType(), |
| 6324 | instruction->GetFieldIndex(), |
| 6325 | instruction->GetDexPc(), |
| 6326 | calling_convention); |
| 6327 | } |
| 6328 | |
| 6329 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet( |
| 6330 | HUnresolvedStaticFieldSet* instruction) { |
| 6331 | FieldAccessCallingConventionMIPS calling_convention; |
| 6332 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 6333 | instruction->GetFieldType(), |
| 6334 | calling_convention); |
| 6335 | } |
| 6336 | |
| 6337 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet( |
| 6338 | HUnresolvedStaticFieldSet* instruction) { |
| 6339 | FieldAccessCallingConventionMIPS calling_convention; |
| 6340 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6341 | instruction->GetFieldType(), |
| 6342 | instruction->GetFieldIndex(), |
| 6343 | instruction->GetDexPc(), |
| 6344 | calling_convention); |
| 6345 | } |
| 6346 | |
| 6347 | void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6348 | LocationSummary* locations = |
| 6349 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6350 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6351 | } |
| 6352 | |
| 6353 | void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 6354 | HBasicBlock* block = instruction->GetBlock(); |
| 6355 | if (block->GetLoopInformation() != nullptr) { |
| 6356 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6357 | // The back edge will generate the suspend check. |
| 6358 | return; |
| 6359 | } |
| 6360 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6361 | // The goto will generate the suspend check. |
| 6362 | return; |
| 6363 | } |
| 6364 | GenerateSuspendCheck(instruction, nullptr); |
| 6365 | } |
| 6366 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6367 | void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) { |
| 6368 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6369 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6370 | InvokeRuntimeCallingConvention calling_convention; |
| 6371 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6372 | } |
| 6373 | |
| 6374 | void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6375 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6376 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 6377 | } |
| 6378 | |
| 6379 | void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
| 6380 | Primitive::Type input_type = conversion->GetInputType(); |
| 6381 | Primitive::Type result_type = conversion->GetResultType(); |
| 6382 | DCHECK_NE(input_type, result_type); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6383 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6384 | |
| 6385 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 6386 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 6387 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 6388 | } |
| 6389 | |
| 6390 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6391 | if (!isR6 && |
| 6392 | ((Primitive::IsFloatingPointType(result_type) && input_type == Primitive::kPrimLong) || |
| 6393 | (result_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(input_type)))) { |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6394 | call_kind = LocationSummary::kCallOnMainOnly; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6395 | } |
| 6396 | |
| 6397 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 6398 | |
| 6399 | if (call_kind == LocationSummary::kNoCall) { |
| 6400 | if (Primitive::IsFloatingPointType(input_type)) { |
| 6401 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6402 | } else { |
| 6403 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6404 | } |
| 6405 | |
| 6406 | if (Primitive::IsFloatingPointType(result_type)) { |
| 6407 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6408 | } else { |
| 6409 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6410 | } |
| 6411 | } else { |
| 6412 | InvokeRuntimeCallingConvention calling_convention; |
| 6413 | |
| 6414 | if (Primitive::IsFloatingPointType(input_type)) { |
| 6415 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 6416 | } else { |
| 6417 | DCHECK_EQ(input_type, Primitive::kPrimLong); |
| 6418 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 6419 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 6420 | } |
| 6421 | |
| 6422 | locations->SetOut(calling_convention.GetReturnLocation(result_type)); |
| 6423 | } |
| 6424 | } |
| 6425 | |
| 6426 | void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
| 6427 | LocationSummary* locations = conversion->GetLocations(); |
| 6428 | Primitive::Type result_type = conversion->GetResultType(); |
| 6429 | Primitive::Type input_type = conversion->GetInputType(); |
| 6430 | bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6431 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6432 | |
| 6433 | DCHECK_NE(input_type, result_type); |
| 6434 | |
| 6435 | if (result_type == Primitive::kPrimLong && Primitive::IsIntegralType(input_type)) { |
| 6436 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 6437 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 6438 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 6439 | |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 6440 | if (dst_low != src) { |
| 6441 | __ Move(dst_low, src); |
| 6442 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6443 | __ Sra(dst_high, src, 31); |
| 6444 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
| 6445 | Register dst = locations->Out().AsRegister<Register>(); |
| 6446 | Register src = (input_type == Primitive::kPrimLong) |
| 6447 | ? locations->InAt(0).AsRegisterPairLow<Register>() |
| 6448 | : locations->InAt(0).AsRegister<Register>(); |
| 6449 | |
| 6450 | switch (result_type) { |
| 6451 | case Primitive::kPrimChar: |
| 6452 | __ Andi(dst, src, 0xFFFF); |
| 6453 | break; |
| 6454 | case Primitive::kPrimByte: |
| 6455 | if (has_sign_extension) { |
| 6456 | __ Seb(dst, src); |
| 6457 | } else { |
| 6458 | __ Sll(dst, src, 24); |
| 6459 | __ Sra(dst, dst, 24); |
| 6460 | } |
| 6461 | break; |
| 6462 | case Primitive::kPrimShort: |
| 6463 | if (has_sign_extension) { |
| 6464 | __ Seh(dst, src); |
| 6465 | } else { |
| 6466 | __ Sll(dst, src, 16); |
| 6467 | __ Sra(dst, dst, 16); |
| 6468 | } |
| 6469 | break; |
| 6470 | case Primitive::kPrimInt: |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 6471 | if (dst != src) { |
| 6472 | __ Move(dst, src); |
| 6473 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6474 | break; |
| 6475 | |
| 6476 | default: |
| 6477 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 6478 | << " to " << result_type; |
| 6479 | } |
| 6480 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6481 | if (input_type == Primitive::kPrimLong) { |
| 6482 | if (isR6) { |
| 6483 | // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 6484 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 6485 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 6486 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 6487 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 6488 | __ Mtc1(src_low, FTMP); |
| 6489 | __ Mthc1(src_high, FTMP); |
| 6490 | if (result_type == Primitive::kPrimFloat) { |
| 6491 | __ Cvtsl(dst, FTMP); |
| 6492 | } else { |
| 6493 | __ Cvtdl(dst, FTMP); |
| 6494 | } |
| 6495 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6496 | QuickEntrypointEnum entrypoint = (result_type == Primitive::kPrimFloat) ? kQuickL2f |
| 6497 | : kQuickL2d; |
| 6498 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6499 | if (result_type == Primitive::kPrimFloat) { |
| 6500 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 6501 | } else { |
| 6502 | CheckEntrypointTypes<kQuickL2d, double, int64_t>(); |
| 6503 | } |
| 6504 | } |
| 6505 | } else { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6506 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 6507 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 6508 | __ Mtc1(src, FTMP); |
| 6509 | if (result_type == Primitive::kPrimFloat) { |
| 6510 | __ Cvtsw(dst, FTMP); |
| 6511 | } else { |
| 6512 | __ Cvtdw(dst, FTMP); |
| 6513 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6514 | } |
| 6515 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
| 6516 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6517 | if (result_type == Primitive::kPrimLong) { |
| 6518 | if (isR6) { |
| 6519 | // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary |
| 6520 | // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction. |
| 6521 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 6522 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 6523 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 6524 | MipsLabel truncate; |
| 6525 | MipsLabel done; |
| 6526 | |
| 6527 | // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive |
| 6528 | // value when the input is either a NaN or is outside of the range of the output type |
| 6529 | // after the truncation. IOW, the three special cases (NaN, too small, too big) produce |
| 6530 | // the same result. |
| 6531 | // |
| 6532 | // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum |
| 6533 | // value of the output type if the input is outside of the range after the truncation or |
| 6534 | // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct |
| 6535 | // results. This matches the desired float/double-to-int/long conversion exactly. |
| 6536 | // |
| 6537 | // So, NAN2008 affects handling of negative values and NaNs by the truncate instruction. |
| 6538 | // |
| 6539 | // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate |
| 6540 | // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6, |
| 6541 | // even though it must be NAN2008=1 on R6. |
| 6542 | // |
| 6543 | // The code takes care of the different behaviors by first comparing the input to the |
| 6544 | // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int). |
| 6545 | // If the input is greater than or equal to the minimum, it procedes to the truncate |
| 6546 | // instruction, which will handle such an input the same way irrespective of NAN2008. |
| 6547 | // Otherwise the input is compared to itself to determine whether it is a NaN or not |
| 6548 | // in order to return either zero or the minimum value. |
| 6549 | // |
| 6550 | // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the |
| 6551 | // truncate instruction for MIPS64R6. |
| 6552 | if (input_type == Primitive::kPrimFloat) { |
| 6553 | uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int64_t>::min()); |
| 6554 | __ LoadConst32(TMP, min_val); |
| 6555 | __ Mtc1(TMP, FTMP); |
| 6556 | __ CmpLeS(FTMP, FTMP, src); |
| 6557 | } else { |
| 6558 | uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int64_t>::min()); |
| 6559 | __ LoadConst32(TMP, High32Bits(min_val)); |
| 6560 | __ Mtc1(ZERO, FTMP); |
| 6561 | __ Mthc1(TMP, FTMP); |
| 6562 | __ CmpLeD(FTMP, FTMP, src); |
| 6563 | } |
| 6564 | |
| 6565 | __ Bc1nez(FTMP, &truncate); |
| 6566 | |
| 6567 | if (input_type == Primitive::kPrimFloat) { |
| 6568 | __ CmpEqS(FTMP, src, src); |
| 6569 | } else { |
| 6570 | __ CmpEqD(FTMP, src, src); |
| 6571 | } |
| 6572 | __ Move(dst_low, ZERO); |
| 6573 | __ LoadConst32(dst_high, std::numeric_limits<int32_t>::min()); |
| 6574 | __ Mfc1(TMP, FTMP); |
| 6575 | __ And(dst_high, dst_high, TMP); |
| 6576 | |
| 6577 | __ B(&done); |
| 6578 | |
| 6579 | __ Bind(&truncate); |
| 6580 | |
| 6581 | if (input_type == Primitive::kPrimFloat) { |
| 6582 | __ TruncLS(FTMP, src); |
| 6583 | } else { |
| 6584 | __ TruncLD(FTMP, src); |
| 6585 | } |
| 6586 | __ Mfc1(dst_low, FTMP); |
| 6587 | __ Mfhc1(dst_high, FTMP); |
| 6588 | |
| 6589 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6590 | } else { |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 6591 | QuickEntrypointEnum entrypoint = (input_type == Primitive::kPrimFloat) ? kQuickF2l |
| 6592 | : kQuickD2l; |
| 6593 | codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc()); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6594 | if (input_type == Primitive::kPrimFloat) { |
| 6595 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 6596 | } else { |
| 6597 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 6598 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6599 | } |
| 6600 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6601 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 6602 | Register dst = locations->Out().AsRegister<Register>(); |
| 6603 | MipsLabel truncate; |
| 6604 | MipsLabel done; |
| 6605 | |
| 6606 | // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate |
| 6607 | // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6, |
| 6608 | // even though it must be NAN2008=1 on R6. |
| 6609 | // |
| 6610 | // For details see the large comment above for the truncation of float/double to long on R6. |
| 6611 | // |
| 6612 | // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the |
| 6613 | // truncate instruction for MIPS64R6. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6614 | if (input_type == Primitive::kPrimFloat) { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6615 | uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min()); |
| 6616 | __ LoadConst32(TMP, min_val); |
| 6617 | __ Mtc1(TMP, FTMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6618 | } else { |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6619 | uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min()); |
| 6620 | __ LoadConst32(TMP, High32Bits(min_val)); |
| 6621 | __ Mtc1(ZERO, FTMP); |
Alexey Frunze | a871ef1 | 2016-06-27 15:20:11 -0700 | [diff] [blame] | 6622 | __ MoveToFpuHigh(TMP, FTMP); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6623 | } |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 6624 | |
| 6625 | if (isR6) { |
| 6626 | if (input_type == Primitive::kPrimFloat) { |
| 6627 | __ CmpLeS(FTMP, FTMP, src); |
| 6628 | } else { |
| 6629 | __ CmpLeD(FTMP, FTMP, src); |
| 6630 | } |
| 6631 | __ Bc1nez(FTMP, &truncate); |
| 6632 | |
| 6633 | if (input_type == Primitive::kPrimFloat) { |
| 6634 | __ CmpEqS(FTMP, src, src); |
| 6635 | } else { |
| 6636 | __ CmpEqD(FTMP, src, src); |
| 6637 | } |
| 6638 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); |
| 6639 | __ Mfc1(TMP, FTMP); |
| 6640 | __ And(dst, dst, TMP); |
| 6641 | } else { |
| 6642 | if (input_type == Primitive::kPrimFloat) { |
| 6643 | __ ColeS(0, FTMP, src); |
| 6644 | } else { |
| 6645 | __ ColeD(0, FTMP, src); |
| 6646 | } |
| 6647 | __ Bc1t(0, &truncate); |
| 6648 | |
| 6649 | if (input_type == Primitive::kPrimFloat) { |
| 6650 | __ CeqS(0, src, src); |
| 6651 | } else { |
| 6652 | __ CeqD(0, src, src); |
| 6653 | } |
| 6654 | __ LoadConst32(dst, std::numeric_limits<int32_t>::min()); |
| 6655 | __ Movf(dst, ZERO, 0); |
| 6656 | } |
| 6657 | |
| 6658 | __ B(&done); |
| 6659 | |
| 6660 | __ Bind(&truncate); |
| 6661 | |
| 6662 | if (input_type == Primitive::kPrimFloat) { |
| 6663 | __ TruncWS(FTMP, src); |
| 6664 | } else { |
| 6665 | __ TruncWD(FTMP, src); |
| 6666 | } |
| 6667 | __ Mfc1(dst, FTMP); |
| 6668 | |
| 6669 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6670 | } |
| 6671 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 6672 | Primitive::IsFloatingPointType(input_type)) { |
| 6673 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 6674 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 6675 | if (result_type == Primitive::kPrimFloat) { |
| 6676 | __ Cvtsd(dst, src); |
| 6677 | } else { |
| 6678 | __ Cvtds(dst, src); |
| 6679 | } |
| 6680 | } else { |
| 6681 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 6682 | << " to " << result_type; |
| 6683 | } |
| 6684 | } |
| 6685 | |
| 6686 | void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) { |
| 6687 | HandleShift(ushr); |
| 6688 | } |
| 6689 | |
| 6690 | void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) { |
| 6691 | HandleShift(ushr); |
| 6692 | } |
| 6693 | |
| 6694 | void LocationsBuilderMIPS::VisitXor(HXor* instruction) { |
| 6695 | HandleBinaryOp(instruction); |
| 6696 | } |
| 6697 | |
| 6698 | void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) { |
| 6699 | HandleBinaryOp(instruction); |
| 6700 | } |
| 6701 | |
| 6702 | void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 6703 | // Nothing to do, this should be removed during prepare for register allocator. |
| 6704 | LOG(FATAL) << "Unreachable"; |
| 6705 | } |
| 6706 | |
| 6707 | void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 6708 | // Nothing to do, this should be removed during prepare for register allocator. |
| 6709 | LOG(FATAL) << "Unreachable"; |
| 6710 | } |
| 6711 | |
| 6712 | void LocationsBuilderMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6713 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6714 | } |
| 6715 | |
| 6716 | void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6717 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6718 | } |
| 6719 | |
| 6720 | void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6721 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6722 | } |
| 6723 | |
| 6724 | void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6725 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6726 | } |
| 6727 | |
| 6728 | void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6729 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6730 | } |
| 6731 | |
| 6732 | void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6733 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6734 | } |
| 6735 | |
| 6736 | void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6737 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6738 | } |
| 6739 | |
| 6740 | void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6741 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6742 | } |
| 6743 | |
| 6744 | void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6745 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6746 | } |
| 6747 | |
| 6748 | void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6749 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6750 | } |
| 6751 | |
| 6752 | void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6753 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6754 | } |
| 6755 | |
| 6756 | void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6757 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6758 | } |
| 6759 | |
| 6760 | void LocationsBuilderMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6761 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6762 | } |
| 6763 | |
| 6764 | void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6765 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6766 | } |
| 6767 | |
| 6768 | void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6769 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6770 | } |
| 6771 | |
| 6772 | void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6773 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6774 | } |
| 6775 | |
| 6776 | void LocationsBuilderMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6777 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6778 | } |
| 6779 | |
| 6780 | void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6781 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6782 | } |
| 6783 | |
| 6784 | void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6785 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6786 | } |
| 6787 | |
| 6788 | void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6789 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6790 | } |
| 6791 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6792 | void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6793 | LocationSummary* locations = |
| 6794 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6795 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6796 | } |
| 6797 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 6798 | void InstructionCodeGeneratorMIPS::GenPackedSwitchWithCompares(Register value_reg, |
| 6799 | int32_t lower_bound, |
| 6800 | uint32_t num_entries, |
| 6801 | HBasicBlock* switch_block, |
| 6802 | HBasicBlock* default_block) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6803 | // Create a set of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6804 | Register temp_reg = TMP; |
| 6805 | __ Addiu32(temp_reg, value_reg, -lower_bound); |
| 6806 | // Jump to default if index is negative |
| 6807 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 6808 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 6809 | __ Bltz(temp_reg, codegen_->GetLabelOf(default_block)); |
| 6810 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 6811 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6812 | // Jump to successors[0] if value == lower_bound. |
| 6813 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 6814 | int32_t last_index = 0; |
| 6815 | for (; num_entries - last_index > 2; last_index += 2) { |
| 6816 | __ Addiu(temp_reg, temp_reg, -2); |
| 6817 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 6818 | __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 6819 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 6820 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 6821 | } |
| 6822 | if (num_entries - last_index == 2) { |
| 6823 | // The last missing case_value. |
| 6824 | __ Addiu(temp_reg, temp_reg, -1); |
| 6825 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6826 | } |
| 6827 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6828 | // And the default for any other value. |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 6829 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6830 | __ B(codegen_->GetLabelOf(default_block)); |
| 6831 | } |
| 6832 | } |
| 6833 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 6834 | void InstructionCodeGeneratorMIPS::GenTableBasedPackedSwitch(Register value_reg, |
| 6835 | Register constant_area, |
| 6836 | int32_t lower_bound, |
| 6837 | uint32_t num_entries, |
| 6838 | HBasicBlock* switch_block, |
| 6839 | HBasicBlock* default_block) { |
| 6840 | // Create a jump table. |
| 6841 | std::vector<MipsLabel*> labels(num_entries); |
| 6842 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 6843 | for (uint32_t i = 0; i < num_entries; i++) { |
| 6844 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 6845 | } |
| 6846 | JumpTable* table = __ CreateJumpTable(std::move(labels)); |
| 6847 | |
| 6848 | // Is the value in range? |
| 6849 | __ Addiu32(TMP, value_reg, -lower_bound); |
| 6850 | if (IsInt<16>(static_cast<int32_t>(num_entries))) { |
| 6851 | __ Sltiu(AT, TMP, num_entries); |
| 6852 | __ Beqz(AT, codegen_->GetLabelOf(default_block)); |
| 6853 | } else { |
| 6854 | __ LoadConst32(AT, num_entries); |
| 6855 | __ Bgeu(TMP, AT, codegen_->GetLabelOf(default_block)); |
| 6856 | } |
| 6857 | |
| 6858 | // We are in the range of the table. |
| 6859 | // Load the target address from the jump table, indexing by the value. |
| 6860 | __ LoadLabelAddress(AT, constant_area, table->GetLabel()); |
| 6861 | __ Sll(TMP, TMP, 2); |
| 6862 | __ Addu(TMP, TMP, AT); |
| 6863 | __ Lw(TMP, TMP, 0); |
| 6864 | // Compute the absolute target address by adding the table start address |
| 6865 | // (the table contains offsets to targets relative to its start). |
| 6866 | __ Addu(TMP, TMP, AT); |
| 6867 | // And jump. |
| 6868 | __ Jr(TMP); |
| 6869 | __ NopIfNoReordering(); |
| 6870 | } |
| 6871 | |
| 6872 | void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6873 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 6874 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 6875 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6876 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6877 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 6878 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6879 | |
| 6880 | if (codegen_->GetInstructionSetFeatures().IsR6() && |
| 6881 | num_entries > kPackedSwitchJumpTableThreshold) { |
| 6882 | // R6 uses PC-relative addressing to access the jump table. |
| 6883 | // R2, OTOH, requires an HMipsComputeBaseMethodAddress input to access |
| 6884 | // the jump table and it is implemented by changing HPackedSwitch to |
| 6885 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress. |
| 6886 | // See VisitMipsPackedSwitch() for the table-based implementation on R2. |
| 6887 | GenTableBasedPackedSwitch(value_reg, |
| 6888 | ZERO, |
| 6889 | lower_bound, |
| 6890 | num_entries, |
| 6891 | switch_block, |
| 6892 | default_block); |
| 6893 | } else { |
| 6894 | GenPackedSwitchWithCompares(value_reg, |
| 6895 | lower_bound, |
| 6896 | num_entries, |
| 6897 | switch_block, |
| 6898 | default_block); |
| 6899 | } |
| 6900 | } |
| 6901 | |
| 6902 | void LocationsBuilderMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 6903 | LocationSummary* locations = |
| 6904 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6905 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6906 | // Constant area pointer (HMipsComputeBaseMethodAddress). |
| 6907 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6908 | } |
| 6909 | |
| 6910 | void InstructionCodeGeneratorMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) { |
| 6911 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 6912 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 6913 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6914 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6915 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 6916 | HBasicBlock* switch_block = switch_instr->GetBlock(); |
| 6917 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6918 | |
| 6919 | // This is an R2-only path. HPackedSwitch has been changed to |
| 6920 | // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress |
| 6921 | // required to address the jump table relative to PC. |
| 6922 | GenTableBasedPackedSwitch(value_reg, |
| 6923 | constant_area, |
| 6924 | lower_bound, |
| 6925 | num_entries, |
| 6926 | switch_block, |
| 6927 | default_block); |
| 6928 | } |
| 6929 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6930 | void LocationsBuilderMIPS::VisitMipsComputeBaseMethodAddress( |
| 6931 | HMipsComputeBaseMethodAddress* insn) { |
| 6932 | LocationSummary* locations = |
| 6933 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 6934 | locations->SetOut(Location::RequiresRegister()); |
| 6935 | } |
| 6936 | |
| 6937 | void InstructionCodeGeneratorMIPS::VisitMipsComputeBaseMethodAddress( |
| 6938 | HMipsComputeBaseMethodAddress* insn) { |
| 6939 | LocationSummary* locations = insn->GetLocations(); |
| 6940 | Register reg = locations->Out().AsRegister<Register>(); |
| 6941 | |
| 6942 | CHECK(!codegen_->GetInstructionSetFeatures().IsR6()); |
| 6943 | |
| 6944 | // Generate a dummy PC-relative call to obtain PC. |
| 6945 | __ Nal(); |
| 6946 | // Grab the return address off RA. |
| 6947 | __ Move(reg, RA); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6948 | // TODO: Can we share this code with that of VisitMipsDexCacheArraysBase()? |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6949 | |
| 6950 | // Remember this offset (the obtained PC value) for later use with constant area. |
| 6951 | __ BindPcRelBaseLabel(); |
| 6952 | } |
| 6953 | |
| 6954 | void LocationsBuilderMIPS::VisitMipsDexCacheArraysBase(HMipsDexCacheArraysBase* base) { |
| 6955 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 6956 | locations->SetOut(Location::RequiresRegister()); |
| 6957 | } |
| 6958 | |
| 6959 | void InstructionCodeGeneratorMIPS::VisitMipsDexCacheArraysBase(HMipsDexCacheArraysBase* base) { |
| 6960 | Register reg = base->GetLocations()->Out().AsRegister<Register>(); |
| 6961 | CodeGeneratorMIPS::PcRelativePatchInfo* info = |
| 6962 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6963 | // TODO: Reuse MipsComputeBaseMethodAddress on R2 instead of passing ZERO to force emitting NAL. |
| 6964 | codegen_->EmitPcRelativeAddressPlaceholder(info, reg, ZERO); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6965 | } |
| 6966 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 6967 | void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 6968 | // The trampoline uses the same calling convention as dex calling conventions, |
| 6969 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 6970 | // the method_idx. |
| 6971 | HandleInvoke(invoke); |
| 6972 | } |
| 6973 | |
| 6974 | void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 6975 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 6976 | } |
| 6977 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 6978 | void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 6979 | LocationSummary* locations = |
| 6980 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6981 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6982 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6983 | } |
| 6984 | |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 6985 | void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) { |
| 6986 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6987 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6988 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 6989 | instruction->GetIndex(), kMipsPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6990 | __ LoadFromOffset(kLoadWord, |
| 6991 | locations->Out().AsRegister<Register>(), |
| 6992 | locations->InAt(0).AsRegister<Register>(), |
| 6993 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 6994 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6995 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6996 | instruction->GetIndex(), kMipsPointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6997 | __ LoadFromOffset(kLoadWord, |
| 6998 | locations->Out().AsRegister<Register>(), |
| 6999 | locations->InAt(0).AsRegister<Register>(), |
| 7000 | mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value()); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7001 | __ LoadFromOffset(kLoadWord, |
| 7002 | locations->Out().AsRegister<Register>(), |
| 7003 | locations->Out().AsRegister<Register>(), |
| 7004 | method_offset); |
Roland Levillain | 2aba7cd | 2016-02-03 12:27:20 +0000 | [diff] [blame] | 7005 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7006 | } |
| 7007 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 7008 | #undef __ |
| 7009 | #undef QUICK_ENTRY_POINT |
| 7010 | |
| 7011 | } // namespace mips |
| 7012 | } // namespace art |