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