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