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