blob: ae8c85dd5e6e7c61d83743313d3360827ba97276 [file] [log] [blame]
Alexey Frunze4dda3372015-06-01 18:31:49 -07001/*
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_mips64.h"
18
19#include "entrypoints/quick/quick_entrypoints.h"
20#include "entrypoints/quick/quick_entrypoints_enum.h"
21#include "gc/accounting/card_table.h"
22#include "intrinsics.h"
23#include "art_method.h"
24#include "mirror/array-inl.h"
25#include "mirror/class-inl.h"
26#include "offsets.h"
27#include "thread.h"
28#include "utils/mips64/assembler_mips64.h"
29#include "utils/assembler.h"
30#include "utils/stack_checks.h"
31
32namespace art {
33namespace mips64 {
34
35static constexpr int kCurrentMethodStackOffset = 0;
36static constexpr GpuRegister kMethodRegisterArgument = A0;
37
38// We need extra temporary/scratch registers (in addition to AT) in some cases.
39static constexpr GpuRegister TMP = T8;
40static constexpr FpuRegister FTMP = F8;
41
42// ART Thread Register.
43static constexpr GpuRegister TR = S1;
44
45Location Mips64ReturnLocation(Primitive::Type return_type) {
46 switch (return_type) {
47 case Primitive::kPrimBoolean:
48 case Primitive::kPrimByte:
49 case Primitive::kPrimChar:
50 case Primitive::kPrimShort:
51 case Primitive::kPrimInt:
52 case Primitive::kPrimNot:
53 case Primitive::kPrimLong:
54 return Location::RegisterLocation(V0);
55
56 case Primitive::kPrimFloat:
57 case Primitive::kPrimDouble:
58 return Location::FpuRegisterLocation(F0);
59
60 case Primitive::kPrimVoid:
61 return Location();
62 }
63 UNREACHABLE();
64}
65
66Location InvokeDexCallingConventionVisitorMIPS64::GetReturnLocation(Primitive::Type type) const {
67 return Mips64ReturnLocation(type);
68}
69
70Location InvokeDexCallingConventionVisitorMIPS64::GetMethodLocation() const {
71 return Location::RegisterLocation(kMethodRegisterArgument);
72}
73
74Location InvokeDexCallingConventionVisitorMIPS64::GetNextLocation(Primitive::Type type) {
75 Location next_location;
76 if (type == Primitive::kPrimVoid) {
77 LOG(FATAL) << "Unexpected parameter type " << type;
78 }
79
80 if (Primitive::IsFloatingPointType(type) &&
81 (float_index_ < calling_convention.GetNumberOfFpuRegisters())) {
82 next_location = Location::FpuRegisterLocation(
83 calling_convention.GetFpuRegisterAt(float_index_++));
84 gp_index_++;
85 } else if (!Primitive::IsFloatingPointType(type) &&
86 (gp_index_ < calling_convention.GetNumberOfRegisters())) {
87 next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index_++));
88 float_index_++;
89 } else {
90 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
91 next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
92 : Location::StackSlot(stack_offset);
93 }
94
95 // Space on the stack is reserved for all arguments.
96 stack_index_ += Primitive::Is64BitType(type) ? 2 : 1;
97
98 // TODO: review
99
100 // TODO: shouldn't we use a whole machine word per argument on the stack?
101 // Implicit 4-byte method pointer (and such) will cause misalignment.
102
103 return next_location;
104}
105
106Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type type) {
107 return Mips64ReturnLocation(type);
108}
109
110#define __ down_cast<CodeGeneratorMIPS64*>(codegen)->GetAssembler()->
111#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64WordSize, x).Int32Value()
112
113class BoundsCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
114 public:
115 BoundsCheckSlowPathMIPS64(HBoundsCheck* instruction,
116 Location index_location,
117 Location length_location)
118 : instruction_(instruction),
119 index_location_(index_location),
120 length_location_(length_location) {}
121
122 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
123 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
124 __ Bind(GetEntryLabel());
125 // We're moving two locations to locations that could overlap, so we need a parallel
126 // move resolver.
127 InvokeRuntimeCallingConvention calling_convention;
128 codegen->EmitParallelMoves(index_location_,
129 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
130 Primitive::kPrimInt,
131 length_location_,
132 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
133 Primitive::kPrimInt);
134 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds),
135 instruction_,
136 instruction_->GetDexPc(),
137 this);
138 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
139 }
140
141 private:
142 HBoundsCheck* const instruction_;
143 const Location index_location_;
144 const Location length_location_;
145
146 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS64);
147};
148
149class DivZeroCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
150 public:
151 explicit DivZeroCheckSlowPathMIPS64(HDivZeroCheck* instruction) : instruction_(instruction) {}
152
153 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
154 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
155 __ Bind(GetEntryLabel());
156 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero),
157 instruction_,
158 instruction_->GetDexPc(),
159 this);
160 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
161 }
162
163 private:
164 HDivZeroCheck* const instruction_;
165 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS64);
166};
167
168class LoadClassSlowPathMIPS64 : public SlowPathCodeMIPS64 {
169 public:
170 LoadClassSlowPathMIPS64(HLoadClass* cls,
171 HInstruction* at,
172 uint32_t dex_pc,
173 bool do_clinit)
174 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
175 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
176 }
177
178 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
179 LocationSummary* locations = at_->GetLocations();
180 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
181
182 __ Bind(GetEntryLabel());
183 SaveLiveRegisters(codegen, locations);
184
185 InvokeRuntimeCallingConvention calling_convention;
186 __ LoadConst32(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
187 int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
188 : QUICK_ENTRY_POINT(pInitializeType);
189 mips64_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
190 if (do_clinit_) {
191 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
192 } else {
193 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
194 }
195
196 // Move the class to the desired location.
197 Location out = locations->Out();
198 if (out.IsValid()) {
199 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
200 Primitive::Type type = at_->GetType();
201 mips64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type);
202 }
203
204 RestoreLiveRegisters(codegen, locations);
205 __ B(GetExitLabel());
206 }
207
208 private:
209 // The class this slow path will load.
210 HLoadClass* const cls_;
211
212 // The instruction where this slow path is happening.
213 // (Might be the load class or an initialization check).
214 HInstruction* const at_;
215
216 // The dex PC of `at_`.
217 const uint32_t dex_pc_;
218
219 // Whether to initialize the class.
220 const bool do_clinit_;
221
222 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS64);
223};
224
225class LoadStringSlowPathMIPS64 : public SlowPathCodeMIPS64 {
226 public:
227 explicit LoadStringSlowPathMIPS64(HLoadString* instruction) : instruction_(instruction) {}
228
229 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
230 LocationSummary* locations = instruction_->GetLocations();
231 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
232 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
233
234 __ Bind(GetEntryLabel());
235 SaveLiveRegisters(codegen, locations);
236
237 InvokeRuntimeCallingConvention calling_convention;
238 __ LoadConst32(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex());
239 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString),
240 instruction_,
241 instruction_->GetDexPc(),
242 this);
243 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
244 Primitive::Type type = instruction_->GetType();
245 mips64_codegen->MoveLocation(locations->Out(),
246 calling_convention.GetReturnLocation(type),
247 type);
248
249 RestoreLiveRegisters(codegen, locations);
250 __ B(GetExitLabel());
251 }
252
253 private:
254 HLoadString* const instruction_;
255
256 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS64);
257};
258
259class NullCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
260 public:
261 explicit NullCheckSlowPathMIPS64(HNullCheck* instr) : instruction_(instr) {}
262
263 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
264 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
265 __ Bind(GetEntryLabel());
266 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer),
267 instruction_,
268 instruction_->GetDexPc(),
269 this);
270 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
271 }
272
273 private:
274 HNullCheck* const instruction_;
275
276 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS64);
277};
278
279class SuspendCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
280 public:
281 explicit SuspendCheckSlowPathMIPS64(HSuspendCheck* instruction,
282 HBasicBlock* successor)
283 : instruction_(instruction), successor_(successor) {}
284
285 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
286 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
287 __ Bind(GetEntryLabel());
288 SaveLiveRegisters(codegen, instruction_->GetLocations());
289 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend),
290 instruction_,
291 instruction_->GetDexPc(),
292 this);
293 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
294 RestoreLiveRegisters(codegen, instruction_->GetLocations());
295 if (successor_ == nullptr) {
296 __ B(GetReturnLabel());
297 } else {
298 __ B(mips64_codegen->GetLabelOf(successor_));
299 }
300 }
301
302 Label* GetReturnLabel() {
303 DCHECK(successor_ == nullptr);
304 return &return_label_;
305 }
306
307 private:
308 HSuspendCheck* const instruction_;
309 // If not null, the block to branch to after the suspend check.
310 HBasicBlock* const successor_;
311
312 // If `successor_` is null, the label to branch to after the suspend check.
313 Label return_label_;
314
315 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS64);
316};
317
318class TypeCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
319 public:
320 TypeCheckSlowPathMIPS64(HInstruction* instruction,
321 Location class_to_check,
322 Location object_class,
323 uint32_t dex_pc)
324 : instruction_(instruction),
325 class_to_check_(class_to_check),
326 object_class_(object_class),
327 dex_pc_(dex_pc) {}
328
329 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
330 LocationSummary* locations = instruction_->GetLocations();
331 DCHECK(instruction_->IsCheckCast()
332 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
333 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
334
335 __ Bind(GetEntryLabel());
336 SaveLiveRegisters(codegen, locations);
337
338 // We're moving two locations to locations that could overlap, so we need a parallel
339 // move resolver.
340 InvokeRuntimeCallingConvention calling_convention;
341 codegen->EmitParallelMoves(class_to_check_,
342 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
343 Primitive::kPrimNot,
344 object_class_,
345 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
346 Primitive::kPrimNot);
347
348 if (instruction_->IsInstanceOf()) {
349 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial),
350 instruction_,
351 dex_pc_,
352 this);
353 Primitive::Type ret_type = instruction_->GetType();
354 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
355 mips64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
356 CheckEntrypointTypes<kQuickInstanceofNonTrivial,
357 uint32_t,
358 const mirror::Class*,
359 const mirror::Class*>();
360 } else {
361 DCHECK(instruction_->IsCheckCast());
362 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_, this);
363 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
364 }
365
366 RestoreLiveRegisters(codegen, locations);
367 __ B(GetExitLabel());
368 }
369
370 private:
371 HInstruction* const instruction_;
372 const Location class_to_check_;
373 const Location object_class_;
374 uint32_t dex_pc_;
375
376 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS64);
377};
378
379class DeoptimizationSlowPathMIPS64 : public SlowPathCodeMIPS64 {
380 public:
381 explicit DeoptimizationSlowPathMIPS64(HInstruction* instruction)
382 : instruction_(instruction) {}
383
384 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
385 __ Bind(GetEntryLabel());
386 SaveLiveRegisters(codegen, instruction_->GetLocations());
387 DCHECK(instruction_->IsDeoptimize());
388 HDeoptimize* deoptimize = instruction_->AsDeoptimize();
389 uint32_t dex_pc = deoptimize->GetDexPc();
390 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
391 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this);
392 }
393
394 private:
395 HInstruction* const instruction_;
396 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS64);
397};
398
399CodeGeneratorMIPS64::CodeGeneratorMIPS64(HGraph* graph,
400 const Mips64InstructionSetFeatures& isa_features,
401 const CompilerOptions& compiler_options)
402 : CodeGenerator(graph,
403 kNumberOfGpuRegisters,
404 kNumberOfFpuRegisters,
405 0, // kNumberOfRegisterPairs
406 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
407 arraysize(kCoreCalleeSaves)),
408 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
409 arraysize(kFpuCalleeSaves)),
410 compiler_options),
411 block_labels_(graph->GetArena(), 0),
412 location_builder_(graph, this),
413 instruction_visitor_(graph, this),
414 move_resolver_(graph->GetArena(), this),
415 isa_features_(isa_features) {
416 // Save RA (containing the return address) to mimic Quick.
417 AddAllocatedRegister(Location::RegisterLocation(RA));
418}
419
420#undef __
421#define __ down_cast<Mips64Assembler*>(GetAssembler())->
422#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64WordSize, x).Int32Value()
423
424void CodeGeneratorMIPS64::Finalize(CodeAllocator* allocator) {
425 CodeGenerator::Finalize(allocator);
426}
427
428Mips64Assembler* ParallelMoveResolverMIPS64::GetAssembler() const {
429 return codegen_->GetAssembler();
430}
431
432void ParallelMoveResolverMIPS64::EmitMove(size_t index) {
433 MoveOperands* move = moves_.Get(index);
434 codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType());
435}
436
437void ParallelMoveResolverMIPS64::EmitSwap(size_t index) {
438 MoveOperands* move = moves_.Get(index);
439 codegen_->SwapLocations(move->GetDestination(), move->GetSource(), move->GetType());
440}
441
442void ParallelMoveResolverMIPS64::RestoreScratch(int reg) {
443 // Pop reg
444 __ Ld(GpuRegister(reg), SP, 0);
445 __ DecreaseFrameSize(kMips64WordSize);
446}
447
448void ParallelMoveResolverMIPS64::SpillScratch(int reg) {
449 // Push reg
450 __ IncreaseFrameSize(kMips64WordSize);
451 __ Sd(GpuRegister(reg), SP, 0);
452}
453
454void ParallelMoveResolverMIPS64::Exchange(int index1, int index2, bool double_slot) {
455 LoadOperandType load_type = double_slot ? kLoadDoubleword : kLoadWord;
456 StoreOperandType store_type = double_slot ? kStoreDoubleword : kStoreWord;
457 // Allocate a scratch register other than TMP, if available.
458 // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be
459 // automatically unspilled when the scratch scope object is destroyed).
460 ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters());
461 // If V0 spills onto the stack, SP-relative offsets need to be adjusted.
462 int stack_offset = ensure_scratch.IsSpilled() ? kMips64WordSize : 0;
463 __ LoadFromOffset(load_type,
464 GpuRegister(ensure_scratch.GetRegister()),
465 SP,
466 index1 + stack_offset);
467 __ LoadFromOffset(load_type,
468 TMP,
469 SP,
470 index2 + stack_offset);
471 __ StoreToOffset(store_type,
472 GpuRegister(ensure_scratch.GetRegister()),
473 SP,
474 index2 + stack_offset);
475 __ StoreToOffset(store_type, TMP, SP, index1 + stack_offset);
476}
477
478static dwarf::Reg DWARFReg(GpuRegister reg) {
479 return dwarf::Reg::Mips64Core(static_cast<int>(reg));
480}
481
482// TODO: mapping of floating-point registers to DWARF
483
484void CodeGeneratorMIPS64::GenerateFrameEntry() {
485 __ Bind(&frame_entry_label_);
486
487 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips64) || !IsLeafMethod();
488
489 if (do_overflow_check) {
490 __ LoadFromOffset(kLoadWord,
491 ZERO,
492 SP,
493 -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips64)));
494 RecordPcInfo(nullptr, 0);
495 }
496
497 // TODO: anything related to T9/GP/GOT/PIC/.so's?
498
499 if (HasEmptyFrame()) {
500 return;
501 }
502
503 // Make sure the frame size isn't unreasonably large. Per the various APIs
504 // it looks like it should always be less than 2GB in size, which allows
505 // us using 32-bit signed offsets from the stack pointer.
506 if (GetFrameSize() > 0x7FFFFFFF)
507 LOG(FATAL) << "Stack frame larger than 2GB";
508
509 // Spill callee-saved registers.
510 // Note that their cumulative size is small and they can be indexed using
511 // 16-bit offsets.
512
513 // TODO: increment/decrement SP in one step instead of two or remove this comment.
514
515 uint32_t ofs = FrameEntrySpillSize();
516 __ IncreaseFrameSize(ofs);
517
518 for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) {
519 GpuRegister reg = kCoreCalleeSaves[i];
520 if (allocated_registers_.ContainsCoreRegister(reg)) {
521 ofs -= kMips64WordSize;
522 __ Sd(reg, SP, ofs);
523 __ cfi().RelOffset(DWARFReg(reg), ofs);
524 }
525 }
526
527 for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) {
528 FpuRegister reg = kFpuCalleeSaves[i];
529 if (allocated_registers_.ContainsFloatingPointRegister(reg)) {
530 ofs -= kMips64WordSize;
531 __ Sdc1(reg, SP, ofs);
532 // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs);
533 }
534 }
535
536 // Allocate the rest of the frame and store the current method pointer
537 // at its end.
538
539 __ IncreaseFrameSize(GetFrameSize() - FrameEntrySpillSize());
540
541 static_assert(IsInt<16>(kCurrentMethodStackOffset),
542 "kCurrentMethodStackOffset must fit into int16_t");
543 __ Sd(kMethodRegisterArgument, SP, kCurrentMethodStackOffset);
544}
545
546void CodeGeneratorMIPS64::GenerateFrameExit() {
547 __ cfi().RememberState();
548
549 // TODO: anything related to T9/GP/GOT/PIC/.so's?
550
551 if (!HasEmptyFrame()) {
552 // Deallocate the rest of the frame.
553
554 __ DecreaseFrameSize(GetFrameSize() - FrameEntrySpillSize());
555
556 // Restore callee-saved registers.
557 // Note that their cumulative size is small and they can be indexed using
558 // 16-bit offsets.
559
560 // TODO: increment/decrement SP in one step instead of two or remove this comment.
561
562 uint32_t ofs = 0;
563
564 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
565 FpuRegister reg = kFpuCalleeSaves[i];
566 if (allocated_registers_.ContainsFloatingPointRegister(reg)) {
567 __ Ldc1(reg, SP, ofs);
568 ofs += kMips64WordSize;
569 // TODO: __ cfi().Restore(DWARFReg(reg));
570 }
571 }
572
573 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
574 GpuRegister reg = kCoreCalleeSaves[i];
575 if (allocated_registers_.ContainsCoreRegister(reg)) {
576 __ Ld(reg, SP, ofs);
577 ofs += kMips64WordSize;
578 __ cfi().Restore(DWARFReg(reg));
579 }
580 }
581
582 DCHECK_EQ(ofs, FrameEntrySpillSize());
583 __ DecreaseFrameSize(ofs);
584 }
585
586 __ Jr(RA);
587
588 __ cfi().RestoreState();
589 __ cfi().DefCFAOffset(GetFrameSize());
590}
591
592void CodeGeneratorMIPS64::Bind(HBasicBlock* block) {
593 __ Bind(GetLabelOf(block));
594}
595
596void CodeGeneratorMIPS64::MoveLocation(Location destination,
597 Location source,
598 Primitive::Type type) {
599 if (source.Equals(destination)) {
600 return;
601 }
602
603 // A valid move can always be inferred from the destination and source
604 // locations. When moving from and to a register, the argument type can be
605 // used to generate 32bit instead of 64bit moves.
606 bool unspecified_type = (type == Primitive::kPrimVoid);
607 DCHECK_EQ(unspecified_type, false);
608
609 if (destination.IsRegister() || destination.IsFpuRegister()) {
610 if (unspecified_type) {
611 HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr;
612 if (source.IsStackSlot() ||
613 (src_cst != nullptr && (src_cst->IsIntConstant()
614 || src_cst->IsFloatConstant()
615 || src_cst->IsNullConstant()))) {
616 // For stack slots and 32bit constants, a 64bit type is appropriate.
617 type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat;
618 } else {
619 // If the source is a double stack slot or a 64bit constant, a 64bit
620 // type is appropriate. Else the source is a register, and since the
621 // type has not been specified, we chose a 64bit type to force a 64bit
622 // move.
623 type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble;
624 }
625 }
626 DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(type)) ||
627 (destination.IsRegister() && !Primitive::IsFloatingPointType(type)));
628 if (source.IsStackSlot() || source.IsDoubleStackSlot()) {
629 // Move to GPR/FPR from stack
630 LoadOperandType load_type = source.IsStackSlot() ? kLoadWord : kLoadDoubleword;
631 if (Primitive::IsFloatingPointType(type)) {
632 __ LoadFpuFromOffset(load_type,
633 destination.AsFpuRegister<FpuRegister>(),
634 SP,
635 source.GetStackIndex());
636 } else {
637 // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot.
638 __ LoadFromOffset(load_type,
639 destination.AsRegister<GpuRegister>(),
640 SP,
641 source.GetStackIndex());
642 }
643 } else if (source.IsConstant()) {
644 // Move to GPR/FPR from constant
645 GpuRegister gpr = AT;
646 if (!Primitive::IsFloatingPointType(type)) {
647 gpr = destination.AsRegister<GpuRegister>();
648 }
649 if (type == Primitive::kPrimInt || type == Primitive::kPrimFloat) {
650 __ LoadConst32(gpr, GetInt32ValueOf(source.GetConstant()->AsConstant()));
651 } else {
652 __ LoadConst64(gpr, GetInt64ValueOf(source.GetConstant()->AsConstant()));
653 }
654 if (type == Primitive::kPrimFloat) {
655 __ Mtc1(gpr, destination.AsFpuRegister<FpuRegister>());
656 } else if (type == Primitive::kPrimDouble) {
657 __ Dmtc1(gpr, destination.AsFpuRegister<FpuRegister>());
658 }
659 } else {
660 if (destination.IsRegister()) {
661 // Move to GPR from GPR
662 __ Move(destination.AsRegister<GpuRegister>(), source.AsRegister<GpuRegister>());
663 } else {
664 // Move to FPR from FPR
665 if (type == Primitive::kPrimFloat) {
666 __ MovS(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>());
667 } else {
668 DCHECK_EQ(type, Primitive::kPrimDouble);
669 __ MovD(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>());
670 }
671 }
672 }
673 } else { // The destination is not a register. It must be a stack slot.
674 DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot());
675 if (source.IsRegister() || source.IsFpuRegister()) {
676 if (unspecified_type) {
677 if (source.IsRegister()) {
678 type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong;
679 } else {
680 type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble;
681 }
682 }
683 DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(type)) &&
684 (source.IsFpuRegister() == Primitive::IsFloatingPointType(type)));
685 // Move to stack from GPR/FPR
686 StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword;
687 if (source.IsRegister()) {
688 __ StoreToOffset(store_type,
689 source.AsRegister<GpuRegister>(),
690 SP,
691 destination.GetStackIndex());
692 } else {
693 __ StoreFpuToOffset(store_type,
694 source.AsFpuRegister<FpuRegister>(),
695 SP,
696 destination.GetStackIndex());
697 }
698 } else if (source.IsConstant()) {
699 // Move to stack from constant
700 HConstant* src_cst = source.GetConstant();
701 StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword;
702 if (destination.IsStackSlot()) {
703 __ LoadConst32(TMP, GetInt32ValueOf(src_cst->AsConstant()));
704 } else {
705 __ LoadConst64(TMP, GetInt64ValueOf(src_cst->AsConstant()));
706 }
707 __ StoreToOffset(store_type, TMP, SP, destination.GetStackIndex());
708 } else {
709 DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot());
710 DCHECK_EQ(source.IsDoubleStackSlot(), destination.IsDoubleStackSlot());
711 // Move to stack from stack
712 if (destination.IsStackSlot()) {
713 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
714 __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex());
715 } else {
716 __ LoadFromOffset(kLoadDoubleword, TMP, SP, source.GetStackIndex());
717 __ StoreToOffset(kStoreDoubleword, TMP, SP, destination.GetStackIndex());
718 }
719 }
720 }
721}
722
723void CodeGeneratorMIPS64::SwapLocations(Location loc1,
724 Location loc2,
725 Primitive::Type type ATTRIBUTE_UNUSED) {
726 DCHECK(!loc1.IsConstant());
727 DCHECK(!loc2.IsConstant());
728
729 if (loc1.Equals(loc2)) {
730 return;
731 }
732
733 bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot();
734 bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot();
735 bool is_fp_reg1 = loc1.IsFpuRegister();
736 bool is_fp_reg2 = loc2.IsFpuRegister();
737
738 if (loc2.IsRegister() && loc1.IsRegister()) {
739 // Swap 2 GPRs
740 GpuRegister r1 = loc1.AsRegister<GpuRegister>();
741 GpuRegister r2 = loc2.AsRegister<GpuRegister>();
742 __ Move(TMP, r2);
743 __ Move(r2, r1);
744 __ Move(r1, TMP);
745 } else if (is_fp_reg2 && is_fp_reg1) {
746 // Swap 2 FPRs
747 FpuRegister r1 = loc1.AsFpuRegister<FpuRegister>();
748 FpuRegister r2 = loc2.AsFpuRegister<FpuRegister>();
749 // TODO: Can MOV.S/MOV.D be used here to save one instruction?
750 // Need to distinguish float from double, right?
751 __ Dmfc1(TMP, r2);
752 __ Dmfc1(AT, r1);
753 __ Dmtc1(TMP, r1);
754 __ Dmtc1(AT, r2);
755 } else if (is_slot1 != is_slot2) {
756 // Swap GPR/FPR and stack slot
757 Location reg_loc = is_slot1 ? loc2 : loc1;
758 Location mem_loc = is_slot1 ? loc1 : loc2;
759 LoadOperandType load_type = mem_loc.IsStackSlot() ? kLoadWord : kLoadDoubleword;
760 StoreOperandType store_type = mem_loc.IsStackSlot() ? kStoreWord : kStoreDoubleword;
761 // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot.
762 __ LoadFromOffset(load_type, TMP, SP, mem_loc.GetStackIndex());
763 if (reg_loc.IsFpuRegister()) {
764 __ StoreFpuToOffset(store_type,
765 reg_loc.AsFpuRegister<FpuRegister>(),
766 SP,
767 mem_loc.GetStackIndex());
768 // TODO: review this MTC1/DMTC1 move
769 if (mem_loc.IsStackSlot()) {
770 __ Mtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>());
771 } else {
772 DCHECK(mem_loc.IsDoubleStackSlot());
773 __ Dmtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>());
774 }
775 } else {
776 __ StoreToOffset(store_type, reg_loc.AsRegister<GpuRegister>(), SP, mem_loc.GetStackIndex());
777 __ Move(reg_loc.AsRegister<GpuRegister>(), TMP);
778 }
779 } else if (is_slot1 && is_slot2) {
780 move_resolver_.Exchange(loc1.GetStackIndex(),
781 loc2.GetStackIndex(),
782 loc1.IsDoubleStackSlot());
783 } else {
784 LOG(FATAL) << "Unimplemented swap between locations " << loc1 << " and " << loc2;
785 }
786}
787
788void CodeGeneratorMIPS64::Move(HInstruction* instruction,
789 Location location,
790 HInstruction* move_for) {
791 LocationSummary* locations = instruction->GetLocations();
792 Primitive::Type type = instruction->GetType();
793 DCHECK_NE(type, Primitive::kPrimVoid);
794
795 if (instruction->IsCurrentMethod()) {
796 MoveLocation(location, Location::DoubleStackSlot(kCurrentMethodStackOffset), type);
797 } else if (locations != nullptr && locations->Out().Equals(location)) {
798 return;
799 } else if (instruction->IsIntConstant()
800 || instruction->IsLongConstant()
801 || instruction->IsNullConstant()) {
802 if (location.IsRegister()) {
803 // Move to GPR from constant
804 GpuRegister dst = location.AsRegister<GpuRegister>();
805 if (instruction->IsNullConstant() || instruction->IsIntConstant()) {
806 __ LoadConst32(dst, GetInt32ValueOf(instruction->AsConstant()));
807 } else {
808 __ LoadConst64(dst, instruction->AsLongConstant()->GetValue());
809 }
810 } else {
811 DCHECK(location.IsStackSlot() || location.IsDoubleStackSlot());
812 // Move to stack from constant
813 if (location.IsStackSlot()) {
814 __ LoadConst32(TMP, GetInt32ValueOf(instruction->AsConstant()));
815 __ StoreToOffset(kStoreWord, TMP, SP, location.GetStackIndex());
816 } else {
817 __ LoadConst64(TMP, instruction->AsLongConstant()->GetValue());
818 __ StoreToOffset(kStoreDoubleword, TMP, SP, location.GetStackIndex());
819 }
820 }
821 } else if (instruction->IsTemporary()) {
822 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
823 MoveLocation(location, temp_location, type);
824 } else if (instruction->IsLoadLocal()) {
825 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
826 if (Primitive::Is64BitType(type)) {
827 MoveLocation(location, Location::DoubleStackSlot(stack_slot), type);
828 } else {
829 MoveLocation(location, Location::StackSlot(stack_slot), type);
830 }
831 } else {
832 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
833 MoveLocation(location, locations->Out(), type);
834 }
835}
836
837Location CodeGeneratorMIPS64::GetStackLocation(HLoadLocal* load) const {
838 Primitive::Type type = load->GetType();
839
840 switch (type) {
841 case Primitive::kPrimNot:
842 case Primitive::kPrimInt:
843 case Primitive::kPrimFloat:
844 return Location::StackSlot(GetStackSlot(load->GetLocal()));
845
846 case Primitive::kPrimLong:
847 case Primitive::kPrimDouble:
848 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
849
850 case Primitive::kPrimBoolean:
851 case Primitive::kPrimByte:
852 case Primitive::kPrimChar:
853 case Primitive::kPrimShort:
854 case Primitive::kPrimVoid:
855 LOG(FATAL) << "Unexpected type " << type;
856 }
857
858 LOG(FATAL) << "Unreachable";
859 return Location::NoLocation();
860}
861
862void CodeGeneratorMIPS64::MarkGCCard(GpuRegister object, GpuRegister value) {
863 Label done;
864 GpuRegister card = AT;
865 GpuRegister temp = TMP;
866 __ Beqzc(value, &done);
867 __ LoadFromOffset(kLoadDoubleword,
868 card,
869 TR,
870 Thread::CardTableOffset<kMips64WordSize>().Int32Value());
871 __ Dsrl(temp, object, gc::accounting::CardTable::kCardShift);
872 __ Daddu(temp, card, temp);
873 __ Sb(card, temp, 0);
874 __ Bind(&done);
875}
876
877void CodeGeneratorMIPS64::SetupBlockedRegisters(bool is_baseline ATTRIBUTE_UNUSED) const {
878 // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated.
879 blocked_core_registers_[ZERO] = true;
880 blocked_core_registers_[K0] = true;
881 blocked_core_registers_[K1] = true;
882 blocked_core_registers_[GP] = true;
883 blocked_core_registers_[SP] = true;
884 blocked_core_registers_[RA] = true;
885
886 // AT and TMP(T8) are used as temporary/scratch registers
887 // (similar to how AT is used by MIPS assemblers).
888 blocked_core_registers_[AT] = true;
889 blocked_core_registers_[TMP] = true;
890 blocked_fpu_registers_[FTMP] = true;
891
892 // Reserve suspend and thread registers.
893 blocked_core_registers_[S0] = true;
894 blocked_core_registers_[TR] = true;
895
896 // Reserve T9 for function calls
897 blocked_core_registers_[T9] = true;
898
899 // TODO: review; anything else?
900
901 // TODO: make these two for's conditional on is_baseline once
902 // all the issues with register saving/restoring are sorted out.
903 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
904 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
905 }
906
907 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
908 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
909 }
910}
911
912Location CodeGeneratorMIPS64::AllocateFreeRegister(Primitive::Type type) const {
913 if (type == Primitive::kPrimVoid) {
914 LOG(FATAL) << "Unreachable type " << type;
915 }
916
917 if (Primitive::IsFloatingPointType(type)) {
918 size_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfFpuRegisters);
919 return Location::FpuRegisterLocation(reg);
920 } else {
921 size_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfGpuRegisters);
922 return Location::RegisterLocation(reg);
923 }
924}
925
926size_t CodeGeneratorMIPS64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
927 __ StoreToOffset(kStoreDoubleword, GpuRegister(reg_id), SP, stack_index);
928 return kMips64WordSize;
929}
930
931size_t CodeGeneratorMIPS64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
932 __ LoadFromOffset(kLoadDoubleword, GpuRegister(reg_id), SP, stack_index);
933 return kMips64WordSize;
934}
935
936size_t CodeGeneratorMIPS64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
937 __ StoreFpuToOffset(kStoreDoubleword, FpuRegister(reg_id), SP, stack_index);
938 return kMips64WordSize;
939}
940
941size_t CodeGeneratorMIPS64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
942 __ LoadFpuFromOffset(kLoadDoubleword, FpuRegister(reg_id), SP, stack_index);
943 return kMips64WordSize;
944}
945
946void CodeGeneratorMIPS64::DumpCoreRegister(std::ostream& stream, int reg) const {
947 stream << Mips64ManagedRegister::FromGpuRegister(GpuRegister(reg));
948}
949
950void CodeGeneratorMIPS64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
951 stream << Mips64ManagedRegister::FromFpuRegister(FpuRegister(reg));
952}
953
954void CodeGeneratorMIPS64::InvokeRuntime(int32_t entry_point_offset,
955 HInstruction* instruction,
956 uint32_t dex_pc,
957 SlowPathCode* slow_path) {
958 // TODO: anything related to T9/GP/GOT/PIC/.so's?
959 __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset);
960 __ Jalr(T9);
961 RecordPcInfo(instruction, dex_pc, slow_path);
962 DCHECK(instruction->IsSuspendCheck()
963 || instruction->IsBoundsCheck()
964 || instruction->IsNullCheck()
965 || instruction->IsDivZeroCheck()
966 || !IsLeafMethod());
967}
968
969void InstructionCodeGeneratorMIPS64::GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path,
970 GpuRegister class_reg) {
971 __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value());
972 __ LoadConst32(AT, mirror::Class::kStatusInitialized);
973 __ Bltc(TMP, AT, slow_path->GetEntryLabel());
974 // TODO: barrier needed?
975 __ Bind(slow_path->GetExitLabel());
976}
977
978void InstructionCodeGeneratorMIPS64::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) {
979 __ Sync(0); // only stype 0 is supported
980}
981
982void InstructionCodeGeneratorMIPS64::GenerateSuspendCheck(HSuspendCheck* instruction,
983 HBasicBlock* successor) {
984 SuspendCheckSlowPathMIPS64* slow_path =
985 new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS64(instruction, successor);
986 codegen_->AddSlowPath(slow_path);
987
988 __ LoadFromOffset(kLoadUnsignedHalfword,
989 TMP,
990 TR,
991 Thread::ThreadFlagsOffset<kMips64WordSize>().Int32Value());
992 if (successor == nullptr) {
993 __ Bnezc(TMP, slow_path->GetEntryLabel());
994 __ Bind(slow_path->GetReturnLabel());
995 } else {
996 __ Beqzc(TMP, codegen_->GetLabelOf(successor));
997 __ B(slow_path->GetEntryLabel());
998 // slow_path will return to GetLabelOf(successor).
999 }
1000}
1001
1002InstructionCodeGeneratorMIPS64::InstructionCodeGeneratorMIPS64(HGraph* graph,
1003 CodeGeneratorMIPS64* codegen)
1004 : HGraphVisitor(graph),
1005 assembler_(codegen->GetAssembler()),
1006 codegen_(codegen) {}
1007
1008void LocationsBuilderMIPS64::HandleBinaryOp(HBinaryOperation* instruction) {
1009 DCHECK_EQ(instruction->InputCount(), 2U);
1010 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1011 Primitive::Type type = instruction->GetResultType();
1012 switch (type) {
1013 case Primitive::kPrimInt:
1014 case Primitive::kPrimLong: {
1015 locations->SetInAt(0, Location::RequiresRegister());
1016 HInstruction* right = instruction->InputAt(1);
1017 bool can_use_imm = false;
1018 if (right->IsConstant()) {
1019 int64_t imm = CodeGenerator::GetInt64ValueOf(right->AsConstant());
1020 if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) {
1021 can_use_imm = IsUint<16>(imm);
1022 } else if (instruction->IsAdd()) {
1023 can_use_imm = IsInt<16>(imm);
1024 } else {
1025 DCHECK(instruction->IsSub());
1026 can_use_imm = IsInt<16>(-imm);
1027 }
1028 }
1029 if (can_use_imm)
1030 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1031 else
1032 locations->SetInAt(1, Location::RequiresRegister());
1033 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1034 }
1035 break;
1036
1037 case Primitive::kPrimFloat:
1038 case Primitive::kPrimDouble:
1039 locations->SetInAt(0, Location::RequiresFpuRegister());
1040 locations->SetInAt(1, Location::RequiresFpuRegister());
1041 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1042 break;
1043
1044 default:
1045 LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type;
1046 }
1047}
1048
1049void InstructionCodeGeneratorMIPS64::HandleBinaryOp(HBinaryOperation* instruction) {
1050 Primitive::Type type = instruction->GetType();
1051 LocationSummary* locations = instruction->GetLocations();
1052
1053 switch (type) {
1054 case Primitive::kPrimInt:
1055 case Primitive::kPrimLong: {
1056 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1057 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1058 Location rhs_location = locations->InAt(1);
1059
1060 GpuRegister rhs_reg = ZERO;
1061 int64_t rhs_imm = 0;
1062 bool use_imm = rhs_location.IsConstant();
1063 if (use_imm) {
1064 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
1065 } else {
1066 rhs_reg = rhs_location.AsRegister<GpuRegister>();
1067 }
1068
1069 if (instruction->IsAnd()) {
1070 if (use_imm)
1071 __ Andi(dst, lhs, rhs_imm);
1072 else
1073 __ And(dst, lhs, rhs_reg);
1074 } else if (instruction->IsOr()) {
1075 if (use_imm)
1076 __ Ori(dst, lhs, rhs_imm);
1077 else
1078 __ Or(dst, lhs, rhs_reg);
1079 } else if (instruction->IsXor()) {
1080 if (use_imm)
1081 __ Xori(dst, lhs, rhs_imm);
1082 else
1083 __ Xor(dst, lhs, rhs_reg);
1084 } else if (instruction->IsAdd()) {
1085 if (type == Primitive::kPrimInt) {
1086 if (use_imm)
1087 __ Addiu(dst, lhs, rhs_imm);
1088 else
1089 __ Addu(dst, lhs, rhs_reg);
1090 } else {
1091 if (use_imm)
1092 __ Daddiu(dst, lhs, rhs_imm);
1093 else
1094 __ Daddu(dst, lhs, rhs_reg);
1095 }
1096 } else {
1097 DCHECK(instruction->IsSub());
1098 if (type == Primitive::kPrimInt) {
1099 if (use_imm)
1100 __ Addiu(dst, lhs, -rhs_imm);
1101 else
1102 __ Subu(dst, lhs, rhs_reg);
1103 } else {
1104 if (use_imm)
1105 __ Daddiu(dst, lhs, -rhs_imm);
1106 else
1107 __ Dsubu(dst, lhs, rhs_reg);
1108 }
1109 }
1110 break;
1111 }
1112 case Primitive::kPrimFloat:
1113 case Primitive::kPrimDouble: {
1114 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
1115 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
1116 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
1117 if (instruction->IsAdd()) {
1118 if (type == Primitive::kPrimFloat)
1119 __ AddS(dst, lhs, rhs);
1120 else
1121 __ AddD(dst, lhs, rhs);
1122 } else if (instruction->IsSub()) {
1123 if (type == Primitive::kPrimFloat)
1124 __ SubS(dst, lhs, rhs);
1125 else
1126 __ SubD(dst, lhs, rhs);
1127 } else {
1128 LOG(FATAL) << "Unexpected floating-point binary operation";
1129 }
1130 break;
1131 }
1132 default:
1133 LOG(FATAL) << "Unexpected binary operation type " << type;
1134 }
1135}
1136
1137void LocationsBuilderMIPS64::HandleShift(HBinaryOperation* instr) {
1138 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1139
1140 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1141 Primitive::Type type = instr->GetResultType();
1142 switch (type) {
1143 case Primitive::kPrimInt:
1144 case Primitive::kPrimLong: {
1145 locations->SetInAt(0, Location::RequiresRegister());
1146 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1147 locations->SetOut(Location::RequiresRegister());
1148 break;
1149 }
1150 default:
1151 LOG(FATAL) << "Unexpected shift type " << type;
1152 }
1153}
1154
1155void InstructionCodeGeneratorMIPS64::HandleShift(HBinaryOperation* instr) {
1156 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1157 LocationSummary* locations = instr->GetLocations();
1158 Primitive::Type type = instr->GetType();
1159
1160 switch (type) {
1161 case Primitive::kPrimInt:
1162 case Primitive::kPrimLong: {
1163 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1164 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1165 Location rhs_location = locations->InAt(1);
1166
1167 GpuRegister rhs_reg = ZERO;
1168 int64_t rhs_imm = 0;
1169 bool use_imm = rhs_location.IsConstant();
1170 if (use_imm) {
1171 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
1172 } else {
1173 rhs_reg = rhs_location.AsRegister<GpuRegister>();
1174 }
1175
1176 if (use_imm) {
1177 uint32_t shift_value = (type == Primitive::kPrimInt)
1178 ? static_cast<uint32_t>(rhs_imm & kMaxIntShiftValue)
1179 : static_cast<uint32_t>(rhs_imm & kMaxLongShiftValue);
1180
1181 if (type == Primitive::kPrimInt) {
1182 if (instr->IsShl()) {
1183 __ Sll(dst, lhs, shift_value);
1184 } else if (instr->IsShr()) {
1185 __ Sra(dst, lhs, shift_value);
1186 } else {
1187 __ Srl(dst, lhs, shift_value);
1188 }
1189 } else {
1190 if (shift_value < 32) {
1191 if (instr->IsShl()) {
1192 __ Dsll(dst, lhs, shift_value);
1193 } else if (instr->IsShr()) {
1194 __ Dsra(dst, lhs, shift_value);
1195 } else {
1196 __ Dsrl(dst, lhs, shift_value);
1197 }
1198 } else {
1199 shift_value -= 32;
1200 if (instr->IsShl()) {
1201 __ Dsll32(dst, lhs, shift_value);
1202 } else if (instr->IsShr()) {
1203 __ Dsra32(dst, lhs, shift_value);
1204 } else {
1205 __ Dsrl32(dst, lhs, shift_value);
1206 }
1207 }
1208 }
1209 } else {
1210 if (type == Primitive::kPrimInt) {
1211 if (instr->IsShl()) {
1212 __ Sllv(dst, lhs, rhs_reg);
1213 } else if (instr->IsShr()) {
1214 __ Srav(dst, lhs, rhs_reg);
1215 } else {
1216 __ Srlv(dst, lhs, rhs_reg);
1217 }
1218 } else {
1219 if (instr->IsShl()) {
1220 __ Dsllv(dst, lhs, rhs_reg);
1221 } else if (instr->IsShr()) {
1222 __ Dsrav(dst, lhs, rhs_reg);
1223 } else {
1224 __ Dsrlv(dst, lhs, rhs_reg);
1225 }
1226 }
1227 }
1228 break;
1229 }
1230 default:
1231 LOG(FATAL) << "Unexpected shift operation type " << type;
1232 }
1233}
1234
1235void LocationsBuilderMIPS64::VisitAdd(HAdd* instruction) {
1236 HandleBinaryOp(instruction);
1237}
1238
1239void InstructionCodeGeneratorMIPS64::VisitAdd(HAdd* instruction) {
1240 HandleBinaryOp(instruction);
1241}
1242
1243void LocationsBuilderMIPS64::VisitAnd(HAnd* instruction) {
1244 HandleBinaryOp(instruction);
1245}
1246
1247void InstructionCodeGeneratorMIPS64::VisitAnd(HAnd* instruction) {
1248 HandleBinaryOp(instruction);
1249}
1250
1251void LocationsBuilderMIPS64::VisitArrayGet(HArrayGet* instruction) {
1252 LocationSummary* locations =
1253 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1254 locations->SetInAt(0, Location::RequiresRegister());
1255 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1256 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1257 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1258 } else {
1259 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1260 }
1261}
1262
1263void InstructionCodeGeneratorMIPS64::VisitArrayGet(HArrayGet* instruction) {
1264 LocationSummary* locations = instruction->GetLocations();
1265 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1266 Location index = locations->InAt(1);
1267 Primitive::Type type = instruction->GetType();
1268
1269 switch (type) {
1270 case Primitive::kPrimBoolean: {
1271 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
1272 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1273 if (index.IsConstant()) {
1274 size_t offset =
1275 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1276 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1277 } else {
1278 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
1279 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset);
1280 }
1281 break;
1282 }
1283
1284 case Primitive::kPrimByte: {
1285 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
1286 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1287 if (index.IsConstant()) {
1288 size_t offset =
1289 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1290 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1291 } else {
1292 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
1293 __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset);
1294 }
1295 break;
1296 }
1297
1298 case Primitive::kPrimShort: {
1299 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
1300 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1301 if (index.IsConstant()) {
1302 size_t offset =
1303 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1304 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1305 } else {
1306 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2);
1307 __ Daddu(TMP, obj, TMP);
1308 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset);
1309 }
1310 break;
1311 }
1312
1313 case Primitive::kPrimChar: {
1314 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
1315 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1316 if (index.IsConstant()) {
1317 size_t offset =
1318 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1319 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1320 } else {
1321 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2);
1322 __ Daddu(TMP, obj, TMP);
1323 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset);
1324 }
1325 break;
1326 }
1327
1328 case Primitive::kPrimInt:
1329 case Primitive::kPrimNot: {
1330 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
1331 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
1332 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1333 LoadOperandType load_type = (type == Primitive::kPrimNot) ? kLoadUnsignedWord : kLoadWord;
1334 if (index.IsConstant()) {
1335 size_t offset =
1336 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1337 __ LoadFromOffset(load_type, out, obj, offset);
1338 } else {
1339 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1340 __ Daddu(TMP, obj, TMP);
1341 __ LoadFromOffset(load_type, out, TMP, data_offset);
1342 }
1343 break;
1344 }
1345
1346 case Primitive::kPrimLong: {
1347 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
1348 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1349 if (index.IsConstant()) {
1350 size_t offset =
1351 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1352 __ LoadFromOffset(kLoadDoubleword, out, obj, offset);
1353 } else {
1354 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1355 __ Daddu(TMP, obj, TMP);
1356 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset);
1357 }
1358 break;
1359 }
1360
1361 case Primitive::kPrimFloat: {
1362 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
1363 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
1364 if (index.IsConstant()) {
1365 size_t offset =
1366 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1367 __ LoadFpuFromOffset(kLoadWord, out, obj, offset);
1368 } else {
1369 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1370 __ Daddu(TMP, obj, TMP);
1371 __ LoadFpuFromOffset(kLoadWord, out, TMP, data_offset);
1372 }
1373 break;
1374 }
1375
1376 case Primitive::kPrimDouble: {
1377 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
1378 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
1379 if (index.IsConstant()) {
1380 size_t offset =
1381 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1382 __ LoadFpuFromOffset(kLoadDoubleword, out, obj, offset);
1383 } else {
1384 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1385 __ Daddu(TMP, obj, TMP);
1386 __ LoadFpuFromOffset(kLoadDoubleword, out, TMP, data_offset);
1387 }
1388 break;
1389 }
1390
1391 case Primitive::kPrimVoid:
1392 LOG(FATAL) << "Unreachable type " << instruction->GetType();
1393 UNREACHABLE();
1394 }
1395 codegen_->MaybeRecordImplicitNullCheck(instruction);
1396}
1397
1398void LocationsBuilderMIPS64::VisitArrayLength(HArrayLength* instruction) {
1399 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1400 locations->SetInAt(0, Location::RequiresRegister());
1401 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1402}
1403
1404void InstructionCodeGeneratorMIPS64::VisitArrayLength(HArrayLength* instruction) {
1405 LocationSummary* locations = instruction->GetLocations();
1406 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
1407 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1408 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1409 __ LoadFromOffset(kLoadWord, out, obj, offset);
1410 codegen_->MaybeRecordImplicitNullCheck(instruction);
1411}
1412
1413void LocationsBuilderMIPS64::VisitArraySet(HArraySet* instruction) {
1414 Primitive::Type value_type = instruction->GetComponentType();
1415 bool is_object = value_type == Primitive::kPrimNot;
1416 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1417 instruction,
1418 is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
1419 if (is_object) {
1420 InvokeRuntimeCallingConvention calling_convention;
1421 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1422 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1423 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1424 } else {
1425 locations->SetInAt(0, Location::RequiresRegister());
1426 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1427 if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
1428 locations->SetInAt(2, Location::RequiresFpuRegister());
1429 } else {
1430 locations->SetInAt(2, Location::RequiresRegister());
1431 }
1432 }
1433}
1434
1435void InstructionCodeGeneratorMIPS64::VisitArraySet(HArraySet* instruction) {
1436 LocationSummary* locations = instruction->GetLocations();
1437 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1438 Location index = locations->InAt(1);
1439 Primitive::Type value_type = instruction->GetComponentType();
1440 bool needs_runtime_call = locations->WillCall();
1441 bool needs_write_barrier =
1442 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
1443
1444 switch (value_type) {
1445 case Primitive::kPrimBoolean:
1446 case Primitive::kPrimByte: {
1447 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
1448 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1449 if (index.IsConstant()) {
1450 size_t offset =
1451 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1452 __ StoreToOffset(kStoreByte, value, obj, offset);
1453 } else {
1454 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
1455 __ StoreToOffset(kStoreByte, value, TMP, data_offset);
1456 }
1457 break;
1458 }
1459
1460 case Primitive::kPrimShort:
1461 case Primitive::kPrimChar: {
1462 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
1463 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1464 if (index.IsConstant()) {
1465 size_t offset =
1466 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1467 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1468 } else {
1469 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2);
1470 __ Daddu(TMP, obj, TMP);
1471 __ StoreToOffset(kStoreHalfword, value, TMP, data_offset);
1472 }
1473 break;
1474 }
1475
1476 case Primitive::kPrimInt:
1477 case Primitive::kPrimNot: {
1478 if (!needs_runtime_call) {
1479 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
1480 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1481 if (index.IsConstant()) {
1482 size_t offset =
1483 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1484 __ StoreToOffset(kStoreWord, value, obj, offset);
1485 } else {
1486 DCHECK(index.IsRegister()) << index;
1487 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1488 __ Daddu(TMP, obj, TMP);
1489 __ StoreToOffset(kStoreWord, value, TMP, data_offset);
1490 }
1491 codegen_->MaybeRecordImplicitNullCheck(instruction);
1492 if (needs_write_barrier) {
1493 DCHECK_EQ(value_type, Primitive::kPrimNot);
1494 codegen_->MarkGCCard(obj, value);
1495 }
1496 } else {
1497 DCHECK_EQ(value_type, Primitive::kPrimNot);
1498 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
1499 instruction,
1500 instruction->GetDexPc(),
1501 nullptr);
1502 }
1503 break;
1504 }
1505
1506 case Primitive::kPrimLong: {
1507 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
1508 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1509 if (index.IsConstant()) {
1510 size_t offset =
1511 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1512 __ StoreToOffset(kStoreDoubleword, value, obj, offset);
1513 } else {
1514 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1515 __ Daddu(TMP, obj, TMP);
1516 __ StoreToOffset(kStoreDoubleword, value, TMP, data_offset);
1517 }
1518 break;
1519 }
1520
1521 case Primitive::kPrimFloat: {
1522 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
1523 FpuRegister value = locations->InAt(2).AsFpuRegister<FpuRegister>();
1524 DCHECK(locations->InAt(2).IsFpuRegister());
1525 if (index.IsConstant()) {
1526 size_t offset =
1527 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1528 __ StoreFpuToOffset(kStoreWord, value, obj, offset);
1529 } else {
1530 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1531 __ Daddu(TMP, obj, TMP);
1532 __ StoreFpuToOffset(kStoreWord, value, TMP, data_offset);
1533 }
1534 break;
1535 }
1536
1537 case Primitive::kPrimDouble: {
1538 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
1539 FpuRegister value = locations->InAt(2).AsFpuRegister<FpuRegister>();
1540 DCHECK(locations->InAt(2).IsFpuRegister());
1541 if (index.IsConstant()) {
1542 size_t offset =
1543 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1544 __ StoreFpuToOffset(kStoreDoubleword, value, obj, offset);
1545 } else {
1546 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1547 __ Daddu(TMP, obj, TMP);
1548 __ StoreFpuToOffset(kStoreDoubleword, value, TMP, data_offset);
1549 }
1550 break;
1551 }
1552
1553 case Primitive::kPrimVoid:
1554 LOG(FATAL) << "Unreachable type " << instruction->GetType();
1555 UNREACHABLE();
1556 }
1557
1558 // Ints and objects are handled in the switch.
1559 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
1560 codegen_->MaybeRecordImplicitNullCheck(instruction);
1561 }
1562}
1563
1564void LocationsBuilderMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) {
1565 LocationSummary* locations =
1566 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1567 locations->SetInAt(0, Location::RequiresRegister());
1568 locations->SetInAt(1, Location::RequiresRegister());
1569 if (instruction->HasUses()) {
1570 locations->SetOut(Location::SameAsFirstInput());
1571 }
1572}
1573
1574void InstructionCodeGeneratorMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) {
1575 LocationSummary* locations = instruction->GetLocations();
1576 BoundsCheckSlowPathMIPS64* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS64(
1577 instruction,
1578 locations->InAt(0),
1579 locations->InAt(1));
1580 codegen_->AddSlowPath(slow_path);
1581
1582 GpuRegister index = locations->InAt(0).AsRegister<GpuRegister>();
1583 GpuRegister length = locations->InAt(1).AsRegister<GpuRegister>();
1584
1585 // length is limited by the maximum positive signed 32-bit integer.
1586 // Unsigned comparison of length and index checks for index < 0
1587 // and for length <= index simultaneously.
1588 // Mips R6 requires lhs != rhs for compact branches.
1589 if (index == length) {
1590 __ B(slow_path->GetEntryLabel());
1591 } else {
1592 __ Bgeuc(index, length, slow_path->GetEntryLabel());
1593 }
1594}
1595
1596void LocationsBuilderMIPS64::VisitCheckCast(HCheckCast* instruction) {
1597 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1598 instruction,
1599 LocationSummary::kCallOnSlowPath);
1600 locations->SetInAt(0, Location::RequiresRegister());
1601 locations->SetInAt(1, Location::RequiresRegister());
1602 locations->AddTemp(Location::RequiresRegister());
1603}
1604
1605void InstructionCodeGeneratorMIPS64::VisitCheckCast(HCheckCast* instruction) {
1606 LocationSummary* locations = instruction->GetLocations();
1607 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1608 GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>();
1609 GpuRegister obj_cls = locations->GetTemp(0).AsRegister<GpuRegister>();
1610
1611 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(
1612 instruction,
1613 locations->InAt(1),
1614 Location::RegisterLocation(obj_cls),
1615 instruction->GetDexPc());
1616 codegen_->AddSlowPath(slow_path);
1617
1618 // TODO: avoid this check if we know obj is not null.
1619 __ Beqzc(obj, slow_path->GetExitLabel());
1620 // Compare the class of `obj` with `cls`.
1621 __ LoadFromOffset(kLoadUnsignedWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value());
1622 __ Bnec(obj_cls, cls, slow_path->GetEntryLabel());
1623 __ Bind(slow_path->GetExitLabel());
1624}
1625
1626void LocationsBuilderMIPS64::VisitClinitCheck(HClinitCheck* check) {
1627 LocationSummary* locations =
1628 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
1629 locations->SetInAt(0, Location::RequiresRegister());
1630 if (check->HasUses()) {
1631 locations->SetOut(Location::SameAsFirstInput());
1632 }
1633}
1634
1635void InstructionCodeGeneratorMIPS64::VisitClinitCheck(HClinitCheck* check) {
1636 // We assume the class is not null.
1637 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64(
1638 check->GetLoadClass(),
1639 check,
1640 check->GetDexPc(),
1641 true);
1642 codegen_->AddSlowPath(slow_path);
1643 GenerateClassInitializationCheck(slow_path,
1644 check->GetLocations()->InAt(0).AsRegister<GpuRegister>());
1645}
1646
1647void LocationsBuilderMIPS64::VisitCompare(HCompare* compare) {
1648 Primitive::Type in_type = compare->InputAt(0)->GetType();
1649
1650 LocationSummary::CallKind call_kind = Primitive::IsFloatingPointType(in_type)
1651 ? LocationSummary::kCall
1652 : LocationSummary::kNoCall;
1653
1654 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(compare, call_kind);
1655
1656 switch (in_type) {
1657 case Primitive::kPrimLong:
1658 locations->SetInAt(0, Location::RequiresRegister());
1659 locations->SetInAt(1, Location::RequiresRegister());
1660 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1661 break;
1662
1663 case Primitive::kPrimFloat:
1664 case Primitive::kPrimDouble: {
1665 InvokeRuntimeCallingConvention calling_convention;
1666 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
1667 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
1668 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimInt));
1669 break;
1670 }
1671
1672 default:
1673 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
1674 }
1675}
1676
1677void InstructionCodeGeneratorMIPS64::VisitCompare(HCompare* instruction) {
1678 LocationSummary* locations = instruction->GetLocations();
1679 Primitive::Type in_type = instruction->InputAt(0)->GetType();
1680
1681 // 0 if: left == right
1682 // 1 if: left > right
1683 // -1 if: left < right
1684 switch (in_type) {
1685 case Primitive::kPrimLong: {
1686 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1687 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1688 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
1689 // TODO: more efficient (direct) comparison with a constant
1690 __ Slt(TMP, lhs, rhs);
1691 __ Slt(dst, rhs, lhs);
1692 __ Subu(dst, dst, TMP);
1693 break;
1694 }
1695
1696 case Primitive::kPrimFloat:
1697 case Primitive::kPrimDouble: {
1698 int32_t entry_point_offset;
1699 if (in_type == Primitive::kPrimFloat) {
1700 entry_point_offset = instruction->IsGtBias() ? QUICK_ENTRY_POINT(pCmpgFloat)
1701 : QUICK_ENTRY_POINT(pCmplFloat);
1702 } else {
1703 entry_point_offset = instruction->IsGtBias() ? QUICK_ENTRY_POINT(pCmpgDouble)
1704 : QUICK_ENTRY_POINT(pCmplDouble);
1705 }
1706 codegen_->InvokeRuntime(entry_point_offset, instruction, instruction->GetDexPc(), nullptr);
1707 break;
1708 }
1709
1710 default:
1711 LOG(FATAL) << "Unimplemented compare type " << in_type;
1712 }
1713}
1714
1715void LocationsBuilderMIPS64::VisitCondition(HCondition* instruction) {
1716 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1717 locations->SetInAt(0, Location::RequiresRegister());
1718 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1719 if (instruction->NeedsMaterialization()) {
1720 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1721 }
1722}
1723
1724void InstructionCodeGeneratorMIPS64::VisitCondition(HCondition* instruction) {
1725 if (!instruction->NeedsMaterialization()) {
1726 return;
1727 }
1728
1729 LocationSummary* locations = instruction->GetLocations();
1730
1731 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1732 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1733 Location rhs_location = locations->InAt(1);
1734
1735 GpuRegister rhs_reg = ZERO;
1736 int64_t rhs_imm = 0;
1737 bool use_imm = rhs_location.IsConstant();
1738 if (use_imm) {
1739 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
1740 } else {
1741 rhs_reg = rhs_location.AsRegister<GpuRegister>();
1742 }
1743
1744 IfCondition if_cond = instruction->GetCondition();
1745
1746 switch (if_cond) {
1747 case kCondEQ:
1748 case kCondNE:
1749 if (use_imm && IsUint<16>(rhs_imm)) {
1750 __ Xori(dst, lhs, rhs_imm);
1751 } else {
1752 if (use_imm) {
1753 rhs_reg = TMP;
1754 __ LoadConst32(rhs_reg, rhs_imm);
1755 }
1756 __ Xor(dst, lhs, rhs_reg);
1757 }
1758 if (if_cond == kCondEQ) {
1759 __ Sltiu(dst, dst, 1);
1760 } else {
1761 __ Sltu(dst, ZERO, dst);
1762 }
1763 break;
1764
1765 case kCondLT:
1766 case kCondGE:
1767 if (use_imm && IsInt<16>(rhs_imm)) {
1768 __ Slti(dst, lhs, rhs_imm);
1769 } else {
1770 if (use_imm) {
1771 rhs_reg = TMP;
1772 __ LoadConst32(rhs_reg, rhs_imm);
1773 }
1774 __ Slt(dst, lhs, rhs_reg);
1775 }
1776 if (if_cond == kCondGE) {
1777 // Simulate lhs >= rhs via !(lhs < rhs) since there's
1778 // only the slt instruction but no sge.
1779 __ Xori(dst, dst, 1);
1780 }
1781 break;
1782
1783 case kCondLE:
1784 case kCondGT:
1785 if (use_imm && IsInt<16>(rhs_imm + 1)) {
1786 // Simulate lhs <= rhs via lhs < rhs + 1.
1787 __ Slti(dst, lhs, rhs_imm + 1);
1788 if (if_cond == kCondGT) {
1789 // Simulate lhs > rhs via !(lhs <= rhs) since there's
1790 // only the slti instruction but no sgti.
1791 __ Xori(dst, dst, 1);
1792 }
1793 } else {
1794 if (use_imm) {
1795 rhs_reg = TMP;
1796 __ LoadConst32(rhs_reg, rhs_imm);
1797 }
1798 __ Slt(dst, rhs_reg, lhs);
1799 if (if_cond == kCondLE) {
1800 // Simulate lhs <= rhs via !(rhs < lhs) since there's
1801 // only the slt instruction but no sle.
1802 __ Xori(dst, dst, 1);
1803 }
1804 }
1805 break;
1806 }
1807}
1808
1809void LocationsBuilderMIPS64::VisitDiv(HDiv* div) {
1810 LocationSummary* locations =
1811 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1812 switch (div->GetResultType()) {
1813 case Primitive::kPrimInt:
1814 case Primitive::kPrimLong:
1815 locations->SetInAt(0, Location::RequiresRegister());
1816 locations->SetInAt(1, Location::RequiresRegister());
1817 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1818 break;
1819
1820 case Primitive::kPrimFloat:
1821 case Primitive::kPrimDouble:
1822 locations->SetInAt(0, Location::RequiresFpuRegister());
1823 locations->SetInAt(1, Location::RequiresFpuRegister());
1824 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1825 break;
1826
1827 default:
1828 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1829 }
1830}
1831
1832void InstructionCodeGeneratorMIPS64::VisitDiv(HDiv* instruction) {
1833 Primitive::Type type = instruction->GetType();
1834 LocationSummary* locations = instruction->GetLocations();
1835
1836 switch (type) {
1837 case Primitive::kPrimInt:
1838 case Primitive::kPrimLong: {
1839 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1840 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1841 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
1842 if (type == Primitive::kPrimInt)
1843 __ DivR6(dst, lhs, rhs);
1844 else
1845 __ Ddiv(dst, lhs, rhs);
1846 break;
1847 }
1848 case Primitive::kPrimFloat:
1849 case Primitive::kPrimDouble: {
1850 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
1851 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
1852 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
1853 if (type == Primitive::kPrimFloat)
1854 __ DivS(dst, lhs, rhs);
1855 else
1856 __ DivD(dst, lhs, rhs);
1857 break;
1858 }
1859 default:
1860 LOG(FATAL) << "Unexpected div type " << type;
1861 }
1862}
1863
1864void LocationsBuilderMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1865 LocationSummary* locations =
1866 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1867 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
1868 if (instruction->HasUses()) {
1869 locations->SetOut(Location::SameAsFirstInput());
1870 }
1871}
1872
1873void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1874 SlowPathCodeMIPS64* slow_path =
1875 new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS64(instruction);
1876 codegen_->AddSlowPath(slow_path);
1877 Location value = instruction->GetLocations()->InAt(0);
1878
1879 Primitive::Type type = instruction->GetType();
1880
1881 if ((type != Primitive::kPrimInt) && (type != Primitive::kPrimLong)) {
1882 LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck.";
1883 }
1884
1885 if (value.IsConstant()) {
1886 int64_t divisor = codegen_->GetInt64ValueOf(value.GetConstant()->AsConstant());
1887 if (divisor == 0) {
1888 __ B(slow_path->GetEntryLabel());
1889 } else {
1890 // A division by a non-null constant is valid. We don't need to perform
1891 // any check, so simply fall through.
1892 }
1893 } else {
1894 __ Beqzc(value.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
1895 }
1896}
1897
1898void LocationsBuilderMIPS64::VisitDoubleConstant(HDoubleConstant* constant) {
1899 LocationSummary* locations =
1900 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1901 locations->SetOut(Location::ConstantLocation(constant));
1902}
1903
1904void InstructionCodeGeneratorMIPS64::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) {
1905 // Will be generated at use site.
1906}
1907
1908void LocationsBuilderMIPS64::VisitExit(HExit* exit) {
1909 exit->SetLocations(nullptr);
1910}
1911
1912void InstructionCodeGeneratorMIPS64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
1913}
1914
1915void LocationsBuilderMIPS64::VisitFloatConstant(HFloatConstant* constant) {
1916 LocationSummary* locations =
1917 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1918 locations->SetOut(Location::ConstantLocation(constant));
1919}
1920
1921void InstructionCodeGeneratorMIPS64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
1922 // Will be generated at use site.
1923}
1924
1925void LocationsBuilderMIPS64::VisitGoto(HGoto* got) {
1926 got->SetLocations(nullptr);
1927}
1928
1929void InstructionCodeGeneratorMIPS64::VisitGoto(HGoto* got) {
1930 HBasicBlock* successor = got->GetSuccessor();
1931 DCHECK(!successor->IsExitBlock());
1932 HBasicBlock* block = got->GetBlock();
1933 HInstruction* previous = got->GetPrevious();
1934 HLoopInformation* info = block->GetLoopInformation();
1935
1936 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
1937 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1938 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1939 return;
1940 }
1941 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1942 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1943 }
1944 if (!codegen_->GoesToNextBlock(block, successor)) {
1945 __ B(codegen_->GetLabelOf(successor));
1946 }
1947}
1948
1949void InstructionCodeGeneratorMIPS64::GenerateTestAndBranch(HInstruction* instruction,
1950 Label* true_target,
1951 Label* false_target,
1952 Label* always_true_target) {
1953 HInstruction* cond = instruction->InputAt(0);
1954 HCondition* condition = cond->AsCondition();
1955
1956 if (cond->IsIntConstant()) {
1957 int32_t cond_value = cond->AsIntConstant()->GetValue();
1958 if (cond_value == 1) {
1959 if (always_true_target != nullptr) {
1960 __ B(always_true_target);
1961 }
1962 return;
1963 } else {
1964 DCHECK_EQ(cond_value, 0);
1965 }
1966 } else if (!cond->IsCondition() || condition->NeedsMaterialization()) {
1967 // The condition instruction has been materialized, compare the output to 0.
1968 Location cond_val = instruction->GetLocations()->InAt(0);
1969 DCHECK(cond_val.IsRegister());
1970 __ Bnezc(cond_val.AsRegister<GpuRegister>(), true_target);
1971 } else {
1972 // The condition instruction has not been materialized, use its inputs as
1973 // the comparison and its condition as the branch condition.
1974 GpuRegister lhs = condition->GetLocations()->InAt(0).AsRegister<GpuRegister>();
1975 Location rhs_location = condition->GetLocations()->InAt(1);
1976 GpuRegister rhs_reg = ZERO;
1977 int32_t rhs_imm = 0;
1978 bool use_imm = rhs_location.IsConstant();
1979 if (use_imm) {
1980 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
1981 } else {
1982 rhs_reg = rhs_location.AsRegister<GpuRegister>();
1983 }
1984
1985 IfCondition if_cond = condition->GetCondition();
1986 if (use_imm && rhs_imm == 0) {
1987 switch (if_cond) {
1988 case kCondEQ:
1989 __ Beqzc(lhs, true_target);
1990 break;
1991 case kCondNE:
1992 __ Bnezc(lhs, true_target);
1993 break;
1994 case kCondLT:
1995 __ Bltzc(lhs, true_target);
1996 break;
1997 case kCondGE:
1998 __ Bgezc(lhs, true_target);
1999 break;
2000 case kCondLE:
2001 __ Blezc(lhs, true_target);
2002 break;
2003 case kCondGT:
2004 __ Bgtzc(lhs, true_target);
2005 break;
2006 }
2007 } else {
2008 if (use_imm) {
2009 rhs_reg = TMP;
2010 __ LoadConst32(rhs_reg, rhs_imm);
2011 }
2012 // It looks like we can get here with lhs == rhs. Should that be possible at all?
2013 // Mips R6 requires lhs != rhs for compact branches.
2014 if (lhs == rhs_reg) {
2015 DCHECK(!use_imm);
2016 switch (if_cond) {
2017 case kCondEQ:
2018 case kCondGE:
2019 case kCondLE:
2020 // if lhs == rhs for a positive condition, then it is a branch
2021 __ B(true_target);
2022 break;
2023 case kCondNE:
2024 case kCondLT:
2025 case kCondGT:
2026 // if lhs == rhs for a negative condition, then it is a NOP
2027 break;
2028 }
2029 } else {
2030 switch (if_cond) {
2031 case kCondEQ:
2032 __ Beqc(lhs, rhs_reg, true_target);
2033 break;
2034 case kCondNE:
2035 __ Bnec(lhs, rhs_reg, true_target);
2036 break;
2037 case kCondLT:
2038 __ Bltc(lhs, rhs_reg, true_target);
2039 break;
2040 case kCondGE:
2041 __ Bgec(lhs, rhs_reg, true_target);
2042 break;
2043 case kCondLE:
2044 __ Bgec(rhs_reg, lhs, true_target);
2045 break;
2046 case kCondGT:
2047 __ Bltc(rhs_reg, lhs, true_target);
2048 break;
2049 }
2050 }
2051 }
2052 }
2053 if (false_target != nullptr) {
2054 __ B(false_target);
2055 }
2056}
2057
2058void LocationsBuilderMIPS64::VisitIf(HIf* if_instr) {
2059 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
2060 HInstruction* cond = if_instr->InputAt(0);
2061 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
2062 locations->SetInAt(0, Location::RequiresRegister());
2063 }
2064}
2065
2066void InstructionCodeGeneratorMIPS64::VisitIf(HIf* if_instr) {
2067 Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
2068 Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
2069 Label* always_true_target = true_target;
2070 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
2071 if_instr->IfTrueSuccessor())) {
2072 always_true_target = nullptr;
2073 }
2074 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
2075 if_instr->IfFalseSuccessor())) {
2076 false_target = nullptr;
2077 }
2078 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
2079}
2080
2081void LocationsBuilderMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) {
2082 LocationSummary* locations = new (GetGraph()->GetArena())
2083 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
2084 HInstruction* cond = deoptimize->InputAt(0);
2085 DCHECK(cond->IsCondition());
2086 if (cond->AsCondition()->NeedsMaterialization()) {
2087 locations->SetInAt(0, Location::RequiresRegister());
2088 }
2089}
2090
2091void InstructionCodeGeneratorMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) {
2092 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena())
2093 DeoptimizationSlowPathMIPS64(deoptimize);
2094 codegen_->AddSlowPath(slow_path);
2095 Label* slow_path_entry = slow_path->GetEntryLabel();
2096 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
2097}
2098
2099void LocationsBuilderMIPS64::HandleFieldGet(HInstruction* instruction,
2100 const FieldInfo& field_info ATTRIBUTE_UNUSED) {
2101 LocationSummary* locations =
2102 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2103 locations->SetInAt(0, Location::RequiresRegister());
2104 if (Primitive::IsFloatingPointType(instruction->GetType())) {
2105 locations->SetOut(Location::RequiresFpuRegister());
2106 } else {
2107 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2108 }
2109}
2110
2111void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction,
2112 const FieldInfo& field_info) {
2113 Primitive::Type type = field_info.GetFieldType();
2114 LocationSummary* locations = instruction->GetLocations();
2115 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2116 LoadOperandType load_type = kLoadUnsignedByte;
2117 switch (type) {
2118 case Primitive::kPrimBoolean:
2119 load_type = kLoadUnsignedByte;
2120 break;
2121 case Primitive::kPrimByte:
2122 load_type = kLoadSignedByte;
2123 break;
2124 case Primitive::kPrimShort:
2125 load_type = kLoadSignedHalfword;
2126 break;
2127 case Primitive::kPrimChar:
2128 load_type = kLoadUnsignedHalfword;
2129 break;
2130 case Primitive::kPrimInt:
2131 case Primitive::kPrimFloat:
2132 load_type = kLoadWord;
2133 break;
2134 case Primitive::kPrimLong:
2135 case Primitive::kPrimDouble:
2136 load_type = kLoadDoubleword;
2137 break;
2138 case Primitive::kPrimNot:
2139 load_type = kLoadUnsignedWord;
2140 break;
2141 case Primitive::kPrimVoid:
2142 LOG(FATAL) << "Unreachable type " << type;
2143 UNREACHABLE();
2144 }
2145 if (!Primitive::IsFloatingPointType(type)) {
2146 DCHECK(locations->Out().IsRegister());
2147 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2148 __ LoadFromOffset(load_type, dst, obj, field_info.GetFieldOffset().Uint32Value());
2149 } else {
2150 DCHECK(locations->Out().IsFpuRegister());
2151 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
2152 __ LoadFpuFromOffset(load_type, dst, obj, field_info.GetFieldOffset().Uint32Value());
2153 }
2154
2155 codegen_->MaybeRecordImplicitNullCheck(instruction);
2156 // TODO: memory barrier?
2157}
2158
2159void LocationsBuilderMIPS64::HandleFieldSet(HInstruction* instruction,
2160 const FieldInfo& field_info ATTRIBUTE_UNUSED) {
2161 LocationSummary* locations =
2162 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2163 locations->SetInAt(0, Location::RequiresRegister());
2164 if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) {
2165 locations->SetInAt(1, Location::RequiresFpuRegister());
2166 } else {
2167 locations->SetInAt(1, Location::RequiresRegister());
2168 }
2169}
2170
2171void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction,
2172 const FieldInfo& field_info) {
2173 Primitive::Type type = field_info.GetFieldType();
2174 LocationSummary* locations = instruction->GetLocations();
2175 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2176 StoreOperandType store_type = kStoreByte;
2177 switch (type) {
2178 case Primitive::kPrimBoolean:
2179 case Primitive::kPrimByte:
2180 store_type = kStoreByte;
2181 break;
2182 case Primitive::kPrimShort:
2183 case Primitive::kPrimChar:
2184 store_type = kStoreHalfword;
2185 break;
2186 case Primitive::kPrimInt:
2187 case Primitive::kPrimFloat:
2188 case Primitive::kPrimNot:
2189 store_type = kStoreWord;
2190 break;
2191 case Primitive::kPrimLong:
2192 case Primitive::kPrimDouble:
2193 store_type = kStoreDoubleword;
2194 break;
2195 case Primitive::kPrimVoid:
2196 LOG(FATAL) << "Unreachable type " << type;
2197 UNREACHABLE();
2198 }
2199 if (!Primitive::IsFloatingPointType(type)) {
2200 DCHECK(locations->InAt(1).IsRegister());
2201 GpuRegister src = locations->InAt(1).AsRegister<GpuRegister>();
2202 __ StoreToOffset(store_type, src, obj, field_info.GetFieldOffset().Uint32Value());
2203 } else {
2204 DCHECK(locations->InAt(1).IsFpuRegister());
2205 FpuRegister src = locations->InAt(1).AsFpuRegister<FpuRegister>();
2206 __ StoreFpuToOffset(store_type, src, obj, field_info.GetFieldOffset().Uint32Value());
2207 }
2208
2209 codegen_->MaybeRecordImplicitNullCheck(instruction);
2210 // TODO: memory barriers?
2211 if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) {
2212 DCHECK(locations->InAt(1).IsRegister());
2213 GpuRegister src = locations->InAt(1).AsRegister<GpuRegister>();
2214 codegen_->MarkGCCard(obj, src);
2215 }
2216}
2217
2218void LocationsBuilderMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2219 HandleFieldGet(instruction, instruction->GetFieldInfo());
2220}
2221
2222void InstructionCodeGeneratorMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2223 HandleFieldGet(instruction, instruction->GetFieldInfo());
2224}
2225
2226void LocationsBuilderMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2227 HandleFieldSet(instruction, instruction->GetFieldInfo());
2228}
2229
2230void InstructionCodeGeneratorMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2231 HandleFieldSet(instruction, instruction->GetFieldInfo());
2232}
2233
2234void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) {
2235 LocationSummary::CallKind call_kind =
2236 instruction->IsClassFinal() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
2237 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
2238 locations->SetInAt(0, Location::RequiresRegister());
2239 locations->SetInAt(1, Location::RequiresRegister());
2240 // The output does overlap inputs.
2241 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
2242}
2243
2244void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) {
2245 LocationSummary* locations = instruction->GetLocations();
2246 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2247 GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>();
2248 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2249
2250 Label done;
2251
2252 // Return 0 if `obj` is null.
2253 // TODO: Avoid this check if we know `obj` is not null.
2254 __ Move(out, ZERO);
2255 __ Beqzc(obj, &done);
2256
2257 // Compare the class of `obj` with `cls`.
2258 __ LoadFromOffset(kLoadUnsignedWord, out, obj, mirror::Object::ClassOffset().Int32Value());
2259 if (instruction->IsClassFinal()) {
2260 // Classes must be equal for the instanceof to succeed.
2261 __ Xor(out, out, cls);
2262 __ Sltiu(out, out, 1);
2263 } else {
2264 // If the classes are not equal, we go into a slow path.
2265 DCHECK(locations->OnlyCallsOnSlowPath());
2266 SlowPathCodeMIPS64* slow_path =
2267 new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction,
2268 locations->InAt(1),
2269 locations->Out(),
2270 instruction->GetDexPc());
2271 codegen_->AddSlowPath(slow_path);
2272 __ Bnec(out, cls, slow_path->GetEntryLabel());
2273 __ LoadConst32(out, 1);
2274 __ Bind(slow_path->GetExitLabel());
2275 }
2276
2277 __ Bind(&done);
2278}
2279
2280void LocationsBuilderMIPS64::VisitIntConstant(HIntConstant* constant) {
2281 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2282 locations->SetOut(Location::ConstantLocation(constant));
2283}
2284
2285void InstructionCodeGeneratorMIPS64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
2286 // Will be generated at use site.
2287}
2288
2289void LocationsBuilderMIPS64::VisitNullConstant(HNullConstant* constant) {
2290 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2291 locations->SetOut(Location::ConstantLocation(constant));
2292}
2293
2294void InstructionCodeGeneratorMIPS64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
2295 // Will be generated at use site.
2296}
2297
2298void LocationsBuilderMIPS64::HandleInvoke(HInvoke* invoke) {
2299 InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor;
2300 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
2301}
2302
2303void LocationsBuilderMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) {
2304 HandleInvoke(invoke);
2305 // The register T0 is required to be used for the hidden argument in
2306 // art_quick_imt_conflict_trampoline, so add the hidden argument.
2307 invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0));
2308}
2309
2310void InstructionCodeGeneratorMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) {
2311 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
2312 GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>();
2313 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
2314 invoke->GetImtIndex() % mirror::Class::kImtSize, kMips64PointerSize).Uint32Value();
2315 Location receiver = invoke->GetLocations()->InAt(0);
2316 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2317 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64WordSize);
2318
2319 // Set the hidden argument.
2320 __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<GpuRegister>(),
2321 invoke->GetDexMethodIndex());
2322
2323 // temp = object->GetClass();
2324 if (receiver.IsStackSlot()) {
2325 __ LoadFromOffset(kLoadUnsignedWord, temp, SP, receiver.GetStackIndex());
2326 __ LoadFromOffset(kLoadUnsignedWord, temp, temp, class_offset);
2327 } else {
2328 __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset);
2329 }
2330 codegen_->MaybeRecordImplicitNullCheck(invoke);
2331 // temp = temp->GetImtEntryAt(method_offset);
2332 __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset);
2333 // T9 = temp->GetEntryPoint();
2334 __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value());
2335 // T9();
2336 __ Jalr(T9);
2337 DCHECK(!codegen_->IsLeafMethod());
2338 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2339}
2340
2341void LocationsBuilderMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
2342 // TODO intrinsic function
2343 HandleInvoke(invoke);
2344}
2345
2346void LocationsBuilderMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
2347 // When we do not run baseline, explicit clinit checks triggered by static
2348 // invokes must have been pruned by art::PrepareForRegisterAllocation.
2349 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
2350
2351 // TODO - intrinsic function
2352 HandleInvoke(invoke);
2353
2354 // While SetupBlockedRegisters() blocks registers S2-S8 due to their
2355 // clobbering somewhere else, reduce further register pressure by avoiding
2356 // allocation of a register for the current method pointer like on x86 baseline.
2357 // TODO: remove this once all the issues with register saving/restoring are
2358 // sorted out.
2359 LocationSummary* locations = invoke->GetLocations();
2360 Location location = locations->InAt(invoke->GetCurrentMethodInputIndex());
2361 if (location.IsUnallocated() && location.GetPolicy() == Location::kRequiresRegister) {
2362 locations->SetInAt(invoke->GetCurrentMethodInputIndex(), Location::NoLocation());
2363 }
2364}
2365
2366static bool TryGenerateIntrinsicCode(HInvoke* invoke,
2367 CodeGeneratorMIPS64* codegen ATTRIBUTE_UNUSED) {
2368 if (invoke->GetLocations()->Intrinsified()) {
2369 // TODO - intrinsic function
2370 return true;
2371 }
2372 return false;
2373}
2374
2375void CodeGeneratorMIPS64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
2376 // All registers are assumed to be correctly set up per the calling convention.
2377
2378 // TODO: Implement all kinds of calls:
2379 // 1) boot -> boot
2380 // 2) app -> boot
2381 // 3) app -> app
2382 //
2383 // Currently we implement the app -> app logic, which looks up in the resolve cache.
2384
2385 if (invoke->IsStringInit()) {
2386 GpuRegister reg = temp.AsRegister<GpuRegister>();
2387 // temp = thread->string_init_entrypoint
2388 __ LoadFromOffset(kLoadDoubleword,
2389 reg,
2390 TR,
2391 invoke->GetStringInitOffset());
2392 // T9 = temp->entry_point_from_quick_compiled_code_;
2393 __ LoadFromOffset(kLoadDoubleword,
2394 T9,
2395 reg,
2396 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
2397 kMips64WordSize).Int32Value());
2398 // T9()
2399 __ Jalr(T9);
2400 } else if (invoke->IsRecursive()) {
2401 __ Jalr(&frame_entry_label_, T9);
2402 } else {
2403 Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
2404 GpuRegister reg = temp.AsRegister<GpuRegister>();
2405 GpuRegister method_reg;
2406 if (current_method.IsRegister()) {
2407 method_reg = current_method.AsRegister<GpuRegister>();
2408 } else {
2409 // TODO: use the appropriate DCHECK() here if possible.
2410 // DCHECK(invoke->GetLocations()->Intrinsified());
2411 DCHECK(!current_method.IsValid());
2412 method_reg = reg;
2413 __ Ld(reg, SP, kCurrentMethodStackOffset);
2414 }
2415
2416 // temp = temp->dex_cache_resolved_methods_;
2417 __ LoadFromOffset(kLoadUnsignedWord,
2418 reg,
2419 method_reg,
2420 ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
2421 // temp = temp[index_in_cache]
2422 __ LoadFromOffset(kLoadDoubleword,
2423 reg,
2424 reg,
2425 CodeGenerator::GetCachePointerOffset(invoke->GetDexMethodIndex()));
2426 // T9 = temp[offset_of_quick_compiled_code]
2427 __ LoadFromOffset(kLoadDoubleword,
2428 T9,
2429 reg,
2430 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
2431 kMips64WordSize).Int32Value());
2432 // T9()
2433 __ Jalr(T9);
2434 }
2435
2436 DCHECK(!IsLeafMethod());
2437}
2438
2439void InstructionCodeGeneratorMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
2440 // When we do not run baseline, explicit clinit checks triggered by static
2441 // invokes must have been pruned by art::PrepareForRegisterAllocation.
2442 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
2443
2444 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2445 return;
2446 }
2447
2448 LocationSummary* locations = invoke->GetLocations();
2449 codegen_->GenerateStaticOrDirectCall(invoke,
2450 locations->HasTemps()
2451 ? locations->GetTemp(0)
2452 : Location::NoLocation());
2453 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2454}
2455
2456void InstructionCodeGeneratorMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
2457 // TODO: Try to generate intrinsics code.
2458 LocationSummary* locations = invoke->GetLocations();
2459 Location receiver = locations->InAt(0);
2460 GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>();
2461 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
2462 invoke->GetVTableIndex(), kMips64PointerSize).SizeValue();
2463 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2464 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64WordSize);
2465
2466 // temp = object->GetClass();
2467 DCHECK(receiver.IsRegister());
2468 __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset);
2469 codegen_->MaybeRecordImplicitNullCheck(invoke);
2470 // temp = temp->GetMethodAt(method_offset);
2471 __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset);
2472 // T9 = temp->GetEntryPoint();
2473 __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value());
2474 // T9();
2475 __ Jalr(T9);
2476 DCHECK(!codegen_->IsLeafMethod());
2477 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2478}
2479
2480void LocationsBuilderMIPS64::VisitLoadClass(HLoadClass* cls) {
2481 LocationSummary::CallKind call_kind = cls->CanCallRuntime() ? LocationSummary::kCallOnSlowPath
2482 : LocationSummary::kNoCall;
2483 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
2484 locations->SetInAt(0, Location::RequiresRegister());
2485 locations->SetOut(Location::RequiresRegister());
2486}
2487
2488void InstructionCodeGeneratorMIPS64::VisitLoadClass(HLoadClass* cls) {
2489 LocationSummary* locations = cls->GetLocations();
2490 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2491 GpuRegister current_method = locations->InAt(0).AsRegister<GpuRegister>();
2492 if (cls->IsReferrersClass()) {
2493 DCHECK(!cls->CanCallRuntime());
2494 DCHECK(!cls->MustGenerateClinitCheck());
2495 __ LoadFromOffset(kLoadUnsignedWord, out, current_method,
2496 ArtMethod::DeclaringClassOffset().Int32Value());
2497 } else {
2498 DCHECK(cls->CanCallRuntime());
2499 __ LoadFromOffset(kLoadUnsignedWord, out, current_method,
2500 ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
2501 __ LoadFromOffset(kLoadUnsignedWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
2502 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64(
2503 cls,
2504 cls,
2505 cls->GetDexPc(),
2506 cls->MustGenerateClinitCheck());
2507 codegen_->AddSlowPath(slow_path);
2508 __ Beqzc(out, slow_path->GetEntryLabel());
2509 if (cls->MustGenerateClinitCheck()) {
2510 GenerateClassInitializationCheck(slow_path, out);
2511 } else {
2512 __ Bind(slow_path->GetExitLabel());
2513 }
2514 }
2515}
2516
2517void LocationsBuilderMIPS64::VisitLoadException(HLoadException* load) {
2518 LocationSummary* locations =
2519 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2520 locations->SetOut(Location::RequiresRegister());
2521}
2522
2523void InstructionCodeGeneratorMIPS64::VisitLoadException(HLoadException* load) {
2524 GpuRegister out = load->GetLocations()->Out().AsRegister<GpuRegister>();
2525 __ LoadFromOffset(kLoadUnsignedWord, out, TR, Thread::ExceptionOffset<kMips64WordSize>().Int32Value());
2526 __ StoreToOffset(kStoreWord, ZERO, TR, Thread::ExceptionOffset<kMips64WordSize>().Int32Value());
2527}
2528
2529void LocationsBuilderMIPS64::VisitLoadLocal(HLoadLocal* load) {
2530 load->SetLocations(nullptr);
2531}
2532
2533void InstructionCodeGeneratorMIPS64::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) {
2534 // Nothing to do, this is driven by the code generator.
2535}
2536
2537void LocationsBuilderMIPS64::VisitLoadString(HLoadString* load) {
2538 LocationSummary* locations =
2539 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2540 locations->SetInAt(0, Location::RequiresRegister());
2541 locations->SetOut(Location::RequiresRegister());
2542}
2543
2544void InstructionCodeGeneratorMIPS64::VisitLoadString(HLoadString* load) {
2545 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS64(load);
2546 codegen_->AddSlowPath(slow_path);
2547
2548 LocationSummary* locations = load->GetLocations();
2549 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2550 GpuRegister current_method = locations->InAt(0).AsRegister<GpuRegister>();
2551 __ LoadFromOffset(kLoadUnsignedWord, out, current_method,
2552 ArtMethod::DeclaringClassOffset().Int32Value());
2553 __ LoadFromOffset(kLoadUnsignedWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
2554 __ LoadFromOffset(kLoadUnsignedWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
2555 __ Beqzc(out, slow_path->GetEntryLabel());
2556 __ Bind(slow_path->GetExitLabel());
2557}
2558
2559void LocationsBuilderMIPS64::VisitLocal(HLocal* local) {
2560 local->SetLocations(nullptr);
2561}
2562
2563void InstructionCodeGeneratorMIPS64::VisitLocal(HLocal* local) {
2564 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
2565}
2566
2567void LocationsBuilderMIPS64::VisitLongConstant(HLongConstant* constant) {
2568 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2569 locations->SetOut(Location::ConstantLocation(constant));
2570}
2571
2572void InstructionCodeGeneratorMIPS64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
2573 // Will be generated at use site.
2574}
2575
2576void LocationsBuilderMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) {
2577 LocationSummary* locations =
2578 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2579 InvokeRuntimeCallingConvention calling_convention;
2580 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2581}
2582
2583void InstructionCodeGeneratorMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) {
2584 codegen_->InvokeRuntime(instruction->IsEnter()
2585 ? QUICK_ENTRY_POINT(pLockObject)
2586 : QUICK_ENTRY_POINT(pUnlockObject),
2587 instruction,
2588 instruction->GetDexPc(),
2589 nullptr);
2590 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
2591}
2592
2593void LocationsBuilderMIPS64::VisitMul(HMul* mul) {
2594 LocationSummary* locations =
2595 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2596 switch (mul->GetResultType()) {
2597 case Primitive::kPrimInt:
2598 case Primitive::kPrimLong:
2599 locations->SetInAt(0, Location::RequiresRegister());
2600 locations->SetInAt(1, Location::RequiresRegister());
2601 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2602 break;
2603
2604 case Primitive::kPrimFloat:
2605 case Primitive::kPrimDouble:
2606 locations->SetInAt(0, Location::RequiresFpuRegister());
2607 locations->SetInAt(1, Location::RequiresFpuRegister());
2608 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2609 break;
2610
2611 default:
2612 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2613 }
2614}
2615
2616void InstructionCodeGeneratorMIPS64::VisitMul(HMul* instruction) {
2617 Primitive::Type type = instruction->GetType();
2618 LocationSummary* locations = instruction->GetLocations();
2619
2620 switch (type) {
2621 case Primitive::kPrimInt:
2622 case Primitive::kPrimLong: {
2623 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2624 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
2625 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
2626 if (type == Primitive::kPrimInt)
2627 __ MulR6(dst, lhs, rhs);
2628 else
2629 __ Dmul(dst, lhs, rhs);
2630 break;
2631 }
2632 case Primitive::kPrimFloat:
2633 case Primitive::kPrimDouble: {
2634 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
2635 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
2636 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
2637 if (type == Primitive::kPrimFloat)
2638 __ MulS(dst, lhs, rhs);
2639 else
2640 __ MulD(dst, lhs, rhs);
2641 break;
2642 }
2643 default:
2644 LOG(FATAL) << "Unexpected mul type " << type;
2645 }
2646}
2647
2648void LocationsBuilderMIPS64::VisitNeg(HNeg* neg) {
2649 LocationSummary* locations =
2650 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
2651 switch (neg->GetResultType()) {
2652 case Primitive::kPrimInt:
2653 case Primitive::kPrimLong:
2654 locations->SetInAt(0, Location::RequiresRegister());
2655 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2656 break;
2657
2658 case Primitive::kPrimFloat:
2659 case Primitive::kPrimDouble:
2660 locations->SetInAt(0, Location::RequiresFpuRegister());
2661 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2662 break;
2663
2664 default:
2665 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2666 }
2667}
2668
2669void InstructionCodeGeneratorMIPS64::VisitNeg(HNeg* instruction) {
2670 Primitive::Type type = instruction->GetType();
2671 LocationSummary* locations = instruction->GetLocations();
2672
2673 switch (type) {
2674 case Primitive::kPrimInt:
2675 case Primitive::kPrimLong: {
2676 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2677 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
2678 if (type == Primitive::kPrimInt)
2679 __ Subu(dst, ZERO, src);
2680 else
2681 __ Dsubu(dst, ZERO, src);
2682 break;
2683 }
2684 case Primitive::kPrimFloat:
2685 case Primitive::kPrimDouble: {
2686 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
2687 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
2688 if (type == Primitive::kPrimFloat)
2689 __ NegS(dst, src);
2690 else
2691 __ NegD(dst, src);
2692 break;
2693 }
2694 default:
2695 LOG(FATAL) << "Unexpected neg type " << type;
2696 }
2697}
2698
2699void LocationsBuilderMIPS64::VisitNewArray(HNewArray* instruction) {
2700 LocationSummary* locations =
2701 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2702 InvokeRuntimeCallingConvention calling_convention;
2703 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2704 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
2705 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2706 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2707}
2708
2709void InstructionCodeGeneratorMIPS64::VisitNewArray(HNewArray* instruction) {
2710 LocationSummary* locations = instruction->GetLocations();
2711 // Move an uint16_t value to a register.
2712 __ LoadConst32(locations->GetTemp(0).AsRegister<GpuRegister>(), instruction->GetTypeIndex());
2713 codegen_->InvokeRuntime(
2714 GetThreadOffset<kMips64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2715 instruction,
2716 instruction->GetDexPc(),
2717 nullptr);
2718 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>();
2719}
2720
2721void LocationsBuilderMIPS64::VisitNewInstance(HNewInstance* instruction) {
2722 LocationSummary* locations =
2723 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2724 InvokeRuntimeCallingConvention calling_convention;
2725 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2726 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2727 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
2728}
2729
2730void InstructionCodeGeneratorMIPS64::VisitNewInstance(HNewInstance* instruction) {
2731 LocationSummary* locations = instruction->GetLocations();
2732 // Move an uint16_t value to a register.
2733 __ LoadConst32(locations->GetTemp(0).AsRegister<GpuRegister>(), instruction->GetTypeIndex());
2734 codegen_->InvokeRuntime(
2735 GetThreadOffset<kMips64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2736 instruction,
2737 instruction->GetDexPc(),
2738 nullptr);
2739 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
2740}
2741
2742void LocationsBuilderMIPS64::VisitNot(HNot* instruction) {
2743 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2744 locations->SetInAt(0, Location::RequiresRegister());
2745 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2746}
2747
2748void InstructionCodeGeneratorMIPS64::VisitNot(HNot* instruction) {
2749 Primitive::Type type = instruction->GetType();
2750 LocationSummary* locations = instruction->GetLocations();
2751
2752 switch (type) {
2753 case Primitive::kPrimInt:
2754 case Primitive::kPrimLong: {
2755 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2756 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
2757 __ Nor(dst, src, ZERO);
2758 break;
2759 }
2760
2761 default:
2762 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
2763 }
2764}
2765
2766void LocationsBuilderMIPS64::VisitBooleanNot(HBooleanNot* instruction) {
2767 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2768 locations->SetInAt(0, Location::RequiresRegister());
2769 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2770}
2771
2772void InstructionCodeGeneratorMIPS64::VisitBooleanNot(HBooleanNot* instruction) {
2773 LocationSummary* locations = instruction->GetLocations();
2774 __ Xori(locations->Out().AsRegister<GpuRegister>(),
2775 locations->InAt(0).AsRegister<GpuRegister>(),
2776 1);
2777}
2778
2779void LocationsBuilderMIPS64::VisitNullCheck(HNullCheck* instruction) {
2780 LocationSummary* locations =
2781 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2782 locations->SetInAt(0, Location::RequiresRegister());
2783 if (instruction->HasUses()) {
2784 locations->SetOut(Location::SameAsFirstInput());
2785 }
2786}
2787
2788void InstructionCodeGeneratorMIPS64::GenerateImplicitNullCheck(HNullCheck* instruction) {
2789 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2790 return;
2791 }
2792 Location obj = instruction->GetLocations()->InAt(0);
2793
2794 __ Lw(ZERO, obj.AsRegister<GpuRegister>(), 0);
2795 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2796}
2797
2798void InstructionCodeGeneratorMIPS64::GenerateExplicitNullCheck(HNullCheck* instruction) {
2799 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS64(instruction);
2800 codegen_->AddSlowPath(slow_path);
2801
2802 Location obj = instruction->GetLocations()->InAt(0);
2803
2804 __ Beqzc(obj.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
2805}
2806
2807void InstructionCodeGeneratorMIPS64::VisitNullCheck(HNullCheck* instruction) {
2808 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2809 GenerateImplicitNullCheck(instruction);
2810 } else {
2811 GenerateExplicitNullCheck(instruction);
2812 }
2813}
2814
2815void LocationsBuilderMIPS64::VisitOr(HOr* instruction) {
2816 HandleBinaryOp(instruction);
2817}
2818
2819void InstructionCodeGeneratorMIPS64::VisitOr(HOr* instruction) {
2820 HandleBinaryOp(instruction);
2821}
2822
2823void LocationsBuilderMIPS64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
2824 LOG(FATAL) << "Unreachable";
2825}
2826
2827void InstructionCodeGeneratorMIPS64::VisitParallelMove(HParallelMove* instruction) {
2828 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2829}
2830
2831void LocationsBuilderMIPS64::VisitParameterValue(HParameterValue* instruction) {
2832 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2833 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2834 if (location.IsStackSlot()) {
2835 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2836 } else if (location.IsDoubleStackSlot()) {
2837 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2838 }
2839 locations->SetOut(location);
2840}
2841
2842void InstructionCodeGeneratorMIPS64::VisitParameterValue(HParameterValue* instruction
2843 ATTRIBUTE_UNUSED) {
2844 // Nothing to do, the parameter is already at its location.
2845}
2846
2847void LocationsBuilderMIPS64::VisitCurrentMethod(HCurrentMethod* instruction) {
2848 LocationSummary* locations =
2849 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2850 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
2851}
2852
2853void InstructionCodeGeneratorMIPS64::VisitCurrentMethod(HCurrentMethod* instruction
2854 ATTRIBUTE_UNUSED) {
2855 // Nothing to do, the method is already at its location.
2856}
2857
2858void LocationsBuilderMIPS64::VisitPhi(HPhi* instruction) {
2859 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2860 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2861 locations->SetInAt(i, Location::Any());
2862 }
2863 locations->SetOut(Location::Any());
2864}
2865
2866void InstructionCodeGeneratorMIPS64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
2867 LOG(FATAL) << "Unreachable";
2868}
2869
2870void LocationsBuilderMIPS64::VisitRem(HRem* rem) {
2871 Primitive::Type type = rem->GetResultType();
2872 LocationSummary::CallKind call_kind =
2873 Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall;
2874 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2875
2876 switch (type) {
2877 case Primitive::kPrimInt:
2878 case Primitive::kPrimLong:
2879 locations->SetInAt(0, Location::RequiresRegister());
2880 locations->SetInAt(1, Location::RequiresRegister());
2881 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2882 break;
2883
2884 case Primitive::kPrimFloat:
2885 case Primitive::kPrimDouble: {
2886 InvokeRuntimeCallingConvention calling_convention;
2887 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2888 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2889 locations->SetOut(calling_convention.GetReturnLocation(type));
2890 break;
2891 }
2892
2893 default:
2894 LOG(FATAL) << "Unexpected rem type " << type;
2895 }
2896}
2897
2898void InstructionCodeGeneratorMIPS64::VisitRem(HRem* instruction) {
2899 Primitive::Type type = instruction->GetType();
2900 LocationSummary* locations = instruction->GetLocations();
2901
2902 switch (type) {
2903 case Primitive::kPrimInt:
2904 case Primitive::kPrimLong: {
2905 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2906 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
2907 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
2908 if (type == Primitive::kPrimInt)
2909 __ ModR6(dst, lhs, rhs);
2910 else
2911 __ Dmod(dst, lhs, rhs);
2912 break;
2913 }
2914
2915 case Primitive::kPrimFloat:
2916 case Primitive::kPrimDouble: {
2917 int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf)
2918 : QUICK_ENTRY_POINT(pFmod);
2919 codegen_->InvokeRuntime(entry_offset, instruction, instruction->GetDexPc(), nullptr);
2920 break;
2921 }
2922 default:
2923 LOG(FATAL) << "Unexpected rem type " << type;
2924 }
2925}
2926
2927void LocationsBuilderMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
2928 memory_barrier->SetLocations(nullptr);
2929}
2930
2931void InstructionCodeGeneratorMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
2932 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
2933}
2934
2935void LocationsBuilderMIPS64::VisitReturn(HReturn* ret) {
2936 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret);
2937 Primitive::Type return_type = ret->InputAt(0)->GetType();
2938 locations->SetInAt(0, Mips64ReturnLocation(return_type));
2939}
2940
2941void InstructionCodeGeneratorMIPS64::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
2942 codegen_->GenerateFrameExit();
2943}
2944
2945void LocationsBuilderMIPS64::VisitReturnVoid(HReturnVoid* ret) {
2946 ret->SetLocations(nullptr);
2947}
2948
2949void InstructionCodeGeneratorMIPS64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
2950 codegen_->GenerateFrameExit();
2951}
2952
2953void LocationsBuilderMIPS64::VisitShl(HShl* shl) {
2954 HandleShift(shl);
2955}
2956
2957void InstructionCodeGeneratorMIPS64::VisitShl(HShl* shl) {
2958 HandleShift(shl);
2959}
2960
2961void LocationsBuilderMIPS64::VisitShr(HShr* shr) {
2962 HandleShift(shr);
2963}
2964
2965void InstructionCodeGeneratorMIPS64::VisitShr(HShr* shr) {
2966 HandleShift(shr);
2967}
2968
2969void LocationsBuilderMIPS64::VisitStoreLocal(HStoreLocal* store) {
2970 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store);
2971 Primitive::Type field_type = store->InputAt(1)->GetType();
2972 switch (field_type) {
2973 case Primitive::kPrimNot:
2974 case Primitive::kPrimBoolean:
2975 case Primitive::kPrimByte:
2976 case Primitive::kPrimChar:
2977 case Primitive::kPrimShort:
2978 case Primitive::kPrimInt:
2979 case Primitive::kPrimFloat:
2980 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
2981 break;
2982
2983 case Primitive::kPrimLong:
2984 case Primitive::kPrimDouble:
2985 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
2986 break;
2987
2988 default:
2989 LOG(FATAL) << "Unimplemented local type " << field_type;
2990 }
2991}
2992
2993void InstructionCodeGeneratorMIPS64::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) {
2994}
2995
2996void LocationsBuilderMIPS64::VisitSub(HSub* instruction) {
2997 HandleBinaryOp(instruction);
2998}
2999
3000void InstructionCodeGeneratorMIPS64::VisitSub(HSub* instruction) {
3001 HandleBinaryOp(instruction);
3002}
3003
3004void LocationsBuilderMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3005 HandleFieldGet(instruction, instruction->GetFieldInfo());
3006}
3007
3008void InstructionCodeGeneratorMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3009 HandleFieldGet(instruction, instruction->GetFieldInfo());
3010}
3011
3012void LocationsBuilderMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3013 HandleFieldSet(instruction, instruction->GetFieldInfo());
3014}
3015
3016void InstructionCodeGeneratorMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3017 HandleFieldSet(instruction, instruction->GetFieldInfo());
3018}
3019
3020void LocationsBuilderMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) {
3021 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3022}
3023
3024void InstructionCodeGeneratorMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) {
3025 HBasicBlock* block = instruction->GetBlock();
3026 if (block->GetLoopInformation() != nullptr) {
3027 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3028 // The back edge will generate the suspend check.
3029 return;
3030 }
3031 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3032 // The goto will generate the suspend check.
3033 return;
3034 }
3035 GenerateSuspendCheck(instruction, nullptr);
3036}
3037
3038void LocationsBuilderMIPS64::VisitTemporary(HTemporary* temp) {
3039 temp->SetLocations(nullptr);
3040}
3041
3042void InstructionCodeGeneratorMIPS64::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) {
3043 // Nothing to do, this is driven by the code generator.
3044}
3045
3046void LocationsBuilderMIPS64::VisitThrow(HThrow* instruction) {
3047 LocationSummary* locations =
3048 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3049 InvokeRuntimeCallingConvention calling_convention;
3050 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3051}
3052
3053void InstructionCodeGeneratorMIPS64::VisitThrow(HThrow* instruction) {
3054 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException),
3055 instruction,
3056 instruction->GetDexPc(),
3057 nullptr);
3058 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
3059}
3060
3061void LocationsBuilderMIPS64::VisitTypeConversion(HTypeConversion* conversion) {
3062 Primitive::Type input_type = conversion->GetInputType();
3063 Primitive::Type result_type = conversion->GetResultType();
3064 DCHECK_NE(input_type, result_type);
3065
3066 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
3067 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
3068 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
3069 }
3070
3071 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
3072 if ((Primitive::IsFloatingPointType(result_type) && input_type == Primitive::kPrimLong) ||
3073 (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type))) {
3074 call_kind = LocationSummary::kCall;
3075 }
3076
3077 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
3078
3079 if (call_kind == LocationSummary::kNoCall) {
3080 if (Primitive::IsFloatingPointType(input_type)) {
3081 locations->SetInAt(0, Location::RequiresFpuRegister());
3082 } else {
3083 locations->SetInAt(0, Location::RequiresRegister());
3084 }
3085
3086 if (Primitive::IsFloatingPointType(result_type)) {
3087 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3088 } else {
3089 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3090 }
3091 } else {
3092 InvokeRuntimeCallingConvention calling_convention;
3093
3094 if (Primitive::IsFloatingPointType(input_type)) {
3095 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
3096 } else {
3097 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3098 }
3099
3100 locations->SetOut(calling_convention.GetReturnLocation(result_type));
3101 }
3102}
3103
3104void InstructionCodeGeneratorMIPS64::VisitTypeConversion(HTypeConversion* conversion) {
3105 LocationSummary* locations = conversion->GetLocations();
3106 Primitive::Type result_type = conversion->GetResultType();
3107 Primitive::Type input_type = conversion->GetInputType();
3108
3109 DCHECK_NE(input_type, result_type);
3110
3111 if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
3112 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3113 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
3114
3115 switch (result_type) {
3116 case Primitive::kPrimChar:
3117 __ Andi(dst, src, 0xFFFF);
3118 break;
3119 case Primitive::kPrimByte:
3120 // long is never converted into types narrower than int directly,
3121 // so SEB and SEH can be used without ever causing unpredictable results
3122 // on 64-bit inputs
3123 DCHECK(input_type != Primitive::kPrimLong);
3124 __ Seb(dst, src);
3125 break;
3126 case Primitive::kPrimShort:
3127 // long is never converted into types narrower than int directly,
3128 // so SEB and SEH can be used without ever causing unpredictable results
3129 // on 64-bit inputs
3130 DCHECK(input_type != Primitive::kPrimLong);
3131 __ Seh(dst, src);
3132 break;
3133 case Primitive::kPrimInt:
3134 case Primitive::kPrimLong:
3135 // Sign-extend 32-bit int into bits 32 through 63 for
3136 // int-to-long and long-to-int conversions
3137 __ Sll(dst, src, 0);
3138 break;
3139
3140 default:
3141 LOG(FATAL) << "Unexpected type conversion from " << input_type
3142 << " to " << result_type;
3143 }
3144 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
3145 if (input_type != Primitive::kPrimLong) {
3146 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
3147 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
3148 __ Mtc1(src, FTMP);
3149 if (result_type == Primitive::kPrimFloat) {
3150 __ Cvtsw(dst, FTMP);
3151 } else {
3152 __ Cvtdw(dst, FTMP);
3153 }
3154 } else {
3155 int32_t entry_offset = (result_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pL2f)
3156 : QUICK_ENTRY_POINT(pL2d);
3157 codegen_->InvokeRuntime(entry_offset,
3158 conversion,
3159 conversion->GetDexPc(),
3160 nullptr);
3161 }
3162 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
3163 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
3164 int32_t entry_offset;
3165 if (result_type != Primitive::kPrimLong) {
3166 entry_offset = (input_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pF2iz)
3167 : QUICK_ENTRY_POINT(pD2iz);
3168 } else {
3169 entry_offset = (input_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pF2l)
3170 : QUICK_ENTRY_POINT(pD2l);
3171 }
3172 codegen_->InvokeRuntime(entry_offset,
3173 conversion,
3174 conversion->GetDexPc(),
3175 nullptr);
3176 } else if (Primitive::IsFloatingPointType(result_type) &&
3177 Primitive::IsFloatingPointType(input_type)) {
3178 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
3179 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
3180 if (result_type == Primitive::kPrimFloat) {
3181 __ Cvtsd(dst, src);
3182 } else {
3183 __ Cvtds(dst, src);
3184 }
3185 } else {
3186 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
3187 << " to " << result_type;
3188 }
3189}
3190
3191void LocationsBuilderMIPS64::VisitUShr(HUShr* ushr) {
3192 HandleShift(ushr);
3193}
3194
3195void InstructionCodeGeneratorMIPS64::VisitUShr(HUShr* ushr) {
3196 HandleShift(ushr);
3197}
3198
3199void LocationsBuilderMIPS64::VisitXor(HXor* instruction) {
3200 HandleBinaryOp(instruction);
3201}
3202
3203void InstructionCodeGeneratorMIPS64::VisitXor(HXor* instruction) {
3204 HandleBinaryOp(instruction);
3205}
3206
3207void LocationsBuilderMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
3208 // Nothing to do, this should be removed during prepare for register allocator.
3209 LOG(FATAL) << "Unreachable";
3210}
3211
3212void InstructionCodeGeneratorMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
3213 // Nothing to do, this should be removed during prepare for register allocator.
3214 LOG(FATAL) << "Unreachable";
3215}
3216
3217void LocationsBuilderMIPS64::VisitEqual(HEqual* comp) {
3218 VisitCondition(comp);
3219}
3220
3221void InstructionCodeGeneratorMIPS64::VisitEqual(HEqual* comp) {
3222 VisitCondition(comp);
3223}
3224
3225void LocationsBuilderMIPS64::VisitNotEqual(HNotEqual* comp) {
3226 VisitCondition(comp);
3227}
3228
3229void InstructionCodeGeneratorMIPS64::VisitNotEqual(HNotEqual* comp) {
3230 VisitCondition(comp);
3231}
3232
3233void LocationsBuilderMIPS64::VisitLessThan(HLessThan* comp) {
3234 VisitCondition(comp);
3235}
3236
3237void InstructionCodeGeneratorMIPS64::VisitLessThan(HLessThan* comp) {
3238 VisitCondition(comp);
3239}
3240
3241void LocationsBuilderMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
3242 VisitCondition(comp);
3243}
3244
3245void InstructionCodeGeneratorMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
3246 VisitCondition(comp);
3247}
3248
3249void LocationsBuilderMIPS64::VisitGreaterThan(HGreaterThan* comp) {
3250 VisitCondition(comp);
3251}
3252
3253void InstructionCodeGeneratorMIPS64::VisitGreaterThan(HGreaterThan* comp) {
3254 VisitCondition(comp);
3255}
3256
3257void LocationsBuilderMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
3258 VisitCondition(comp);
3259}
3260
3261void InstructionCodeGeneratorMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
3262 VisitCondition(comp);
3263}
3264
3265} // namespace mips64
3266} // namespace art