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