blob: f561c97eb0ccec4d271cc347ff48526f3164e4be [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"
Chris Larsen3039e382015-08-26 07:54:08 -070023#include "intrinsics_mips64.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070024#include "art_method.h"
Chris Larsen3039e382015-08-26 07:54:08 -070025#include "code_generator_utils.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070026#include "mirror/array-inl.h"
27#include "mirror/class-inl.h"
28#include "offsets.h"
29#include "thread.h"
30#include "utils/mips64/assembler_mips64.h"
31#include "utils/assembler.h"
32#include "utils/stack_checks.h"
33
34namespace art {
35namespace mips64 {
36
37static constexpr int kCurrentMethodStackOffset = 0;
38static constexpr GpuRegister kMethodRegisterArgument = A0;
39
40// We need extra temporary/scratch registers (in addition to AT) in some cases.
Alexey Frunze4dda3372015-06-01 18:31:49 -070041static constexpr FpuRegister FTMP = F8;
42
Alexey Frunze4dda3372015-06-01 18:31:49 -070043Location Mips64ReturnLocation(Primitive::Type return_type) {
44 switch (return_type) {
45 case Primitive::kPrimBoolean:
46 case Primitive::kPrimByte:
47 case Primitive::kPrimChar:
48 case Primitive::kPrimShort:
49 case Primitive::kPrimInt:
50 case Primitive::kPrimNot:
51 case Primitive::kPrimLong:
52 return Location::RegisterLocation(V0);
53
54 case Primitive::kPrimFloat:
55 case Primitive::kPrimDouble:
56 return Location::FpuRegisterLocation(F0);
57
58 case Primitive::kPrimVoid:
59 return Location();
60 }
61 UNREACHABLE();
62}
63
64Location InvokeDexCallingConventionVisitorMIPS64::GetReturnLocation(Primitive::Type type) const {
65 return Mips64ReturnLocation(type);
66}
67
68Location InvokeDexCallingConventionVisitorMIPS64::GetMethodLocation() const {
69 return Location::RegisterLocation(kMethodRegisterArgument);
70}
71
72Location InvokeDexCallingConventionVisitorMIPS64::GetNextLocation(Primitive::Type type) {
73 Location next_location;
74 if (type == Primitive::kPrimVoid) {
75 LOG(FATAL) << "Unexpected parameter type " << type;
76 }
77
78 if (Primitive::IsFloatingPointType(type) &&
79 (float_index_ < calling_convention.GetNumberOfFpuRegisters())) {
80 next_location = Location::FpuRegisterLocation(
81 calling_convention.GetFpuRegisterAt(float_index_++));
82 gp_index_++;
83 } else if (!Primitive::IsFloatingPointType(type) &&
84 (gp_index_ < calling_convention.GetNumberOfRegisters())) {
85 next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index_++));
86 float_index_++;
87 } else {
88 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
89 next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
90 : Location::StackSlot(stack_offset);
91 }
92
93 // Space on the stack is reserved for all arguments.
94 stack_index_ += Primitive::Is64BitType(type) ? 2 : 1;
95
96 // TODO: review
97
98 // TODO: shouldn't we use a whole machine word per argument on the stack?
99 // Implicit 4-byte method pointer (and such) will cause misalignment.
100
101 return next_location;
102}
103
104Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type type) {
105 return Mips64ReturnLocation(type);
106}
107
108#define __ down_cast<CodeGeneratorMIPS64*>(codegen)->GetAssembler()->
109#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64WordSize, x).Int32Value()
110
111class BoundsCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
112 public:
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100113 explicit BoundsCheckSlowPathMIPS64(HBoundsCheck* instruction) : instruction_(instruction) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700114
115 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100116 LocationSummary* locations = instruction_->GetLocations();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700117 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
118 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +0000119 if (instruction_->CanThrowIntoCatchBlock()) {
120 // Live registers will be restored in the catch block if caught.
121 SaveLiveRegisters(codegen, instruction_->GetLocations());
122 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700123 // We're moving two locations to locations that could overlap, so we need a parallel
124 // move resolver.
125 InvokeRuntimeCallingConvention calling_convention;
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100126 codegen->EmitParallelMoves(locations->InAt(0),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700127 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
128 Primitive::kPrimInt,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100129 locations->InAt(1),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700130 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
131 Primitive::kPrimInt);
132 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds),
133 instruction_,
134 instruction_->GetDexPc(),
135 this);
136 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
137 }
138
Alexandre Rames8158f282015-08-07 10:26:17 +0100139 bool IsFatal() const OVERRIDE { return true; }
140
Roland Levillain46648892015-06-19 16:07:18 +0100141 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS64"; }
142
Alexey Frunze4dda3372015-06-01 18:31:49 -0700143 private:
144 HBoundsCheck* const instruction_;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700145
146 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS64);
147};
148
149class DivZeroCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
150 public:
151 explicit DivZeroCheckSlowPathMIPS64(HDivZeroCheck* instruction) : instruction_(instruction) {}
152
153 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
154 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
155 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +0000156 if (instruction_->CanThrowIntoCatchBlock()) {
157 // Live registers will be restored in the catch block if caught.
158 SaveLiveRegisters(codegen, instruction_->GetLocations());
159 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700160 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());
David Brazdil77a48ae2015-09-15 12:34:04 +0000278 if (instruction_->CanThrowIntoCatchBlock()) {
279 // Live registers will be restored in the catch block if caught.
280 SaveLiveRegisters(codegen, instruction_->GetLocations());
281 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700282 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer),
283 instruction_,
284 instruction_->GetDexPc(),
285 this);
286 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
287 }
288
Alexandre Rames8158f282015-08-07 10:26:17 +0100289 bool IsFatal() const OVERRIDE { return true; }
290
Roland Levillain46648892015-06-19 16:07:18 +0100291 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS64"; }
292
Alexey Frunze4dda3372015-06-01 18:31:49 -0700293 private:
294 HNullCheck* const instruction_;
295
296 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS64);
297};
298
299class SuspendCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
300 public:
Roland Levillain3887c462015-08-12 18:15:42 +0100301 SuspendCheckSlowPathMIPS64(HSuspendCheck* instruction, HBasicBlock* successor)
Alexey Frunze4dda3372015-06-01 18:31:49 -0700302 : instruction_(instruction), successor_(successor) {}
303
304 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
305 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
306 __ Bind(GetEntryLabel());
307 SaveLiveRegisters(codegen, instruction_->GetLocations());
308 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend),
309 instruction_,
310 instruction_->GetDexPc(),
311 this);
312 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
313 RestoreLiveRegisters(codegen, instruction_->GetLocations());
314 if (successor_ == nullptr) {
315 __ B(GetReturnLabel());
316 } else {
317 __ B(mips64_codegen->GetLabelOf(successor_));
318 }
319 }
320
321 Label* GetReturnLabel() {
322 DCHECK(successor_ == nullptr);
323 return &return_label_;
324 }
325
Roland Levillain46648892015-06-19 16:07:18 +0100326 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS64"; }
327
Alexey Frunze4dda3372015-06-01 18:31:49 -0700328 private:
329 HSuspendCheck* const instruction_;
330 // If not null, the block to branch to after the suspend check.
331 HBasicBlock* const successor_;
332
333 // If `successor_` is null, the label to branch to after the suspend check.
334 Label return_label_;
335
336 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS64);
337};
338
339class TypeCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 {
340 public:
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100341 explicit TypeCheckSlowPathMIPS64(HInstruction* instruction) : instruction_(instruction) {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700342
343 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
344 LocationSummary* locations = instruction_->GetLocations();
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100345 Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0)
346 : locations->Out();
347 uint32_t dex_pc = instruction_->GetDexPc();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700348 DCHECK(instruction_->IsCheckCast()
349 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
350 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
351
352 __ Bind(GetEntryLabel());
353 SaveLiveRegisters(codegen, locations);
354
355 // We're moving two locations to locations that could overlap, so we need a parallel
356 // move resolver.
357 InvokeRuntimeCallingConvention calling_convention;
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100358 codegen->EmitParallelMoves(locations->InAt(1),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700359 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
360 Primitive::kPrimNot,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100361 object_class,
Alexey Frunze4dda3372015-06-01 18:31:49 -0700362 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
363 Primitive::kPrimNot);
364
365 if (instruction_->IsInstanceOf()) {
366 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial),
367 instruction_,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100368 dex_pc,
Alexey Frunze4dda3372015-06-01 18:31:49 -0700369 this);
370 Primitive::Type ret_type = instruction_->GetType();
371 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
372 mips64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
373 CheckEntrypointTypes<kQuickInstanceofNonTrivial,
374 uint32_t,
375 const mirror::Class*,
376 const mirror::Class*>();
377 } else {
378 DCHECK(instruction_->IsCheckCast());
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100379 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc, this);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700380 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
381 }
382
383 RestoreLiveRegisters(codegen, locations);
384 __ B(GetExitLabel());
385 }
386
Roland Levillain46648892015-06-19 16:07:18 +0100387 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS64"; }
388
Alexey Frunze4dda3372015-06-01 18:31:49 -0700389 private:
390 HInstruction* const instruction_;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700391
392 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS64);
393};
394
395class DeoptimizationSlowPathMIPS64 : public SlowPathCodeMIPS64 {
396 public:
397 explicit DeoptimizationSlowPathMIPS64(HInstruction* instruction)
398 : instruction_(instruction) {}
399
400 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
401 __ Bind(GetEntryLabel());
402 SaveLiveRegisters(codegen, instruction_->GetLocations());
403 DCHECK(instruction_->IsDeoptimize());
404 HDeoptimize* deoptimize = instruction_->AsDeoptimize();
405 uint32_t dex_pc = deoptimize->GetDexPc();
406 CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen);
407 mips64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this);
408 }
409
Roland Levillain46648892015-06-19 16:07:18 +0100410 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS64"; }
411
Alexey Frunze4dda3372015-06-01 18:31:49 -0700412 private:
413 HInstruction* const instruction_;
414 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS64);
415};
416
417CodeGeneratorMIPS64::CodeGeneratorMIPS64(HGraph* graph,
418 const Mips64InstructionSetFeatures& isa_features,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100419 const CompilerOptions& compiler_options,
420 OptimizingCompilerStats* stats)
Alexey Frunze4dda3372015-06-01 18:31:49 -0700421 : CodeGenerator(graph,
422 kNumberOfGpuRegisters,
423 kNumberOfFpuRegisters,
424 0, // kNumberOfRegisterPairs
425 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
426 arraysize(kCoreCalleeSaves)),
427 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
428 arraysize(kFpuCalleeSaves)),
Serban Constantinescuecc43662015-08-13 13:33:12 +0100429 compiler_options,
430 stats),
Vladimir Marko225b6462015-09-28 12:17:40 +0100431 block_labels_(nullptr),
Alexey Frunze4dda3372015-06-01 18:31:49 -0700432 location_builder_(graph, this),
433 instruction_visitor_(graph, this),
434 move_resolver_(graph->GetArena(), this),
435 isa_features_(isa_features) {
436 // Save RA (containing the return address) to mimic Quick.
437 AddAllocatedRegister(Location::RegisterLocation(RA));
438}
439
440#undef __
441#define __ down_cast<Mips64Assembler*>(GetAssembler())->
442#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMips64WordSize, x).Int32Value()
443
444void CodeGeneratorMIPS64::Finalize(CodeAllocator* allocator) {
445 CodeGenerator::Finalize(allocator);
446}
447
448Mips64Assembler* ParallelMoveResolverMIPS64::GetAssembler() const {
449 return codegen_->GetAssembler();
450}
451
452void ParallelMoveResolverMIPS64::EmitMove(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +0100453 MoveOperands* move = moves_[index];
Alexey Frunze4dda3372015-06-01 18:31:49 -0700454 codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType());
455}
456
457void ParallelMoveResolverMIPS64::EmitSwap(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +0100458 MoveOperands* move = moves_[index];
Alexey Frunze4dda3372015-06-01 18:31:49 -0700459 codegen_->SwapLocations(move->GetDestination(), move->GetSource(), move->GetType());
460}
461
462void ParallelMoveResolverMIPS64::RestoreScratch(int reg) {
463 // Pop reg
464 __ Ld(GpuRegister(reg), SP, 0);
465 __ DecreaseFrameSize(kMips64WordSize);
466}
467
468void ParallelMoveResolverMIPS64::SpillScratch(int reg) {
469 // Push reg
470 __ IncreaseFrameSize(kMips64WordSize);
471 __ Sd(GpuRegister(reg), SP, 0);
472}
473
474void ParallelMoveResolverMIPS64::Exchange(int index1, int index2, bool double_slot) {
475 LoadOperandType load_type = double_slot ? kLoadDoubleword : kLoadWord;
476 StoreOperandType store_type = double_slot ? kStoreDoubleword : kStoreWord;
477 // Allocate a scratch register other than TMP, if available.
478 // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be
479 // automatically unspilled when the scratch scope object is destroyed).
480 ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters());
481 // If V0 spills onto the stack, SP-relative offsets need to be adjusted.
482 int stack_offset = ensure_scratch.IsSpilled() ? kMips64WordSize : 0;
483 __ LoadFromOffset(load_type,
484 GpuRegister(ensure_scratch.GetRegister()),
485 SP,
486 index1 + stack_offset);
487 __ LoadFromOffset(load_type,
488 TMP,
489 SP,
490 index2 + stack_offset);
491 __ StoreToOffset(store_type,
492 GpuRegister(ensure_scratch.GetRegister()),
493 SP,
494 index2 + stack_offset);
495 __ StoreToOffset(store_type, TMP, SP, index1 + stack_offset);
496}
497
498static dwarf::Reg DWARFReg(GpuRegister reg) {
499 return dwarf::Reg::Mips64Core(static_cast<int>(reg));
500}
501
502// TODO: mapping of floating-point registers to DWARF
503
504void CodeGeneratorMIPS64::GenerateFrameEntry() {
505 __ Bind(&frame_entry_label_);
506
507 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips64) || !IsLeafMethod();
508
509 if (do_overflow_check) {
510 __ LoadFromOffset(kLoadWord,
511 ZERO,
512 SP,
513 -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips64)));
514 RecordPcInfo(nullptr, 0);
515 }
516
517 // TODO: anything related to T9/GP/GOT/PIC/.so's?
518
519 if (HasEmptyFrame()) {
520 return;
521 }
522
523 // Make sure the frame size isn't unreasonably large. Per the various APIs
524 // it looks like it should always be less than 2GB in size, which allows
525 // us using 32-bit signed offsets from the stack pointer.
526 if (GetFrameSize() > 0x7FFFFFFF)
527 LOG(FATAL) << "Stack frame larger than 2GB";
528
529 // Spill callee-saved registers.
530 // Note that their cumulative size is small and they can be indexed using
531 // 16-bit offsets.
532
533 // TODO: increment/decrement SP in one step instead of two or remove this comment.
534
535 uint32_t ofs = FrameEntrySpillSize();
536 __ IncreaseFrameSize(ofs);
537
538 for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) {
539 GpuRegister reg = kCoreCalleeSaves[i];
540 if (allocated_registers_.ContainsCoreRegister(reg)) {
541 ofs -= kMips64WordSize;
542 __ Sd(reg, SP, ofs);
543 __ cfi().RelOffset(DWARFReg(reg), ofs);
544 }
545 }
546
547 for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) {
548 FpuRegister reg = kFpuCalleeSaves[i];
549 if (allocated_registers_.ContainsFloatingPointRegister(reg)) {
550 ofs -= kMips64WordSize;
551 __ Sdc1(reg, SP, ofs);
552 // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs);
553 }
554 }
555
556 // Allocate the rest of the frame and store the current method pointer
557 // at its end.
558
559 __ IncreaseFrameSize(GetFrameSize() - FrameEntrySpillSize());
560
561 static_assert(IsInt<16>(kCurrentMethodStackOffset),
562 "kCurrentMethodStackOffset must fit into int16_t");
563 __ Sd(kMethodRegisterArgument, SP, kCurrentMethodStackOffset);
564}
565
566void CodeGeneratorMIPS64::GenerateFrameExit() {
567 __ cfi().RememberState();
568
569 // TODO: anything related to T9/GP/GOT/PIC/.so's?
570
571 if (!HasEmptyFrame()) {
572 // Deallocate the rest of the frame.
573
574 __ DecreaseFrameSize(GetFrameSize() - FrameEntrySpillSize());
575
576 // Restore callee-saved registers.
577 // Note that their cumulative size is small and they can be indexed using
578 // 16-bit offsets.
579
580 // TODO: increment/decrement SP in one step instead of two or remove this comment.
581
582 uint32_t ofs = 0;
583
584 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
585 FpuRegister reg = kFpuCalleeSaves[i];
586 if (allocated_registers_.ContainsFloatingPointRegister(reg)) {
587 __ Ldc1(reg, SP, ofs);
588 ofs += kMips64WordSize;
589 // TODO: __ cfi().Restore(DWARFReg(reg));
590 }
591 }
592
593 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
594 GpuRegister reg = kCoreCalleeSaves[i];
595 if (allocated_registers_.ContainsCoreRegister(reg)) {
596 __ Ld(reg, SP, ofs);
597 ofs += kMips64WordSize;
598 __ cfi().Restore(DWARFReg(reg));
599 }
600 }
601
602 DCHECK_EQ(ofs, FrameEntrySpillSize());
603 __ DecreaseFrameSize(ofs);
604 }
605
606 __ Jr(RA);
607
608 __ cfi().RestoreState();
609 __ cfi().DefCFAOffset(GetFrameSize());
610}
611
612void CodeGeneratorMIPS64::Bind(HBasicBlock* block) {
613 __ Bind(GetLabelOf(block));
614}
615
616void CodeGeneratorMIPS64::MoveLocation(Location destination,
617 Location source,
Calin Juravlee460d1d2015-09-29 04:52:17 +0100618 Primitive::Type dst_type) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700619 if (source.Equals(destination)) {
620 return;
621 }
622
623 // A valid move can always be inferred from the destination and source
624 // locations. When moving from and to a register, the argument type can be
625 // used to generate 32bit instead of 64bit moves.
Calin Juravlee460d1d2015-09-29 04:52:17 +0100626 bool unspecified_type = (dst_type == Primitive::kPrimVoid);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700627 DCHECK_EQ(unspecified_type, false);
628
629 if (destination.IsRegister() || destination.IsFpuRegister()) {
630 if (unspecified_type) {
631 HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr;
632 if (source.IsStackSlot() ||
633 (src_cst != nullptr && (src_cst->IsIntConstant()
634 || src_cst->IsFloatConstant()
635 || src_cst->IsNullConstant()))) {
636 // For stack slots and 32bit constants, a 64bit type is appropriate.
Calin Juravlee460d1d2015-09-29 04:52:17 +0100637 dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700638 } else {
639 // If the source is a double stack slot or a 64bit constant, a 64bit
640 // type is appropriate. Else the source is a register, and since the
641 // type has not been specified, we chose a 64bit type to force a 64bit
642 // move.
Calin Juravlee460d1d2015-09-29 04:52:17 +0100643 dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700644 }
645 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100646 DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) ||
647 (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type)));
Alexey Frunze4dda3372015-06-01 18:31:49 -0700648 if (source.IsStackSlot() || source.IsDoubleStackSlot()) {
649 // Move to GPR/FPR from stack
650 LoadOperandType load_type = source.IsStackSlot() ? kLoadWord : kLoadDoubleword;
Calin Juravlee460d1d2015-09-29 04:52:17 +0100651 if (Primitive::IsFloatingPointType(dst_type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700652 __ LoadFpuFromOffset(load_type,
653 destination.AsFpuRegister<FpuRegister>(),
654 SP,
655 source.GetStackIndex());
656 } else {
657 // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot.
658 __ LoadFromOffset(load_type,
659 destination.AsRegister<GpuRegister>(),
660 SP,
661 source.GetStackIndex());
662 }
663 } else if (source.IsConstant()) {
664 // Move to GPR/FPR from constant
665 GpuRegister gpr = AT;
Calin Juravlee460d1d2015-09-29 04:52:17 +0100666 if (!Primitive::IsFloatingPointType(dst_type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700667 gpr = destination.AsRegister<GpuRegister>();
668 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100669 if (dst_type == Primitive::kPrimInt || dst_type == Primitive::kPrimFloat) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700670 __ LoadConst32(gpr, GetInt32ValueOf(source.GetConstant()->AsConstant()));
671 } else {
672 __ LoadConst64(gpr, GetInt64ValueOf(source.GetConstant()->AsConstant()));
673 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100674 if (dst_type == Primitive::kPrimFloat) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700675 __ Mtc1(gpr, destination.AsFpuRegister<FpuRegister>());
Calin Juravlee460d1d2015-09-29 04:52:17 +0100676 } else if (dst_type == Primitive::kPrimDouble) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700677 __ Dmtc1(gpr, destination.AsFpuRegister<FpuRegister>());
678 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100679 } else if (source.IsRegister()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700680 if (destination.IsRegister()) {
681 // Move to GPR from GPR
682 __ Move(destination.AsRegister<GpuRegister>(), source.AsRegister<GpuRegister>());
683 } else {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100684 DCHECK(destination.IsFpuRegister());
685 if (Primitive::Is64BitType(dst_type)) {
686 __ Dmtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>());
687 } else {
688 __ Mtc1(source.AsRegister<GpuRegister>(), destination.AsFpuRegister<FpuRegister>());
689 }
690 }
691 } else if (source.IsFpuRegister()) {
692 if (destination.IsFpuRegister()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700693 // Move to FPR from FPR
Calin Juravlee460d1d2015-09-29 04:52:17 +0100694 if (dst_type == Primitive::kPrimFloat) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700695 __ MovS(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>());
696 } else {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100697 DCHECK_EQ(dst_type, Primitive::kPrimDouble);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700698 __ MovD(destination.AsFpuRegister<FpuRegister>(), source.AsFpuRegister<FpuRegister>());
699 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100700 } else {
701 DCHECK(destination.IsRegister());
702 if (Primitive::Is64BitType(dst_type)) {
703 __ Dmfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>());
704 } else {
705 __ Mfc1(destination.AsRegister<GpuRegister>(), source.AsFpuRegister<FpuRegister>());
706 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700707 }
708 }
709 } else { // The destination is not a register. It must be a stack slot.
710 DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot());
711 if (source.IsRegister() || source.IsFpuRegister()) {
712 if (unspecified_type) {
713 if (source.IsRegister()) {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100714 dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700715 } else {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100716 dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700717 }
718 }
Calin Juravlee460d1d2015-09-29 04:52:17 +0100719 DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) &&
720 (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type)));
Alexey Frunze4dda3372015-06-01 18:31:49 -0700721 // Move to stack from GPR/FPR
722 StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword;
723 if (source.IsRegister()) {
724 __ StoreToOffset(store_type,
725 source.AsRegister<GpuRegister>(),
726 SP,
727 destination.GetStackIndex());
728 } else {
729 __ StoreFpuToOffset(store_type,
730 source.AsFpuRegister<FpuRegister>(),
731 SP,
732 destination.GetStackIndex());
733 }
734 } else if (source.IsConstant()) {
735 // Move to stack from constant
736 HConstant* src_cst = source.GetConstant();
737 StoreOperandType store_type = destination.IsStackSlot() ? kStoreWord : kStoreDoubleword;
738 if (destination.IsStackSlot()) {
739 __ LoadConst32(TMP, GetInt32ValueOf(src_cst->AsConstant()));
740 } else {
741 __ LoadConst64(TMP, GetInt64ValueOf(src_cst->AsConstant()));
742 }
743 __ StoreToOffset(store_type, TMP, SP, destination.GetStackIndex());
744 } else {
745 DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot());
746 DCHECK_EQ(source.IsDoubleStackSlot(), destination.IsDoubleStackSlot());
747 // Move to stack from stack
748 if (destination.IsStackSlot()) {
749 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
750 __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex());
751 } else {
752 __ LoadFromOffset(kLoadDoubleword, TMP, SP, source.GetStackIndex());
753 __ StoreToOffset(kStoreDoubleword, TMP, SP, destination.GetStackIndex());
754 }
755 }
756 }
757}
758
759void CodeGeneratorMIPS64::SwapLocations(Location loc1,
760 Location loc2,
761 Primitive::Type type ATTRIBUTE_UNUSED) {
762 DCHECK(!loc1.IsConstant());
763 DCHECK(!loc2.IsConstant());
764
765 if (loc1.Equals(loc2)) {
766 return;
767 }
768
769 bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot();
770 bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot();
771 bool is_fp_reg1 = loc1.IsFpuRegister();
772 bool is_fp_reg2 = loc2.IsFpuRegister();
773
774 if (loc2.IsRegister() && loc1.IsRegister()) {
775 // Swap 2 GPRs
776 GpuRegister r1 = loc1.AsRegister<GpuRegister>();
777 GpuRegister r2 = loc2.AsRegister<GpuRegister>();
778 __ Move(TMP, r2);
779 __ Move(r2, r1);
780 __ Move(r1, TMP);
781 } else if (is_fp_reg2 && is_fp_reg1) {
782 // Swap 2 FPRs
783 FpuRegister r1 = loc1.AsFpuRegister<FpuRegister>();
784 FpuRegister r2 = loc2.AsFpuRegister<FpuRegister>();
785 // TODO: Can MOV.S/MOV.D be used here to save one instruction?
786 // Need to distinguish float from double, right?
787 __ Dmfc1(TMP, r2);
788 __ Dmfc1(AT, r1);
789 __ Dmtc1(TMP, r1);
790 __ Dmtc1(AT, r2);
791 } else if (is_slot1 != is_slot2) {
792 // Swap GPR/FPR and stack slot
793 Location reg_loc = is_slot1 ? loc2 : loc1;
794 Location mem_loc = is_slot1 ? loc1 : loc2;
795 LoadOperandType load_type = mem_loc.IsStackSlot() ? kLoadWord : kLoadDoubleword;
796 StoreOperandType store_type = mem_loc.IsStackSlot() ? kStoreWord : kStoreDoubleword;
797 // TODO: use load_type = kLoadUnsignedWord when type == Primitive::kPrimNot.
798 __ LoadFromOffset(load_type, TMP, SP, mem_loc.GetStackIndex());
799 if (reg_loc.IsFpuRegister()) {
800 __ StoreFpuToOffset(store_type,
801 reg_loc.AsFpuRegister<FpuRegister>(),
802 SP,
803 mem_loc.GetStackIndex());
804 // TODO: review this MTC1/DMTC1 move
805 if (mem_loc.IsStackSlot()) {
806 __ Mtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>());
807 } else {
808 DCHECK(mem_loc.IsDoubleStackSlot());
809 __ Dmtc1(TMP, reg_loc.AsFpuRegister<FpuRegister>());
810 }
811 } else {
812 __ StoreToOffset(store_type, reg_loc.AsRegister<GpuRegister>(), SP, mem_loc.GetStackIndex());
813 __ Move(reg_loc.AsRegister<GpuRegister>(), TMP);
814 }
815 } else if (is_slot1 && is_slot2) {
816 move_resolver_.Exchange(loc1.GetStackIndex(),
817 loc2.GetStackIndex(),
818 loc1.IsDoubleStackSlot());
819 } else {
820 LOG(FATAL) << "Unimplemented swap between locations " << loc1 << " and " << loc2;
821 }
822}
823
824void CodeGeneratorMIPS64::Move(HInstruction* instruction,
825 Location location,
826 HInstruction* move_for) {
827 LocationSummary* locations = instruction->GetLocations();
828 Primitive::Type type = instruction->GetType();
829 DCHECK_NE(type, Primitive::kPrimVoid);
830
831 if (instruction->IsCurrentMethod()) {
832 MoveLocation(location, Location::DoubleStackSlot(kCurrentMethodStackOffset), type);
833 } else if (locations != nullptr && locations->Out().Equals(location)) {
834 return;
835 } else if (instruction->IsIntConstant()
836 || instruction->IsLongConstant()
837 || instruction->IsNullConstant()) {
838 if (location.IsRegister()) {
839 // Move to GPR from constant
840 GpuRegister dst = location.AsRegister<GpuRegister>();
841 if (instruction->IsNullConstant() || instruction->IsIntConstant()) {
842 __ LoadConst32(dst, GetInt32ValueOf(instruction->AsConstant()));
843 } else {
844 __ LoadConst64(dst, instruction->AsLongConstant()->GetValue());
845 }
846 } else {
847 DCHECK(location.IsStackSlot() || location.IsDoubleStackSlot());
848 // Move to stack from constant
849 if (location.IsStackSlot()) {
850 __ LoadConst32(TMP, GetInt32ValueOf(instruction->AsConstant()));
851 __ StoreToOffset(kStoreWord, TMP, SP, location.GetStackIndex());
852 } else {
853 __ LoadConst64(TMP, instruction->AsLongConstant()->GetValue());
854 __ StoreToOffset(kStoreDoubleword, TMP, SP, location.GetStackIndex());
855 }
856 }
857 } else if (instruction->IsTemporary()) {
858 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
859 MoveLocation(location, temp_location, type);
860 } else if (instruction->IsLoadLocal()) {
861 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
862 if (Primitive::Is64BitType(type)) {
863 MoveLocation(location, Location::DoubleStackSlot(stack_slot), type);
864 } else {
865 MoveLocation(location, Location::StackSlot(stack_slot), type);
866 }
867 } else {
868 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
869 MoveLocation(location, locations->Out(), type);
870 }
871}
872
Calin Juravle175dc732015-08-25 15:42:32 +0100873void CodeGeneratorMIPS64::MoveConstant(Location location, int32_t value) {
874 DCHECK(location.IsRegister());
875 __ LoadConst32(location.AsRegister<GpuRegister>(), value);
876}
877
Calin Juravlee460d1d2015-09-29 04:52:17 +0100878void CodeGeneratorMIPS64::AddLocationAsTemp(Location location, LocationSummary* locations) {
879 if (location.IsRegister()) {
880 locations->AddTemp(location);
881 } else {
882 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
883 }
884}
885
Alexey Frunze4dda3372015-06-01 18:31:49 -0700886Location CodeGeneratorMIPS64::GetStackLocation(HLoadLocal* load) const {
887 Primitive::Type type = load->GetType();
888
889 switch (type) {
890 case Primitive::kPrimNot:
891 case Primitive::kPrimInt:
892 case Primitive::kPrimFloat:
893 return Location::StackSlot(GetStackSlot(load->GetLocal()));
894
895 case Primitive::kPrimLong:
896 case Primitive::kPrimDouble:
897 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
898
899 case Primitive::kPrimBoolean:
900 case Primitive::kPrimByte:
901 case Primitive::kPrimChar:
902 case Primitive::kPrimShort:
903 case Primitive::kPrimVoid:
904 LOG(FATAL) << "Unexpected type " << type;
905 }
906
907 LOG(FATAL) << "Unreachable";
908 return Location::NoLocation();
909}
910
911void CodeGeneratorMIPS64::MarkGCCard(GpuRegister object, GpuRegister value) {
912 Label done;
913 GpuRegister card = AT;
914 GpuRegister temp = TMP;
915 __ Beqzc(value, &done);
916 __ LoadFromOffset(kLoadDoubleword,
917 card,
918 TR,
919 Thread::CardTableOffset<kMips64WordSize>().Int32Value());
920 __ Dsrl(temp, object, gc::accounting::CardTable::kCardShift);
921 __ Daddu(temp, card, temp);
922 __ Sb(card, temp, 0);
923 __ Bind(&done);
924}
925
926void CodeGeneratorMIPS64::SetupBlockedRegisters(bool is_baseline ATTRIBUTE_UNUSED) const {
927 // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated.
928 blocked_core_registers_[ZERO] = true;
929 blocked_core_registers_[K0] = true;
930 blocked_core_registers_[K1] = true;
931 blocked_core_registers_[GP] = true;
932 blocked_core_registers_[SP] = true;
933 blocked_core_registers_[RA] = true;
934
935 // AT and TMP(T8) are used as temporary/scratch registers
936 // (similar to how AT is used by MIPS assemblers).
937 blocked_core_registers_[AT] = true;
938 blocked_core_registers_[TMP] = true;
939 blocked_fpu_registers_[FTMP] = true;
940
941 // Reserve suspend and thread registers.
942 blocked_core_registers_[S0] = true;
943 blocked_core_registers_[TR] = true;
944
945 // Reserve T9 for function calls
946 blocked_core_registers_[T9] = true;
947
948 // TODO: review; anything else?
949
950 // TODO: make these two for's conditional on is_baseline once
951 // all the issues with register saving/restoring are sorted out.
952 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
953 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
954 }
955
956 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
957 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
958 }
959}
960
961Location CodeGeneratorMIPS64::AllocateFreeRegister(Primitive::Type type) const {
962 if (type == Primitive::kPrimVoid) {
963 LOG(FATAL) << "Unreachable type " << type;
964 }
965
966 if (Primitive::IsFloatingPointType(type)) {
967 size_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfFpuRegisters);
968 return Location::FpuRegisterLocation(reg);
969 } else {
970 size_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfGpuRegisters);
971 return Location::RegisterLocation(reg);
972 }
973}
974
975size_t CodeGeneratorMIPS64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
976 __ StoreToOffset(kStoreDoubleword, GpuRegister(reg_id), SP, stack_index);
977 return kMips64WordSize;
978}
979
980size_t CodeGeneratorMIPS64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
981 __ LoadFromOffset(kLoadDoubleword, GpuRegister(reg_id), SP, stack_index);
982 return kMips64WordSize;
983}
984
985size_t CodeGeneratorMIPS64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
986 __ StoreFpuToOffset(kStoreDoubleword, FpuRegister(reg_id), SP, stack_index);
987 return kMips64WordSize;
988}
989
990size_t CodeGeneratorMIPS64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
991 __ LoadFpuFromOffset(kLoadDoubleword, FpuRegister(reg_id), SP, stack_index);
992 return kMips64WordSize;
993}
994
995void CodeGeneratorMIPS64::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdil9f0dece2015-09-21 18:20:26 +0100996 stream << GpuRegister(reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700997}
998
999void CodeGeneratorMIPS64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdil9f0dece2015-09-21 18:20:26 +01001000 stream << FpuRegister(reg);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001001}
1002
Calin Juravle175dc732015-08-25 15:42:32 +01001003void CodeGeneratorMIPS64::InvokeRuntime(QuickEntrypointEnum entrypoint,
1004 HInstruction* instruction,
1005 uint32_t dex_pc,
1006 SlowPathCode* slow_path) {
1007 InvokeRuntime(GetThreadOffset<kMips64WordSize>(entrypoint).Int32Value(),
1008 instruction,
1009 dex_pc,
1010 slow_path);
1011}
1012
Alexey Frunze4dda3372015-06-01 18:31:49 -07001013void CodeGeneratorMIPS64::InvokeRuntime(int32_t entry_point_offset,
1014 HInstruction* instruction,
1015 uint32_t dex_pc,
1016 SlowPathCode* slow_path) {
Alexandre Rames78e3ef62015-08-12 13:43:29 +01001017 ValidateInvokeRuntime(instruction, slow_path);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001018 // TODO: anything related to T9/GP/GOT/PIC/.so's?
1019 __ LoadFromOffset(kLoadDoubleword, T9, TR, entry_point_offset);
1020 __ Jalr(T9);
1021 RecordPcInfo(instruction, dex_pc, slow_path);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001022}
1023
1024void InstructionCodeGeneratorMIPS64::GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path,
1025 GpuRegister class_reg) {
1026 __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value());
1027 __ LoadConst32(AT, mirror::Class::kStatusInitialized);
1028 __ Bltc(TMP, AT, slow_path->GetEntryLabel());
1029 // TODO: barrier needed?
1030 __ Bind(slow_path->GetExitLabel());
1031}
1032
1033void InstructionCodeGeneratorMIPS64::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) {
1034 __ Sync(0); // only stype 0 is supported
1035}
1036
1037void InstructionCodeGeneratorMIPS64::GenerateSuspendCheck(HSuspendCheck* instruction,
1038 HBasicBlock* successor) {
1039 SuspendCheckSlowPathMIPS64* slow_path =
1040 new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS64(instruction, successor);
1041 codegen_->AddSlowPath(slow_path);
1042
1043 __ LoadFromOffset(kLoadUnsignedHalfword,
1044 TMP,
1045 TR,
1046 Thread::ThreadFlagsOffset<kMips64WordSize>().Int32Value());
1047 if (successor == nullptr) {
1048 __ Bnezc(TMP, slow_path->GetEntryLabel());
1049 __ Bind(slow_path->GetReturnLabel());
1050 } else {
1051 __ Beqzc(TMP, codegen_->GetLabelOf(successor));
1052 __ B(slow_path->GetEntryLabel());
1053 // slow_path will return to GetLabelOf(successor).
1054 }
1055}
1056
1057InstructionCodeGeneratorMIPS64::InstructionCodeGeneratorMIPS64(HGraph* graph,
1058 CodeGeneratorMIPS64* codegen)
1059 : HGraphVisitor(graph),
1060 assembler_(codegen->GetAssembler()),
1061 codegen_(codegen) {}
1062
1063void LocationsBuilderMIPS64::HandleBinaryOp(HBinaryOperation* instruction) {
1064 DCHECK_EQ(instruction->InputCount(), 2U);
1065 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1066 Primitive::Type type = instruction->GetResultType();
1067 switch (type) {
1068 case Primitive::kPrimInt:
1069 case Primitive::kPrimLong: {
1070 locations->SetInAt(0, Location::RequiresRegister());
1071 HInstruction* right = instruction->InputAt(1);
1072 bool can_use_imm = false;
1073 if (right->IsConstant()) {
1074 int64_t imm = CodeGenerator::GetInt64ValueOf(right->AsConstant());
1075 if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) {
1076 can_use_imm = IsUint<16>(imm);
1077 } else if (instruction->IsAdd()) {
1078 can_use_imm = IsInt<16>(imm);
1079 } else {
1080 DCHECK(instruction->IsSub());
1081 can_use_imm = IsInt<16>(-imm);
1082 }
1083 }
1084 if (can_use_imm)
1085 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1086 else
1087 locations->SetInAt(1, Location::RequiresRegister());
1088 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1089 }
1090 break;
1091
1092 case Primitive::kPrimFloat:
1093 case Primitive::kPrimDouble:
1094 locations->SetInAt(0, Location::RequiresFpuRegister());
1095 locations->SetInAt(1, Location::RequiresFpuRegister());
1096 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1097 break;
1098
1099 default:
1100 LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type;
1101 }
1102}
1103
1104void InstructionCodeGeneratorMIPS64::HandleBinaryOp(HBinaryOperation* instruction) {
1105 Primitive::Type type = instruction->GetType();
1106 LocationSummary* locations = instruction->GetLocations();
1107
1108 switch (type) {
1109 case Primitive::kPrimInt:
1110 case Primitive::kPrimLong: {
1111 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1112 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1113 Location rhs_location = locations->InAt(1);
1114
1115 GpuRegister rhs_reg = ZERO;
1116 int64_t rhs_imm = 0;
1117 bool use_imm = rhs_location.IsConstant();
1118 if (use_imm) {
1119 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
1120 } else {
1121 rhs_reg = rhs_location.AsRegister<GpuRegister>();
1122 }
1123
1124 if (instruction->IsAnd()) {
1125 if (use_imm)
1126 __ Andi(dst, lhs, rhs_imm);
1127 else
1128 __ And(dst, lhs, rhs_reg);
1129 } else if (instruction->IsOr()) {
1130 if (use_imm)
1131 __ Ori(dst, lhs, rhs_imm);
1132 else
1133 __ Or(dst, lhs, rhs_reg);
1134 } else if (instruction->IsXor()) {
1135 if (use_imm)
1136 __ Xori(dst, lhs, rhs_imm);
1137 else
1138 __ Xor(dst, lhs, rhs_reg);
1139 } else if (instruction->IsAdd()) {
1140 if (type == Primitive::kPrimInt) {
1141 if (use_imm)
1142 __ Addiu(dst, lhs, rhs_imm);
1143 else
1144 __ Addu(dst, lhs, rhs_reg);
1145 } else {
1146 if (use_imm)
1147 __ Daddiu(dst, lhs, rhs_imm);
1148 else
1149 __ Daddu(dst, lhs, rhs_reg);
1150 }
1151 } else {
1152 DCHECK(instruction->IsSub());
1153 if (type == Primitive::kPrimInt) {
1154 if (use_imm)
1155 __ Addiu(dst, lhs, -rhs_imm);
1156 else
1157 __ Subu(dst, lhs, rhs_reg);
1158 } else {
1159 if (use_imm)
1160 __ Daddiu(dst, lhs, -rhs_imm);
1161 else
1162 __ Dsubu(dst, lhs, rhs_reg);
1163 }
1164 }
1165 break;
1166 }
1167 case Primitive::kPrimFloat:
1168 case Primitive::kPrimDouble: {
1169 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
1170 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
1171 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
1172 if (instruction->IsAdd()) {
1173 if (type == Primitive::kPrimFloat)
1174 __ AddS(dst, lhs, rhs);
1175 else
1176 __ AddD(dst, lhs, rhs);
1177 } else if (instruction->IsSub()) {
1178 if (type == Primitive::kPrimFloat)
1179 __ SubS(dst, lhs, rhs);
1180 else
1181 __ SubD(dst, lhs, rhs);
1182 } else {
1183 LOG(FATAL) << "Unexpected floating-point binary operation";
1184 }
1185 break;
1186 }
1187 default:
1188 LOG(FATAL) << "Unexpected binary operation type " << type;
1189 }
1190}
1191
1192void LocationsBuilderMIPS64::HandleShift(HBinaryOperation* instr) {
1193 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1194
1195 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1196 Primitive::Type type = instr->GetResultType();
1197 switch (type) {
1198 case Primitive::kPrimInt:
1199 case Primitive::kPrimLong: {
1200 locations->SetInAt(0, Location::RequiresRegister());
1201 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1202 locations->SetOut(Location::RequiresRegister());
1203 break;
1204 }
1205 default:
1206 LOG(FATAL) << "Unexpected shift type " << type;
1207 }
1208}
1209
1210void InstructionCodeGeneratorMIPS64::HandleShift(HBinaryOperation* instr) {
1211 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1212 LocationSummary* locations = instr->GetLocations();
1213 Primitive::Type type = instr->GetType();
1214
1215 switch (type) {
1216 case Primitive::kPrimInt:
1217 case Primitive::kPrimLong: {
1218 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1219 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1220 Location rhs_location = locations->InAt(1);
1221
1222 GpuRegister rhs_reg = ZERO;
1223 int64_t rhs_imm = 0;
1224 bool use_imm = rhs_location.IsConstant();
1225 if (use_imm) {
1226 rhs_imm = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant());
1227 } else {
1228 rhs_reg = rhs_location.AsRegister<GpuRegister>();
1229 }
1230
1231 if (use_imm) {
1232 uint32_t shift_value = (type == Primitive::kPrimInt)
1233 ? static_cast<uint32_t>(rhs_imm & kMaxIntShiftValue)
1234 : static_cast<uint32_t>(rhs_imm & kMaxLongShiftValue);
1235
1236 if (type == Primitive::kPrimInt) {
1237 if (instr->IsShl()) {
1238 __ Sll(dst, lhs, shift_value);
1239 } else if (instr->IsShr()) {
1240 __ Sra(dst, lhs, shift_value);
1241 } else {
1242 __ Srl(dst, lhs, shift_value);
1243 }
1244 } else {
1245 if (shift_value < 32) {
1246 if (instr->IsShl()) {
1247 __ Dsll(dst, lhs, shift_value);
1248 } else if (instr->IsShr()) {
1249 __ Dsra(dst, lhs, shift_value);
1250 } else {
1251 __ Dsrl(dst, lhs, shift_value);
1252 }
1253 } else {
1254 shift_value -= 32;
1255 if (instr->IsShl()) {
1256 __ Dsll32(dst, lhs, shift_value);
1257 } else if (instr->IsShr()) {
1258 __ Dsra32(dst, lhs, shift_value);
1259 } else {
1260 __ Dsrl32(dst, lhs, shift_value);
1261 }
1262 }
1263 }
1264 } else {
1265 if (type == Primitive::kPrimInt) {
1266 if (instr->IsShl()) {
1267 __ Sllv(dst, lhs, rhs_reg);
1268 } else if (instr->IsShr()) {
1269 __ Srav(dst, lhs, rhs_reg);
1270 } else {
1271 __ Srlv(dst, lhs, rhs_reg);
1272 }
1273 } else {
1274 if (instr->IsShl()) {
1275 __ Dsllv(dst, lhs, rhs_reg);
1276 } else if (instr->IsShr()) {
1277 __ Dsrav(dst, lhs, rhs_reg);
1278 } else {
1279 __ Dsrlv(dst, lhs, rhs_reg);
1280 }
1281 }
1282 }
1283 break;
1284 }
1285 default:
1286 LOG(FATAL) << "Unexpected shift operation type " << type;
1287 }
1288}
1289
1290void LocationsBuilderMIPS64::VisitAdd(HAdd* instruction) {
1291 HandleBinaryOp(instruction);
1292}
1293
1294void InstructionCodeGeneratorMIPS64::VisitAdd(HAdd* instruction) {
1295 HandleBinaryOp(instruction);
1296}
1297
1298void LocationsBuilderMIPS64::VisitAnd(HAnd* instruction) {
1299 HandleBinaryOp(instruction);
1300}
1301
1302void InstructionCodeGeneratorMIPS64::VisitAnd(HAnd* instruction) {
1303 HandleBinaryOp(instruction);
1304}
1305
1306void LocationsBuilderMIPS64::VisitArrayGet(HArrayGet* instruction) {
1307 LocationSummary* locations =
1308 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1309 locations->SetInAt(0, Location::RequiresRegister());
1310 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1311 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1312 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1313 } else {
1314 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1315 }
1316}
1317
1318void InstructionCodeGeneratorMIPS64::VisitArrayGet(HArrayGet* instruction) {
1319 LocationSummary* locations = instruction->GetLocations();
1320 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1321 Location index = locations->InAt(1);
1322 Primitive::Type type = instruction->GetType();
1323
1324 switch (type) {
1325 case Primitive::kPrimBoolean: {
1326 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
1327 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1328 if (index.IsConstant()) {
1329 size_t offset =
1330 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1331 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1332 } else {
1333 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
1334 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset);
1335 }
1336 break;
1337 }
1338
1339 case Primitive::kPrimByte: {
1340 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
1341 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1342 if (index.IsConstant()) {
1343 size_t offset =
1344 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1345 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1346 } else {
1347 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
1348 __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset);
1349 }
1350 break;
1351 }
1352
1353 case Primitive::kPrimShort: {
1354 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
1355 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1356 if (index.IsConstant()) {
1357 size_t offset =
1358 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1359 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1360 } else {
1361 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2);
1362 __ Daddu(TMP, obj, TMP);
1363 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset);
1364 }
1365 break;
1366 }
1367
1368 case Primitive::kPrimChar: {
1369 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
1370 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1371 if (index.IsConstant()) {
1372 size_t offset =
1373 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1374 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1375 } else {
1376 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2);
1377 __ Daddu(TMP, obj, TMP);
1378 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset);
1379 }
1380 break;
1381 }
1382
1383 case Primitive::kPrimInt:
1384 case Primitive::kPrimNot: {
1385 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
1386 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
1387 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1388 LoadOperandType load_type = (type == Primitive::kPrimNot) ? kLoadUnsignedWord : kLoadWord;
1389 if (index.IsConstant()) {
1390 size_t offset =
1391 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1392 __ LoadFromOffset(load_type, out, obj, offset);
1393 } else {
1394 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1395 __ Daddu(TMP, obj, TMP);
1396 __ LoadFromOffset(load_type, out, TMP, data_offset);
1397 }
1398 break;
1399 }
1400
1401 case Primitive::kPrimLong: {
1402 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
1403 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1404 if (index.IsConstant()) {
1405 size_t offset =
1406 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1407 __ LoadFromOffset(kLoadDoubleword, out, obj, offset);
1408 } else {
1409 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1410 __ Daddu(TMP, obj, TMP);
1411 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset);
1412 }
1413 break;
1414 }
1415
1416 case Primitive::kPrimFloat: {
1417 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
1418 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
1419 if (index.IsConstant()) {
1420 size_t offset =
1421 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1422 __ LoadFpuFromOffset(kLoadWord, out, obj, offset);
1423 } else {
1424 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1425 __ Daddu(TMP, obj, TMP);
1426 __ LoadFpuFromOffset(kLoadWord, out, TMP, data_offset);
1427 }
1428 break;
1429 }
1430
1431 case Primitive::kPrimDouble: {
1432 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
1433 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
1434 if (index.IsConstant()) {
1435 size_t offset =
1436 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1437 __ LoadFpuFromOffset(kLoadDoubleword, out, obj, offset);
1438 } else {
1439 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1440 __ Daddu(TMP, obj, TMP);
1441 __ LoadFpuFromOffset(kLoadDoubleword, out, TMP, data_offset);
1442 }
1443 break;
1444 }
1445
1446 case Primitive::kPrimVoid:
1447 LOG(FATAL) << "Unreachable type " << instruction->GetType();
1448 UNREACHABLE();
1449 }
1450 codegen_->MaybeRecordImplicitNullCheck(instruction);
1451}
1452
1453void LocationsBuilderMIPS64::VisitArrayLength(HArrayLength* instruction) {
1454 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1455 locations->SetInAt(0, Location::RequiresRegister());
1456 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1457}
1458
1459void InstructionCodeGeneratorMIPS64::VisitArrayLength(HArrayLength* instruction) {
1460 LocationSummary* locations = instruction->GetLocations();
1461 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
1462 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1463 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1464 __ LoadFromOffset(kLoadWord, out, obj, offset);
1465 codegen_->MaybeRecordImplicitNullCheck(instruction);
1466}
1467
1468void LocationsBuilderMIPS64::VisitArraySet(HArraySet* instruction) {
David Brazdilbb3d5052015-09-21 18:39:16 +01001469 bool needs_runtime_call = instruction->NeedsTypeCheck();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001470 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1471 instruction,
David Brazdilbb3d5052015-09-21 18:39:16 +01001472 needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
1473 if (needs_runtime_call) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001474 InvokeRuntimeCallingConvention calling_convention;
1475 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1476 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1477 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1478 } else {
1479 locations->SetInAt(0, Location::RequiresRegister());
1480 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1481 if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
1482 locations->SetInAt(2, Location::RequiresFpuRegister());
1483 } else {
1484 locations->SetInAt(2, Location::RequiresRegister());
1485 }
1486 }
1487}
1488
1489void InstructionCodeGeneratorMIPS64::VisitArraySet(HArraySet* instruction) {
1490 LocationSummary* locations = instruction->GetLocations();
1491 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1492 Location index = locations->InAt(1);
1493 Primitive::Type value_type = instruction->GetComponentType();
1494 bool needs_runtime_call = locations->WillCall();
1495 bool needs_write_barrier =
1496 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
1497
1498 switch (value_type) {
1499 case Primitive::kPrimBoolean:
1500 case Primitive::kPrimByte: {
1501 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
1502 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1503 if (index.IsConstant()) {
1504 size_t offset =
1505 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1506 __ StoreToOffset(kStoreByte, value, obj, offset);
1507 } else {
1508 __ Daddu(TMP, obj, index.AsRegister<GpuRegister>());
1509 __ StoreToOffset(kStoreByte, value, TMP, data_offset);
1510 }
1511 break;
1512 }
1513
1514 case Primitive::kPrimShort:
1515 case Primitive::kPrimChar: {
1516 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
1517 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1518 if (index.IsConstant()) {
1519 size_t offset =
1520 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1521 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1522 } else {
1523 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_2);
1524 __ Daddu(TMP, obj, TMP);
1525 __ StoreToOffset(kStoreHalfword, value, TMP, data_offset);
1526 }
1527 break;
1528 }
1529
1530 case Primitive::kPrimInt:
1531 case Primitive::kPrimNot: {
1532 if (!needs_runtime_call) {
1533 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
1534 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1535 if (index.IsConstant()) {
1536 size_t offset =
1537 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1538 __ StoreToOffset(kStoreWord, value, obj, offset);
1539 } else {
1540 DCHECK(index.IsRegister()) << index;
1541 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1542 __ Daddu(TMP, obj, TMP);
1543 __ StoreToOffset(kStoreWord, value, TMP, data_offset);
1544 }
1545 codegen_->MaybeRecordImplicitNullCheck(instruction);
1546 if (needs_write_barrier) {
1547 DCHECK_EQ(value_type, Primitive::kPrimNot);
1548 codegen_->MarkGCCard(obj, value);
1549 }
1550 } else {
1551 DCHECK_EQ(value_type, Primitive::kPrimNot);
1552 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
1553 instruction,
1554 instruction->GetDexPc(),
1555 nullptr);
1556 }
1557 break;
1558 }
1559
1560 case Primitive::kPrimLong: {
1561 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
1562 GpuRegister value = locations->InAt(2).AsRegister<GpuRegister>();
1563 if (index.IsConstant()) {
1564 size_t offset =
1565 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1566 __ StoreToOffset(kStoreDoubleword, value, obj, offset);
1567 } else {
1568 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1569 __ Daddu(TMP, obj, TMP);
1570 __ StoreToOffset(kStoreDoubleword, value, TMP, data_offset);
1571 }
1572 break;
1573 }
1574
1575 case Primitive::kPrimFloat: {
1576 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
1577 FpuRegister value = locations->InAt(2).AsFpuRegister<FpuRegister>();
1578 DCHECK(locations->InAt(2).IsFpuRegister());
1579 if (index.IsConstant()) {
1580 size_t offset =
1581 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1582 __ StoreFpuToOffset(kStoreWord, value, obj, offset);
1583 } else {
1584 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_4);
1585 __ Daddu(TMP, obj, TMP);
1586 __ StoreFpuToOffset(kStoreWord, value, TMP, data_offset);
1587 }
1588 break;
1589 }
1590
1591 case Primitive::kPrimDouble: {
1592 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
1593 FpuRegister value = locations->InAt(2).AsFpuRegister<FpuRegister>();
1594 DCHECK(locations->InAt(2).IsFpuRegister());
1595 if (index.IsConstant()) {
1596 size_t offset =
1597 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1598 __ StoreFpuToOffset(kStoreDoubleword, value, obj, offset);
1599 } else {
1600 __ Dsll(TMP, index.AsRegister<GpuRegister>(), TIMES_8);
1601 __ Daddu(TMP, obj, TMP);
1602 __ StoreFpuToOffset(kStoreDoubleword, value, TMP, data_offset);
1603 }
1604 break;
1605 }
1606
1607 case Primitive::kPrimVoid:
1608 LOG(FATAL) << "Unreachable type " << instruction->GetType();
1609 UNREACHABLE();
1610 }
1611
1612 // Ints and objects are handled in the switch.
1613 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
1614 codegen_->MaybeRecordImplicitNullCheck(instruction);
1615 }
1616}
1617
1618void LocationsBuilderMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00001619 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
1620 ? LocationSummary::kCallOnSlowPath
1621 : LocationSummary::kNoCall;
1622 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001623 locations->SetInAt(0, Location::RequiresRegister());
1624 locations->SetInAt(1, Location::RequiresRegister());
1625 if (instruction->HasUses()) {
1626 locations->SetOut(Location::SameAsFirstInput());
1627 }
1628}
1629
1630void InstructionCodeGeneratorMIPS64::VisitBoundsCheck(HBoundsCheck* instruction) {
1631 LocationSummary* locations = instruction->GetLocations();
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01001632 BoundsCheckSlowPathMIPS64* slow_path =
1633 new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS64(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001634 codegen_->AddSlowPath(slow_path);
1635
1636 GpuRegister index = locations->InAt(0).AsRegister<GpuRegister>();
1637 GpuRegister length = locations->InAt(1).AsRegister<GpuRegister>();
1638
1639 // length is limited by the maximum positive signed 32-bit integer.
1640 // Unsigned comparison of length and index checks for index < 0
1641 // and for length <= index simultaneously.
1642 // Mips R6 requires lhs != rhs for compact branches.
1643 if (index == length) {
1644 __ B(slow_path->GetEntryLabel());
1645 } else {
1646 __ Bgeuc(index, length, slow_path->GetEntryLabel());
1647 }
1648}
1649
1650void LocationsBuilderMIPS64::VisitCheckCast(HCheckCast* instruction) {
1651 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1652 instruction,
1653 LocationSummary::kCallOnSlowPath);
1654 locations->SetInAt(0, Location::RequiresRegister());
1655 locations->SetInAt(1, Location::RequiresRegister());
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01001656 // Note that TypeCheckSlowPathMIPS64 uses this register too.
Alexey Frunze4dda3372015-06-01 18:31:49 -07001657 locations->AddTemp(Location::RequiresRegister());
1658}
1659
1660void InstructionCodeGeneratorMIPS64::VisitCheckCast(HCheckCast* instruction) {
1661 LocationSummary* locations = instruction->GetLocations();
1662 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1663 GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>();
1664 GpuRegister obj_cls = locations->GetTemp(0).AsRegister<GpuRegister>();
1665
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01001666 SlowPathCodeMIPS64* slow_path =
1667 new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001668 codegen_->AddSlowPath(slow_path);
1669
1670 // TODO: avoid this check if we know obj is not null.
1671 __ Beqzc(obj, slow_path->GetExitLabel());
1672 // Compare the class of `obj` with `cls`.
1673 __ LoadFromOffset(kLoadUnsignedWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value());
1674 __ Bnec(obj_cls, cls, slow_path->GetEntryLabel());
1675 __ Bind(slow_path->GetExitLabel());
1676}
1677
1678void LocationsBuilderMIPS64::VisitClinitCheck(HClinitCheck* check) {
1679 LocationSummary* locations =
1680 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
1681 locations->SetInAt(0, Location::RequiresRegister());
1682 if (check->HasUses()) {
1683 locations->SetOut(Location::SameAsFirstInput());
1684 }
1685}
1686
1687void InstructionCodeGeneratorMIPS64::VisitClinitCheck(HClinitCheck* check) {
1688 // We assume the class is not null.
1689 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64(
1690 check->GetLoadClass(),
1691 check,
1692 check->GetDexPc(),
1693 true);
1694 codegen_->AddSlowPath(slow_path);
1695 GenerateClassInitializationCheck(slow_path,
1696 check->GetLocations()->InAt(0).AsRegister<GpuRegister>());
1697}
1698
1699void LocationsBuilderMIPS64::VisitCompare(HCompare* compare) {
1700 Primitive::Type in_type = compare->InputAt(0)->GetType();
1701
1702 LocationSummary::CallKind call_kind = Primitive::IsFloatingPointType(in_type)
1703 ? LocationSummary::kCall
1704 : LocationSummary::kNoCall;
1705
1706 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(compare, call_kind);
1707
1708 switch (in_type) {
1709 case Primitive::kPrimLong:
1710 locations->SetInAt(0, Location::RequiresRegister());
1711 locations->SetInAt(1, Location::RequiresRegister());
1712 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1713 break;
1714
1715 case Primitive::kPrimFloat:
1716 case Primitive::kPrimDouble: {
1717 InvokeRuntimeCallingConvention calling_convention;
1718 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
1719 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
1720 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimInt));
1721 break;
1722 }
1723
1724 default:
1725 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
1726 }
1727}
1728
1729void InstructionCodeGeneratorMIPS64::VisitCompare(HCompare* instruction) {
1730 LocationSummary* locations = instruction->GetLocations();
1731 Primitive::Type in_type = instruction->InputAt(0)->GetType();
1732
1733 // 0 if: left == right
1734 // 1 if: left > right
1735 // -1 if: left < right
1736 switch (in_type) {
1737 case Primitive::kPrimLong: {
1738 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1739 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1740 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
1741 // TODO: more efficient (direct) comparison with a constant
1742 __ Slt(TMP, lhs, rhs);
1743 __ Slt(dst, rhs, lhs);
1744 __ Subu(dst, dst, TMP);
1745 break;
1746 }
1747
1748 case Primitive::kPrimFloat:
1749 case Primitive::kPrimDouble: {
1750 int32_t entry_point_offset;
1751 if (in_type == Primitive::kPrimFloat) {
1752 entry_point_offset = instruction->IsGtBias() ? QUICK_ENTRY_POINT(pCmpgFloat)
1753 : QUICK_ENTRY_POINT(pCmplFloat);
1754 } else {
1755 entry_point_offset = instruction->IsGtBias() ? QUICK_ENTRY_POINT(pCmpgDouble)
1756 : QUICK_ENTRY_POINT(pCmplDouble);
1757 }
1758 codegen_->InvokeRuntime(entry_point_offset, instruction, instruction->GetDexPc(), nullptr);
1759 break;
1760 }
1761
1762 default:
1763 LOG(FATAL) << "Unimplemented compare type " << in_type;
1764 }
1765}
1766
1767void LocationsBuilderMIPS64::VisitCondition(HCondition* instruction) {
1768 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1769 locations->SetInAt(0, Location::RequiresRegister());
1770 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1771 if (instruction->NeedsMaterialization()) {
1772 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1773 }
1774}
1775
1776void InstructionCodeGeneratorMIPS64::VisitCondition(HCondition* instruction) {
1777 if (!instruction->NeedsMaterialization()) {
1778 return;
1779 }
1780
Aart Bike9f37602015-10-09 11:15:55 -07001781 // TODO: generalize to long
1782 DCHECK_NE(instruction->InputAt(0)->GetType(), Primitive::kPrimLong);
1783
Alexey Frunze4dda3372015-06-01 18:31:49 -07001784 LocationSummary* locations = instruction->GetLocations();
1785
1786 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1787 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1788 Location rhs_location = locations->InAt(1);
1789
1790 GpuRegister rhs_reg = ZERO;
1791 int64_t rhs_imm = 0;
1792 bool use_imm = rhs_location.IsConstant();
1793 if (use_imm) {
1794 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
1795 } else {
1796 rhs_reg = rhs_location.AsRegister<GpuRegister>();
1797 }
1798
1799 IfCondition if_cond = instruction->GetCondition();
1800
1801 switch (if_cond) {
1802 case kCondEQ:
1803 case kCondNE:
1804 if (use_imm && IsUint<16>(rhs_imm)) {
1805 __ Xori(dst, lhs, rhs_imm);
1806 } else {
1807 if (use_imm) {
1808 rhs_reg = TMP;
1809 __ LoadConst32(rhs_reg, rhs_imm);
1810 }
1811 __ Xor(dst, lhs, rhs_reg);
1812 }
1813 if (if_cond == kCondEQ) {
1814 __ Sltiu(dst, dst, 1);
1815 } else {
1816 __ Sltu(dst, ZERO, dst);
1817 }
1818 break;
1819
1820 case kCondLT:
1821 case kCondGE:
1822 if (use_imm && IsInt<16>(rhs_imm)) {
1823 __ Slti(dst, lhs, rhs_imm);
1824 } else {
1825 if (use_imm) {
1826 rhs_reg = TMP;
1827 __ LoadConst32(rhs_reg, rhs_imm);
1828 }
1829 __ Slt(dst, lhs, rhs_reg);
1830 }
1831 if (if_cond == kCondGE) {
1832 // Simulate lhs >= rhs via !(lhs < rhs) since there's
1833 // only the slt instruction but no sge.
1834 __ Xori(dst, dst, 1);
1835 }
1836 break;
1837
1838 case kCondLE:
1839 case kCondGT:
1840 if (use_imm && IsInt<16>(rhs_imm + 1)) {
1841 // Simulate lhs <= rhs via lhs < rhs + 1.
1842 __ Slti(dst, lhs, rhs_imm + 1);
1843 if (if_cond == kCondGT) {
1844 // Simulate lhs > rhs via !(lhs <= rhs) since there's
1845 // only the slti instruction but no sgti.
1846 __ Xori(dst, dst, 1);
1847 }
1848 } else {
1849 if (use_imm) {
1850 rhs_reg = TMP;
1851 __ LoadConst32(rhs_reg, rhs_imm);
1852 }
1853 __ Slt(dst, rhs_reg, lhs);
1854 if (if_cond == kCondLE) {
1855 // Simulate lhs <= rhs via !(rhs < lhs) since there's
1856 // only the slt instruction but no sle.
1857 __ Xori(dst, dst, 1);
1858 }
1859 }
1860 break;
Aart Bike9f37602015-10-09 11:15:55 -07001861
1862 case kCondB:
1863 case kCondAE:
1864 if (use_imm && 0 <= rhs_imm && rhs_imm <= 0x7fff) {
1865 __ Sltiu(dst, lhs, rhs_imm);
1866 } else {
1867 if (use_imm) {
1868 rhs_reg = TMP;
1869 __ LoadConst32(rhs_reg, rhs_imm);
1870 }
1871 __ Sltu(dst, lhs, rhs_reg);
1872 }
1873 if (if_cond == kCondAE) {
1874 // Simulate lhs >= rhs via !(lhs < rhs) since there's
1875 // only the sltu instruction but no sgeu.
1876 __ Xori(dst, dst, 1);
1877 }
1878 break;
1879
1880 case kCondBE:
1881 case kCondA:
1882 if (use_imm && 0 <= rhs_imm && rhs_imm <= 0x7ffe) {
1883 // Simulate lhs <= rhs via lhs < rhs + 1.
1884 __ Sltiu(dst, lhs, rhs_imm + 1);
1885 if (if_cond == kCondA) {
1886 // Simulate lhs > rhs via !(lhs <= rhs) since there's
1887 // only the sltiu instruction but no sgtiu.
1888 __ Xori(dst, dst, 1);
1889 }
1890 } else {
1891 if (use_imm) {
1892 rhs_reg = TMP;
1893 __ LoadConst32(rhs_reg, rhs_imm);
1894 }
1895 __ Sltu(dst, rhs_reg, lhs);
1896 if (if_cond == kCondBE) {
1897 // Simulate lhs <= rhs via !(rhs < lhs) since there's
1898 // only the sltu instruction but no sleu.
1899 __ Xori(dst, dst, 1);
1900 }
1901 }
1902 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001903 }
1904}
1905
1906void LocationsBuilderMIPS64::VisitDiv(HDiv* div) {
1907 LocationSummary* locations =
1908 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1909 switch (div->GetResultType()) {
1910 case Primitive::kPrimInt:
1911 case Primitive::kPrimLong:
1912 locations->SetInAt(0, Location::RequiresRegister());
1913 locations->SetInAt(1, Location::RequiresRegister());
1914 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1915 break;
1916
1917 case Primitive::kPrimFloat:
1918 case Primitive::kPrimDouble:
1919 locations->SetInAt(0, Location::RequiresFpuRegister());
1920 locations->SetInAt(1, Location::RequiresFpuRegister());
1921 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1922 break;
1923
1924 default:
1925 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1926 }
1927}
1928
1929void InstructionCodeGeneratorMIPS64::VisitDiv(HDiv* instruction) {
1930 Primitive::Type type = instruction->GetType();
1931 LocationSummary* locations = instruction->GetLocations();
1932
1933 switch (type) {
1934 case Primitive::kPrimInt:
1935 case Primitive::kPrimLong: {
1936 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1937 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1938 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
1939 if (type == Primitive::kPrimInt)
1940 __ DivR6(dst, lhs, rhs);
1941 else
1942 __ Ddiv(dst, lhs, rhs);
1943 break;
1944 }
1945 case Primitive::kPrimFloat:
1946 case Primitive::kPrimDouble: {
1947 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
1948 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
1949 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
1950 if (type == Primitive::kPrimFloat)
1951 __ DivS(dst, lhs, rhs);
1952 else
1953 __ DivD(dst, lhs, rhs);
1954 break;
1955 }
1956 default:
1957 LOG(FATAL) << "Unexpected div type " << type;
1958 }
1959}
1960
1961void LocationsBuilderMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00001962 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
1963 ? LocationSummary::kCallOnSlowPath
1964 : LocationSummary::kNoCall;
1965 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001966 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
1967 if (instruction->HasUses()) {
1968 locations->SetOut(Location::SameAsFirstInput());
1969 }
1970}
1971
1972void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1973 SlowPathCodeMIPS64* slow_path =
1974 new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS64(instruction);
1975 codegen_->AddSlowPath(slow_path);
1976 Location value = instruction->GetLocations()->InAt(0);
1977
1978 Primitive::Type type = instruction->GetType();
1979
Serguei Katkov8c0676c2015-08-03 13:55:33 +06001980 if ((type == Primitive::kPrimBoolean) || !Primitive::IsIntegralType(type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001981 LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck.";
Serguei Katkov8c0676c2015-08-03 13:55:33 +06001982 return;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001983 }
1984
1985 if (value.IsConstant()) {
1986 int64_t divisor = codegen_->GetInt64ValueOf(value.GetConstant()->AsConstant());
1987 if (divisor == 0) {
1988 __ B(slow_path->GetEntryLabel());
1989 } else {
1990 // A division by a non-null constant is valid. We don't need to perform
1991 // any check, so simply fall through.
1992 }
1993 } else {
1994 __ Beqzc(value.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
1995 }
1996}
1997
1998void LocationsBuilderMIPS64::VisitDoubleConstant(HDoubleConstant* constant) {
1999 LocationSummary* locations =
2000 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2001 locations->SetOut(Location::ConstantLocation(constant));
2002}
2003
2004void InstructionCodeGeneratorMIPS64::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) {
2005 // Will be generated at use site.
2006}
2007
2008void LocationsBuilderMIPS64::VisitExit(HExit* exit) {
2009 exit->SetLocations(nullptr);
2010}
2011
2012void InstructionCodeGeneratorMIPS64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
2013}
2014
2015void LocationsBuilderMIPS64::VisitFloatConstant(HFloatConstant* constant) {
2016 LocationSummary* locations =
2017 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2018 locations->SetOut(Location::ConstantLocation(constant));
2019}
2020
2021void InstructionCodeGeneratorMIPS64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
2022 // Will be generated at use site.
2023}
2024
David Brazdilfc6a86a2015-06-26 10:33:45 +00002025void InstructionCodeGeneratorMIPS64::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002026 DCHECK(!successor->IsExitBlock());
2027 HBasicBlock* block = got->GetBlock();
2028 HInstruction* previous = got->GetPrevious();
2029 HLoopInformation* info = block->GetLoopInformation();
2030
2031 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
2032 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
2033 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
2034 return;
2035 }
2036 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
2037 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
2038 }
2039 if (!codegen_->GoesToNextBlock(block, successor)) {
2040 __ B(codegen_->GetLabelOf(successor));
2041 }
2042}
2043
David Brazdilfc6a86a2015-06-26 10:33:45 +00002044void LocationsBuilderMIPS64::VisitGoto(HGoto* got) {
2045 got->SetLocations(nullptr);
2046}
2047
2048void InstructionCodeGeneratorMIPS64::VisitGoto(HGoto* got) {
2049 HandleGoto(got, got->GetSuccessor());
2050}
2051
2052void LocationsBuilderMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) {
2053 try_boundary->SetLocations(nullptr);
2054}
2055
2056void InstructionCodeGeneratorMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) {
2057 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
2058 if (!successor->IsExitBlock()) {
2059 HandleGoto(try_boundary, successor);
2060 }
2061}
2062
Alexey Frunze4dda3372015-06-01 18:31:49 -07002063void InstructionCodeGeneratorMIPS64::GenerateTestAndBranch(HInstruction* instruction,
2064 Label* true_target,
2065 Label* false_target,
2066 Label* always_true_target) {
2067 HInstruction* cond = instruction->InputAt(0);
2068 HCondition* condition = cond->AsCondition();
2069
2070 if (cond->IsIntConstant()) {
2071 int32_t cond_value = cond->AsIntConstant()->GetValue();
2072 if (cond_value == 1) {
2073 if (always_true_target != nullptr) {
2074 __ B(always_true_target);
2075 }
2076 return;
2077 } else {
2078 DCHECK_EQ(cond_value, 0);
2079 }
2080 } else if (!cond->IsCondition() || condition->NeedsMaterialization()) {
2081 // The condition instruction has been materialized, compare the output to 0.
2082 Location cond_val = instruction->GetLocations()->InAt(0);
2083 DCHECK(cond_val.IsRegister());
2084 __ Bnezc(cond_val.AsRegister<GpuRegister>(), true_target);
2085 } else {
2086 // The condition instruction has not been materialized, use its inputs as
2087 // the comparison and its condition as the branch condition.
2088 GpuRegister lhs = condition->GetLocations()->InAt(0).AsRegister<GpuRegister>();
2089 Location rhs_location = condition->GetLocations()->InAt(1);
2090 GpuRegister rhs_reg = ZERO;
2091 int32_t rhs_imm = 0;
2092 bool use_imm = rhs_location.IsConstant();
2093 if (use_imm) {
2094 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2095 } else {
2096 rhs_reg = rhs_location.AsRegister<GpuRegister>();
2097 }
2098
2099 IfCondition if_cond = condition->GetCondition();
2100 if (use_imm && rhs_imm == 0) {
2101 switch (if_cond) {
2102 case kCondEQ:
2103 __ Beqzc(lhs, true_target);
2104 break;
2105 case kCondNE:
2106 __ Bnezc(lhs, true_target);
2107 break;
2108 case kCondLT:
2109 __ Bltzc(lhs, true_target);
2110 break;
2111 case kCondGE:
2112 __ Bgezc(lhs, true_target);
2113 break;
2114 case kCondLE:
2115 __ Blezc(lhs, true_target);
2116 break;
2117 case kCondGT:
2118 __ Bgtzc(lhs, true_target);
2119 break;
Aart Bike9f37602015-10-09 11:15:55 -07002120 case kCondB:
2121 break; // always false
2122 case kCondBE:
2123 __ Beqzc(lhs, true_target); // <= 0 if zero
2124 break;
2125 case kCondA:
2126 __ Bnezc(lhs, true_target); // > 0 if non-zero
2127 break;
2128 case kCondAE:
2129 __ B(true_target); // always true
2130 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002131 }
2132 } else {
2133 if (use_imm) {
2134 rhs_reg = TMP;
2135 __ LoadConst32(rhs_reg, rhs_imm);
2136 }
2137 // It looks like we can get here with lhs == rhs. Should that be possible at all?
2138 // Mips R6 requires lhs != rhs for compact branches.
2139 if (lhs == rhs_reg) {
2140 DCHECK(!use_imm);
2141 switch (if_cond) {
2142 case kCondEQ:
2143 case kCondGE:
2144 case kCondLE:
Aart Bike9f37602015-10-09 11:15:55 -07002145 case kCondBE:
2146 case kCondAE:
Alexey Frunze4dda3372015-06-01 18:31:49 -07002147 // if lhs == rhs for a positive condition, then it is a branch
2148 __ B(true_target);
2149 break;
2150 case kCondNE:
2151 case kCondLT:
2152 case kCondGT:
Aart Bike9f37602015-10-09 11:15:55 -07002153 case kCondB:
2154 case kCondA:
Alexey Frunze4dda3372015-06-01 18:31:49 -07002155 // if lhs == rhs for a negative condition, then it is a NOP
2156 break;
2157 }
2158 } else {
2159 switch (if_cond) {
2160 case kCondEQ:
2161 __ Beqc(lhs, rhs_reg, true_target);
2162 break;
2163 case kCondNE:
2164 __ Bnec(lhs, rhs_reg, true_target);
2165 break;
2166 case kCondLT:
2167 __ Bltc(lhs, rhs_reg, true_target);
2168 break;
2169 case kCondGE:
2170 __ Bgec(lhs, rhs_reg, true_target);
2171 break;
2172 case kCondLE:
2173 __ Bgec(rhs_reg, lhs, true_target);
2174 break;
2175 case kCondGT:
2176 __ Bltc(rhs_reg, lhs, true_target);
2177 break;
Aart Bike9f37602015-10-09 11:15:55 -07002178 case kCondB:
2179 __ Bltuc(lhs, rhs_reg, true_target);
2180 break;
2181 case kCondAE:
2182 __ Bgeuc(lhs, rhs_reg, true_target);
2183 break;
2184 case kCondBE:
2185 __ Bgeuc(rhs_reg, lhs, true_target);
2186 break;
2187 case kCondA:
2188 __ Bltuc(rhs_reg, lhs, true_target);
2189 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002190 }
2191 }
2192 }
2193 }
2194 if (false_target != nullptr) {
2195 __ B(false_target);
2196 }
2197}
2198
2199void LocationsBuilderMIPS64::VisitIf(HIf* if_instr) {
2200 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
2201 HInstruction* cond = if_instr->InputAt(0);
2202 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
2203 locations->SetInAt(0, Location::RequiresRegister());
2204 }
2205}
2206
2207void InstructionCodeGeneratorMIPS64::VisitIf(HIf* if_instr) {
2208 Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
2209 Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
2210 Label* always_true_target = true_target;
2211 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
2212 if_instr->IfTrueSuccessor())) {
2213 always_true_target = nullptr;
2214 }
2215 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
2216 if_instr->IfFalseSuccessor())) {
2217 false_target = nullptr;
2218 }
2219 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
2220}
2221
2222void LocationsBuilderMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) {
2223 LocationSummary* locations = new (GetGraph()->GetArena())
2224 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
2225 HInstruction* cond = deoptimize->InputAt(0);
Aart Bikbb245d12015-10-19 11:05:03 -07002226 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002227 locations->SetInAt(0, Location::RequiresRegister());
2228 }
2229}
2230
2231void InstructionCodeGeneratorMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) {
2232 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena())
2233 DeoptimizationSlowPathMIPS64(deoptimize);
2234 codegen_->AddSlowPath(slow_path);
2235 Label* slow_path_entry = slow_path->GetEntryLabel();
2236 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
2237}
2238
2239void LocationsBuilderMIPS64::HandleFieldGet(HInstruction* instruction,
2240 const FieldInfo& field_info ATTRIBUTE_UNUSED) {
2241 LocationSummary* locations =
2242 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2243 locations->SetInAt(0, Location::RequiresRegister());
2244 if (Primitive::IsFloatingPointType(instruction->GetType())) {
2245 locations->SetOut(Location::RequiresFpuRegister());
2246 } else {
2247 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2248 }
2249}
2250
2251void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction,
2252 const FieldInfo& field_info) {
2253 Primitive::Type type = field_info.GetFieldType();
2254 LocationSummary* locations = instruction->GetLocations();
2255 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2256 LoadOperandType load_type = kLoadUnsignedByte;
2257 switch (type) {
2258 case Primitive::kPrimBoolean:
2259 load_type = kLoadUnsignedByte;
2260 break;
2261 case Primitive::kPrimByte:
2262 load_type = kLoadSignedByte;
2263 break;
2264 case Primitive::kPrimShort:
2265 load_type = kLoadSignedHalfword;
2266 break;
2267 case Primitive::kPrimChar:
2268 load_type = kLoadUnsignedHalfword;
2269 break;
2270 case Primitive::kPrimInt:
2271 case Primitive::kPrimFloat:
2272 load_type = kLoadWord;
2273 break;
2274 case Primitive::kPrimLong:
2275 case Primitive::kPrimDouble:
2276 load_type = kLoadDoubleword;
2277 break;
2278 case Primitive::kPrimNot:
2279 load_type = kLoadUnsignedWord;
2280 break;
2281 case Primitive::kPrimVoid:
2282 LOG(FATAL) << "Unreachable type " << type;
2283 UNREACHABLE();
2284 }
2285 if (!Primitive::IsFloatingPointType(type)) {
2286 DCHECK(locations->Out().IsRegister());
2287 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2288 __ LoadFromOffset(load_type, dst, obj, field_info.GetFieldOffset().Uint32Value());
2289 } else {
2290 DCHECK(locations->Out().IsFpuRegister());
2291 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
2292 __ LoadFpuFromOffset(load_type, dst, obj, field_info.GetFieldOffset().Uint32Value());
2293 }
2294
2295 codegen_->MaybeRecordImplicitNullCheck(instruction);
2296 // TODO: memory barrier?
2297}
2298
2299void LocationsBuilderMIPS64::HandleFieldSet(HInstruction* instruction,
2300 const FieldInfo& field_info ATTRIBUTE_UNUSED) {
2301 LocationSummary* locations =
2302 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2303 locations->SetInAt(0, Location::RequiresRegister());
2304 if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) {
2305 locations->SetInAt(1, Location::RequiresFpuRegister());
2306 } else {
2307 locations->SetInAt(1, Location::RequiresRegister());
2308 }
2309}
2310
2311void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction,
2312 const FieldInfo& field_info) {
2313 Primitive::Type type = field_info.GetFieldType();
2314 LocationSummary* locations = instruction->GetLocations();
2315 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2316 StoreOperandType store_type = kStoreByte;
2317 switch (type) {
2318 case Primitive::kPrimBoolean:
2319 case Primitive::kPrimByte:
2320 store_type = kStoreByte;
2321 break;
2322 case Primitive::kPrimShort:
2323 case Primitive::kPrimChar:
2324 store_type = kStoreHalfword;
2325 break;
2326 case Primitive::kPrimInt:
2327 case Primitive::kPrimFloat:
2328 case Primitive::kPrimNot:
2329 store_type = kStoreWord;
2330 break;
2331 case Primitive::kPrimLong:
2332 case Primitive::kPrimDouble:
2333 store_type = kStoreDoubleword;
2334 break;
2335 case Primitive::kPrimVoid:
2336 LOG(FATAL) << "Unreachable type " << type;
2337 UNREACHABLE();
2338 }
2339 if (!Primitive::IsFloatingPointType(type)) {
2340 DCHECK(locations->InAt(1).IsRegister());
2341 GpuRegister src = locations->InAt(1).AsRegister<GpuRegister>();
2342 __ StoreToOffset(store_type, src, obj, field_info.GetFieldOffset().Uint32Value());
2343 } else {
2344 DCHECK(locations->InAt(1).IsFpuRegister());
2345 FpuRegister src = locations->InAt(1).AsFpuRegister<FpuRegister>();
2346 __ StoreFpuToOffset(store_type, src, obj, field_info.GetFieldOffset().Uint32Value());
2347 }
2348
2349 codegen_->MaybeRecordImplicitNullCheck(instruction);
2350 // TODO: memory barriers?
2351 if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) {
2352 DCHECK(locations->InAt(1).IsRegister());
2353 GpuRegister src = locations->InAt(1).AsRegister<GpuRegister>();
2354 codegen_->MarkGCCard(obj, src);
2355 }
2356}
2357
2358void LocationsBuilderMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2359 HandleFieldGet(instruction, instruction->GetFieldInfo());
2360}
2361
2362void InstructionCodeGeneratorMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2363 HandleFieldGet(instruction, instruction->GetFieldInfo());
2364}
2365
2366void LocationsBuilderMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2367 HandleFieldSet(instruction, instruction->GetFieldInfo());
2368}
2369
2370void InstructionCodeGeneratorMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2371 HandleFieldSet(instruction, instruction->GetFieldInfo());
2372}
2373
2374void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) {
2375 LocationSummary::CallKind call_kind =
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00002376 instruction->IsExactCheck() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002377 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
2378 locations->SetInAt(0, Location::RequiresRegister());
2379 locations->SetInAt(1, Location::RequiresRegister());
2380 // The output does overlap inputs.
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01002381 // Note that TypeCheckSlowPathMIPS64 uses this register too.
Alexey Frunze4dda3372015-06-01 18:31:49 -07002382 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
2383}
2384
2385void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) {
2386 LocationSummary* locations = instruction->GetLocations();
2387 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2388 GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>();
2389 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2390
2391 Label done;
2392
2393 // Return 0 if `obj` is null.
2394 // TODO: Avoid this check if we know `obj` is not null.
2395 __ Move(out, ZERO);
2396 __ Beqzc(obj, &done);
2397
2398 // Compare the class of `obj` with `cls`.
2399 __ LoadFromOffset(kLoadUnsignedWord, out, obj, mirror::Object::ClassOffset().Int32Value());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00002400 if (instruction->IsExactCheck()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002401 // Classes must be equal for the instanceof to succeed.
2402 __ Xor(out, out, cls);
2403 __ Sltiu(out, out, 1);
2404 } else {
2405 // If the classes are not equal, we go into a slow path.
2406 DCHECK(locations->OnlyCallsOnSlowPath());
2407 SlowPathCodeMIPS64* slow_path =
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01002408 new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002409 codegen_->AddSlowPath(slow_path);
2410 __ Bnec(out, cls, slow_path->GetEntryLabel());
2411 __ LoadConst32(out, 1);
2412 __ Bind(slow_path->GetExitLabel());
2413 }
2414
2415 __ Bind(&done);
2416}
2417
2418void LocationsBuilderMIPS64::VisitIntConstant(HIntConstant* constant) {
2419 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2420 locations->SetOut(Location::ConstantLocation(constant));
2421}
2422
2423void InstructionCodeGeneratorMIPS64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
2424 // Will be generated at use site.
2425}
2426
2427void LocationsBuilderMIPS64::VisitNullConstant(HNullConstant* constant) {
2428 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2429 locations->SetOut(Location::ConstantLocation(constant));
2430}
2431
2432void InstructionCodeGeneratorMIPS64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
2433 // Will be generated at use site.
2434}
2435
Calin Juravle175dc732015-08-25 15:42:32 +01002436void LocationsBuilderMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
2437 // The trampoline uses the same calling convention as dex calling conventions,
2438 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
2439 // the method_idx.
2440 HandleInvoke(invoke);
2441}
2442
2443void InstructionCodeGeneratorMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
2444 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
2445}
2446
Alexey Frunze4dda3372015-06-01 18:31:49 -07002447void LocationsBuilderMIPS64::HandleInvoke(HInvoke* invoke) {
2448 InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor;
2449 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
2450}
2451
2452void LocationsBuilderMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) {
2453 HandleInvoke(invoke);
2454 // The register T0 is required to be used for the hidden argument in
2455 // art_quick_imt_conflict_trampoline, so add the hidden argument.
2456 invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0));
2457}
2458
2459void InstructionCodeGeneratorMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) {
2460 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
2461 GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>();
2462 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
2463 invoke->GetImtIndex() % mirror::Class::kImtSize, kMips64PointerSize).Uint32Value();
2464 Location receiver = invoke->GetLocations()->InAt(0);
2465 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2466 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64WordSize);
2467
2468 // Set the hidden argument.
2469 __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<GpuRegister>(),
2470 invoke->GetDexMethodIndex());
2471
2472 // temp = object->GetClass();
2473 if (receiver.IsStackSlot()) {
2474 __ LoadFromOffset(kLoadUnsignedWord, temp, SP, receiver.GetStackIndex());
2475 __ LoadFromOffset(kLoadUnsignedWord, temp, temp, class_offset);
2476 } else {
2477 __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset);
2478 }
2479 codegen_->MaybeRecordImplicitNullCheck(invoke);
2480 // temp = temp->GetImtEntryAt(method_offset);
2481 __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset);
2482 // T9 = temp->GetEntryPoint();
2483 __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value());
2484 // T9();
2485 __ Jalr(T9);
2486 DCHECK(!codegen_->IsLeafMethod());
2487 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2488}
2489
2490void LocationsBuilderMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Chris Larsen3039e382015-08-26 07:54:08 -07002491 IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_);
2492 if (intrinsic.TryDispatch(invoke)) {
2493 return;
2494 }
2495
Alexey Frunze4dda3372015-06-01 18:31:49 -07002496 HandleInvoke(invoke);
2497}
2498
2499void LocationsBuilderMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
2500 // When we do not run baseline, explicit clinit checks triggered by static
2501 // invokes must have been pruned by art::PrepareForRegisterAllocation.
2502 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
2503
Chris Larsen3039e382015-08-26 07:54:08 -07002504 IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_);
2505 if (intrinsic.TryDispatch(invoke)) {
2506 return;
2507 }
2508
Alexey Frunze4dda3372015-06-01 18:31:49 -07002509 HandleInvoke(invoke);
2510
2511 // While SetupBlockedRegisters() blocks registers S2-S8 due to their
2512 // clobbering somewhere else, reduce further register pressure by avoiding
2513 // allocation of a register for the current method pointer like on x86 baseline.
2514 // TODO: remove this once all the issues with register saving/restoring are
2515 // sorted out.
2516 LocationSummary* locations = invoke->GetLocations();
2517 Location location = locations->InAt(invoke->GetCurrentMethodInputIndex());
2518 if (location.IsUnallocated() && location.GetPolicy() == Location::kRequiresRegister) {
2519 locations->SetInAt(invoke->GetCurrentMethodInputIndex(), Location::NoLocation());
2520 }
2521}
2522
Chris Larsen3039e382015-08-26 07:54:08 -07002523static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS64* codegen) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002524 if (invoke->GetLocations()->Intrinsified()) {
Chris Larsen3039e382015-08-26 07:54:08 -07002525 IntrinsicCodeGeneratorMIPS64 intrinsic(codegen);
2526 intrinsic.Dispatch(invoke);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002527 return true;
2528 }
2529 return false;
2530}
2531
2532void CodeGeneratorMIPS64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
2533 // All registers are assumed to be correctly set up per the calling convention.
2534
Vladimir Marko58155012015-08-19 12:49:41 +00002535 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
2536 switch (invoke->GetMethodLoadKind()) {
2537 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
2538 // temp = thread->string_init_entrypoint
2539 __ LoadFromOffset(kLoadDoubleword,
2540 temp.AsRegister<GpuRegister>(),
2541 TR,
2542 invoke->GetStringInitOffset());
2543 break;
2544 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
2545 callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
2546 break;
2547 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
2548 __ LoadConst64(temp.AsRegister<GpuRegister>(), invoke->GetMethodAddress());
2549 break;
2550 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
2551 // TODO: Implement this type. (Needs literal support.) At the moment, the
2552 // CompilerDriver will not direct the backend to use this type for MIPS.
2553 LOG(FATAL) << "Unsupported!";
2554 UNREACHABLE();
2555 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative:
2556 // TODO: Implement this type. For the moment, we fall back to kDexCacheViaMethod.
2557 FALLTHROUGH_INTENDED;
2558 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
2559 Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
2560 GpuRegister reg = temp.AsRegister<GpuRegister>();
2561 GpuRegister method_reg;
2562 if (current_method.IsRegister()) {
2563 method_reg = current_method.AsRegister<GpuRegister>();
2564 } else {
2565 // TODO: use the appropriate DCHECK() here if possible.
2566 // DCHECK(invoke->GetLocations()->Intrinsified());
2567 DCHECK(!current_method.IsValid());
2568 method_reg = reg;
2569 __ Ld(reg, SP, kCurrentMethodStackOffset);
2570 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002571
Vladimir Marko58155012015-08-19 12:49:41 +00002572 // temp = temp->dex_cache_resolved_methods_;
Vladimir Marko05792b92015-08-03 11:56:49 +01002573 __ LoadFromOffset(kLoadDoubleword,
Vladimir Marko58155012015-08-19 12:49:41 +00002574 reg,
2575 method_reg,
Vladimir Marko05792b92015-08-03 11:56:49 +01002576 ArtMethod::DexCacheResolvedMethodsOffset(kMips64PointerSize).Int32Value());
Vladimir Marko58155012015-08-19 12:49:41 +00002577 // temp = temp[index_in_cache]
2578 uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index;
2579 __ LoadFromOffset(kLoadDoubleword,
2580 reg,
2581 reg,
2582 CodeGenerator::GetCachePointerOffset(index_in_cache));
2583 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002584 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002585 }
2586
Vladimir Marko58155012015-08-19 12:49:41 +00002587 switch (invoke->GetCodePtrLocation()) {
2588 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
2589 __ Jalr(&frame_entry_label_, T9);
2590 break;
2591 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
2592 // LR = invoke->GetDirectCodePtr();
2593 __ LoadConst64(T9, invoke->GetDirectCodePtr());
2594 // LR()
2595 __ Jalr(T9);
2596 break;
2597 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
2598 // TODO: Implement kCallPCRelative. For the moment, we fall back to kMethodCode.
2599 FALLTHROUGH_INTENDED;
2600 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
2601 // TODO: Implement kDirectCodeFixup. For the moment, we fall back to kMethodCode.
2602 FALLTHROUGH_INTENDED;
2603 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
2604 // T9 = callee_method->entry_point_from_quick_compiled_code_;
2605 __ LoadFromOffset(kLoadDoubleword,
2606 T9,
2607 callee_method.AsRegister<GpuRegister>(),
2608 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
2609 kMips64WordSize).Int32Value());
2610 // T9()
2611 __ Jalr(T9);
2612 break;
2613 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002614 DCHECK(!IsLeafMethod());
2615}
2616
2617void InstructionCodeGeneratorMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
2618 // When we do not run baseline, explicit clinit checks triggered by static
2619 // invokes must have been pruned by art::PrepareForRegisterAllocation.
2620 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
2621
2622 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2623 return;
2624 }
2625
2626 LocationSummary* locations = invoke->GetLocations();
2627 codegen_->GenerateStaticOrDirectCall(invoke,
2628 locations->HasTemps()
2629 ? locations->GetTemp(0)
2630 : Location::NoLocation());
2631 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2632}
2633
2634void InstructionCodeGeneratorMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Chris Larsen3039e382015-08-26 07:54:08 -07002635 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2636 return;
2637 }
2638
Alexey Frunze4dda3372015-06-01 18:31:49 -07002639 LocationSummary* locations = invoke->GetLocations();
2640 Location receiver = locations->InAt(0);
2641 GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>();
2642 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
2643 invoke->GetVTableIndex(), kMips64PointerSize).SizeValue();
2644 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2645 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64WordSize);
2646
2647 // temp = object->GetClass();
2648 DCHECK(receiver.IsRegister());
2649 __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset);
2650 codegen_->MaybeRecordImplicitNullCheck(invoke);
2651 // temp = temp->GetMethodAt(method_offset);
2652 __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset);
2653 // T9 = temp->GetEntryPoint();
2654 __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value());
2655 // T9();
2656 __ Jalr(T9);
2657 DCHECK(!codegen_->IsLeafMethod());
2658 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2659}
2660
2661void LocationsBuilderMIPS64::VisitLoadClass(HLoadClass* cls) {
Calin Juravle98893e12015-10-02 21:05:03 +01002662 InvokeRuntimeCallingConvention calling_convention;
2663 CodeGenerator::CreateLoadClassLocationSummary(
2664 cls,
2665 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
2666 Location::RegisterLocation(A0));
Alexey Frunze4dda3372015-06-01 18:31:49 -07002667}
2668
2669void InstructionCodeGeneratorMIPS64::VisitLoadClass(HLoadClass* cls) {
2670 LocationSummary* locations = cls->GetLocations();
Calin Juravle98893e12015-10-02 21:05:03 +01002671 if (cls->NeedsAccessCheck()) {
2672 codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex());
2673 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess),
2674 cls,
2675 cls->GetDexPc(),
2676 nullptr);
Calin Juravle580b6092015-10-06 17:35:58 +01002677 return;
2678 }
2679
2680 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2681 GpuRegister current_method = locations->InAt(0).AsRegister<GpuRegister>();
2682 if (cls->IsReferrersClass()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002683 DCHECK(!cls->CanCallRuntime());
2684 DCHECK(!cls->MustGenerateClinitCheck());
2685 __ LoadFromOffset(kLoadUnsignedWord, out, current_method,
2686 ArtMethod::DeclaringClassOffset().Int32Value());
2687 } else {
2688 DCHECK(cls->CanCallRuntime());
Vladimir Marko05792b92015-08-03 11:56:49 +01002689 __ LoadFromOffset(kLoadDoubleword, out, current_method,
2690 ArtMethod::DexCacheResolvedTypesOffset(kMips64PointerSize).Int32Value());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002691 __ LoadFromOffset(kLoadUnsignedWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Vladimir Marko05792b92015-08-03 11:56:49 +01002692 // TODO: We will need a read barrier here.
Alexey Frunze4dda3372015-06-01 18:31:49 -07002693 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64(
2694 cls,
2695 cls,
2696 cls->GetDexPc(),
2697 cls->MustGenerateClinitCheck());
2698 codegen_->AddSlowPath(slow_path);
2699 __ Beqzc(out, slow_path->GetEntryLabel());
2700 if (cls->MustGenerateClinitCheck()) {
2701 GenerateClassInitializationCheck(slow_path, out);
2702 } else {
2703 __ Bind(slow_path->GetExitLabel());
2704 }
2705 }
2706}
2707
David Brazdilcb1c0552015-08-04 16:22:25 +01002708static int32_t GetExceptionTlsOffset() {
2709 return Thread::ExceptionOffset<kMips64WordSize>().Int32Value();
2710}
2711
Alexey Frunze4dda3372015-06-01 18:31:49 -07002712void LocationsBuilderMIPS64::VisitLoadException(HLoadException* load) {
2713 LocationSummary* locations =
2714 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2715 locations->SetOut(Location::RequiresRegister());
2716}
2717
2718void InstructionCodeGeneratorMIPS64::VisitLoadException(HLoadException* load) {
2719 GpuRegister out = load->GetLocations()->Out().AsRegister<GpuRegister>();
David Brazdilcb1c0552015-08-04 16:22:25 +01002720 __ LoadFromOffset(kLoadUnsignedWord, out, TR, GetExceptionTlsOffset());
2721}
2722
2723void LocationsBuilderMIPS64::VisitClearException(HClearException* clear) {
2724 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
2725}
2726
2727void InstructionCodeGeneratorMIPS64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
2728 __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002729}
2730
2731void LocationsBuilderMIPS64::VisitLoadLocal(HLoadLocal* load) {
2732 load->SetLocations(nullptr);
2733}
2734
2735void InstructionCodeGeneratorMIPS64::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) {
2736 // Nothing to do, this is driven by the code generator.
2737}
2738
2739void LocationsBuilderMIPS64::VisitLoadString(HLoadString* load) {
2740 LocationSummary* locations =
2741 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2742 locations->SetInAt(0, Location::RequiresRegister());
2743 locations->SetOut(Location::RequiresRegister());
2744}
2745
2746void InstructionCodeGeneratorMIPS64::VisitLoadString(HLoadString* load) {
2747 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS64(load);
2748 codegen_->AddSlowPath(slow_path);
2749
2750 LocationSummary* locations = load->GetLocations();
2751 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2752 GpuRegister current_method = locations->InAt(0).AsRegister<GpuRegister>();
2753 __ LoadFromOffset(kLoadUnsignedWord, out, current_method,
2754 ArtMethod::DeclaringClassOffset().Int32Value());
Vladimir Marko05792b92015-08-03 11:56:49 +01002755 __ LoadFromOffset(kLoadDoubleword, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002756 __ LoadFromOffset(kLoadUnsignedWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
Vladimir Marko05792b92015-08-03 11:56:49 +01002757 // TODO: We will need a read barrier here.
Alexey Frunze4dda3372015-06-01 18:31:49 -07002758 __ Beqzc(out, slow_path->GetEntryLabel());
2759 __ Bind(slow_path->GetExitLabel());
2760}
2761
2762void LocationsBuilderMIPS64::VisitLocal(HLocal* local) {
2763 local->SetLocations(nullptr);
2764}
2765
2766void InstructionCodeGeneratorMIPS64::VisitLocal(HLocal* local) {
2767 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
2768}
2769
2770void LocationsBuilderMIPS64::VisitLongConstant(HLongConstant* constant) {
2771 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2772 locations->SetOut(Location::ConstantLocation(constant));
2773}
2774
2775void InstructionCodeGeneratorMIPS64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
2776 // Will be generated at use site.
2777}
2778
2779void LocationsBuilderMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) {
2780 LocationSummary* locations =
2781 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2782 InvokeRuntimeCallingConvention calling_convention;
2783 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2784}
2785
2786void InstructionCodeGeneratorMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) {
2787 codegen_->InvokeRuntime(instruction->IsEnter()
2788 ? QUICK_ENTRY_POINT(pLockObject)
2789 : QUICK_ENTRY_POINT(pUnlockObject),
2790 instruction,
2791 instruction->GetDexPc(),
2792 nullptr);
2793 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
2794}
2795
2796void LocationsBuilderMIPS64::VisitMul(HMul* mul) {
2797 LocationSummary* locations =
2798 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2799 switch (mul->GetResultType()) {
2800 case Primitive::kPrimInt:
2801 case Primitive::kPrimLong:
2802 locations->SetInAt(0, Location::RequiresRegister());
2803 locations->SetInAt(1, Location::RequiresRegister());
2804 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2805 break;
2806
2807 case Primitive::kPrimFloat:
2808 case Primitive::kPrimDouble:
2809 locations->SetInAt(0, Location::RequiresFpuRegister());
2810 locations->SetInAt(1, Location::RequiresFpuRegister());
2811 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2812 break;
2813
2814 default:
2815 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2816 }
2817}
2818
2819void InstructionCodeGeneratorMIPS64::VisitMul(HMul* instruction) {
2820 Primitive::Type type = instruction->GetType();
2821 LocationSummary* locations = instruction->GetLocations();
2822
2823 switch (type) {
2824 case Primitive::kPrimInt:
2825 case Primitive::kPrimLong: {
2826 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2827 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
2828 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
2829 if (type == Primitive::kPrimInt)
2830 __ MulR6(dst, lhs, rhs);
2831 else
2832 __ Dmul(dst, lhs, rhs);
2833 break;
2834 }
2835 case Primitive::kPrimFloat:
2836 case Primitive::kPrimDouble: {
2837 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
2838 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
2839 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
2840 if (type == Primitive::kPrimFloat)
2841 __ MulS(dst, lhs, rhs);
2842 else
2843 __ MulD(dst, lhs, rhs);
2844 break;
2845 }
2846 default:
2847 LOG(FATAL) << "Unexpected mul type " << type;
2848 }
2849}
2850
2851void LocationsBuilderMIPS64::VisitNeg(HNeg* neg) {
2852 LocationSummary* locations =
2853 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
2854 switch (neg->GetResultType()) {
2855 case Primitive::kPrimInt:
2856 case Primitive::kPrimLong:
2857 locations->SetInAt(0, Location::RequiresRegister());
2858 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2859 break;
2860
2861 case Primitive::kPrimFloat:
2862 case Primitive::kPrimDouble:
2863 locations->SetInAt(0, Location::RequiresFpuRegister());
2864 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2865 break;
2866
2867 default:
2868 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2869 }
2870}
2871
2872void InstructionCodeGeneratorMIPS64::VisitNeg(HNeg* instruction) {
2873 Primitive::Type type = instruction->GetType();
2874 LocationSummary* locations = instruction->GetLocations();
2875
2876 switch (type) {
2877 case Primitive::kPrimInt:
2878 case Primitive::kPrimLong: {
2879 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2880 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
2881 if (type == Primitive::kPrimInt)
2882 __ Subu(dst, ZERO, src);
2883 else
2884 __ Dsubu(dst, ZERO, src);
2885 break;
2886 }
2887 case Primitive::kPrimFloat:
2888 case Primitive::kPrimDouble: {
2889 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
2890 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
2891 if (type == Primitive::kPrimFloat)
2892 __ NegS(dst, src);
2893 else
2894 __ NegD(dst, src);
2895 break;
2896 }
2897 default:
2898 LOG(FATAL) << "Unexpected neg type " << type;
2899 }
2900}
2901
2902void LocationsBuilderMIPS64::VisitNewArray(HNewArray* instruction) {
2903 LocationSummary* locations =
2904 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2905 InvokeRuntimeCallingConvention calling_convention;
2906 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2907 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
2908 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2909 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2910}
2911
2912void InstructionCodeGeneratorMIPS64::VisitNewArray(HNewArray* instruction) {
2913 LocationSummary* locations = instruction->GetLocations();
2914 // Move an uint16_t value to a register.
2915 __ LoadConst32(locations->GetTemp(0).AsRegister<GpuRegister>(), instruction->GetTypeIndex());
Calin Juravle175dc732015-08-25 15:42:32 +01002916 codegen_->InvokeRuntime(instruction->GetEntrypoint(),
2917 instruction,
2918 instruction->GetDexPc(),
2919 nullptr);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002920 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>();
2921}
2922
2923void LocationsBuilderMIPS64::VisitNewInstance(HNewInstance* instruction) {
2924 LocationSummary* locations =
2925 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2926 InvokeRuntimeCallingConvention calling_convention;
2927 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2928 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2929 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
2930}
2931
2932void InstructionCodeGeneratorMIPS64::VisitNewInstance(HNewInstance* instruction) {
2933 LocationSummary* locations = instruction->GetLocations();
2934 // Move an uint16_t value to a register.
2935 __ LoadConst32(locations->GetTemp(0).AsRegister<GpuRegister>(), instruction->GetTypeIndex());
Calin Juravle175dc732015-08-25 15:42:32 +01002936 codegen_->InvokeRuntime(instruction->GetEntrypoint(),
2937 instruction,
2938 instruction->GetDexPc(),
2939 nullptr);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002940 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
2941}
2942
2943void LocationsBuilderMIPS64::VisitNot(HNot* instruction) {
2944 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2945 locations->SetInAt(0, Location::RequiresRegister());
2946 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2947}
2948
2949void InstructionCodeGeneratorMIPS64::VisitNot(HNot* instruction) {
2950 Primitive::Type type = instruction->GetType();
2951 LocationSummary* locations = instruction->GetLocations();
2952
2953 switch (type) {
2954 case Primitive::kPrimInt:
2955 case Primitive::kPrimLong: {
2956 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2957 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
2958 __ Nor(dst, src, ZERO);
2959 break;
2960 }
2961
2962 default:
2963 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
2964 }
2965}
2966
2967void LocationsBuilderMIPS64::VisitBooleanNot(HBooleanNot* instruction) {
2968 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2969 locations->SetInAt(0, Location::RequiresRegister());
2970 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2971}
2972
2973void InstructionCodeGeneratorMIPS64::VisitBooleanNot(HBooleanNot* instruction) {
2974 LocationSummary* locations = instruction->GetLocations();
2975 __ Xori(locations->Out().AsRegister<GpuRegister>(),
2976 locations->InAt(0).AsRegister<GpuRegister>(),
2977 1);
2978}
2979
2980void LocationsBuilderMIPS64::VisitNullCheck(HNullCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00002981 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
2982 ? LocationSummary::kCallOnSlowPath
2983 : LocationSummary::kNoCall;
2984 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002985 locations->SetInAt(0, Location::RequiresRegister());
2986 if (instruction->HasUses()) {
2987 locations->SetOut(Location::SameAsFirstInput());
2988 }
2989}
2990
2991void InstructionCodeGeneratorMIPS64::GenerateImplicitNullCheck(HNullCheck* instruction) {
2992 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2993 return;
2994 }
2995 Location obj = instruction->GetLocations()->InAt(0);
2996
2997 __ Lw(ZERO, obj.AsRegister<GpuRegister>(), 0);
2998 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2999}
3000
3001void InstructionCodeGeneratorMIPS64::GenerateExplicitNullCheck(HNullCheck* instruction) {
3002 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS64(instruction);
3003 codegen_->AddSlowPath(slow_path);
3004
3005 Location obj = instruction->GetLocations()->InAt(0);
3006
3007 __ Beqzc(obj.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
3008}
3009
3010void InstructionCodeGeneratorMIPS64::VisitNullCheck(HNullCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00003011 if (codegen_->IsImplicitNullCheckAllowed(instruction)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003012 GenerateImplicitNullCheck(instruction);
3013 } else {
3014 GenerateExplicitNullCheck(instruction);
3015 }
3016}
3017
3018void LocationsBuilderMIPS64::VisitOr(HOr* instruction) {
3019 HandleBinaryOp(instruction);
3020}
3021
3022void InstructionCodeGeneratorMIPS64::VisitOr(HOr* instruction) {
3023 HandleBinaryOp(instruction);
3024}
3025
3026void LocationsBuilderMIPS64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
3027 LOG(FATAL) << "Unreachable";
3028}
3029
3030void InstructionCodeGeneratorMIPS64::VisitParallelMove(HParallelMove* instruction) {
3031 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3032}
3033
3034void LocationsBuilderMIPS64::VisitParameterValue(HParameterValue* instruction) {
3035 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
3036 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
3037 if (location.IsStackSlot()) {
3038 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3039 } else if (location.IsDoubleStackSlot()) {
3040 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3041 }
3042 locations->SetOut(location);
3043}
3044
3045void InstructionCodeGeneratorMIPS64::VisitParameterValue(HParameterValue* instruction
3046 ATTRIBUTE_UNUSED) {
3047 // Nothing to do, the parameter is already at its location.
3048}
3049
3050void LocationsBuilderMIPS64::VisitCurrentMethod(HCurrentMethod* instruction) {
3051 LocationSummary* locations =
3052 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3053 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
3054}
3055
3056void InstructionCodeGeneratorMIPS64::VisitCurrentMethod(HCurrentMethod* instruction
3057 ATTRIBUTE_UNUSED) {
3058 // Nothing to do, the method is already at its location.
3059}
3060
3061void LocationsBuilderMIPS64::VisitPhi(HPhi* instruction) {
3062 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
3063 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
3064 locations->SetInAt(i, Location::Any());
3065 }
3066 locations->SetOut(Location::Any());
3067}
3068
3069void InstructionCodeGeneratorMIPS64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
3070 LOG(FATAL) << "Unreachable";
3071}
3072
3073void LocationsBuilderMIPS64::VisitRem(HRem* rem) {
3074 Primitive::Type type = rem->GetResultType();
3075 LocationSummary::CallKind call_kind =
3076 Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall;
3077 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
3078
3079 switch (type) {
3080 case Primitive::kPrimInt:
3081 case Primitive::kPrimLong:
3082 locations->SetInAt(0, Location::RequiresRegister());
3083 locations->SetInAt(1, Location::RequiresRegister());
3084 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3085 break;
3086
3087 case Primitive::kPrimFloat:
3088 case Primitive::kPrimDouble: {
3089 InvokeRuntimeCallingConvention calling_convention;
3090 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
3091 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
3092 locations->SetOut(calling_convention.GetReturnLocation(type));
3093 break;
3094 }
3095
3096 default:
3097 LOG(FATAL) << "Unexpected rem type " << type;
3098 }
3099}
3100
3101void InstructionCodeGeneratorMIPS64::VisitRem(HRem* instruction) {
3102 Primitive::Type type = instruction->GetType();
3103 LocationSummary* locations = instruction->GetLocations();
3104
3105 switch (type) {
3106 case Primitive::kPrimInt:
3107 case Primitive::kPrimLong: {
3108 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3109 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
3110 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
3111 if (type == Primitive::kPrimInt)
3112 __ ModR6(dst, lhs, rhs);
3113 else
3114 __ Dmod(dst, lhs, rhs);
3115 break;
3116 }
3117
3118 case Primitive::kPrimFloat:
3119 case Primitive::kPrimDouble: {
3120 int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf)
3121 : QUICK_ENTRY_POINT(pFmod);
3122 codegen_->InvokeRuntime(entry_offset, instruction, instruction->GetDexPc(), nullptr);
3123 break;
3124 }
3125 default:
3126 LOG(FATAL) << "Unexpected rem type " << type;
3127 }
3128}
3129
3130void LocationsBuilderMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
3131 memory_barrier->SetLocations(nullptr);
3132}
3133
3134void InstructionCodeGeneratorMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
3135 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
3136}
3137
3138void LocationsBuilderMIPS64::VisitReturn(HReturn* ret) {
3139 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret);
3140 Primitive::Type return_type = ret->InputAt(0)->GetType();
3141 locations->SetInAt(0, Mips64ReturnLocation(return_type));
3142}
3143
3144void InstructionCodeGeneratorMIPS64::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
3145 codegen_->GenerateFrameExit();
3146}
3147
3148void LocationsBuilderMIPS64::VisitReturnVoid(HReturnVoid* ret) {
3149 ret->SetLocations(nullptr);
3150}
3151
3152void InstructionCodeGeneratorMIPS64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
3153 codegen_->GenerateFrameExit();
3154}
3155
3156void LocationsBuilderMIPS64::VisitShl(HShl* shl) {
3157 HandleShift(shl);
3158}
3159
3160void InstructionCodeGeneratorMIPS64::VisitShl(HShl* shl) {
3161 HandleShift(shl);
3162}
3163
3164void LocationsBuilderMIPS64::VisitShr(HShr* shr) {
3165 HandleShift(shr);
3166}
3167
3168void InstructionCodeGeneratorMIPS64::VisitShr(HShr* shr) {
3169 HandleShift(shr);
3170}
3171
3172void LocationsBuilderMIPS64::VisitStoreLocal(HStoreLocal* store) {
3173 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store);
3174 Primitive::Type field_type = store->InputAt(1)->GetType();
3175 switch (field_type) {
3176 case Primitive::kPrimNot:
3177 case Primitive::kPrimBoolean:
3178 case Primitive::kPrimByte:
3179 case Primitive::kPrimChar:
3180 case Primitive::kPrimShort:
3181 case Primitive::kPrimInt:
3182 case Primitive::kPrimFloat:
3183 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
3184 break;
3185
3186 case Primitive::kPrimLong:
3187 case Primitive::kPrimDouble:
3188 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
3189 break;
3190
3191 default:
3192 LOG(FATAL) << "Unimplemented local type " << field_type;
3193 }
3194}
3195
3196void InstructionCodeGeneratorMIPS64::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) {
3197}
3198
3199void LocationsBuilderMIPS64::VisitSub(HSub* instruction) {
3200 HandleBinaryOp(instruction);
3201}
3202
3203void InstructionCodeGeneratorMIPS64::VisitSub(HSub* instruction) {
3204 HandleBinaryOp(instruction);
3205}
3206
3207void LocationsBuilderMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3208 HandleFieldGet(instruction, instruction->GetFieldInfo());
3209}
3210
3211void InstructionCodeGeneratorMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3212 HandleFieldGet(instruction, instruction->GetFieldInfo());
3213}
3214
3215void LocationsBuilderMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3216 HandleFieldSet(instruction, instruction->GetFieldInfo());
3217}
3218
3219void InstructionCodeGeneratorMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3220 HandleFieldSet(instruction, instruction->GetFieldInfo());
3221}
3222
Calin Juravlee460d1d2015-09-29 04:52:17 +01003223void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldGet(
3224 HUnresolvedInstanceFieldGet* instruction) {
3225 FieldAccessCallingConventionMIPS64 calling_convention;
3226 codegen_->CreateUnresolvedFieldLocationSummary(
3227 instruction, instruction->GetFieldType(), calling_convention);
3228}
3229
3230void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldGet(
3231 HUnresolvedInstanceFieldGet* instruction) {
3232 FieldAccessCallingConventionMIPS64 calling_convention;
3233 codegen_->GenerateUnresolvedFieldAccess(instruction,
3234 instruction->GetFieldType(),
3235 instruction->GetFieldIndex(),
3236 instruction->GetDexPc(),
3237 calling_convention);
3238}
3239
3240void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldSet(
3241 HUnresolvedInstanceFieldSet* instruction) {
3242 FieldAccessCallingConventionMIPS64 calling_convention;
3243 codegen_->CreateUnresolvedFieldLocationSummary(
3244 instruction, instruction->GetFieldType(), calling_convention);
3245}
3246
3247void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldSet(
3248 HUnresolvedInstanceFieldSet* instruction) {
3249 FieldAccessCallingConventionMIPS64 calling_convention;
3250 codegen_->GenerateUnresolvedFieldAccess(instruction,
3251 instruction->GetFieldType(),
3252 instruction->GetFieldIndex(),
3253 instruction->GetDexPc(),
3254 calling_convention);
3255}
3256
3257void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldGet(
3258 HUnresolvedStaticFieldGet* instruction) {
3259 FieldAccessCallingConventionMIPS64 calling_convention;
3260 codegen_->CreateUnresolvedFieldLocationSummary(
3261 instruction, instruction->GetFieldType(), calling_convention);
3262}
3263
3264void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldGet(
3265 HUnresolvedStaticFieldGet* instruction) {
3266 FieldAccessCallingConventionMIPS64 calling_convention;
3267 codegen_->GenerateUnresolvedFieldAccess(instruction,
3268 instruction->GetFieldType(),
3269 instruction->GetFieldIndex(),
3270 instruction->GetDexPc(),
3271 calling_convention);
3272}
3273
3274void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldSet(
3275 HUnresolvedStaticFieldSet* instruction) {
3276 FieldAccessCallingConventionMIPS64 calling_convention;
3277 codegen_->CreateUnresolvedFieldLocationSummary(
3278 instruction, instruction->GetFieldType(), calling_convention);
3279}
3280
3281void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldSet(
3282 HUnresolvedStaticFieldSet* instruction) {
3283 FieldAccessCallingConventionMIPS64 calling_convention;
3284 codegen_->GenerateUnresolvedFieldAccess(instruction,
3285 instruction->GetFieldType(),
3286 instruction->GetFieldIndex(),
3287 instruction->GetDexPc(),
3288 calling_convention);
3289}
3290
Alexey Frunze4dda3372015-06-01 18:31:49 -07003291void LocationsBuilderMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) {
3292 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3293}
3294
3295void InstructionCodeGeneratorMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) {
3296 HBasicBlock* block = instruction->GetBlock();
3297 if (block->GetLoopInformation() != nullptr) {
3298 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3299 // The back edge will generate the suspend check.
3300 return;
3301 }
3302 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3303 // The goto will generate the suspend check.
3304 return;
3305 }
3306 GenerateSuspendCheck(instruction, nullptr);
3307}
3308
3309void LocationsBuilderMIPS64::VisitTemporary(HTemporary* temp) {
3310 temp->SetLocations(nullptr);
3311}
3312
3313void InstructionCodeGeneratorMIPS64::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) {
3314 // Nothing to do, this is driven by the code generator.
3315}
3316
3317void LocationsBuilderMIPS64::VisitThrow(HThrow* instruction) {
3318 LocationSummary* locations =
3319 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3320 InvokeRuntimeCallingConvention calling_convention;
3321 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3322}
3323
3324void InstructionCodeGeneratorMIPS64::VisitThrow(HThrow* instruction) {
3325 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException),
3326 instruction,
3327 instruction->GetDexPc(),
3328 nullptr);
3329 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
3330}
3331
3332void LocationsBuilderMIPS64::VisitTypeConversion(HTypeConversion* conversion) {
3333 Primitive::Type input_type = conversion->GetInputType();
3334 Primitive::Type result_type = conversion->GetResultType();
3335 DCHECK_NE(input_type, result_type);
3336
3337 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
3338 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
3339 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
3340 }
3341
3342 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
3343 if ((Primitive::IsFloatingPointType(result_type) && input_type == Primitive::kPrimLong) ||
3344 (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type))) {
3345 call_kind = LocationSummary::kCall;
3346 }
3347
3348 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
3349
3350 if (call_kind == LocationSummary::kNoCall) {
3351 if (Primitive::IsFloatingPointType(input_type)) {
3352 locations->SetInAt(0, Location::RequiresFpuRegister());
3353 } else {
3354 locations->SetInAt(0, Location::RequiresRegister());
3355 }
3356
3357 if (Primitive::IsFloatingPointType(result_type)) {
3358 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3359 } else {
3360 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3361 }
3362 } else {
3363 InvokeRuntimeCallingConvention calling_convention;
3364
3365 if (Primitive::IsFloatingPointType(input_type)) {
3366 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
3367 } else {
3368 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3369 }
3370
3371 locations->SetOut(calling_convention.GetReturnLocation(result_type));
3372 }
3373}
3374
3375void InstructionCodeGeneratorMIPS64::VisitTypeConversion(HTypeConversion* conversion) {
3376 LocationSummary* locations = conversion->GetLocations();
3377 Primitive::Type result_type = conversion->GetResultType();
3378 Primitive::Type input_type = conversion->GetInputType();
3379
3380 DCHECK_NE(input_type, result_type);
3381
3382 if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
3383 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3384 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
3385
3386 switch (result_type) {
3387 case Primitive::kPrimChar:
3388 __ Andi(dst, src, 0xFFFF);
3389 break;
3390 case Primitive::kPrimByte:
3391 // long is never converted into types narrower than int directly,
3392 // so SEB and SEH can be used without ever causing unpredictable results
3393 // on 64-bit inputs
3394 DCHECK(input_type != Primitive::kPrimLong);
3395 __ Seb(dst, src);
3396 break;
3397 case Primitive::kPrimShort:
3398 // long is never converted into types narrower than int directly,
3399 // so SEB and SEH can be used without ever causing unpredictable results
3400 // on 64-bit inputs
3401 DCHECK(input_type != Primitive::kPrimLong);
3402 __ Seh(dst, src);
3403 break;
3404 case Primitive::kPrimInt:
3405 case Primitive::kPrimLong:
3406 // Sign-extend 32-bit int into bits 32 through 63 for
3407 // int-to-long and long-to-int conversions
3408 __ Sll(dst, src, 0);
3409 break;
3410
3411 default:
3412 LOG(FATAL) << "Unexpected type conversion from " << input_type
3413 << " to " << result_type;
3414 }
3415 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
3416 if (input_type != Primitive::kPrimLong) {
3417 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
3418 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
3419 __ Mtc1(src, FTMP);
3420 if (result_type == Primitive::kPrimFloat) {
3421 __ Cvtsw(dst, FTMP);
3422 } else {
3423 __ Cvtdw(dst, FTMP);
3424 }
3425 } else {
3426 int32_t entry_offset = (result_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pL2f)
3427 : QUICK_ENTRY_POINT(pL2d);
3428 codegen_->InvokeRuntime(entry_offset,
3429 conversion,
3430 conversion->GetDexPc(),
3431 nullptr);
3432 }
3433 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
3434 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
3435 int32_t entry_offset;
3436 if (result_type != Primitive::kPrimLong) {
3437 entry_offset = (input_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pF2iz)
3438 : QUICK_ENTRY_POINT(pD2iz);
3439 } else {
3440 entry_offset = (input_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pF2l)
3441 : QUICK_ENTRY_POINT(pD2l);
3442 }
3443 codegen_->InvokeRuntime(entry_offset,
3444 conversion,
3445 conversion->GetDexPc(),
3446 nullptr);
3447 } else if (Primitive::IsFloatingPointType(result_type) &&
3448 Primitive::IsFloatingPointType(input_type)) {
3449 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
3450 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
3451 if (result_type == Primitive::kPrimFloat) {
3452 __ Cvtsd(dst, src);
3453 } else {
3454 __ Cvtds(dst, src);
3455 }
3456 } else {
3457 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
3458 << " to " << result_type;
3459 }
3460}
3461
3462void LocationsBuilderMIPS64::VisitUShr(HUShr* ushr) {
3463 HandleShift(ushr);
3464}
3465
3466void InstructionCodeGeneratorMIPS64::VisitUShr(HUShr* ushr) {
3467 HandleShift(ushr);
3468}
3469
3470void LocationsBuilderMIPS64::VisitXor(HXor* instruction) {
3471 HandleBinaryOp(instruction);
3472}
3473
3474void InstructionCodeGeneratorMIPS64::VisitXor(HXor* instruction) {
3475 HandleBinaryOp(instruction);
3476}
3477
3478void LocationsBuilderMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
3479 // Nothing to do, this should be removed during prepare for register allocator.
3480 LOG(FATAL) << "Unreachable";
3481}
3482
3483void InstructionCodeGeneratorMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
3484 // Nothing to do, this should be removed during prepare for register allocator.
3485 LOG(FATAL) << "Unreachable";
3486}
3487
3488void LocationsBuilderMIPS64::VisitEqual(HEqual* comp) {
3489 VisitCondition(comp);
3490}
3491
3492void InstructionCodeGeneratorMIPS64::VisitEqual(HEqual* comp) {
3493 VisitCondition(comp);
3494}
3495
3496void LocationsBuilderMIPS64::VisitNotEqual(HNotEqual* comp) {
3497 VisitCondition(comp);
3498}
3499
3500void InstructionCodeGeneratorMIPS64::VisitNotEqual(HNotEqual* comp) {
3501 VisitCondition(comp);
3502}
3503
3504void LocationsBuilderMIPS64::VisitLessThan(HLessThan* comp) {
3505 VisitCondition(comp);
3506}
3507
3508void InstructionCodeGeneratorMIPS64::VisitLessThan(HLessThan* comp) {
3509 VisitCondition(comp);
3510}
3511
3512void LocationsBuilderMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
3513 VisitCondition(comp);
3514}
3515
3516void InstructionCodeGeneratorMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
3517 VisitCondition(comp);
3518}
3519
3520void LocationsBuilderMIPS64::VisitGreaterThan(HGreaterThan* comp) {
3521 VisitCondition(comp);
3522}
3523
3524void InstructionCodeGeneratorMIPS64::VisitGreaterThan(HGreaterThan* comp) {
3525 VisitCondition(comp);
3526}
3527
3528void LocationsBuilderMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
3529 VisitCondition(comp);
3530}
3531
3532void InstructionCodeGeneratorMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
3533 VisitCondition(comp);
3534}
3535
Aart Bike9f37602015-10-09 11:15:55 -07003536void LocationsBuilderMIPS64::VisitBelow(HBelow* comp) {
3537 VisitCondition(comp);
3538}
3539
3540void InstructionCodeGeneratorMIPS64::VisitBelow(HBelow* comp) {
3541 VisitCondition(comp);
3542}
3543
3544void LocationsBuilderMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) {
3545 VisitCondition(comp);
3546}
3547
3548void InstructionCodeGeneratorMIPS64::VisitBelowOrEqual(HBelowOrEqual* comp) {
3549 VisitCondition(comp);
3550}
3551
3552void LocationsBuilderMIPS64::VisitAbove(HAbove* comp) {
3553 VisitCondition(comp);
3554}
3555
3556void InstructionCodeGeneratorMIPS64::VisitAbove(HAbove* comp) {
3557 VisitCondition(comp);
3558}
3559
3560void LocationsBuilderMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) {
3561 VisitCondition(comp);
3562}
3563
3564void InstructionCodeGeneratorMIPS64::VisitAboveOrEqual(HAboveOrEqual* comp) {
3565 VisitCondition(comp);
3566}
3567
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +01003568void LocationsBuilderMIPS64::VisitFakeString(HFakeString* instruction) {
3569 DCHECK(codegen_->IsBaseline());
3570 LocationSummary* locations =
3571 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3572 locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant()));
3573}
3574
3575void InstructionCodeGeneratorMIPS64::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) {
3576 DCHECK(codegen_->IsBaseline());
3577 // Will be generated at use site.
3578}
3579
Mark Mendellfe57faa2015-09-18 09:26:15 -04003580// Simple implementation of packed switch - generate cascaded compare/jumps.
3581void LocationsBuilderMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) {
3582 LocationSummary* locations =
3583 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
3584 locations->SetInAt(0, Location::RequiresRegister());
3585}
3586
3587void InstructionCodeGeneratorMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) {
3588 int32_t lower_bound = switch_instr->GetStartValue();
3589 int32_t num_entries = switch_instr->GetNumEntries();
3590 LocationSummary* locations = switch_instr->GetLocations();
3591 GpuRegister value_reg = locations->InAt(0).AsRegister<GpuRegister>();
3592 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
3593
3594 // Create a series of compare/jumps.
3595 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
3596 for (int32_t i = 0; i < num_entries; i++) {
3597 int32_t case_value = lower_bound + i;
Vladimir Markoec7802a2015-10-01 20:57:57 +01003598 Label* succ = codegen_->GetLabelOf(successors[i]);
Mark Mendellfe57faa2015-09-18 09:26:15 -04003599 if (case_value == 0) {
3600 __ Beqzc(value_reg, succ);
3601 } else {
3602 __ LoadConst32(TMP, case_value);
3603 __ Beqc(value_reg, TMP, succ);
3604 }
3605 }
3606
3607 // And the default for any other value.
3608 if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) {
3609 __ B(codegen_->GetLabelOf(default_block));
3610 }
3611}
3612
Alexey Frunze4dda3372015-06-01 18:31:49 -07003613} // namespace mips64
3614} // namespace art