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