blob: ab684d41d4234aa551e1b473b39d3c73d58e139c [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 Brazdil3e187382015-06-26 09:59:52 +00001941void LocationsBuilderMIPS64::VisitGoto(HGoto* got) {
1942 got->SetLocations(nullptr);
1943}
1944
1945void InstructionCodeGeneratorMIPS64::VisitGoto(HGoto* got) {
1946 HBasicBlock* successor = got->GetSuccessor();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001947 DCHECK(!successor->IsExitBlock());
1948 HBasicBlock* block = got->GetBlock();
1949 HInstruction* previous = got->GetPrevious();
1950 HLoopInformation* info = block->GetLoopInformation();
1951
1952 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
1953 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1954 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1955 return;
1956 }
1957 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1958 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1959 }
1960 if (!codegen_->GoesToNextBlock(block, successor)) {
1961 __ B(codegen_->GetLabelOf(successor));
1962 }
1963}
1964
Alexey Frunze4dda3372015-06-01 18:31:49 -07001965void InstructionCodeGeneratorMIPS64::GenerateTestAndBranch(HInstruction* instruction,
1966 Label* true_target,
1967 Label* false_target,
1968 Label* always_true_target) {
1969 HInstruction* cond = instruction->InputAt(0);
1970 HCondition* condition = cond->AsCondition();
1971
1972 if (cond->IsIntConstant()) {
1973 int32_t cond_value = cond->AsIntConstant()->GetValue();
1974 if (cond_value == 1) {
1975 if (always_true_target != nullptr) {
1976 __ B(always_true_target);
1977 }
1978 return;
1979 } else {
1980 DCHECK_EQ(cond_value, 0);
1981 }
1982 } else if (!cond->IsCondition() || condition->NeedsMaterialization()) {
1983 // The condition instruction has been materialized, compare the output to 0.
1984 Location cond_val = instruction->GetLocations()->InAt(0);
1985 DCHECK(cond_val.IsRegister());
1986 __ Bnezc(cond_val.AsRegister<GpuRegister>(), true_target);
1987 } else {
1988 // The condition instruction has not been materialized, use its inputs as
1989 // the comparison and its condition as the branch condition.
1990 GpuRegister lhs = condition->GetLocations()->InAt(0).AsRegister<GpuRegister>();
1991 Location rhs_location = condition->GetLocations()->InAt(1);
1992 GpuRegister rhs_reg = ZERO;
1993 int32_t rhs_imm = 0;
1994 bool use_imm = rhs_location.IsConstant();
1995 if (use_imm) {
1996 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
1997 } else {
1998 rhs_reg = rhs_location.AsRegister<GpuRegister>();
1999 }
2000
2001 IfCondition if_cond = condition->GetCondition();
2002 if (use_imm && rhs_imm == 0) {
2003 switch (if_cond) {
2004 case kCondEQ:
2005 __ Beqzc(lhs, true_target);
2006 break;
2007 case kCondNE:
2008 __ Bnezc(lhs, true_target);
2009 break;
2010 case kCondLT:
2011 __ Bltzc(lhs, true_target);
2012 break;
2013 case kCondGE:
2014 __ Bgezc(lhs, true_target);
2015 break;
2016 case kCondLE:
2017 __ Blezc(lhs, true_target);
2018 break;
2019 case kCondGT:
2020 __ Bgtzc(lhs, true_target);
2021 break;
2022 }
2023 } else {
2024 if (use_imm) {
2025 rhs_reg = TMP;
2026 __ LoadConst32(rhs_reg, rhs_imm);
2027 }
2028 // It looks like we can get here with lhs == rhs. Should that be possible at all?
2029 // Mips R6 requires lhs != rhs for compact branches.
2030 if (lhs == rhs_reg) {
2031 DCHECK(!use_imm);
2032 switch (if_cond) {
2033 case kCondEQ:
2034 case kCondGE:
2035 case kCondLE:
2036 // if lhs == rhs for a positive condition, then it is a branch
2037 __ B(true_target);
2038 break;
2039 case kCondNE:
2040 case kCondLT:
2041 case kCondGT:
2042 // if lhs == rhs for a negative condition, then it is a NOP
2043 break;
2044 }
2045 } else {
2046 switch (if_cond) {
2047 case kCondEQ:
2048 __ Beqc(lhs, rhs_reg, true_target);
2049 break;
2050 case kCondNE:
2051 __ Bnec(lhs, rhs_reg, true_target);
2052 break;
2053 case kCondLT:
2054 __ Bltc(lhs, rhs_reg, true_target);
2055 break;
2056 case kCondGE:
2057 __ Bgec(lhs, rhs_reg, true_target);
2058 break;
2059 case kCondLE:
2060 __ Bgec(rhs_reg, lhs, true_target);
2061 break;
2062 case kCondGT:
2063 __ Bltc(rhs_reg, lhs, true_target);
2064 break;
2065 }
2066 }
2067 }
2068 }
2069 if (false_target != nullptr) {
2070 __ B(false_target);
2071 }
2072}
2073
2074void LocationsBuilderMIPS64::VisitIf(HIf* if_instr) {
2075 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
2076 HInstruction* cond = if_instr->InputAt(0);
2077 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
2078 locations->SetInAt(0, Location::RequiresRegister());
2079 }
2080}
2081
2082void InstructionCodeGeneratorMIPS64::VisitIf(HIf* if_instr) {
2083 Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
2084 Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
2085 Label* always_true_target = true_target;
2086 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
2087 if_instr->IfTrueSuccessor())) {
2088 always_true_target = nullptr;
2089 }
2090 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
2091 if_instr->IfFalseSuccessor())) {
2092 false_target = nullptr;
2093 }
2094 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
2095}
2096
2097void LocationsBuilderMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) {
2098 LocationSummary* locations = new (GetGraph()->GetArena())
2099 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
2100 HInstruction* cond = deoptimize->InputAt(0);
2101 DCHECK(cond->IsCondition());
2102 if (cond->AsCondition()->NeedsMaterialization()) {
2103 locations->SetInAt(0, Location::RequiresRegister());
2104 }
2105}
2106
2107void InstructionCodeGeneratorMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) {
2108 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena())
2109 DeoptimizationSlowPathMIPS64(deoptimize);
2110 codegen_->AddSlowPath(slow_path);
2111 Label* slow_path_entry = slow_path->GetEntryLabel();
2112 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
2113}
2114
2115void LocationsBuilderMIPS64::HandleFieldGet(HInstruction* instruction,
2116 const FieldInfo& field_info ATTRIBUTE_UNUSED) {
2117 LocationSummary* locations =
2118 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2119 locations->SetInAt(0, Location::RequiresRegister());
2120 if (Primitive::IsFloatingPointType(instruction->GetType())) {
2121 locations->SetOut(Location::RequiresFpuRegister());
2122 } else {
2123 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2124 }
2125}
2126
2127void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction,
2128 const FieldInfo& field_info) {
2129 Primitive::Type type = field_info.GetFieldType();
2130 LocationSummary* locations = instruction->GetLocations();
2131 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2132 LoadOperandType load_type = kLoadUnsignedByte;
2133 switch (type) {
2134 case Primitive::kPrimBoolean:
2135 load_type = kLoadUnsignedByte;
2136 break;
2137 case Primitive::kPrimByte:
2138 load_type = kLoadSignedByte;
2139 break;
2140 case Primitive::kPrimShort:
2141 load_type = kLoadSignedHalfword;
2142 break;
2143 case Primitive::kPrimChar:
2144 load_type = kLoadUnsignedHalfword;
2145 break;
2146 case Primitive::kPrimInt:
2147 case Primitive::kPrimFloat:
2148 load_type = kLoadWord;
2149 break;
2150 case Primitive::kPrimLong:
2151 case Primitive::kPrimDouble:
2152 load_type = kLoadDoubleword;
2153 break;
2154 case Primitive::kPrimNot:
2155 load_type = kLoadUnsignedWord;
2156 break;
2157 case Primitive::kPrimVoid:
2158 LOG(FATAL) << "Unreachable type " << type;
2159 UNREACHABLE();
2160 }
2161 if (!Primitive::IsFloatingPointType(type)) {
2162 DCHECK(locations->Out().IsRegister());
2163 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2164 __ LoadFromOffset(load_type, dst, obj, field_info.GetFieldOffset().Uint32Value());
2165 } else {
2166 DCHECK(locations->Out().IsFpuRegister());
2167 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
2168 __ LoadFpuFromOffset(load_type, dst, obj, field_info.GetFieldOffset().Uint32Value());
2169 }
2170
2171 codegen_->MaybeRecordImplicitNullCheck(instruction);
2172 // TODO: memory barrier?
2173}
2174
2175void LocationsBuilderMIPS64::HandleFieldSet(HInstruction* instruction,
2176 const FieldInfo& field_info ATTRIBUTE_UNUSED) {
2177 LocationSummary* locations =
2178 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2179 locations->SetInAt(0, Location::RequiresRegister());
2180 if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) {
2181 locations->SetInAt(1, Location::RequiresFpuRegister());
2182 } else {
2183 locations->SetInAt(1, Location::RequiresRegister());
2184 }
2185}
2186
2187void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction,
2188 const FieldInfo& field_info) {
2189 Primitive::Type type = field_info.GetFieldType();
2190 LocationSummary* locations = instruction->GetLocations();
2191 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2192 StoreOperandType store_type = kStoreByte;
2193 switch (type) {
2194 case Primitive::kPrimBoolean:
2195 case Primitive::kPrimByte:
2196 store_type = kStoreByte;
2197 break;
2198 case Primitive::kPrimShort:
2199 case Primitive::kPrimChar:
2200 store_type = kStoreHalfword;
2201 break;
2202 case Primitive::kPrimInt:
2203 case Primitive::kPrimFloat:
2204 case Primitive::kPrimNot:
2205 store_type = kStoreWord;
2206 break;
2207 case Primitive::kPrimLong:
2208 case Primitive::kPrimDouble:
2209 store_type = kStoreDoubleword;
2210 break;
2211 case Primitive::kPrimVoid:
2212 LOG(FATAL) << "Unreachable type " << type;
2213 UNREACHABLE();
2214 }
2215 if (!Primitive::IsFloatingPointType(type)) {
2216 DCHECK(locations->InAt(1).IsRegister());
2217 GpuRegister src = locations->InAt(1).AsRegister<GpuRegister>();
2218 __ StoreToOffset(store_type, src, obj, field_info.GetFieldOffset().Uint32Value());
2219 } else {
2220 DCHECK(locations->InAt(1).IsFpuRegister());
2221 FpuRegister src = locations->InAt(1).AsFpuRegister<FpuRegister>();
2222 __ StoreFpuToOffset(store_type, src, obj, field_info.GetFieldOffset().Uint32Value());
2223 }
2224
2225 codegen_->MaybeRecordImplicitNullCheck(instruction);
2226 // TODO: memory barriers?
2227 if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) {
2228 DCHECK(locations->InAt(1).IsRegister());
2229 GpuRegister src = locations->InAt(1).AsRegister<GpuRegister>();
2230 codegen_->MarkGCCard(obj, src);
2231 }
2232}
2233
2234void LocationsBuilderMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2235 HandleFieldGet(instruction, instruction->GetFieldInfo());
2236}
2237
2238void InstructionCodeGeneratorMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2239 HandleFieldGet(instruction, instruction->GetFieldInfo());
2240}
2241
2242void LocationsBuilderMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2243 HandleFieldSet(instruction, instruction->GetFieldInfo());
2244}
2245
2246void InstructionCodeGeneratorMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2247 HandleFieldSet(instruction, instruction->GetFieldInfo());
2248}
2249
2250void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) {
2251 LocationSummary::CallKind call_kind =
2252 instruction->IsClassFinal() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
2253 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
2254 locations->SetInAt(0, Location::RequiresRegister());
2255 locations->SetInAt(1, Location::RequiresRegister());
2256 // The output does overlap inputs.
2257 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
2258}
2259
2260void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) {
2261 LocationSummary* locations = instruction->GetLocations();
2262 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2263 GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>();
2264 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2265
2266 Label done;
2267
2268 // Return 0 if `obj` is null.
2269 // TODO: Avoid this check if we know `obj` is not null.
2270 __ Move(out, ZERO);
2271 __ Beqzc(obj, &done);
2272
2273 // Compare the class of `obj` with `cls`.
2274 __ LoadFromOffset(kLoadUnsignedWord, out, obj, mirror::Object::ClassOffset().Int32Value());
2275 if (instruction->IsClassFinal()) {
2276 // Classes must be equal for the instanceof to succeed.
2277 __ Xor(out, out, cls);
2278 __ Sltiu(out, out, 1);
2279 } else {
2280 // If the classes are not equal, we go into a slow path.
2281 DCHECK(locations->OnlyCallsOnSlowPath());
2282 SlowPathCodeMIPS64* slow_path =
2283 new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction,
2284 locations->InAt(1),
2285 locations->Out(),
2286 instruction->GetDexPc());
2287 codegen_->AddSlowPath(slow_path);
2288 __ Bnec(out, cls, slow_path->GetEntryLabel());
2289 __ LoadConst32(out, 1);
2290 __ Bind(slow_path->GetExitLabel());
2291 }
2292
2293 __ Bind(&done);
2294}
2295
2296void LocationsBuilderMIPS64::VisitIntConstant(HIntConstant* constant) {
2297 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2298 locations->SetOut(Location::ConstantLocation(constant));
2299}
2300
2301void InstructionCodeGeneratorMIPS64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
2302 // Will be generated at use site.
2303}
2304
2305void LocationsBuilderMIPS64::VisitNullConstant(HNullConstant* constant) {
2306 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2307 locations->SetOut(Location::ConstantLocation(constant));
2308}
2309
2310void InstructionCodeGeneratorMIPS64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
2311 // Will be generated at use site.
2312}
2313
2314void LocationsBuilderMIPS64::HandleInvoke(HInvoke* invoke) {
2315 InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor;
2316 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
2317}
2318
2319void LocationsBuilderMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) {
2320 HandleInvoke(invoke);
2321 // The register T0 is required to be used for the hidden argument in
2322 // art_quick_imt_conflict_trampoline, so add the hidden argument.
2323 invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0));
2324}
2325
2326void InstructionCodeGeneratorMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) {
2327 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
2328 GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>();
2329 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
2330 invoke->GetImtIndex() % mirror::Class::kImtSize, kMips64PointerSize).Uint32Value();
2331 Location receiver = invoke->GetLocations()->InAt(0);
2332 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2333 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64WordSize);
2334
2335 // Set the hidden argument.
2336 __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<GpuRegister>(),
2337 invoke->GetDexMethodIndex());
2338
2339 // temp = object->GetClass();
2340 if (receiver.IsStackSlot()) {
2341 __ LoadFromOffset(kLoadUnsignedWord, temp, SP, receiver.GetStackIndex());
2342 __ LoadFromOffset(kLoadUnsignedWord, temp, temp, class_offset);
2343 } else {
2344 __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset);
2345 }
2346 codegen_->MaybeRecordImplicitNullCheck(invoke);
2347 // temp = temp->GetImtEntryAt(method_offset);
2348 __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset);
2349 // T9 = temp->GetEntryPoint();
2350 __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value());
2351 // T9();
2352 __ Jalr(T9);
2353 DCHECK(!codegen_->IsLeafMethod());
2354 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2355}
2356
2357void LocationsBuilderMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
2358 // TODO intrinsic function
2359 HandleInvoke(invoke);
2360}
2361
2362void LocationsBuilderMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
2363 // When we do not run baseline, explicit clinit checks triggered by static
2364 // invokes must have been pruned by art::PrepareForRegisterAllocation.
2365 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
2366
2367 // TODO - intrinsic function
2368 HandleInvoke(invoke);
2369
2370 // While SetupBlockedRegisters() blocks registers S2-S8 due to their
2371 // clobbering somewhere else, reduce further register pressure by avoiding
2372 // allocation of a register for the current method pointer like on x86 baseline.
2373 // TODO: remove this once all the issues with register saving/restoring are
2374 // sorted out.
2375 LocationSummary* locations = invoke->GetLocations();
2376 Location location = locations->InAt(invoke->GetCurrentMethodInputIndex());
2377 if (location.IsUnallocated() && location.GetPolicy() == Location::kRequiresRegister) {
2378 locations->SetInAt(invoke->GetCurrentMethodInputIndex(), Location::NoLocation());
2379 }
2380}
2381
2382static bool TryGenerateIntrinsicCode(HInvoke* invoke,
2383 CodeGeneratorMIPS64* codegen ATTRIBUTE_UNUSED) {
2384 if (invoke->GetLocations()->Intrinsified()) {
2385 // TODO - intrinsic function
2386 return true;
2387 }
2388 return false;
2389}
2390
2391void CodeGeneratorMIPS64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
2392 // All registers are assumed to be correctly set up per the calling convention.
2393
2394 // TODO: Implement all kinds of calls:
2395 // 1) boot -> boot
2396 // 2) app -> boot
2397 // 3) app -> app
2398 //
2399 // Currently we implement the app -> app logic, which looks up in the resolve cache.
2400
2401 if (invoke->IsStringInit()) {
2402 GpuRegister reg = temp.AsRegister<GpuRegister>();
2403 // temp = thread->string_init_entrypoint
2404 __ LoadFromOffset(kLoadDoubleword,
2405 reg,
2406 TR,
2407 invoke->GetStringInitOffset());
2408 // T9 = temp->entry_point_from_quick_compiled_code_;
2409 __ LoadFromOffset(kLoadDoubleword,
2410 T9,
2411 reg,
2412 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
2413 kMips64WordSize).Int32Value());
2414 // T9()
2415 __ Jalr(T9);
2416 } else if (invoke->IsRecursive()) {
2417 __ Jalr(&frame_entry_label_, T9);
2418 } else {
2419 Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
2420 GpuRegister reg = temp.AsRegister<GpuRegister>();
2421 GpuRegister method_reg;
2422 if (current_method.IsRegister()) {
2423 method_reg = current_method.AsRegister<GpuRegister>();
2424 } else {
2425 // TODO: use the appropriate DCHECK() here if possible.
2426 // DCHECK(invoke->GetLocations()->Intrinsified());
2427 DCHECK(!current_method.IsValid());
2428 method_reg = reg;
2429 __ Ld(reg, SP, kCurrentMethodStackOffset);
2430 }
2431
2432 // temp = temp->dex_cache_resolved_methods_;
2433 __ LoadFromOffset(kLoadUnsignedWord,
2434 reg,
2435 method_reg,
2436 ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
2437 // temp = temp[index_in_cache]
2438 __ LoadFromOffset(kLoadDoubleword,
2439 reg,
2440 reg,
2441 CodeGenerator::GetCachePointerOffset(invoke->GetDexMethodIndex()));
2442 // T9 = temp[offset_of_quick_compiled_code]
2443 __ LoadFromOffset(kLoadDoubleword,
2444 T9,
2445 reg,
2446 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
2447 kMips64WordSize).Int32Value());
2448 // T9()
2449 __ Jalr(T9);
2450 }
2451
2452 DCHECK(!IsLeafMethod());
2453}
2454
2455void InstructionCodeGeneratorMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
2456 // When we do not run baseline, explicit clinit checks triggered by static
2457 // invokes must have been pruned by art::PrepareForRegisterAllocation.
2458 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
2459
2460 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2461 return;
2462 }
2463
2464 LocationSummary* locations = invoke->GetLocations();
2465 codegen_->GenerateStaticOrDirectCall(invoke,
2466 locations->HasTemps()
2467 ? locations->GetTemp(0)
2468 : Location::NoLocation());
2469 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2470}
2471
2472void InstructionCodeGeneratorMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
2473 // TODO: Try to generate intrinsics code.
2474 LocationSummary* locations = invoke->GetLocations();
2475 Location receiver = locations->InAt(0);
2476 GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>();
2477 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
2478 invoke->GetVTableIndex(), kMips64PointerSize).SizeValue();
2479 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2480 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64WordSize);
2481
2482 // temp = object->GetClass();
2483 DCHECK(receiver.IsRegister());
2484 __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset);
2485 codegen_->MaybeRecordImplicitNullCheck(invoke);
2486 // temp = temp->GetMethodAt(method_offset);
2487 __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset);
2488 // T9 = temp->GetEntryPoint();
2489 __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value());
2490 // T9();
2491 __ Jalr(T9);
2492 DCHECK(!codegen_->IsLeafMethod());
2493 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2494}
2495
2496void LocationsBuilderMIPS64::VisitLoadClass(HLoadClass* cls) {
2497 LocationSummary::CallKind call_kind = cls->CanCallRuntime() ? LocationSummary::kCallOnSlowPath
2498 : LocationSummary::kNoCall;
2499 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
2500 locations->SetInAt(0, Location::RequiresRegister());
2501 locations->SetOut(Location::RequiresRegister());
2502}
2503
2504void InstructionCodeGeneratorMIPS64::VisitLoadClass(HLoadClass* cls) {
2505 LocationSummary* locations = cls->GetLocations();
2506 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2507 GpuRegister current_method = locations->InAt(0).AsRegister<GpuRegister>();
2508 if (cls->IsReferrersClass()) {
2509 DCHECK(!cls->CanCallRuntime());
2510 DCHECK(!cls->MustGenerateClinitCheck());
2511 __ LoadFromOffset(kLoadUnsignedWord, out, current_method,
2512 ArtMethod::DeclaringClassOffset().Int32Value());
2513 } else {
2514 DCHECK(cls->CanCallRuntime());
2515 __ LoadFromOffset(kLoadUnsignedWord, out, current_method,
2516 ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
2517 __ LoadFromOffset(kLoadUnsignedWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
2518 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64(
2519 cls,
2520 cls,
2521 cls->GetDexPc(),
2522 cls->MustGenerateClinitCheck());
2523 codegen_->AddSlowPath(slow_path);
2524 __ Beqzc(out, slow_path->GetEntryLabel());
2525 if (cls->MustGenerateClinitCheck()) {
2526 GenerateClassInitializationCheck(slow_path, out);
2527 } else {
2528 __ Bind(slow_path->GetExitLabel());
2529 }
2530 }
2531}
2532
2533void LocationsBuilderMIPS64::VisitLoadException(HLoadException* load) {
2534 LocationSummary* locations =
2535 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2536 locations->SetOut(Location::RequiresRegister());
2537}
2538
2539void InstructionCodeGeneratorMIPS64::VisitLoadException(HLoadException* load) {
2540 GpuRegister out = load->GetLocations()->Out().AsRegister<GpuRegister>();
2541 __ LoadFromOffset(kLoadUnsignedWord, out, TR, Thread::ExceptionOffset<kMips64WordSize>().Int32Value());
2542 __ StoreToOffset(kStoreWord, ZERO, TR, Thread::ExceptionOffset<kMips64WordSize>().Int32Value());
2543}
2544
2545void LocationsBuilderMIPS64::VisitLoadLocal(HLoadLocal* load) {
2546 load->SetLocations(nullptr);
2547}
2548
2549void InstructionCodeGeneratorMIPS64::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) {
2550 // Nothing to do, this is driven by the code generator.
2551}
2552
2553void LocationsBuilderMIPS64::VisitLoadString(HLoadString* load) {
2554 LocationSummary* locations =
2555 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2556 locations->SetInAt(0, Location::RequiresRegister());
2557 locations->SetOut(Location::RequiresRegister());
2558}
2559
2560void InstructionCodeGeneratorMIPS64::VisitLoadString(HLoadString* load) {
2561 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS64(load);
2562 codegen_->AddSlowPath(slow_path);
2563
2564 LocationSummary* locations = load->GetLocations();
2565 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2566 GpuRegister current_method = locations->InAt(0).AsRegister<GpuRegister>();
2567 __ LoadFromOffset(kLoadUnsignedWord, out, current_method,
2568 ArtMethod::DeclaringClassOffset().Int32Value());
2569 __ LoadFromOffset(kLoadUnsignedWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
2570 __ LoadFromOffset(kLoadUnsignedWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
2571 __ Beqzc(out, slow_path->GetEntryLabel());
2572 __ Bind(slow_path->GetExitLabel());
2573}
2574
2575void LocationsBuilderMIPS64::VisitLocal(HLocal* local) {
2576 local->SetLocations(nullptr);
2577}
2578
2579void InstructionCodeGeneratorMIPS64::VisitLocal(HLocal* local) {
2580 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
2581}
2582
2583void LocationsBuilderMIPS64::VisitLongConstant(HLongConstant* constant) {
2584 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2585 locations->SetOut(Location::ConstantLocation(constant));
2586}
2587
2588void InstructionCodeGeneratorMIPS64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
2589 // Will be generated at use site.
2590}
2591
2592void LocationsBuilderMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) {
2593 LocationSummary* locations =
2594 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2595 InvokeRuntimeCallingConvention calling_convention;
2596 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2597}
2598
2599void InstructionCodeGeneratorMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) {
2600 codegen_->InvokeRuntime(instruction->IsEnter()
2601 ? QUICK_ENTRY_POINT(pLockObject)
2602 : QUICK_ENTRY_POINT(pUnlockObject),
2603 instruction,
2604 instruction->GetDexPc(),
2605 nullptr);
2606 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
2607}
2608
2609void LocationsBuilderMIPS64::VisitMul(HMul* mul) {
2610 LocationSummary* locations =
2611 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2612 switch (mul->GetResultType()) {
2613 case Primitive::kPrimInt:
2614 case Primitive::kPrimLong:
2615 locations->SetInAt(0, Location::RequiresRegister());
2616 locations->SetInAt(1, Location::RequiresRegister());
2617 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2618 break;
2619
2620 case Primitive::kPrimFloat:
2621 case Primitive::kPrimDouble:
2622 locations->SetInAt(0, Location::RequiresFpuRegister());
2623 locations->SetInAt(1, Location::RequiresFpuRegister());
2624 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2625 break;
2626
2627 default:
2628 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2629 }
2630}
2631
2632void InstructionCodeGeneratorMIPS64::VisitMul(HMul* instruction) {
2633 Primitive::Type type = instruction->GetType();
2634 LocationSummary* locations = instruction->GetLocations();
2635
2636 switch (type) {
2637 case Primitive::kPrimInt:
2638 case Primitive::kPrimLong: {
2639 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2640 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
2641 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
2642 if (type == Primitive::kPrimInt)
2643 __ MulR6(dst, lhs, rhs);
2644 else
2645 __ Dmul(dst, lhs, rhs);
2646 break;
2647 }
2648 case Primitive::kPrimFloat:
2649 case Primitive::kPrimDouble: {
2650 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
2651 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
2652 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
2653 if (type == Primitive::kPrimFloat)
2654 __ MulS(dst, lhs, rhs);
2655 else
2656 __ MulD(dst, lhs, rhs);
2657 break;
2658 }
2659 default:
2660 LOG(FATAL) << "Unexpected mul type " << type;
2661 }
2662}
2663
2664void LocationsBuilderMIPS64::VisitNeg(HNeg* neg) {
2665 LocationSummary* locations =
2666 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
2667 switch (neg->GetResultType()) {
2668 case Primitive::kPrimInt:
2669 case Primitive::kPrimLong:
2670 locations->SetInAt(0, Location::RequiresRegister());
2671 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2672 break;
2673
2674 case Primitive::kPrimFloat:
2675 case Primitive::kPrimDouble:
2676 locations->SetInAt(0, Location::RequiresFpuRegister());
2677 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2678 break;
2679
2680 default:
2681 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2682 }
2683}
2684
2685void InstructionCodeGeneratorMIPS64::VisitNeg(HNeg* instruction) {
2686 Primitive::Type type = instruction->GetType();
2687 LocationSummary* locations = instruction->GetLocations();
2688
2689 switch (type) {
2690 case Primitive::kPrimInt:
2691 case Primitive::kPrimLong: {
2692 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2693 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
2694 if (type == Primitive::kPrimInt)
2695 __ Subu(dst, ZERO, src);
2696 else
2697 __ Dsubu(dst, ZERO, src);
2698 break;
2699 }
2700 case Primitive::kPrimFloat:
2701 case Primitive::kPrimDouble: {
2702 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
2703 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
2704 if (type == Primitive::kPrimFloat)
2705 __ NegS(dst, src);
2706 else
2707 __ NegD(dst, src);
2708 break;
2709 }
2710 default:
2711 LOG(FATAL) << "Unexpected neg type " << type;
2712 }
2713}
2714
2715void LocationsBuilderMIPS64::VisitNewArray(HNewArray* instruction) {
2716 LocationSummary* locations =
2717 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2718 InvokeRuntimeCallingConvention calling_convention;
2719 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2720 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
2721 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2722 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2723}
2724
2725void InstructionCodeGeneratorMIPS64::VisitNewArray(HNewArray* instruction) {
2726 LocationSummary* locations = instruction->GetLocations();
2727 // Move an uint16_t value to a register.
2728 __ LoadConst32(locations->GetTemp(0).AsRegister<GpuRegister>(), instruction->GetTypeIndex());
2729 codegen_->InvokeRuntime(
2730 GetThreadOffset<kMips64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2731 instruction,
2732 instruction->GetDexPc(),
2733 nullptr);
2734 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>();
2735}
2736
2737void LocationsBuilderMIPS64::VisitNewInstance(HNewInstance* instruction) {
2738 LocationSummary* locations =
2739 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2740 InvokeRuntimeCallingConvention calling_convention;
2741 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2742 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2743 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
2744}
2745
2746void InstructionCodeGeneratorMIPS64::VisitNewInstance(HNewInstance* instruction) {
2747 LocationSummary* locations = instruction->GetLocations();
2748 // Move an uint16_t value to a register.
2749 __ LoadConst32(locations->GetTemp(0).AsRegister<GpuRegister>(), instruction->GetTypeIndex());
2750 codegen_->InvokeRuntime(
2751 GetThreadOffset<kMips64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2752 instruction,
2753 instruction->GetDexPc(),
2754 nullptr);
2755 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
2756}
2757
2758void LocationsBuilderMIPS64::VisitNot(HNot* instruction) {
2759 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2760 locations->SetInAt(0, Location::RequiresRegister());
2761 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2762}
2763
2764void InstructionCodeGeneratorMIPS64::VisitNot(HNot* instruction) {
2765 Primitive::Type type = instruction->GetType();
2766 LocationSummary* locations = instruction->GetLocations();
2767
2768 switch (type) {
2769 case Primitive::kPrimInt:
2770 case Primitive::kPrimLong: {
2771 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2772 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
2773 __ Nor(dst, src, ZERO);
2774 break;
2775 }
2776
2777 default:
2778 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
2779 }
2780}
2781
2782void LocationsBuilderMIPS64::VisitBooleanNot(HBooleanNot* instruction) {
2783 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2784 locations->SetInAt(0, Location::RequiresRegister());
2785 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2786}
2787
2788void InstructionCodeGeneratorMIPS64::VisitBooleanNot(HBooleanNot* instruction) {
2789 LocationSummary* locations = instruction->GetLocations();
2790 __ Xori(locations->Out().AsRegister<GpuRegister>(),
2791 locations->InAt(0).AsRegister<GpuRegister>(),
2792 1);
2793}
2794
2795void LocationsBuilderMIPS64::VisitNullCheck(HNullCheck* instruction) {
2796 LocationSummary* locations =
2797 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2798 locations->SetInAt(0, Location::RequiresRegister());
2799 if (instruction->HasUses()) {
2800 locations->SetOut(Location::SameAsFirstInput());
2801 }
2802}
2803
2804void InstructionCodeGeneratorMIPS64::GenerateImplicitNullCheck(HNullCheck* instruction) {
2805 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2806 return;
2807 }
2808 Location obj = instruction->GetLocations()->InAt(0);
2809
2810 __ Lw(ZERO, obj.AsRegister<GpuRegister>(), 0);
2811 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2812}
2813
2814void InstructionCodeGeneratorMIPS64::GenerateExplicitNullCheck(HNullCheck* instruction) {
2815 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS64(instruction);
2816 codegen_->AddSlowPath(slow_path);
2817
2818 Location obj = instruction->GetLocations()->InAt(0);
2819
2820 __ Beqzc(obj.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
2821}
2822
2823void InstructionCodeGeneratorMIPS64::VisitNullCheck(HNullCheck* instruction) {
2824 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2825 GenerateImplicitNullCheck(instruction);
2826 } else {
2827 GenerateExplicitNullCheck(instruction);
2828 }
2829}
2830
2831void LocationsBuilderMIPS64::VisitOr(HOr* instruction) {
2832 HandleBinaryOp(instruction);
2833}
2834
2835void InstructionCodeGeneratorMIPS64::VisitOr(HOr* instruction) {
2836 HandleBinaryOp(instruction);
2837}
2838
2839void LocationsBuilderMIPS64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
2840 LOG(FATAL) << "Unreachable";
2841}
2842
2843void InstructionCodeGeneratorMIPS64::VisitParallelMove(HParallelMove* instruction) {
2844 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2845}
2846
2847void LocationsBuilderMIPS64::VisitParameterValue(HParameterValue* instruction) {
2848 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2849 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2850 if (location.IsStackSlot()) {
2851 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2852 } else if (location.IsDoubleStackSlot()) {
2853 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2854 }
2855 locations->SetOut(location);
2856}
2857
2858void InstructionCodeGeneratorMIPS64::VisitParameterValue(HParameterValue* instruction
2859 ATTRIBUTE_UNUSED) {
2860 // Nothing to do, the parameter is already at its location.
2861}
2862
2863void LocationsBuilderMIPS64::VisitCurrentMethod(HCurrentMethod* instruction) {
2864 LocationSummary* locations =
2865 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2866 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
2867}
2868
2869void InstructionCodeGeneratorMIPS64::VisitCurrentMethod(HCurrentMethod* instruction
2870 ATTRIBUTE_UNUSED) {
2871 // Nothing to do, the method is already at its location.
2872}
2873
2874void LocationsBuilderMIPS64::VisitPhi(HPhi* instruction) {
2875 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2876 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2877 locations->SetInAt(i, Location::Any());
2878 }
2879 locations->SetOut(Location::Any());
2880}
2881
2882void InstructionCodeGeneratorMIPS64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
2883 LOG(FATAL) << "Unreachable";
2884}
2885
2886void LocationsBuilderMIPS64::VisitRem(HRem* rem) {
2887 Primitive::Type type = rem->GetResultType();
2888 LocationSummary::CallKind call_kind =
2889 Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall;
2890 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2891
2892 switch (type) {
2893 case Primitive::kPrimInt:
2894 case Primitive::kPrimLong:
2895 locations->SetInAt(0, Location::RequiresRegister());
2896 locations->SetInAt(1, Location::RequiresRegister());
2897 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2898 break;
2899
2900 case Primitive::kPrimFloat:
2901 case Primitive::kPrimDouble: {
2902 InvokeRuntimeCallingConvention calling_convention;
2903 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2904 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2905 locations->SetOut(calling_convention.GetReturnLocation(type));
2906 break;
2907 }
2908
2909 default:
2910 LOG(FATAL) << "Unexpected rem type " << type;
2911 }
2912}
2913
2914void InstructionCodeGeneratorMIPS64::VisitRem(HRem* instruction) {
2915 Primitive::Type type = instruction->GetType();
2916 LocationSummary* locations = instruction->GetLocations();
2917
2918 switch (type) {
2919 case Primitive::kPrimInt:
2920 case Primitive::kPrimLong: {
2921 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2922 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
2923 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
2924 if (type == Primitive::kPrimInt)
2925 __ ModR6(dst, lhs, rhs);
2926 else
2927 __ Dmod(dst, lhs, rhs);
2928 break;
2929 }
2930
2931 case Primitive::kPrimFloat:
2932 case Primitive::kPrimDouble: {
2933 int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf)
2934 : QUICK_ENTRY_POINT(pFmod);
2935 codegen_->InvokeRuntime(entry_offset, instruction, instruction->GetDexPc(), nullptr);
2936 break;
2937 }
2938 default:
2939 LOG(FATAL) << "Unexpected rem type " << type;
2940 }
2941}
2942
2943void LocationsBuilderMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
2944 memory_barrier->SetLocations(nullptr);
2945}
2946
2947void InstructionCodeGeneratorMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
2948 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
2949}
2950
2951void LocationsBuilderMIPS64::VisitReturn(HReturn* ret) {
2952 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret);
2953 Primitive::Type return_type = ret->InputAt(0)->GetType();
2954 locations->SetInAt(0, Mips64ReturnLocation(return_type));
2955}
2956
2957void InstructionCodeGeneratorMIPS64::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
2958 codegen_->GenerateFrameExit();
2959}
2960
2961void LocationsBuilderMIPS64::VisitReturnVoid(HReturnVoid* ret) {
2962 ret->SetLocations(nullptr);
2963}
2964
2965void InstructionCodeGeneratorMIPS64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
2966 codegen_->GenerateFrameExit();
2967}
2968
2969void LocationsBuilderMIPS64::VisitShl(HShl* shl) {
2970 HandleShift(shl);
2971}
2972
2973void InstructionCodeGeneratorMIPS64::VisitShl(HShl* shl) {
2974 HandleShift(shl);
2975}
2976
2977void LocationsBuilderMIPS64::VisitShr(HShr* shr) {
2978 HandleShift(shr);
2979}
2980
2981void InstructionCodeGeneratorMIPS64::VisitShr(HShr* shr) {
2982 HandleShift(shr);
2983}
2984
2985void LocationsBuilderMIPS64::VisitStoreLocal(HStoreLocal* store) {
2986 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store);
2987 Primitive::Type field_type = store->InputAt(1)->GetType();
2988 switch (field_type) {
2989 case Primitive::kPrimNot:
2990 case Primitive::kPrimBoolean:
2991 case Primitive::kPrimByte:
2992 case Primitive::kPrimChar:
2993 case Primitive::kPrimShort:
2994 case Primitive::kPrimInt:
2995 case Primitive::kPrimFloat:
2996 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
2997 break;
2998
2999 case Primitive::kPrimLong:
3000 case Primitive::kPrimDouble:
3001 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
3002 break;
3003
3004 default:
3005 LOG(FATAL) << "Unimplemented local type " << field_type;
3006 }
3007}
3008
3009void InstructionCodeGeneratorMIPS64::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) {
3010}
3011
3012void LocationsBuilderMIPS64::VisitSub(HSub* instruction) {
3013 HandleBinaryOp(instruction);
3014}
3015
3016void InstructionCodeGeneratorMIPS64::VisitSub(HSub* instruction) {
3017 HandleBinaryOp(instruction);
3018}
3019
3020void LocationsBuilderMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3021 HandleFieldGet(instruction, instruction->GetFieldInfo());
3022}
3023
3024void InstructionCodeGeneratorMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3025 HandleFieldGet(instruction, instruction->GetFieldInfo());
3026}
3027
3028void LocationsBuilderMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3029 HandleFieldSet(instruction, instruction->GetFieldInfo());
3030}
3031
3032void InstructionCodeGeneratorMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3033 HandleFieldSet(instruction, instruction->GetFieldInfo());
3034}
3035
3036void LocationsBuilderMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) {
3037 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3038}
3039
3040void InstructionCodeGeneratorMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) {
3041 HBasicBlock* block = instruction->GetBlock();
3042 if (block->GetLoopInformation() != nullptr) {
3043 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3044 // The back edge will generate the suspend check.
3045 return;
3046 }
3047 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3048 // The goto will generate the suspend check.
3049 return;
3050 }
3051 GenerateSuspendCheck(instruction, nullptr);
3052}
3053
3054void LocationsBuilderMIPS64::VisitTemporary(HTemporary* temp) {
3055 temp->SetLocations(nullptr);
3056}
3057
3058void InstructionCodeGeneratorMIPS64::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) {
3059 // Nothing to do, this is driven by the code generator.
3060}
3061
3062void LocationsBuilderMIPS64::VisitThrow(HThrow* instruction) {
3063 LocationSummary* locations =
3064 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3065 InvokeRuntimeCallingConvention calling_convention;
3066 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3067}
3068
3069void InstructionCodeGeneratorMIPS64::VisitThrow(HThrow* instruction) {
3070 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException),
3071 instruction,
3072 instruction->GetDexPc(),
3073 nullptr);
3074 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
3075}
3076
3077void LocationsBuilderMIPS64::VisitTypeConversion(HTypeConversion* conversion) {
3078 Primitive::Type input_type = conversion->GetInputType();
3079 Primitive::Type result_type = conversion->GetResultType();
3080 DCHECK_NE(input_type, result_type);
3081
3082 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
3083 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
3084 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
3085 }
3086
3087 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
3088 if ((Primitive::IsFloatingPointType(result_type) && input_type == Primitive::kPrimLong) ||
3089 (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type))) {
3090 call_kind = LocationSummary::kCall;
3091 }
3092
3093 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
3094
3095 if (call_kind == LocationSummary::kNoCall) {
3096 if (Primitive::IsFloatingPointType(input_type)) {
3097 locations->SetInAt(0, Location::RequiresFpuRegister());
3098 } else {
3099 locations->SetInAt(0, Location::RequiresRegister());
3100 }
3101
3102 if (Primitive::IsFloatingPointType(result_type)) {
3103 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3104 } else {
3105 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3106 }
3107 } else {
3108 InvokeRuntimeCallingConvention calling_convention;
3109
3110 if (Primitive::IsFloatingPointType(input_type)) {
3111 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
3112 } else {
3113 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3114 }
3115
3116 locations->SetOut(calling_convention.GetReturnLocation(result_type));
3117 }
3118}
3119
3120void InstructionCodeGeneratorMIPS64::VisitTypeConversion(HTypeConversion* conversion) {
3121 LocationSummary* locations = conversion->GetLocations();
3122 Primitive::Type result_type = conversion->GetResultType();
3123 Primitive::Type input_type = conversion->GetInputType();
3124
3125 DCHECK_NE(input_type, result_type);
3126
3127 if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
3128 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3129 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
3130
3131 switch (result_type) {
3132 case Primitive::kPrimChar:
3133 __ Andi(dst, src, 0xFFFF);
3134 break;
3135 case Primitive::kPrimByte:
3136 // long is never converted into types narrower than int directly,
3137 // so SEB and SEH can be used without ever causing unpredictable results
3138 // on 64-bit inputs
3139 DCHECK(input_type != Primitive::kPrimLong);
3140 __ Seb(dst, src);
3141 break;
3142 case Primitive::kPrimShort:
3143 // long is never converted into types narrower than int directly,
3144 // so SEB and SEH can be used without ever causing unpredictable results
3145 // on 64-bit inputs
3146 DCHECK(input_type != Primitive::kPrimLong);
3147 __ Seh(dst, src);
3148 break;
3149 case Primitive::kPrimInt:
3150 case Primitive::kPrimLong:
3151 // Sign-extend 32-bit int into bits 32 through 63 for
3152 // int-to-long and long-to-int conversions
3153 __ Sll(dst, src, 0);
3154 break;
3155
3156 default:
3157 LOG(FATAL) << "Unexpected type conversion from " << input_type
3158 << " to " << result_type;
3159 }
3160 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
3161 if (input_type != Primitive::kPrimLong) {
3162 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
3163 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
3164 __ Mtc1(src, FTMP);
3165 if (result_type == Primitive::kPrimFloat) {
3166 __ Cvtsw(dst, FTMP);
3167 } else {
3168 __ Cvtdw(dst, FTMP);
3169 }
3170 } else {
3171 int32_t entry_offset = (result_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pL2f)
3172 : QUICK_ENTRY_POINT(pL2d);
3173 codegen_->InvokeRuntime(entry_offset,
3174 conversion,
3175 conversion->GetDexPc(),
3176 nullptr);
3177 }
3178 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
3179 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
3180 int32_t entry_offset;
3181 if (result_type != Primitive::kPrimLong) {
3182 entry_offset = (input_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pF2iz)
3183 : QUICK_ENTRY_POINT(pD2iz);
3184 } else {
3185 entry_offset = (input_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pF2l)
3186 : QUICK_ENTRY_POINT(pD2l);
3187 }
3188 codegen_->InvokeRuntime(entry_offset,
3189 conversion,
3190 conversion->GetDexPc(),
3191 nullptr);
3192 } else if (Primitive::IsFloatingPointType(result_type) &&
3193 Primitive::IsFloatingPointType(input_type)) {
3194 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
3195 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
3196 if (result_type == Primitive::kPrimFloat) {
3197 __ Cvtsd(dst, src);
3198 } else {
3199 __ Cvtds(dst, src);
3200 }
3201 } else {
3202 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
3203 << " to " << result_type;
3204 }
3205}
3206
3207void LocationsBuilderMIPS64::VisitUShr(HUShr* ushr) {
3208 HandleShift(ushr);
3209}
3210
3211void InstructionCodeGeneratorMIPS64::VisitUShr(HUShr* ushr) {
3212 HandleShift(ushr);
3213}
3214
3215void LocationsBuilderMIPS64::VisitXor(HXor* instruction) {
3216 HandleBinaryOp(instruction);
3217}
3218
3219void InstructionCodeGeneratorMIPS64::VisitXor(HXor* instruction) {
3220 HandleBinaryOp(instruction);
3221}
3222
3223void LocationsBuilderMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
3224 // Nothing to do, this should be removed during prepare for register allocator.
3225 LOG(FATAL) << "Unreachable";
3226}
3227
3228void InstructionCodeGeneratorMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
3229 // Nothing to do, this should be removed during prepare for register allocator.
3230 LOG(FATAL) << "Unreachable";
3231}
3232
3233void LocationsBuilderMIPS64::VisitEqual(HEqual* comp) {
3234 VisitCondition(comp);
3235}
3236
3237void InstructionCodeGeneratorMIPS64::VisitEqual(HEqual* comp) {
3238 VisitCondition(comp);
3239}
3240
3241void LocationsBuilderMIPS64::VisitNotEqual(HNotEqual* comp) {
3242 VisitCondition(comp);
3243}
3244
3245void InstructionCodeGeneratorMIPS64::VisitNotEqual(HNotEqual* comp) {
3246 VisitCondition(comp);
3247}
3248
3249void LocationsBuilderMIPS64::VisitLessThan(HLessThan* comp) {
3250 VisitCondition(comp);
3251}
3252
3253void InstructionCodeGeneratorMIPS64::VisitLessThan(HLessThan* comp) {
3254 VisitCondition(comp);
3255}
3256
3257void LocationsBuilderMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
3258 VisitCondition(comp);
3259}
3260
3261void InstructionCodeGeneratorMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
3262 VisitCondition(comp);
3263}
3264
3265void LocationsBuilderMIPS64::VisitGreaterThan(HGreaterThan* comp) {
3266 VisitCondition(comp);
3267}
3268
3269void InstructionCodeGeneratorMIPS64::VisitGreaterThan(HGreaterThan* comp) {
3270 VisitCondition(comp);
3271}
3272
3273void LocationsBuilderMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
3274 VisitCondition(comp);
3275}
3276
3277void InstructionCodeGeneratorMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
3278 VisitCondition(comp);
3279}
3280
3281} // namespace mips64
3282} // namespace art