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" |
| 22 | #include "entrypoints/quick/quick_entrypoints.h" |
| 23 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
| 24 | #include "gc/accounting/card_table.h" |
| 25 | #include "intrinsics.h" |
| 26 | #include "mirror/array-inl.h" |
| 27 | #include "mirror/class-inl.h" |
| 28 | #include "offsets.h" |
| 29 | #include "thread.h" |
| 30 | #include "utils/assembler.h" |
| 31 | #include "utils/mips/assembler_mips.h" |
| 32 | #include "utils/stack_checks.h" |
| 33 | |
| 34 | namespace art { |
| 35 | namespace mips { |
| 36 | |
| 37 | static constexpr int kCurrentMethodStackOffset = 0; |
| 38 | static constexpr Register kMethodRegisterArgument = A0; |
| 39 | |
| 40 | // We need extra temporary/scratch registers (in addition to AT) in some cases. |
| 41 | static constexpr Register TMP = T8; |
| 42 | static constexpr FRegister FTMP = F8; |
| 43 | |
| 44 | // ART Thread Register. |
| 45 | static constexpr Register TR = S1; |
| 46 | |
| 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 | |
| 149 | #define __ down_cast<CodeGeneratorMIPS*>(codegen)->GetAssembler()-> |
| 150 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsWordSize, x).Int32Value() |
| 151 | |
| 152 | class BoundsCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 153 | public: |
| 154 | explicit BoundsCheckSlowPathMIPS(HBoundsCheck* instruction) : instruction_(instruction) {} |
| 155 | |
| 156 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 157 | LocationSummary* locations = instruction_->GetLocations(); |
| 158 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 159 | __ Bind(GetEntryLabel()); |
| 160 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 161 | // Live registers will be restored in the catch block if caught. |
| 162 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 163 | } |
| 164 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 165 | // move resolver. |
| 166 | InvokeRuntimeCallingConvention calling_convention; |
| 167 | codegen->EmitParallelMoves(locations->InAt(0), |
| 168 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 169 | Primitive::kPrimInt, |
| 170 | locations->InAt(1), |
| 171 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 172 | Primitive::kPrimInt); |
| 173 | mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 174 | instruction_, |
| 175 | instruction_->GetDexPc(), |
| 176 | this, |
| 177 | IsDirectEntrypoint(kQuickThrowArrayBounds)); |
| 178 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 179 | } |
| 180 | |
| 181 | bool IsFatal() const OVERRIDE { return true; } |
| 182 | |
| 183 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS"; } |
| 184 | |
| 185 | private: |
| 186 | HBoundsCheck* const instruction_; |
| 187 | |
| 188 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS); |
| 189 | }; |
| 190 | |
| 191 | class DivZeroCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 192 | public: |
| 193 | explicit DivZeroCheckSlowPathMIPS(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 194 | |
| 195 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 196 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 197 | __ Bind(GetEntryLabel()); |
| 198 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 199 | // Live registers will be restored in the catch block if caught. |
| 200 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 201 | } |
| 202 | mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 203 | instruction_, |
| 204 | instruction_->GetDexPc(), |
| 205 | this, |
| 206 | IsDirectEntrypoint(kQuickThrowDivZero)); |
| 207 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 208 | } |
| 209 | |
| 210 | bool IsFatal() const OVERRIDE { return true; } |
| 211 | |
| 212 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS"; } |
| 213 | |
| 214 | private: |
| 215 | HDivZeroCheck* const instruction_; |
| 216 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS); |
| 217 | }; |
| 218 | |
| 219 | class LoadClassSlowPathMIPS : public SlowPathCodeMIPS { |
| 220 | public: |
| 221 | LoadClassSlowPathMIPS(HLoadClass* cls, |
| 222 | HInstruction* at, |
| 223 | uint32_t dex_pc, |
| 224 | bool do_clinit) |
| 225 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 226 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 227 | } |
| 228 | |
| 229 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 230 | LocationSummary* locations = at_->GetLocations(); |
| 231 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 232 | |
| 233 | __ Bind(GetEntryLabel()); |
| 234 | SaveLiveRegisters(codegen, locations); |
| 235 | |
| 236 | InvokeRuntimeCallingConvention calling_convention; |
| 237 | __ LoadConst32(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex()); |
| 238 | |
| 239 | int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 240 | : QUICK_ENTRY_POINT(pInitializeType); |
| 241 | bool direct = do_clinit_ ? IsDirectEntrypoint(kQuickInitializeStaticStorage) |
| 242 | : IsDirectEntrypoint(kQuickInitializeType); |
| 243 | |
| 244 | mips_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this, direct); |
| 245 | if (do_clinit_) { |
| 246 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 247 | } else { |
| 248 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 249 | } |
| 250 | |
| 251 | // Move the class to the desired location. |
| 252 | Location out = locations->Out(); |
| 253 | if (out.IsValid()) { |
| 254 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 255 | Primitive::Type type = at_->GetType(); |
| 256 | mips_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
| 257 | } |
| 258 | |
| 259 | RestoreLiveRegisters(codegen, locations); |
| 260 | __ B(GetExitLabel()); |
| 261 | } |
| 262 | |
| 263 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS"; } |
| 264 | |
| 265 | private: |
| 266 | // The class this slow path will load. |
| 267 | HLoadClass* const cls_; |
| 268 | |
| 269 | // The instruction where this slow path is happening. |
| 270 | // (Might be the load class or an initialization check). |
| 271 | HInstruction* const at_; |
| 272 | |
| 273 | // The dex PC of `at_`. |
| 274 | const uint32_t dex_pc_; |
| 275 | |
| 276 | // Whether to initialize the class. |
| 277 | const bool do_clinit_; |
| 278 | |
| 279 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS); |
| 280 | }; |
| 281 | |
| 282 | class LoadStringSlowPathMIPS : public SlowPathCodeMIPS { |
| 283 | public: |
| 284 | explicit LoadStringSlowPathMIPS(HLoadString* instruction) : instruction_(instruction) {} |
| 285 | |
| 286 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 287 | LocationSummary* locations = instruction_->GetLocations(); |
| 288 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 289 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 290 | |
| 291 | __ Bind(GetEntryLabel()); |
| 292 | SaveLiveRegisters(codegen, locations); |
| 293 | |
| 294 | InvokeRuntimeCallingConvention calling_convention; |
| 295 | __ LoadConst32(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex()); |
| 296 | mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 297 | instruction_, |
| 298 | instruction_->GetDexPc(), |
| 299 | this, |
| 300 | IsDirectEntrypoint(kQuickResolveString)); |
| 301 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 302 | Primitive::Type type = instruction_->GetType(); |
| 303 | mips_codegen->MoveLocation(locations->Out(), |
| 304 | calling_convention.GetReturnLocation(type), |
| 305 | type); |
| 306 | |
| 307 | RestoreLiveRegisters(codegen, locations); |
| 308 | __ B(GetExitLabel()); |
| 309 | } |
| 310 | |
| 311 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS"; } |
| 312 | |
| 313 | private: |
| 314 | HLoadString* const instruction_; |
| 315 | |
| 316 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS); |
| 317 | }; |
| 318 | |
| 319 | class NullCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 320 | public: |
| 321 | explicit NullCheckSlowPathMIPS(HNullCheck* instr) : instruction_(instr) {} |
| 322 | |
| 323 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 324 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 325 | __ Bind(GetEntryLabel()); |
| 326 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 327 | // Live registers will be restored in the catch block if caught. |
| 328 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 329 | } |
| 330 | mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 331 | instruction_, |
| 332 | instruction_->GetDexPc(), |
| 333 | this, |
| 334 | IsDirectEntrypoint(kQuickThrowNullPointer)); |
| 335 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 336 | } |
| 337 | |
| 338 | bool IsFatal() const OVERRIDE { return true; } |
| 339 | |
| 340 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS"; } |
| 341 | |
| 342 | private: |
| 343 | HNullCheck* const instruction_; |
| 344 | |
| 345 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS); |
| 346 | }; |
| 347 | |
| 348 | class SuspendCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 349 | public: |
| 350 | SuspendCheckSlowPathMIPS(HSuspendCheck* instruction, HBasicBlock* successor) |
| 351 | : instruction_(instruction), successor_(successor) {} |
| 352 | |
| 353 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 354 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 355 | __ Bind(GetEntryLabel()); |
| 356 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 357 | mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 358 | instruction_, |
| 359 | instruction_->GetDexPc(), |
| 360 | this, |
| 361 | IsDirectEntrypoint(kQuickTestSuspend)); |
| 362 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| 363 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
| 364 | if (successor_ == nullptr) { |
| 365 | __ B(GetReturnLabel()); |
| 366 | } else { |
| 367 | __ B(mips_codegen->GetLabelOf(successor_)); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | MipsLabel* GetReturnLabel() { |
| 372 | DCHECK(successor_ == nullptr); |
| 373 | return &return_label_; |
| 374 | } |
| 375 | |
| 376 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS"; } |
| 377 | |
| 378 | private: |
| 379 | HSuspendCheck* const instruction_; |
| 380 | // If not null, the block to branch to after the suspend check. |
| 381 | HBasicBlock* const successor_; |
| 382 | |
| 383 | // If `successor_` is null, the label to branch to after the suspend check. |
| 384 | MipsLabel return_label_; |
| 385 | |
| 386 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS); |
| 387 | }; |
| 388 | |
| 389 | class TypeCheckSlowPathMIPS : public SlowPathCodeMIPS { |
| 390 | public: |
| 391 | explicit TypeCheckSlowPathMIPS(HInstruction* instruction) : instruction_(instruction) {} |
| 392 | |
| 393 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 394 | LocationSummary* locations = instruction_->GetLocations(); |
| 395 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) : locations->Out(); |
| 396 | uint32_t dex_pc = instruction_->GetDexPc(); |
| 397 | DCHECK(instruction_->IsCheckCast() |
| 398 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 399 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 400 | |
| 401 | __ Bind(GetEntryLabel()); |
| 402 | SaveLiveRegisters(codegen, locations); |
| 403 | |
| 404 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 405 | // move resolver. |
| 406 | InvokeRuntimeCallingConvention calling_convention; |
| 407 | codegen->EmitParallelMoves(locations->InAt(1), |
| 408 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 409 | Primitive::kPrimNot, |
| 410 | object_class, |
| 411 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 412 | Primitive::kPrimNot); |
| 413 | |
| 414 | if (instruction_->IsInstanceOf()) { |
| 415 | mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 416 | instruction_, |
| 417 | dex_pc, |
| 418 | this, |
| 419 | IsDirectEntrypoint(kQuickInstanceofNonTrivial)); |
| 420 | Primitive::Type ret_type = instruction_->GetType(); |
| 421 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 422 | mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 423 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, |
| 424 | uint32_t, |
| 425 | const mirror::Class*, |
| 426 | const mirror::Class*>(); |
| 427 | } else { |
| 428 | DCHECK(instruction_->IsCheckCast()); |
| 429 | mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 430 | instruction_, |
| 431 | dex_pc, |
| 432 | this, |
| 433 | IsDirectEntrypoint(kQuickCheckCast)); |
| 434 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
| 435 | } |
| 436 | |
| 437 | RestoreLiveRegisters(codegen, locations); |
| 438 | __ B(GetExitLabel()); |
| 439 | } |
| 440 | |
| 441 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; } |
| 442 | |
| 443 | private: |
| 444 | HInstruction* const instruction_; |
| 445 | |
| 446 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS); |
| 447 | }; |
| 448 | |
| 449 | class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS { |
| 450 | public: |
| 451 | explicit DeoptimizationSlowPathMIPS(HInstruction* instruction) |
| 452 | : instruction_(instruction) {} |
| 453 | |
| 454 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 455 | __ Bind(GetEntryLabel()); |
| 456 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 457 | DCHECK(instruction_->IsDeoptimize()); |
| 458 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); |
| 459 | uint32_t dex_pc = deoptimize->GetDexPc(); |
| 460 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 461 | mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 462 | instruction_, |
| 463 | dex_pc, |
| 464 | this, |
| 465 | IsDirectEntrypoint(kQuickDeoptimize)); |
| 466 | } |
| 467 | |
| 468 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; } |
| 469 | |
| 470 | private: |
| 471 | HInstruction* const instruction_; |
| 472 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS); |
| 473 | }; |
| 474 | |
| 475 | CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph, |
| 476 | const MipsInstructionSetFeatures& isa_features, |
| 477 | const CompilerOptions& compiler_options, |
| 478 | OptimizingCompilerStats* stats) |
| 479 | : CodeGenerator(graph, |
| 480 | kNumberOfCoreRegisters, |
| 481 | kNumberOfFRegisters, |
| 482 | kNumberOfRegisterPairs, |
| 483 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 484 | arraysize(kCoreCalleeSaves)), |
| 485 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 486 | arraysize(kFpuCalleeSaves)), |
| 487 | compiler_options, |
| 488 | stats), |
| 489 | block_labels_(nullptr), |
| 490 | location_builder_(graph, this), |
| 491 | instruction_visitor_(graph, this), |
| 492 | move_resolver_(graph->GetArena(), this), |
| 493 | assembler_(&isa_features), |
| 494 | isa_features_(isa_features) { |
| 495 | // Save RA (containing the return address) to mimic Quick. |
| 496 | AddAllocatedRegister(Location::RegisterLocation(RA)); |
| 497 | } |
| 498 | |
| 499 | #undef __ |
| 500 | #define __ down_cast<MipsAssembler*>(GetAssembler())-> |
| 501 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsWordSize, x).Int32Value() |
| 502 | |
| 503 | void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) { |
| 504 | // Ensure that we fix up branches. |
| 505 | __ FinalizeCode(); |
| 506 | |
| 507 | // Adjust native pc offsets in stack maps. |
| 508 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
| 509 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; |
| 510 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 511 | DCHECK_GE(new_position, old_position); |
| 512 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 513 | } |
| 514 | |
| 515 | // Adjust pc offsets for the disassembly information. |
| 516 | if (disasm_info_ != nullptr) { |
| 517 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 518 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 519 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 520 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 521 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 522 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 523 | } |
| 524 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 525 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 526 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | CodeGenerator::Finalize(allocator); |
| 531 | } |
| 532 | |
| 533 | MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const { |
| 534 | return codegen_->GetAssembler(); |
| 535 | } |
| 536 | |
| 537 | void ParallelMoveResolverMIPS::EmitMove(size_t index) { |
| 538 | DCHECK_LT(index, moves_.size()); |
| 539 | MoveOperands* move = moves_[index]; |
| 540 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); |
| 541 | } |
| 542 | |
| 543 | void ParallelMoveResolverMIPS::EmitSwap(size_t index) { |
| 544 | DCHECK_LT(index, moves_.size()); |
| 545 | MoveOperands* move = moves_[index]; |
| 546 | Primitive::Type type = move->GetType(); |
| 547 | Location loc1 = move->GetDestination(); |
| 548 | Location loc2 = move->GetSource(); |
| 549 | |
| 550 | DCHECK(!loc1.IsConstant()); |
| 551 | DCHECK(!loc2.IsConstant()); |
| 552 | |
| 553 | if (loc1.Equals(loc2)) { |
| 554 | return; |
| 555 | } |
| 556 | |
| 557 | if (loc1.IsRegister() && loc2.IsRegister()) { |
| 558 | // Swap 2 GPRs. |
| 559 | Register r1 = loc1.AsRegister<Register>(); |
| 560 | Register r2 = loc2.AsRegister<Register>(); |
| 561 | __ Move(TMP, r2); |
| 562 | __ Move(r2, r1); |
| 563 | __ Move(r1, TMP); |
| 564 | } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) { |
| 565 | FRegister f1 = loc1.AsFpuRegister<FRegister>(); |
| 566 | FRegister f2 = loc2.AsFpuRegister<FRegister>(); |
| 567 | if (type == Primitive::kPrimFloat) { |
| 568 | __ MovS(FTMP, f2); |
| 569 | __ MovS(f2, f1); |
| 570 | __ MovS(f1, FTMP); |
| 571 | } else { |
| 572 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 573 | __ MovD(FTMP, f2); |
| 574 | __ MovD(f2, f1); |
| 575 | __ MovD(f1, FTMP); |
| 576 | } |
| 577 | } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) || |
| 578 | (loc1.IsFpuRegister() && loc2.IsRegister())) { |
| 579 | // Swap FPR and GPR. |
| 580 | DCHECK_EQ(type, Primitive::kPrimFloat); // Can only swap a float. |
| 581 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 582 | : loc2.AsFpuRegister<FRegister>(); |
| 583 | Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>() |
| 584 | : loc2.AsRegister<Register>(); |
| 585 | __ Move(TMP, r2); |
| 586 | __ Mfc1(r2, f1); |
| 587 | __ Mtc1(TMP, f1); |
| 588 | } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) { |
| 589 | // Swap 2 GPR register pairs. |
| 590 | Register r1 = loc1.AsRegisterPairLow<Register>(); |
| 591 | Register r2 = loc2.AsRegisterPairLow<Register>(); |
| 592 | __ Move(TMP, r2); |
| 593 | __ Move(r2, r1); |
| 594 | __ Move(r1, TMP); |
| 595 | r1 = loc1.AsRegisterPairHigh<Register>(); |
| 596 | r2 = loc2.AsRegisterPairHigh<Register>(); |
| 597 | __ Move(TMP, r2); |
| 598 | __ Move(r2, r1); |
| 599 | __ Move(r1, TMP); |
| 600 | } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) || |
| 601 | (loc1.IsFpuRegister() && loc2.IsRegisterPair())) { |
| 602 | // Swap FPR and GPR register pair. |
| 603 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 604 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 605 | : loc2.AsFpuRegister<FRegister>(); |
| 606 | Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 607 | : loc2.AsRegisterPairLow<Register>(); |
| 608 | Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 609 | : loc2.AsRegisterPairHigh<Register>(); |
| 610 | // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and |
| 611 | // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR |
| 612 | // unpredictable and the following mfch1 will fail. |
| 613 | __ Mfc1(TMP, f1); |
| 614 | __ Mfhc1(AT, f1); |
| 615 | __ Mtc1(r2_l, f1); |
| 616 | __ Mthc1(r2_h, f1); |
| 617 | __ Move(r2_l, TMP); |
| 618 | __ Move(r2_h, AT); |
| 619 | } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) { |
| 620 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false); |
| 621 | } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) { |
| 622 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true); |
| 623 | } else { |
| 624 | LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported"; |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | void ParallelMoveResolverMIPS::RestoreScratch(int reg) { |
| 629 | __ Pop(static_cast<Register>(reg)); |
| 630 | } |
| 631 | |
| 632 | void ParallelMoveResolverMIPS::SpillScratch(int reg) { |
| 633 | __ Push(static_cast<Register>(reg)); |
| 634 | } |
| 635 | |
| 636 | void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) { |
| 637 | // Allocate a scratch register other than TMP, if available. |
| 638 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be |
| 639 | // automatically unspilled when the scratch scope object is destroyed). |
| 640 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); |
| 641 | // If V0 spills onto the stack, SP-relative offsets need to be adjusted. |
| 642 | int stack_offset = ensure_scratch.IsSpilled() ? kMipsWordSize : 0; |
| 643 | for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) { |
| 644 | __ LoadFromOffset(kLoadWord, |
| 645 | Register(ensure_scratch.GetRegister()), |
| 646 | SP, |
| 647 | index1 + stack_offset); |
| 648 | __ LoadFromOffset(kLoadWord, |
| 649 | TMP, |
| 650 | SP, |
| 651 | index2 + stack_offset); |
| 652 | __ StoreToOffset(kStoreWord, |
| 653 | Register(ensure_scratch.GetRegister()), |
| 654 | SP, |
| 655 | index2 + stack_offset); |
| 656 | __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset); |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | static dwarf::Reg DWARFReg(Register reg) { |
| 661 | return dwarf::Reg::MipsCore(static_cast<int>(reg)); |
| 662 | } |
| 663 | |
| 664 | // TODO: mapping of floating-point registers to DWARF. |
| 665 | |
| 666 | void CodeGeneratorMIPS::GenerateFrameEntry() { |
| 667 | __ Bind(&frame_entry_label_); |
| 668 | |
| 669 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips) || !IsLeafMethod(); |
| 670 | |
| 671 | if (do_overflow_check) { |
| 672 | __ LoadFromOffset(kLoadWord, |
| 673 | ZERO, |
| 674 | SP, |
| 675 | -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips))); |
| 676 | RecordPcInfo(nullptr, 0); |
| 677 | } |
| 678 | |
| 679 | if (HasEmptyFrame()) { |
| 680 | return; |
| 681 | } |
| 682 | |
| 683 | // Make sure the frame size isn't unreasonably large. |
| 684 | if (GetFrameSize() > GetStackOverflowReservedBytes(kMips)) { |
| 685 | LOG(FATAL) << "Stack frame larger than " << GetStackOverflowReservedBytes(kMips) << " bytes"; |
| 686 | } |
| 687 | |
| 688 | // Spill callee-saved registers. |
| 689 | // Note that their cumulative size is small and they can be indexed using |
| 690 | // 16-bit offsets. |
| 691 | |
| 692 | // TODO: increment/decrement SP in one step instead of two or remove this comment. |
| 693 | |
| 694 | uint32_t ofs = FrameEntrySpillSize(); |
| 695 | bool unaligned_float = ofs & 0x7; |
| 696 | bool fpu_32bit = isa_features_.Is32BitFloatingPoint(); |
| 697 | __ IncreaseFrameSize(ofs); |
| 698 | |
| 699 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 700 | Register reg = kCoreCalleeSaves[i]; |
| 701 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 702 | ofs -= kMipsWordSize; |
| 703 | __ Sw(reg, SP, ofs); |
| 704 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 709 | FRegister reg = kFpuCalleeSaves[i]; |
| 710 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
| 711 | ofs -= kMipsDoublewordSize; |
| 712 | // TODO: Change the frame to avoid unaligned accesses for fpu registers. |
| 713 | if (unaligned_float) { |
| 714 | if (fpu_32bit) { |
| 715 | __ Swc1(reg, SP, ofs); |
| 716 | __ Swc1(static_cast<FRegister>(reg + 1), SP, ofs + 4); |
| 717 | } else { |
| 718 | __ Mfhc1(TMP, reg); |
| 719 | __ Swc1(reg, SP, ofs); |
| 720 | __ Sw(TMP, SP, ofs + 4); |
| 721 | } |
| 722 | } else { |
| 723 | __ Sdc1(reg, SP, ofs); |
| 724 | } |
| 725 | // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | // Allocate the rest of the frame and store the current method pointer |
| 730 | // at its end. |
| 731 | |
| 732 | __ IncreaseFrameSize(GetFrameSize() - FrameEntrySpillSize()); |
| 733 | |
| 734 | static_assert(IsInt<16>(kCurrentMethodStackOffset), |
| 735 | "kCurrentMethodStackOffset must fit into int16_t"); |
| 736 | __ Sw(kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
| 737 | } |
| 738 | |
| 739 | void CodeGeneratorMIPS::GenerateFrameExit() { |
| 740 | __ cfi().RememberState(); |
| 741 | |
| 742 | if (!HasEmptyFrame()) { |
| 743 | // Deallocate the rest of the frame. |
| 744 | |
| 745 | __ DecreaseFrameSize(GetFrameSize() - FrameEntrySpillSize()); |
| 746 | |
| 747 | // Restore callee-saved registers. |
| 748 | // Note that their cumulative size is small and they can be indexed using |
| 749 | // 16-bit offsets. |
| 750 | |
| 751 | // TODO: increment/decrement SP in one step instead of two or remove this comment. |
| 752 | |
| 753 | uint32_t ofs = 0; |
| 754 | bool unaligned_float = FrameEntrySpillSize() & 0x7; |
| 755 | bool fpu_32bit = isa_features_.Is32BitFloatingPoint(); |
| 756 | |
| 757 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 758 | FRegister reg = kFpuCalleeSaves[i]; |
| 759 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
| 760 | if (unaligned_float) { |
| 761 | if (fpu_32bit) { |
| 762 | __ Lwc1(reg, SP, ofs); |
| 763 | __ Lwc1(static_cast<FRegister>(reg + 1), SP, ofs + 4); |
| 764 | } else { |
| 765 | __ Lwc1(reg, SP, ofs); |
| 766 | __ Lw(TMP, SP, ofs + 4); |
| 767 | __ Mthc1(TMP, reg); |
| 768 | } |
| 769 | } else { |
| 770 | __ Ldc1(reg, SP, ofs); |
| 771 | } |
| 772 | ofs += kMipsDoublewordSize; |
| 773 | // TODO: __ cfi().Restore(DWARFReg(reg)); |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 778 | Register reg = kCoreCalleeSaves[i]; |
| 779 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 780 | __ Lw(reg, SP, ofs); |
| 781 | ofs += kMipsWordSize; |
| 782 | __ cfi().Restore(DWARFReg(reg)); |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | DCHECK_EQ(ofs, FrameEntrySpillSize()); |
| 787 | __ DecreaseFrameSize(ofs); |
| 788 | } |
| 789 | |
| 790 | __ Jr(RA); |
| 791 | __ Nop(); |
| 792 | |
| 793 | __ cfi().RestoreState(); |
| 794 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 795 | } |
| 796 | |
| 797 | void CodeGeneratorMIPS::Bind(HBasicBlock* block) { |
| 798 | __ Bind(GetLabelOf(block)); |
| 799 | } |
| 800 | |
| 801 | void CodeGeneratorMIPS::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
| 802 | if (src.Equals(dst)) { |
| 803 | return; |
| 804 | } |
| 805 | |
| 806 | if (src.IsConstant()) { |
| 807 | MoveConstant(dst, src.GetConstant()); |
| 808 | } else { |
| 809 | if (Primitive::Is64BitType(dst_type)) { |
| 810 | Move64(dst, src); |
| 811 | } else { |
| 812 | Move32(dst, src); |
| 813 | } |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | void CodeGeneratorMIPS::Move32(Location destination, Location source) { |
| 818 | if (source.Equals(destination)) { |
| 819 | return; |
| 820 | } |
| 821 | |
| 822 | if (destination.IsRegister()) { |
| 823 | if (source.IsRegister()) { |
| 824 | __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 825 | } else if (source.IsFpuRegister()) { |
| 826 | __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>()); |
| 827 | } else { |
| 828 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 829 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
| 830 | } |
| 831 | } else if (destination.IsFpuRegister()) { |
| 832 | if (source.IsRegister()) { |
| 833 | __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>()); |
| 834 | } else if (source.IsFpuRegister()) { |
| 835 | __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 836 | } else { |
| 837 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 838 | __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 839 | } |
| 840 | } else { |
| 841 | DCHECK(destination.IsStackSlot()) << destination; |
| 842 | if (source.IsRegister()) { |
| 843 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
| 844 | } else if (source.IsFpuRegister()) { |
| 845 | __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex()); |
| 846 | } else { |
| 847 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 848 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 849 | __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex()); |
| 850 | } |
| 851 | } |
| 852 | } |
| 853 | |
| 854 | void CodeGeneratorMIPS::Move64(Location destination, Location source) { |
| 855 | if (source.Equals(destination)) { |
| 856 | return; |
| 857 | } |
| 858 | |
| 859 | if (destination.IsRegisterPair()) { |
| 860 | if (source.IsRegisterPair()) { |
| 861 | __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 862 | __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 863 | } else if (source.IsFpuRegister()) { |
| 864 | Register dst_high = destination.AsRegisterPairHigh<Register>(); |
| 865 | Register dst_low = destination.AsRegisterPairLow<Register>(); |
| 866 | FRegister src = source.AsFpuRegister<FRegister>(); |
| 867 | __ Mfc1(dst_low, src); |
| 868 | __ Mfhc1(dst_high, src); |
| 869 | } else { |
| 870 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 871 | int32_t off = source.GetStackIndex(); |
| 872 | Register r = destination.AsRegisterPairLow<Register>(); |
| 873 | __ LoadFromOffset(kLoadDoubleword, r, SP, off); |
| 874 | } |
| 875 | } else if (destination.IsFpuRegister()) { |
| 876 | if (source.IsRegisterPair()) { |
| 877 | FRegister dst = destination.AsFpuRegister<FRegister>(); |
| 878 | Register src_high = source.AsRegisterPairHigh<Register>(); |
| 879 | Register src_low = source.AsRegisterPairLow<Register>(); |
| 880 | __ Mtc1(src_low, dst); |
| 881 | __ Mthc1(src_high, dst); |
| 882 | } else if (source.IsFpuRegister()) { |
| 883 | __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 884 | } else { |
| 885 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 886 | __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 887 | } |
| 888 | } else { |
| 889 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 890 | int32_t off = destination.GetStackIndex(); |
| 891 | if (source.IsRegisterPair()) { |
| 892 | __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, off); |
| 893 | } else if (source.IsFpuRegister()) { |
| 894 | __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, off); |
| 895 | } else { |
| 896 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 897 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 898 | __ StoreToOffset(kStoreWord, TMP, SP, off); |
| 899 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4); |
| 900 | __ StoreToOffset(kStoreWord, TMP, SP, off + 4); |
| 901 | } |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) { |
| 906 | if (c->IsIntConstant() || c->IsNullConstant()) { |
| 907 | // Move 32 bit constant. |
| 908 | int32_t value = GetInt32ValueOf(c); |
| 909 | if (destination.IsRegister()) { |
| 910 | Register dst = destination.AsRegister<Register>(); |
| 911 | __ LoadConst32(dst, value); |
| 912 | } else { |
| 913 | DCHECK(destination.IsStackSlot()) |
| 914 | << "Cannot move " << c->DebugName() << " to " << destination; |
| 915 | __ StoreConst32ToOffset(value, SP, destination.GetStackIndex(), TMP); |
| 916 | } |
| 917 | } else if (c->IsLongConstant()) { |
| 918 | // Move 64 bit constant. |
| 919 | int64_t value = GetInt64ValueOf(c); |
| 920 | if (destination.IsRegisterPair()) { |
| 921 | Register r_h = destination.AsRegisterPairHigh<Register>(); |
| 922 | Register r_l = destination.AsRegisterPairLow<Register>(); |
| 923 | __ LoadConst64(r_h, r_l, value); |
| 924 | } else { |
| 925 | DCHECK(destination.IsDoubleStackSlot()) |
| 926 | << "Cannot move " << c->DebugName() << " to " << destination; |
| 927 | __ StoreConst64ToOffset(value, SP, destination.GetStackIndex(), TMP); |
| 928 | } |
| 929 | } else if (c->IsFloatConstant()) { |
| 930 | // Move 32 bit float constant. |
| 931 | int32_t value = GetInt32ValueOf(c); |
| 932 | if (destination.IsFpuRegister()) { |
| 933 | __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP); |
| 934 | } else { |
| 935 | DCHECK(destination.IsStackSlot()) |
| 936 | << "Cannot move " << c->DebugName() << " to " << destination; |
| 937 | __ StoreConst32ToOffset(value, SP, destination.GetStackIndex(), TMP); |
| 938 | } |
| 939 | } else { |
| 940 | // Move 64 bit double constant. |
| 941 | DCHECK(c->IsDoubleConstant()) << c->DebugName(); |
| 942 | int64_t value = GetInt64ValueOf(c); |
| 943 | if (destination.IsFpuRegister()) { |
| 944 | FRegister fd = destination.AsFpuRegister<FRegister>(); |
| 945 | __ LoadDConst64(fd, value, TMP); |
| 946 | } else { |
| 947 | DCHECK(destination.IsDoubleStackSlot()) |
| 948 | << "Cannot move " << c->DebugName() << " to " << destination; |
| 949 | __ StoreConst64ToOffset(value, SP, destination.GetStackIndex(), TMP); |
| 950 | } |
| 951 | } |
| 952 | } |
| 953 | |
| 954 | void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) { |
| 955 | DCHECK(destination.IsRegister()); |
| 956 | Register dst = destination.AsRegister<Register>(); |
| 957 | __ LoadConst32(dst, value); |
| 958 | } |
| 959 | |
| 960 | void CodeGeneratorMIPS::Move(HInstruction* instruction, |
| 961 | Location location, |
| 962 | HInstruction* move_for) { |
| 963 | LocationSummary* locations = instruction->GetLocations(); |
| 964 | Primitive::Type type = instruction->GetType(); |
| 965 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 966 | |
| 967 | if (instruction->IsCurrentMethod()) { |
| 968 | Move32(location, Location::StackSlot(kCurrentMethodStackOffset)); |
| 969 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
| 970 | return; |
| 971 | } else if (instruction->IsIntConstant() |
| 972 | || instruction->IsLongConstant() |
| 973 | || instruction->IsNullConstant()) { |
| 974 | MoveConstant(location, instruction->AsConstant()); |
| 975 | } else if (instruction->IsTemporary()) { |
| 976 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
| 977 | if (temp_location.IsStackSlot()) { |
| 978 | Move32(location, temp_location); |
| 979 | } else { |
| 980 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 981 | Move64(location, temp_location); |
| 982 | } |
| 983 | } else if (instruction->IsLoadLocal()) { |
| 984 | uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
| 985 | if (Primitive::Is64BitType(type)) { |
| 986 | Move64(location, Location::DoubleStackSlot(stack_slot)); |
| 987 | } else { |
| 988 | Move32(location, Location::StackSlot(stack_slot)); |
| 989 | } |
| 990 | } else { |
| 991 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
| 992 | if (Primitive::Is64BitType(type)) { |
| 993 | Move64(location, locations->Out()); |
| 994 | } else { |
| 995 | Move32(location, locations->Out()); |
| 996 | } |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1001 | if (location.IsRegister()) { |
| 1002 | locations->AddTemp(location); |
Alexey Frunze | c9e94f3 | 2015-10-26 16:11:39 -0700 | [diff] [blame] | 1003 | } else if (location.IsRegisterPair()) { |
| 1004 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1005 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1006 | } else { |
| 1007 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1008 | } |
| 1009 | } |
| 1010 | |
| 1011 | Location CodeGeneratorMIPS::GetStackLocation(HLoadLocal* load) const { |
| 1012 | Primitive::Type type = load->GetType(); |
| 1013 | |
| 1014 | switch (type) { |
| 1015 | case Primitive::kPrimNot: |
| 1016 | case Primitive::kPrimInt: |
| 1017 | case Primitive::kPrimFloat: |
| 1018 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
| 1019 | |
| 1020 | case Primitive::kPrimLong: |
| 1021 | case Primitive::kPrimDouble: |
| 1022 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
| 1023 | |
| 1024 | case Primitive::kPrimBoolean: |
| 1025 | case Primitive::kPrimByte: |
| 1026 | case Primitive::kPrimChar: |
| 1027 | case Primitive::kPrimShort: |
| 1028 | case Primitive::kPrimVoid: |
| 1029 | LOG(FATAL) << "Unexpected type " << type; |
| 1030 | } |
| 1031 | |
| 1032 | LOG(FATAL) << "Unreachable"; |
| 1033 | return Location::NoLocation(); |
| 1034 | } |
| 1035 | |
| 1036 | void CodeGeneratorMIPS::MarkGCCard(Register object, Register value) { |
| 1037 | MipsLabel done; |
| 1038 | Register card = AT; |
| 1039 | Register temp = TMP; |
| 1040 | __ Beqz(value, &done); |
| 1041 | __ LoadFromOffset(kLoadWord, |
| 1042 | card, |
| 1043 | TR, |
| 1044 | Thread::CardTableOffset<kMipsWordSize>().Int32Value()); |
| 1045 | __ Srl(temp, object, gc::accounting::CardTable::kCardShift); |
| 1046 | __ Addu(temp, card, temp); |
| 1047 | __ Sb(card, temp, 0); |
| 1048 | __ Bind(&done); |
| 1049 | } |
| 1050 | |
| 1051 | void CodeGeneratorMIPS::SetupBlockedRegisters(bool is_baseline) const { |
| 1052 | // Don't allocate the dalvik style register pair passing. |
| 1053 | blocked_register_pairs_[A1_A2] = true; |
| 1054 | |
| 1055 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1056 | blocked_core_registers_[ZERO] = true; |
| 1057 | blocked_core_registers_[K0] = true; |
| 1058 | blocked_core_registers_[K1] = true; |
| 1059 | blocked_core_registers_[GP] = true; |
| 1060 | blocked_core_registers_[SP] = true; |
| 1061 | blocked_core_registers_[RA] = true; |
| 1062 | |
| 1063 | // AT and TMP(T8) are used as temporary/scratch registers |
| 1064 | // (similar to how AT is used by MIPS assemblers). |
| 1065 | blocked_core_registers_[AT] = true; |
| 1066 | blocked_core_registers_[TMP] = true; |
| 1067 | blocked_fpu_registers_[FTMP] = true; |
| 1068 | |
| 1069 | // Reserve suspend and thread registers. |
| 1070 | blocked_core_registers_[S0] = true; |
| 1071 | blocked_core_registers_[TR] = true; |
| 1072 | |
| 1073 | // Reserve T9 for function calls |
| 1074 | blocked_core_registers_[T9] = true; |
| 1075 | |
| 1076 | // Reserve odd-numbered FPU registers. |
| 1077 | for (size_t i = 1; i < kNumberOfFRegisters; i += 2) { |
| 1078 | blocked_fpu_registers_[i] = true; |
| 1079 | } |
| 1080 | |
| 1081 | if (is_baseline) { |
| 1082 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1083 | blocked_core_registers_[kCoreCalleeSaves[i]] = true; |
| 1084 | } |
| 1085 | |
| 1086 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1087 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | UpdateBlockedPairRegisters(); |
| 1092 | } |
| 1093 | |
| 1094 | void CodeGeneratorMIPS::UpdateBlockedPairRegisters() const { |
| 1095 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 1096 | MipsManagedRegister current = |
| 1097 | MipsManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 1098 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 1099 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 1100 | blocked_register_pairs_[i] = true; |
| 1101 | } |
| 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | Location CodeGeneratorMIPS::AllocateFreeRegister(Primitive::Type type) const { |
| 1106 | switch (type) { |
| 1107 | case Primitive::kPrimLong: { |
| 1108 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
| 1109 | MipsManagedRegister pair = |
| 1110 | MipsManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
| 1111 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 1112 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
| 1113 | |
| 1114 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 1115 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
| 1116 | UpdateBlockedPairRegisters(); |
| 1117 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
| 1118 | } |
| 1119 | |
| 1120 | case Primitive::kPrimByte: |
| 1121 | case Primitive::kPrimBoolean: |
| 1122 | case Primitive::kPrimChar: |
| 1123 | case Primitive::kPrimShort: |
| 1124 | case Primitive::kPrimInt: |
| 1125 | case Primitive::kPrimNot: { |
| 1126 | int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters); |
| 1127 | // Block all register pairs that contain `reg`. |
| 1128 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 1129 | MipsManagedRegister current = |
| 1130 | MipsManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 1131 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
| 1132 | blocked_register_pairs_[i] = true; |
| 1133 | } |
| 1134 | } |
| 1135 | return Location::RegisterLocation(reg); |
| 1136 | } |
| 1137 | |
| 1138 | case Primitive::kPrimFloat: |
| 1139 | case Primitive::kPrimDouble: { |
| 1140 | int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfFRegisters); |
| 1141 | return Location::FpuRegisterLocation(reg); |
| 1142 | } |
| 1143 | |
| 1144 | case Primitive::kPrimVoid: |
| 1145 | LOG(FATAL) << "Unreachable type " << type; |
| 1146 | } |
| 1147 | |
| 1148 | UNREACHABLE(); |
| 1149 | } |
| 1150 | |
| 1151 | size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1152 | __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index); |
| 1153 | return kMipsWordSize; |
| 1154 | } |
| 1155 | |
| 1156 | size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1157 | __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index); |
| 1158 | return kMipsWordSize; |
| 1159 | } |
| 1160 | |
| 1161 | size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1162 | __ StoreDToOffset(FRegister(reg_id), SP, stack_index); |
| 1163 | return kMipsDoublewordSize; |
| 1164 | } |
| 1165 | |
| 1166 | size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1167 | __ LoadDFromOffset(FRegister(reg_id), SP, stack_index); |
| 1168 | return kMipsDoublewordSize; |
| 1169 | } |
| 1170 | |
| 1171 | void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 1172 | stream << MipsManagedRegister::FromCoreRegister(Register(reg)); |
| 1173 | } |
| 1174 | |
| 1175 | void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 1176 | stream << MipsManagedRegister::FromFRegister(FRegister(reg)); |
| 1177 | } |
| 1178 | |
| 1179 | void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1180 | HInstruction* instruction, |
| 1181 | uint32_t dex_pc, |
| 1182 | SlowPathCode* slow_path) { |
| 1183 | InvokeRuntime(GetThreadOffset<kMipsWordSize>(entrypoint).Int32Value(), |
| 1184 | instruction, |
| 1185 | dex_pc, |
| 1186 | slow_path, |
| 1187 | IsDirectEntrypoint(entrypoint)); |
| 1188 | } |
| 1189 | |
| 1190 | constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16; |
| 1191 | |
| 1192 | void CodeGeneratorMIPS::InvokeRuntime(int32_t entry_point_offset, |
| 1193 | HInstruction* instruction, |
| 1194 | uint32_t dex_pc, |
| 1195 | SlowPathCode* slow_path, |
| 1196 | bool is_direct_entrypoint) { |
| 1197 | if (is_direct_entrypoint) { |
| 1198 | // Reserve argument space on stack (for $a0-$a3) for |
| 1199 | // entrypoints that directly reference native implementations. |
| 1200 | // Called function may use this space to store $a0-$a3 regs. |
| 1201 | __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); |
| 1202 | } |
| 1203 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 1204 | __ Jalr(T9); |
| 1205 | __ Nop(); |
| 1206 | if (is_direct_entrypoint) { |
| 1207 | __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); |
| 1208 | } |
| 1209 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1210 | } |
| 1211 | |
| 1212 | void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path, |
| 1213 | Register class_reg) { |
| 1214 | __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 1215 | __ LoadConst32(AT, mirror::Class::kStatusInitialized); |
| 1216 | __ Blt(TMP, AT, slow_path->GetEntryLabel()); |
| 1217 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 1218 | __ Sync(0); |
| 1219 | __ Bind(slow_path->GetExitLabel()); |
| 1220 | } |
| 1221 | |
| 1222 | void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1223 | __ Sync(0); // Only stype 0 is supported. |
| 1224 | } |
| 1225 | |
| 1226 | void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1227 | HBasicBlock* successor) { |
| 1228 | SuspendCheckSlowPathMIPS* slow_path = |
| 1229 | new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS(instruction, successor); |
| 1230 | codegen_->AddSlowPath(slow_path); |
| 1231 | |
| 1232 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1233 | TMP, |
| 1234 | TR, |
| 1235 | Thread::ThreadFlagsOffset<kMipsWordSize>().Int32Value()); |
| 1236 | if (successor == nullptr) { |
| 1237 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
| 1238 | __ Bind(slow_path->GetReturnLabel()); |
| 1239 | } else { |
| 1240 | __ Beqz(TMP, codegen_->GetLabelOf(successor)); |
| 1241 | __ B(slow_path->GetEntryLabel()); |
| 1242 | // slow_path will return to GetLabelOf(successor). |
| 1243 | } |
| 1244 | } |
| 1245 | |
| 1246 | InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph, |
| 1247 | CodeGeneratorMIPS* codegen) |
| 1248 | : HGraphVisitor(graph), |
| 1249 | assembler_(codegen->GetAssembler()), |
| 1250 | codegen_(codegen) {} |
| 1251 | |
| 1252 | void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1253 | DCHECK_EQ(instruction->InputCount(), 2U); |
| 1254 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1255 | Primitive::Type type = instruction->GetResultType(); |
| 1256 | switch (type) { |
| 1257 | case Primitive::kPrimInt: { |
| 1258 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1259 | HInstruction* right = instruction->InputAt(1); |
| 1260 | bool can_use_imm = false; |
| 1261 | if (right->IsConstant()) { |
| 1262 | int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant()); |
| 1263 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 1264 | can_use_imm = IsUint<16>(imm); |
| 1265 | } else if (instruction->IsAdd()) { |
| 1266 | can_use_imm = IsInt<16>(imm); |
| 1267 | } else { |
| 1268 | DCHECK(instruction->IsSub()); |
| 1269 | can_use_imm = IsInt<16>(-imm); |
| 1270 | } |
| 1271 | } |
| 1272 | if (can_use_imm) |
| 1273 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 1274 | else |
| 1275 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1276 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1277 | break; |
| 1278 | } |
| 1279 | |
| 1280 | case Primitive::kPrimLong: { |
| 1281 | // TODO: can 2nd param be const? |
| 1282 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1283 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1284 | if (instruction->IsAdd() || instruction->IsSub()) { |
| 1285 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 1286 | } else { |
| 1287 | DCHECK(instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()); |
| 1288 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1289 | } |
| 1290 | break; |
| 1291 | } |
| 1292 | |
| 1293 | case Primitive::kPrimFloat: |
| 1294 | case Primitive::kPrimDouble: |
| 1295 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 1296 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1297 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1298 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1299 | break; |
| 1300 | |
| 1301 | default: |
| 1302 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 1303 | } |
| 1304 | } |
| 1305 | |
| 1306 | void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1307 | Primitive::Type type = instruction->GetType(); |
| 1308 | LocationSummary* locations = instruction->GetLocations(); |
| 1309 | |
| 1310 | switch (type) { |
| 1311 | case Primitive::kPrimInt: { |
| 1312 | Register dst = locations->Out().AsRegister<Register>(); |
| 1313 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 1314 | Location rhs_location = locations->InAt(1); |
| 1315 | |
| 1316 | Register rhs_reg = ZERO; |
| 1317 | int32_t rhs_imm = 0; |
| 1318 | bool use_imm = rhs_location.IsConstant(); |
| 1319 | if (use_imm) { |
| 1320 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 1321 | } else { |
| 1322 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 1323 | } |
| 1324 | |
| 1325 | if (instruction->IsAnd()) { |
| 1326 | if (use_imm) |
| 1327 | __ Andi(dst, lhs, rhs_imm); |
| 1328 | else |
| 1329 | __ And(dst, lhs, rhs_reg); |
| 1330 | } else if (instruction->IsOr()) { |
| 1331 | if (use_imm) |
| 1332 | __ Ori(dst, lhs, rhs_imm); |
| 1333 | else |
| 1334 | __ Or(dst, lhs, rhs_reg); |
| 1335 | } else if (instruction->IsXor()) { |
| 1336 | if (use_imm) |
| 1337 | __ Xori(dst, lhs, rhs_imm); |
| 1338 | else |
| 1339 | __ Xor(dst, lhs, rhs_reg); |
| 1340 | } else if (instruction->IsAdd()) { |
| 1341 | if (use_imm) |
| 1342 | __ Addiu(dst, lhs, rhs_imm); |
| 1343 | else |
| 1344 | __ Addu(dst, lhs, rhs_reg); |
| 1345 | } else { |
| 1346 | DCHECK(instruction->IsSub()); |
| 1347 | if (use_imm) |
| 1348 | __ Addiu(dst, lhs, -rhs_imm); |
| 1349 | else |
| 1350 | __ Subu(dst, lhs, rhs_reg); |
| 1351 | } |
| 1352 | break; |
| 1353 | } |
| 1354 | |
| 1355 | case Primitive::kPrimLong: { |
| 1356 | // TODO: can 2nd param be const? |
| 1357 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 1358 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 1359 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 1360 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 1361 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 1362 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 1363 | |
| 1364 | if (instruction->IsAnd()) { |
| 1365 | __ And(dst_low, lhs_low, rhs_low); |
| 1366 | __ And(dst_high, lhs_high, rhs_high); |
| 1367 | } else if (instruction->IsOr()) { |
| 1368 | __ Or(dst_low, lhs_low, rhs_low); |
| 1369 | __ Or(dst_high, lhs_high, rhs_high); |
| 1370 | } else if (instruction->IsXor()) { |
| 1371 | __ Xor(dst_low, lhs_low, rhs_low); |
| 1372 | __ Xor(dst_high, lhs_high, rhs_high); |
| 1373 | } else if (instruction->IsAdd()) { |
| 1374 | __ Addu(dst_low, lhs_low, rhs_low); |
| 1375 | __ Sltu(TMP, dst_low, lhs_low); |
| 1376 | __ Addu(dst_high, lhs_high, rhs_high); |
| 1377 | __ Addu(dst_high, dst_high, TMP); |
| 1378 | } else { |
| 1379 | DCHECK(instruction->IsSub()); |
| 1380 | __ Subu(dst_low, lhs_low, rhs_low); |
| 1381 | __ Sltu(TMP, lhs_low, dst_low); |
| 1382 | __ Subu(dst_high, lhs_high, rhs_high); |
| 1383 | __ Subu(dst_high, dst_high, TMP); |
| 1384 | } |
| 1385 | break; |
| 1386 | } |
| 1387 | |
| 1388 | case Primitive::kPrimFloat: |
| 1389 | case Primitive::kPrimDouble: { |
| 1390 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 1391 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 1392 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 1393 | if (instruction->IsAdd()) { |
| 1394 | if (type == Primitive::kPrimFloat) { |
| 1395 | __ AddS(dst, lhs, rhs); |
| 1396 | } else { |
| 1397 | __ AddD(dst, lhs, rhs); |
| 1398 | } |
| 1399 | } else { |
| 1400 | DCHECK(instruction->IsSub()); |
| 1401 | if (type == Primitive::kPrimFloat) { |
| 1402 | __ SubS(dst, lhs, rhs); |
| 1403 | } else { |
| 1404 | __ SubD(dst, lhs, rhs); |
| 1405 | } |
| 1406 | } |
| 1407 | break; |
| 1408 | } |
| 1409 | |
| 1410 | default: |
| 1411 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 1412 | } |
| 1413 | } |
| 1414 | |
| 1415 | void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) { |
| 1416 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 1417 | |
| 1418 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1419 | Primitive::Type type = instr->GetResultType(); |
| 1420 | switch (type) { |
| 1421 | case Primitive::kPrimInt: |
| 1422 | case Primitive::kPrimLong: { |
| 1423 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1424 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 1425 | locations->SetOut(Location::RequiresRegister()); |
| 1426 | break; |
| 1427 | } |
| 1428 | default: |
| 1429 | LOG(FATAL) << "Unexpected shift type " << type; |
| 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte; |
| 1434 | |
| 1435 | void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) { |
| 1436 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 1437 | LocationSummary* locations = instr->GetLocations(); |
| 1438 | Primitive::Type type = instr->GetType(); |
| 1439 | |
| 1440 | Location rhs_location = locations->InAt(1); |
| 1441 | bool use_imm = rhs_location.IsConstant(); |
| 1442 | Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>(); |
| 1443 | int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0; |
| 1444 | uint32_t shift_mask = (type == Primitive::kPrimInt) ? kMaxIntShiftValue : kMaxLongShiftValue; |
| 1445 | uint32_t shift_value = rhs_imm & shift_mask; |
| 1446 | |
| 1447 | switch (type) { |
| 1448 | case Primitive::kPrimInt: { |
| 1449 | Register dst = locations->Out().AsRegister<Register>(); |
| 1450 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 1451 | if (use_imm) { |
| 1452 | if (instr->IsShl()) { |
| 1453 | __ Sll(dst, lhs, shift_value); |
| 1454 | } else if (instr->IsShr()) { |
| 1455 | __ Sra(dst, lhs, shift_value); |
| 1456 | } else { |
| 1457 | __ Srl(dst, lhs, shift_value); |
| 1458 | } |
| 1459 | } else { |
| 1460 | if (instr->IsShl()) { |
| 1461 | __ Sllv(dst, lhs, rhs_reg); |
| 1462 | } else if (instr->IsShr()) { |
| 1463 | __ Srav(dst, lhs, rhs_reg); |
| 1464 | } else { |
| 1465 | __ Srlv(dst, lhs, rhs_reg); |
| 1466 | } |
| 1467 | } |
| 1468 | break; |
| 1469 | } |
| 1470 | |
| 1471 | case Primitive::kPrimLong: { |
| 1472 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 1473 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 1474 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 1475 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 1476 | if (use_imm) { |
| 1477 | if (shift_value == 0) { |
| 1478 | codegen_->Move64(locations->Out(), locations->InAt(0)); |
| 1479 | } else if (shift_value < kMipsBitsPerWord) { |
| 1480 | if (instr->IsShl()) { |
| 1481 | __ Sll(dst_low, lhs_low, shift_value); |
| 1482 | __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value); |
| 1483 | __ Sll(dst_high, lhs_high, shift_value); |
| 1484 | __ Or(dst_high, dst_high, TMP); |
| 1485 | } else if (instr->IsShr()) { |
| 1486 | __ Sra(dst_high, lhs_high, shift_value); |
| 1487 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 1488 | __ Srl(dst_low, lhs_low, shift_value); |
| 1489 | __ Or(dst_low, dst_low, TMP); |
| 1490 | } else { |
| 1491 | __ Srl(dst_high, lhs_high, shift_value); |
| 1492 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 1493 | __ Srl(dst_low, lhs_low, shift_value); |
| 1494 | __ Or(dst_low, dst_low, TMP); |
| 1495 | } |
| 1496 | } else { |
| 1497 | shift_value -= kMipsBitsPerWord; |
| 1498 | if (instr->IsShl()) { |
| 1499 | __ Sll(dst_high, lhs_low, shift_value); |
| 1500 | __ Move(dst_low, ZERO); |
| 1501 | } else if (instr->IsShr()) { |
| 1502 | __ Sra(dst_low, lhs_high, shift_value); |
| 1503 | __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1); |
| 1504 | } else { |
| 1505 | __ Srl(dst_low, lhs_high, shift_value); |
| 1506 | __ Move(dst_high, ZERO); |
| 1507 | } |
| 1508 | } |
| 1509 | } else { |
| 1510 | MipsLabel done; |
| 1511 | if (instr->IsShl()) { |
| 1512 | __ Sllv(dst_low, lhs_low, rhs_reg); |
| 1513 | __ Nor(AT, ZERO, rhs_reg); |
| 1514 | __ Srl(TMP, lhs_low, 1); |
| 1515 | __ Srlv(TMP, TMP, AT); |
| 1516 | __ Sllv(dst_high, lhs_high, rhs_reg); |
| 1517 | __ Or(dst_high, dst_high, TMP); |
| 1518 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 1519 | __ Beqz(TMP, &done); |
| 1520 | __ Move(dst_high, dst_low); |
| 1521 | __ Move(dst_low, ZERO); |
| 1522 | } else if (instr->IsShr()) { |
| 1523 | __ Srav(dst_high, lhs_high, rhs_reg); |
| 1524 | __ Nor(AT, ZERO, rhs_reg); |
| 1525 | __ Sll(TMP, lhs_high, 1); |
| 1526 | __ Sllv(TMP, TMP, AT); |
| 1527 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 1528 | __ Or(dst_low, dst_low, TMP); |
| 1529 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 1530 | __ Beqz(TMP, &done); |
| 1531 | __ Move(dst_low, dst_high); |
| 1532 | __ Sra(dst_high, dst_high, 31); |
| 1533 | } else { |
| 1534 | __ Srlv(dst_high, lhs_high, rhs_reg); |
| 1535 | __ Nor(AT, ZERO, rhs_reg); |
| 1536 | __ Sll(TMP, lhs_high, 1); |
| 1537 | __ Sllv(TMP, TMP, AT); |
| 1538 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 1539 | __ Or(dst_low, dst_low, TMP); |
| 1540 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 1541 | __ Beqz(TMP, &done); |
| 1542 | __ Move(dst_low, dst_high); |
| 1543 | __ Move(dst_high, ZERO); |
| 1544 | } |
| 1545 | __ Bind(&done); |
| 1546 | } |
| 1547 | break; |
| 1548 | } |
| 1549 | |
| 1550 | default: |
| 1551 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 1552 | } |
| 1553 | } |
| 1554 | |
| 1555 | void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) { |
| 1556 | HandleBinaryOp(instruction); |
| 1557 | } |
| 1558 | |
| 1559 | void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) { |
| 1560 | HandleBinaryOp(instruction); |
| 1561 | } |
| 1562 | |
| 1563 | void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) { |
| 1564 | HandleBinaryOp(instruction); |
| 1565 | } |
| 1566 | |
| 1567 | void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) { |
| 1568 | HandleBinaryOp(instruction); |
| 1569 | } |
| 1570 | |
| 1571 | void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) { |
| 1572 | LocationSummary* locations = |
| 1573 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1574 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1575 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1576 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 1577 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1578 | } else { |
| 1579 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1580 | } |
| 1581 | } |
| 1582 | |
| 1583 | void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) { |
| 1584 | LocationSummary* locations = instruction->GetLocations(); |
| 1585 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 1586 | Location index = locations->InAt(1); |
| 1587 | Primitive::Type type = instruction->GetType(); |
| 1588 | |
| 1589 | switch (type) { |
| 1590 | case Primitive::kPrimBoolean: { |
| 1591 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 1592 | Register out = locations->Out().AsRegister<Register>(); |
| 1593 | if (index.IsConstant()) { |
| 1594 | size_t offset = |
| 1595 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
| 1596 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); |
| 1597 | } else { |
| 1598 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
| 1599 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 1600 | } |
| 1601 | break; |
| 1602 | } |
| 1603 | |
| 1604 | case Primitive::kPrimByte: { |
| 1605 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
| 1606 | Register out = locations->Out().AsRegister<Register>(); |
| 1607 | if (index.IsConstant()) { |
| 1608 | size_t offset = |
| 1609 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
| 1610 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset); |
| 1611 | } else { |
| 1612 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
| 1613 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset); |
| 1614 | } |
| 1615 | break; |
| 1616 | } |
| 1617 | |
| 1618 | case Primitive::kPrimShort: { |
| 1619 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
| 1620 | Register out = locations->Out().AsRegister<Register>(); |
| 1621 | if (index.IsConstant()) { |
| 1622 | size_t offset = |
| 1623 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 1624 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); |
| 1625 | } else { |
| 1626 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_2); |
| 1627 | __ Addu(TMP, obj, TMP); |
| 1628 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset); |
| 1629 | } |
| 1630 | break; |
| 1631 | } |
| 1632 | |
| 1633 | case Primitive::kPrimChar: { |
| 1634 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 1635 | Register out = locations->Out().AsRegister<Register>(); |
| 1636 | if (index.IsConstant()) { |
| 1637 | size_t offset = |
| 1638 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 1639 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); |
| 1640 | } else { |
| 1641 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_2); |
| 1642 | __ Addu(TMP, obj, TMP); |
| 1643 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 1644 | } |
| 1645 | break; |
| 1646 | } |
| 1647 | |
| 1648 | case Primitive::kPrimInt: |
| 1649 | case Primitive::kPrimNot: { |
| 1650 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
| 1651 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 1652 | Register out = locations->Out().AsRegister<Register>(); |
| 1653 | if (index.IsConstant()) { |
| 1654 | size_t offset = |
| 1655 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 1656 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 1657 | } else { |
| 1658 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_4); |
| 1659 | __ Addu(TMP, obj, TMP); |
| 1660 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset); |
| 1661 | } |
| 1662 | break; |
| 1663 | } |
| 1664 | |
| 1665 | case Primitive::kPrimLong: { |
| 1666 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 1667 | Register out = locations->Out().AsRegisterPairLow<Register>(); |
| 1668 | if (index.IsConstant()) { |
| 1669 | size_t offset = |
| 1670 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 1671 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset); |
| 1672 | } else { |
| 1673 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_8); |
| 1674 | __ Addu(TMP, obj, TMP); |
| 1675 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset); |
| 1676 | } |
| 1677 | break; |
| 1678 | } |
| 1679 | |
| 1680 | case Primitive::kPrimFloat: { |
| 1681 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 1682 | FRegister out = locations->Out().AsFpuRegister<FRegister>(); |
| 1683 | if (index.IsConstant()) { |
| 1684 | size_t offset = |
| 1685 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 1686 | __ LoadSFromOffset(out, obj, offset); |
| 1687 | } else { |
| 1688 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_4); |
| 1689 | __ Addu(TMP, obj, TMP); |
| 1690 | __ LoadSFromOffset(out, TMP, data_offset); |
| 1691 | } |
| 1692 | break; |
| 1693 | } |
| 1694 | |
| 1695 | case Primitive::kPrimDouble: { |
| 1696 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 1697 | FRegister out = locations->Out().AsFpuRegister<FRegister>(); |
| 1698 | if (index.IsConstant()) { |
| 1699 | size_t offset = |
| 1700 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 1701 | __ LoadDFromOffset(out, obj, offset); |
| 1702 | } else { |
| 1703 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_8); |
| 1704 | __ Addu(TMP, obj, TMP); |
| 1705 | __ LoadDFromOffset(out, TMP, data_offset); |
| 1706 | } |
| 1707 | break; |
| 1708 | } |
| 1709 | |
| 1710 | case Primitive::kPrimVoid: |
| 1711 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 1712 | UNREACHABLE(); |
| 1713 | } |
| 1714 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1715 | } |
| 1716 | |
| 1717 | void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) { |
| 1718 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1719 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1720 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1721 | } |
| 1722 | |
| 1723 | void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) { |
| 1724 | LocationSummary* locations = instruction->GetLocations(); |
| 1725 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
| 1726 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 1727 | Register out = locations->Out().AsRegister<Register>(); |
| 1728 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 1729 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1730 | } |
| 1731 | |
| 1732 | void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) { |
| 1733 | Primitive::Type value_type = instruction->GetComponentType(); |
| 1734 | bool is_object = value_type == Primitive::kPrimNot; |
| 1735 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 1736 | instruction, |
| 1737 | is_object ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 1738 | if (is_object) { |
| 1739 | InvokeRuntimeCallingConvention calling_convention; |
| 1740 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1741 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1742 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1743 | } else { |
| 1744 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1745 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1746 | if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
| 1747 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 1748 | } else { |
| 1749 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1750 | } |
| 1751 | } |
| 1752 | } |
| 1753 | |
| 1754 | void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) { |
| 1755 | LocationSummary* locations = instruction->GetLocations(); |
| 1756 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 1757 | Location index = locations->InAt(1); |
| 1758 | Primitive::Type value_type = instruction->GetComponentType(); |
| 1759 | bool needs_runtime_call = locations->WillCall(); |
| 1760 | bool needs_write_barrier = |
| 1761 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 1762 | |
| 1763 | switch (value_type) { |
| 1764 | case Primitive::kPrimBoolean: |
| 1765 | case Primitive::kPrimByte: { |
| 1766 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 1767 | Register value = locations->InAt(2).AsRegister<Register>(); |
| 1768 | if (index.IsConstant()) { |
| 1769 | size_t offset = |
| 1770 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
| 1771 | __ StoreToOffset(kStoreByte, value, obj, offset); |
| 1772 | } else { |
| 1773 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
| 1774 | __ StoreToOffset(kStoreByte, value, TMP, data_offset); |
| 1775 | } |
| 1776 | break; |
| 1777 | } |
| 1778 | |
| 1779 | case Primitive::kPrimShort: |
| 1780 | case Primitive::kPrimChar: { |
| 1781 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 1782 | Register value = locations->InAt(2).AsRegister<Register>(); |
| 1783 | if (index.IsConstant()) { |
| 1784 | size_t offset = |
| 1785 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 1786 | __ StoreToOffset(kStoreHalfword, value, obj, offset); |
| 1787 | } else { |
| 1788 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_2); |
| 1789 | __ Addu(TMP, obj, TMP); |
| 1790 | __ StoreToOffset(kStoreHalfword, value, TMP, data_offset); |
| 1791 | } |
| 1792 | break; |
| 1793 | } |
| 1794 | |
| 1795 | case Primitive::kPrimInt: |
| 1796 | case Primitive::kPrimNot: { |
| 1797 | if (!needs_runtime_call) { |
| 1798 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 1799 | Register value = locations->InAt(2).AsRegister<Register>(); |
| 1800 | if (index.IsConstant()) { |
| 1801 | size_t offset = |
| 1802 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 1803 | __ StoreToOffset(kStoreWord, value, obj, offset); |
| 1804 | } else { |
| 1805 | DCHECK(index.IsRegister()) << index; |
| 1806 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_4); |
| 1807 | __ Addu(TMP, obj, TMP); |
| 1808 | __ StoreToOffset(kStoreWord, value, TMP, data_offset); |
| 1809 | } |
| 1810 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1811 | if (needs_write_barrier) { |
| 1812 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 1813 | codegen_->MarkGCCard(obj, value); |
| 1814 | } |
| 1815 | } else { |
| 1816 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 1817 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 1818 | instruction, |
| 1819 | instruction->GetDexPc(), |
| 1820 | nullptr, |
| 1821 | IsDirectEntrypoint(kQuickAputObject)); |
| 1822 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 1823 | } |
| 1824 | break; |
| 1825 | } |
| 1826 | |
| 1827 | case Primitive::kPrimLong: { |
| 1828 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 1829 | Register value = locations->InAt(2).AsRegisterPairLow<Register>(); |
| 1830 | if (index.IsConstant()) { |
| 1831 | size_t offset = |
| 1832 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 1833 | __ StoreToOffset(kStoreDoubleword, value, obj, offset); |
| 1834 | } else { |
| 1835 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_8); |
| 1836 | __ Addu(TMP, obj, TMP); |
| 1837 | __ StoreToOffset(kStoreDoubleword, value, TMP, data_offset); |
| 1838 | } |
| 1839 | break; |
| 1840 | } |
| 1841 | |
| 1842 | case Primitive::kPrimFloat: { |
| 1843 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 1844 | FRegister value = locations->InAt(2).AsFpuRegister<FRegister>(); |
| 1845 | DCHECK(locations->InAt(2).IsFpuRegister()); |
| 1846 | if (index.IsConstant()) { |
| 1847 | size_t offset = |
| 1848 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 1849 | __ StoreSToOffset(value, obj, offset); |
| 1850 | } else { |
| 1851 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_4); |
| 1852 | __ Addu(TMP, obj, TMP); |
| 1853 | __ StoreSToOffset(value, TMP, data_offset); |
| 1854 | } |
| 1855 | break; |
| 1856 | } |
| 1857 | |
| 1858 | case Primitive::kPrimDouble: { |
| 1859 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 1860 | FRegister value = locations->InAt(2).AsFpuRegister<FRegister>(); |
| 1861 | DCHECK(locations->InAt(2).IsFpuRegister()); |
| 1862 | if (index.IsConstant()) { |
| 1863 | size_t offset = |
| 1864 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 1865 | __ StoreDToOffset(value, obj, offset); |
| 1866 | } else { |
| 1867 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_8); |
| 1868 | __ Addu(TMP, obj, TMP); |
| 1869 | __ StoreDToOffset(value, TMP, data_offset); |
| 1870 | } |
| 1871 | break; |
| 1872 | } |
| 1873 | |
| 1874 | case Primitive::kPrimVoid: |
| 1875 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 1876 | UNREACHABLE(); |
| 1877 | } |
| 1878 | |
| 1879 | // Ints and objects are handled in the switch. |
| 1880 | if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) { |
| 1881 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1882 | } |
| 1883 | } |
| 1884 | |
| 1885 | void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 1886 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 1887 | ? LocationSummary::kCallOnSlowPath |
| 1888 | : LocationSummary::kNoCall; |
| 1889 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 1890 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1891 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1892 | if (instruction->HasUses()) { |
| 1893 | locations->SetOut(Location::SameAsFirstInput()); |
| 1894 | } |
| 1895 | } |
| 1896 | |
| 1897 | void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 1898 | LocationSummary* locations = instruction->GetLocations(); |
| 1899 | BoundsCheckSlowPathMIPS* slow_path = |
| 1900 | new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS(instruction); |
| 1901 | codegen_->AddSlowPath(slow_path); |
| 1902 | |
| 1903 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 1904 | Register length = locations->InAt(1).AsRegister<Register>(); |
| 1905 | |
| 1906 | // length is limited by the maximum positive signed 32-bit integer. |
| 1907 | // Unsigned comparison of length and index checks for index < 0 |
| 1908 | // and for length <= index simultaneously. |
| 1909 | __ Bgeu(index, length, slow_path->GetEntryLabel()); |
| 1910 | } |
| 1911 | |
| 1912 | void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) { |
| 1913 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 1914 | instruction, |
| 1915 | LocationSummary::kCallOnSlowPath); |
| 1916 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1917 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1918 | // Note that TypeCheckSlowPathMIPS uses this register too. |
| 1919 | locations->AddTemp(Location::RequiresRegister()); |
| 1920 | } |
| 1921 | |
| 1922 | void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) { |
| 1923 | LocationSummary* locations = instruction->GetLocations(); |
| 1924 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 1925 | Register cls = locations->InAt(1).AsRegister<Register>(); |
| 1926 | Register obj_cls = locations->GetTemp(0).AsRegister<Register>(); |
| 1927 | |
| 1928 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction); |
| 1929 | codegen_->AddSlowPath(slow_path); |
| 1930 | |
| 1931 | // TODO: avoid this check if we know obj is not null. |
| 1932 | __ Beqz(obj, slow_path->GetExitLabel()); |
| 1933 | // Compare the class of `obj` with `cls`. |
| 1934 | __ LoadFromOffset(kLoadWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value()); |
| 1935 | __ Bne(obj_cls, cls, slow_path->GetEntryLabel()); |
| 1936 | __ Bind(slow_path->GetExitLabel()); |
| 1937 | } |
| 1938 | |
| 1939 | void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 1940 | LocationSummary* locations = |
| 1941 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 1942 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1943 | if (check->HasUses()) { |
| 1944 | locations->SetOut(Location::SameAsFirstInput()); |
| 1945 | } |
| 1946 | } |
| 1947 | |
| 1948 | void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 1949 | // We assume the class is not null. |
| 1950 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS( |
| 1951 | check->GetLoadClass(), |
| 1952 | check, |
| 1953 | check->GetDexPc(), |
| 1954 | true); |
| 1955 | codegen_->AddSlowPath(slow_path); |
| 1956 | GenerateClassInitializationCheck(slow_path, |
| 1957 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
| 1958 | } |
| 1959 | |
| 1960 | void LocationsBuilderMIPS::VisitCompare(HCompare* compare) { |
| 1961 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 1962 | |
| 1963 | LocationSummary::CallKind call_kind = Primitive::IsFloatingPointType(in_type) |
| 1964 | ? LocationSummary::kCall |
| 1965 | : LocationSummary::kNoCall; |
| 1966 | |
| 1967 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(compare, call_kind); |
| 1968 | |
| 1969 | switch (in_type) { |
| 1970 | case Primitive::kPrimLong: |
| 1971 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1972 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1973 | // Output overlaps because it is written before doing the low comparison. |
| 1974 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 1975 | break; |
| 1976 | |
| 1977 | case Primitive::kPrimFloat: |
| 1978 | case Primitive::kPrimDouble: { |
| 1979 | InvokeRuntimeCallingConvention calling_convention; |
| 1980 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 1981 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 1982 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimInt)); |
| 1983 | break; |
| 1984 | } |
| 1985 | |
| 1986 | default: |
| 1987 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 1988 | } |
| 1989 | } |
| 1990 | |
| 1991 | void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) { |
| 1992 | LocationSummary* locations = instruction->GetLocations(); |
| 1993 | Primitive::Type in_type = instruction->InputAt(0)->GetType(); |
| 1994 | |
| 1995 | // 0 if: left == right |
| 1996 | // 1 if: left > right |
| 1997 | // -1 if: left < right |
| 1998 | switch (in_type) { |
| 1999 | case Primitive::kPrimLong: { |
| 2000 | MipsLabel done; |
| 2001 | Register res = locations->Out().AsRegister<Register>(); |
| 2002 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2003 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 2004 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 2005 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 2006 | // TODO: more efficient (direct) comparison with a constant. |
| 2007 | __ Slt(TMP, lhs_high, rhs_high); |
| 2008 | __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt. |
| 2009 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 2010 | __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal. |
| 2011 | __ Sltu(TMP, lhs_low, rhs_low); |
| 2012 | __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt. |
| 2013 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 2014 | __ Bind(&done); |
| 2015 | break; |
| 2016 | } |
| 2017 | |
| 2018 | case Primitive::kPrimFloat: |
| 2019 | case Primitive::kPrimDouble: { |
| 2020 | int32_t entry_point_offset; |
| 2021 | bool direct; |
| 2022 | if (in_type == Primitive::kPrimFloat) { |
| 2023 | if (instruction->IsGtBias()) { |
| 2024 | entry_point_offset = QUICK_ENTRY_POINT(pCmpgFloat); |
| 2025 | direct = IsDirectEntrypoint(kQuickCmpgFloat); |
| 2026 | } else { |
| 2027 | entry_point_offset = QUICK_ENTRY_POINT(pCmplFloat); |
| 2028 | direct = IsDirectEntrypoint(kQuickCmplFloat); |
| 2029 | } |
| 2030 | } else { |
| 2031 | if (instruction->IsGtBias()) { |
| 2032 | entry_point_offset = QUICK_ENTRY_POINT(pCmpgDouble); |
| 2033 | direct = IsDirectEntrypoint(kQuickCmpgDouble); |
| 2034 | } else { |
| 2035 | entry_point_offset = QUICK_ENTRY_POINT(pCmplDouble); |
| 2036 | direct = IsDirectEntrypoint(kQuickCmplDouble); |
| 2037 | } |
| 2038 | } |
| 2039 | codegen_->InvokeRuntime(entry_point_offset, |
| 2040 | instruction, |
| 2041 | instruction->GetDexPc(), |
| 2042 | nullptr, |
| 2043 | direct); |
| 2044 | if (in_type == Primitive::kPrimFloat) { |
| 2045 | if (instruction->IsGtBias()) { |
| 2046 | CheckEntrypointTypes<kQuickCmpgFloat, int32_t, float, float>(); |
| 2047 | } else { |
| 2048 | CheckEntrypointTypes<kQuickCmplFloat, int32_t, float, float>(); |
| 2049 | } |
| 2050 | } else { |
| 2051 | if (instruction->IsGtBias()) { |
| 2052 | CheckEntrypointTypes<kQuickCmpgDouble, int32_t, double, double>(); |
| 2053 | } else { |
| 2054 | CheckEntrypointTypes<kQuickCmplDouble, int32_t, double, double>(); |
| 2055 | } |
| 2056 | } |
| 2057 | break; |
| 2058 | } |
| 2059 | |
| 2060 | default: |
| 2061 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2062 | } |
| 2063 | } |
| 2064 | |
| 2065 | void LocationsBuilderMIPS::VisitCondition(HCondition* instruction) { |
| 2066 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2067 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2068 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2069 | if (instruction->NeedsMaterialization()) { |
| 2070 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2071 | } |
| 2072 | } |
| 2073 | |
| 2074 | void InstructionCodeGeneratorMIPS::VisitCondition(HCondition* instruction) { |
| 2075 | if (!instruction->NeedsMaterialization()) { |
| 2076 | return; |
| 2077 | } |
| 2078 | // TODO: generalize to long |
| 2079 | DCHECK_NE(instruction->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 2080 | |
| 2081 | LocationSummary* locations = instruction->GetLocations(); |
| 2082 | Register dst = locations->Out().AsRegister<Register>(); |
| 2083 | |
| 2084 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2085 | Location rhs_location = locations->InAt(1); |
| 2086 | |
| 2087 | Register rhs_reg = ZERO; |
| 2088 | int64_t rhs_imm = 0; |
| 2089 | bool use_imm = rhs_location.IsConstant(); |
| 2090 | if (use_imm) { |
| 2091 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 2092 | } else { |
| 2093 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 2094 | } |
| 2095 | |
| 2096 | IfCondition if_cond = instruction->GetCondition(); |
| 2097 | |
| 2098 | switch (if_cond) { |
| 2099 | case kCondEQ: |
| 2100 | case kCondNE: |
| 2101 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 2102 | __ Xori(dst, lhs, rhs_imm); |
| 2103 | } else { |
| 2104 | if (use_imm) { |
| 2105 | rhs_reg = TMP; |
| 2106 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2107 | } |
| 2108 | __ Xor(dst, lhs, rhs_reg); |
| 2109 | } |
| 2110 | if (if_cond == kCondEQ) { |
| 2111 | __ Sltiu(dst, dst, 1); |
| 2112 | } else { |
| 2113 | __ Sltu(dst, ZERO, dst); |
| 2114 | } |
| 2115 | break; |
| 2116 | |
| 2117 | case kCondLT: |
| 2118 | case kCondGE: |
| 2119 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 2120 | __ Slti(dst, lhs, rhs_imm); |
| 2121 | } else { |
| 2122 | if (use_imm) { |
| 2123 | rhs_reg = TMP; |
| 2124 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2125 | } |
| 2126 | __ Slt(dst, lhs, rhs_reg); |
| 2127 | } |
| 2128 | if (if_cond == kCondGE) { |
| 2129 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 2130 | // only the slt instruction but no sge. |
| 2131 | __ Xori(dst, dst, 1); |
| 2132 | } |
| 2133 | break; |
| 2134 | |
| 2135 | case kCondLE: |
| 2136 | case kCondGT: |
| 2137 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 2138 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 2139 | __ Slti(dst, lhs, rhs_imm + 1); |
| 2140 | if (if_cond == kCondGT) { |
| 2141 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 2142 | // only the slti instruction but no sgti. |
| 2143 | __ Xori(dst, dst, 1); |
| 2144 | } |
| 2145 | } else { |
| 2146 | if (use_imm) { |
| 2147 | rhs_reg = TMP; |
| 2148 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2149 | } |
| 2150 | __ Slt(dst, rhs_reg, lhs); |
| 2151 | if (if_cond == kCondLE) { |
| 2152 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 2153 | // only the slt instruction but no sle. |
| 2154 | __ Xori(dst, dst, 1); |
| 2155 | } |
| 2156 | } |
| 2157 | break; |
| 2158 | |
| 2159 | case kCondB: |
| 2160 | case kCondAE: |
| 2161 | // Use sltiu instruction if rhs_imm is in range [0, 32767] or in |
| 2162 | // [max_unsigned - 32767 = 0xffff8000, max_unsigned = 0xffffffff]. |
| 2163 | if (use_imm && |
| 2164 | (IsUint<15>(rhs_imm) || |
| 2165 | IsUint<15>(rhs_imm - (MaxInt<uint64_t>(32) - MaxInt<uint64_t>(15))))) { |
| 2166 | if (IsUint<15>(rhs_imm)) { |
| 2167 | __ Sltiu(dst, lhs, rhs_imm); |
| 2168 | } else { |
| 2169 | // 16-bit value (in range [0x8000, 0xffff]) passed to sltiu is sign-extended |
| 2170 | // and then used as unsigned integer (range [0xffff8000, 0xffffffff]). |
| 2171 | __ Sltiu(dst, lhs, rhs_imm - (MaxInt<uint64_t>(32) - MaxInt<uint64_t>(16))); |
| 2172 | } |
| 2173 | } else { |
| 2174 | if (use_imm) { |
| 2175 | rhs_reg = TMP; |
| 2176 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2177 | } |
| 2178 | __ Sltu(dst, lhs, rhs_reg); |
| 2179 | } |
| 2180 | if (if_cond == kCondAE) { |
| 2181 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 2182 | // only the sltu instruction but no sgeu. |
| 2183 | __ Xori(dst, dst, 1); |
| 2184 | } |
| 2185 | break; |
| 2186 | |
| 2187 | case kCondBE: |
| 2188 | case kCondA: |
| 2189 | // Use sltiu instruction if rhs_imm is in range [0, 32766] or in |
| 2190 | // [max_unsigned - 32767 - 1 = 0xffff7fff, max_unsigned - 1 = 0xfffffffe]. |
| 2191 | // lhs <= rhs is simulated via lhs < rhs + 1. |
| 2192 | if (use_imm && (rhs_imm != -1) && |
| 2193 | (IsUint<15>(rhs_imm + 1) || |
| 2194 | IsUint<15>(rhs_imm + 1 - (MaxInt<uint64_t>(32) - MaxInt<uint64_t>(15))))) { |
| 2195 | if (IsUint<15>(rhs_imm + 1)) { |
| 2196 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 2197 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 2198 | } else { |
| 2199 | // 16-bit value (in range [0x8000, 0xffff]) passed to sltiu is sign-extended |
| 2200 | // and then used as unsigned integer (range [0xffff8000, 0xffffffff] where rhs_imm |
| 2201 | // is in range [0xffff7fff, 0xfffffffe] since lhs <= rhs is simulated via lhs < rhs + 1). |
| 2202 | __ Sltiu(dst, lhs, rhs_imm + 1 - (MaxInt<uint64_t>(32) - MaxInt<uint64_t>(16))); |
| 2203 | } |
| 2204 | if (if_cond == kCondA) { |
| 2205 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 2206 | // only the sltiu instruction but no sgtiu. |
| 2207 | __ Xori(dst, dst, 1); |
| 2208 | } |
| 2209 | } else { |
| 2210 | if (use_imm) { |
| 2211 | rhs_reg = TMP; |
| 2212 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2213 | } |
| 2214 | __ Sltu(dst, rhs_reg, lhs); |
| 2215 | if (if_cond == kCondBE) { |
| 2216 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 2217 | // only the sltu instruction but no sleu. |
| 2218 | __ Xori(dst, dst, 1); |
| 2219 | } |
| 2220 | } |
| 2221 | break; |
| 2222 | } |
| 2223 | } |
| 2224 | |
| 2225 | void LocationsBuilderMIPS::VisitDiv(HDiv* div) { |
| 2226 | Primitive::Type type = div->GetResultType(); |
| 2227 | LocationSummary::CallKind call_kind = (type == Primitive::kPrimLong) |
| 2228 | ? LocationSummary::kCall |
| 2229 | : LocationSummary::kNoCall; |
| 2230 | |
| 2231 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2232 | |
| 2233 | switch (type) { |
| 2234 | case Primitive::kPrimInt: |
| 2235 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2236 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2237 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2238 | break; |
| 2239 | |
| 2240 | case Primitive::kPrimLong: { |
| 2241 | InvokeRuntimeCallingConvention calling_convention; |
| 2242 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2243 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2244 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2245 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2246 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 2247 | break; |
| 2248 | } |
| 2249 | |
| 2250 | case Primitive::kPrimFloat: |
| 2251 | case Primitive::kPrimDouble: |
| 2252 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2253 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2254 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2255 | break; |
| 2256 | |
| 2257 | default: |
| 2258 | LOG(FATAL) << "Unexpected div type " << type; |
| 2259 | } |
| 2260 | } |
| 2261 | |
| 2262 | void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) { |
| 2263 | Primitive::Type type = instruction->GetType(); |
| 2264 | LocationSummary* locations = instruction->GetLocations(); |
| 2265 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 2266 | |
| 2267 | switch (type) { |
| 2268 | case Primitive::kPrimInt: { |
| 2269 | Register dst = locations->Out().AsRegister<Register>(); |
| 2270 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2271 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 2272 | if (isR6) { |
| 2273 | __ DivR6(dst, lhs, rhs); |
| 2274 | } else { |
| 2275 | __ DivR2(dst, lhs, rhs); |
| 2276 | } |
| 2277 | break; |
| 2278 | } |
| 2279 | case Primitive::kPrimLong: { |
| 2280 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 2281 | instruction, |
| 2282 | instruction->GetDexPc(), |
| 2283 | nullptr, |
| 2284 | IsDirectEntrypoint(kQuickLdiv)); |
| 2285 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| 2286 | break; |
| 2287 | } |
| 2288 | case Primitive::kPrimFloat: |
| 2289 | case Primitive::kPrimDouble: { |
| 2290 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 2291 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2292 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2293 | if (type == Primitive::kPrimFloat) { |
| 2294 | __ DivS(dst, lhs, rhs); |
| 2295 | } else { |
| 2296 | __ DivD(dst, lhs, rhs); |
| 2297 | } |
| 2298 | break; |
| 2299 | } |
| 2300 | default: |
| 2301 | LOG(FATAL) << "Unexpected div type " << type; |
| 2302 | } |
| 2303 | } |
| 2304 | |
| 2305 | void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2306 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 2307 | ? LocationSummary::kCallOnSlowPath |
| 2308 | : LocationSummary::kNoCall; |
| 2309 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 2310 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 2311 | if (instruction->HasUses()) { |
| 2312 | locations->SetOut(Location::SameAsFirstInput()); |
| 2313 | } |
| 2314 | } |
| 2315 | |
| 2316 | void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2317 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS(instruction); |
| 2318 | codegen_->AddSlowPath(slow_path); |
| 2319 | Location value = instruction->GetLocations()->InAt(0); |
| 2320 | Primitive::Type type = instruction->GetType(); |
| 2321 | |
| 2322 | switch (type) { |
| 2323 | case Primitive::kPrimByte: |
| 2324 | case Primitive::kPrimChar: |
| 2325 | case Primitive::kPrimShort: |
| 2326 | case Primitive::kPrimInt: { |
| 2327 | if (value.IsConstant()) { |
| 2328 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 2329 | __ B(slow_path->GetEntryLabel()); |
| 2330 | } else { |
| 2331 | // A division by a non-null constant is valid. We don't need to perform |
| 2332 | // any check, so simply fall through. |
| 2333 | } |
| 2334 | } else { |
| 2335 | DCHECK(value.IsRegister()) << value; |
| 2336 | __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 2337 | } |
| 2338 | break; |
| 2339 | } |
| 2340 | case Primitive::kPrimLong: { |
| 2341 | if (value.IsConstant()) { |
| 2342 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 2343 | __ B(slow_path->GetEntryLabel()); |
| 2344 | } else { |
| 2345 | // A division by a non-null constant is valid. We don't need to perform |
| 2346 | // any check, so simply fall through. |
| 2347 | } |
| 2348 | } else { |
| 2349 | DCHECK(value.IsRegisterPair()) << value; |
| 2350 | __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>()); |
| 2351 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 2352 | } |
| 2353 | break; |
| 2354 | } |
| 2355 | default: |
| 2356 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
| 2357 | } |
| 2358 | } |
| 2359 | |
| 2360 | void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2361 | LocationSummary* locations = |
| 2362 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2363 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2364 | } |
| 2365 | |
| 2366 | void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 2367 | // Will be generated at use site. |
| 2368 | } |
| 2369 | |
| 2370 | void LocationsBuilderMIPS::VisitExit(HExit* exit) { |
| 2371 | exit->SetLocations(nullptr); |
| 2372 | } |
| 2373 | |
| 2374 | void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 2375 | } |
| 2376 | |
| 2377 | void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) { |
| 2378 | LocationSummary* locations = |
| 2379 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2380 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2381 | } |
| 2382 | |
| 2383 | void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 2384 | // Will be generated at use site. |
| 2385 | } |
| 2386 | |
| 2387 | void LocationsBuilderMIPS::VisitGoto(HGoto* got) { |
| 2388 | got->SetLocations(nullptr); |
| 2389 | } |
| 2390 | |
| 2391 | void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| 2392 | DCHECK(!successor->IsExitBlock()); |
| 2393 | HBasicBlock* block = got->GetBlock(); |
| 2394 | HInstruction* previous = got->GetPrevious(); |
| 2395 | HLoopInformation* info = block->GetLoopInformation(); |
| 2396 | |
| 2397 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| 2398 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2399 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2400 | return; |
| 2401 | } |
| 2402 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2403 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2404 | } |
| 2405 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 2406 | __ B(codegen_->GetLabelOf(successor)); |
| 2407 | } |
| 2408 | } |
| 2409 | |
| 2410 | void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) { |
| 2411 | HandleGoto(got, got->GetSuccessor()); |
| 2412 | } |
| 2413 | |
| 2414 | void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2415 | try_boundary->SetLocations(nullptr); |
| 2416 | } |
| 2417 | |
| 2418 | void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2419 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2420 | if (!successor->IsExitBlock()) { |
| 2421 | HandleGoto(try_boundary, successor); |
| 2422 | } |
| 2423 | } |
| 2424 | |
| 2425 | void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction, |
| 2426 | MipsLabel* true_target, |
| 2427 | MipsLabel* false_target, |
| 2428 | MipsLabel* always_true_target) { |
| 2429 | HInstruction* cond = instruction->InputAt(0); |
| 2430 | HCondition* condition = cond->AsCondition(); |
| 2431 | |
| 2432 | if (cond->IsIntConstant()) { |
| 2433 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 2434 | if (cond_value == 1) { |
| 2435 | if (always_true_target != nullptr) { |
| 2436 | __ B(always_true_target); |
| 2437 | } |
| 2438 | return; |
| 2439 | } else { |
| 2440 | DCHECK_EQ(cond_value, 0); |
| 2441 | } |
| 2442 | } else if (!cond->IsCondition() || condition->NeedsMaterialization()) { |
| 2443 | // The condition instruction has been materialized, compare the output to 0. |
| 2444 | Location cond_val = instruction->GetLocations()->InAt(0); |
| 2445 | DCHECK(cond_val.IsRegister()); |
| 2446 | __ Bnez(cond_val.AsRegister<Register>(), true_target); |
| 2447 | } else { |
| 2448 | // The condition instruction has not been materialized, use its inputs as |
| 2449 | // the comparison and its condition as the branch condition. |
| 2450 | Register lhs = condition->GetLocations()->InAt(0).AsRegister<Register>(); |
| 2451 | Location rhs_location = condition->GetLocations()->InAt(1); |
| 2452 | Register rhs_reg = ZERO; |
| 2453 | int32_t rhs_imm = 0; |
| 2454 | bool use_imm = rhs_location.IsConstant(); |
| 2455 | if (use_imm) { |
| 2456 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 2457 | } else { |
| 2458 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 2459 | } |
| 2460 | |
| 2461 | IfCondition if_cond = condition->GetCondition(); |
| 2462 | if (use_imm && rhs_imm == 0) { |
| 2463 | switch (if_cond) { |
| 2464 | case kCondEQ: |
| 2465 | __ Beqz(lhs, true_target); |
| 2466 | break; |
| 2467 | case kCondNE: |
| 2468 | __ Bnez(lhs, true_target); |
| 2469 | break; |
| 2470 | case kCondLT: |
| 2471 | __ Bltz(lhs, true_target); |
| 2472 | break; |
| 2473 | case kCondGE: |
| 2474 | __ Bgez(lhs, true_target); |
| 2475 | break; |
| 2476 | case kCondLE: |
| 2477 | __ Blez(lhs, true_target); |
| 2478 | break; |
| 2479 | case kCondGT: |
| 2480 | __ Bgtz(lhs, true_target); |
| 2481 | break; |
| 2482 | case kCondB: |
| 2483 | break; // always false |
| 2484 | case kCondBE: |
| 2485 | __ Beqz(lhs, true_target); // <= 0 if zero |
| 2486 | break; |
| 2487 | case kCondA: |
| 2488 | __ Bnez(lhs, true_target); // > 0 if non-zero |
| 2489 | break; |
| 2490 | case kCondAE: |
| 2491 | __ B(true_target); // always true |
| 2492 | break; |
| 2493 | } |
| 2494 | } else { |
| 2495 | if (use_imm) { |
| 2496 | // TODO: more efficient comparison with 16-bit constants without loading them into TMP. |
| 2497 | rhs_reg = TMP; |
| 2498 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2499 | } |
| 2500 | switch (if_cond) { |
| 2501 | case kCondEQ: |
| 2502 | __ Beq(lhs, rhs_reg, true_target); |
| 2503 | break; |
| 2504 | case kCondNE: |
| 2505 | __ Bne(lhs, rhs_reg, true_target); |
| 2506 | break; |
| 2507 | case kCondLT: |
| 2508 | __ Blt(lhs, rhs_reg, true_target); |
| 2509 | break; |
| 2510 | case kCondGE: |
| 2511 | __ Bge(lhs, rhs_reg, true_target); |
| 2512 | break; |
| 2513 | case kCondLE: |
| 2514 | __ Bge(rhs_reg, lhs, true_target); |
| 2515 | break; |
| 2516 | case kCondGT: |
| 2517 | __ Blt(rhs_reg, lhs, true_target); |
| 2518 | break; |
| 2519 | case kCondB: |
| 2520 | __ Bltu(lhs, rhs_reg, true_target); |
| 2521 | break; |
| 2522 | case kCondAE: |
| 2523 | __ Bgeu(lhs, rhs_reg, true_target); |
| 2524 | break; |
| 2525 | case kCondBE: |
| 2526 | __ Bgeu(rhs_reg, lhs, true_target); |
| 2527 | break; |
| 2528 | case kCondA: |
| 2529 | __ Bltu(rhs_reg, lhs, true_target); |
| 2530 | break; |
| 2531 | } |
| 2532 | } |
| 2533 | } |
| 2534 | if (false_target != nullptr) { |
| 2535 | __ B(false_target); |
| 2536 | } |
| 2537 | } |
| 2538 | |
| 2539 | void LocationsBuilderMIPS::VisitIf(HIf* if_instr) { |
| 2540 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 2541 | HInstruction* cond = if_instr->InputAt(0); |
| 2542 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 2543 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2544 | } |
| 2545 | } |
| 2546 | |
| 2547 | void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) { |
| 2548 | MipsLabel* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 2549 | MipsLabel* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 2550 | MipsLabel* always_true_target = true_target; |
| 2551 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 2552 | if_instr->IfTrueSuccessor())) { |
| 2553 | always_true_target = nullptr; |
| 2554 | } |
| 2555 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 2556 | if_instr->IfFalseSuccessor())) { |
| 2557 | false_target = nullptr; |
| 2558 | } |
| 2559 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 2560 | } |
| 2561 | |
| 2562 | void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2563 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2564 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 2565 | HInstruction* cond = deoptimize->InputAt(0); |
| 2566 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 2567 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2568 | } |
| 2569 | } |
| 2570 | |
| 2571 | void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2572 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) |
| 2573 | DeoptimizationSlowPathMIPS(deoptimize); |
| 2574 | codegen_->AddSlowPath(slow_path); |
| 2575 | MipsLabel* slow_path_entry = slow_path->GetEntryLabel(); |
| 2576 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 2577 | } |
| 2578 | |
| 2579 | void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 2580 | Primitive::Type field_type = field_info.GetFieldType(); |
| 2581 | bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble); |
| 2582 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
| 2583 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2584 | instruction, generate_volatile ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 2585 | |
| 2586 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2587 | if (generate_volatile) { |
| 2588 | InvokeRuntimeCallingConvention calling_convention; |
| 2589 | // need A0 to hold base + offset |
| 2590 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2591 | if (field_type == Primitive::kPrimLong) { |
| 2592 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimLong)); |
| 2593 | } else { |
| 2594 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2595 | // Need some temp core regs since FP results are returned in core registers |
| 2596 | Location reg = calling_convention.GetReturnLocation(Primitive::kPrimLong); |
| 2597 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>())); |
| 2598 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>())); |
| 2599 | } |
| 2600 | } else { |
| 2601 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2602 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2603 | } else { |
| 2604 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2605 | } |
| 2606 | } |
| 2607 | } |
| 2608 | |
| 2609 | void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction, |
| 2610 | const FieldInfo& field_info, |
| 2611 | uint32_t dex_pc) { |
| 2612 | Primitive::Type type = field_info.GetFieldType(); |
| 2613 | LocationSummary* locations = instruction->GetLocations(); |
| 2614 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2615 | LoadOperandType load_type = kLoadUnsignedByte; |
| 2616 | bool is_volatile = field_info.IsVolatile(); |
| 2617 | |
| 2618 | switch (type) { |
| 2619 | case Primitive::kPrimBoolean: |
| 2620 | load_type = kLoadUnsignedByte; |
| 2621 | break; |
| 2622 | case Primitive::kPrimByte: |
| 2623 | load_type = kLoadSignedByte; |
| 2624 | break; |
| 2625 | case Primitive::kPrimShort: |
| 2626 | load_type = kLoadSignedHalfword; |
| 2627 | break; |
| 2628 | case Primitive::kPrimChar: |
| 2629 | load_type = kLoadUnsignedHalfword; |
| 2630 | break; |
| 2631 | case Primitive::kPrimInt: |
| 2632 | case Primitive::kPrimFloat: |
| 2633 | case Primitive::kPrimNot: |
| 2634 | load_type = kLoadWord; |
| 2635 | break; |
| 2636 | case Primitive::kPrimLong: |
| 2637 | case Primitive::kPrimDouble: |
| 2638 | load_type = kLoadDoubleword; |
| 2639 | break; |
| 2640 | case Primitive::kPrimVoid: |
| 2641 | LOG(FATAL) << "Unreachable type " << type; |
| 2642 | UNREACHABLE(); |
| 2643 | } |
| 2644 | |
| 2645 | if (is_volatile && load_type == kLoadDoubleword) { |
| 2646 | InvokeRuntimeCallingConvention calling_convention; |
| 2647 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), |
| 2648 | obj, field_info.GetFieldOffset().Uint32Value()); |
| 2649 | // Do implicit Null check |
| 2650 | __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0); |
| 2651 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 2652 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pA64Load), |
| 2653 | instruction, |
| 2654 | dex_pc, |
| 2655 | nullptr, |
| 2656 | IsDirectEntrypoint(kQuickA64Load)); |
| 2657 | CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>(); |
| 2658 | if (type == Primitive::kPrimDouble) { |
| 2659 | // Need to move to FP regs since FP results are returned in core registers. |
| 2660 | __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), |
| 2661 | locations->Out().AsFpuRegister<FRegister>()); |
| 2662 | __ Mthc1(locations->GetTemp(2).AsRegister<Register>(), |
| 2663 | locations->Out().AsFpuRegister<FRegister>()); |
| 2664 | } |
| 2665 | } else { |
| 2666 | if (!Primitive::IsFloatingPointType(type)) { |
| 2667 | Register dst; |
| 2668 | if (type == Primitive::kPrimLong) { |
| 2669 | DCHECK(locations->Out().IsRegisterPair()); |
| 2670 | dst = locations->Out().AsRegisterPairLow<Register>(); |
| 2671 | } else { |
| 2672 | DCHECK(locations->Out().IsRegister()); |
| 2673 | dst = locations->Out().AsRegister<Register>(); |
| 2674 | } |
| 2675 | __ LoadFromOffset(load_type, dst, obj, field_info.GetFieldOffset().Uint32Value()); |
| 2676 | } else { |
| 2677 | DCHECK(locations->Out().IsFpuRegister()); |
| 2678 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 2679 | if (type == Primitive::kPrimFloat) { |
| 2680 | __ LoadSFromOffset(dst, obj, field_info.GetFieldOffset().Uint32Value()); |
| 2681 | } else { |
| 2682 | __ LoadDFromOffset(dst, obj, field_info.GetFieldOffset().Uint32Value()); |
| 2683 | } |
| 2684 | } |
| 2685 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2686 | } |
| 2687 | |
| 2688 | if (is_volatile) { |
| 2689 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 2690 | } |
| 2691 | } |
| 2692 | |
| 2693 | void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 2694 | Primitive::Type field_type = field_info.GetFieldType(); |
| 2695 | bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble); |
| 2696 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
| 2697 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2698 | instruction, generate_volatile ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 2699 | |
| 2700 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2701 | if (generate_volatile) { |
| 2702 | InvokeRuntimeCallingConvention calling_convention; |
| 2703 | // need A0 to hold base + offset |
| 2704 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2705 | if (field_type == Primitive::kPrimLong) { |
| 2706 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2707 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2708 | } else { |
| 2709 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2710 | // Pass FP parameters in core registers. |
| 2711 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 2712 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3))); |
| 2713 | } |
| 2714 | } else { |
| 2715 | if (Primitive::IsFloatingPointType(field_type)) { |
| 2716 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2717 | } else { |
| 2718 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2719 | } |
| 2720 | } |
| 2721 | } |
| 2722 | |
| 2723 | void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction, |
| 2724 | const FieldInfo& field_info, |
| 2725 | uint32_t dex_pc) { |
| 2726 | Primitive::Type type = field_info.GetFieldType(); |
| 2727 | LocationSummary* locations = instruction->GetLocations(); |
| 2728 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2729 | StoreOperandType store_type = kStoreByte; |
| 2730 | bool is_volatile = field_info.IsVolatile(); |
| 2731 | |
| 2732 | switch (type) { |
| 2733 | case Primitive::kPrimBoolean: |
| 2734 | case Primitive::kPrimByte: |
| 2735 | store_type = kStoreByte; |
| 2736 | break; |
| 2737 | case Primitive::kPrimShort: |
| 2738 | case Primitive::kPrimChar: |
| 2739 | store_type = kStoreHalfword; |
| 2740 | break; |
| 2741 | case Primitive::kPrimInt: |
| 2742 | case Primitive::kPrimFloat: |
| 2743 | case Primitive::kPrimNot: |
| 2744 | store_type = kStoreWord; |
| 2745 | break; |
| 2746 | case Primitive::kPrimLong: |
| 2747 | case Primitive::kPrimDouble: |
| 2748 | store_type = kStoreDoubleword; |
| 2749 | break; |
| 2750 | case Primitive::kPrimVoid: |
| 2751 | LOG(FATAL) << "Unreachable type " << type; |
| 2752 | UNREACHABLE(); |
| 2753 | } |
| 2754 | |
| 2755 | if (is_volatile) { |
| 2756 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 2757 | } |
| 2758 | |
| 2759 | if (is_volatile && store_type == kStoreDoubleword) { |
| 2760 | InvokeRuntimeCallingConvention calling_convention; |
| 2761 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), |
| 2762 | obj, field_info.GetFieldOffset().Uint32Value()); |
| 2763 | // Do implicit Null check. |
| 2764 | __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0); |
| 2765 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 2766 | if (type == Primitive::kPrimDouble) { |
| 2767 | // Pass FP parameters in core registers. |
| 2768 | __ Mfc1(locations->GetTemp(1).AsRegister<Register>(), |
| 2769 | locations->InAt(1).AsFpuRegister<FRegister>()); |
| 2770 | __ Mfhc1(locations->GetTemp(2).AsRegister<Register>(), |
| 2771 | locations->InAt(1).AsFpuRegister<FRegister>()); |
| 2772 | } |
| 2773 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pA64Store), |
| 2774 | instruction, |
| 2775 | dex_pc, |
| 2776 | nullptr, |
| 2777 | IsDirectEntrypoint(kQuickA64Store)); |
| 2778 | CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>(); |
| 2779 | } else { |
| 2780 | if (!Primitive::IsFloatingPointType(type)) { |
| 2781 | Register src; |
| 2782 | if (type == Primitive::kPrimLong) { |
| 2783 | DCHECK(locations->InAt(1).IsRegisterPair()); |
| 2784 | src = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 2785 | } else { |
| 2786 | DCHECK(locations->InAt(1).IsRegister()); |
| 2787 | src = locations->InAt(1).AsRegister<Register>(); |
| 2788 | } |
| 2789 | __ StoreToOffset(store_type, src, obj, field_info.GetFieldOffset().Uint32Value()); |
| 2790 | } else { |
| 2791 | DCHECK(locations->InAt(1).IsFpuRegister()); |
| 2792 | FRegister src = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2793 | if (type == Primitive::kPrimFloat) { |
| 2794 | __ StoreSToOffset(src, obj, field_info.GetFieldOffset().Uint32Value()); |
| 2795 | } else { |
| 2796 | __ StoreDToOffset(src, obj, field_info.GetFieldOffset().Uint32Value()); |
| 2797 | } |
| 2798 | } |
| 2799 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2800 | } |
| 2801 | |
| 2802 | // TODO: memory barriers? |
| 2803 | if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) { |
| 2804 | DCHECK(locations->InAt(1).IsRegister()); |
| 2805 | Register src = locations->InAt(1).AsRegister<Register>(); |
| 2806 | codegen_->MarkGCCard(obj, src); |
| 2807 | } |
| 2808 | |
| 2809 | if (is_volatile) { |
| 2810 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 2811 | } |
| 2812 | } |
| 2813 | |
| 2814 | void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 2815 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 2816 | } |
| 2817 | |
| 2818 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 2819 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 2820 | } |
| 2821 | |
| 2822 | void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 2823 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 2824 | } |
| 2825 | |
| 2826 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 2827 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 2828 | } |
| 2829 | |
| 2830 | void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
| 2831 | LocationSummary::CallKind call_kind = |
| 2832 | instruction->IsExactCheck() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath; |
| 2833 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 2834 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2835 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2836 | // The output does overlap inputs. |
| 2837 | // Note that TypeCheckSlowPathMIPS uses this register too. |
| 2838 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2839 | } |
| 2840 | |
| 2841 | void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
| 2842 | LocationSummary* locations = instruction->GetLocations(); |
| 2843 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2844 | Register cls = locations->InAt(1).AsRegister<Register>(); |
| 2845 | Register out = locations->Out().AsRegister<Register>(); |
| 2846 | |
| 2847 | MipsLabel done; |
| 2848 | |
| 2849 | // Return 0 if `obj` is null. |
| 2850 | // TODO: Avoid this check if we know `obj` is not null. |
| 2851 | __ Move(out, ZERO); |
| 2852 | __ Beqz(obj, &done); |
| 2853 | |
| 2854 | // Compare the class of `obj` with `cls`. |
| 2855 | __ LoadFromOffset(kLoadWord, out, obj, mirror::Object::ClassOffset().Int32Value()); |
| 2856 | if (instruction->IsExactCheck()) { |
| 2857 | // Classes must be equal for the instanceof to succeed. |
| 2858 | __ Xor(out, out, cls); |
| 2859 | __ Sltiu(out, out, 1); |
| 2860 | } else { |
| 2861 | // If the classes are not equal, we go into a slow path. |
| 2862 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 2863 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction); |
| 2864 | codegen_->AddSlowPath(slow_path); |
| 2865 | __ Bne(out, cls, slow_path->GetEntryLabel()); |
| 2866 | __ LoadConst32(out, 1); |
| 2867 | __ Bind(slow_path->GetExitLabel()); |
| 2868 | } |
| 2869 | |
| 2870 | __ Bind(&done); |
| 2871 | } |
| 2872 | |
| 2873 | void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) { |
| 2874 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 2875 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2876 | } |
| 2877 | |
| 2878 | void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 2879 | // Will be generated at use site. |
| 2880 | } |
| 2881 | |
| 2882 | void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) { |
| 2883 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 2884 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2885 | } |
| 2886 | |
| 2887 | void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 2888 | // Will be generated at use site. |
| 2889 | } |
| 2890 | |
| 2891 | void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) { |
| 2892 | InvokeDexCallingConventionVisitorMIPS calling_convention_visitor; |
| 2893 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 2894 | } |
| 2895 | |
| 2896 | void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2897 | HandleInvoke(invoke); |
| 2898 | // The register T0 is required to be used for the hidden argument in |
| 2899 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
| 2900 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0)); |
| 2901 | } |
| 2902 | |
| 2903 | void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2904 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 2905 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
| 2906 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2907 | invoke->GetImtIndex() % mirror::Class::kImtSize, kMipsPointerSize).Uint32Value(); |
| 2908 | Location receiver = invoke->GetLocations()->InAt(0); |
| 2909 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2910 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsWordSize); |
| 2911 | |
| 2912 | // Set the hidden argument. |
| 2913 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(), |
| 2914 | invoke->GetDexMethodIndex()); |
| 2915 | |
| 2916 | // temp = object->GetClass(); |
| 2917 | if (receiver.IsStackSlot()) { |
| 2918 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 2919 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 2920 | } else { |
| 2921 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
| 2922 | } |
| 2923 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 2924 | // temp = temp->GetImtEntryAt(method_offset); |
| 2925 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 2926 | // T9 = temp->GetEntryPoint(); |
| 2927 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 2928 | // T9(); |
| 2929 | __ Jalr(T9); |
| 2930 | __ Nop(); |
| 2931 | DCHECK(!codegen_->IsLeafMethod()); |
| 2932 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2933 | } |
| 2934 | |
| 2935 | void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 2936 | // TODO: intrinsic function. |
| 2937 | HandleInvoke(invoke); |
| 2938 | } |
| 2939 | |
| 2940 | void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 2941 | // When we do not run baseline, explicit clinit checks triggered by static |
| 2942 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 2943 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
| 2944 | |
| 2945 | // TODO: intrinsic function. |
| 2946 | HandleInvoke(invoke); |
| 2947 | } |
| 2948 | |
| 2949 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen ATTRIBUTE_UNUSED) { |
| 2950 | if (invoke->GetLocations()->Intrinsified()) { |
| 2951 | // TODO: intrinsic function. |
| 2952 | return true; |
| 2953 | } |
| 2954 | return false; |
| 2955 | } |
| 2956 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2957 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch( |
| 2958 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 2959 | MethodReference target_method ATTRIBUTE_UNUSED) { |
| 2960 | switch (desired_dispatch_info.method_load_kind) { |
| 2961 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 2962 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
| 2963 | // TODO: Implement these types. For the moment, we fall back to kDexCacheViaMethod. |
| 2964 | return HInvokeStaticOrDirect::DispatchInfo { |
| 2965 | HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod, |
| 2966 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 2967 | 0u, |
| 2968 | 0u |
| 2969 | }; |
| 2970 | default: |
| 2971 | break; |
| 2972 | } |
| 2973 | switch (desired_dispatch_info.code_ptr_location) { |
| 2974 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 2975 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
| 2976 | // TODO: Implement these types. For the moment, we fall back to kCallArtMethod. |
| 2977 | return HInvokeStaticOrDirect::DispatchInfo { |
| 2978 | desired_dispatch_info.method_load_kind, |
| 2979 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 2980 | desired_dispatch_info.method_load_data, |
| 2981 | 0u |
| 2982 | }; |
| 2983 | default: |
| 2984 | return desired_dispatch_info; |
| 2985 | } |
| 2986 | } |
| 2987 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2988 | void CodeGeneratorMIPS::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 2989 | // All registers are assumed to be correctly set up per the calling convention. |
| 2990 | |
| 2991 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 2992 | switch (invoke->GetMethodLoadKind()) { |
| 2993 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 2994 | // temp = thread->string_init_entrypoint |
| 2995 | __ LoadFromOffset(kLoadWord, |
| 2996 | temp.AsRegister<Register>(), |
| 2997 | TR, |
| 2998 | invoke->GetStringInitOffset()); |
| 2999 | break; |
| 3000 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 3001 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 3002 | break; |
| 3003 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 3004 | __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 3005 | break; |
| 3006 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3007 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3008 | // TODO: Implement these types. |
| 3009 | // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 3010 | LOG(FATAL) << "Unsupported"; |
| 3011 | UNREACHABLE(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3012 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 3013 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 3014 | Register reg = temp.AsRegister<Register>(); |
| 3015 | Register method_reg; |
| 3016 | if (current_method.IsRegister()) { |
| 3017 | method_reg = current_method.AsRegister<Register>(); |
| 3018 | } else { |
| 3019 | // TODO: use the appropriate DCHECK() here if possible. |
| 3020 | // DCHECK(invoke->GetLocations()->Intrinsified()); |
| 3021 | DCHECK(!current_method.IsValid()); |
| 3022 | method_reg = reg; |
| 3023 | __ Lw(reg, SP, kCurrentMethodStackOffset); |
| 3024 | } |
| 3025 | |
| 3026 | // temp = temp->dex_cache_resolved_methods_; |
| 3027 | __ LoadFromOffset(kLoadWord, |
| 3028 | reg, |
| 3029 | method_reg, |
| 3030 | ArtMethod::DexCacheResolvedMethodsOffset(kMipsPointerSize).Int32Value()); |
| 3031 | // temp = temp[index_in_cache] |
| 3032 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 3033 | __ LoadFromOffset(kLoadWord, |
| 3034 | reg, |
| 3035 | reg, |
| 3036 | CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 3037 | break; |
| 3038 | } |
| 3039 | } |
| 3040 | |
| 3041 | switch (invoke->GetCodePtrLocation()) { |
| 3042 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 3043 | __ Jalr(&frame_entry_label_, T9); |
| 3044 | break; |
| 3045 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3046 | // LR = invoke->GetDirectCodePtr(); |
| 3047 | __ LoadConst32(T9, invoke->GetDirectCodePtr()); |
| 3048 | // LR() |
| 3049 | __ Jalr(T9); |
| 3050 | __ Nop(); |
| 3051 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3052 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3053 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
| 3054 | // TODO: Implement these types. |
| 3055 | // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 3056 | LOG(FATAL) << "Unsupported"; |
| 3057 | UNREACHABLE(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3058 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 3059 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
Goran Jakovljevic | 1a87837 | 2015-10-26 14:28:52 +0100 | [diff] [blame] | 3060 | __ LoadFromOffset(kLoadWord, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3061 | T9, |
| 3062 | callee_method.AsRegister<Register>(), |
| 3063 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 3064 | kMipsWordSize).Int32Value()); |
| 3065 | // T9() |
| 3066 | __ Jalr(T9); |
| 3067 | __ Nop(); |
| 3068 | break; |
| 3069 | } |
| 3070 | DCHECK(!IsLeafMethod()); |
| 3071 | } |
| 3072 | |
| 3073 | void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3074 | // When we do not run baseline, explicit clinit checks triggered by static |
| 3075 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 3076 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
| 3077 | |
| 3078 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3079 | return; |
| 3080 | } |
| 3081 | |
| 3082 | LocationSummary* locations = invoke->GetLocations(); |
| 3083 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 3084 | locations->HasTemps() |
| 3085 | ? locations->GetTemp(0) |
| 3086 | : Location::NoLocation()); |
| 3087 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3088 | } |
| 3089 | |
| 3090 | void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 3091 | // TODO: Try to generate intrinsics code. |
| 3092 | LocationSummary* locations = invoke->GetLocations(); |
| 3093 | Location receiver = locations->InAt(0); |
| 3094 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
| 3095 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 3096 | invoke->GetVTableIndex(), kMipsPointerSize).SizeValue(); |
| 3097 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3098 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsWordSize); |
| 3099 | |
| 3100 | // temp = object->GetClass(); |
| 3101 | if (receiver.IsStackSlot()) { |
| 3102 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 3103 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 3104 | } else { |
| 3105 | DCHECK(receiver.IsRegister()); |
| 3106 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
| 3107 | } |
| 3108 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 3109 | // temp = temp->GetMethodAt(method_offset); |
| 3110 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 3111 | // T9 = temp->GetEntryPoint(); |
| 3112 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 3113 | // T9(); |
| 3114 | __ Jalr(T9); |
| 3115 | __ Nop(); |
| 3116 | DCHECK(!codegen_->IsLeafMethod()); |
| 3117 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3118 | } |
| 3119 | |
| 3120 | void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) { |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame^] | 3121 | InvokeRuntimeCallingConvention calling_convention; |
| 3122 | CodeGenerator::CreateLoadClassLocationSummary( |
| 3123 | cls, |
| 3124 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 3125 | Location::RegisterLocation(V0)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) { |
| 3129 | LocationSummary* locations = cls->GetLocations(); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame^] | 3130 | if (cls->NeedsAccessCheck()) { |
| 3131 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 3132 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 3133 | cls, |
| 3134 | cls->GetDexPc(), |
| 3135 | nullptr, |
| 3136 | IsDirectEntrypoint(kQuickInitializeTypeAndVerifyAccess)); |
| 3137 | return; |
| 3138 | } |
| 3139 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3140 | Register out = locations->Out().AsRegister<Register>(); |
| 3141 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 3142 | if (cls->IsReferrersClass()) { |
| 3143 | DCHECK(!cls->CanCallRuntime()); |
| 3144 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 3145 | __ LoadFromOffset(kLoadWord, out, current_method, |
| 3146 | ArtMethod::DeclaringClassOffset().Int32Value()); |
| 3147 | } else { |
| 3148 | DCHECK(cls->CanCallRuntime()); |
| 3149 | __ LoadFromOffset(kLoadWord, out, current_method, |
| 3150 | ArtMethod::DexCacheResolvedTypesOffset(kMipsPointerSize).Int32Value()); |
| 3151 | __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
| 3152 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS( |
| 3153 | cls, |
| 3154 | cls, |
| 3155 | cls->GetDexPc(), |
| 3156 | cls->MustGenerateClinitCheck()); |
| 3157 | codegen_->AddSlowPath(slow_path); |
| 3158 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 3159 | if (cls->MustGenerateClinitCheck()) { |
| 3160 | GenerateClassInitializationCheck(slow_path, out); |
| 3161 | } else { |
| 3162 | __ Bind(slow_path->GetExitLabel()); |
| 3163 | } |
| 3164 | } |
| 3165 | } |
| 3166 | |
| 3167 | static int32_t GetExceptionTlsOffset() { |
| 3168 | return Thread::ExceptionOffset<kMipsWordSize>().Int32Value(); |
| 3169 | } |
| 3170 | |
| 3171 | void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) { |
| 3172 | LocationSummary* locations = |
| 3173 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 3174 | locations->SetOut(Location::RequiresRegister()); |
| 3175 | } |
| 3176 | |
| 3177 | void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) { |
| 3178 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
| 3179 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 3180 | } |
| 3181 | |
| 3182 | void LocationsBuilderMIPS::VisitClearException(HClearException* clear) { |
| 3183 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 3184 | } |
| 3185 | |
| 3186 | void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 3187 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
| 3188 | } |
| 3189 | |
| 3190 | void LocationsBuilderMIPS::VisitLoadLocal(HLoadLocal* load) { |
| 3191 | load->SetLocations(nullptr); |
| 3192 | } |
| 3193 | |
| 3194 | void InstructionCodeGeneratorMIPS::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
| 3195 | // Nothing to do, this is driven by the code generator. |
| 3196 | } |
| 3197 | |
| 3198 | void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) { |
| 3199 | LocationSummary* locations = |
| 3200 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
| 3201 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3202 | locations->SetOut(Location::RequiresRegister()); |
| 3203 | } |
| 3204 | |
| 3205 | void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) { |
| 3206 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS(load); |
| 3207 | codegen_->AddSlowPath(slow_path); |
| 3208 | |
| 3209 | LocationSummary* locations = load->GetLocations(); |
| 3210 | Register out = locations->Out().AsRegister<Register>(); |
| 3211 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 3212 | __ LoadFromOffset(kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
| 3213 | __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value()); |
| 3214 | __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
| 3215 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 3216 | __ Bind(slow_path->GetExitLabel()); |
| 3217 | } |
| 3218 | |
| 3219 | void LocationsBuilderMIPS::VisitLocal(HLocal* local) { |
| 3220 | local->SetLocations(nullptr); |
| 3221 | } |
| 3222 | |
| 3223 | void InstructionCodeGeneratorMIPS::VisitLocal(HLocal* local) { |
| 3224 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 3225 | } |
| 3226 | |
| 3227 | void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) { |
| 3228 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3229 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3230 | } |
| 3231 | |
| 3232 | void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 3233 | // Will be generated at use site. |
| 3234 | } |
| 3235 | |
| 3236 | void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 3237 | LocationSummary* locations = |
| 3238 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3239 | InvokeRuntimeCallingConvention calling_convention; |
| 3240 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3241 | } |
| 3242 | |
| 3243 | void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 3244 | if (instruction->IsEnter()) { |
| 3245 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLockObject), |
| 3246 | instruction, |
| 3247 | instruction->GetDexPc(), |
| 3248 | nullptr, |
| 3249 | IsDirectEntrypoint(kQuickLockObject)); |
| 3250 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 3251 | } else { |
| 3252 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pUnlockObject), |
| 3253 | instruction, |
| 3254 | instruction->GetDexPc(), |
| 3255 | nullptr, |
| 3256 | IsDirectEntrypoint(kQuickUnlockObject)); |
| 3257 | } |
| 3258 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 3259 | } |
| 3260 | |
| 3261 | void LocationsBuilderMIPS::VisitMul(HMul* mul) { |
| 3262 | LocationSummary* locations = |
| 3263 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3264 | switch (mul->GetResultType()) { |
| 3265 | case Primitive::kPrimInt: |
| 3266 | case Primitive::kPrimLong: |
| 3267 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3268 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3269 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3270 | break; |
| 3271 | |
| 3272 | case Primitive::kPrimFloat: |
| 3273 | case Primitive::kPrimDouble: |
| 3274 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3275 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3276 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3277 | break; |
| 3278 | |
| 3279 | default: |
| 3280 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 3281 | } |
| 3282 | } |
| 3283 | |
| 3284 | void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) { |
| 3285 | Primitive::Type type = instruction->GetType(); |
| 3286 | LocationSummary* locations = instruction->GetLocations(); |
| 3287 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3288 | |
| 3289 | switch (type) { |
| 3290 | case Primitive::kPrimInt: { |
| 3291 | Register dst = locations->Out().AsRegister<Register>(); |
| 3292 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 3293 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 3294 | |
| 3295 | if (isR6) { |
| 3296 | __ MulR6(dst, lhs, rhs); |
| 3297 | } else { |
| 3298 | __ MulR2(dst, lhs, rhs); |
| 3299 | } |
| 3300 | break; |
| 3301 | } |
| 3302 | case Primitive::kPrimLong: { |
| 3303 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 3304 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 3305 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3306 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3307 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 3308 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 3309 | |
| 3310 | // Extra checks to protect caused by the existance of A1_A2. |
| 3311 | // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo: |
| 3312 | // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2). |
| 3313 | DCHECK_NE(dst_high, lhs_low); |
| 3314 | DCHECK_NE(dst_high, rhs_low); |
| 3315 | |
| 3316 | // A_B * C_D |
| 3317 | // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ] |
| 3318 | // dst_lo: [ low(B*D) ] |
| 3319 | // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result. |
| 3320 | |
| 3321 | if (isR6) { |
| 3322 | __ MulR6(TMP, lhs_high, rhs_low); |
| 3323 | __ MulR6(dst_high, lhs_low, rhs_high); |
| 3324 | __ Addu(dst_high, dst_high, TMP); |
| 3325 | __ MuhuR6(TMP, lhs_low, rhs_low); |
| 3326 | __ Addu(dst_high, dst_high, TMP); |
| 3327 | __ MulR6(dst_low, lhs_low, rhs_low); |
| 3328 | } else { |
| 3329 | __ MulR2(TMP, lhs_high, rhs_low); |
| 3330 | __ MulR2(dst_high, lhs_low, rhs_high); |
| 3331 | __ Addu(dst_high, dst_high, TMP); |
| 3332 | __ MultuR2(lhs_low, rhs_low); |
| 3333 | __ Mfhi(TMP); |
| 3334 | __ Addu(dst_high, dst_high, TMP); |
| 3335 | __ Mflo(dst_low); |
| 3336 | } |
| 3337 | break; |
| 3338 | } |
| 3339 | case Primitive::kPrimFloat: |
| 3340 | case Primitive::kPrimDouble: { |
| 3341 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 3342 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3343 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3344 | if (type == Primitive::kPrimFloat) { |
| 3345 | __ MulS(dst, lhs, rhs); |
| 3346 | } else { |
| 3347 | __ MulD(dst, lhs, rhs); |
| 3348 | } |
| 3349 | break; |
| 3350 | } |
| 3351 | default: |
| 3352 | LOG(FATAL) << "Unexpected mul type " << type; |
| 3353 | } |
| 3354 | } |
| 3355 | |
| 3356 | void LocationsBuilderMIPS::VisitNeg(HNeg* neg) { |
| 3357 | LocationSummary* locations = |
| 3358 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 3359 | switch (neg->GetResultType()) { |
| 3360 | case Primitive::kPrimInt: |
| 3361 | case Primitive::kPrimLong: |
| 3362 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3363 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3364 | break; |
| 3365 | |
| 3366 | case Primitive::kPrimFloat: |
| 3367 | case Primitive::kPrimDouble: |
| 3368 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3369 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3370 | break; |
| 3371 | |
| 3372 | default: |
| 3373 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3374 | } |
| 3375 | } |
| 3376 | |
| 3377 | void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) { |
| 3378 | Primitive::Type type = instruction->GetType(); |
| 3379 | LocationSummary* locations = instruction->GetLocations(); |
| 3380 | |
| 3381 | switch (type) { |
| 3382 | case Primitive::kPrimInt: { |
| 3383 | Register dst = locations->Out().AsRegister<Register>(); |
| 3384 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 3385 | __ Subu(dst, ZERO, src); |
| 3386 | break; |
| 3387 | } |
| 3388 | case Primitive::kPrimLong: { |
| 3389 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 3390 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 3391 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3392 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3393 | __ Subu(dst_low, ZERO, src_low); |
| 3394 | __ Sltu(TMP, ZERO, dst_low); |
| 3395 | __ Subu(dst_high, ZERO, src_high); |
| 3396 | __ Subu(dst_high, dst_high, TMP); |
| 3397 | break; |
| 3398 | } |
| 3399 | case Primitive::kPrimFloat: |
| 3400 | case Primitive::kPrimDouble: { |
| 3401 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 3402 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3403 | if (type == Primitive::kPrimFloat) { |
| 3404 | __ NegS(dst, src); |
| 3405 | } else { |
| 3406 | __ NegD(dst, src); |
| 3407 | } |
| 3408 | break; |
| 3409 | } |
| 3410 | default: |
| 3411 | LOG(FATAL) << "Unexpected neg type " << type; |
| 3412 | } |
| 3413 | } |
| 3414 | |
| 3415 | void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) { |
| 3416 | LocationSummary* locations = |
| 3417 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3418 | InvokeRuntimeCallingConvention calling_convention; |
| 3419 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3420 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 3421 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 3422 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3423 | } |
| 3424 | |
| 3425 | void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) { |
| 3426 | InvokeRuntimeCallingConvention calling_convention; |
| 3427 | Register current_method_register = calling_convention.GetRegisterAt(2); |
| 3428 | __ Lw(current_method_register, SP, kCurrentMethodStackOffset); |
| 3429 | // Move an uint16_t value to a register. |
| 3430 | __ LoadConst32(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
| 3431 | codegen_->InvokeRuntime( |
| 3432 | GetThreadOffset<kMipsWordSize>(instruction->GetEntrypoint()).Int32Value(), |
| 3433 | instruction, |
| 3434 | instruction->GetDexPc(), |
| 3435 | nullptr, |
| 3436 | IsDirectEntrypoint(kQuickAllocArrayWithAccessCheck)); |
| 3437 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, |
| 3438 | void*, uint32_t, int32_t, ArtMethod*>(); |
| 3439 | } |
| 3440 | |
| 3441 | void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) { |
| 3442 | LocationSummary* locations = |
| 3443 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3444 | InvokeRuntimeCallingConvention calling_convention; |
| 3445 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3446 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3447 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 3448 | } |
| 3449 | |
| 3450 | void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) { |
| 3451 | InvokeRuntimeCallingConvention calling_convention; |
| 3452 | Register current_method_register = calling_convention.GetRegisterAt(1); |
| 3453 | __ Lw(current_method_register, SP, kCurrentMethodStackOffset); |
| 3454 | // Move an uint16_t value to a register. |
| 3455 | __ LoadConst32(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
| 3456 | codegen_->InvokeRuntime( |
| 3457 | GetThreadOffset<kMipsWordSize>(instruction->GetEntrypoint()).Int32Value(), |
| 3458 | instruction, |
| 3459 | instruction->GetDexPc(), |
| 3460 | nullptr, |
| 3461 | IsDirectEntrypoint(kQuickAllocObjectWithAccessCheck)); |
| 3462 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3463 | } |
| 3464 | |
| 3465 | void LocationsBuilderMIPS::VisitNot(HNot* instruction) { |
| 3466 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 3467 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3468 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3469 | } |
| 3470 | |
| 3471 | void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) { |
| 3472 | Primitive::Type type = instruction->GetType(); |
| 3473 | LocationSummary* locations = instruction->GetLocations(); |
| 3474 | |
| 3475 | switch (type) { |
| 3476 | case Primitive::kPrimInt: { |
| 3477 | Register dst = locations->Out().AsRegister<Register>(); |
| 3478 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 3479 | __ Nor(dst, src, ZERO); |
| 3480 | break; |
| 3481 | } |
| 3482 | |
| 3483 | case Primitive::kPrimLong: { |
| 3484 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 3485 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 3486 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3487 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3488 | __ Nor(dst_high, src_high, ZERO); |
| 3489 | __ Nor(dst_low, src_low, ZERO); |
| 3490 | break; |
| 3491 | } |
| 3492 | |
| 3493 | default: |
| 3494 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 3495 | } |
| 3496 | } |
| 3497 | |
| 3498 | void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
| 3499 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 3500 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3501 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3502 | } |
| 3503 | |
| 3504 | void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
| 3505 | LocationSummary* locations = instruction->GetLocations(); |
| 3506 | __ Xori(locations->Out().AsRegister<Register>(), |
| 3507 | locations->InAt(0).AsRegister<Register>(), |
| 3508 | 1); |
| 3509 | } |
| 3510 | |
| 3511 | void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) { |
| 3512 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3513 | ? LocationSummary::kCallOnSlowPath |
| 3514 | : LocationSummary::kNoCall; |
| 3515 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 3516 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3517 | if (instruction->HasUses()) { |
| 3518 | locations->SetOut(Location::SameAsFirstInput()); |
| 3519 | } |
| 3520 | } |
| 3521 | |
| 3522 | void InstructionCodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 3523 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 3524 | return; |
| 3525 | } |
| 3526 | Location obj = instruction->GetLocations()->InAt(0); |
| 3527 | |
| 3528 | __ Lw(ZERO, obj.AsRegister<Register>(), 0); |
| 3529 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3530 | } |
| 3531 | |
| 3532 | void InstructionCodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| 3533 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS(instruction); |
| 3534 | codegen_->AddSlowPath(slow_path); |
| 3535 | |
| 3536 | Location obj = instruction->GetLocations()->InAt(0); |
| 3537 | |
| 3538 | __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 3539 | } |
| 3540 | |
| 3541 | void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) { |
| 3542 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
| 3543 | GenerateImplicitNullCheck(instruction); |
| 3544 | } else { |
| 3545 | GenerateExplicitNullCheck(instruction); |
| 3546 | } |
| 3547 | } |
| 3548 | |
| 3549 | void LocationsBuilderMIPS::VisitOr(HOr* instruction) { |
| 3550 | HandleBinaryOp(instruction); |
| 3551 | } |
| 3552 | |
| 3553 | void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) { |
| 3554 | HandleBinaryOp(instruction); |
| 3555 | } |
| 3556 | |
| 3557 | void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 3558 | LOG(FATAL) << "Unreachable"; |
| 3559 | } |
| 3560 | |
| 3561 | void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) { |
| 3562 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 3563 | } |
| 3564 | |
| 3565 | void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) { |
| 3566 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 3567 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3568 | if (location.IsStackSlot()) { |
| 3569 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3570 | } else if (location.IsDoubleStackSlot()) { |
| 3571 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3572 | } |
| 3573 | locations->SetOut(location); |
| 3574 | } |
| 3575 | |
| 3576 | void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction |
| 3577 | ATTRIBUTE_UNUSED) { |
| 3578 | // Nothing to do, the parameter is already at its location. |
| 3579 | } |
| 3580 | |
| 3581 | void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3582 | LocationSummary* locations = |
| 3583 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3584 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3585 | } |
| 3586 | |
| 3587 | void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction |
| 3588 | ATTRIBUTE_UNUSED) { |
| 3589 | // Nothing to do, the method is already at its location. |
| 3590 | } |
| 3591 | |
| 3592 | void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) { |
| 3593 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 3594 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3595 | locations->SetInAt(i, Location::Any()); |
| 3596 | } |
| 3597 | locations->SetOut(Location::Any()); |
| 3598 | } |
| 3599 | |
| 3600 | void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 3601 | LOG(FATAL) << "Unreachable"; |
| 3602 | } |
| 3603 | |
| 3604 | void LocationsBuilderMIPS::VisitRem(HRem* rem) { |
| 3605 | Primitive::Type type = rem->GetResultType(); |
| 3606 | LocationSummary::CallKind call_kind = |
| 3607 | (type == Primitive::kPrimInt) ? LocationSummary::kNoCall : LocationSummary::kCall; |
| 3608 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 3609 | |
| 3610 | switch (type) { |
| 3611 | case Primitive::kPrimInt: |
| 3612 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3613 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3614 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3615 | break; |
| 3616 | |
| 3617 | case Primitive::kPrimLong: { |
| 3618 | InvokeRuntimeCallingConvention calling_convention; |
| 3619 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3620 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3621 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3622 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3623 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 3624 | break; |
| 3625 | } |
| 3626 | |
| 3627 | case Primitive::kPrimFloat: |
| 3628 | case Primitive::kPrimDouble: { |
| 3629 | InvokeRuntimeCallingConvention calling_convention; |
| 3630 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 3631 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 3632 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 3633 | break; |
| 3634 | } |
| 3635 | |
| 3636 | default: |
| 3637 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3638 | } |
| 3639 | } |
| 3640 | |
| 3641 | void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) { |
| 3642 | Primitive::Type type = instruction->GetType(); |
| 3643 | LocationSummary* locations = instruction->GetLocations(); |
| 3644 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3645 | |
| 3646 | switch (type) { |
| 3647 | case Primitive::kPrimInt: { |
| 3648 | Register dst = locations->Out().AsRegister<Register>(); |
| 3649 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 3650 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 3651 | if (isR6) { |
| 3652 | __ ModR6(dst, lhs, rhs); |
| 3653 | } else { |
| 3654 | __ ModR2(dst, lhs, rhs); |
| 3655 | } |
| 3656 | break; |
| 3657 | } |
| 3658 | case Primitive::kPrimLong: { |
| 3659 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 3660 | instruction, |
| 3661 | instruction->GetDexPc(), |
| 3662 | nullptr, |
| 3663 | IsDirectEntrypoint(kQuickLmod)); |
| 3664 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 3665 | break; |
| 3666 | } |
| 3667 | case Primitive::kPrimFloat: { |
| 3668 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), |
| 3669 | instruction, instruction->GetDexPc(), |
| 3670 | nullptr, |
| 3671 | IsDirectEntrypoint(kQuickFmodf)); |
| 3672 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 3673 | break; |
| 3674 | } |
| 3675 | case Primitive::kPrimDouble: { |
| 3676 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), |
| 3677 | instruction, instruction->GetDexPc(), |
| 3678 | nullptr, |
| 3679 | IsDirectEntrypoint(kQuickFmod)); |
| 3680 | CheckEntrypointTypes<kQuickL2d, double, int64_t>(); |
| 3681 | break; |
| 3682 | } |
| 3683 | default: |
| 3684 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3685 | } |
| 3686 | } |
| 3687 | |
| 3688 | void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3689 | memory_barrier->SetLocations(nullptr); |
| 3690 | } |
| 3691 | |
| 3692 | void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3693 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 3694 | } |
| 3695 | |
| 3696 | void LocationsBuilderMIPS::VisitReturn(HReturn* ret) { |
| 3697 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret); |
| 3698 | Primitive::Type return_type = ret->InputAt(0)->GetType(); |
| 3699 | locations->SetInAt(0, MipsReturnLocation(return_type)); |
| 3700 | } |
| 3701 | |
| 3702 | void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 3703 | codegen_->GenerateFrameExit(); |
| 3704 | } |
| 3705 | |
| 3706 | void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) { |
| 3707 | ret->SetLocations(nullptr); |
| 3708 | } |
| 3709 | |
| 3710 | void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 3711 | codegen_->GenerateFrameExit(); |
| 3712 | } |
| 3713 | |
| 3714 | void LocationsBuilderMIPS::VisitShl(HShl* shl) { |
| 3715 | HandleShift(shl); |
| 3716 | } |
| 3717 | |
| 3718 | void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) { |
| 3719 | HandleShift(shl); |
| 3720 | } |
| 3721 | |
| 3722 | void LocationsBuilderMIPS::VisitShr(HShr* shr) { |
| 3723 | HandleShift(shr); |
| 3724 | } |
| 3725 | |
| 3726 | void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) { |
| 3727 | HandleShift(shr); |
| 3728 | } |
| 3729 | |
| 3730 | void LocationsBuilderMIPS::VisitStoreLocal(HStoreLocal* store) { |
| 3731 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store); |
| 3732 | Primitive::Type field_type = store->InputAt(1)->GetType(); |
| 3733 | switch (field_type) { |
| 3734 | case Primitive::kPrimNot: |
| 3735 | case Primitive::kPrimBoolean: |
| 3736 | case Primitive::kPrimByte: |
| 3737 | case Primitive::kPrimChar: |
| 3738 | case Primitive::kPrimShort: |
| 3739 | case Primitive::kPrimInt: |
| 3740 | case Primitive::kPrimFloat: |
| 3741 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 3742 | break; |
| 3743 | |
| 3744 | case Primitive::kPrimLong: |
| 3745 | case Primitive::kPrimDouble: |
| 3746 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 3747 | break; |
| 3748 | |
| 3749 | default: |
| 3750 | LOG(FATAL) << "Unimplemented local type " << field_type; |
| 3751 | } |
| 3752 | } |
| 3753 | |
| 3754 | void InstructionCodeGeneratorMIPS::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
| 3755 | } |
| 3756 | |
| 3757 | void LocationsBuilderMIPS::VisitSub(HSub* instruction) { |
| 3758 | HandleBinaryOp(instruction); |
| 3759 | } |
| 3760 | |
| 3761 | void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) { |
| 3762 | HandleBinaryOp(instruction); |
| 3763 | } |
| 3764 | |
| 3765 | void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3766 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3767 | } |
| 3768 | |
| 3769 | void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3770 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 3771 | } |
| 3772 | |
| 3773 | void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3774 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3775 | } |
| 3776 | |
| 3777 | void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3778 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 3779 | } |
| 3780 | |
| 3781 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet( |
| 3782 | HUnresolvedInstanceFieldGet* instruction) { |
| 3783 | FieldAccessCallingConventionMIPS calling_convention; |
| 3784 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 3785 | instruction->GetFieldType(), |
| 3786 | calling_convention); |
| 3787 | } |
| 3788 | |
| 3789 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet( |
| 3790 | HUnresolvedInstanceFieldGet* instruction) { |
| 3791 | FieldAccessCallingConventionMIPS calling_convention; |
| 3792 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3793 | instruction->GetFieldType(), |
| 3794 | instruction->GetFieldIndex(), |
| 3795 | instruction->GetDexPc(), |
| 3796 | calling_convention); |
| 3797 | } |
| 3798 | |
| 3799 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet( |
| 3800 | HUnresolvedInstanceFieldSet* instruction) { |
| 3801 | FieldAccessCallingConventionMIPS calling_convention; |
| 3802 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 3803 | instruction->GetFieldType(), |
| 3804 | calling_convention); |
| 3805 | } |
| 3806 | |
| 3807 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet( |
| 3808 | HUnresolvedInstanceFieldSet* instruction) { |
| 3809 | FieldAccessCallingConventionMIPS calling_convention; |
| 3810 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3811 | instruction->GetFieldType(), |
| 3812 | instruction->GetFieldIndex(), |
| 3813 | instruction->GetDexPc(), |
| 3814 | calling_convention); |
| 3815 | } |
| 3816 | |
| 3817 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet( |
| 3818 | HUnresolvedStaticFieldGet* instruction) { |
| 3819 | FieldAccessCallingConventionMIPS calling_convention; |
| 3820 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 3821 | instruction->GetFieldType(), |
| 3822 | calling_convention); |
| 3823 | } |
| 3824 | |
| 3825 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet( |
| 3826 | HUnresolvedStaticFieldGet* instruction) { |
| 3827 | FieldAccessCallingConventionMIPS calling_convention; |
| 3828 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3829 | instruction->GetFieldType(), |
| 3830 | instruction->GetFieldIndex(), |
| 3831 | instruction->GetDexPc(), |
| 3832 | calling_convention); |
| 3833 | } |
| 3834 | |
| 3835 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet( |
| 3836 | HUnresolvedStaticFieldSet* instruction) { |
| 3837 | FieldAccessCallingConventionMIPS calling_convention; |
| 3838 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 3839 | instruction->GetFieldType(), |
| 3840 | calling_convention); |
| 3841 | } |
| 3842 | |
| 3843 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet( |
| 3844 | HUnresolvedStaticFieldSet* instruction) { |
| 3845 | FieldAccessCallingConventionMIPS calling_convention; |
| 3846 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3847 | instruction->GetFieldType(), |
| 3848 | instruction->GetFieldIndex(), |
| 3849 | instruction->GetDexPc(), |
| 3850 | calling_convention); |
| 3851 | } |
| 3852 | |
| 3853 | void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 3854 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 3855 | } |
| 3856 | |
| 3857 | void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 3858 | HBasicBlock* block = instruction->GetBlock(); |
| 3859 | if (block->GetLoopInformation() != nullptr) { |
| 3860 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 3861 | // The back edge will generate the suspend check. |
| 3862 | return; |
| 3863 | } |
| 3864 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 3865 | // The goto will generate the suspend check. |
| 3866 | return; |
| 3867 | } |
| 3868 | GenerateSuspendCheck(instruction, nullptr); |
| 3869 | } |
| 3870 | |
| 3871 | void LocationsBuilderMIPS::VisitTemporary(HTemporary* temp) { |
| 3872 | temp->SetLocations(nullptr); |
| 3873 | } |
| 3874 | |
| 3875 | void InstructionCodeGeneratorMIPS::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) { |
| 3876 | // Nothing to do, this is driven by the code generator. |
| 3877 | } |
| 3878 | |
| 3879 | void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) { |
| 3880 | LocationSummary* locations = |
| 3881 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3882 | InvokeRuntimeCallingConvention calling_convention; |
| 3883 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3884 | } |
| 3885 | |
| 3886 | void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) { |
| 3887 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 3888 | instruction, |
| 3889 | instruction->GetDexPc(), |
| 3890 | nullptr, |
| 3891 | IsDirectEntrypoint(kQuickDeliverException)); |
| 3892 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 3893 | } |
| 3894 | |
| 3895 | void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
| 3896 | Primitive::Type input_type = conversion->GetInputType(); |
| 3897 | Primitive::Type result_type = conversion->GetResultType(); |
| 3898 | DCHECK_NE(input_type, result_type); |
| 3899 | |
| 3900 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 3901 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 3902 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 3903 | } |
| 3904 | |
| 3905 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3906 | if ((Primitive::IsFloatingPointType(result_type) && input_type == Primitive::kPrimLong) || |
| 3907 | (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type))) { |
| 3908 | call_kind = LocationSummary::kCall; |
| 3909 | } |
| 3910 | |
| 3911 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 3912 | |
| 3913 | if (call_kind == LocationSummary::kNoCall) { |
| 3914 | if (Primitive::IsFloatingPointType(input_type)) { |
| 3915 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3916 | } else { |
| 3917 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3918 | } |
| 3919 | |
| 3920 | if (Primitive::IsFloatingPointType(result_type)) { |
| 3921 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3922 | } else { |
| 3923 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3924 | } |
| 3925 | } else { |
| 3926 | InvokeRuntimeCallingConvention calling_convention; |
| 3927 | |
| 3928 | if (Primitive::IsFloatingPointType(input_type)) { |
| 3929 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 3930 | } else { |
| 3931 | DCHECK_EQ(input_type, Primitive::kPrimLong); |
| 3932 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3933 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3934 | } |
| 3935 | |
| 3936 | locations->SetOut(calling_convention.GetReturnLocation(result_type)); |
| 3937 | } |
| 3938 | } |
| 3939 | |
| 3940 | void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
| 3941 | LocationSummary* locations = conversion->GetLocations(); |
| 3942 | Primitive::Type result_type = conversion->GetResultType(); |
| 3943 | Primitive::Type input_type = conversion->GetInputType(); |
| 3944 | bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
| 3945 | |
| 3946 | DCHECK_NE(input_type, result_type); |
| 3947 | |
| 3948 | if (result_type == Primitive::kPrimLong && Primitive::IsIntegralType(input_type)) { |
| 3949 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 3950 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 3951 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 3952 | |
| 3953 | __ Move(dst_low, src); |
| 3954 | __ Sra(dst_high, src, 31); |
| 3955 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
| 3956 | Register dst = locations->Out().AsRegister<Register>(); |
| 3957 | Register src = (input_type == Primitive::kPrimLong) |
| 3958 | ? locations->InAt(0).AsRegisterPairLow<Register>() |
| 3959 | : locations->InAt(0).AsRegister<Register>(); |
| 3960 | |
| 3961 | switch (result_type) { |
| 3962 | case Primitive::kPrimChar: |
| 3963 | __ Andi(dst, src, 0xFFFF); |
| 3964 | break; |
| 3965 | case Primitive::kPrimByte: |
| 3966 | if (has_sign_extension) { |
| 3967 | __ Seb(dst, src); |
| 3968 | } else { |
| 3969 | __ Sll(dst, src, 24); |
| 3970 | __ Sra(dst, dst, 24); |
| 3971 | } |
| 3972 | break; |
| 3973 | case Primitive::kPrimShort: |
| 3974 | if (has_sign_extension) { |
| 3975 | __ Seh(dst, src); |
| 3976 | } else { |
| 3977 | __ Sll(dst, src, 16); |
| 3978 | __ Sra(dst, dst, 16); |
| 3979 | } |
| 3980 | break; |
| 3981 | case Primitive::kPrimInt: |
| 3982 | __ Move(dst, src); |
| 3983 | break; |
| 3984 | |
| 3985 | default: |
| 3986 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3987 | << " to " << result_type; |
| 3988 | } |
| 3989 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
| 3990 | if (input_type != Primitive::kPrimLong) { |
| 3991 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 3992 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 3993 | __ Mtc1(src, FTMP); |
| 3994 | if (result_type == Primitive::kPrimFloat) { |
| 3995 | __ Cvtsw(dst, FTMP); |
| 3996 | } else { |
| 3997 | __ Cvtdw(dst, FTMP); |
| 3998 | } |
| 3999 | } else { |
| 4000 | int32_t entry_offset = (result_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pL2f) |
| 4001 | : QUICK_ENTRY_POINT(pL2d); |
| 4002 | bool direct = (result_type == Primitive::kPrimFloat) ? IsDirectEntrypoint(kQuickL2f) |
| 4003 | : IsDirectEntrypoint(kQuickL2d); |
| 4004 | codegen_->InvokeRuntime(entry_offset, |
| 4005 | conversion, |
| 4006 | conversion->GetDexPc(), |
| 4007 | nullptr, |
| 4008 | direct); |
| 4009 | if (result_type == Primitive::kPrimFloat) { |
| 4010 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 4011 | } else { |
| 4012 | CheckEntrypointTypes<kQuickL2d, double, int64_t>(); |
| 4013 | } |
| 4014 | } |
| 4015 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
| 4016 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
| 4017 | int32_t entry_offset; |
| 4018 | bool direct; |
| 4019 | if (result_type != Primitive::kPrimLong) { |
| 4020 | entry_offset = (input_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pF2iz) |
| 4021 | : QUICK_ENTRY_POINT(pD2iz); |
| 4022 | direct = (result_type == Primitive::kPrimFloat) ? IsDirectEntrypoint(kQuickF2iz) |
| 4023 | : IsDirectEntrypoint(kQuickD2iz); |
| 4024 | } else { |
| 4025 | entry_offset = (input_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pF2l) |
| 4026 | : QUICK_ENTRY_POINT(pD2l); |
| 4027 | direct = (result_type == Primitive::kPrimFloat) ? IsDirectEntrypoint(kQuickF2l) |
| 4028 | : IsDirectEntrypoint(kQuickD2l); |
| 4029 | } |
| 4030 | codegen_->InvokeRuntime(entry_offset, |
| 4031 | conversion, |
| 4032 | conversion->GetDexPc(), |
| 4033 | nullptr, |
| 4034 | direct); |
| 4035 | if (result_type != Primitive::kPrimLong) { |
| 4036 | if (input_type == Primitive::kPrimFloat) { |
| 4037 | CheckEntrypointTypes<kQuickF2iz, int32_t, float>(); |
| 4038 | } else { |
| 4039 | CheckEntrypointTypes<kQuickD2iz, int32_t, double>(); |
| 4040 | } |
| 4041 | } else { |
| 4042 | if (input_type == Primitive::kPrimFloat) { |
| 4043 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 4044 | } else { |
| 4045 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 4046 | } |
| 4047 | } |
| 4048 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 4049 | Primitive::IsFloatingPointType(input_type)) { |
| 4050 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 4051 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 4052 | if (result_type == Primitive::kPrimFloat) { |
| 4053 | __ Cvtsd(dst, src); |
| 4054 | } else { |
| 4055 | __ Cvtds(dst, src); |
| 4056 | } |
| 4057 | } else { |
| 4058 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 4059 | << " to " << result_type; |
| 4060 | } |
| 4061 | } |
| 4062 | |
| 4063 | void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) { |
| 4064 | HandleShift(ushr); |
| 4065 | } |
| 4066 | |
| 4067 | void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) { |
| 4068 | HandleShift(ushr); |
| 4069 | } |
| 4070 | |
| 4071 | void LocationsBuilderMIPS::VisitXor(HXor* instruction) { |
| 4072 | HandleBinaryOp(instruction); |
| 4073 | } |
| 4074 | |
| 4075 | void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) { |
| 4076 | HandleBinaryOp(instruction); |
| 4077 | } |
| 4078 | |
| 4079 | void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 4080 | // Nothing to do, this should be removed during prepare for register allocator. |
| 4081 | LOG(FATAL) << "Unreachable"; |
| 4082 | } |
| 4083 | |
| 4084 | void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 4085 | // Nothing to do, this should be removed during prepare for register allocator. |
| 4086 | LOG(FATAL) << "Unreachable"; |
| 4087 | } |
| 4088 | |
| 4089 | void LocationsBuilderMIPS::VisitEqual(HEqual* comp) { |
| 4090 | VisitCondition(comp); |
| 4091 | } |
| 4092 | |
| 4093 | void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) { |
| 4094 | VisitCondition(comp); |
| 4095 | } |
| 4096 | |
| 4097 | void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) { |
| 4098 | VisitCondition(comp); |
| 4099 | } |
| 4100 | |
| 4101 | void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) { |
| 4102 | VisitCondition(comp); |
| 4103 | } |
| 4104 | |
| 4105 | void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) { |
| 4106 | VisitCondition(comp); |
| 4107 | } |
| 4108 | |
| 4109 | void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) { |
| 4110 | VisitCondition(comp); |
| 4111 | } |
| 4112 | |
| 4113 | void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 4114 | VisitCondition(comp); |
| 4115 | } |
| 4116 | |
| 4117 | void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 4118 | VisitCondition(comp); |
| 4119 | } |
| 4120 | |
| 4121 | void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) { |
| 4122 | VisitCondition(comp); |
| 4123 | } |
| 4124 | |
| 4125 | void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) { |
| 4126 | VisitCondition(comp); |
| 4127 | } |
| 4128 | |
| 4129 | void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 4130 | VisitCondition(comp); |
| 4131 | } |
| 4132 | |
| 4133 | void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 4134 | VisitCondition(comp); |
| 4135 | } |
| 4136 | |
| 4137 | void LocationsBuilderMIPS::VisitBelow(HBelow* comp) { |
| 4138 | VisitCondition(comp); |
| 4139 | } |
| 4140 | |
| 4141 | void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) { |
| 4142 | VisitCondition(comp); |
| 4143 | } |
| 4144 | |
| 4145 | void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 4146 | VisitCondition(comp); |
| 4147 | } |
| 4148 | |
| 4149 | void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 4150 | VisitCondition(comp); |
| 4151 | } |
| 4152 | |
| 4153 | void LocationsBuilderMIPS::VisitAbove(HAbove* comp) { |
| 4154 | VisitCondition(comp); |
| 4155 | } |
| 4156 | |
| 4157 | void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) { |
| 4158 | VisitCondition(comp); |
| 4159 | } |
| 4160 | |
| 4161 | void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 4162 | VisitCondition(comp); |
| 4163 | } |
| 4164 | |
| 4165 | void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 4166 | VisitCondition(comp); |
| 4167 | } |
| 4168 | |
| 4169 | void LocationsBuilderMIPS::VisitFakeString(HFakeString* instruction) { |
| 4170 | DCHECK(codegen_->IsBaseline()); |
| 4171 | LocationSummary* locations = |
| 4172 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4173 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 4174 | } |
| 4175 | |
| 4176 | void InstructionCodeGeneratorMIPS::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 4177 | DCHECK(codegen_->IsBaseline()); |
| 4178 | // Will be generated at use site. |
| 4179 | } |
| 4180 | |
| 4181 | void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 4182 | LocationSummary* locations = |
| 4183 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 4184 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4185 | } |
| 4186 | |
| 4187 | void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 4188 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 4189 | int32_t num_entries = switch_instr->GetNumEntries(); |
| 4190 | LocationSummary* locations = switch_instr->GetLocations(); |
| 4191 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 4192 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 4193 | |
| 4194 | // Create a set of compare/jumps. |
| 4195 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 4196 | for (int32_t i = 0; i < num_entries; ++i) { |
| 4197 | int32_t case_value = lower_bound + i; |
| 4198 | MipsLabel* successor_label = codegen_->GetLabelOf(successors[i]); |
| 4199 | if (case_value == 0) { |
| 4200 | __ Beqz(value_reg, successor_label); |
| 4201 | } else { |
| 4202 | __ LoadConst32(TMP, case_value); |
| 4203 | __ Beq(value_reg, TMP, successor_label); |
| 4204 | } |
| 4205 | } |
| 4206 | |
| 4207 | // Insert the default branch for every other value. |
| 4208 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 4209 | __ B(codegen_->GetLabelOf(default_block)); |
| 4210 | } |
| 4211 | } |
| 4212 | |
| 4213 | void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4214 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4215 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4216 | // the method_idx. |
| 4217 | HandleInvoke(invoke); |
| 4218 | } |
| 4219 | |
| 4220 | void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4221 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 4222 | } |
| 4223 | |
| 4224 | #undef __ |
| 4225 | #undef QUICK_ENTRY_POINT |
| 4226 | |
| 4227 | } // namespace mips |
| 4228 | } // namespace art |