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)); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 418 | CheckEntrypointTypes< |
| 419 | kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 420 | Primitive::Type ret_type = instruction_->GetType(); |
| 421 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 422 | mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 423 | } else { |
| 424 | DCHECK(instruction_->IsCheckCast()); |
| 425 | mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 426 | instruction_, |
| 427 | dex_pc, |
| 428 | this, |
| 429 | IsDirectEntrypoint(kQuickCheckCast)); |
| 430 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
| 431 | } |
| 432 | |
| 433 | RestoreLiveRegisters(codegen, locations); |
| 434 | __ B(GetExitLabel()); |
| 435 | } |
| 436 | |
| 437 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; } |
| 438 | |
| 439 | private: |
| 440 | HInstruction* const instruction_; |
| 441 | |
| 442 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS); |
| 443 | }; |
| 444 | |
| 445 | class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS { |
| 446 | public: |
| 447 | explicit DeoptimizationSlowPathMIPS(HInstruction* instruction) |
| 448 | : instruction_(instruction) {} |
| 449 | |
| 450 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 451 | __ Bind(GetEntryLabel()); |
| 452 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 453 | DCHECK(instruction_->IsDeoptimize()); |
| 454 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); |
| 455 | uint32_t dex_pc = deoptimize->GetDexPc(); |
| 456 | CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); |
| 457 | mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 458 | instruction_, |
| 459 | dex_pc, |
| 460 | this, |
| 461 | IsDirectEntrypoint(kQuickDeoptimize)); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 462 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; } |
| 466 | |
| 467 | private: |
| 468 | HInstruction* const instruction_; |
| 469 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS); |
| 470 | }; |
| 471 | |
| 472 | CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph, |
| 473 | const MipsInstructionSetFeatures& isa_features, |
| 474 | const CompilerOptions& compiler_options, |
| 475 | OptimizingCompilerStats* stats) |
| 476 | : CodeGenerator(graph, |
| 477 | kNumberOfCoreRegisters, |
| 478 | kNumberOfFRegisters, |
| 479 | kNumberOfRegisterPairs, |
| 480 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 481 | arraysize(kCoreCalleeSaves)), |
| 482 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 483 | arraysize(kFpuCalleeSaves)), |
| 484 | compiler_options, |
| 485 | stats), |
| 486 | block_labels_(nullptr), |
| 487 | location_builder_(graph, this), |
| 488 | instruction_visitor_(graph, this), |
| 489 | move_resolver_(graph->GetArena(), this), |
| 490 | assembler_(&isa_features), |
| 491 | isa_features_(isa_features) { |
| 492 | // Save RA (containing the return address) to mimic Quick. |
| 493 | AddAllocatedRegister(Location::RegisterLocation(RA)); |
| 494 | } |
| 495 | |
| 496 | #undef __ |
| 497 | #define __ down_cast<MipsAssembler*>(GetAssembler())-> |
| 498 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsWordSize, x).Int32Value() |
| 499 | |
| 500 | void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) { |
| 501 | // Ensure that we fix up branches. |
| 502 | __ FinalizeCode(); |
| 503 | |
| 504 | // Adjust native pc offsets in stack maps. |
| 505 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
| 506 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; |
| 507 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 508 | DCHECK_GE(new_position, old_position); |
| 509 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 510 | } |
| 511 | |
| 512 | // Adjust pc offsets for the disassembly information. |
| 513 | if (disasm_info_ != nullptr) { |
| 514 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 515 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 516 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 517 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 518 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 519 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 520 | } |
| 521 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 522 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 523 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | CodeGenerator::Finalize(allocator); |
| 528 | } |
| 529 | |
| 530 | MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const { |
| 531 | return codegen_->GetAssembler(); |
| 532 | } |
| 533 | |
| 534 | void ParallelMoveResolverMIPS::EmitMove(size_t index) { |
| 535 | DCHECK_LT(index, moves_.size()); |
| 536 | MoveOperands* move = moves_[index]; |
| 537 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType()); |
| 538 | } |
| 539 | |
| 540 | void ParallelMoveResolverMIPS::EmitSwap(size_t index) { |
| 541 | DCHECK_LT(index, moves_.size()); |
| 542 | MoveOperands* move = moves_[index]; |
| 543 | Primitive::Type type = move->GetType(); |
| 544 | Location loc1 = move->GetDestination(); |
| 545 | Location loc2 = move->GetSource(); |
| 546 | |
| 547 | DCHECK(!loc1.IsConstant()); |
| 548 | DCHECK(!loc2.IsConstant()); |
| 549 | |
| 550 | if (loc1.Equals(loc2)) { |
| 551 | return; |
| 552 | } |
| 553 | |
| 554 | if (loc1.IsRegister() && loc2.IsRegister()) { |
| 555 | // Swap 2 GPRs. |
| 556 | Register r1 = loc1.AsRegister<Register>(); |
| 557 | Register r2 = loc2.AsRegister<Register>(); |
| 558 | __ Move(TMP, r2); |
| 559 | __ Move(r2, r1); |
| 560 | __ Move(r1, TMP); |
| 561 | } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) { |
| 562 | FRegister f1 = loc1.AsFpuRegister<FRegister>(); |
| 563 | FRegister f2 = loc2.AsFpuRegister<FRegister>(); |
| 564 | if (type == Primitive::kPrimFloat) { |
| 565 | __ MovS(FTMP, f2); |
| 566 | __ MovS(f2, f1); |
| 567 | __ MovS(f1, FTMP); |
| 568 | } else { |
| 569 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 570 | __ MovD(FTMP, f2); |
| 571 | __ MovD(f2, f1); |
| 572 | __ MovD(f1, FTMP); |
| 573 | } |
| 574 | } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) || |
| 575 | (loc1.IsFpuRegister() && loc2.IsRegister())) { |
| 576 | // Swap FPR and GPR. |
| 577 | DCHECK_EQ(type, Primitive::kPrimFloat); // Can only swap a float. |
| 578 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 579 | : loc2.AsFpuRegister<FRegister>(); |
| 580 | Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>() |
| 581 | : loc2.AsRegister<Register>(); |
| 582 | __ Move(TMP, r2); |
| 583 | __ Mfc1(r2, f1); |
| 584 | __ Mtc1(TMP, f1); |
| 585 | } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) { |
| 586 | // Swap 2 GPR register pairs. |
| 587 | Register r1 = loc1.AsRegisterPairLow<Register>(); |
| 588 | Register r2 = loc2.AsRegisterPairLow<Register>(); |
| 589 | __ Move(TMP, r2); |
| 590 | __ Move(r2, r1); |
| 591 | __ Move(r1, TMP); |
| 592 | r1 = loc1.AsRegisterPairHigh<Register>(); |
| 593 | r2 = loc2.AsRegisterPairHigh<Register>(); |
| 594 | __ Move(TMP, r2); |
| 595 | __ Move(r2, r1); |
| 596 | __ Move(r1, TMP); |
| 597 | } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) || |
| 598 | (loc1.IsFpuRegister() && loc2.IsRegisterPair())) { |
| 599 | // Swap FPR and GPR register pair. |
| 600 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 601 | FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>() |
| 602 | : loc2.AsFpuRegister<FRegister>(); |
| 603 | Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>() |
| 604 | : loc2.AsRegisterPairLow<Register>(); |
| 605 | Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>() |
| 606 | : loc2.AsRegisterPairHigh<Register>(); |
| 607 | // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and |
| 608 | // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR |
| 609 | // unpredictable and the following mfch1 will fail. |
| 610 | __ Mfc1(TMP, f1); |
| 611 | __ Mfhc1(AT, f1); |
| 612 | __ Mtc1(r2_l, f1); |
| 613 | __ Mthc1(r2_h, f1); |
| 614 | __ Move(r2_l, TMP); |
| 615 | __ Move(r2_h, AT); |
| 616 | } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) { |
| 617 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false); |
| 618 | } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) { |
| 619 | Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true); |
| 620 | } else { |
| 621 | LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported"; |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | void ParallelMoveResolverMIPS::RestoreScratch(int reg) { |
| 626 | __ Pop(static_cast<Register>(reg)); |
| 627 | } |
| 628 | |
| 629 | void ParallelMoveResolverMIPS::SpillScratch(int reg) { |
| 630 | __ Push(static_cast<Register>(reg)); |
| 631 | } |
| 632 | |
| 633 | void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) { |
| 634 | // Allocate a scratch register other than TMP, if available. |
| 635 | // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be |
| 636 | // automatically unspilled when the scratch scope object is destroyed). |
| 637 | ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters()); |
| 638 | // If V0 spills onto the stack, SP-relative offsets need to be adjusted. |
| 639 | int stack_offset = ensure_scratch.IsSpilled() ? kMipsWordSize : 0; |
| 640 | for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) { |
| 641 | __ LoadFromOffset(kLoadWord, |
| 642 | Register(ensure_scratch.GetRegister()), |
| 643 | SP, |
| 644 | index1 + stack_offset); |
| 645 | __ LoadFromOffset(kLoadWord, |
| 646 | TMP, |
| 647 | SP, |
| 648 | index2 + stack_offset); |
| 649 | __ StoreToOffset(kStoreWord, |
| 650 | Register(ensure_scratch.GetRegister()), |
| 651 | SP, |
| 652 | index2 + stack_offset); |
| 653 | __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset); |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | static dwarf::Reg DWARFReg(Register reg) { |
| 658 | return dwarf::Reg::MipsCore(static_cast<int>(reg)); |
| 659 | } |
| 660 | |
| 661 | // TODO: mapping of floating-point registers to DWARF. |
| 662 | |
| 663 | void CodeGeneratorMIPS::GenerateFrameEntry() { |
| 664 | __ Bind(&frame_entry_label_); |
| 665 | |
| 666 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips) || !IsLeafMethod(); |
| 667 | |
| 668 | if (do_overflow_check) { |
| 669 | __ LoadFromOffset(kLoadWord, |
| 670 | ZERO, |
| 671 | SP, |
| 672 | -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips))); |
| 673 | RecordPcInfo(nullptr, 0); |
| 674 | } |
| 675 | |
| 676 | if (HasEmptyFrame()) { |
| 677 | return; |
| 678 | } |
| 679 | |
| 680 | // Make sure the frame size isn't unreasonably large. |
| 681 | if (GetFrameSize() > GetStackOverflowReservedBytes(kMips)) { |
| 682 | LOG(FATAL) << "Stack frame larger than " << GetStackOverflowReservedBytes(kMips) << " bytes"; |
| 683 | } |
| 684 | |
| 685 | // Spill callee-saved registers. |
| 686 | // Note that their cumulative size is small and they can be indexed using |
| 687 | // 16-bit offsets. |
| 688 | |
| 689 | // TODO: increment/decrement SP in one step instead of two or remove this comment. |
| 690 | |
| 691 | uint32_t ofs = FrameEntrySpillSize(); |
| 692 | bool unaligned_float = ofs & 0x7; |
| 693 | bool fpu_32bit = isa_features_.Is32BitFloatingPoint(); |
| 694 | __ IncreaseFrameSize(ofs); |
| 695 | |
| 696 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 697 | Register reg = kCoreCalleeSaves[i]; |
| 698 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 699 | ofs -= kMipsWordSize; |
| 700 | __ Sw(reg, SP, ofs); |
| 701 | __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 706 | FRegister reg = kFpuCalleeSaves[i]; |
| 707 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
| 708 | ofs -= kMipsDoublewordSize; |
| 709 | // TODO: Change the frame to avoid unaligned accesses for fpu registers. |
| 710 | if (unaligned_float) { |
| 711 | if (fpu_32bit) { |
| 712 | __ Swc1(reg, SP, ofs); |
| 713 | __ Swc1(static_cast<FRegister>(reg + 1), SP, ofs + 4); |
| 714 | } else { |
| 715 | __ Mfhc1(TMP, reg); |
| 716 | __ Swc1(reg, SP, ofs); |
| 717 | __ Sw(TMP, SP, ofs + 4); |
| 718 | } |
| 719 | } else { |
| 720 | __ Sdc1(reg, SP, ofs); |
| 721 | } |
| 722 | // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs); |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | // Allocate the rest of the frame and store the current method pointer |
| 727 | // at its end. |
| 728 | |
| 729 | __ IncreaseFrameSize(GetFrameSize() - FrameEntrySpillSize()); |
| 730 | |
| 731 | static_assert(IsInt<16>(kCurrentMethodStackOffset), |
| 732 | "kCurrentMethodStackOffset must fit into int16_t"); |
| 733 | __ Sw(kMethodRegisterArgument, SP, kCurrentMethodStackOffset); |
| 734 | } |
| 735 | |
| 736 | void CodeGeneratorMIPS::GenerateFrameExit() { |
| 737 | __ cfi().RememberState(); |
| 738 | |
| 739 | if (!HasEmptyFrame()) { |
| 740 | // Deallocate the rest of the frame. |
| 741 | |
| 742 | __ DecreaseFrameSize(GetFrameSize() - FrameEntrySpillSize()); |
| 743 | |
| 744 | // Restore callee-saved registers. |
| 745 | // Note that their cumulative size is small and they can be indexed using |
| 746 | // 16-bit offsets. |
| 747 | |
| 748 | // TODO: increment/decrement SP in one step instead of two or remove this comment. |
| 749 | |
| 750 | uint32_t ofs = 0; |
| 751 | bool unaligned_float = FrameEntrySpillSize() & 0x7; |
| 752 | bool fpu_32bit = isa_features_.Is32BitFloatingPoint(); |
| 753 | |
| 754 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 755 | FRegister reg = kFpuCalleeSaves[i]; |
| 756 | if (allocated_registers_.ContainsFloatingPointRegister(reg)) { |
| 757 | if (unaligned_float) { |
| 758 | if (fpu_32bit) { |
| 759 | __ Lwc1(reg, SP, ofs); |
| 760 | __ Lwc1(static_cast<FRegister>(reg + 1), SP, ofs + 4); |
| 761 | } else { |
| 762 | __ Lwc1(reg, SP, ofs); |
| 763 | __ Lw(TMP, SP, ofs + 4); |
| 764 | __ Mthc1(TMP, reg); |
| 765 | } |
| 766 | } else { |
| 767 | __ Ldc1(reg, SP, ofs); |
| 768 | } |
| 769 | ofs += kMipsDoublewordSize; |
| 770 | // TODO: __ cfi().Restore(DWARFReg(reg)); |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 775 | Register reg = kCoreCalleeSaves[i]; |
| 776 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 777 | __ Lw(reg, SP, ofs); |
| 778 | ofs += kMipsWordSize; |
| 779 | __ cfi().Restore(DWARFReg(reg)); |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | DCHECK_EQ(ofs, FrameEntrySpillSize()); |
| 784 | __ DecreaseFrameSize(ofs); |
| 785 | } |
| 786 | |
| 787 | __ Jr(RA); |
| 788 | __ Nop(); |
| 789 | |
| 790 | __ cfi().RestoreState(); |
| 791 | __ cfi().DefCFAOffset(GetFrameSize()); |
| 792 | } |
| 793 | |
| 794 | void CodeGeneratorMIPS::Bind(HBasicBlock* block) { |
| 795 | __ Bind(GetLabelOf(block)); |
| 796 | } |
| 797 | |
| 798 | void CodeGeneratorMIPS::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
| 799 | if (src.Equals(dst)) { |
| 800 | return; |
| 801 | } |
| 802 | |
| 803 | if (src.IsConstant()) { |
| 804 | MoveConstant(dst, src.GetConstant()); |
| 805 | } else { |
| 806 | if (Primitive::Is64BitType(dst_type)) { |
| 807 | Move64(dst, src); |
| 808 | } else { |
| 809 | Move32(dst, src); |
| 810 | } |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | void CodeGeneratorMIPS::Move32(Location destination, Location source) { |
| 815 | if (source.Equals(destination)) { |
| 816 | return; |
| 817 | } |
| 818 | |
| 819 | if (destination.IsRegister()) { |
| 820 | if (source.IsRegister()) { |
| 821 | __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 822 | } else if (source.IsFpuRegister()) { |
| 823 | __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>()); |
| 824 | } else { |
| 825 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 826 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
| 827 | } |
| 828 | } else if (destination.IsFpuRegister()) { |
| 829 | if (source.IsRegister()) { |
| 830 | __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>()); |
| 831 | } else if (source.IsFpuRegister()) { |
| 832 | __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 833 | } else { |
| 834 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 835 | __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 836 | } |
| 837 | } else { |
| 838 | DCHECK(destination.IsStackSlot()) << destination; |
| 839 | if (source.IsRegister()) { |
| 840 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
| 841 | } else if (source.IsFpuRegister()) { |
| 842 | __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex()); |
| 843 | } else { |
| 844 | DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 845 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 846 | __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex()); |
| 847 | } |
| 848 | } |
| 849 | } |
| 850 | |
| 851 | void CodeGeneratorMIPS::Move64(Location destination, Location source) { |
| 852 | if (source.Equals(destination)) { |
| 853 | return; |
| 854 | } |
| 855 | |
| 856 | if (destination.IsRegisterPair()) { |
| 857 | if (source.IsRegisterPair()) { |
| 858 | __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 859 | __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 860 | } else if (source.IsFpuRegister()) { |
| 861 | Register dst_high = destination.AsRegisterPairHigh<Register>(); |
| 862 | Register dst_low = destination.AsRegisterPairLow<Register>(); |
| 863 | FRegister src = source.AsFpuRegister<FRegister>(); |
| 864 | __ Mfc1(dst_low, src); |
| 865 | __ Mfhc1(dst_high, src); |
| 866 | } else { |
| 867 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 868 | int32_t off = source.GetStackIndex(); |
| 869 | Register r = destination.AsRegisterPairLow<Register>(); |
| 870 | __ LoadFromOffset(kLoadDoubleword, r, SP, off); |
| 871 | } |
| 872 | } else if (destination.IsFpuRegister()) { |
| 873 | if (source.IsRegisterPair()) { |
| 874 | FRegister dst = destination.AsFpuRegister<FRegister>(); |
| 875 | Register src_high = source.AsRegisterPairHigh<Register>(); |
| 876 | Register src_low = source.AsRegisterPairLow<Register>(); |
| 877 | __ Mtc1(src_low, dst); |
| 878 | __ Mthc1(src_high, dst); |
| 879 | } else if (source.IsFpuRegister()) { |
| 880 | __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>()); |
| 881 | } else { |
| 882 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 883 | __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex()); |
| 884 | } |
| 885 | } else { |
| 886 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 887 | int32_t off = destination.GetStackIndex(); |
| 888 | if (source.IsRegisterPair()) { |
| 889 | __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, off); |
| 890 | } else if (source.IsFpuRegister()) { |
| 891 | __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, off); |
| 892 | } else { |
| 893 | DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination; |
| 894 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex()); |
| 895 | __ StoreToOffset(kStoreWord, TMP, SP, off); |
| 896 | __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4); |
| 897 | __ StoreToOffset(kStoreWord, TMP, SP, off + 4); |
| 898 | } |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) { |
| 903 | if (c->IsIntConstant() || c->IsNullConstant()) { |
| 904 | // Move 32 bit constant. |
| 905 | int32_t value = GetInt32ValueOf(c); |
| 906 | if (destination.IsRegister()) { |
| 907 | Register dst = destination.AsRegister<Register>(); |
| 908 | __ LoadConst32(dst, value); |
| 909 | } else { |
| 910 | DCHECK(destination.IsStackSlot()) |
| 911 | << "Cannot move " << c->DebugName() << " to " << destination; |
| 912 | __ StoreConst32ToOffset(value, SP, destination.GetStackIndex(), TMP); |
| 913 | } |
| 914 | } else if (c->IsLongConstant()) { |
| 915 | // Move 64 bit constant. |
| 916 | int64_t value = GetInt64ValueOf(c); |
| 917 | if (destination.IsRegisterPair()) { |
| 918 | Register r_h = destination.AsRegisterPairHigh<Register>(); |
| 919 | Register r_l = destination.AsRegisterPairLow<Register>(); |
| 920 | __ LoadConst64(r_h, r_l, value); |
| 921 | } else { |
| 922 | DCHECK(destination.IsDoubleStackSlot()) |
| 923 | << "Cannot move " << c->DebugName() << " to " << destination; |
| 924 | __ StoreConst64ToOffset(value, SP, destination.GetStackIndex(), TMP); |
| 925 | } |
| 926 | } else if (c->IsFloatConstant()) { |
| 927 | // Move 32 bit float constant. |
| 928 | int32_t value = GetInt32ValueOf(c); |
| 929 | if (destination.IsFpuRegister()) { |
| 930 | __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP); |
| 931 | } else { |
| 932 | DCHECK(destination.IsStackSlot()) |
| 933 | << "Cannot move " << c->DebugName() << " to " << destination; |
| 934 | __ StoreConst32ToOffset(value, SP, destination.GetStackIndex(), TMP); |
| 935 | } |
| 936 | } else { |
| 937 | // Move 64 bit double constant. |
| 938 | DCHECK(c->IsDoubleConstant()) << c->DebugName(); |
| 939 | int64_t value = GetInt64ValueOf(c); |
| 940 | if (destination.IsFpuRegister()) { |
| 941 | FRegister fd = destination.AsFpuRegister<FRegister>(); |
| 942 | __ LoadDConst64(fd, value, TMP); |
| 943 | } else { |
| 944 | DCHECK(destination.IsDoubleStackSlot()) |
| 945 | << "Cannot move " << c->DebugName() << " to " << destination; |
| 946 | __ StoreConst64ToOffset(value, SP, destination.GetStackIndex(), TMP); |
| 947 | } |
| 948 | } |
| 949 | } |
| 950 | |
| 951 | void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) { |
| 952 | DCHECK(destination.IsRegister()); |
| 953 | Register dst = destination.AsRegister<Register>(); |
| 954 | __ LoadConst32(dst, value); |
| 955 | } |
| 956 | |
| 957 | void CodeGeneratorMIPS::Move(HInstruction* instruction, |
| 958 | Location location, |
| 959 | HInstruction* move_for) { |
| 960 | LocationSummary* locations = instruction->GetLocations(); |
| 961 | Primitive::Type type = instruction->GetType(); |
| 962 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 963 | |
| 964 | if (instruction->IsCurrentMethod()) { |
| 965 | Move32(location, Location::StackSlot(kCurrentMethodStackOffset)); |
| 966 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
| 967 | return; |
| 968 | } else if (instruction->IsIntConstant() |
| 969 | || instruction->IsLongConstant() |
| 970 | || instruction->IsNullConstant()) { |
| 971 | MoveConstant(location, instruction->AsConstant()); |
| 972 | } else if (instruction->IsTemporary()) { |
| 973 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
| 974 | if (temp_location.IsStackSlot()) { |
| 975 | Move32(location, temp_location); |
| 976 | } else { |
| 977 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 978 | Move64(location, temp_location); |
| 979 | } |
| 980 | } else if (instruction->IsLoadLocal()) { |
| 981 | uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
| 982 | if (Primitive::Is64BitType(type)) { |
| 983 | Move64(location, Location::DoubleStackSlot(stack_slot)); |
| 984 | } else { |
| 985 | Move32(location, Location::StackSlot(stack_slot)); |
| 986 | } |
| 987 | } else { |
| 988 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
| 989 | if (Primitive::Is64BitType(type)) { |
| 990 | Move64(location, locations->Out()); |
| 991 | } else { |
| 992 | Move32(location, locations->Out()); |
| 993 | } |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 998 | if (location.IsRegister()) { |
| 999 | locations->AddTemp(location); |
Alexey Frunze | c9e94f3 | 2015-10-26 16:11:39 -0700 | [diff] [blame] | 1000 | } else if (location.IsRegisterPair()) { |
| 1001 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1002 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1003 | } else { |
| 1004 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1005 | } |
| 1006 | } |
| 1007 | |
| 1008 | Location CodeGeneratorMIPS::GetStackLocation(HLoadLocal* load) const { |
| 1009 | Primitive::Type type = load->GetType(); |
| 1010 | |
| 1011 | switch (type) { |
| 1012 | case Primitive::kPrimNot: |
| 1013 | case Primitive::kPrimInt: |
| 1014 | case Primitive::kPrimFloat: |
| 1015 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
| 1016 | |
| 1017 | case Primitive::kPrimLong: |
| 1018 | case Primitive::kPrimDouble: |
| 1019 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
| 1020 | |
| 1021 | case Primitive::kPrimBoolean: |
| 1022 | case Primitive::kPrimByte: |
| 1023 | case Primitive::kPrimChar: |
| 1024 | case Primitive::kPrimShort: |
| 1025 | case Primitive::kPrimVoid: |
| 1026 | LOG(FATAL) << "Unexpected type " << type; |
| 1027 | } |
| 1028 | |
| 1029 | LOG(FATAL) << "Unreachable"; |
| 1030 | return Location::NoLocation(); |
| 1031 | } |
| 1032 | |
| 1033 | void CodeGeneratorMIPS::MarkGCCard(Register object, Register value) { |
| 1034 | MipsLabel done; |
| 1035 | Register card = AT; |
| 1036 | Register temp = TMP; |
| 1037 | __ Beqz(value, &done); |
| 1038 | __ LoadFromOffset(kLoadWord, |
| 1039 | card, |
| 1040 | TR, |
| 1041 | Thread::CardTableOffset<kMipsWordSize>().Int32Value()); |
| 1042 | __ Srl(temp, object, gc::accounting::CardTable::kCardShift); |
| 1043 | __ Addu(temp, card, temp); |
| 1044 | __ Sb(card, temp, 0); |
| 1045 | __ Bind(&done); |
| 1046 | } |
| 1047 | |
| 1048 | void CodeGeneratorMIPS::SetupBlockedRegisters(bool is_baseline) const { |
| 1049 | // Don't allocate the dalvik style register pair passing. |
| 1050 | blocked_register_pairs_[A1_A2] = true; |
| 1051 | |
| 1052 | // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated. |
| 1053 | blocked_core_registers_[ZERO] = true; |
| 1054 | blocked_core_registers_[K0] = true; |
| 1055 | blocked_core_registers_[K1] = true; |
| 1056 | blocked_core_registers_[GP] = true; |
| 1057 | blocked_core_registers_[SP] = true; |
| 1058 | blocked_core_registers_[RA] = true; |
| 1059 | |
| 1060 | // AT and TMP(T8) are used as temporary/scratch registers |
| 1061 | // (similar to how AT is used by MIPS assemblers). |
| 1062 | blocked_core_registers_[AT] = true; |
| 1063 | blocked_core_registers_[TMP] = true; |
| 1064 | blocked_fpu_registers_[FTMP] = true; |
| 1065 | |
| 1066 | // Reserve suspend and thread registers. |
| 1067 | blocked_core_registers_[S0] = true; |
| 1068 | blocked_core_registers_[TR] = true; |
| 1069 | |
| 1070 | // Reserve T9 for function calls |
| 1071 | blocked_core_registers_[T9] = true; |
| 1072 | |
| 1073 | // Reserve odd-numbered FPU registers. |
| 1074 | for (size_t i = 1; i < kNumberOfFRegisters; i += 2) { |
| 1075 | blocked_fpu_registers_[i] = true; |
| 1076 | } |
| 1077 | |
| 1078 | if (is_baseline) { |
| 1079 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1080 | blocked_core_registers_[kCoreCalleeSaves[i]] = true; |
| 1081 | } |
| 1082 | |
| 1083 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1084 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | UpdateBlockedPairRegisters(); |
| 1089 | } |
| 1090 | |
| 1091 | void CodeGeneratorMIPS::UpdateBlockedPairRegisters() const { |
| 1092 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 1093 | MipsManagedRegister current = |
| 1094 | MipsManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 1095 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 1096 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 1097 | blocked_register_pairs_[i] = true; |
| 1098 | } |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | Location CodeGeneratorMIPS::AllocateFreeRegister(Primitive::Type type) const { |
| 1103 | switch (type) { |
| 1104 | case Primitive::kPrimLong: { |
| 1105 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
| 1106 | MipsManagedRegister pair = |
| 1107 | MipsManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
| 1108 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 1109 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
| 1110 | |
| 1111 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 1112 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
| 1113 | UpdateBlockedPairRegisters(); |
| 1114 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
| 1115 | } |
| 1116 | |
| 1117 | case Primitive::kPrimByte: |
| 1118 | case Primitive::kPrimBoolean: |
| 1119 | case Primitive::kPrimChar: |
| 1120 | case Primitive::kPrimShort: |
| 1121 | case Primitive::kPrimInt: |
| 1122 | case Primitive::kPrimNot: { |
| 1123 | int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters); |
| 1124 | // Block all register pairs that contain `reg`. |
| 1125 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 1126 | MipsManagedRegister current = |
| 1127 | MipsManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 1128 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
| 1129 | blocked_register_pairs_[i] = true; |
| 1130 | } |
| 1131 | } |
| 1132 | return Location::RegisterLocation(reg); |
| 1133 | } |
| 1134 | |
| 1135 | case Primitive::kPrimFloat: |
| 1136 | case Primitive::kPrimDouble: { |
| 1137 | int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfFRegisters); |
| 1138 | return Location::FpuRegisterLocation(reg); |
| 1139 | } |
| 1140 | |
| 1141 | case Primitive::kPrimVoid: |
| 1142 | LOG(FATAL) << "Unreachable type " << type; |
| 1143 | } |
| 1144 | |
| 1145 | UNREACHABLE(); |
| 1146 | } |
| 1147 | |
| 1148 | size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1149 | __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index); |
| 1150 | return kMipsWordSize; |
| 1151 | } |
| 1152 | |
| 1153 | size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1154 | __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index); |
| 1155 | return kMipsWordSize; |
| 1156 | } |
| 1157 | |
| 1158 | size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1159 | __ StoreDToOffset(FRegister(reg_id), SP, stack_index); |
| 1160 | return kMipsDoublewordSize; |
| 1161 | } |
| 1162 | |
| 1163 | size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1164 | __ LoadDFromOffset(FRegister(reg_id), SP, stack_index); |
| 1165 | return kMipsDoublewordSize; |
| 1166 | } |
| 1167 | |
| 1168 | void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 1169 | stream << MipsManagedRegister::FromCoreRegister(Register(reg)); |
| 1170 | } |
| 1171 | |
| 1172 | void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 1173 | stream << MipsManagedRegister::FromFRegister(FRegister(reg)); |
| 1174 | } |
| 1175 | |
| 1176 | void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1177 | HInstruction* instruction, |
| 1178 | uint32_t dex_pc, |
| 1179 | SlowPathCode* slow_path) { |
| 1180 | InvokeRuntime(GetThreadOffset<kMipsWordSize>(entrypoint).Int32Value(), |
| 1181 | instruction, |
| 1182 | dex_pc, |
| 1183 | slow_path, |
| 1184 | IsDirectEntrypoint(entrypoint)); |
| 1185 | } |
| 1186 | |
| 1187 | constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16; |
| 1188 | |
| 1189 | void CodeGeneratorMIPS::InvokeRuntime(int32_t entry_point_offset, |
| 1190 | HInstruction* instruction, |
| 1191 | uint32_t dex_pc, |
| 1192 | SlowPathCode* slow_path, |
| 1193 | bool is_direct_entrypoint) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1194 | __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset); |
| 1195 | __ Jalr(T9); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1196 | if (is_direct_entrypoint) { |
| 1197 | // Reserve argument space on stack (for $a0-$a3) for |
| 1198 | // entrypoints that directly reference native implementations. |
| 1199 | // Called function may use this space to store $a0-$a3 regs. |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1200 | __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1201 | __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1202 | } else { |
| 1203 | __ Nop(); // In delay slot. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1204 | } |
| 1205 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1206 | } |
| 1207 | |
| 1208 | void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path, |
| 1209 | Register class_reg) { |
| 1210 | __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 1211 | __ LoadConst32(AT, mirror::Class::kStatusInitialized); |
| 1212 | __ Blt(TMP, AT, slow_path->GetEntryLabel()); |
| 1213 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| 1214 | __ Sync(0); |
| 1215 | __ Bind(slow_path->GetExitLabel()); |
| 1216 | } |
| 1217 | |
| 1218 | void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) { |
| 1219 | __ Sync(0); // Only stype 0 is supported. |
| 1220 | } |
| 1221 | |
| 1222 | void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1223 | HBasicBlock* successor) { |
| 1224 | SuspendCheckSlowPathMIPS* slow_path = |
| 1225 | new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS(instruction, successor); |
| 1226 | codegen_->AddSlowPath(slow_path); |
| 1227 | |
| 1228 | __ LoadFromOffset(kLoadUnsignedHalfword, |
| 1229 | TMP, |
| 1230 | TR, |
| 1231 | Thread::ThreadFlagsOffset<kMipsWordSize>().Int32Value()); |
| 1232 | if (successor == nullptr) { |
| 1233 | __ Bnez(TMP, slow_path->GetEntryLabel()); |
| 1234 | __ Bind(slow_path->GetReturnLabel()); |
| 1235 | } else { |
| 1236 | __ Beqz(TMP, codegen_->GetLabelOf(successor)); |
| 1237 | __ B(slow_path->GetEntryLabel()); |
| 1238 | // slow_path will return to GetLabelOf(successor). |
| 1239 | } |
| 1240 | } |
| 1241 | |
| 1242 | InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph, |
| 1243 | CodeGeneratorMIPS* codegen) |
| 1244 | : HGraphVisitor(graph), |
| 1245 | assembler_(codegen->GetAssembler()), |
| 1246 | codegen_(codegen) {} |
| 1247 | |
| 1248 | void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1249 | DCHECK_EQ(instruction->InputCount(), 2U); |
| 1250 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1251 | Primitive::Type type = instruction->GetResultType(); |
| 1252 | switch (type) { |
| 1253 | case Primitive::kPrimInt: { |
| 1254 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1255 | HInstruction* right = instruction->InputAt(1); |
| 1256 | bool can_use_imm = false; |
| 1257 | if (right->IsConstant()) { |
| 1258 | int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant()); |
| 1259 | if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) { |
| 1260 | can_use_imm = IsUint<16>(imm); |
| 1261 | } else if (instruction->IsAdd()) { |
| 1262 | can_use_imm = IsInt<16>(imm); |
| 1263 | } else { |
| 1264 | DCHECK(instruction->IsSub()); |
| 1265 | can_use_imm = IsInt<16>(-imm); |
| 1266 | } |
| 1267 | } |
| 1268 | if (can_use_imm) |
| 1269 | locations->SetInAt(1, Location::ConstantLocation(right->AsConstant())); |
| 1270 | else |
| 1271 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1272 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1273 | break; |
| 1274 | } |
| 1275 | |
| 1276 | case Primitive::kPrimLong: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1277 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1278 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1279 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1280 | break; |
| 1281 | } |
| 1282 | |
| 1283 | case Primitive::kPrimFloat: |
| 1284 | case Primitive::kPrimDouble: |
| 1285 | DCHECK(instruction->IsAdd() || instruction->IsSub()); |
| 1286 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1287 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1288 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1289 | break; |
| 1290 | |
| 1291 | default: |
| 1292 | LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type; |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) { |
| 1297 | Primitive::Type type = instruction->GetType(); |
| 1298 | LocationSummary* locations = instruction->GetLocations(); |
| 1299 | |
| 1300 | switch (type) { |
| 1301 | case Primitive::kPrimInt: { |
| 1302 | Register dst = locations->Out().AsRegister<Register>(); |
| 1303 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 1304 | Location rhs_location = locations->InAt(1); |
| 1305 | |
| 1306 | Register rhs_reg = ZERO; |
| 1307 | int32_t rhs_imm = 0; |
| 1308 | bool use_imm = rhs_location.IsConstant(); |
| 1309 | if (use_imm) { |
| 1310 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 1311 | } else { |
| 1312 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 1313 | } |
| 1314 | |
| 1315 | if (instruction->IsAnd()) { |
| 1316 | if (use_imm) |
| 1317 | __ Andi(dst, lhs, rhs_imm); |
| 1318 | else |
| 1319 | __ And(dst, lhs, rhs_reg); |
| 1320 | } else if (instruction->IsOr()) { |
| 1321 | if (use_imm) |
| 1322 | __ Ori(dst, lhs, rhs_imm); |
| 1323 | else |
| 1324 | __ Or(dst, lhs, rhs_reg); |
| 1325 | } else if (instruction->IsXor()) { |
| 1326 | if (use_imm) |
| 1327 | __ Xori(dst, lhs, rhs_imm); |
| 1328 | else |
| 1329 | __ Xor(dst, lhs, rhs_reg); |
| 1330 | } else if (instruction->IsAdd()) { |
| 1331 | if (use_imm) |
| 1332 | __ Addiu(dst, lhs, rhs_imm); |
| 1333 | else |
| 1334 | __ Addu(dst, lhs, rhs_reg); |
| 1335 | } else { |
| 1336 | DCHECK(instruction->IsSub()); |
| 1337 | if (use_imm) |
| 1338 | __ Addiu(dst, lhs, -rhs_imm); |
| 1339 | else |
| 1340 | __ Subu(dst, lhs, rhs_reg); |
| 1341 | } |
| 1342 | break; |
| 1343 | } |
| 1344 | |
| 1345 | case Primitive::kPrimLong: { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1346 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 1347 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 1348 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 1349 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1350 | Location rhs_location = locations->InAt(1); |
| 1351 | bool use_imm = rhs_location.IsConstant(); |
| 1352 | if (!use_imm) { |
| 1353 | Register rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 1354 | Register rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 1355 | if (instruction->IsAnd()) { |
| 1356 | __ And(dst_low, lhs_low, rhs_low); |
| 1357 | __ And(dst_high, lhs_high, rhs_high); |
| 1358 | } else if (instruction->IsOr()) { |
| 1359 | __ Or(dst_low, lhs_low, rhs_low); |
| 1360 | __ Or(dst_high, lhs_high, rhs_high); |
| 1361 | } else if (instruction->IsXor()) { |
| 1362 | __ Xor(dst_low, lhs_low, rhs_low); |
| 1363 | __ Xor(dst_high, lhs_high, rhs_high); |
| 1364 | } else if (instruction->IsAdd()) { |
| 1365 | if (lhs_low == rhs_low) { |
| 1366 | // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs. |
| 1367 | __ Slt(TMP, lhs_low, ZERO); |
| 1368 | __ Addu(dst_low, lhs_low, rhs_low); |
| 1369 | } else { |
| 1370 | __ Addu(dst_low, lhs_low, rhs_low); |
| 1371 | // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged. |
| 1372 | __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low); |
| 1373 | } |
| 1374 | __ Addu(dst_high, lhs_high, rhs_high); |
| 1375 | __ Addu(dst_high, dst_high, TMP); |
| 1376 | } else { |
| 1377 | DCHECK(instruction->IsSub()); |
| 1378 | __ Sltu(TMP, lhs_low, rhs_low); |
| 1379 | __ Subu(dst_low, lhs_low, rhs_low); |
| 1380 | __ Subu(dst_high, lhs_high, rhs_high); |
| 1381 | __ Subu(dst_high, dst_high, TMP); |
| 1382 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1383 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1384 | int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant()); |
| 1385 | if (instruction->IsOr()) { |
| 1386 | uint32_t low = Low32Bits(value); |
| 1387 | uint32_t high = High32Bits(value); |
| 1388 | if (IsUint<16>(low)) { |
| 1389 | if (dst_low != lhs_low || low != 0) { |
| 1390 | __ Ori(dst_low, lhs_low, low); |
| 1391 | } |
| 1392 | } else { |
| 1393 | __ LoadConst32(TMP, low); |
| 1394 | __ Or(dst_low, lhs_low, TMP); |
| 1395 | } |
| 1396 | if (IsUint<16>(high)) { |
| 1397 | if (dst_high != lhs_high || high != 0) { |
| 1398 | __ Ori(dst_high, lhs_high, high); |
| 1399 | } |
| 1400 | } else { |
| 1401 | if (high != low) { |
| 1402 | __ LoadConst32(TMP, high); |
| 1403 | } |
| 1404 | __ Or(dst_high, lhs_high, TMP); |
| 1405 | } |
| 1406 | } else if (instruction->IsXor()) { |
| 1407 | uint32_t low = Low32Bits(value); |
| 1408 | uint32_t high = High32Bits(value); |
| 1409 | if (IsUint<16>(low)) { |
| 1410 | if (dst_low != lhs_low || low != 0) { |
| 1411 | __ Xori(dst_low, lhs_low, low); |
| 1412 | } |
| 1413 | } else { |
| 1414 | __ LoadConst32(TMP, low); |
| 1415 | __ Xor(dst_low, lhs_low, TMP); |
| 1416 | } |
| 1417 | if (IsUint<16>(high)) { |
| 1418 | if (dst_high != lhs_high || high != 0) { |
| 1419 | __ Xori(dst_high, lhs_high, high); |
| 1420 | } |
| 1421 | } else { |
| 1422 | if (high != low) { |
| 1423 | __ LoadConst32(TMP, high); |
| 1424 | } |
| 1425 | __ Xor(dst_high, lhs_high, TMP); |
| 1426 | } |
| 1427 | } else if (instruction->IsAnd()) { |
| 1428 | uint32_t low = Low32Bits(value); |
| 1429 | uint32_t high = High32Bits(value); |
| 1430 | if (IsUint<16>(low)) { |
| 1431 | __ Andi(dst_low, lhs_low, low); |
| 1432 | } else if (low != 0xFFFFFFFF) { |
| 1433 | __ LoadConst32(TMP, low); |
| 1434 | __ And(dst_low, lhs_low, TMP); |
| 1435 | } else if (dst_low != lhs_low) { |
| 1436 | __ Move(dst_low, lhs_low); |
| 1437 | } |
| 1438 | if (IsUint<16>(high)) { |
| 1439 | __ Andi(dst_high, lhs_high, high); |
| 1440 | } else if (high != 0xFFFFFFFF) { |
| 1441 | if (high != low) { |
| 1442 | __ LoadConst32(TMP, high); |
| 1443 | } |
| 1444 | __ And(dst_high, lhs_high, TMP); |
| 1445 | } else if (dst_high != lhs_high) { |
| 1446 | __ Move(dst_high, lhs_high); |
| 1447 | } |
| 1448 | } else { |
| 1449 | if (instruction->IsSub()) { |
| 1450 | value = -value; |
| 1451 | } else { |
| 1452 | DCHECK(instruction->IsAdd()); |
| 1453 | } |
| 1454 | int32_t low = Low32Bits(value); |
| 1455 | int32_t high = High32Bits(value); |
| 1456 | if (IsInt<16>(low)) { |
| 1457 | if (dst_low != lhs_low || low != 0) { |
| 1458 | __ Addiu(dst_low, lhs_low, low); |
| 1459 | } |
| 1460 | if (low != 0) { |
| 1461 | __ Sltiu(AT, dst_low, low); |
| 1462 | } |
| 1463 | } else { |
| 1464 | __ LoadConst32(TMP, low); |
| 1465 | __ Addu(dst_low, lhs_low, TMP); |
| 1466 | __ Sltu(AT, dst_low, TMP); |
| 1467 | } |
| 1468 | if (IsInt<16>(high)) { |
| 1469 | if (dst_high != lhs_high || high != 0) { |
| 1470 | __ Addiu(dst_high, lhs_high, high); |
| 1471 | } |
| 1472 | } else { |
| 1473 | if (high != low) { |
| 1474 | __ LoadConst32(TMP, high); |
| 1475 | } |
| 1476 | __ Addu(dst_high, lhs_high, TMP); |
| 1477 | } |
| 1478 | if (low != 0) { |
| 1479 | __ Addu(dst_high, dst_high, AT); |
| 1480 | } |
| 1481 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1482 | } |
| 1483 | break; |
| 1484 | } |
| 1485 | |
| 1486 | case Primitive::kPrimFloat: |
| 1487 | case Primitive::kPrimDouble: { |
| 1488 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 1489 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 1490 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 1491 | if (instruction->IsAdd()) { |
| 1492 | if (type == Primitive::kPrimFloat) { |
| 1493 | __ AddS(dst, lhs, rhs); |
| 1494 | } else { |
| 1495 | __ AddD(dst, lhs, rhs); |
| 1496 | } |
| 1497 | } else { |
| 1498 | DCHECK(instruction->IsSub()); |
| 1499 | if (type == Primitive::kPrimFloat) { |
| 1500 | __ SubS(dst, lhs, rhs); |
| 1501 | } else { |
| 1502 | __ SubD(dst, lhs, rhs); |
| 1503 | } |
| 1504 | } |
| 1505 | break; |
| 1506 | } |
| 1507 | |
| 1508 | default: |
| 1509 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| 1510 | } |
| 1511 | } |
| 1512 | |
| 1513 | void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) { |
| 1514 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 1515 | |
| 1516 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1517 | Primitive::Type type = instr->GetResultType(); |
| 1518 | switch (type) { |
| 1519 | case Primitive::kPrimInt: |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1520 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1521 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 1522 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1523 | break; |
| 1524 | case Primitive::kPrimLong: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1525 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1526 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 1527 | locations->SetOut(Location::RequiresRegister()); |
| 1528 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1529 | default: |
| 1530 | LOG(FATAL) << "Unexpected shift type " << type; |
| 1531 | } |
| 1532 | } |
| 1533 | |
| 1534 | static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte; |
| 1535 | |
| 1536 | void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) { |
| 1537 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 1538 | LocationSummary* locations = instr->GetLocations(); |
| 1539 | Primitive::Type type = instr->GetType(); |
| 1540 | |
| 1541 | Location rhs_location = locations->InAt(1); |
| 1542 | bool use_imm = rhs_location.IsConstant(); |
| 1543 | Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>(); |
| 1544 | int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0; |
| 1545 | uint32_t shift_mask = (type == Primitive::kPrimInt) ? kMaxIntShiftValue : kMaxLongShiftValue; |
| 1546 | uint32_t shift_value = rhs_imm & shift_mask; |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1547 | // Is the INS (Insert Bit Field) instruction supported? |
| 1548 | bool has_ins = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1549 | |
| 1550 | switch (type) { |
| 1551 | case Primitive::kPrimInt: { |
| 1552 | Register dst = locations->Out().AsRegister<Register>(); |
| 1553 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 1554 | if (use_imm) { |
| 1555 | if (instr->IsShl()) { |
| 1556 | __ Sll(dst, lhs, shift_value); |
| 1557 | } else if (instr->IsShr()) { |
| 1558 | __ Sra(dst, lhs, shift_value); |
| 1559 | } else { |
| 1560 | __ Srl(dst, lhs, shift_value); |
| 1561 | } |
| 1562 | } else { |
| 1563 | if (instr->IsShl()) { |
| 1564 | __ Sllv(dst, lhs, rhs_reg); |
| 1565 | } else if (instr->IsShr()) { |
| 1566 | __ Srav(dst, lhs, rhs_reg); |
| 1567 | } else { |
| 1568 | __ Srlv(dst, lhs, rhs_reg); |
| 1569 | } |
| 1570 | } |
| 1571 | break; |
| 1572 | } |
| 1573 | |
| 1574 | case Primitive::kPrimLong: { |
| 1575 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 1576 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 1577 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 1578 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 1579 | if (use_imm) { |
| 1580 | if (shift_value == 0) { |
| 1581 | codegen_->Move64(locations->Out(), locations->InAt(0)); |
| 1582 | } else if (shift_value < kMipsBitsPerWord) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1583 | if (has_ins) { |
| 1584 | if (instr->IsShl()) { |
| 1585 | __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value); |
| 1586 | __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value); |
| 1587 | __ Sll(dst_low, lhs_low, shift_value); |
| 1588 | } else if (instr->IsShr()) { |
| 1589 | __ Srl(dst_low, lhs_low, shift_value); |
| 1590 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 1591 | __ Sra(dst_high, lhs_high, shift_value); |
| 1592 | } else { |
| 1593 | __ Srl(dst_low, lhs_low, shift_value); |
| 1594 | __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value); |
| 1595 | __ Srl(dst_high, lhs_high, shift_value); |
| 1596 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1597 | } else { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 1598 | if (instr->IsShl()) { |
| 1599 | __ Sll(dst_low, lhs_low, shift_value); |
| 1600 | __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value); |
| 1601 | __ Sll(dst_high, lhs_high, shift_value); |
| 1602 | __ Or(dst_high, dst_high, TMP); |
| 1603 | } else if (instr->IsShr()) { |
| 1604 | __ Sra(dst_high, lhs_high, shift_value); |
| 1605 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 1606 | __ Srl(dst_low, lhs_low, shift_value); |
| 1607 | __ Or(dst_low, dst_low, TMP); |
| 1608 | } else { |
| 1609 | __ Srl(dst_high, lhs_high, shift_value); |
| 1610 | __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value); |
| 1611 | __ Srl(dst_low, lhs_low, shift_value); |
| 1612 | __ Or(dst_low, dst_low, TMP); |
| 1613 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1614 | } |
| 1615 | } else { |
| 1616 | shift_value -= kMipsBitsPerWord; |
| 1617 | if (instr->IsShl()) { |
| 1618 | __ Sll(dst_high, lhs_low, shift_value); |
| 1619 | __ Move(dst_low, ZERO); |
| 1620 | } else if (instr->IsShr()) { |
| 1621 | __ Sra(dst_low, lhs_high, shift_value); |
| 1622 | __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1); |
| 1623 | } else { |
| 1624 | __ Srl(dst_low, lhs_high, shift_value); |
| 1625 | __ Move(dst_high, ZERO); |
| 1626 | } |
| 1627 | } |
| 1628 | } else { |
| 1629 | MipsLabel done; |
| 1630 | if (instr->IsShl()) { |
| 1631 | __ Sllv(dst_low, lhs_low, rhs_reg); |
| 1632 | __ Nor(AT, ZERO, rhs_reg); |
| 1633 | __ Srl(TMP, lhs_low, 1); |
| 1634 | __ Srlv(TMP, TMP, AT); |
| 1635 | __ Sllv(dst_high, lhs_high, rhs_reg); |
| 1636 | __ Or(dst_high, dst_high, TMP); |
| 1637 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 1638 | __ Beqz(TMP, &done); |
| 1639 | __ Move(dst_high, dst_low); |
| 1640 | __ Move(dst_low, ZERO); |
| 1641 | } else if (instr->IsShr()) { |
| 1642 | __ Srav(dst_high, lhs_high, rhs_reg); |
| 1643 | __ Nor(AT, ZERO, rhs_reg); |
| 1644 | __ Sll(TMP, lhs_high, 1); |
| 1645 | __ Sllv(TMP, TMP, AT); |
| 1646 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 1647 | __ Or(dst_low, dst_low, TMP); |
| 1648 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 1649 | __ Beqz(TMP, &done); |
| 1650 | __ Move(dst_low, dst_high); |
| 1651 | __ Sra(dst_high, dst_high, 31); |
| 1652 | } else { |
| 1653 | __ Srlv(dst_high, lhs_high, rhs_reg); |
| 1654 | __ Nor(AT, ZERO, rhs_reg); |
| 1655 | __ Sll(TMP, lhs_high, 1); |
| 1656 | __ Sllv(TMP, TMP, AT); |
| 1657 | __ Srlv(dst_low, lhs_low, rhs_reg); |
| 1658 | __ Or(dst_low, dst_low, TMP); |
| 1659 | __ Andi(TMP, rhs_reg, kMipsBitsPerWord); |
| 1660 | __ Beqz(TMP, &done); |
| 1661 | __ Move(dst_low, dst_high); |
| 1662 | __ Move(dst_high, ZERO); |
| 1663 | } |
| 1664 | __ Bind(&done); |
| 1665 | } |
| 1666 | break; |
| 1667 | } |
| 1668 | |
| 1669 | default: |
| 1670 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 1671 | } |
| 1672 | } |
| 1673 | |
| 1674 | void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) { |
| 1675 | HandleBinaryOp(instruction); |
| 1676 | } |
| 1677 | |
| 1678 | void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) { |
| 1679 | HandleBinaryOp(instruction); |
| 1680 | } |
| 1681 | |
| 1682 | void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) { |
| 1683 | HandleBinaryOp(instruction); |
| 1684 | } |
| 1685 | |
| 1686 | void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) { |
| 1687 | HandleBinaryOp(instruction); |
| 1688 | } |
| 1689 | |
| 1690 | void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) { |
| 1691 | LocationSummary* locations = |
| 1692 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1693 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1694 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1695 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 1696 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1697 | } else { |
| 1698 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1699 | } |
| 1700 | } |
| 1701 | |
| 1702 | void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) { |
| 1703 | LocationSummary* locations = instruction->GetLocations(); |
| 1704 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 1705 | Location index = locations->InAt(1); |
| 1706 | Primitive::Type type = instruction->GetType(); |
| 1707 | |
| 1708 | switch (type) { |
| 1709 | case Primitive::kPrimBoolean: { |
| 1710 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 1711 | Register out = locations->Out().AsRegister<Register>(); |
| 1712 | if (index.IsConstant()) { |
| 1713 | size_t offset = |
| 1714 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
| 1715 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); |
| 1716 | } else { |
| 1717 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
| 1718 | __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset); |
| 1719 | } |
| 1720 | break; |
| 1721 | } |
| 1722 | |
| 1723 | case Primitive::kPrimByte: { |
| 1724 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
| 1725 | Register out = locations->Out().AsRegister<Register>(); |
| 1726 | if (index.IsConstant()) { |
| 1727 | size_t offset = |
| 1728 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
| 1729 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset); |
| 1730 | } else { |
| 1731 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
| 1732 | __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset); |
| 1733 | } |
| 1734 | break; |
| 1735 | } |
| 1736 | |
| 1737 | case Primitive::kPrimShort: { |
| 1738 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
| 1739 | Register out = locations->Out().AsRegister<Register>(); |
| 1740 | if (index.IsConstant()) { |
| 1741 | size_t offset = |
| 1742 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 1743 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); |
| 1744 | } else { |
| 1745 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_2); |
| 1746 | __ Addu(TMP, obj, TMP); |
| 1747 | __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset); |
| 1748 | } |
| 1749 | break; |
| 1750 | } |
| 1751 | |
| 1752 | case Primitive::kPrimChar: { |
| 1753 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 1754 | Register out = locations->Out().AsRegister<Register>(); |
| 1755 | if (index.IsConstant()) { |
| 1756 | size_t offset = |
| 1757 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 1758 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); |
| 1759 | } else { |
| 1760 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_2); |
| 1761 | __ Addu(TMP, obj, TMP); |
| 1762 | __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset); |
| 1763 | } |
| 1764 | break; |
| 1765 | } |
| 1766 | |
| 1767 | case Primitive::kPrimInt: |
| 1768 | case Primitive::kPrimNot: { |
| 1769 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
| 1770 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 1771 | Register out = locations->Out().AsRegister<Register>(); |
| 1772 | if (index.IsConstant()) { |
| 1773 | size_t offset = |
| 1774 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 1775 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 1776 | } else { |
| 1777 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_4); |
| 1778 | __ Addu(TMP, obj, TMP); |
| 1779 | __ LoadFromOffset(kLoadWord, out, TMP, data_offset); |
| 1780 | } |
| 1781 | break; |
| 1782 | } |
| 1783 | |
| 1784 | case Primitive::kPrimLong: { |
| 1785 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 1786 | Register out = locations->Out().AsRegisterPairLow<Register>(); |
| 1787 | if (index.IsConstant()) { |
| 1788 | size_t offset = |
| 1789 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 1790 | __ LoadFromOffset(kLoadDoubleword, out, obj, offset); |
| 1791 | } else { |
| 1792 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_8); |
| 1793 | __ Addu(TMP, obj, TMP); |
| 1794 | __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset); |
| 1795 | } |
| 1796 | break; |
| 1797 | } |
| 1798 | |
| 1799 | case Primitive::kPrimFloat: { |
| 1800 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 1801 | FRegister out = locations->Out().AsFpuRegister<FRegister>(); |
| 1802 | if (index.IsConstant()) { |
| 1803 | size_t offset = |
| 1804 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 1805 | __ LoadSFromOffset(out, obj, offset); |
| 1806 | } else { |
| 1807 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_4); |
| 1808 | __ Addu(TMP, obj, TMP); |
| 1809 | __ LoadSFromOffset(out, TMP, data_offset); |
| 1810 | } |
| 1811 | break; |
| 1812 | } |
| 1813 | |
| 1814 | case Primitive::kPrimDouble: { |
| 1815 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 1816 | FRegister out = locations->Out().AsFpuRegister<FRegister>(); |
| 1817 | if (index.IsConstant()) { |
| 1818 | size_t offset = |
| 1819 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 1820 | __ LoadDFromOffset(out, obj, offset); |
| 1821 | } else { |
| 1822 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_8); |
| 1823 | __ Addu(TMP, obj, TMP); |
| 1824 | __ LoadDFromOffset(out, TMP, data_offset); |
| 1825 | } |
| 1826 | break; |
| 1827 | } |
| 1828 | |
| 1829 | case Primitive::kPrimVoid: |
| 1830 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 1831 | UNREACHABLE(); |
| 1832 | } |
| 1833 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1834 | } |
| 1835 | |
| 1836 | void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) { |
| 1837 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1838 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1839 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1840 | } |
| 1841 | |
| 1842 | void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) { |
| 1843 | LocationSummary* locations = instruction->GetLocations(); |
| 1844 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
| 1845 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 1846 | Register out = locations->Out().AsRegister<Register>(); |
| 1847 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 1848 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1849 | } |
| 1850 | |
| 1851 | void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) { |
Pavle Batuta | 934808f | 2015-11-03 13:23:54 +0100 | [diff] [blame] | 1852 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1853 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 1854 | instruction, |
Pavle Batuta | 934808f | 2015-11-03 13:23:54 +0100 | [diff] [blame] | 1855 | needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 1856 | if (needs_runtime_call) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1857 | InvokeRuntimeCallingConvention calling_convention; |
| 1858 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1859 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1860 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1861 | } else { |
| 1862 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1863 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1864 | if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
| 1865 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 1866 | } else { |
| 1867 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1868 | } |
| 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) { |
| 1873 | LocationSummary* locations = instruction->GetLocations(); |
| 1874 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 1875 | Location index = locations->InAt(1); |
| 1876 | Primitive::Type value_type = instruction->GetComponentType(); |
| 1877 | bool needs_runtime_call = locations->WillCall(); |
| 1878 | bool needs_write_barrier = |
| 1879 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 1880 | |
| 1881 | switch (value_type) { |
| 1882 | case Primitive::kPrimBoolean: |
| 1883 | case Primitive::kPrimByte: { |
| 1884 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 1885 | Register value = locations->InAt(2).AsRegister<Register>(); |
| 1886 | if (index.IsConstant()) { |
| 1887 | size_t offset = |
| 1888 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
| 1889 | __ StoreToOffset(kStoreByte, value, obj, offset); |
| 1890 | } else { |
| 1891 | __ Addu(TMP, obj, index.AsRegister<Register>()); |
| 1892 | __ StoreToOffset(kStoreByte, value, TMP, data_offset); |
| 1893 | } |
| 1894 | break; |
| 1895 | } |
| 1896 | |
| 1897 | case Primitive::kPrimShort: |
| 1898 | case Primitive::kPrimChar: { |
| 1899 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 1900 | Register value = locations->InAt(2).AsRegister<Register>(); |
| 1901 | if (index.IsConstant()) { |
| 1902 | size_t offset = |
| 1903 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 1904 | __ StoreToOffset(kStoreHalfword, value, obj, offset); |
| 1905 | } else { |
| 1906 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_2); |
| 1907 | __ Addu(TMP, obj, TMP); |
| 1908 | __ StoreToOffset(kStoreHalfword, value, TMP, data_offset); |
| 1909 | } |
| 1910 | break; |
| 1911 | } |
| 1912 | |
| 1913 | case Primitive::kPrimInt: |
| 1914 | case Primitive::kPrimNot: { |
| 1915 | if (!needs_runtime_call) { |
| 1916 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 1917 | Register value = locations->InAt(2).AsRegister<Register>(); |
| 1918 | if (index.IsConstant()) { |
| 1919 | size_t offset = |
| 1920 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 1921 | __ StoreToOffset(kStoreWord, value, obj, offset); |
| 1922 | } else { |
| 1923 | DCHECK(index.IsRegister()) << index; |
| 1924 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_4); |
| 1925 | __ Addu(TMP, obj, TMP); |
| 1926 | __ StoreToOffset(kStoreWord, value, TMP, data_offset); |
| 1927 | } |
| 1928 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1929 | if (needs_write_barrier) { |
| 1930 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 1931 | codegen_->MarkGCCard(obj, value); |
| 1932 | } |
| 1933 | } else { |
| 1934 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 1935 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 1936 | instruction, |
| 1937 | instruction->GetDexPc(), |
| 1938 | nullptr, |
| 1939 | IsDirectEntrypoint(kQuickAputObject)); |
| 1940 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 1941 | } |
| 1942 | break; |
| 1943 | } |
| 1944 | |
| 1945 | case Primitive::kPrimLong: { |
| 1946 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 1947 | Register value = locations->InAt(2).AsRegisterPairLow<Register>(); |
| 1948 | if (index.IsConstant()) { |
| 1949 | size_t offset = |
| 1950 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 1951 | __ StoreToOffset(kStoreDoubleword, value, obj, offset); |
| 1952 | } else { |
| 1953 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_8); |
| 1954 | __ Addu(TMP, obj, TMP); |
| 1955 | __ StoreToOffset(kStoreDoubleword, value, TMP, data_offset); |
| 1956 | } |
| 1957 | break; |
| 1958 | } |
| 1959 | |
| 1960 | case Primitive::kPrimFloat: { |
| 1961 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 1962 | FRegister value = locations->InAt(2).AsFpuRegister<FRegister>(); |
| 1963 | DCHECK(locations->InAt(2).IsFpuRegister()); |
| 1964 | if (index.IsConstant()) { |
| 1965 | size_t offset = |
| 1966 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 1967 | __ StoreSToOffset(value, obj, offset); |
| 1968 | } else { |
| 1969 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_4); |
| 1970 | __ Addu(TMP, obj, TMP); |
| 1971 | __ StoreSToOffset(value, TMP, data_offset); |
| 1972 | } |
| 1973 | break; |
| 1974 | } |
| 1975 | |
| 1976 | case Primitive::kPrimDouble: { |
| 1977 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 1978 | FRegister value = locations->InAt(2).AsFpuRegister<FRegister>(); |
| 1979 | DCHECK(locations->InAt(2).IsFpuRegister()); |
| 1980 | if (index.IsConstant()) { |
| 1981 | size_t offset = |
| 1982 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 1983 | __ StoreDToOffset(value, obj, offset); |
| 1984 | } else { |
| 1985 | __ Sll(TMP, index.AsRegister<Register>(), TIMES_8); |
| 1986 | __ Addu(TMP, obj, TMP); |
| 1987 | __ StoreDToOffset(value, TMP, data_offset); |
| 1988 | } |
| 1989 | break; |
| 1990 | } |
| 1991 | |
| 1992 | case Primitive::kPrimVoid: |
| 1993 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 1994 | UNREACHABLE(); |
| 1995 | } |
| 1996 | |
| 1997 | // Ints and objects are handled in the switch. |
| 1998 | if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) { |
| 1999 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2000 | } |
| 2001 | } |
| 2002 | |
| 2003 | void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2004 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 2005 | ? LocationSummary::kCallOnSlowPath |
| 2006 | : LocationSummary::kNoCall; |
| 2007 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 2008 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2009 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2010 | if (instruction->HasUses()) { |
| 2011 | locations->SetOut(Location::SameAsFirstInput()); |
| 2012 | } |
| 2013 | } |
| 2014 | |
| 2015 | void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2016 | LocationSummary* locations = instruction->GetLocations(); |
| 2017 | BoundsCheckSlowPathMIPS* slow_path = |
| 2018 | new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS(instruction); |
| 2019 | codegen_->AddSlowPath(slow_path); |
| 2020 | |
| 2021 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 2022 | Register length = locations->InAt(1).AsRegister<Register>(); |
| 2023 | |
| 2024 | // length is limited by the maximum positive signed 32-bit integer. |
| 2025 | // Unsigned comparison of length and index checks for index < 0 |
| 2026 | // and for length <= index simultaneously. |
| 2027 | __ Bgeu(index, length, slow_path->GetEntryLabel()); |
| 2028 | } |
| 2029 | |
| 2030 | void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) { |
| 2031 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2032 | instruction, |
| 2033 | LocationSummary::kCallOnSlowPath); |
| 2034 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2035 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2036 | // Note that TypeCheckSlowPathMIPS uses this register too. |
| 2037 | locations->AddTemp(Location::RequiresRegister()); |
| 2038 | } |
| 2039 | |
| 2040 | void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) { |
| 2041 | LocationSummary* locations = instruction->GetLocations(); |
| 2042 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 2043 | Register cls = locations->InAt(1).AsRegister<Register>(); |
| 2044 | Register obj_cls = locations->GetTemp(0).AsRegister<Register>(); |
| 2045 | |
| 2046 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction); |
| 2047 | codegen_->AddSlowPath(slow_path); |
| 2048 | |
| 2049 | // TODO: avoid this check if we know obj is not null. |
| 2050 | __ Beqz(obj, slow_path->GetExitLabel()); |
| 2051 | // Compare the class of `obj` with `cls`. |
| 2052 | __ LoadFromOffset(kLoadWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value()); |
| 2053 | __ Bne(obj_cls, cls, slow_path->GetEntryLabel()); |
| 2054 | __ Bind(slow_path->GetExitLabel()); |
| 2055 | } |
| 2056 | |
| 2057 | void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 2058 | LocationSummary* locations = |
| 2059 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2060 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2061 | if (check->HasUses()) { |
| 2062 | locations->SetOut(Location::SameAsFirstInput()); |
| 2063 | } |
| 2064 | } |
| 2065 | |
| 2066 | void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) { |
| 2067 | // We assume the class is not null. |
| 2068 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS( |
| 2069 | check->GetLoadClass(), |
| 2070 | check, |
| 2071 | check->GetDexPc(), |
| 2072 | true); |
| 2073 | codegen_->AddSlowPath(slow_path); |
| 2074 | GenerateClassInitializationCheck(slow_path, |
| 2075 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
| 2076 | } |
| 2077 | |
| 2078 | void LocationsBuilderMIPS::VisitCompare(HCompare* compare) { |
| 2079 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 2080 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2081 | LocationSummary* locations = |
| 2082 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2083 | |
| 2084 | switch (in_type) { |
| 2085 | case Primitive::kPrimLong: |
| 2086 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2087 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2088 | // Output overlaps because it is written before doing the low comparison. |
| 2089 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2090 | break; |
| 2091 | |
| 2092 | case Primitive::kPrimFloat: |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2093 | case Primitive::kPrimDouble: |
| 2094 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2095 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2096 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2097 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2098 | |
| 2099 | default: |
| 2100 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2101 | } |
| 2102 | } |
| 2103 | |
| 2104 | void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) { |
| 2105 | LocationSummary* locations = instruction->GetLocations(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2106 | Register res = locations->Out().AsRegister<Register>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2107 | Primitive::Type in_type = instruction->InputAt(0)->GetType(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2108 | bool gt_bias = instruction->IsGtBias(); |
| 2109 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2110 | |
| 2111 | // 0 if: left == right |
| 2112 | // 1 if: left > right |
| 2113 | // -1 if: left < right |
| 2114 | switch (in_type) { |
| 2115 | case Primitive::kPrimLong: { |
| 2116 | MipsLabel done; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2117 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2118 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 2119 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 2120 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 2121 | // TODO: more efficient (direct) comparison with a constant. |
| 2122 | __ Slt(TMP, lhs_high, rhs_high); |
| 2123 | __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt. |
| 2124 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 2125 | __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal. |
| 2126 | __ Sltu(TMP, lhs_low, rhs_low); |
| 2127 | __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt. |
| 2128 | __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ]. |
| 2129 | __ Bind(&done); |
| 2130 | break; |
| 2131 | } |
| 2132 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2133 | case Primitive::kPrimFloat: { |
| 2134 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2135 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2136 | MipsLabel done; |
| 2137 | if (isR6) { |
| 2138 | __ CmpEqS(FTMP, lhs, rhs); |
| 2139 | __ LoadConst32(res, 0); |
| 2140 | __ Bc1nez(FTMP, &done); |
| 2141 | if (gt_bias) { |
| 2142 | __ CmpLtS(FTMP, lhs, rhs); |
| 2143 | __ LoadConst32(res, -1); |
| 2144 | __ Bc1nez(FTMP, &done); |
| 2145 | __ LoadConst32(res, 1); |
| 2146 | } else { |
| 2147 | __ CmpLtS(FTMP, rhs, lhs); |
| 2148 | __ LoadConst32(res, 1); |
| 2149 | __ Bc1nez(FTMP, &done); |
| 2150 | __ LoadConst32(res, -1); |
| 2151 | } |
| 2152 | } else { |
| 2153 | if (gt_bias) { |
| 2154 | __ ColtS(0, lhs, rhs); |
| 2155 | __ LoadConst32(res, -1); |
| 2156 | __ Bc1t(0, &done); |
| 2157 | __ CeqS(0, lhs, rhs); |
| 2158 | __ LoadConst32(res, 1); |
| 2159 | __ Movt(res, ZERO, 0); |
| 2160 | } else { |
| 2161 | __ ColtS(0, rhs, lhs); |
| 2162 | __ LoadConst32(res, 1); |
| 2163 | __ Bc1t(0, &done); |
| 2164 | __ CeqS(0, lhs, rhs); |
| 2165 | __ LoadConst32(res, -1); |
| 2166 | __ Movt(res, ZERO, 0); |
| 2167 | } |
| 2168 | } |
| 2169 | __ Bind(&done); |
| 2170 | break; |
| 2171 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2172 | case Primitive::kPrimDouble: { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2173 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2174 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2175 | MipsLabel done; |
| 2176 | if (isR6) { |
| 2177 | __ CmpEqD(FTMP, lhs, rhs); |
| 2178 | __ LoadConst32(res, 0); |
| 2179 | __ Bc1nez(FTMP, &done); |
| 2180 | if (gt_bias) { |
| 2181 | __ CmpLtD(FTMP, lhs, rhs); |
| 2182 | __ LoadConst32(res, -1); |
| 2183 | __ Bc1nez(FTMP, &done); |
| 2184 | __ LoadConst32(res, 1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2185 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2186 | __ CmpLtD(FTMP, rhs, lhs); |
| 2187 | __ LoadConst32(res, 1); |
| 2188 | __ Bc1nez(FTMP, &done); |
| 2189 | __ LoadConst32(res, -1); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2190 | } |
| 2191 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2192 | if (gt_bias) { |
| 2193 | __ ColtD(0, lhs, rhs); |
| 2194 | __ LoadConst32(res, -1); |
| 2195 | __ Bc1t(0, &done); |
| 2196 | __ CeqD(0, lhs, rhs); |
| 2197 | __ LoadConst32(res, 1); |
| 2198 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2199 | } else { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2200 | __ ColtD(0, rhs, lhs); |
| 2201 | __ LoadConst32(res, 1); |
| 2202 | __ Bc1t(0, &done); |
| 2203 | __ CeqD(0, lhs, rhs); |
| 2204 | __ LoadConst32(res, -1); |
| 2205 | __ Movt(res, ZERO, 0); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2206 | } |
| 2207 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2208 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2209 | break; |
| 2210 | } |
| 2211 | |
| 2212 | default: |
| 2213 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2214 | } |
| 2215 | } |
| 2216 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2217 | void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2218 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2219 | switch (instruction->InputAt(0)->GetType()) { |
| 2220 | default: |
| 2221 | case Primitive::kPrimLong: |
| 2222 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2223 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2224 | break; |
| 2225 | |
| 2226 | case Primitive::kPrimFloat: |
| 2227 | case Primitive::kPrimDouble: |
| 2228 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2229 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2230 | break; |
| 2231 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2232 | if (instruction->NeedsMaterialization()) { |
| 2233 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2234 | } |
| 2235 | } |
| 2236 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2237 | void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2238 | if (!instruction->NeedsMaterialization()) { |
| 2239 | return; |
| 2240 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2241 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2242 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2243 | LocationSummary* locations = instruction->GetLocations(); |
| 2244 | Register dst = locations->Out().AsRegister<Register>(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2245 | MipsLabel true_label; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2246 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2247 | switch (type) { |
| 2248 | default: |
| 2249 | // Integer case. |
| 2250 | GenerateIntCompare(instruction->GetCondition(), locations); |
| 2251 | return; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2252 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2253 | case Primitive::kPrimLong: |
| 2254 | // TODO: don't use branches. |
| 2255 | GenerateLongCompareAndBranch(instruction->GetCondition(), locations, &true_label); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2256 | break; |
| 2257 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2258 | case Primitive::kPrimFloat: |
| 2259 | case Primitive::kPrimDouble: |
| 2260 | // TODO: don't use branches. |
| 2261 | GenerateFpCompareAndBranch(instruction->GetCondition(), |
| 2262 | instruction->IsGtBias(), |
| 2263 | type, |
| 2264 | locations, |
| 2265 | &true_label); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2266 | break; |
| 2267 | } |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2268 | |
| 2269 | // Convert the branches into the result. |
| 2270 | MipsLabel done; |
| 2271 | |
| 2272 | // False case: result = 0. |
| 2273 | __ LoadConst32(dst, 0); |
| 2274 | __ B(&done); |
| 2275 | |
| 2276 | // True case: result = 1. |
| 2277 | __ Bind(&true_label); |
| 2278 | __ LoadConst32(dst, 1); |
| 2279 | __ Bind(&done); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2280 | } |
| 2281 | |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2282 | void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2283 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2284 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 2285 | |
| 2286 | LocationSummary* locations = instruction->GetLocations(); |
| 2287 | Location second = locations->InAt(1); |
| 2288 | DCHECK(second.IsConstant()); |
| 2289 | |
| 2290 | Register out = locations->Out().AsRegister<Register>(); |
| 2291 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2292 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2293 | DCHECK(imm == 1 || imm == -1); |
| 2294 | |
| 2295 | if (instruction->IsRem()) { |
| 2296 | __ Move(out, ZERO); |
| 2297 | } else { |
| 2298 | if (imm == -1) { |
| 2299 | __ Subu(out, ZERO, dividend); |
| 2300 | } else if (out != dividend) { |
| 2301 | __ Move(out, dividend); |
| 2302 | } |
| 2303 | } |
| 2304 | } |
| 2305 | |
| 2306 | void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2307 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2308 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 2309 | |
| 2310 | LocationSummary* locations = instruction->GetLocations(); |
| 2311 | Location second = locations->InAt(1); |
| 2312 | DCHECK(second.IsConstant()); |
| 2313 | |
| 2314 | Register out = locations->Out().AsRegister<Register>(); |
| 2315 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2316 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2317 | uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm)); |
| 2318 | DCHECK(IsPowerOfTwo(abs_imm)); |
| 2319 | int ctz_imm = CTZ(abs_imm); |
| 2320 | |
| 2321 | if (instruction->IsDiv()) { |
| 2322 | if (ctz_imm == 1) { |
| 2323 | // Fast path for division by +/-2, which is very common. |
| 2324 | __ Srl(TMP, dividend, 31); |
| 2325 | } else { |
| 2326 | __ Sra(TMP, dividend, 31); |
| 2327 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 2328 | } |
| 2329 | __ Addu(out, dividend, TMP); |
| 2330 | __ Sra(out, out, ctz_imm); |
| 2331 | if (imm < 0) { |
| 2332 | __ Subu(out, ZERO, out); |
| 2333 | } |
| 2334 | } else { |
| 2335 | if (ctz_imm == 1) { |
| 2336 | // Fast path for modulo +/-2, which is very common. |
| 2337 | __ Sra(TMP, dividend, 31); |
| 2338 | __ Subu(out, dividend, TMP); |
| 2339 | __ Andi(out, out, 1); |
| 2340 | __ Addu(out, out, TMP); |
| 2341 | } else { |
| 2342 | __ Sra(TMP, dividend, 31); |
| 2343 | __ Srl(TMP, TMP, 32 - ctz_imm); |
| 2344 | __ Addu(out, dividend, TMP); |
| 2345 | if (IsUint<16>(abs_imm - 1)) { |
| 2346 | __ Andi(out, out, abs_imm - 1); |
| 2347 | } else { |
| 2348 | __ Sll(out, out, 32 - ctz_imm); |
| 2349 | __ Srl(out, out, 32 - ctz_imm); |
| 2350 | } |
| 2351 | __ Subu(out, out, TMP); |
| 2352 | } |
| 2353 | } |
| 2354 | } |
| 2355 | |
| 2356 | void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2357 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2358 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 2359 | |
| 2360 | LocationSummary* locations = instruction->GetLocations(); |
| 2361 | Location second = locations->InAt(1); |
| 2362 | DCHECK(second.IsConstant()); |
| 2363 | |
| 2364 | Register out = locations->Out().AsRegister<Register>(); |
| 2365 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2366 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2367 | |
| 2368 | int64_t magic; |
| 2369 | int shift; |
| 2370 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2371 | |
| 2372 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 2373 | |
| 2374 | __ LoadConst32(TMP, magic); |
| 2375 | if (isR6) { |
| 2376 | __ MuhR6(TMP, dividend, TMP); |
| 2377 | } else { |
| 2378 | __ MultR2(dividend, TMP); |
| 2379 | __ Mfhi(TMP); |
| 2380 | } |
| 2381 | if (imm > 0 && magic < 0) { |
| 2382 | __ Addu(TMP, TMP, dividend); |
| 2383 | } else if (imm < 0 && magic > 0) { |
| 2384 | __ Subu(TMP, TMP, dividend); |
| 2385 | } |
| 2386 | |
| 2387 | if (shift != 0) { |
| 2388 | __ Sra(TMP, TMP, shift); |
| 2389 | } |
| 2390 | |
| 2391 | if (instruction->IsDiv()) { |
| 2392 | __ Sra(out, TMP, 31); |
| 2393 | __ Subu(out, TMP, out); |
| 2394 | } else { |
| 2395 | __ Sra(AT, TMP, 31); |
| 2396 | __ Subu(AT, TMP, AT); |
| 2397 | __ LoadConst32(TMP, imm); |
| 2398 | if (isR6) { |
| 2399 | __ MulR6(TMP, AT, TMP); |
| 2400 | } else { |
| 2401 | __ MulR2(TMP, AT, TMP); |
| 2402 | } |
| 2403 | __ Subu(out, dividend, TMP); |
| 2404 | } |
| 2405 | } |
| 2406 | |
| 2407 | void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2408 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2409 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt); |
| 2410 | |
| 2411 | LocationSummary* locations = instruction->GetLocations(); |
| 2412 | Register out = locations->Out().AsRegister<Register>(); |
| 2413 | Location second = locations->InAt(1); |
| 2414 | |
| 2415 | if (second.IsConstant()) { |
| 2416 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2417 | if (imm == 0) { |
| 2418 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2419 | } else if (imm == 1 || imm == -1) { |
| 2420 | DivRemOneOrMinusOne(instruction); |
| 2421 | } else if (IsPowerOfTwo(std::abs(imm))) { |
| 2422 | DivRemByPowerOfTwo(instruction); |
| 2423 | } else { |
| 2424 | DCHECK(imm <= -2 || imm >= 2); |
| 2425 | GenerateDivRemWithAnyConstant(instruction); |
| 2426 | } |
| 2427 | } else { |
| 2428 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2429 | Register divisor = second.AsRegister<Register>(); |
| 2430 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 2431 | if (instruction->IsDiv()) { |
| 2432 | if (isR6) { |
| 2433 | __ DivR6(out, dividend, divisor); |
| 2434 | } else { |
| 2435 | __ DivR2(out, dividend, divisor); |
| 2436 | } |
| 2437 | } else { |
| 2438 | if (isR6) { |
| 2439 | __ ModR6(out, dividend, divisor); |
| 2440 | } else { |
| 2441 | __ ModR2(out, dividend, divisor); |
| 2442 | } |
| 2443 | } |
| 2444 | } |
| 2445 | } |
| 2446 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2447 | void LocationsBuilderMIPS::VisitDiv(HDiv* div) { |
| 2448 | Primitive::Type type = div->GetResultType(); |
| 2449 | LocationSummary::CallKind call_kind = (type == Primitive::kPrimLong) |
| 2450 | ? LocationSummary::kCall |
| 2451 | : LocationSummary::kNoCall; |
| 2452 | |
| 2453 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2454 | |
| 2455 | switch (type) { |
| 2456 | case Primitive::kPrimInt: |
| 2457 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2458 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2459 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2460 | break; |
| 2461 | |
| 2462 | case Primitive::kPrimLong: { |
| 2463 | InvokeRuntimeCallingConvention calling_convention; |
| 2464 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2465 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2466 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2467 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2468 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 2469 | break; |
| 2470 | } |
| 2471 | |
| 2472 | case Primitive::kPrimFloat: |
| 2473 | case Primitive::kPrimDouble: |
| 2474 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2475 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2476 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2477 | break; |
| 2478 | |
| 2479 | default: |
| 2480 | LOG(FATAL) << "Unexpected div type " << type; |
| 2481 | } |
| 2482 | } |
| 2483 | |
| 2484 | void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) { |
| 2485 | Primitive::Type type = instruction->GetType(); |
| 2486 | LocationSummary* locations = instruction->GetLocations(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2487 | |
| 2488 | switch (type) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 2489 | case Primitive::kPrimInt: |
| 2490 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2491 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 2492 | case Primitive::kPrimLong: { |
| 2493 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 2494 | instruction, |
| 2495 | instruction->GetDexPc(), |
| 2496 | nullptr, |
| 2497 | IsDirectEntrypoint(kQuickLdiv)); |
| 2498 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| 2499 | break; |
| 2500 | } |
| 2501 | case Primitive::kPrimFloat: |
| 2502 | case Primitive::kPrimDouble: { |
| 2503 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 2504 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 2505 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 2506 | if (type == Primitive::kPrimFloat) { |
| 2507 | __ DivS(dst, lhs, rhs); |
| 2508 | } else { |
| 2509 | __ DivD(dst, lhs, rhs); |
| 2510 | } |
| 2511 | break; |
| 2512 | } |
| 2513 | default: |
| 2514 | LOG(FATAL) << "Unexpected div type " << type; |
| 2515 | } |
| 2516 | } |
| 2517 | |
| 2518 | void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2519 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 2520 | ? LocationSummary::kCallOnSlowPath |
| 2521 | : LocationSummary::kNoCall; |
| 2522 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 2523 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 2524 | if (instruction->HasUses()) { |
| 2525 | locations->SetOut(Location::SameAsFirstInput()); |
| 2526 | } |
| 2527 | } |
| 2528 | |
| 2529 | void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2530 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS(instruction); |
| 2531 | codegen_->AddSlowPath(slow_path); |
| 2532 | Location value = instruction->GetLocations()->InAt(0); |
| 2533 | Primitive::Type type = instruction->GetType(); |
| 2534 | |
| 2535 | switch (type) { |
| 2536 | case Primitive::kPrimByte: |
| 2537 | case Primitive::kPrimChar: |
| 2538 | case Primitive::kPrimShort: |
| 2539 | case Primitive::kPrimInt: { |
| 2540 | if (value.IsConstant()) { |
| 2541 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 2542 | __ B(slow_path->GetEntryLabel()); |
| 2543 | } else { |
| 2544 | // A division by a non-null constant is valid. We don't need to perform |
| 2545 | // any check, so simply fall through. |
| 2546 | } |
| 2547 | } else { |
| 2548 | DCHECK(value.IsRegister()) << value; |
| 2549 | __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 2550 | } |
| 2551 | break; |
| 2552 | } |
| 2553 | case Primitive::kPrimLong: { |
| 2554 | if (value.IsConstant()) { |
| 2555 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 2556 | __ B(slow_path->GetEntryLabel()); |
| 2557 | } else { |
| 2558 | // A division by a non-null constant is valid. We don't need to perform |
| 2559 | // any check, so simply fall through. |
| 2560 | } |
| 2561 | } else { |
| 2562 | DCHECK(value.IsRegisterPair()) << value; |
| 2563 | __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>()); |
| 2564 | __ Beqz(TMP, slow_path->GetEntryLabel()); |
| 2565 | } |
| 2566 | break; |
| 2567 | } |
| 2568 | default: |
| 2569 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
| 2570 | } |
| 2571 | } |
| 2572 | |
| 2573 | void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2574 | LocationSummary* locations = |
| 2575 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2576 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2577 | } |
| 2578 | |
| 2579 | void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) { |
| 2580 | // Will be generated at use site. |
| 2581 | } |
| 2582 | |
| 2583 | void LocationsBuilderMIPS::VisitExit(HExit* exit) { |
| 2584 | exit->SetLocations(nullptr); |
| 2585 | } |
| 2586 | |
| 2587 | void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 2588 | } |
| 2589 | |
| 2590 | void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) { |
| 2591 | LocationSummary* locations = |
| 2592 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2593 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2594 | } |
| 2595 | |
| 2596 | void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| 2597 | // Will be generated at use site. |
| 2598 | } |
| 2599 | |
| 2600 | void LocationsBuilderMIPS::VisitGoto(HGoto* got) { |
| 2601 | got->SetLocations(nullptr); |
| 2602 | } |
| 2603 | |
| 2604 | void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| 2605 | DCHECK(!successor->IsExitBlock()); |
| 2606 | HBasicBlock* block = got->GetBlock(); |
| 2607 | HInstruction* previous = got->GetPrevious(); |
| 2608 | HLoopInformation* info = block->GetLoopInformation(); |
| 2609 | |
| 2610 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| 2611 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2612 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2613 | return; |
| 2614 | } |
| 2615 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2616 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2617 | } |
| 2618 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 2619 | __ B(codegen_->GetLabelOf(successor)); |
| 2620 | } |
| 2621 | } |
| 2622 | |
| 2623 | void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) { |
| 2624 | HandleGoto(got, got->GetSuccessor()); |
| 2625 | } |
| 2626 | |
| 2627 | void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2628 | try_boundary->SetLocations(nullptr); |
| 2629 | } |
| 2630 | |
| 2631 | void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2632 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2633 | if (!successor->IsExitBlock()) { |
| 2634 | HandleGoto(try_boundary, successor); |
| 2635 | } |
| 2636 | } |
| 2637 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 2638 | void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond, |
| 2639 | LocationSummary* locations) { |
| 2640 | Register dst = locations->Out().AsRegister<Register>(); |
| 2641 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2642 | Location rhs_location = locations->InAt(1); |
| 2643 | Register rhs_reg = ZERO; |
| 2644 | int64_t rhs_imm = 0; |
| 2645 | bool use_imm = rhs_location.IsConstant(); |
| 2646 | if (use_imm) { |
| 2647 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 2648 | } else { |
| 2649 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 2650 | } |
| 2651 | |
| 2652 | switch (cond) { |
| 2653 | case kCondEQ: |
| 2654 | case kCondNE: |
| 2655 | if (use_imm && IsUint<16>(rhs_imm)) { |
| 2656 | __ Xori(dst, lhs, rhs_imm); |
| 2657 | } else { |
| 2658 | if (use_imm) { |
| 2659 | rhs_reg = TMP; |
| 2660 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2661 | } |
| 2662 | __ Xor(dst, lhs, rhs_reg); |
| 2663 | } |
| 2664 | if (cond == kCondEQ) { |
| 2665 | __ Sltiu(dst, dst, 1); |
| 2666 | } else { |
| 2667 | __ Sltu(dst, ZERO, dst); |
| 2668 | } |
| 2669 | break; |
| 2670 | |
| 2671 | case kCondLT: |
| 2672 | case kCondGE: |
| 2673 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 2674 | __ Slti(dst, lhs, rhs_imm); |
| 2675 | } else { |
| 2676 | if (use_imm) { |
| 2677 | rhs_reg = TMP; |
| 2678 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2679 | } |
| 2680 | __ Slt(dst, lhs, rhs_reg); |
| 2681 | } |
| 2682 | if (cond == kCondGE) { |
| 2683 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 2684 | // only the slt instruction but no sge. |
| 2685 | __ Xori(dst, dst, 1); |
| 2686 | } |
| 2687 | break; |
| 2688 | |
| 2689 | case kCondLE: |
| 2690 | case kCondGT: |
| 2691 | if (use_imm && IsInt<16>(rhs_imm + 1)) { |
| 2692 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 2693 | __ Slti(dst, lhs, rhs_imm + 1); |
| 2694 | if (cond == kCondGT) { |
| 2695 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 2696 | // only the slti instruction but no sgti. |
| 2697 | __ Xori(dst, dst, 1); |
| 2698 | } |
| 2699 | } else { |
| 2700 | if (use_imm) { |
| 2701 | rhs_reg = TMP; |
| 2702 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2703 | } |
| 2704 | __ Slt(dst, rhs_reg, lhs); |
| 2705 | if (cond == kCondLE) { |
| 2706 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 2707 | // only the slt instruction but no sle. |
| 2708 | __ Xori(dst, dst, 1); |
| 2709 | } |
| 2710 | } |
| 2711 | break; |
| 2712 | |
| 2713 | case kCondB: |
| 2714 | case kCondAE: |
| 2715 | if (use_imm && IsInt<16>(rhs_imm)) { |
| 2716 | // Sltiu sign-extends its 16-bit immediate operand before |
| 2717 | // the comparison and thus lets us compare directly with |
| 2718 | // unsigned values in the ranges [0, 0x7fff] and |
| 2719 | // [0xffff8000, 0xffffffff]. |
| 2720 | __ Sltiu(dst, lhs, rhs_imm); |
| 2721 | } else { |
| 2722 | if (use_imm) { |
| 2723 | rhs_reg = TMP; |
| 2724 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2725 | } |
| 2726 | __ Sltu(dst, lhs, rhs_reg); |
| 2727 | } |
| 2728 | if (cond == kCondAE) { |
| 2729 | // Simulate lhs >= rhs via !(lhs < rhs) since there's |
| 2730 | // only the sltu instruction but no sgeu. |
| 2731 | __ Xori(dst, dst, 1); |
| 2732 | } |
| 2733 | break; |
| 2734 | |
| 2735 | case kCondBE: |
| 2736 | case kCondA: |
| 2737 | if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) { |
| 2738 | // Simulate lhs <= rhs via lhs < rhs + 1. |
| 2739 | // Note that this only works if rhs + 1 does not overflow |
| 2740 | // to 0, hence the check above. |
| 2741 | // Sltiu sign-extends its 16-bit immediate operand before |
| 2742 | // the comparison and thus lets us compare directly with |
| 2743 | // unsigned values in the ranges [0, 0x7fff] and |
| 2744 | // [0xffff8000, 0xffffffff]. |
| 2745 | __ Sltiu(dst, lhs, rhs_imm + 1); |
| 2746 | if (cond == kCondA) { |
| 2747 | // Simulate lhs > rhs via !(lhs <= rhs) since there's |
| 2748 | // only the sltiu instruction but no sgtiu. |
| 2749 | __ Xori(dst, dst, 1); |
| 2750 | } |
| 2751 | } else { |
| 2752 | if (use_imm) { |
| 2753 | rhs_reg = TMP; |
| 2754 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2755 | } |
| 2756 | __ Sltu(dst, rhs_reg, lhs); |
| 2757 | if (cond == kCondBE) { |
| 2758 | // Simulate lhs <= rhs via !(rhs < lhs) since there's |
| 2759 | // only the sltu instruction but no sleu. |
| 2760 | __ Xori(dst, dst, 1); |
| 2761 | } |
| 2762 | } |
| 2763 | break; |
| 2764 | } |
| 2765 | } |
| 2766 | |
| 2767 | void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond, |
| 2768 | LocationSummary* locations, |
| 2769 | MipsLabel* label) { |
| 2770 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 2771 | Location rhs_location = locations->InAt(1); |
| 2772 | Register rhs_reg = ZERO; |
| 2773 | int32_t rhs_imm = 0; |
| 2774 | bool use_imm = rhs_location.IsConstant(); |
| 2775 | if (use_imm) { |
| 2776 | rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant()); |
| 2777 | } else { |
| 2778 | rhs_reg = rhs_location.AsRegister<Register>(); |
| 2779 | } |
| 2780 | |
| 2781 | if (use_imm && rhs_imm == 0) { |
| 2782 | switch (cond) { |
| 2783 | case kCondEQ: |
| 2784 | case kCondBE: // <= 0 if zero |
| 2785 | __ Beqz(lhs, label); |
| 2786 | break; |
| 2787 | case kCondNE: |
| 2788 | case kCondA: // > 0 if non-zero |
| 2789 | __ Bnez(lhs, label); |
| 2790 | break; |
| 2791 | case kCondLT: |
| 2792 | __ Bltz(lhs, label); |
| 2793 | break; |
| 2794 | case kCondGE: |
| 2795 | __ Bgez(lhs, label); |
| 2796 | break; |
| 2797 | case kCondLE: |
| 2798 | __ Blez(lhs, label); |
| 2799 | break; |
| 2800 | case kCondGT: |
| 2801 | __ Bgtz(lhs, label); |
| 2802 | break; |
| 2803 | case kCondB: // always false |
| 2804 | break; |
| 2805 | case kCondAE: // always true |
| 2806 | __ B(label); |
| 2807 | break; |
| 2808 | } |
| 2809 | } else { |
| 2810 | if (use_imm) { |
| 2811 | // TODO: more efficient comparison with 16-bit constants without loading them into TMP. |
| 2812 | rhs_reg = TMP; |
| 2813 | __ LoadConst32(rhs_reg, rhs_imm); |
| 2814 | } |
| 2815 | switch (cond) { |
| 2816 | case kCondEQ: |
| 2817 | __ Beq(lhs, rhs_reg, label); |
| 2818 | break; |
| 2819 | case kCondNE: |
| 2820 | __ Bne(lhs, rhs_reg, label); |
| 2821 | break; |
| 2822 | case kCondLT: |
| 2823 | __ Blt(lhs, rhs_reg, label); |
| 2824 | break; |
| 2825 | case kCondGE: |
| 2826 | __ Bge(lhs, rhs_reg, label); |
| 2827 | break; |
| 2828 | case kCondLE: |
| 2829 | __ Bge(rhs_reg, lhs, label); |
| 2830 | break; |
| 2831 | case kCondGT: |
| 2832 | __ Blt(rhs_reg, lhs, label); |
| 2833 | break; |
| 2834 | case kCondB: |
| 2835 | __ Bltu(lhs, rhs_reg, label); |
| 2836 | break; |
| 2837 | case kCondAE: |
| 2838 | __ Bgeu(lhs, rhs_reg, label); |
| 2839 | break; |
| 2840 | case kCondBE: |
| 2841 | __ Bgeu(rhs_reg, lhs, label); |
| 2842 | break; |
| 2843 | case kCondA: |
| 2844 | __ Bltu(rhs_reg, lhs, label); |
| 2845 | break; |
| 2846 | } |
| 2847 | } |
| 2848 | } |
| 2849 | |
| 2850 | void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond, |
| 2851 | LocationSummary* locations, |
| 2852 | MipsLabel* label) { |
| 2853 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2854 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 2855 | Location rhs_location = locations->InAt(1); |
| 2856 | Register rhs_high = ZERO; |
| 2857 | Register rhs_low = ZERO; |
| 2858 | int64_t imm = 0; |
| 2859 | uint32_t imm_high = 0; |
| 2860 | uint32_t imm_low = 0; |
| 2861 | bool use_imm = rhs_location.IsConstant(); |
| 2862 | if (use_imm) { |
| 2863 | imm = rhs_location.GetConstant()->AsLongConstant()->GetValue(); |
| 2864 | imm_high = High32Bits(imm); |
| 2865 | imm_low = Low32Bits(imm); |
| 2866 | } else { |
| 2867 | rhs_high = rhs_location.AsRegisterPairHigh<Register>(); |
| 2868 | rhs_low = rhs_location.AsRegisterPairLow<Register>(); |
| 2869 | } |
| 2870 | |
| 2871 | if (use_imm && imm == 0) { |
| 2872 | switch (cond) { |
| 2873 | case kCondEQ: |
| 2874 | case kCondBE: // <= 0 if zero |
| 2875 | __ Or(TMP, lhs_high, lhs_low); |
| 2876 | __ Beqz(TMP, label); |
| 2877 | break; |
| 2878 | case kCondNE: |
| 2879 | case kCondA: // > 0 if non-zero |
| 2880 | __ Or(TMP, lhs_high, lhs_low); |
| 2881 | __ Bnez(TMP, label); |
| 2882 | break; |
| 2883 | case kCondLT: |
| 2884 | __ Bltz(lhs_high, label); |
| 2885 | break; |
| 2886 | case kCondGE: |
| 2887 | __ Bgez(lhs_high, label); |
| 2888 | break; |
| 2889 | case kCondLE: |
| 2890 | __ Or(TMP, lhs_high, lhs_low); |
| 2891 | __ Sra(AT, lhs_high, 31); |
| 2892 | __ Bgeu(AT, TMP, label); |
| 2893 | break; |
| 2894 | case kCondGT: |
| 2895 | __ Or(TMP, lhs_high, lhs_low); |
| 2896 | __ Sra(AT, lhs_high, 31); |
| 2897 | __ Bltu(AT, TMP, label); |
| 2898 | break; |
| 2899 | case kCondB: // always false |
| 2900 | break; |
| 2901 | case kCondAE: // always true |
| 2902 | __ B(label); |
| 2903 | break; |
| 2904 | } |
| 2905 | } else if (use_imm) { |
| 2906 | // TODO: more efficient comparison with constants without loading them into TMP/AT. |
| 2907 | switch (cond) { |
| 2908 | case kCondEQ: |
| 2909 | __ LoadConst32(TMP, imm_high); |
| 2910 | __ Xor(TMP, TMP, lhs_high); |
| 2911 | __ LoadConst32(AT, imm_low); |
| 2912 | __ Xor(AT, AT, lhs_low); |
| 2913 | __ Or(TMP, TMP, AT); |
| 2914 | __ Beqz(TMP, label); |
| 2915 | break; |
| 2916 | case kCondNE: |
| 2917 | __ LoadConst32(TMP, imm_high); |
| 2918 | __ Xor(TMP, TMP, lhs_high); |
| 2919 | __ LoadConst32(AT, imm_low); |
| 2920 | __ Xor(AT, AT, lhs_low); |
| 2921 | __ Or(TMP, TMP, AT); |
| 2922 | __ Bnez(TMP, label); |
| 2923 | break; |
| 2924 | case kCondLT: |
| 2925 | __ LoadConst32(TMP, imm_high); |
| 2926 | __ Blt(lhs_high, TMP, label); |
| 2927 | __ Slt(TMP, TMP, lhs_high); |
| 2928 | __ LoadConst32(AT, imm_low); |
| 2929 | __ Sltu(AT, lhs_low, AT); |
| 2930 | __ Blt(TMP, AT, label); |
| 2931 | break; |
| 2932 | case kCondGE: |
| 2933 | __ LoadConst32(TMP, imm_high); |
| 2934 | __ Blt(TMP, lhs_high, label); |
| 2935 | __ Slt(TMP, lhs_high, TMP); |
| 2936 | __ LoadConst32(AT, imm_low); |
| 2937 | __ Sltu(AT, lhs_low, AT); |
| 2938 | __ Or(TMP, TMP, AT); |
| 2939 | __ Beqz(TMP, label); |
| 2940 | break; |
| 2941 | case kCondLE: |
| 2942 | __ LoadConst32(TMP, imm_high); |
| 2943 | __ Blt(lhs_high, TMP, label); |
| 2944 | __ Slt(TMP, TMP, lhs_high); |
| 2945 | __ LoadConst32(AT, imm_low); |
| 2946 | __ Sltu(AT, AT, lhs_low); |
| 2947 | __ Or(TMP, TMP, AT); |
| 2948 | __ Beqz(TMP, label); |
| 2949 | break; |
| 2950 | case kCondGT: |
| 2951 | __ LoadConst32(TMP, imm_high); |
| 2952 | __ Blt(TMP, lhs_high, label); |
| 2953 | __ Slt(TMP, lhs_high, TMP); |
| 2954 | __ LoadConst32(AT, imm_low); |
| 2955 | __ Sltu(AT, AT, lhs_low); |
| 2956 | __ Blt(TMP, AT, label); |
| 2957 | break; |
| 2958 | case kCondB: |
| 2959 | __ LoadConst32(TMP, imm_high); |
| 2960 | __ Bltu(lhs_high, TMP, label); |
| 2961 | __ Sltu(TMP, TMP, lhs_high); |
| 2962 | __ LoadConst32(AT, imm_low); |
| 2963 | __ Sltu(AT, lhs_low, AT); |
| 2964 | __ Blt(TMP, AT, label); |
| 2965 | break; |
| 2966 | case kCondAE: |
| 2967 | __ LoadConst32(TMP, imm_high); |
| 2968 | __ Bltu(TMP, lhs_high, label); |
| 2969 | __ Sltu(TMP, lhs_high, TMP); |
| 2970 | __ LoadConst32(AT, imm_low); |
| 2971 | __ Sltu(AT, lhs_low, AT); |
| 2972 | __ Or(TMP, TMP, AT); |
| 2973 | __ Beqz(TMP, label); |
| 2974 | break; |
| 2975 | case kCondBE: |
| 2976 | __ LoadConst32(TMP, imm_high); |
| 2977 | __ Bltu(lhs_high, TMP, label); |
| 2978 | __ Sltu(TMP, TMP, lhs_high); |
| 2979 | __ LoadConst32(AT, imm_low); |
| 2980 | __ Sltu(AT, AT, lhs_low); |
| 2981 | __ Or(TMP, TMP, AT); |
| 2982 | __ Beqz(TMP, label); |
| 2983 | break; |
| 2984 | case kCondA: |
| 2985 | __ LoadConst32(TMP, imm_high); |
| 2986 | __ Bltu(TMP, lhs_high, label); |
| 2987 | __ Sltu(TMP, lhs_high, TMP); |
| 2988 | __ LoadConst32(AT, imm_low); |
| 2989 | __ Sltu(AT, AT, lhs_low); |
| 2990 | __ Blt(TMP, AT, label); |
| 2991 | break; |
| 2992 | } |
| 2993 | } else { |
| 2994 | switch (cond) { |
| 2995 | case kCondEQ: |
| 2996 | __ Xor(TMP, lhs_high, rhs_high); |
| 2997 | __ Xor(AT, lhs_low, rhs_low); |
| 2998 | __ Or(TMP, TMP, AT); |
| 2999 | __ Beqz(TMP, label); |
| 3000 | break; |
| 3001 | case kCondNE: |
| 3002 | __ Xor(TMP, lhs_high, rhs_high); |
| 3003 | __ Xor(AT, lhs_low, rhs_low); |
| 3004 | __ Or(TMP, TMP, AT); |
| 3005 | __ Bnez(TMP, label); |
| 3006 | break; |
| 3007 | case kCondLT: |
| 3008 | __ Blt(lhs_high, rhs_high, label); |
| 3009 | __ Slt(TMP, rhs_high, lhs_high); |
| 3010 | __ Sltu(AT, lhs_low, rhs_low); |
| 3011 | __ Blt(TMP, AT, label); |
| 3012 | break; |
| 3013 | case kCondGE: |
| 3014 | __ Blt(rhs_high, lhs_high, label); |
| 3015 | __ Slt(TMP, lhs_high, rhs_high); |
| 3016 | __ Sltu(AT, lhs_low, rhs_low); |
| 3017 | __ Or(TMP, TMP, AT); |
| 3018 | __ Beqz(TMP, label); |
| 3019 | break; |
| 3020 | case kCondLE: |
| 3021 | __ Blt(lhs_high, rhs_high, label); |
| 3022 | __ Slt(TMP, rhs_high, lhs_high); |
| 3023 | __ Sltu(AT, rhs_low, lhs_low); |
| 3024 | __ Or(TMP, TMP, AT); |
| 3025 | __ Beqz(TMP, label); |
| 3026 | break; |
| 3027 | case kCondGT: |
| 3028 | __ Blt(rhs_high, lhs_high, label); |
| 3029 | __ Slt(TMP, lhs_high, rhs_high); |
| 3030 | __ Sltu(AT, rhs_low, lhs_low); |
| 3031 | __ Blt(TMP, AT, label); |
| 3032 | break; |
| 3033 | case kCondB: |
| 3034 | __ Bltu(lhs_high, rhs_high, label); |
| 3035 | __ Sltu(TMP, rhs_high, lhs_high); |
| 3036 | __ Sltu(AT, lhs_low, rhs_low); |
| 3037 | __ Blt(TMP, AT, label); |
| 3038 | break; |
| 3039 | case kCondAE: |
| 3040 | __ Bltu(rhs_high, lhs_high, label); |
| 3041 | __ Sltu(TMP, lhs_high, rhs_high); |
| 3042 | __ Sltu(AT, lhs_low, rhs_low); |
| 3043 | __ Or(TMP, TMP, AT); |
| 3044 | __ Beqz(TMP, label); |
| 3045 | break; |
| 3046 | case kCondBE: |
| 3047 | __ Bltu(lhs_high, rhs_high, label); |
| 3048 | __ Sltu(TMP, rhs_high, lhs_high); |
| 3049 | __ Sltu(AT, rhs_low, lhs_low); |
| 3050 | __ Or(TMP, TMP, AT); |
| 3051 | __ Beqz(TMP, label); |
| 3052 | break; |
| 3053 | case kCondA: |
| 3054 | __ Bltu(rhs_high, lhs_high, label); |
| 3055 | __ Sltu(TMP, lhs_high, rhs_high); |
| 3056 | __ Sltu(AT, rhs_low, lhs_low); |
| 3057 | __ Blt(TMP, AT, label); |
| 3058 | break; |
| 3059 | } |
| 3060 | } |
| 3061 | } |
| 3062 | |
| 3063 | void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond, |
| 3064 | bool gt_bias, |
| 3065 | Primitive::Type type, |
| 3066 | LocationSummary* locations, |
| 3067 | MipsLabel* label) { |
| 3068 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 3069 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3070 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 3071 | if (type == Primitive::kPrimFloat) { |
| 3072 | if (isR6) { |
| 3073 | switch (cond) { |
| 3074 | case kCondEQ: |
| 3075 | __ CmpEqS(FTMP, lhs, rhs); |
| 3076 | __ Bc1nez(FTMP, label); |
| 3077 | break; |
| 3078 | case kCondNE: |
| 3079 | __ CmpEqS(FTMP, lhs, rhs); |
| 3080 | __ Bc1eqz(FTMP, label); |
| 3081 | break; |
| 3082 | case kCondLT: |
| 3083 | if (gt_bias) { |
| 3084 | __ CmpLtS(FTMP, lhs, rhs); |
| 3085 | } else { |
| 3086 | __ CmpUltS(FTMP, lhs, rhs); |
| 3087 | } |
| 3088 | __ Bc1nez(FTMP, label); |
| 3089 | break; |
| 3090 | case kCondLE: |
| 3091 | if (gt_bias) { |
| 3092 | __ CmpLeS(FTMP, lhs, rhs); |
| 3093 | } else { |
| 3094 | __ CmpUleS(FTMP, lhs, rhs); |
| 3095 | } |
| 3096 | __ Bc1nez(FTMP, label); |
| 3097 | break; |
| 3098 | case kCondGT: |
| 3099 | if (gt_bias) { |
| 3100 | __ CmpUltS(FTMP, rhs, lhs); |
| 3101 | } else { |
| 3102 | __ CmpLtS(FTMP, rhs, lhs); |
| 3103 | } |
| 3104 | __ Bc1nez(FTMP, label); |
| 3105 | break; |
| 3106 | case kCondGE: |
| 3107 | if (gt_bias) { |
| 3108 | __ CmpUleS(FTMP, rhs, lhs); |
| 3109 | } else { |
| 3110 | __ CmpLeS(FTMP, rhs, lhs); |
| 3111 | } |
| 3112 | __ Bc1nez(FTMP, label); |
| 3113 | break; |
| 3114 | default: |
| 3115 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3116 | } |
| 3117 | } else { |
| 3118 | switch (cond) { |
| 3119 | case kCondEQ: |
| 3120 | __ CeqS(0, lhs, rhs); |
| 3121 | __ Bc1t(0, label); |
| 3122 | break; |
| 3123 | case kCondNE: |
| 3124 | __ CeqS(0, lhs, rhs); |
| 3125 | __ Bc1f(0, label); |
| 3126 | break; |
| 3127 | case kCondLT: |
| 3128 | if (gt_bias) { |
| 3129 | __ ColtS(0, lhs, rhs); |
| 3130 | } else { |
| 3131 | __ CultS(0, lhs, rhs); |
| 3132 | } |
| 3133 | __ Bc1t(0, label); |
| 3134 | break; |
| 3135 | case kCondLE: |
| 3136 | if (gt_bias) { |
| 3137 | __ ColeS(0, lhs, rhs); |
| 3138 | } else { |
| 3139 | __ CuleS(0, lhs, rhs); |
| 3140 | } |
| 3141 | __ Bc1t(0, label); |
| 3142 | break; |
| 3143 | case kCondGT: |
| 3144 | if (gt_bias) { |
| 3145 | __ CultS(0, rhs, lhs); |
| 3146 | } else { |
| 3147 | __ ColtS(0, rhs, lhs); |
| 3148 | } |
| 3149 | __ Bc1t(0, label); |
| 3150 | break; |
| 3151 | case kCondGE: |
| 3152 | if (gt_bias) { |
| 3153 | __ CuleS(0, rhs, lhs); |
| 3154 | } else { |
| 3155 | __ ColeS(0, rhs, lhs); |
| 3156 | } |
| 3157 | __ Bc1t(0, label); |
| 3158 | break; |
| 3159 | default: |
| 3160 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3161 | } |
| 3162 | } |
| 3163 | } else { |
| 3164 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 3165 | if (isR6) { |
| 3166 | switch (cond) { |
| 3167 | case kCondEQ: |
| 3168 | __ CmpEqD(FTMP, lhs, rhs); |
| 3169 | __ Bc1nez(FTMP, label); |
| 3170 | break; |
| 3171 | case kCondNE: |
| 3172 | __ CmpEqD(FTMP, lhs, rhs); |
| 3173 | __ Bc1eqz(FTMP, label); |
| 3174 | break; |
| 3175 | case kCondLT: |
| 3176 | if (gt_bias) { |
| 3177 | __ CmpLtD(FTMP, lhs, rhs); |
| 3178 | } else { |
| 3179 | __ CmpUltD(FTMP, lhs, rhs); |
| 3180 | } |
| 3181 | __ Bc1nez(FTMP, label); |
| 3182 | break; |
| 3183 | case kCondLE: |
| 3184 | if (gt_bias) { |
| 3185 | __ CmpLeD(FTMP, lhs, rhs); |
| 3186 | } else { |
| 3187 | __ CmpUleD(FTMP, lhs, rhs); |
| 3188 | } |
| 3189 | __ Bc1nez(FTMP, label); |
| 3190 | break; |
| 3191 | case kCondGT: |
| 3192 | if (gt_bias) { |
| 3193 | __ CmpUltD(FTMP, rhs, lhs); |
| 3194 | } else { |
| 3195 | __ CmpLtD(FTMP, rhs, lhs); |
| 3196 | } |
| 3197 | __ Bc1nez(FTMP, label); |
| 3198 | break; |
| 3199 | case kCondGE: |
| 3200 | if (gt_bias) { |
| 3201 | __ CmpUleD(FTMP, rhs, lhs); |
| 3202 | } else { |
| 3203 | __ CmpLeD(FTMP, rhs, lhs); |
| 3204 | } |
| 3205 | __ Bc1nez(FTMP, label); |
| 3206 | break; |
| 3207 | default: |
| 3208 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3209 | } |
| 3210 | } else { |
| 3211 | switch (cond) { |
| 3212 | case kCondEQ: |
| 3213 | __ CeqD(0, lhs, rhs); |
| 3214 | __ Bc1t(0, label); |
| 3215 | break; |
| 3216 | case kCondNE: |
| 3217 | __ CeqD(0, lhs, rhs); |
| 3218 | __ Bc1f(0, label); |
| 3219 | break; |
| 3220 | case kCondLT: |
| 3221 | if (gt_bias) { |
| 3222 | __ ColtD(0, lhs, rhs); |
| 3223 | } else { |
| 3224 | __ CultD(0, lhs, rhs); |
| 3225 | } |
| 3226 | __ Bc1t(0, label); |
| 3227 | break; |
| 3228 | case kCondLE: |
| 3229 | if (gt_bias) { |
| 3230 | __ ColeD(0, lhs, rhs); |
| 3231 | } else { |
| 3232 | __ CuleD(0, lhs, rhs); |
| 3233 | } |
| 3234 | __ Bc1t(0, label); |
| 3235 | break; |
| 3236 | case kCondGT: |
| 3237 | if (gt_bias) { |
| 3238 | __ CultD(0, rhs, lhs); |
| 3239 | } else { |
| 3240 | __ ColtD(0, rhs, lhs); |
| 3241 | } |
| 3242 | __ Bc1t(0, label); |
| 3243 | break; |
| 3244 | case kCondGE: |
| 3245 | if (gt_bias) { |
| 3246 | __ CuleD(0, rhs, lhs); |
| 3247 | } else { |
| 3248 | __ ColeD(0, rhs, lhs); |
| 3249 | } |
| 3250 | __ Bc1t(0, label); |
| 3251 | break; |
| 3252 | default: |
| 3253 | LOG(FATAL) << "Unexpected non-floating-point condition"; |
| 3254 | } |
| 3255 | } |
| 3256 | } |
| 3257 | } |
| 3258 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3259 | void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3260 | size_t condition_input_index, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3261 | MipsLabel* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3262 | MipsLabel* false_target) { |
| 3263 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3264 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3265 | if (true_target == nullptr && false_target == nullptr) { |
| 3266 | // Nothing to do. The code always falls through. |
| 3267 | return; |
| 3268 | } else if (cond->IsIntConstant()) { |
| 3269 | // Constant condition, statically compared against 1. |
| 3270 | if (cond->AsIntConstant()->IsOne()) { |
| 3271 | if (true_target != nullptr) { |
| 3272 | __ B(true_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3273 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3274 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3275 | DCHECK(cond->AsIntConstant()->IsZero()); |
| 3276 | if (false_target != nullptr) { |
| 3277 | __ B(false_target); |
| 3278 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3279 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3280 | return; |
| 3281 | } |
| 3282 | |
| 3283 | // The following code generates these patterns: |
| 3284 | // (1) true_target == nullptr && false_target != nullptr |
| 3285 | // - opposite condition true => branch to false_target |
| 3286 | // (2) true_target != nullptr && false_target == nullptr |
| 3287 | // - condition true => branch to true_target |
| 3288 | // (3) true_target != nullptr && false_target != nullptr |
| 3289 | // - condition true => branch to true_target |
| 3290 | // - branch to false_target |
| 3291 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3292 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3293 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3294 | DCHECK(cond_val.IsRegister()); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3295 | if (true_target == nullptr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3296 | __ Beqz(cond_val.AsRegister<Register>(), false_target); |
| 3297 | } else { |
| 3298 | __ Bnez(cond_val.AsRegister<Register>(), true_target); |
| 3299 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3300 | } else { |
| 3301 | // The condition instruction has not been materialized, use its inputs as |
| 3302 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3303 | HCondition* condition = cond->AsCondition(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3304 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 3305 | LocationSummary* locations = cond->GetLocations(); |
| 3306 | IfCondition if_cond = condition->GetCondition(); |
| 3307 | MipsLabel* branch_target = true_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3308 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3309 | if (true_target == nullptr) { |
| 3310 | if_cond = condition->GetOppositeCondition(); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3311 | branch_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3312 | } |
| 3313 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 3314 | switch (type) { |
| 3315 | default: |
| 3316 | GenerateIntCompareAndBranch(if_cond, locations, branch_target); |
| 3317 | break; |
| 3318 | case Primitive::kPrimLong: |
| 3319 | GenerateLongCompareAndBranch(if_cond, locations, branch_target); |
| 3320 | break; |
| 3321 | case Primitive::kPrimFloat: |
| 3322 | case Primitive::kPrimDouble: |
| 3323 | GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target); |
| 3324 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3325 | } |
| 3326 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3327 | |
| 3328 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3329 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3330 | if (true_target != nullptr && false_target != nullptr) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3331 | __ B(false_target); |
| 3332 | } |
| 3333 | } |
| 3334 | |
| 3335 | void LocationsBuilderMIPS::VisitIf(HIf* if_instr) { |
| 3336 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3337 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3338 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3339 | } |
| 3340 | } |
| 3341 | |
| 3342 | void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3343 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3344 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 3345 | MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 3346 | nullptr : codegen_->GetLabelOf(true_successor); |
| 3347 | MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 3348 | nullptr : codegen_->GetLabelOf(false_successor); |
| 3349 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3350 | } |
| 3351 | |
| 3352 | void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3353 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3354 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3355 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3356 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3357 | } |
| 3358 | } |
| 3359 | |
| 3360 | void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3361 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) DeoptimizationSlowPathMIPS(deoptimize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3362 | codegen_->AddSlowPath(slow_path); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3363 | GenerateTestAndBranch(deoptimize, |
| 3364 | /* condition_input_index */ 0, |
| 3365 | slow_path->GetEntryLabel(), |
| 3366 | /* false_target */ nullptr); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3367 | } |
| 3368 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3369 | void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3370 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3371 | } |
| 3372 | |
| 3373 | void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3374 | codegen_->RecordPcInfo(info, info->GetDexPc()); |
| 3375 | } |
| 3376 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3377 | void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3378 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3379 | bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble); |
| 3380 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
| 3381 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 3382 | instruction, generate_volatile ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 3383 | |
| 3384 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3385 | if (generate_volatile) { |
| 3386 | InvokeRuntimeCallingConvention calling_convention; |
| 3387 | // need A0 to hold base + offset |
| 3388 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3389 | if (field_type == Primitive::kPrimLong) { |
| 3390 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimLong)); |
| 3391 | } else { |
| 3392 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3393 | // Need some temp core regs since FP results are returned in core registers |
| 3394 | Location reg = calling_convention.GetReturnLocation(Primitive::kPrimLong); |
| 3395 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>())); |
| 3396 | locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>())); |
| 3397 | } |
| 3398 | } else { |
| 3399 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3400 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3401 | } else { |
| 3402 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3403 | } |
| 3404 | } |
| 3405 | } |
| 3406 | |
| 3407 | void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction, |
| 3408 | const FieldInfo& field_info, |
| 3409 | uint32_t dex_pc) { |
| 3410 | Primitive::Type type = field_info.GetFieldType(); |
| 3411 | LocationSummary* locations = instruction->GetLocations(); |
| 3412 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 3413 | LoadOperandType load_type = kLoadUnsignedByte; |
| 3414 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3415 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3416 | |
| 3417 | switch (type) { |
| 3418 | case Primitive::kPrimBoolean: |
| 3419 | load_type = kLoadUnsignedByte; |
| 3420 | break; |
| 3421 | case Primitive::kPrimByte: |
| 3422 | load_type = kLoadSignedByte; |
| 3423 | break; |
| 3424 | case Primitive::kPrimShort: |
| 3425 | load_type = kLoadSignedHalfword; |
| 3426 | break; |
| 3427 | case Primitive::kPrimChar: |
| 3428 | load_type = kLoadUnsignedHalfword; |
| 3429 | break; |
| 3430 | case Primitive::kPrimInt: |
| 3431 | case Primitive::kPrimFloat: |
| 3432 | case Primitive::kPrimNot: |
| 3433 | load_type = kLoadWord; |
| 3434 | break; |
| 3435 | case Primitive::kPrimLong: |
| 3436 | case Primitive::kPrimDouble: |
| 3437 | load_type = kLoadDoubleword; |
| 3438 | break; |
| 3439 | case Primitive::kPrimVoid: |
| 3440 | LOG(FATAL) << "Unreachable type " << type; |
| 3441 | UNREACHABLE(); |
| 3442 | } |
| 3443 | |
| 3444 | if (is_volatile && load_type == kLoadDoubleword) { |
| 3445 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3446 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3447 | // Do implicit Null check |
| 3448 | __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0); |
| 3449 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3450 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pA64Load), |
| 3451 | instruction, |
| 3452 | dex_pc, |
| 3453 | nullptr, |
| 3454 | IsDirectEntrypoint(kQuickA64Load)); |
| 3455 | CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>(); |
| 3456 | if (type == Primitive::kPrimDouble) { |
| 3457 | // Need to move to FP regs since FP results are returned in core registers. |
| 3458 | __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), |
| 3459 | locations->Out().AsFpuRegister<FRegister>()); |
| 3460 | __ Mthc1(locations->GetTemp(2).AsRegister<Register>(), |
| 3461 | locations->Out().AsFpuRegister<FRegister>()); |
| 3462 | } |
| 3463 | } else { |
| 3464 | if (!Primitive::IsFloatingPointType(type)) { |
| 3465 | Register dst; |
| 3466 | if (type == Primitive::kPrimLong) { |
| 3467 | DCHECK(locations->Out().IsRegisterPair()); |
| 3468 | dst = locations->Out().AsRegisterPairLow<Register>(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3469 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 3470 | if (obj == dst) { |
| 3471 | __ LoadFromOffset(kLoadWord, dst_high, obj, offset + kMipsWordSize); |
| 3472 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3473 | __ LoadFromOffset(kLoadWord, dst, obj, offset); |
| 3474 | } else { |
| 3475 | __ LoadFromOffset(kLoadWord, dst, obj, offset); |
| 3476 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3477 | __ LoadFromOffset(kLoadWord, dst_high, obj, offset + kMipsWordSize); |
| 3478 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3479 | } else { |
| 3480 | DCHECK(locations->Out().IsRegister()); |
| 3481 | dst = locations->Out().AsRegister<Register>(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3482 | __ LoadFromOffset(load_type, dst, obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3483 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3484 | } else { |
| 3485 | DCHECK(locations->Out().IsFpuRegister()); |
| 3486 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 3487 | if (type == Primitive::kPrimFloat) { |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3488 | __ LoadSFromOffset(dst, obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3489 | } else { |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3490 | __ LoadDFromOffset(dst, obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3491 | } |
| 3492 | } |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3493 | // Longs are handled earlier. |
| 3494 | if (type != Primitive::kPrimLong) { |
| 3495 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3496 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3497 | } |
| 3498 | |
| 3499 | if (is_volatile) { |
| 3500 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3501 | } |
| 3502 | } |
| 3503 | |
| 3504 | void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3505 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3506 | bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble); |
| 3507 | bool generate_volatile = field_info.IsVolatile() && is_wide; |
| 3508 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 3509 | instruction, generate_volatile ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 3510 | |
| 3511 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3512 | if (generate_volatile) { |
| 3513 | InvokeRuntimeCallingConvention calling_convention; |
| 3514 | // need A0 to hold base + offset |
| 3515 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3516 | if (field_type == Primitive::kPrimLong) { |
| 3517 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3518 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3519 | } else { |
| 3520 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3521 | // Pass FP parameters in core registers. |
| 3522 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 3523 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3))); |
| 3524 | } |
| 3525 | } else { |
| 3526 | if (Primitive::IsFloatingPointType(field_type)) { |
| 3527 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3528 | } else { |
| 3529 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3530 | } |
| 3531 | } |
| 3532 | } |
| 3533 | |
| 3534 | void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction, |
| 3535 | const FieldInfo& field_info, |
| 3536 | uint32_t dex_pc) { |
| 3537 | Primitive::Type type = field_info.GetFieldType(); |
| 3538 | LocationSummary* locations = instruction->GetLocations(); |
| 3539 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 3540 | StoreOperandType store_type = kStoreByte; |
| 3541 | bool is_volatile = field_info.IsVolatile(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3542 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3543 | |
| 3544 | switch (type) { |
| 3545 | case Primitive::kPrimBoolean: |
| 3546 | case Primitive::kPrimByte: |
| 3547 | store_type = kStoreByte; |
| 3548 | break; |
| 3549 | case Primitive::kPrimShort: |
| 3550 | case Primitive::kPrimChar: |
| 3551 | store_type = kStoreHalfword; |
| 3552 | break; |
| 3553 | case Primitive::kPrimInt: |
| 3554 | case Primitive::kPrimFloat: |
| 3555 | case Primitive::kPrimNot: |
| 3556 | store_type = kStoreWord; |
| 3557 | break; |
| 3558 | case Primitive::kPrimLong: |
| 3559 | case Primitive::kPrimDouble: |
| 3560 | store_type = kStoreDoubleword; |
| 3561 | break; |
| 3562 | case Primitive::kPrimVoid: |
| 3563 | LOG(FATAL) << "Unreachable type " << type; |
| 3564 | UNREACHABLE(); |
| 3565 | } |
| 3566 | |
| 3567 | if (is_volatile) { |
| 3568 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3569 | } |
| 3570 | |
| 3571 | if (is_volatile && store_type == kStoreDoubleword) { |
| 3572 | InvokeRuntimeCallingConvention calling_convention; |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3573 | __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3574 | // Do implicit Null check. |
| 3575 | __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0); |
| 3576 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3577 | if (type == Primitive::kPrimDouble) { |
| 3578 | // Pass FP parameters in core registers. |
| 3579 | __ Mfc1(locations->GetTemp(1).AsRegister<Register>(), |
| 3580 | locations->InAt(1).AsFpuRegister<FRegister>()); |
| 3581 | __ Mfhc1(locations->GetTemp(2).AsRegister<Register>(), |
| 3582 | locations->InAt(1).AsFpuRegister<FRegister>()); |
| 3583 | } |
| 3584 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pA64Store), |
| 3585 | instruction, |
| 3586 | dex_pc, |
| 3587 | nullptr, |
| 3588 | IsDirectEntrypoint(kQuickA64Store)); |
| 3589 | CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>(); |
| 3590 | } else { |
| 3591 | if (!Primitive::IsFloatingPointType(type)) { |
| 3592 | Register src; |
| 3593 | if (type == Primitive::kPrimLong) { |
| 3594 | DCHECK(locations->InAt(1).IsRegisterPair()); |
| 3595 | src = locations->InAt(1).AsRegisterPairLow<Register>(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3596 | Register src_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 3597 | __ StoreToOffset(kStoreWord, src, obj, offset); |
| 3598 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3599 | __ StoreToOffset(kStoreWord, src_high, obj, offset + kMipsWordSize); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3600 | } else { |
| 3601 | DCHECK(locations->InAt(1).IsRegister()); |
| 3602 | src = locations->InAt(1).AsRegister<Register>(); |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3603 | __ StoreToOffset(store_type, src, obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3604 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3605 | } else { |
| 3606 | DCHECK(locations->InAt(1).IsFpuRegister()); |
| 3607 | FRegister src = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 3608 | if (type == Primitive::kPrimFloat) { |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3609 | __ StoreSToOffset(src, obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3610 | } else { |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3611 | __ StoreDToOffset(src, obj, offset); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3612 | } |
| 3613 | } |
Goran Jakovljevic | 73a4265 | 2015-11-20 17:22:57 +0100 | [diff] [blame] | 3614 | // Longs are handled earlier. |
| 3615 | if (type != Primitive::kPrimLong) { |
| 3616 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3617 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3618 | } |
| 3619 | |
| 3620 | // TODO: memory barriers? |
| 3621 | if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) { |
| 3622 | DCHECK(locations->InAt(1).IsRegister()); |
| 3623 | Register src = locations->InAt(1).AsRegister<Register>(); |
| 3624 | codegen_->MarkGCCard(obj, src); |
| 3625 | } |
| 3626 | |
| 3627 | if (is_volatile) { |
| 3628 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 3629 | } |
| 3630 | } |
| 3631 | |
| 3632 | void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 3633 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3634 | } |
| 3635 | |
| 3636 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 3637 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 3638 | } |
| 3639 | |
| 3640 | void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 3641 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3642 | } |
| 3643 | |
| 3644 | void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 3645 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 3646 | } |
| 3647 | |
| 3648 | void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
| 3649 | LocationSummary::CallKind call_kind = |
| 3650 | instruction->IsExactCheck() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath; |
| 3651 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 3652 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3653 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3654 | // The output does overlap inputs. |
| 3655 | // Note that TypeCheckSlowPathMIPS uses this register too. |
| 3656 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3657 | } |
| 3658 | |
| 3659 | void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { |
| 3660 | LocationSummary* locations = instruction->GetLocations(); |
| 3661 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 3662 | Register cls = locations->InAt(1).AsRegister<Register>(); |
| 3663 | Register out = locations->Out().AsRegister<Register>(); |
| 3664 | |
| 3665 | MipsLabel done; |
| 3666 | |
| 3667 | // Return 0 if `obj` is null. |
| 3668 | // TODO: Avoid this check if we know `obj` is not null. |
| 3669 | __ Move(out, ZERO); |
| 3670 | __ Beqz(obj, &done); |
| 3671 | |
| 3672 | // Compare the class of `obj` with `cls`. |
| 3673 | __ LoadFromOffset(kLoadWord, out, obj, mirror::Object::ClassOffset().Int32Value()); |
| 3674 | if (instruction->IsExactCheck()) { |
| 3675 | // Classes must be equal for the instanceof to succeed. |
| 3676 | __ Xor(out, out, cls); |
| 3677 | __ Sltiu(out, out, 1); |
| 3678 | } else { |
| 3679 | // If the classes are not equal, we go into a slow path. |
| 3680 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 3681 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction); |
| 3682 | codegen_->AddSlowPath(slow_path); |
| 3683 | __ Bne(out, cls, slow_path->GetEntryLabel()); |
| 3684 | __ LoadConst32(out, 1); |
| 3685 | __ Bind(slow_path->GetExitLabel()); |
| 3686 | } |
| 3687 | |
| 3688 | __ Bind(&done); |
| 3689 | } |
| 3690 | |
| 3691 | void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) { |
| 3692 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3693 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3694 | } |
| 3695 | |
| 3696 | void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 3697 | // Will be generated at use site. |
| 3698 | } |
| 3699 | |
| 3700 | void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) { |
| 3701 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3702 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3703 | } |
| 3704 | |
| 3705 | void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 3706 | // Will be generated at use site. |
| 3707 | } |
| 3708 | |
| 3709 | void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) { |
| 3710 | InvokeDexCallingConventionVisitorMIPS calling_convention_visitor; |
| 3711 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 3712 | } |
| 3713 | |
| 3714 | void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3715 | HandleInvoke(invoke); |
| 3716 | // The register T0 is required to be used for the hidden argument in |
| 3717 | // art_quick_imt_conflict_trampoline, so add the hidden argument. |
| 3718 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0)); |
| 3719 | } |
| 3720 | |
| 3721 | void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3722 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 3723 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
| 3724 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 3725 | invoke->GetImtIndex() % mirror::Class::kImtSize, kMipsPointerSize).Uint32Value(); |
| 3726 | Location receiver = invoke->GetLocations()->InAt(0); |
| 3727 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3728 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsWordSize); |
| 3729 | |
| 3730 | // Set the hidden argument. |
| 3731 | __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(), |
| 3732 | invoke->GetDexMethodIndex()); |
| 3733 | |
| 3734 | // temp = object->GetClass(); |
| 3735 | if (receiver.IsStackSlot()) { |
| 3736 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 3737 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 3738 | } else { |
| 3739 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
| 3740 | } |
| 3741 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 3742 | // temp = temp->GetImtEntryAt(method_offset); |
| 3743 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 3744 | // T9 = temp->GetEntryPoint(); |
| 3745 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 3746 | // T9(); |
| 3747 | __ Jalr(T9); |
| 3748 | __ Nop(); |
| 3749 | DCHECK(!codegen_->IsLeafMethod()); |
| 3750 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3751 | } |
| 3752 | |
| 3753 | void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 3754 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 3755 | if (intrinsic.TryDispatch(invoke)) { |
| 3756 | return; |
| 3757 | } |
| 3758 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3759 | HandleInvoke(invoke); |
| 3760 | } |
| 3761 | |
| 3762 | void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3763 | // When we do not run baseline, explicit clinit checks triggered by static |
| 3764 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 3765 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
| 3766 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 3767 | IntrinsicLocationsBuilderMIPS intrinsic(codegen_); |
| 3768 | if (intrinsic.TryDispatch(invoke)) { |
| 3769 | return; |
| 3770 | } |
| 3771 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3772 | HandleInvoke(invoke); |
| 3773 | } |
| 3774 | |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 3775 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3776 | if (invoke->GetLocations()->Intrinsified()) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 3777 | IntrinsicCodeGeneratorMIPS intrinsic(codegen); |
| 3778 | intrinsic.Dispatch(invoke); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3779 | return true; |
| 3780 | } |
| 3781 | return false; |
| 3782 | } |
| 3783 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3784 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch( |
| 3785 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 3786 | MethodReference target_method ATTRIBUTE_UNUSED) { |
| 3787 | switch (desired_dispatch_info.method_load_kind) { |
| 3788 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 3789 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
| 3790 | // TODO: Implement these types. For the moment, we fall back to kDexCacheViaMethod. |
| 3791 | return HInvokeStaticOrDirect::DispatchInfo { |
| 3792 | HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod, |
| 3793 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 3794 | 0u, |
| 3795 | 0u |
| 3796 | }; |
| 3797 | default: |
| 3798 | break; |
| 3799 | } |
| 3800 | switch (desired_dispatch_info.code_ptr_location) { |
| 3801 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3802 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
| 3803 | // TODO: Implement these types. For the moment, we fall back to kCallArtMethod. |
| 3804 | return HInvokeStaticOrDirect::DispatchInfo { |
| 3805 | desired_dispatch_info.method_load_kind, |
| 3806 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 3807 | desired_dispatch_info.method_load_data, |
| 3808 | 0u |
| 3809 | }; |
| 3810 | default: |
| 3811 | return desired_dispatch_info; |
| 3812 | } |
| 3813 | } |
| 3814 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3815 | void CodeGeneratorMIPS::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 3816 | // All registers are assumed to be correctly set up per the calling convention. |
| 3817 | |
| 3818 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 3819 | switch (invoke->GetMethodLoadKind()) { |
| 3820 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 3821 | // temp = thread->string_init_entrypoint |
| 3822 | __ LoadFromOffset(kLoadWord, |
| 3823 | temp.AsRegister<Register>(), |
| 3824 | TR, |
| 3825 | invoke->GetStringInitOffset()); |
| 3826 | break; |
| 3827 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3828 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3829 | break; |
| 3830 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 3831 | __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 3832 | break; |
| 3833 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3834 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3835 | // TODO: Implement these types. |
| 3836 | // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 3837 | LOG(FATAL) << "Unsupported"; |
| 3838 | UNREACHABLE(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3839 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3840 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3841 | Register reg = temp.AsRegister<Register>(); |
| 3842 | Register method_reg; |
| 3843 | if (current_method.IsRegister()) { |
| 3844 | method_reg = current_method.AsRegister<Register>(); |
| 3845 | } else { |
| 3846 | // TODO: use the appropriate DCHECK() here if possible. |
| 3847 | // DCHECK(invoke->GetLocations()->Intrinsified()); |
| 3848 | DCHECK(!current_method.IsValid()); |
| 3849 | method_reg = reg; |
| 3850 | __ Lw(reg, SP, kCurrentMethodStackOffset); |
| 3851 | } |
| 3852 | |
| 3853 | // temp = temp->dex_cache_resolved_methods_; |
| 3854 | __ LoadFromOffset(kLoadWord, |
| 3855 | reg, |
| 3856 | method_reg, |
| 3857 | ArtMethod::DexCacheResolvedMethodsOffset(kMipsPointerSize).Int32Value()); |
| 3858 | // temp = temp[index_in_cache] |
| 3859 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 3860 | __ LoadFromOffset(kLoadWord, |
| 3861 | reg, |
| 3862 | reg, |
| 3863 | CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 3864 | break; |
| 3865 | } |
| 3866 | } |
| 3867 | |
| 3868 | switch (invoke->GetCodePtrLocation()) { |
| 3869 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 3870 | __ Jalr(&frame_entry_label_, T9); |
| 3871 | break; |
| 3872 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3873 | // LR = invoke->GetDirectCodePtr(); |
| 3874 | __ LoadConst32(T9, invoke->GetDirectCodePtr()); |
| 3875 | // LR() |
| 3876 | __ Jalr(T9); |
| 3877 | __ Nop(); |
| 3878 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3879 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3880 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
| 3881 | // TODO: Implement these types. |
| 3882 | // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 3883 | LOG(FATAL) << "Unsupported"; |
| 3884 | UNREACHABLE(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3885 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 3886 | // T9 = callee_method->entry_point_from_quick_compiled_code_; |
Goran Jakovljevic | 1a87837 | 2015-10-26 14:28:52 +0100 | [diff] [blame] | 3887 | __ LoadFromOffset(kLoadWord, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3888 | T9, |
| 3889 | callee_method.AsRegister<Register>(), |
| 3890 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 3891 | kMipsWordSize).Int32Value()); |
| 3892 | // T9() |
| 3893 | __ Jalr(T9); |
| 3894 | __ Nop(); |
| 3895 | break; |
| 3896 | } |
| 3897 | DCHECK(!IsLeafMethod()); |
| 3898 | } |
| 3899 | |
| 3900 | void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3901 | // When we do not run baseline, explicit clinit checks triggered by static |
| 3902 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 3903 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
| 3904 | |
| 3905 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3906 | return; |
| 3907 | } |
| 3908 | |
| 3909 | LocationSummary* locations = invoke->GetLocations(); |
| 3910 | codegen_->GenerateStaticOrDirectCall(invoke, |
| 3911 | locations->HasTemps() |
| 3912 | ? locations->GetTemp(0) |
| 3913 | : Location::NoLocation()); |
| 3914 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3915 | } |
| 3916 | |
| 3917 | void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Chris Larsen | 701566a | 2015-10-27 15:29:13 -0700 | [diff] [blame] | 3918 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3919 | return; |
| 3920 | } |
| 3921 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3922 | LocationSummary* locations = invoke->GetLocations(); |
| 3923 | Location receiver = locations->InAt(0); |
| 3924 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
| 3925 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 3926 | invoke->GetVTableIndex(), kMipsPointerSize).SizeValue(); |
| 3927 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3928 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsWordSize); |
| 3929 | |
| 3930 | // temp = object->GetClass(); |
| 3931 | if (receiver.IsStackSlot()) { |
| 3932 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 3933 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 3934 | } else { |
| 3935 | DCHECK(receiver.IsRegister()); |
| 3936 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
| 3937 | } |
| 3938 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 3939 | // temp = temp->GetMethodAt(method_offset); |
| 3940 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 3941 | // T9 = temp->GetEntryPoint(); |
| 3942 | __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value()); |
| 3943 | // T9(); |
| 3944 | __ Jalr(T9); |
| 3945 | __ Nop(); |
| 3946 | DCHECK(!codegen_->IsLeafMethod()); |
| 3947 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3948 | } |
| 3949 | |
| 3950 | void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) { |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 3951 | InvokeRuntimeCallingConvention calling_convention; |
| 3952 | CodeGenerator::CreateLoadClassLocationSummary( |
| 3953 | cls, |
| 3954 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 3955 | Location::RegisterLocation(V0)); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3956 | } |
| 3957 | |
| 3958 | void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) { |
| 3959 | LocationSummary* locations = cls->GetLocations(); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 3960 | if (cls->NeedsAccessCheck()) { |
| 3961 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 3962 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 3963 | cls, |
| 3964 | cls->GetDexPc(), |
| 3965 | nullptr, |
| 3966 | IsDirectEntrypoint(kQuickInitializeTypeAndVerifyAccess)); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3967 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Pavle Batuta | e87a718 | 2015-10-28 13:10:42 +0100 | [diff] [blame] | 3968 | return; |
| 3969 | } |
| 3970 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3971 | Register out = locations->Out().AsRegister<Register>(); |
| 3972 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 3973 | if (cls->IsReferrersClass()) { |
| 3974 | DCHECK(!cls->CanCallRuntime()); |
| 3975 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 3976 | __ LoadFromOffset(kLoadWord, out, current_method, |
| 3977 | ArtMethod::DeclaringClassOffset().Int32Value()); |
| 3978 | } else { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3979 | __ LoadFromOffset(kLoadWord, out, current_method, |
| 3980 | ArtMethod::DexCacheResolvedTypesOffset(kMipsPointerSize).Int32Value()); |
| 3981 | __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 3982 | |
| 3983 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 3984 | DCHECK(cls->CanCallRuntime()); |
| 3985 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS( |
| 3986 | cls, |
| 3987 | cls, |
| 3988 | cls->GetDexPc(), |
| 3989 | cls->MustGenerateClinitCheck()); |
| 3990 | codegen_->AddSlowPath(slow_path); |
| 3991 | if (!cls->IsInDexCache()) { |
| 3992 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 3993 | } |
| 3994 | if (cls->MustGenerateClinitCheck()) { |
| 3995 | GenerateClassInitializationCheck(slow_path, out); |
| 3996 | } else { |
| 3997 | __ Bind(slow_path->GetExitLabel()); |
| 3998 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 3999 | } |
| 4000 | } |
| 4001 | } |
| 4002 | |
| 4003 | static int32_t GetExceptionTlsOffset() { |
| 4004 | return Thread::ExceptionOffset<kMipsWordSize>().Int32Value(); |
| 4005 | } |
| 4006 | |
| 4007 | void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) { |
| 4008 | LocationSummary* locations = |
| 4009 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4010 | locations->SetOut(Location::RequiresRegister()); |
| 4011 | } |
| 4012 | |
| 4013 | void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) { |
| 4014 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
| 4015 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 4016 | } |
| 4017 | |
| 4018 | void LocationsBuilderMIPS::VisitClearException(HClearException* clear) { |
| 4019 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4020 | } |
| 4021 | |
| 4022 | void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4023 | __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset()); |
| 4024 | } |
| 4025 | |
| 4026 | void LocationsBuilderMIPS::VisitLoadLocal(HLoadLocal* load) { |
| 4027 | load->SetLocations(nullptr); |
| 4028 | } |
| 4029 | |
| 4030 | void InstructionCodeGeneratorMIPS::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
| 4031 | // Nothing to do, this is driven by the code generator. |
| 4032 | } |
| 4033 | |
| 4034 | void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) { |
Roland Levillain | 698fa97 | 2015-12-16 17:06:47 +0000 | [diff] [blame] | 4035 | LocationSummary::CallKind call_kind = load->IsInDexCache() |
| 4036 | ? LocationSummary::kNoCall |
| 4037 | : LocationSummary::kCallOnSlowPath; |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 4038 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4039 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4040 | locations->SetOut(Location::RequiresRegister()); |
| 4041 | } |
| 4042 | |
| 4043 | void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4044 | LocationSummary* locations = load->GetLocations(); |
| 4045 | Register out = locations->Out().AsRegister<Register>(); |
| 4046 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 4047 | __ LoadFromOffset(kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
| 4048 | __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value()); |
| 4049 | __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 4050 | |
| 4051 | if (!load->IsInDexCache()) { |
| 4052 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS(load); |
| 4053 | codegen_->AddSlowPath(slow_path); |
| 4054 | __ Beqz(out, slow_path->GetEntryLabel()); |
| 4055 | __ Bind(slow_path->GetExitLabel()); |
| 4056 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4057 | } |
| 4058 | |
| 4059 | void LocationsBuilderMIPS::VisitLocal(HLocal* local) { |
| 4060 | local->SetLocations(nullptr); |
| 4061 | } |
| 4062 | |
| 4063 | void InstructionCodeGeneratorMIPS::VisitLocal(HLocal* local) { |
| 4064 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 4065 | } |
| 4066 | |
| 4067 | void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) { |
| 4068 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4069 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4070 | } |
| 4071 | |
| 4072 | void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 4073 | // Will be generated at use site. |
| 4074 | } |
| 4075 | |
| 4076 | void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4077 | LocationSummary* locations = |
| 4078 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4079 | InvokeRuntimeCallingConvention calling_convention; |
| 4080 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4081 | } |
| 4082 | |
| 4083 | void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4084 | if (instruction->IsEnter()) { |
| 4085 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLockObject), |
| 4086 | instruction, |
| 4087 | instruction->GetDexPc(), |
| 4088 | nullptr, |
| 4089 | IsDirectEntrypoint(kQuickLockObject)); |
| 4090 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 4091 | } else { |
| 4092 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pUnlockObject), |
| 4093 | instruction, |
| 4094 | instruction->GetDexPc(), |
| 4095 | nullptr, |
| 4096 | IsDirectEntrypoint(kQuickUnlockObject)); |
| 4097 | } |
| 4098 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 4099 | } |
| 4100 | |
| 4101 | void LocationsBuilderMIPS::VisitMul(HMul* mul) { |
| 4102 | LocationSummary* locations = |
| 4103 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 4104 | switch (mul->GetResultType()) { |
| 4105 | case Primitive::kPrimInt: |
| 4106 | case Primitive::kPrimLong: |
| 4107 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4108 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4109 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4110 | break; |
| 4111 | |
| 4112 | case Primitive::kPrimFloat: |
| 4113 | case Primitive::kPrimDouble: |
| 4114 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4115 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4116 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4117 | break; |
| 4118 | |
| 4119 | default: |
| 4120 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4121 | } |
| 4122 | } |
| 4123 | |
| 4124 | void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) { |
| 4125 | Primitive::Type type = instruction->GetType(); |
| 4126 | LocationSummary* locations = instruction->GetLocations(); |
| 4127 | bool isR6 = codegen_->GetInstructionSetFeatures().IsR6(); |
| 4128 | |
| 4129 | switch (type) { |
| 4130 | case Primitive::kPrimInt: { |
| 4131 | Register dst = locations->Out().AsRegister<Register>(); |
| 4132 | Register lhs = locations->InAt(0).AsRegister<Register>(); |
| 4133 | Register rhs = locations->InAt(1).AsRegister<Register>(); |
| 4134 | |
| 4135 | if (isR6) { |
| 4136 | __ MulR6(dst, lhs, rhs); |
| 4137 | } else { |
| 4138 | __ MulR2(dst, lhs, rhs); |
| 4139 | } |
| 4140 | break; |
| 4141 | } |
| 4142 | case Primitive::kPrimLong: { |
| 4143 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 4144 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 4145 | Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4146 | Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4147 | Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>(); |
| 4148 | Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>(); |
| 4149 | |
| 4150 | // Extra checks to protect caused by the existance of A1_A2. |
| 4151 | // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo: |
| 4152 | // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2). |
| 4153 | DCHECK_NE(dst_high, lhs_low); |
| 4154 | DCHECK_NE(dst_high, rhs_low); |
| 4155 | |
| 4156 | // A_B * C_D |
| 4157 | // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ] |
| 4158 | // dst_lo: [ low(B*D) ] |
| 4159 | // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result. |
| 4160 | |
| 4161 | if (isR6) { |
| 4162 | __ MulR6(TMP, lhs_high, rhs_low); |
| 4163 | __ MulR6(dst_high, lhs_low, rhs_high); |
| 4164 | __ Addu(dst_high, dst_high, TMP); |
| 4165 | __ MuhuR6(TMP, lhs_low, rhs_low); |
| 4166 | __ Addu(dst_high, dst_high, TMP); |
| 4167 | __ MulR6(dst_low, lhs_low, rhs_low); |
| 4168 | } else { |
| 4169 | __ MulR2(TMP, lhs_high, rhs_low); |
| 4170 | __ MulR2(dst_high, lhs_low, rhs_high); |
| 4171 | __ Addu(dst_high, dst_high, TMP); |
| 4172 | __ MultuR2(lhs_low, rhs_low); |
| 4173 | __ Mfhi(TMP); |
| 4174 | __ Addu(dst_high, dst_high, TMP); |
| 4175 | __ Mflo(dst_low); |
| 4176 | } |
| 4177 | break; |
| 4178 | } |
| 4179 | case Primitive::kPrimFloat: |
| 4180 | case Primitive::kPrimDouble: { |
| 4181 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 4182 | FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 4183 | FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>(); |
| 4184 | if (type == Primitive::kPrimFloat) { |
| 4185 | __ MulS(dst, lhs, rhs); |
| 4186 | } else { |
| 4187 | __ MulD(dst, lhs, rhs); |
| 4188 | } |
| 4189 | break; |
| 4190 | } |
| 4191 | default: |
| 4192 | LOG(FATAL) << "Unexpected mul type " << type; |
| 4193 | } |
| 4194 | } |
| 4195 | |
| 4196 | void LocationsBuilderMIPS::VisitNeg(HNeg* neg) { |
| 4197 | LocationSummary* locations = |
| 4198 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 4199 | switch (neg->GetResultType()) { |
| 4200 | case Primitive::kPrimInt: |
| 4201 | case Primitive::kPrimLong: |
| 4202 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4203 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4204 | break; |
| 4205 | |
| 4206 | case Primitive::kPrimFloat: |
| 4207 | case Primitive::kPrimDouble: |
| 4208 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4209 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4210 | break; |
| 4211 | |
| 4212 | default: |
| 4213 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 4214 | } |
| 4215 | } |
| 4216 | |
| 4217 | void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) { |
| 4218 | Primitive::Type type = instruction->GetType(); |
| 4219 | LocationSummary* locations = instruction->GetLocations(); |
| 4220 | |
| 4221 | switch (type) { |
| 4222 | case Primitive::kPrimInt: { |
| 4223 | Register dst = locations->Out().AsRegister<Register>(); |
| 4224 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 4225 | __ Subu(dst, ZERO, src); |
| 4226 | break; |
| 4227 | } |
| 4228 | case Primitive::kPrimLong: { |
| 4229 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 4230 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 4231 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4232 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4233 | __ Subu(dst_low, ZERO, src_low); |
| 4234 | __ Sltu(TMP, ZERO, dst_low); |
| 4235 | __ Subu(dst_high, ZERO, src_high); |
| 4236 | __ Subu(dst_high, dst_high, TMP); |
| 4237 | break; |
| 4238 | } |
| 4239 | case Primitive::kPrimFloat: |
| 4240 | case Primitive::kPrimDouble: { |
| 4241 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 4242 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 4243 | if (type == Primitive::kPrimFloat) { |
| 4244 | __ NegS(dst, src); |
| 4245 | } else { |
| 4246 | __ NegD(dst, src); |
| 4247 | } |
| 4248 | break; |
| 4249 | } |
| 4250 | default: |
| 4251 | LOG(FATAL) << "Unexpected neg type " << type; |
| 4252 | } |
| 4253 | } |
| 4254 | |
| 4255 | void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) { |
| 4256 | LocationSummary* locations = |
| 4257 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4258 | InvokeRuntimeCallingConvention calling_convention; |
| 4259 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4260 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 4261 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 4262 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4263 | } |
| 4264 | |
| 4265 | void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) { |
| 4266 | InvokeRuntimeCallingConvention calling_convention; |
| 4267 | Register current_method_register = calling_convention.GetRegisterAt(2); |
| 4268 | __ Lw(current_method_register, SP, kCurrentMethodStackOffset); |
| 4269 | // Move an uint16_t value to a register. |
| 4270 | __ LoadConst32(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
| 4271 | codegen_->InvokeRuntime( |
| 4272 | GetThreadOffset<kMipsWordSize>(instruction->GetEntrypoint()).Int32Value(), |
| 4273 | instruction, |
| 4274 | instruction->GetDexPc(), |
| 4275 | nullptr, |
| 4276 | IsDirectEntrypoint(kQuickAllocArrayWithAccessCheck)); |
| 4277 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, |
| 4278 | void*, uint32_t, int32_t, ArtMethod*>(); |
| 4279 | } |
| 4280 | |
| 4281 | void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) { |
| 4282 | LocationSummary* locations = |
| 4283 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4284 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 4285 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4286 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4287 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 4288 | } |
| 4289 | |
| 4290 | void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4291 | codegen_->InvokeRuntime( |
| 4292 | GetThreadOffset<kMipsWordSize>(instruction->GetEntrypoint()).Int32Value(), |
| 4293 | instruction, |
| 4294 | instruction->GetDexPc(), |
| 4295 | nullptr, |
| 4296 | IsDirectEntrypoint(kQuickAllocObjectWithAccessCheck)); |
| 4297 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4298 | } |
| 4299 | |
| 4300 | void LocationsBuilderMIPS::VisitNot(HNot* instruction) { |
| 4301 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4302 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4303 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4304 | } |
| 4305 | |
| 4306 | void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) { |
| 4307 | Primitive::Type type = instruction->GetType(); |
| 4308 | LocationSummary* locations = instruction->GetLocations(); |
| 4309 | |
| 4310 | switch (type) { |
| 4311 | case Primitive::kPrimInt: { |
| 4312 | Register dst = locations->Out().AsRegister<Register>(); |
| 4313 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 4314 | __ Nor(dst, src, ZERO); |
| 4315 | break; |
| 4316 | } |
| 4317 | |
| 4318 | case Primitive::kPrimLong: { |
| 4319 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 4320 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 4321 | Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4322 | Register src_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4323 | __ Nor(dst_high, src_high, ZERO); |
| 4324 | __ Nor(dst_low, src_low, ZERO); |
| 4325 | break; |
| 4326 | } |
| 4327 | |
| 4328 | default: |
| 4329 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 4330 | } |
| 4331 | } |
| 4332 | |
| 4333 | void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
| 4334 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4335 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4336 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4337 | } |
| 4338 | |
| 4339 | void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) { |
| 4340 | LocationSummary* locations = instruction->GetLocations(); |
| 4341 | __ Xori(locations->Out().AsRegister<Register>(), |
| 4342 | locations->InAt(0).AsRegister<Register>(), |
| 4343 | 1); |
| 4344 | } |
| 4345 | |
| 4346 | void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) { |
| 4347 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4348 | ? LocationSummary::kCallOnSlowPath |
| 4349 | : LocationSummary::kNoCall; |
| 4350 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4351 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4352 | if (instruction->HasUses()) { |
| 4353 | locations->SetOut(Location::SameAsFirstInput()); |
| 4354 | } |
| 4355 | } |
| 4356 | |
| 4357 | void InstructionCodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4358 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4359 | return; |
| 4360 | } |
| 4361 | Location obj = instruction->GetLocations()->InAt(0); |
| 4362 | |
| 4363 | __ Lw(ZERO, obj.AsRegister<Register>(), 0); |
| 4364 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4365 | } |
| 4366 | |
| 4367 | void InstructionCodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| 4368 | SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS(instruction); |
| 4369 | codegen_->AddSlowPath(slow_path); |
| 4370 | |
| 4371 | Location obj = instruction->GetLocations()->InAt(0); |
| 4372 | |
| 4373 | __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 4374 | } |
| 4375 | |
| 4376 | void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) { |
| 4377 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
| 4378 | GenerateImplicitNullCheck(instruction); |
| 4379 | } else { |
| 4380 | GenerateExplicitNullCheck(instruction); |
| 4381 | } |
| 4382 | } |
| 4383 | |
| 4384 | void LocationsBuilderMIPS::VisitOr(HOr* instruction) { |
| 4385 | HandleBinaryOp(instruction); |
| 4386 | } |
| 4387 | |
| 4388 | void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) { |
| 4389 | HandleBinaryOp(instruction); |
| 4390 | } |
| 4391 | |
| 4392 | void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 4393 | LOG(FATAL) << "Unreachable"; |
| 4394 | } |
| 4395 | |
| 4396 | void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) { |
| 4397 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4398 | } |
| 4399 | |
| 4400 | void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) { |
| 4401 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4402 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4403 | if (location.IsStackSlot()) { |
| 4404 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4405 | } else if (location.IsDoubleStackSlot()) { |
| 4406 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4407 | } |
| 4408 | locations->SetOut(location); |
| 4409 | } |
| 4410 | |
| 4411 | void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction |
| 4412 | ATTRIBUTE_UNUSED) { |
| 4413 | // Nothing to do, the parameter is already at its location. |
| 4414 | } |
| 4415 | |
| 4416 | void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4417 | LocationSummary* locations = |
| 4418 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4419 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4420 | } |
| 4421 | |
| 4422 | void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction |
| 4423 | ATTRIBUTE_UNUSED) { |
| 4424 | // Nothing to do, the method is already at its location. |
| 4425 | } |
| 4426 | |
| 4427 | void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) { |
| 4428 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4429 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 4430 | locations->SetInAt(i, Location::Any()); |
| 4431 | } |
| 4432 | locations->SetOut(Location::Any()); |
| 4433 | } |
| 4434 | |
| 4435 | void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 4436 | LOG(FATAL) << "Unreachable"; |
| 4437 | } |
| 4438 | |
| 4439 | void LocationsBuilderMIPS::VisitRem(HRem* rem) { |
| 4440 | Primitive::Type type = rem->GetResultType(); |
| 4441 | LocationSummary::CallKind call_kind = |
| 4442 | (type == Primitive::kPrimInt) ? LocationSummary::kNoCall : LocationSummary::kCall; |
| 4443 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 4444 | |
| 4445 | switch (type) { |
| 4446 | case Primitive::kPrimInt: |
| 4447 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4448 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4449 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4450 | break; |
| 4451 | |
| 4452 | case Primitive::kPrimLong: { |
| 4453 | InvokeRuntimeCallingConvention calling_convention; |
| 4454 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4455 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4456 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4457 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4458 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 4459 | break; |
| 4460 | } |
| 4461 | |
| 4462 | case Primitive::kPrimFloat: |
| 4463 | case Primitive::kPrimDouble: { |
| 4464 | InvokeRuntimeCallingConvention calling_convention; |
| 4465 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 4466 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 4467 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 4468 | break; |
| 4469 | } |
| 4470 | |
| 4471 | default: |
| 4472 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4473 | } |
| 4474 | } |
| 4475 | |
| 4476 | void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) { |
| 4477 | Primitive::Type type = instruction->GetType(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4478 | |
| 4479 | switch (type) { |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 4480 | case Primitive::kPrimInt: |
| 4481 | GenerateDivRemIntegral(instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4482 | break; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4483 | case Primitive::kPrimLong: { |
| 4484 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 4485 | instruction, |
| 4486 | instruction->GetDexPc(), |
| 4487 | nullptr, |
| 4488 | IsDirectEntrypoint(kQuickLmod)); |
| 4489 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 4490 | break; |
| 4491 | } |
| 4492 | case Primitive::kPrimFloat: { |
| 4493 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), |
| 4494 | instruction, instruction->GetDexPc(), |
| 4495 | nullptr, |
| 4496 | IsDirectEntrypoint(kQuickFmodf)); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4497 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4498 | break; |
| 4499 | } |
| 4500 | case Primitive::kPrimDouble: { |
| 4501 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), |
| 4502 | instruction, instruction->GetDexPc(), |
| 4503 | nullptr, |
| 4504 | IsDirectEntrypoint(kQuickFmod)); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4505 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4506 | break; |
| 4507 | } |
| 4508 | default: |
| 4509 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4510 | } |
| 4511 | } |
| 4512 | |
| 4513 | void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 4514 | memory_barrier->SetLocations(nullptr); |
| 4515 | } |
| 4516 | |
| 4517 | void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 4518 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 4519 | } |
| 4520 | |
| 4521 | void LocationsBuilderMIPS::VisitReturn(HReturn* ret) { |
| 4522 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret); |
| 4523 | Primitive::Type return_type = ret->InputAt(0)->GetType(); |
| 4524 | locations->SetInAt(0, MipsReturnLocation(return_type)); |
| 4525 | } |
| 4526 | |
| 4527 | void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 4528 | codegen_->GenerateFrameExit(); |
| 4529 | } |
| 4530 | |
| 4531 | void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) { |
| 4532 | ret->SetLocations(nullptr); |
| 4533 | } |
| 4534 | |
| 4535 | void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 4536 | codegen_->GenerateFrameExit(); |
| 4537 | } |
| 4538 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4539 | void LocationsBuilderMIPS::VisitRor(HRor* ror ATTRIBUTE_UNUSED) { |
| 4540 | LOG(FATAL) << "Unreachable"; |
| 4541 | UNREACHABLE(); |
| 4542 | } |
| 4543 | |
| 4544 | void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror ATTRIBUTE_UNUSED) { |
| 4545 | LOG(FATAL) << "Unreachable"; |
| 4546 | UNREACHABLE(); |
| 4547 | } |
| 4548 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4549 | void LocationsBuilderMIPS::VisitShl(HShl* shl) { |
| 4550 | HandleShift(shl); |
| 4551 | } |
| 4552 | |
| 4553 | void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) { |
| 4554 | HandleShift(shl); |
| 4555 | } |
| 4556 | |
| 4557 | void LocationsBuilderMIPS::VisitShr(HShr* shr) { |
| 4558 | HandleShift(shr); |
| 4559 | } |
| 4560 | |
| 4561 | void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) { |
| 4562 | HandleShift(shr); |
| 4563 | } |
| 4564 | |
| 4565 | void LocationsBuilderMIPS::VisitStoreLocal(HStoreLocal* store) { |
| 4566 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store); |
| 4567 | Primitive::Type field_type = store->InputAt(1)->GetType(); |
| 4568 | switch (field_type) { |
| 4569 | case Primitive::kPrimNot: |
| 4570 | case Primitive::kPrimBoolean: |
| 4571 | case Primitive::kPrimByte: |
| 4572 | case Primitive::kPrimChar: |
| 4573 | case Primitive::kPrimShort: |
| 4574 | case Primitive::kPrimInt: |
| 4575 | case Primitive::kPrimFloat: |
| 4576 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 4577 | break; |
| 4578 | |
| 4579 | case Primitive::kPrimLong: |
| 4580 | case Primitive::kPrimDouble: |
| 4581 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 4582 | break; |
| 4583 | |
| 4584 | default: |
| 4585 | LOG(FATAL) << "Unimplemented local type " << field_type; |
| 4586 | } |
| 4587 | } |
| 4588 | |
| 4589 | void InstructionCodeGeneratorMIPS::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
| 4590 | } |
| 4591 | |
| 4592 | void LocationsBuilderMIPS::VisitSub(HSub* instruction) { |
| 4593 | HandleBinaryOp(instruction); |
| 4594 | } |
| 4595 | |
| 4596 | void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) { |
| 4597 | HandleBinaryOp(instruction); |
| 4598 | } |
| 4599 | |
| 4600 | void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4601 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4602 | } |
| 4603 | |
| 4604 | void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4605 | HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 4606 | } |
| 4607 | |
| 4608 | void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4609 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4610 | } |
| 4611 | |
| 4612 | void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4613 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc()); |
| 4614 | } |
| 4615 | |
| 4616 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet( |
| 4617 | HUnresolvedInstanceFieldGet* instruction) { |
| 4618 | FieldAccessCallingConventionMIPS calling_convention; |
| 4619 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 4620 | instruction->GetFieldType(), |
| 4621 | calling_convention); |
| 4622 | } |
| 4623 | |
| 4624 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet( |
| 4625 | HUnresolvedInstanceFieldGet* instruction) { |
| 4626 | FieldAccessCallingConventionMIPS calling_convention; |
| 4627 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4628 | instruction->GetFieldType(), |
| 4629 | instruction->GetFieldIndex(), |
| 4630 | instruction->GetDexPc(), |
| 4631 | calling_convention); |
| 4632 | } |
| 4633 | |
| 4634 | void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet( |
| 4635 | HUnresolvedInstanceFieldSet* instruction) { |
| 4636 | FieldAccessCallingConventionMIPS calling_convention; |
| 4637 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 4638 | instruction->GetFieldType(), |
| 4639 | calling_convention); |
| 4640 | } |
| 4641 | |
| 4642 | void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet( |
| 4643 | HUnresolvedInstanceFieldSet* instruction) { |
| 4644 | FieldAccessCallingConventionMIPS calling_convention; |
| 4645 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4646 | instruction->GetFieldType(), |
| 4647 | instruction->GetFieldIndex(), |
| 4648 | instruction->GetDexPc(), |
| 4649 | calling_convention); |
| 4650 | } |
| 4651 | |
| 4652 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet( |
| 4653 | HUnresolvedStaticFieldGet* instruction) { |
| 4654 | FieldAccessCallingConventionMIPS calling_convention; |
| 4655 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 4656 | instruction->GetFieldType(), |
| 4657 | calling_convention); |
| 4658 | } |
| 4659 | |
| 4660 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet( |
| 4661 | HUnresolvedStaticFieldGet* instruction) { |
| 4662 | FieldAccessCallingConventionMIPS calling_convention; |
| 4663 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4664 | instruction->GetFieldType(), |
| 4665 | instruction->GetFieldIndex(), |
| 4666 | instruction->GetDexPc(), |
| 4667 | calling_convention); |
| 4668 | } |
| 4669 | |
| 4670 | void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet( |
| 4671 | HUnresolvedStaticFieldSet* instruction) { |
| 4672 | FieldAccessCallingConventionMIPS calling_convention; |
| 4673 | codegen_->CreateUnresolvedFieldLocationSummary(instruction, |
| 4674 | instruction->GetFieldType(), |
| 4675 | calling_convention); |
| 4676 | } |
| 4677 | |
| 4678 | void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet( |
| 4679 | HUnresolvedStaticFieldSet* instruction) { |
| 4680 | FieldAccessCallingConventionMIPS calling_convention; |
| 4681 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4682 | instruction->GetFieldType(), |
| 4683 | instruction->GetFieldIndex(), |
| 4684 | instruction->GetDexPc(), |
| 4685 | calling_convention); |
| 4686 | } |
| 4687 | |
| 4688 | void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4689 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4690 | } |
| 4691 | |
| 4692 | void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4693 | HBasicBlock* block = instruction->GetBlock(); |
| 4694 | if (block->GetLoopInformation() != nullptr) { |
| 4695 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4696 | // The back edge will generate the suspend check. |
| 4697 | return; |
| 4698 | } |
| 4699 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4700 | // The goto will generate the suspend check. |
| 4701 | return; |
| 4702 | } |
| 4703 | GenerateSuspendCheck(instruction, nullptr); |
| 4704 | } |
| 4705 | |
| 4706 | void LocationsBuilderMIPS::VisitTemporary(HTemporary* temp) { |
| 4707 | temp->SetLocations(nullptr); |
| 4708 | } |
| 4709 | |
| 4710 | void InstructionCodeGeneratorMIPS::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) { |
| 4711 | // Nothing to do, this is driven by the code generator. |
| 4712 | } |
| 4713 | |
| 4714 | void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) { |
| 4715 | LocationSummary* locations = |
| 4716 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4717 | InvokeRuntimeCallingConvention calling_convention; |
| 4718 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4719 | } |
| 4720 | |
| 4721 | void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) { |
| 4722 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 4723 | instruction, |
| 4724 | instruction->GetDexPc(), |
| 4725 | nullptr, |
| 4726 | IsDirectEntrypoint(kQuickDeliverException)); |
| 4727 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 4728 | } |
| 4729 | |
| 4730 | void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
| 4731 | Primitive::Type input_type = conversion->GetInputType(); |
| 4732 | Primitive::Type result_type = conversion->GetResultType(); |
| 4733 | DCHECK_NE(input_type, result_type); |
| 4734 | |
| 4735 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 4736 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 4737 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 4738 | } |
| 4739 | |
| 4740 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4741 | if ((Primitive::IsFloatingPointType(result_type) && input_type == Primitive::kPrimLong) || |
| 4742 | (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type))) { |
| 4743 | call_kind = LocationSummary::kCall; |
| 4744 | } |
| 4745 | |
| 4746 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 4747 | |
| 4748 | if (call_kind == LocationSummary::kNoCall) { |
| 4749 | if (Primitive::IsFloatingPointType(input_type)) { |
| 4750 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4751 | } else { |
| 4752 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4753 | } |
| 4754 | |
| 4755 | if (Primitive::IsFloatingPointType(result_type)) { |
| 4756 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4757 | } else { |
| 4758 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4759 | } |
| 4760 | } else { |
| 4761 | InvokeRuntimeCallingConvention calling_convention; |
| 4762 | |
| 4763 | if (Primitive::IsFloatingPointType(input_type)) { |
| 4764 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 4765 | } else { |
| 4766 | DCHECK_EQ(input_type, Primitive::kPrimLong); |
| 4767 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4768 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4769 | } |
| 4770 | |
| 4771 | locations->SetOut(calling_convention.GetReturnLocation(result_type)); |
| 4772 | } |
| 4773 | } |
| 4774 | |
| 4775 | void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) { |
| 4776 | LocationSummary* locations = conversion->GetLocations(); |
| 4777 | Primitive::Type result_type = conversion->GetResultType(); |
| 4778 | Primitive::Type input_type = conversion->GetInputType(); |
| 4779 | bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2(); |
| 4780 | |
| 4781 | DCHECK_NE(input_type, result_type); |
| 4782 | |
| 4783 | if (result_type == Primitive::kPrimLong && Primitive::IsIntegralType(input_type)) { |
| 4784 | Register dst_high = locations->Out().AsRegisterPairHigh<Register>(); |
| 4785 | Register dst_low = locations->Out().AsRegisterPairLow<Register>(); |
| 4786 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 4787 | |
| 4788 | __ Move(dst_low, src); |
| 4789 | __ Sra(dst_high, src, 31); |
| 4790 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
| 4791 | Register dst = locations->Out().AsRegister<Register>(); |
| 4792 | Register src = (input_type == Primitive::kPrimLong) |
| 4793 | ? locations->InAt(0).AsRegisterPairLow<Register>() |
| 4794 | : locations->InAt(0).AsRegister<Register>(); |
| 4795 | |
| 4796 | switch (result_type) { |
| 4797 | case Primitive::kPrimChar: |
| 4798 | __ Andi(dst, src, 0xFFFF); |
| 4799 | break; |
| 4800 | case Primitive::kPrimByte: |
| 4801 | if (has_sign_extension) { |
| 4802 | __ Seb(dst, src); |
| 4803 | } else { |
| 4804 | __ Sll(dst, src, 24); |
| 4805 | __ Sra(dst, dst, 24); |
| 4806 | } |
| 4807 | break; |
| 4808 | case Primitive::kPrimShort: |
| 4809 | if (has_sign_extension) { |
| 4810 | __ Seh(dst, src); |
| 4811 | } else { |
| 4812 | __ Sll(dst, src, 16); |
| 4813 | __ Sra(dst, dst, 16); |
| 4814 | } |
| 4815 | break; |
| 4816 | case Primitive::kPrimInt: |
| 4817 | __ Move(dst, src); |
| 4818 | break; |
| 4819 | |
| 4820 | default: |
| 4821 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4822 | << " to " << result_type; |
| 4823 | } |
| 4824 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
| 4825 | if (input_type != Primitive::kPrimLong) { |
| 4826 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 4827 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 4828 | __ Mtc1(src, FTMP); |
| 4829 | if (result_type == Primitive::kPrimFloat) { |
| 4830 | __ Cvtsw(dst, FTMP); |
| 4831 | } else { |
| 4832 | __ Cvtdw(dst, FTMP); |
| 4833 | } |
| 4834 | } else { |
| 4835 | int32_t entry_offset = (result_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pL2f) |
| 4836 | : QUICK_ENTRY_POINT(pL2d); |
| 4837 | bool direct = (result_type == Primitive::kPrimFloat) ? IsDirectEntrypoint(kQuickL2f) |
| 4838 | : IsDirectEntrypoint(kQuickL2d); |
| 4839 | codegen_->InvokeRuntime(entry_offset, |
| 4840 | conversion, |
| 4841 | conversion->GetDexPc(), |
| 4842 | nullptr, |
| 4843 | direct); |
| 4844 | if (result_type == Primitive::kPrimFloat) { |
| 4845 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 4846 | } else { |
| 4847 | CheckEntrypointTypes<kQuickL2d, double, int64_t>(); |
| 4848 | } |
| 4849 | } |
| 4850 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
| 4851 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
| 4852 | int32_t entry_offset; |
| 4853 | bool direct; |
| 4854 | if (result_type != Primitive::kPrimLong) { |
| 4855 | entry_offset = (input_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pF2iz) |
| 4856 | : QUICK_ENTRY_POINT(pD2iz); |
| 4857 | direct = (result_type == Primitive::kPrimFloat) ? IsDirectEntrypoint(kQuickF2iz) |
| 4858 | : IsDirectEntrypoint(kQuickD2iz); |
| 4859 | } else { |
| 4860 | entry_offset = (input_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pF2l) |
| 4861 | : QUICK_ENTRY_POINT(pD2l); |
| 4862 | direct = (result_type == Primitive::kPrimFloat) ? IsDirectEntrypoint(kQuickF2l) |
| 4863 | : IsDirectEntrypoint(kQuickD2l); |
| 4864 | } |
| 4865 | codegen_->InvokeRuntime(entry_offset, |
| 4866 | conversion, |
| 4867 | conversion->GetDexPc(), |
| 4868 | nullptr, |
| 4869 | direct); |
| 4870 | if (result_type != Primitive::kPrimLong) { |
| 4871 | if (input_type == Primitive::kPrimFloat) { |
| 4872 | CheckEntrypointTypes<kQuickF2iz, int32_t, float>(); |
| 4873 | } else { |
| 4874 | CheckEntrypointTypes<kQuickD2iz, int32_t, double>(); |
| 4875 | } |
| 4876 | } else { |
| 4877 | if (input_type == Primitive::kPrimFloat) { |
| 4878 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 4879 | } else { |
| 4880 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 4881 | } |
| 4882 | } |
| 4883 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 4884 | Primitive::IsFloatingPointType(input_type)) { |
| 4885 | FRegister dst = locations->Out().AsFpuRegister<FRegister>(); |
| 4886 | FRegister src = locations->InAt(0).AsFpuRegister<FRegister>(); |
| 4887 | if (result_type == Primitive::kPrimFloat) { |
| 4888 | __ Cvtsd(dst, src); |
| 4889 | } else { |
| 4890 | __ Cvtds(dst, src); |
| 4891 | } |
| 4892 | } else { |
| 4893 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 4894 | << " to " << result_type; |
| 4895 | } |
| 4896 | } |
| 4897 | |
| 4898 | void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) { |
| 4899 | HandleShift(ushr); |
| 4900 | } |
| 4901 | |
| 4902 | void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) { |
| 4903 | HandleShift(ushr); |
| 4904 | } |
| 4905 | |
| 4906 | void LocationsBuilderMIPS::VisitXor(HXor* instruction) { |
| 4907 | HandleBinaryOp(instruction); |
| 4908 | } |
| 4909 | |
| 4910 | void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) { |
| 4911 | HandleBinaryOp(instruction); |
| 4912 | } |
| 4913 | |
| 4914 | void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 4915 | // Nothing to do, this should be removed during prepare for register allocator. |
| 4916 | LOG(FATAL) << "Unreachable"; |
| 4917 | } |
| 4918 | |
| 4919 | void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 4920 | // Nothing to do, this should be removed during prepare for register allocator. |
| 4921 | LOG(FATAL) << "Unreachable"; |
| 4922 | } |
| 4923 | |
| 4924 | void LocationsBuilderMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4925 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4926 | } |
| 4927 | |
| 4928 | void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4929 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4930 | } |
| 4931 | |
| 4932 | void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4933 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4934 | } |
| 4935 | |
| 4936 | void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4937 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4938 | } |
| 4939 | |
| 4940 | void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4941 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4942 | } |
| 4943 | |
| 4944 | void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4945 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4946 | } |
| 4947 | |
| 4948 | void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4949 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4950 | } |
| 4951 | |
| 4952 | void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4953 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4954 | } |
| 4955 | |
| 4956 | void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4957 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4958 | } |
| 4959 | |
| 4960 | void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4961 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4962 | } |
| 4963 | |
| 4964 | void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4965 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4966 | } |
| 4967 | |
| 4968 | void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4969 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4970 | } |
| 4971 | |
| 4972 | void LocationsBuilderMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4973 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4974 | } |
| 4975 | |
| 4976 | void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4977 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4978 | } |
| 4979 | |
| 4980 | void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4981 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4982 | } |
| 4983 | |
| 4984 | void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4985 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4986 | } |
| 4987 | |
| 4988 | void LocationsBuilderMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4989 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4990 | } |
| 4991 | |
| 4992 | void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4993 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4994 | } |
| 4995 | |
| 4996 | void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4997 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4998 | } |
| 4999 | |
| 5000 | void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5001 | HandleCondition(comp); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5002 | } |
| 5003 | |
| 5004 | void LocationsBuilderMIPS::VisitFakeString(HFakeString* instruction) { |
| 5005 | DCHECK(codegen_->IsBaseline()); |
| 5006 | LocationSummary* locations = |
| 5007 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5008 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 5009 | } |
| 5010 | |
| 5011 | void InstructionCodeGeneratorMIPS::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 5012 | DCHECK(codegen_->IsBaseline()); |
| 5013 | // Will be generated at use site. |
| 5014 | } |
| 5015 | |
| 5016 | void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5017 | LocationSummary* locations = |
| 5018 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 5019 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5020 | } |
| 5021 | |
| 5022 | void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5023 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 5024 | int32_t num_entries = switch_instr->GetNumEntries(); |
| 5025 | LocationSummary* locations = switch_instr->GetLocations(); |
| 5026 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 5027 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5028 | |
| 5029 | // Create a set of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5030 | Register temp_reg = TMP; |
| 5031 | __ Addiu32(temp_reg, value_reg, -lower_bound); |
| 5032 | // Jump to default if index is negative |
| 5033 | // Note: We don't check the case that index is positive while value < lower_bound, because in |
| 5034 | // this case, index >= num_entries must be true. So that we can save one branch instruction. |
| 5035 | __ Bltz(temp_reg, codegen_->GetLabelOf(default_block)); |
| 5036 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5037 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5038 | // Jump to successors[0] if value == lower_bound. |
| 5039 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0])); |
| 5040 | int32_t last_index = 0; |
| 5041 | for (; num_entries - last_index > 2; last_index += 2) { |
| 5042 | __ Addiu(temp_reg, temp_reg, -2); |
| 5043 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 5044 | __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
| 5045 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 5046 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2])); |
| 5047 | } |
| 5048 | if (num_entries - last_index == 2) { |
| 5049 | // The last missing case_value. |
| 5050 | __ Addiu(temp_reg, temp_reg, -1); |
| 5051 | __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1])); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5052 | } |
| 5053 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5054 | // And the default for any other value. |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 5055 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5056 | __ B(codegen_->GetLabelOf(default_block)); |
| 5057 | } |
| 5058 | } |
| 5059 | |
| 5060 | void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 5061 | // The trampoline uses the same calling convention as dex calling conventions, |
| 5062 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 5063 | // the method_idx. |
| 5064 | HandleInvoke(invoke); |
| 5065 | } |
| 5066 | |
| 5067 | void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 5068 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 5069 | } |
| 5070 | |
| 5071 | #undef __ |
| 5072 | #undef QUICK_ENTRY_POINT |
| 5073 | |
| 5074 | } // namespace mips |
| 5075 | } // namespace art |