blob: b6d67de18125d7dcaab7b0ed65fde7d29cc03b04 [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:
297 explicit SuspendCheckSlowPathMIPS64(HSuspendCheck* instruction,
298 HBasicBlock* successor)
299 : instruction_(instruction), successor_(successor) {}
300
301 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
302 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
303 __ Bind(GetEntryLabel());
304 SaveLiveRegisters(codegen, instruction_->GetLocations());
305 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend),
306 instruction_,
307 instruction_->GetDexPc(),
308 this);
309 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
310 RestoreLiveRegisters(codegen, instruction_->GetLocations());
311 if (successor_ == nullptr) {
312 __ B(GetReturnLabel());
313 } else {
314 __ B(mips64_codegen->GetLabelOf(successor_));
315 }
316 }
317
318 Label* GetReturnLabel() {
319 DCHECK(successor_ == nullptr);
320 return &return_label_;
321 }
322
Roland Levillain46648892015-06-19 16:07:18 +0100323 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS64"; }
324
Alexey Frunze4dda3372015-06-01 18:31:49 -0700325 private:
326 HSuspendCheck* const instruction_;
327 // If not null, the block to branch to after the suspend check.
328 HBasicBlock* const successor_;
329
330 // If `successor_` is null, the label to branch to after the suspend check.
331 Label return_label_;
332
333 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS64);
334};
335
336class TypeCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
337 public:
338 TypeCheckSlowPathMIPS64(HInstruction* instruction,
339 Location class_to_check,
340 Location object_class,
341 uint32_t dex_pc)
342 : instruction_(instruction),
343 class_to_check_(class_to_check),
344 object_class_(object_class),
345 dex_pc_(dex_pc) {}
346
347 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
348 LocationSummary* locations = instruction_->GetLocations();
349 DCHECK(instruction_->IsCheckCast()
350 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
351 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
352
353 __ Bind(GetEntryLabel());
354 SaveLiveRegisters(codegen, locations);
355
356 // We're moving two locations to locations that could overlap, so we need a parallel
357 // move resolver.
358 InvokeRuntimeCallingConvention calling_convention;
359 codegen->EmitParallelMoves(class_to_check_,
360 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
361 Primitive::kPrimNot,
362 object_class_,
363 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
364 Primitive::kPrimNot);
365
366 if (instruction_->IsInstanceOf()) {
367 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial),
368 instruction_,
369 dex_pc_,
370 this);
371 Primitive::Type ret_type = instruction_->GetType();
372 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
373 mips64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
374 CheckEntrypointTypes<kQuickInstanceofNonTrivial,
375 uint32_t,
376 const mirror::Class*,
377 const mirror::Class*>();
378 } else {
379 DCHECK(instruction_->IsCheckCast());
380 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_, this);
381 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
382 }
383
384 RestoreLiveRegisters(codegen, locations);
385 __ B(GetExitLabel());
386 }
387
Roland Levillain46648892015-06-19 16:07:18 +0100388 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS64"; }
389
Alexey Frunze4dda3372015-06-01 18:31:49 -0700390 private:
391 HInstruction* const instruction_;
392 const Location class_to_check_;
393 const Location object_class_;
394 uint32_t dex_pc_;
395
396 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS64);
397};
398
399class DeoptimizationSlowPathMIPS64 : public SlowPathCodeMIPS64 {
400 public:
401 explicit DeoptimizationSlowPathMIPS64(HInstruction* instruction)
402 : instruction_(instruction) {}
403
404 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
405 __ Bind(GetEntryLabel());
406 SaveLiveRegisters(codegen, instruction_->GetLocations());
407 DCHECK(instruction_->IsDeoptimize());
408 HDeoptimize* deoptimize = instruction_->AsDeoptimize();
409 uint32_t dex_pc = deoptimize->GetDexPc();
410 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
411 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this);
412 }
413
Roland Levillain46648892015-06-19 16:07:18 +0100414 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS64"; }
415
Alexey Frunze4dda3372015-06-01 18:31:49 -0700416 private:
417 HInstruction* const instruction_;
418 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS64);
419};
420
421CodeGeneratorMIPS64::CodeGeneratorMIPS64(HGraph* graph,
422 const Mips64InstructionSetFeatures& isa_features,
423 const CompilerOptions& compiler_options)
424 : CodeGenerator(graph,
425 kNumberOfGpuRegisters,
426 kNumberOfFpuRegisters,
427 0, // kNumberOfRegisterPairs
428 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
429 arraysize(kCoreCalleeSaves)),
430 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
431 arraysize(kFpuCalleeSaves)),
432 compiler_options),
433 block_labels_(graph->GetArena(), 0),
434 location_builder_(graph, this),
435 instruction_visitor_(graph, this),
436 move_resolver_(graph->GetArena(), this),
437 isa_features_(isa_features) {
438 // Save RA (containing the return address) to mimic Quick.
439 AddAllocatedRegister(Location::RegisterLocation(RA));
440}
441
442#undef __
443#define __ down_cast<Mips64Assembler*>(GetAssembler())->
444#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64WordSize, x).Int32Value()
445
446void CodeGeneratorMIPS64::Finalize(CodeAllocator* allocator) {
447 CodeGenerator::Finalize(allocator);
448}
449
450Mips64Assembler* ParallelMoveResolverMIPS64::GetAssembler() const {
451 return codegen_->GetAssembler();
452}
453
454void ParallelMoveResolverMIPS64::EmitMove(size_t index) {
455 MoveOperands* move = moves_.Get(index);
456 codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType());
457}
458
459void ParallelMoveResolverMIPS64::EmitSwap(size_t index) {
460 MoveOperands* move = moves_.Get(index);
461 codegen_->SwapLocations(move->GetDestination(), move->GetSource(), move->GetType());
462}
463
464void ParallelMoveResolverMIPS64::RestoreScratch(int reg) {
465 // Pop reg
466 __ Ld(GpuRegister(reg), SP, 0);
467 __ DecreaseFrameSize(kMips64WordSize);
468}
469
470void ParallelMoveResolverMIPS64::SpillScratch(int reg) {
471 // Push reg
472 __ IncreaseFrameSize(kMips64WordSize);
473 __ Sd(GpuRegister(reg), SP, 0);
474}
475
476void ParallelMoveResolverMIPS64::Exchange(int index1, int index2, bool double_slot) {
477 LoadOperandType load_type = double_slot ? kLoadDoubleword : kLoadWord;
478 StoreOperandType store_type = double_slot ? kStoreDoubleword : kStoreWord;
479 // Allocate a scratch register other than TMP, if available.
480 // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be
481 // automatically unspilled when the scratch scope object is destroyed).
482 ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters());
483 // If V0 spills onto the stack, SP-relative offsets need to be adjusted.
484 int stack_offset = ensure_scratch.IsSpilled() ? kMips64WordSize : 0;
485 __ LoadFromOffset(load_type,
486 GpuRegister(ensure_scratch.GetRegister()),
487 SP,
488 index1 + stack_offset);
489 __ LoadFromOffset(load_type,
490 TMP,
491 SP,
492 index2 + stack_offset);
493 __ StoreToOffset(store_type,
494 GpuRegister(ensure_scratch.GetRegister()),
495 SP,
496 index2 + stack_offset);
497 __ StoreToOffset(store_type, TMP, SP, index1 + stack_offset);
498}
499
500static dwarf::Reg DWARFReg(GpuRegister reg) {
501 return dwarf::Reg::Mips64Core(static_cast<int>(reg));
502}
503
504// TODO: mapping of floating-point registers to DWARF
505
506void CodeGeneratorMIPS64::GenerateFrameEntry() {
507 __ Bind(&frame_entry_label_);
508
509 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips64) || !IsLeafMethod();
510
511 if (do_overflow_check) {
512 __ LoadFromOffset(kLoadWord,
513 ZERO,
514 SP,
515 -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips64)));
516 RecordPcInfo(nullptr, 0);
517 }
518
519 // TODO: anything related to T9/GP/GOT/PIC/.so's?
520
521 if (HasEmptyFrame()) {
522 return;
523 }
524
525 // Make sure the frame size isn't unreasonably large. Per the various APIs
526 // it looks like it should always be less than 2GB in size, which allows
527 // us using 32-bit signed offsets from the stack pointer.
528 if (GetFrameSize() > 0x7FFFFFFF)
529 LOG(FATAL) << "Stack frame larger than 2GB";
530
531 // Spill callee-saved registers.
532 // Note that their cumulative size is small and they can be indexed using
533 // 16-bit offsets.
534
535 // TODO: increment/decrement SP in one step instead of two or remove this comment.
536
537 uint32_t ofs = FrameEntrySpillSize();
538 __ IncreaseFrameSize(ofs);
539
540 for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) {
541 GpuRegister reg = kCoreCalleeSaves[i];
542 if (allocated_registers_.ContainsCoreRegister(reg)) {
543 ofs -= kMips64WordSize;
544 __ Sd(reg, SP, ofs);
545 __ cfi().RelOffset(DWARFReg(reg), ofs);
546 }
547 }
548
549 for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) {
550 FpuRegister reg = kFpuCalleeSaves[i];
551 if (allocated_registers_.ContainsFloatingPointRegister(reg)) {
552 ofs -= kMips64WordSize;
553 __ Sdc1(reg, SP, ofs);
554 // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs);
555 }
556 }
557
558 // Allocate the rest of the frame and store the current method pointer
559 // at its end.
560
561 __ IncreaseFrameSize(GetFrameSize() - FrameEntrySpillSize());
562
563 static_assert(IsInt<16>(kCurrentMethodStackOffset),
564 "kCurrentMethodStackOffset must fit into int16_t");
565 __ Sd(kMethodRegisterArgument, SP, kCurrentMethodStackOffset);
566}
567
568void CodeGeneratorMIPS64::GenerateFrameExit() {
569 __ cfi().RememberState();
570
571 // TODO: anything related to T9/GP/GOT/PIC/.so's?
572
573 if (!HasEmptyFrame()) {
574 // Deallocate the rest of the frame.
575
576 __ DecreaseFrameSize(GetFrameSize() - FrameEntrySpillSize());
577
578 // Restore callee-saved registers.
579 // Note that their cumulative size is small and they can be indexed using
580 // 16-bit offsets.
581
582 // TODO: increment/decrement SP in one step instead of two or remove this comment.
583
584 uint32_t ofs = 0;
585
586 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
587 FpuRegister reg = kFpuCalleeSaves[i];
588 if (allocated_registers_.ContainsFloatingPointRegister(reg)) {
589 __ Ldc1(reg, SP, ofs);
590 ofs += kMips64WordSize;
591 // TODO: __ cfi().Restore(DWARFReg(reg));
592 }
593 }
594
595 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
596 GpuRegister reg = kCoreCalleeSaves[i];
597 if (allocated_registers_.ContainsCoreRegister(reg)) {
598 __ Ld(reg, SP, ofs);
599 ofs += kMips64WordSize;
600 __ cfi().Restore(DWARFReg(reg));
601 }
602 }
603
604 DCHECK_EQ(ofs, FrameEntrySpillSize());
605 __ DecreaseFrameSize(ofs);
606 }
607
608 __ Jr(RA);
609
610 __ cfi().RestoreState();
611 __ cfi().DefCFAOffset(GetFrameSize());
612}
613
614void CodeGeneratorMIPS64::Bind(HBasicBlock* block) {
615 __ Bind(GetLabelOf(block));
616}
617
618void CodeGeneratorMIPS64::MoveLocation(Location destination,
619 Location source,
620 Primitive::Type type) {
621 if (source.Equals(destination)) {
622 return;
623 }
624
625 // A valid move can always be inferred from the destination and source
626 // locations. When moving from and to a register, the argument type can be
627 // used to generate 32bit instead of 64bit moves.
628 bool unspecified_type = (type == Primitive::kPrimVoid);
629 DCHECK_EQ(unspecified_type, false);
630
631 if (destination.IsRegister() || destination.IsFpuRegister()) {
632 if (unspecified_type) {
633 HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr;
634 if (source.IsStackSlot() ||
635 (src_cst != nullptr && (src_cst->IsIntConstant()
636 || src_cst->IsFloatConstant()
637 || src_cst->IsNullConstant()))) {
638 // For stack slots and 32bit constants, a 64bit type is appropriate.
639 type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat;
640 } else {
641 // If the source is a double stack slot or a 64bit constant, a 64bit
642 // type is appropriate. Else the source is a register, and since the
643 // type has not been specified, we chose a 64bit type to force a 64bit
644 // move.
645 type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble;
646 }
647 }
648 DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(type)) ||
649 (destination.IsRegister() && !Primitive::IsFloatingPointType(type)));
650 if (source.IsStackSlot() || source.IsDoubleStackSlot()) {
651 // Move to GPR/FPR from stack
652 LoadOperandType load_type = source.IsStackSlot() ? kLoadWord : kLoadDoubleword;
653 if (Primitive::IsFloatingPointType(type)) {
654 __ LoadFpuFromOffset(load_type,
655 destination.AsFpuRegister<FpuRegister>(),
656 SP,
657 source.GetStackIndex());
658 } else {
659 // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot.
660 __ LoadFromOffset(load_type,
661 destination.AsRegister<GpuRegister>(),
662 SP,
663 source.GetStackIndex());
664 }
665 } else if (source.IsConstant()) {
666 // Move to GPR/FPR from constant
667 GpuRegister gpr = AT;
668 if (!Primitive::IsFloatingPointType(type)) {
669 gpr = destination.AsRegister<GpuRegister>();
670 }
671 if (type == Primitive::kPrimInt || type == Primitive::kPrimFloat) {
672 __ LoadConst32(gpr, GetInt32ValueOf(source.GetConstant()->AsConstant()));
673 } else {
674 __ LoadConst64(gpr, GetInt64ValueOf(source.GetConstant()->AsConstant()));
675 }
676 if (type == Primitive::kPrimFloat) {
677 __ Mtc1(gpr, destination.AsFpuRegister<FpuRegister>());
678 } else if (type == Primitive::kPrimDouble) {
679 __ Dmtc1(gpr, destination.AsFpuRegister<FpuRegister>());
680 }
681 } else {
682 if (destination.IsRegister()) {
683 // Move to GPR from GPR
684 __ Move(destination.AsRegister<GpuRegister>(), source.AsRegister<GpuRegister>());
685 } else {
686 // Move to FPR from FPR
687 if (type == Primitive::kPrimFloat) {
688 __ MovS(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>());
689 } else {
690 DCHECK_EQ(type, Primitive::kPrimDouble);
691 __ MovD(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>());
692 }
693 }
694 }
695 } else { // The destination is not a register. It must be a stack slot.
696 DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot());
697 if (source.IsRegister() || source.IsFpuRegister()) {
698 if (unspecified_type) {
699 if (source.IsRegister()) {
700 type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong;
701 } else {
702 type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble;
703 }
704 }
705 DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(type)) &&
706 (source.IsFpuRegister() == Primitive::IsFloatingPointType(type)));
707 // Move to stack from GPR/FPR
708 StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword;
709 if (source.IsRegister()) {
710 __ StoreToOffset(store_type,
711 source.AsRegister<GpuRegister>(),
712 SP,
713 destination.GetStackIndex());
714 } else {
715 __ StoreFpuToOffset(store_type,
716 source.AsFpuRegister<FpuRegister>(),
717 SP,
718 destination.GetStackIndex());
719 }
720 } else if (source.IsConstant()) {
721 // Move to stack from constant
722 HConstant* src_cst = source.GetConstant();
723 StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword;
724 if (destination.IsStackSlot()) {
725 __ LoadConst32(TMP, GetInt32ValueOf(src_cst->AsConstant()));
726 } else {
727 __ LoadConst64(TMP, GetInt64ValueOf(src_cst->AsConstant()));
728 }
729 __ StoreToOffset(store_type, TMP, SP, destination.GetStackIndex());
730 } else {
731 DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot());
732 DCHECK_EQ(source.IsDoubleStackSlot(), destination.IsDoubleStackSlot());
733 // Move to stack from stack
734 if (destination.IsStackSlot()) {
735 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
736 __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex());
737 } else {
738 __ LoadFromOffset(kLoadDoubleword, TMP, SP, source.GetStackIndex());
739 __ StoreToOffset(kStoreDoubleword, TMP, SP, destination.GetStackIndex());
740 }
741 }
742 }
743}
744
745void CodeGeneratorMIPS64::SwapLocations(Location loc1,
746 Location loc2,
747 Primitive::Type type ATTRIBUTE_UNUSED) {
748 DCHECK(!loc1.IsConstant());
749 DCHECK(!loc2.IsConstant());
750
751 if (loc1.Equals(loc2)) {
752 return;
753 }
754
755 bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot();
756 bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot();
757 bool is_fp_reg1 = loc1.IsFpuRegister();
758 bool is_fp_reg2 = loc2.IsFpuRegister();
759
760 if (loc2.IsRegister() && loc1.IsRegister()) {
761 // Swap 2 GPRs
762 GpuRegister r1 = loc1.AsRegister<GpuRegister>();
763 GpuRegister r2 = loc2.AsRegister<GpuRegister>();
764 __ Move(TMP, r2);
765 __ Move(r2, r1);
766 __ Move(r1, TMP);
767 } else if (is_fp_reg2 && is_fp_reg1) {
768 // Swap 2 FPRs
769 FpuRegister r1 = loc1.AsFpuRegister<FpuRegister>();
770 FpuRegister r2 = loc2.AsFpuRegister<FpuRegister>();
771 // TODO: Can MOV.S/MOV.D be used here to save one instruction?
772 // Need to distinguish float from double, right?
773 __ Dmfc1(TMP, r2);
774 __ Dmfc1(AT, r1);
775 __ Dmtc1(TMP, r1);
776 __ Dmtc1(AT, r2);
777 } else if (is_slot1 != is_slot2) {
778 // Swap GPR/FPR and stack slot
779 Location reg_loc = is_slot1 ? loc2 : loc1;
780 Location mem_loc = is_slot1 ? loc1 : loc2;
781 LoadOperandType load_type = mem_loc.IsStackSlot() ? kLoadWord : kLoadDoubleword;
782 StoreOperandType store_type = mem_loc.IsStackSlot() ? kStoreWord : kStoreDoubleword;
783 // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot.
784 __ LoadFromOffset(load_type, TMP, SP, mem_loc.GetStackIndex());
785 if (reg_loc.IsFpuRegister()) {
786 __ StoreFpuToOffset(store_type,
787 reg_loc.AsFpuRegister<FpuRegister>(),
788 SP,
789 mem_loc.GetStackIndex());
790 // TODO: review this MTC1/DMTC1 move
791 if (mem_loc.IsStackSlot()) {
792 __ Mtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>());
793 } else {
794 DCHECK(mem_loc.IsDoubleStackSlot());
795 __ Dmtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>());
796 }
797 } else {
798 __ StoreToOffset(store_type, reg_loc.AsRegister<GpuRegister>(), SP, mem_loc.GetStackIndex());
799 __ Move(reg_loc.AsRegister<GpuRegister>(), TMP);
800 }
801 } else if (is_slot1 && is_slot2) {
802 move_resolver_.Exchange(loc1.GetStackIndex(),
803 loc2.GetStackIndex(),
804 loc1.IsDoubleStackSlot());
805 } else {
806 LOG(FATAL) << "Unimplemented swap between locations " << loc1 << " and " << loc2;
807 }
808}
809
810void CodeGeneratorMIPS64::Move(HInstruction* instruction,
811 Location location,
812 HInstruction* move_for) {
813 LocationSummary* locations = instruction->GetLocations();
814 Primitive::Type type = instruction->GetType();
815 DCHECK_NE(type, Primitive::kPrimVoid);
816
817 if (instruction->IsCurrentMethod()) {
818 MoveLocation(location, Location::DoubleStackSlot(kCurrentMethodStackOffset), type);
819 } else if (locations != nullptr && locations->Out().Equals(location)) {
820 return;
821 } else if (instruction->IsIntConstant()
822 || instruction->IsLongConstant()
823 || instruction->IsNullConstant()) {
824 if (location.IsRegister()) {
825 // Move to GPR from constant
826 GpuRegister dst = location.AsRegister<GpuRegister>();
827 if (instruction->IsNullConstant() || instruction->IsIntConstant()) {
828 __ LoadConst32(dst, GetInt32ValueOf(instruction->AsConstant()));
829 } else {
830 __ LoadConst64(dst, instruction->AsLongConstant()->GetValue());
831 }
832 } else {
833 DCHECK(location.IsStackSlot() || location.IsDoubleStackSlot());
834 // Move to stack from constant
835 if (location.IsStackSlot()) {
836 __ LoadConst32(TMP, GetInt32ValueOf(instruction->AsConstant()));
837 __ StoreToOffset(kStoreWord, TMP, SP, location.GetStackIndex());
838 } else {
839 __ LoadConst64(TMP, instruction->AsLongConstant()->GetValue());
840 __ StoreToOffset(kStoreDoubleword, TMP, SP, location.GetStackIndex());
841 }
842 }
843 } else if (instruction->IsTemporary()) {
844 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
845 MoveLocation(location, temp_location, type);
846 } else if (instruction->IsLoadLocal()) {
847 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
848 if (Primitive::Is64BitType(type)) {
849 MoveLocation(location, Location::DoubleStackSlot(stack_slot), type);
850 } else {
851 MoveLocation(location, Location::StackSlot(stack_slot), type);
852 }
853 } else {
854 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
855 MoveLocation(location, locations->Out(), type);
856 }
857}
858
859Location CodeGeneratorMIPS64::GetStackLocation(HLoadLocal* load) const {
860 Primitive::Type type = load->GetType();
861
862 switch (type) {
863 case Primitive::kPrimNot:
864 case Primitive::kPrimInt:
865 case Primitive::kPrimFloat:
866 return Location::StackSlot(GetStackSlot(load->GetLocal()));
867
868 case Primitive::kPrimLong:
869 case Primitive::kPrimDouble:
870 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
871
872 case Primitive::kPrimBoolean:
873 case Primitive::kPrimByte:
874 case Primitive::kPrimChar:
875 case Primitive::kPrimShort:
876 case Primitive::kPrimVoid:
877 LOG(FATAL) << "Unexpected type " << type;
878 }
879
880 LOG(FATAL) << "Unreachable";
881 return Location::NoLocation();
882}
883
884void CodeGeneratorMIPS64::MarkGCCard(GpuRegister object, GpuRegister value) {
885 Label done;
886 GpuRegister card = AT;
887 GpuRegister temp = TMP;
888 __ Beqzc(value, &done);
889 __ LoadFromOffset(kLoadDoubleword,
890 card,
891 TR,
892 Thread::CardTableOffset<kMips64WordSize>().Int32Value());
893 __ Dsrl(temp, object, gc::accounting::CardTable::kCardShift);
894 __ Daddu(temp, card, temp);
895 __ Sb(card, temp, 0);
896 __ Bind(&done);
897}
898
899void CodeGeneratorMIPS64::SetupBlockedRegisters(bool is_baseline ATTRIBUTE_UNUSED) const {
900 // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated.
901 blocked_core_registers_[ZERO] = true;
902 blocked_core_registers_[K0] = true;
903 blocked_core_registers_[K1] = true;
904 blocked_core_registers_[GP] = true;
905 blocked_core_registers_[SP] = true;
906 blocked_core_registers_[RA] = true;
907
908 // AT and TMP(T8) are used as temporary/scratch registers
909 // (similar to how AT is used by MIPS assemblers).
910 blocked_core_registers_[AT] = true;
911 blocked_core_registers_[TMP] = true;
912 blocked_fpu_registers_[FTMP] = true;
913
914 // Reserve suspend and thread registers.
915 blocked_core_registers_[S0] = true;
916 blocked_core_registers_[TR] = true;
917
918 // Reserve T9 for function calls
919 blocked_core_registers_[T9] = true;
920
921 // TODO: review; anything else?
922
923 // TODO: make these two for's conditional on is_baseline once
924 // all the issues with register saving/restoring are sorted out.
925 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
926 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
927 }
928
929 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
930 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
931 }
932}
933
934Location CodeGeneratorMIPS64::AllocateFreeRegister(Primitive::Type type) const {
935 if (type == Primitive::kPrimVoid) {
936 LOG(FATAL) << "Unreachable type " << type;
937 }
938
939 if (Primitive::IsFloatingPointType(type)) {
940 size_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfFpuRegisters);
941 return Location::FpuRegisterLocation(reg);
942 } else {
943 size_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfGpuRegisters);
944 return Location::RegisterLocation(reg);
945 }
946}
947
948size_t CodeGeneratorMIPS64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
949 __ StoreToOffset(kStoreDoubleword, GpuRegister(reg_id), SP, stack_index);
950 return kMips64WordSize;
951}
952
953size_t CodeGeneratorMIPS64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
954 __ LoadFromOffset(kLoadDoubleword, GpuRegister(reg_id), SP, stack_index);
955 return kMips64WordSize;
956}
957
958size_t CodeGeneratorMIPS64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
959 __ StoreFpuToOffset(kStoreDoubleword, FpuRegister(reg_id), SP, stack_index);
960 return kMips64WordSize;
961}
962
963size_t CodeGeneratorMIPS64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
964 __ LoadFpuFromOffset(kLoadDoubleword, FpuRegister(reg_id), SP, stack_index);
965 return kMips64WordSize;
966}
967
968void CodeGeneratorMIPS64::DumpCoreRegister(std::ostream& stream, int reg) const {
969 stream << Mips64ManagedRegister::FromGpuRegister(GpuRegister(reg));
970}
971
972void CodeGeneratorMIPS64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
973 stream << Mips64ManagedRegister::FromFpuRegister(FpuRegister(reg));
974}
975
976void CodeGeneratorMIPS64::InvokeRuntime(int32_t entry_point_offset,
977 HInstruction* instruction,
978 uint32_t dex_pc,
979 SlowPathCode* slow_path) {
Alexandre Rames8158f282015-08-07 10:26:17 +0100980 // Ensure that the call kind indication given to the register allocator is
981 // coherent with the runtime call generated.
982 if (slow_path == nullptr) {
983 DCHECK(instruction->GetLocations()->WillCall());
984 } else {
985 DCHECK(instruction->GetLocations()->OnlyCallsOnSlowPath() || slow_path->IsFatal());
986 }
987
Alexey Frunze4dda3372015-06-01 18:31:49 -0700988 // TODO: anything related to T9/GP/GOT/PIC/.so's?
989 __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset);
990 __ Jalr(T9);
991 RecordPcInfo(instruction, dex_pc, slow_path);
992 DCHECK(instruction->IsSuspendCheck()
993 || instruction->IsBoundsCheck()
994 || instruction->IsNullCheck()
995 || instruction->IsDivZeroCheck()
996 || !IsLeafMethod());
997}
998
999void InstructionCodeGeneratorMIPS64::GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path,
1000 GpuRegister class_reg) {
1001 __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value());
1002 __ LoadConst32(AT, mirror::Class::kStatusInitialized);
1003 __ Bltc(TMP, AT, slow_path->GetEntryLabel());
1004 // TODO: barrier needed?
1005 __ Bind(slow_path->GetExitLabel());
1006}
1007
1008void InstructionCodeGeneratorMIPS64::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) {
1009 __ Sync(0); // only stype 0 is supported
1010}
1011
1012void InstructionCodeGeneratorMIPS64::GenerateSuspendCheck(HSuspendCheck* instruction,
1013 HBasicBlock* successor) {
1014 SuspendCheckSlowPathMIPS64* slow_path =
1015 new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS64(instruction, successor);
1016 codegen_->AddSlowPath(slow_path);
1017
1018 __ LoadFromOffset(kLoadUnsignedHalfword,
1019 TMP,
1020 TR,
1021 Thread::ThreadFlagsOffset<kMips64WordSize>().Int32Value());
1022 if (successor == nullptr) {
1023 __ Bnezc(TMP, slow_path->GetEntryLabel());
1024 __ Bind(slow_path->GetReturnLabel());
1025 } else {
1026 __ Beqzc(TMP, codegen_->GetLabelOf(successor));
1027 __ B(slow_path->GetEntryLabel());
1028 // slow_path will return to GetLabelOf(successor).
1029 }
1030}
1031
1032InstructionCodeGeneratorMIPS64::InstructionCodeGeneratorMIPS64(HGraph* graph,
1033 CodeGeneratorMIPS64* codegen)
1034 : HGraphVisitor(graph),
1035 assembler_(codegen->GetAssembler()),
1036 codegen_(codegen) {}
1037
1038void LocationsBuilderMIPS64::HandleBinaryOp(HBinaryOperation* instruction) {
1039 DCHECK_EQ(instruction->InputCount(), 2U);
1040 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1041 Primitive::Type type = instruction->GetResultType();
1042 switch (type) {
1043 case Primitive::kPrimInt:
1044 case Primitive::kPrimLong: {
1045 locations->SetInAt(0, Location::RequiresRegister());
1046 HInstruction* right = instruction->InputAt(1);
1047 bool can_use_imm = false;
1048 if (right->IsConstant()) {
1049 int64_t imm = CodeGenerator::GetInt64ValueOf(right->AsConstant());
1050 if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) {
1051 can_use_imm = IsUint<16>(imm);
1052 } else if (instruction->IsAdd()) {
1053 can_use_imm = IsInt<16>(imm);
1054 } else {
1055 DCHECK(instruction->IsSub());
1056 can_use_imm = IsInt<16>(-imm);
1057 }
1058 }
1059 if (can_use_imm)
1060 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1061 else
1062 locations->SetInAt(1, Location::RequiresRegister());
1063 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1064 }
1065 break;
1066
1067 case Primitive::kPrimFloat:
1068 case Primitive::kPrimDouble:
1069 locations->SetInAt(0, Location::RequiresFpuRegister());
1070 locations->SetInAt(1, Location::RequiresFpuRegister());
1071 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1072 break;
1073
1074 default:
1075 LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type;
1076 }
1077}
1078
1079void InstructionCodeGeneratorMIPS64::HandleBinaryOp(HBinaryOperation* instruction) {
1080 Primitive::Type type = instruction->GetType();
1081 LocationSummary* locations = instruction->GetLocations();
1082
1083 switch (type) {
1084 case Primitive::kPrimInt:
1085 case Primitive::kPrimLong: {
1086 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1087 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1088 Location rhs_location = locations->InAt(1);
1089
1090 GpuRegister rhs_reg = ZERO;
1091 int64_t rhs_imm = 0;
1092 bool use_imm = rhs_location.IsConstant();
1093 if (use_imm) {
1094 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
1095 } else {
1096 rhs_reg = rhs_location.AsRegister<GpuRegister>();
1097 }
1098
1099 if (instruction->IsAnd()) {
1100 if (use_imm)
1101 __ Andi(dst, lhs, rhs_imm);
1102 else
1103 __ And(dst, lhs, rhs_reg);
1104 } else if (instruction->IsOr()) {
1105 if (use_imm)
1106 __ Ori(dst, lhs, rhs_imm);
1107 else
1108 __ Or(dst, lhs, rhs_reg);
1109 } else if (instruction->IsXor()) {
1110 if (use_imm)
1111 __ Xori(dst, lhs, rhs_imm);
1112 else
1113 __ Xor(dst, lhs, rhs_reg);
1114 } else if (instruction->IsAdd()) {
1115 if (type == Primitive::kPrimInt) {
1116 if (use_imm)
1117 __ Addiu(dst, lhs, rhs_imm);
1118 else
1119 __ Addu(dst, lhs, rhs_reg);
1120 } else {
1121 if (use_imm)
1122 __ Daddiu(dst, lhs, rhs_imm);
1123 else
1124 __ Daddu(dst, lhs, rhs_reg);
1125 }
1126 } else {
1127 DCHECK(instruction->IsSub());
1128 if (type == Primitive::kPrimInt) {
1129 if (use_imm)
1130 __ Addiu(dst, lhs, -rhs_imm);
1131 else
1132 __ Subu(dst, lhs, rhs_reg);
1133 } else {
1134 if (use_imm)
1135 __ Daddiu(dst, lhs, -rhs_imm);
1136 else
1137 __ Dsubu(dst, lhs, rhs_reg);
1138 }
1139 }
1140 break;
1141 }
1142 case Primitive::kPrimFloat:
1143 case Primitive::kPrimDouble: {
1144 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
1145 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
1146 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
1147 if (instruction->IsAdd()) {
1148 if (type == Primitive::kPrimFloat)
1149 __ AddS(dst, lhs, rhs);
1150 else
1151 __ AddD(dst, lhs, rhs);
1152 } else if (instruction->IsSub()) {
1153 if (type == Primitive::kPrimFloat)
1154 __ SubS(dst, lhs, rhs);
1155 else
1156 __ SubD(dst, lhs, rhs);
1157 } else {
1158 LOG(FATAL) << "Unexpected floating-point binary operation";
1159 }
1160 break;
1161 }
1162 default:
1163 LOG(FATAL) << "Unexpected binary operation type " << type;
1164 }
1165}
1166
1167void LocationsBuilderMIPS64::HandleShift(HBinaryOperation* instr) {
1168 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1169
1170 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1171 Primitive::Type type = instr->GetResultType();
1172 switch (type) {
1173 case Primitive::kPrimInt:
1174 case Primitive::kPrimLong: {
1175 locations->SetInAt(0, Location::RequiresRegister());
1176 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1177 locations->SetOut(Location::RequiresRegister());
1178 break;
1179 }
1180 default:
1181 LOG(FATAL) << "Unexpected shift type " << type;
1182 }
1183}
1184
1185void InstructionCodeGeneratorMIPS64::HandleShift(HBinaryOperation* instr) {
1186 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1187 LocationSummary* locations = instr->GetLocations();
1188 Primitive::Type type = instr->GetType();
1189
1190 switch (type) {
1191 case Primitive::kPrimInt:
1192 case Primitive::kPrimLong: {
1193 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1194 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1195 Location rhs_location = locations->InAt(1);
1196
1197 GpuRegister rhs_reg = ZERO;
1198 int64_t rhs_imm = 0;
1199 bool use_imm = rhs_location.IsConstant();
1200 if (use_imm) {
1201 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
1202 } else {
1203 rhs_reg = rhs_location.AsRegister<GpuRegister>();
1204 }
1205
1206 if (use_imm) {
1207 uint32_t shift_value = (type == Primitive::kPrimInt)
1208 ? static_cast<uint32_t>(rhs_imm & kMaxIntShiftValue)
1209 : static_cast<uint32_t>(rhs_imm & kMaxLongShiftValue);
1210
1211 if (type == Primitive::kPrimInt) {
1212 if (instr->IsShl()) {
1213 __ Sll(dst, lhs, shift_value);
1214 } else if (instr->IsShr()) {
1215 __ Sra(dst, lhs, shift_value);
1216 } else {
1217 __ Srl(dst, lhs, shift_value);
1218 }
1219 } else {
1220 if (shift_value < 32) {
1221 if (instr->IsShl()) {
1222 __ Dsll(dst, lhs, shift_value);
1223 } else if (instr->IsShr()) {
1224 __ Dsra(dst, lhs, shift_value);
1225 } else {
1226 __ Dsrl(dst, lhs, shift_value);
1227 }
1228 } else {
1229 shift_value -= 32;
1230 if (instr->IsShl()) {
1231 __ Dsll32(dst, lhs, shift_value);
1232 } else if (instr->IsShr()) {
1233 __ Dsra32(dst, lhs, shift_value);
1234 } else {
1235 __ Dsrl32(dst, lhs, shift_value);
1236 }
1237 }
1238 }
1239 } else {
1240 if (type == Primitive::kPrimInt) {
1241 if (instr->IsShl()) {
1242 __ Sllv(dst, lhs, rhs_reg);
1243 } else if (instr->IsShr()) {
1244 __ Srav(dst, lhs, rhs_reg);
1245 } else {
1246 __ Srlv(dst, lhs, rhs_reg);
1247 }
1248 } else {
1249 if (instr->IsShl()) {
1250 __ Dsllv(dst, lhs, rhs_reg);
1251 } else if (instr->IsShr()) {
1252 __ Dsrav(dst, lhs, rhs_reg);
1253 } else {
1254 __ Dsrlv(dst, lhs, rhs_reg);
1255 }
1256 }
1257 }
1258 break;
1259 }
1260 default:
1261 LOG(FATAL) << "Unexpected shift operation type " << type;
1262 }
1263}
1264
1265void LocationsBuilderMIPS64::VisitAdd(HAdd* instruction) {
1266 HandleBinaryOp(instruction);
1267}
1268
1269void InstructionCodeGeneratorMIPS64::VisitAdd(HAdd* instruction) {
1270 HandleBinaryOp(instruction);
1271}
1272
1273void LocationsBuilderMIPS64::VisitAnd(HAnd* instruction) {
1274 HandleBinaryOp(instruction);
1275}
1276
1277void InstructionCodeGeneratorMIPS64::VisitAnd(HAnd* instruction) {
1278 HandleBinaryOp(instruction);
1279}
1280
1281void LocationsBuilderMIPS64::VisitArrayGet(HArrayGet* instruction) {
1282 LocationSummary* locations =
1283 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1284 locations->SetInAt(0, Location::RequiresRegister());
1285 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1286 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1287 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1288 } else {
1289 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1290 }
1291}
1292
1293void InstructionCodeGeneratorMIPS64::VisitArrayGet(HArrayGet* instruction) {
1294 LocationSummary* locations = instruction->GetLocations();
1295 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1296 Location index = locations->InAt(1);
1297 Primitive::Type type = instruction->GetType();
1298
1299 switch (type) {
1300 case Primitive::kPrimBoolean: {
1301 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
1302 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1303 if (index.IsConstant()) {
1304 size_t offset =
1305 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1306 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1307 } else {
1308 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
1309 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset);
1310 }
1311 break;
1312 }
1313
1314 case Primitive::kPrimByte: {
1315 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
1316 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1317 if (index.IsConstant()) {
1318 size_t offset =
1319 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1320 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1321 } else {
1322 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
1323 __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset);
1324 }
1325 break;
1326 }
1327
1328 case Primitive::kPrimShort: {
1329 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
1330 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1331 if (index.IsConstant()) {
1332 size_t offset =
1333 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1334 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1335 } else {
1336 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2);
1337 __ Daddu(TMP, obj, TMP);
1338 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset);
1339 }
1340 break;
1341 }
1342
1343 case Primitive::kPrimChar: {
1344 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
1345 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1346 if (index.IsConstant()) {
1347 size_t offset =
1348 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1349 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1350 } else {
1351 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2);
1352 __ Daddu(TMP, obj, TMP);
1353 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset);
1354 }
1355 break;
1356 }
1357
1358 case Primitive::kPrimInt:
1359 case Primitive::kPrimNot: {
1360 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
1361 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
1362 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1363 LoadOperandType load_type = (type == Primitive::kPrimNot) ? kLoadUnsignedWord : kLoadWord;
1364 if (index.IsConstant()) {
1365 size_t offset =
1366 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1367 __ LoadFromOffset(load_type, out, obj, offset);
1368 } else {
1369 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1370 __ Daddu(TMP, obj, TMP);
1371 __ LoadFromOffset(load_type, out, TMP, data_offset);
1372 }
1373 break;
1374 }
1375
1376 case Primitive::kPrimLong: {
1377 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
1378 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1379 if (index.IsConstant()) {
1380 size_t offset =
1381 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1382 __ LoadFromOffset(kLoadDoubleword, out, obj, offset);
1383 } else {
1384 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1385 __ Daddu(TMP, obj, TMP);
1386 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset);
1387 }
1388 break;
1389 }
1390
1391 case Primitive::kPrimFloat: {
1392 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
1393 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
1394 if (index.IsConstant()) {
1395 size_t offset =
1396 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1397 __ LoadFpuFromOffset(kLoadWord, out, obj, offset);
1398 } else {
1399 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1400 __ Daddu(TMP, obj, TMP);
1401 __ LoadFpuFromOffset(kLoadWord, out, TMP, data_offset);
1402 }
1403 break;
1404 }
1405
1406 case Primitive::kPrimDouble: {
1407 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
1408 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
1409 if (index.IsConstant()) {
1410 size_t offset =
1411 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1412 __ LoadFpuFromOffset(kLoadDoubleword, out, obj, offset);
1413 } else {
1414 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1415 __ Daddu(TMP, obj, TMP);
1416 __ LoadFpuFromOffset(kLoadDoubleword, out, TMP, data_offset);
1417 }
1418 break;
1419 }
1420
1421 case Primitive::kPrimVoid:
1422 LOG(FATAL) << "Unreachable type " << instruction->GetType();
1423 UNREACHABLE();
1424 }
1425 codegen_->MaybeRecordImplicitNullCheck(instruction);
1426}
1427
1428void LocationsBuilderMIPS64::VisitArrayLength(HArrayLength* instruction) {
1429 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1430 locations->SetInAt(0, Location::RequiresRegister());
1431 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1432}
1433
1434void InstructionCodeGeneratorMIPS64::VisitArrayLength(HArrayLength* instruction) {
1435 LocationSummary* locations = instruction->GetLocations();
1436 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
1437 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1438 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1439 __ LoadFromOffset(kLoadWord, out, obj, offset);
1440 codegen_->MaybeRecordImplicitNullCheck(instruction);
1441}
1442
1443void LocationsBuilderMIPS64::VisitArraySet(HArraySet* instruction) {
1444 Primitive::Type value_type = instruction->GetComponentType();
1445 bool is_object = value_type == Primitive::kPrimNot;
1446 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1447 instruction,
1448 is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
1449 if (is_object) {
1450 InvokeRuntimeCallingConvention calling_convention;
1451 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1452 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1453 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1454 } else {
1455 locations->SetInAt(0, Location::RequiresRegister());
1456 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1457 if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
1458 locations->SetInAt(2, Location::RequiresFpuRegister());
1459 } else {
1460 locations->SetInAt(2, Location::RequiresRegister());
1461 }
1462 }
1463}
1464
1465void InstructionCodeGeneratorMIPS64::VisitArraySet(HArraySet* instruction) {
1466 LocationSummary* locations = instruction->GetLocations();
1467 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1468 Location index = locations->InAt(1);
1469 Primitive::Type value_type = instruction->GetComponentType();
1470 bool needs_runtime_call = locations->WillCall();
1471 bool needs_write_barrier =
1472 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
1473
1474 switch (value_type) {
1475 case Primitive::kPrimBoolean:
1476 case Primitive::kPrimByte: {
1477 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
1478 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1479 if (index.IsConstant()) {
1480 size_t offset =
1481 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1482 __ StoreToOffset(kStoreByte, value, obj, offset);
1483 } else {
1484 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
1485 __ StoreToOffset(kStoreByte, value, TMP, data_offset);
1486 }
1487 break;
1488 }
1489
1490 case Primitive::kPrimShort:
1491 case Primitive::kPrimChar: {
1492 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
1493 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1494 if (index.IsConstant()) {
1495 size_t offset =
1496 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1497 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1498 } else {
1499 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2);
1500 __ Daddu(TMP, obj, TMP);
1501 __ StoreToOffset(kStoreHalfword, value, TMP, data_offset);
1502 }
1503 break;
1504 }
1505
1506 case Primitive::kPrimInt:
1507 case Primitive::kPrimNot: {
1508 if (!needs_runtime_call) {
1509 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
1510 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1511 if (index.IsConstant()) {
1512 size_t offset =
1513 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1514 __ StoreToOffset(kStoreWord, value, obj, offset);
1515 } else {
1516 DCHECK(index.IsRegister()) << index;
1517 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1518 __ Daddu(TMP, obj, TMP);
1519 __ StoreToOffset(kStoreWord, value, TMP, data_offset);
1520 }
1521 codegen_->MaybeRecordImplicitNullCheck(instruction);
1522 if (needs_write_barrier) {
1523 DCHECK_EQ(value_type, Primitive::kPrimNot);
1524 codegen_->MarkGCCard(obj, value);
1525 }
1526 } else {
1527 DCHECK_EQ(value_type, Primitive::kPrimNot);
1528 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
1529 instruction,
1530 instruction->GetDexPc(),
1531 nullptr);
1532 }
1533 break;
1534 }
1535
1536 case Primitive::kPrimLong: {
1537 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
1538 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1539 if (index.IsConstant()) {
1540 size_t offset =
1541 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1542 __ StoreToOffset(kStoreDoubleword, value, obj, offset);
1543 } else {
1544 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1545 __ Daddu(TMP, obj, TMP);
1546 __ StoreToOffset(kStoreDoubleword, value, TMP, data_offset);
1547 }
1548 break;
1549 }
1550
1551 case Primitive::kPrimFloat: {
1552 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
1553 FpuRegister value = locations->InAt(2).AsFpuRegister<FpuRegister>();
1554 DCHECK(locations->InAt(2).IsFpuRegister());
1555 if (index.IsConstant()) {
1556 size_t offset =
1557 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1558 __ StoreFpuToOffset(kStoreWord, value, obj, offset);
1559 } else {
1560 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1561 __ Daddu(TMP, obj, TMP);
1562 __ StoreFpuToOffset(kStoreWord, value, TMP, data_offset);
1563 }
1564 break;
1565 }
1566
1567 case Primitive::kPrimDouble: {
1568 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
1569 FpuRegister value = locations->InAt(2).AsFpuRegister<FpuRegister>();
1570 DCHECK(locations->InAt(2).IsFpuRegister());
1571 if (index.IsConstant()) {
1572 size_t offset =
1573 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1574 __ StoreFpuToOffset(kStoreDoubleword, value, obj, offset);
1575 } else {
1576 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1577 __ Daddu(TMP, obj, TMP);
1578 __ StoreFpuToOffset(kStoreDoubleword, value, TMP, data_offset);
1579 }
1580 break;
1581 }
1582
1583 case Primitive::kPrimVoid:
1584 LOG(FATAL) << "Unreachable type " << instruction->GetType();
1585 UNREACHABLE();
1586 }
1587
1588 // Ints and objects are handled in the switch.
1589 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
1590 codegen_->MaybeRecordImplicitNullCheck(instruction);
1591 }
1592}
1593
1594void LocationsBuilderMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) {
1595 LocationSummary* locations =
1596 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1597 locations->SetInAt(0, Location::RequiresRegister());
1598 locations->SetInAt(1, Location::RequiresRegister());
1599 if (instruction->HasUses()) {
1600 locations->SetOut(Location::SameAsFirstInput());
1601 }
1602}
1603
1604void InstructionCodeGeneratorMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) {
1605 LocationSummary* locations = instruction->GetLocations();
1606 BoundsCheckSlowPathMIPS64* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS64(
1607 instruction,
1608 locations->InAt(0),
1609 locations->InAt(1));
1610 codegen_->AddSlowPath(slow_path);
1611
1612 GpuRegister index = locations->InAt(0).AsRegister<GpuRegister>();
1613 GpuRegister length = locations->InAt(1).AsRegister<GpuRegister>();
1614
1615 // length is limited by the maximum positive signed 32-bit integer.
1616 // Unsigned comparison of length and index checks for index < 0
1617 // and for length <= index simultaneously.
1618 // Mips R6 requires lhs != rhs for compact branches.
1619 if (index == length) {
1620 __ B(slow_path->GetEntryLabel());
1621 } else {
1622 __ Bgeuc(index, length, slow_path->GetEntryLabel());
1623 }
1624}
1625
1626void LocationsBuilderMIPS64::VisitCheckCast(HCheckCast* instruction) {
1627 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1628 instruction,
1629 LocationSummary::kCallOnSlowPath);
1630 locations->SetInAt(0, Location::RequiresRegister());
1631 locations->SetInAt(1, Location::RequiresRegister());
1632 locations->AddTemp(Location::RequiresRegister());
1633}
1634
1635void InstructionCodeGeneratorMIPS64::VisitCheckCast(HCheckCast* instruction) {
1636 LocationSummary* locations = instruction->GetLocations();
1637 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1638 GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>();
1639 GpuRegister obj_cls = locations->GetTemp(0).AsRegister<GpuRegister>();
1640
1641 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(
1642 instruction,
1643 locations->InAt(1),
1644 Location::RegisterLocation(obj_cls),
1645 instruction->GetDexPc());
1646 codegen_->AddSlowPath(slow_path);
1647
1648 // TODO: avoid this check if we know obj is not null.
1649 __ Beqzc(obj, slow_path->GetExitLabel());
1650 // Compare the class of `obj` with `cls`.
1651 __ LoadFromOffset(kLoadUnsignedWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value());
1652 __ Bnec(obj_cls, cls, slow_path->GetEntryLabel());
1653 __ Bind(slow_path->GetExitLabel());
1654}
1655
1656void LocationsBuilderMIPS64::VisitClinitCheck(HClinitCheck* check) {
1657 LocationSummary* locations =
1658 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
1659 locations->SetInAt(0, Location::RequiresRegister());
1660 if (check->HasUses()) {
1661 locations->SetOut(Location::SameAsFirstInput());
1662 }
1663}
1664
1665void InstructionCodeGeneratorMIPS64::VisitClinitCheck(HClinitCheck* check) {
1666 // We assume the class is not null.
1667 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64(
1668 check->GetLoadClass(),
1669 check,
1670 check->GetDexPc(),
1671 true);
1672 codegen_->AddSlowPath(slow_path);
1673 GenerateClassInitializationCheck(slow_path,
1674 check->GetLocations()->InAt(0).AsRegister<GpuRegister>());
1675}
1676
1677void LocationsBuilderMIPS64::VisitCompare(HCompare* compare) {
1678 Primitive::Type in_type = compare->InputAt(0)->GetType();
1679
1680 LocationSummary::CallKind call_kind = Primitive::IsFloatingPointType(in_type)
1681 ? LocationSummary::kCall
1682 : LocationSummary::kNoCall;
1683
1684 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(compare, call_kind);
1685
1686 switch (in_type) {
1687 case Primitive::kPrimLong:
1688 locations->SetInAt(0, Location::RequiresRegister());
1689 locations->SetInAt(1, Location::RequiresRegister());
1690 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1691 break;
1692
1693 case Primitive::kPrimFloat:
1694 case Primitive::kPrimDouble: {
1695 InvokeRuntimeCallingConvention calling_convention;
1696 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
1697 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
1698 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimInt));
1699 break;
1700 }
1701
1702 default:
1703 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
1704 }
1705}
1706
1707void InstructionCodeGeneratorMIPS64::VisitCompare(HCompare* instruction) {
1708 LocationSummary* locations = instruction->GetLocations();
1709 Primitive::Type in_type = instruction->InputAt(0)->GetType();
1710
1711 // 0 if: left == right
1712 // 1 if: left > right
1713 // -1 if: left < right
1714 switch (in_type) {
1715 case Primitive::kPrimLong: {
1716 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1717 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1718 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
1719 // TODO: more efficient (direct) comparison with a constant
1720 __ Slt(TMP, lhs, rhs);
1721 __ Slt(dst, rhs, lhs);
1722 __ Subu(dst, dst, TMP);
1723 break;
1724 }
1725
1726 case Primitive::kPrimFloat:
1727 case Primitive::kPrimDouble: {
1728 int32_t entry_point_offset;
1729 if (in_type == Primitive::kPrimFloat) {
1730 entry_point_offset = instruction->IsGtBias() ? QUICK_ENTRY_POINT(pCmpgFloat)
1731 : QUICK_ENTRY_POINT(pCmplFloat);
1732 } else {
1733 entry_point_offset = instruction->IsGtBias() ? QUICK_ENTRY_POINT(pCmpgDouble)
1734 : QUICK_ENTRY_POINT(pCmplDouble);
1735 }
1736 codegen_->InvokeRuntime(entry_point_offset, instruction, instruction->GetDexPc(), nullptr);
1737 break;
1738 }
1739
1740 default:
1741 LOG(FATAL) << "Unimplemented compare type " << in_type;
1742 }
1743}
1744
1745void LocationsBuilderMIPS64::VisitCondition(HCondition* instruction) {
1746 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1747 locations->SetInAt(0, Location::RequiresRegister());
1748 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1749 if (instruction->NeedsMaterialization()) {
1750 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1751 }
1752}
1753
1754void InstructionCodeGeneratorMIPS64::VisitCondition(HCondition* instruction) {
1755 if (!instruction->NeedsMaterialization()) {
1756 return;
1757 }
1758
1759 LocationSummary* locations = instruction->GetLocations();
1760
1761 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1762 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1763 Location rhs_location = locations->InAt(1);
1764
1765 GpuRegister rhs_reg = ZERO;
1766 int64_t rhs_imm = 0;
1767 bool use_imm = rhs_location.IsConstant();
1768 if (use_imm) {
1769 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
1770 } else {
1771 rhs_reg = rhs_location.AsRegister<GpuRegister>();
1772 }
1773
1774 IfCondition if_cond = instruction->GetCondition();
1775
1776 switch (if_cond) {
1777 case kCondEQ:
1778 case kCondNE:
1779 if (use_imm && IsUint<16>(rhs_imm)) {
1780 __ Xori(dst, lhs, rhs_imm);
1781 } else {
1782 if (use_imm) {
1783 rhs_reg = TMP;
1784 __ LoadConst32(rhs_reg, rhs_imm);
1785 }
1786 __ Xor(dst, lhs, rhs_reg);
1787 }
1788 if (if_cond == kCondEQ) {
1789 __ Sltiu(dst, dst, 1);
1790 } else {
1791 __ Sltu(dst, ZERO, dst);
1792 }
1793 break;
1794
1795 case kCondLT:
1796 case kCondGE:
1797 if (use_imm && IsInt<16>(rhs_imm)) {
1798 __ Slti(dst, lhs, rhs_imm);
1799 } else {
1800 if (use_imm) {
1801 rhs_reg = TMP;
1802 __ LoadConst32(rhs_reg, rhs_imm);
1803 }
1804 __ Slt(dst, lhs, rhs_reg);
1805 }
1806 if (if_cond == kCondGE) {
1807 // Simulate lhs >= rhs via !(lhs < rhs) since there's
1808 // only the slt instruction but no sge.
1809 __ Xori(dst, dst, 1);
1810 }
1811 break;
1812
1813 case kCondLE:
1814 case kCondGT:
1815 if (use_imm && IsInt<16>(rhs_imm + 1)) {
1816 // Simulate lhs <= rhs via lhs < rhs + 1.
1817 __ Slti(dst, lhs, rhs_imm + 1);
1818 if (if_cond == kCondGT) {
1819 // Simulate lhs > rhs via !(lhs <= rhs) since there's
1820 // only the slti instruction but no sgti.
1821 __ Xori(dst, dst, 1);
1822 }
1823 } else {
1824 if (use_imm) {
1825 rhs_reg = TMP;
1826 __ LoadConst32(rhs_reg, rhs_imm);
1827 }
1828 __ Slt(dst, rhs_reg, lhs);
1829 if (if_cond == kCondLE) {
1830 // Simulate lhs <= rhs via !(rhs < lhs) since there's
1831 // only the slt instruction but no sle.
1832 __ Xori(dst, dst, 1);
1833 }
1834 }
1835 break;
1836 }
1837}
1838
1839void LocationsBuilderMIPS64::VisitDiv(HDiv* div) {
1840 LocationSummary* locations =
1841 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1842 switch (div->GetResultType()) {
1843 case Primitive::kPrimInt:
1844 case Primitive::kPrimLong:
1845 locations->SetInAt(0, Location::RequiresRegister());
1846 locations->SetInAt(1, Location::RequiresRegister());
1847 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1848 break;
1849
1850 case Primitive::kPrimFloat:
1851 case Primitive::kPrimDouble:
1852 locations->SetInAt(0, Location::RequiresFpuRegister());
1853 locations->SetInAt(1, Location::RequiresFpuRegister());
1854 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1855 break;
1856
1857 default:
1858 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1859 }
1860}
1861
1862void InstructionCodeGeneratorMIPS64::VisitDiv(HDiv* instruction) {
1863 Primitive::Type type = instruction->GetType();
1864 LocationSummary* locations = instruction->GetLocations();
1865
1866 switch (type) {
1867 case Primitive::kPrimInt:
1868 case Primitive::kPrimLong: {
1869 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1870 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1871 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
1872 if (type == Primitive::kPrimInt)
1873 __ DivR6(dst, lhs, rhs);
1874 else
1875 __ Ddiv(dst, lhs, rhs);
1876 break;
1877 }
1878 case Primitive::kPrimFloat:
1879 case Primitive::kPrimDouble: {
1880 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
1881 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
1882 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
1883 if (type == Primitive::kPrimFloat)
1884 __ DivS(dst, lhs, rhs);
1885 else
1886 __ DivD(dst, lhs, rhs);
1887 break;
1888 }
1889 default:
1890 LOG(FATAL) << "Unexpected div type " << type;
1891 }
1892}
1893
1894void LocationsBuilderMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1895 LocationSummary* locations =
1896 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1897 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
1898 if (instruction->HasUses()) {
1899 locations->SetOut(Location::SameAsFirstInput());
1900 }
1901}
1902
1903void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1904 SlowPathCodeMIPS64* slow_path =
1905 new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS64(instruction);
1906 codegen_->AddSlowPath(slow_path);
1907 Location value = instruction->GetLocations()->InAt(0);
1908
1909 Primitive::Type type = instruction->GetType();
1910
1911 if ((type != Primitive::kPrimInt) && (type != Primitive::kPrimLong)) {
1912 LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck.";
1913 }
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