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