blob: 1a08503cf91ba8d4c3dc944a783613382e9ad375 [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
1781 LocationSummary* locations = instruction->GetLocations();
1782
1783 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1784 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1785 Location rhs_location = locations->InAt(1);
1786
1787 GpuRegister rhs_reg = ZERO;
1788 int64_t rhs_imm = 0;
1789 bool use_imm = rhs_location.IsConstant();
1790 if (use_imm) {
1791 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
1792 } else {
1793 rhs_reg = rhs_location.AsRegister<GpuRegister>();
1794 }
1795
1796 IfCondition if_cond = instruction->GetCondition();
1797
1798 switch (if_cond) {
1799 case kCondEQ:
1800 case kCondNE:
1801 if (use_imm && IsUint<16>(rhs_imm)) {
1802 __ Xori(dst, lhs, rhs_imm);
1803 } else {
1804 if (use_imm) {
1805 rhs_reg = TMP;
1806 __ LoadConst32(rhs_reg, rhs_imm);
1807 }
1808 __ Xor(dst, lhs, rhs_reg);
1809 }
1810 if (if_cond == kCondEQ) {
1811 __ Sltiu(dst, dst, 1);
1812 } else {
1813 __ Sltu(dst, ZERO, dst);
1814 }
1815 break;
1816
1817 case kCondLT:
1818 case kCondGE:
1819 if (use_imm && IsInt<16>(rhs_imm)) {
1820 __ Slti(dst, lhs, rhs_imm);
1821 } else {
1822 if (use_imm) {
1823 rhs_reg = TMP;
1824 __ LoadConst32(rhs_reg, rhs_imm);
1825 }
1826 __ Slt(dst, lhs, rhs_reg);
1827 }
1828 if (if_cond == kCondGE) {
1829 // Simulate lhs >= rhs via !(lhs < rhs) since there's
1830 // only the slt instruction but no sge.
1831 __ Xori(dst, dst, 1);
1832 }
1833 break;
1834
1835 case kCondLE:
1836 case kCondGT:
1837 if (use_imm && IsInt<16>(rhs_imm + 1)) {
1838 // Simulate lhs <= rhs via lhs < rhs + 1.
1839 __ Slti(dst, lhs, rhs_imm + 1);
1840 if (if_cond == kCondGT) {
1841 // Simulate lhs > rhs via !(lhs <= rhs) since there's
1842 // only the slti instruction but no sgti.
1843 __ Xori(dst, dst, 1);
1844 }
1845 } else {
1846 if (use_imm) {
1847 rhs_reg = TMP;
1848 __ LoadConst32(rhs_reg, rhs_imm);
1849 }
1850 __ Slt(dst, rhs_reg, lhs);
1851 if (if_cond == kCondLE) {
1852 // Simulate lhs <= rhs via !(rhs < lhs) since there's
1853 // only the slt instruction but no sle.
1854 __ Xori(dst, dst, 1);
1855 }
1856 }
1857 break;
1858 }
1859}
1860
1861void LocationsBuilderMIPS64::VisitDiv(HDiv* div) {
1862 LocationSummary* locations =
1863 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1864 switch (div->GetResultType()) {
1865 case Primitive::kPrimInt:
1866 case Primitive::kPrimLong:
1867 locations->SetInAt(0, Location::RequiresRegister());
1868 locations->SetInAt(1, Location::RequiresRegister());
1869 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1870 break;
1871
1872 case Primitive::kPrimFloat:
1873 case Primitive::kPrimDouble:
1874 locations->SetInAt(0, Location::RequiresFpuRegister());
1875 locations->SetInAt(1, Location::RequiresFpuRegister());
1876 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1877 break;
1878
1879 default:
1880 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1881 }
1882}
1883
1884void InstructionCodeGeneratorMIPS64::VisitDiv(HDiv* instruction) {
1885 Primitive::Type type = instruction->GetType();
1886 LocationSummary* locations = instruction->GetLocations();
1887
1888 switch (type) {
1889 case Primitive::kPrimInt:
1890 case Primitive::kPrimLong: {
1891 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
1892 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
1893 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
1894 if (type == Primitive::kPrimInt)
1895 __ DivR6(dst, lhs, rhs);
1896 else
1897 __ Ddiv(dst, lhs, rhs);
1898 break;
1899 }
1900 case Primitive::kPrimFloat:
1901 case Primitive::kPrimDouble: {
1902 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
1903 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
1904 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
1905 if (type == Primitive::kPrimFloat)
1906 __ DivS(dst, lhs, rhs);
1907 else
1908 __ DivD(dst, lhs, rhs);
1909 break;
1910 }
1911 default:
1912 LOG(FATAL) << "Unexpected div type " << type;
1913 }
1914}
1915
1916void LocationsBuilderMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00001917 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
1918 ? LocationSummary::kCallOnSlowPath
1919 : LocationSummary::kNoCall;
1920 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001921 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
1922 if (instruction->HasUses()) {
1923 locations->SetOut(Location::SameAsFirstInput());
1924 }
1925}
1926
1927void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1928 SlowPathCodeMIPS64* slow_path =
1929 new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS64(instruction);
1930 codegen_->AddSlowPath(slow_path);
1931 Location value = instruction->GetLocations()->InAt(0);
1932
1933 Primitive::Type type = instruction->GetType();
1934
Serguei Katkov8c0676c2015-08-03 13:55:33 +06001935 if ((type == Primitive::kPrimBoolean) || !Primitive::IsIntegralType(type)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001936 LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck.";
Serguei Katkov8c0676c2015-08-03 13:55:33 +06001937 return;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001938 }
1939
1940 if (value.IsConstant()) {
1941 int64_t divisor = codegen_->GetInt64ValueOf(value.GetConstant()->AsConstant());
1942 if (divisor == 0) {
1943 __ B(slow_path->GetEntryLabel());
1944 } else {
1945 // A division by a non-null constant is valid. We don't need to perform
1946 // any check, so simply fall through.
1947 }
1948 } else {
1949 __ Beqzc(value.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
1950 }
1951}
1952
1953void LocationsBuilderMIPS64::VisitDoubleConstant(HDoubleConstant* constant) {
1954 LocationSummary* locations =
1955 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1956 locations->SetOut(Location::ConstantLocation(constant));
1957}
1958
1959void InstructionCodeGeneratorMIPS64::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) {
1960 // Will be generated at use site.
1961}
1962
1963void LocationsBuilderMIPS64::VisitExit(HExit* exit) {
1964 exit->SetLocations(nullptr);
1965}
1966
1967void InstructionCodeGeneratorMIPS64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
1968}
1969
1970void LocationsBuilderMIPS64::VisitFloatConstant(HFloatConstant* constant) {
1971 LocationSummary* locations =
1972 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1973 locations->SetOut(Location::ConstantLocation(constant));
1974}
1975
1976void InstructionCodeGeneratorMIPS64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
1977 // Will be generated at use site.
1978}
1979
David Brazdilfc6a86a2015-06-26 10:33:45 +00001980void InstructionCodeGeneratorMIPS64::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001981 DCHECK(!successor->IsExitBlock());
1982 HBasicBlock* block = got->GetBlock();
1983 HInstruction* previous = got->GetPrevious();
1984 HLoopInformation* info = block->GetLoopInformation();
1985
1986 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
1987 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1988 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1989 return;
1990 }
1991 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1992 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1993 }
1994 if (!codegen_->GoesToNextBlock(block, successor)) {
1995 __ B(codegen_->GetLabelOf(successor));
1996 }
1997}
1998
David Brazdilfc6a86a2015-06-26 10:33:45 +00001999void LocationsBuilderMIPS64::VisitGoto(HGoto* got) {
2000 got->SetLocations(nullptr);
2001}
2002
2003void InstructionCodeGeneratorMIPS64::VisitGoto(HGoto* got) {
2004 HandleGoto(got, got->GetSuccessor());
2005}
2006
2007void LocationsBuilderMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) {
2008 try_boundary->SetLocations(nullptr);
2009}
2010
2011void InstructionCodeGeneratorMIPS64::VisitTryBoundary(HTryBoundary* try_boundary) {
2012 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
2013 if (!successor->IsExitBlock()) {
2014 HandleGoto(try_boundary, successor);
2015 }
2016}
2017
Alexey Frunze4dda3372015-06-01 18:31:49 -07002018void InstructionCodeGeneratorMIPS64::GenerateTestAndBranch(HInstruction* instruction,
2019 Label* true_target,
2020 Label* false_target,
2021 Label* always_true_target) {
2022 HInstruction* cond = instruction->InputAt(0);
2023 HCondition* condition = cond->AsCondition();
2024
2025 if (cond->IsIntConstant()) {
2026 int32_t cond_value = cond->AsIntConstant()->GetValue();
2027 if (cond_value == 1) {
2028 if (always_true_target != nullptr) {
2029 __ B(always_true_target);
2030 }
2031 return;
2032 } else {
2033 DCHECK_EQ(cond_value, 0);
2034 }
2035 } else if (!cond->IsCondition() || condition->NeedsMaterialization()) {
2036 // The condition instruction has been materialized, compare the output to 0.
2037 Location cond_val = instruction->GetLocations()->InAt(0);
2038 DCHECK(cond_val.IsRegister());
2039 __ Bnezc(cond_val.AsRegister<GpuRegister>(), true_target);
2040 } else {
2041 // The condition instruction has not been materialized, use its inputs as
2042 // the comparison and its condition as the branch condition.
2043 GpuRegister lhs = condition->GetLocations()->InAt(0).AsRegister<GpuRegister>();
2044 Location rhs_location = condition->GetLocations()->InAt(1);
2045 GpuRegister rhs_reg = ZERO;
2046 int32_t rhs_imm = 0;
2047 bool use_imm = rhs_location.IsConstant();
2048 if (use_imm) {
2049 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2050 } else {
2051 rhs_reg = rhs_location.AsRegister<GpuRegister>();
2052 }
2053
2054 IfCondition if_cond = condition->GetCondition();
2055 if (use_imm && rhs_imm == 0) {
2056 switch (if_cond) {
2057 case kCondEQ:
2058 __ Beqzc(lhs, true_target);
2059 break;
2060 case kCondNE:
2061 __ Bnezc(lhs, true_target);
2062 break;
2063 case kCondLT:
2064 __ Bltzc(lhs, true_target);
2065 break;
2066 case kCondGE:
2067 __ Bgezc(lhs, true_target);
2068 break;
2069 case kCondLE:
2070 __ Blezc(lhs, true_target);
2071 break;
2072 case kCondGT:
2073 __ Bgtzc(lhs, true_target);
2074 break;
2075 }
2076 } else {
2077 if (use_imm) {
2078 rhs_reg = TMP;
2079 __ LoadConst32(rhs_reg, rhs_imm);
2080 }
2081 // It looks like we can get here with lhs == rhs. Should that be possible at all?
2082 // Mips R6 requires lhs != rhs for compact branches.
2083 if (lhs == rhs_reg) {
2084 DCHECK(!use_imm);
2085 switch (if_cond) {
2086 case kCondEQ:
2087 case kCondGE:
2088 case kCondLE:
2089 // if lhs == rhs for a positive condition, then it is a branch
2090 __ B(true_target);
2091 break;
2092 case kCondNE:
2093 case kCondLT:
2094 case kCondGT:
2095 // if lhs == rhs for a negative condition, then it is a NOP
2096 break;
2097 }
2098 } else {
2099 switch (if_cond) {
2100 case kCondEQ:
2101 __ Beqc(lhs, rhs_reg, true_target);
2102 break;
2103 case kCondNE:
2104 __ Bnec(lhs, rhs_reg, true_target);
2105 break;
2106 case kCondLT:
2107 __ Bltc(lhs, rhs_reg, true_target);
2108 break;
2109 case kCondGE:
2110 __ Bgec(lhs, rhs_reg, true_target);
2111 break;
2112 case kCondLE:
2113 __ Bgec(rhs_reg, lhs, true_target);
2114 break;
2115 case kCondGT:
2116 __ Bltc(rhs_reg, lhs, true_target);
2117 break;
2118 }
2119 }
2120 }
2121 }
2122 if (false_target != nullptr) {
2123 __ B(false_target);
2124 }
2125}
2126
2127void LocationsBuilderMIPS64::VisitIf(HIf* if_instr) {
2128 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
2129 HInstruction* cond = if_instr->InputAt(0);
2130 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
2131 locations->SetInAt(0, Location::RequiresRegister());
2132 }
2133}
2134
2135void InstructionCodeGeneratorMIPS64::VisitIf(HIf* if_instr) {
2136 Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
2137 Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
2138 Label* always_true_target = true_target;
2139 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
2140 if_instr->IfTrueSuccessor())) {
2141 always_true_target = nullptr;
2142 }
2143 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
2144 if_instr->IfFalseSuccessor())) {
2145 false_target = nullptr;
2146 }
2147 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
2148}
2149
2150void LocationsBuilderMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) {
2151 LocationSummary* locations = new (GetGraph()->GetArena())
2152 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
2153 HInstruction* cond = deoptimize->InputAt(0);
2154 DCHECK(cond->IsCondition());
2155 if (cond->AsCondition()->NeedsMaterialization()) {
2156 locations->SetInAt(0, Location::RequiresRegister());
2157 }
2158}
2159
2160void InstructionCodeGeneratorMIPS64::VisitDeoptimize(HDeoptimize* deoptimize) {
2161 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena())
2162 DeoptimizationSlowPathMIPS64(deoptimize);
2163 codegen_->AddSlowPath(slow_path);
2164 Label* slow_path_entry = slow_path->GetEntryLabel();
2165 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
2166}
2167
2168void LocationsBuilderMIPS64::HandleFieldGet(HInstruction* instruction,
2169 const FieldInfo& field_info ATTRIBUTE_UNUSED) {
2170 LocationSummary* locations =
2171 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2172 locations->SetInAt(0, Location::RequiresRegister());
2173 if (Primitive::IsFloatingPointType(instruction->GetType())) {
2174 locations->SetOut(Location::RequiresFpuRegister());
2175 } else {
2176 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2177 }
2178}
2179
2180void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction,
2181 const FieldInfo& field_info) {
2182 Primitive::Type type = field_info.GetFieldType();
2183 LocationSummary* locations = instruction->GetLocations();
2184 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2185 LoadOperandType load_type = kLoadUnsignedByte;
2186 switch (type) {
2187 case Primitive::kPrimBoolean:
2188 load_type = kLoadUnsignedByte;
2189 break;
2190 case Primitive::kPrimByte:
2191 load_type = kLoadSignedByte;
2192 break;
2193 case Primitive::kPrimShort:
2194 load_type = kLoadSignedHalfword;
2195 break;
2196 case Primitive::kPrimChar:
2197 load_type = kLoadUnsignedHalfword;
2198 break;
2199 case Primitive::kPrimInt:
2200 case Primitive::kPrimFloat:
2201 load_type = kLoadWord;
2202 break;
2203 case Primitive::kPrimLong:
2204 case Primitive::kPrimDouble:
2205 load_type = kLoadDoubleword;
2206 break;
2207 case Primitive::kPrimNot:
2208 load_type = kLoadUnsignedWord;
2209 break;
2210 case Primitive::kPrimVoid:
2211 LOG(FATAL) << "Unreachable type " << type;
2212 UNREACHABLE();
2213 }
2214 if (!Primitive::IsFloatingPointType(type)) {
2215 DCHECK(locations->Out().IsRegister());
2216 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2217 __ LoadFromOffset(load_type, dst, obj, field_info.GetFieldOffset().Uint32Value());
2218 } else {
2219 DCHECK(locations->Out().IsFpuRegister());
2220 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
2221 __ LoadFpuFromOffset(load_type, dst, obj, field_info.GetFieldOffset().Uint32Value());
2222 }
2223
2224 codegen_->MaybeRecordImplicitNullCheck(instruction);
2225 // TODO: memory barrier?
2226}
2227
2228void LocationsBuilderMIPS64::HandleFieldSet(HInstruction* instruction,
2229 const FieldInfo& field_info ATTRIBUTE_UNUSED) {
2230 LocationSummary* locations =
2231 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2232 locations->SetInAt(0, Location::RequiresRegister());
2233 if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) {
2234 locations->SetInAt(1, Location::RequiresFpuRegister());
2235 } else {
2236 locations->SetInAt(1, Location::RequiresRegister());
2237 }
2238}
2239
2240void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction,
2241 const FieldInfo& field_info) {
2242 Primitive::Type type = field_info.GetFieldType();
2243 LocationSummary* locations = instruction->GetLocations();
2244 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2245 StoreOperandType store_type = kStoreByte;
2246 switch (type) {
2247 case Primitive::kPrimBoolean:
2248 case Primitive::kPrimByte:
2249 store_type = kStoreByte;
2250 break;
2251 case Primitive::kPrimShort:
2252 case Primitive::kPrimChar:
2253 store_type = kStoreHalfword;
2254 break;
2255 case Primitive::kPrimInt:
2256 case Primitive::kPrimFloat:
2257 case Primitive::kPrimNot:
2258 store_type = kStoreWord;
2259 break;
2260 case Primitive::kPrimLong:
2261 case Primitive::kPrimDouble:
2262 store_type = kStoreDoubleword;
2263 break;
2264 case Primitive::kPrimVoid:
2265 LOG(FATAL) << "Unreachable type " << type;
2266 UNREACHABLE();
2267 }
2268 if (!Primitive::IsFloatingPointType(type)) {
2269 DCHECK(locations->InAt(1).IsRegister());
2270 GpuRegister src = locations->InAt(1).AsRegister<GpuRegister>();
2271 __ StoreToOffset(store_type, src, obj, field_info.GetFieldOffset().Uint32Value());
2272 } else {
2273 DCHECK(locations->InAt(1).IsFpuRegister());
2274 FpuRegister src = locations->InAt(1).AsFpuRegister<FpuRegister>();
2275 __ StoreFpuToOffset(store_type, src, obj, field_info.GetFieldOffset().Uint32Value());
2276 }
2277
2278 codegen_->MaybeRecordImplicitNullCheck(instruction);
2279 // TODO: memory barriers?
2280 if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) {
2281 DCHECK(locations->InAt(1).IsRegister());
2282 GpuRegister src = locations->InAt(1).AsRegister<GpuRegister>();
2283 codegen_->MarkGCCard(obj, src);
2284 }
2285}
2286
2287void LocationsBuilderMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2288 HandleFieldGet(instruction, instruction->GetFieldInfo());
2289}
2290
2291void InstructionCodeGeneratorMIPS64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2292 HandleFieldGet(instruction, instruction->GetFieldInfo());
2293}
2294
2295void LocationsBuilderMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2296 HandleFieldSet(instruction, instruction->GetFieldInfo());
2297}
2298
2299void InstructionCodeGeneratorMIPS64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2300 HandleFieldSet(instruction, instruction->GetFieldInfo());
2301}
2302
2303void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) {
2304 LocationSummary::CallKind call_kind =
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00002305 instruction->IsExactCheck() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002306 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
2307 locations->SetInAt(0, Location::RequiresRegister());
2308 locations->SetInAt(1, Location::RequiresRegister());
2309 // The output does overlap inputs.
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01002310 // Note that TypeCheckSlowPathMIPS64 uses this register too.
Alexey Frunze4dda3372015-06-01 18:31:49 -07002311 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
2312}
2313
2314void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) {
2315 LocationSummary* locations = instruction->GetLocations();
2316 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
2317 GpuRegister cls = locations->InAt(1).AsRegister<GpuRegister>();
2318 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2319
2320 Label done;
2321
2322 // Return 0 if `obj` is null.
2323 // TODO: Avoid this check if we know `obj` is not null.
2324 __ Move(out, ZERO);
2325 __ Beqzc(obj, &done);
2326
2327 // Compare the class of `obj` with `cls`.
2328 __ LoadFromOffset(kLoadUnsignedWord, out, obj, mirror::Object::ClassOffset().Int32Value());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00002329 if (instruction->IsExactCheck()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002330 // Classes must be equal for the instanceof to succeed.
2331 __ Xor(out, out, cls);
2332 __ Sltiu(out, out, 1);
2333 } else {
2334 // If the classes are not equal, we go into a slow path.
2335 DCHECK(locations->OnlyCallsOnSlowPath());
2336 SlowPathCodeMIPS64* slow_path =
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01002337 new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS64(instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002338 codegen_->AddSlowPath(slow_path);
2339 __ Bnec(out, cls, slow_path->GetEntryLabel());
2340 __ LoadConst32(out, 1);
2341 __ Bind(slow_path->GetExitLabel());
2342 }
2343
2344 __ Bind(&done);
2345}
2346
2347void LocationsBuilderMIPS64::VisitIntConstant(HIntConstant* constant) {
2348 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2349 locations->SetOut(Location::ConstantLocation(constant));
2350}
2351
2352void InstructionCodeGeneratorMIPS64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
2353 // Will be generated at use site.
2354}
2355
2356void LocationsBuilderMIPS64::VisitNullConstant(HNullConstant* constant) {
2357 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2358 locations->SetOut(Location::ConstantLocation(constant));
2359}
2360
2361void InstructionCodeGeneratorMIPS64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
2362 // Will be generated at use site.
2363}
2364
Calin Juravle175dc732015-08-25 15:42:32 +01002365void LocationsBuilderMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
2366 // The trampoline uses the same calling convention as dex calling conventions,
2367 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
2368 // the method_idx.
2369 HandleInvoke(invoke);
2370}
2371
2372void InstructionCodeGeneratorMIPS64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
2373 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
2374}
2375
Alexey Frunze4dda3372015-06-01 18:31:49 -07002376void LocationsBuilderMIPS64::HandleInvoke(HInvoke* invoke) {
2377 InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor;
2378 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
2379}
2380
2381void LocationsBuilderMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) {
2382 HandleInvoke(invoke);
2383 // The register T0 is required to be used for the hidden argument in
2384 // art_quick_imt_conflict_trampoline, so add the hidden argument.
2385 invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0));
2386}
2387
2388void InstructionCodeGeneratorMIPS64::VisitInvokeInterface(HInvokeInterface* invoke) {
2389 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
2390 GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>();
2391 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
2392 invoke->GetImtIndex() % mirror::Class::kImtSize, kMips64PointerSize).Uint32Value();
2393 Location receiver = invoke->GetLocations()->InAt(0);
2394 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2395 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64WordSize);
2396
2397 // Set the hidden argument.
2398 __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<GpuRegister>(),
2399 invoke->GetDexMethodIndex());
2400
2401 // temp = object->GetClass();
2402 if (receiver.IsStackSlot()) {
2403 __ LoadFromOffset(kLoadUnsignedWord, temp, SP, receiver.GetStackIndex());
2404 __ LoadFromOffset(kLoadUnsignedWord, temp, temp, class_offset);
2405 } else {
2406 __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset);
2407 }
2408 codegen_->MaybeRecordImplicitNullCheck(invoke);
2409 // temp = temp->GetImtEntryAt(method_offset);
2410 __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset);
2411 // T9 = temp->GetEntryPoint();
2412 __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value());
2413 // T9();
2414 __ Jalr(T9);
2415 DCHECK(!codegen_->IsLeafMethod());
2416 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2417}
2418
2419void LocationsBuilderMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Chris Larsen3039e382015-08-26 07:54:08 -07002420 IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_);
2421 if (intrinsic.TryDispatch(invoke)) {
2422 return;
2423 }
2424
Alexey Frunze4dda3372015-06-01 18:31:49 -07002425 HandleInvoke(invoke);
2426}
2427
2428void LocationsBuilderMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
2429 // When we do not run baseline, explicit clinit checks triggered by static
2430 // invokes must have been pruned by art::PrepareForRegisterAllocation.
2431 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
2432
Chris Larsen3039e382015-08-26 07:54:08 -07002433 IntrinsicLocationsBuilderMIPS64 intrinsic(codegen_);
2434 if (intrinsic.TryDispatch(invoke)) {
2435 return;
2436 }
2437
Alexey Frunze4dda3372015-06-01 18:31:49 -07002438 HandleInvoke(invoke);
2439
2440 // While SetupBlockedRegisters() blocks registers S2-S8 due to their
2441 // clobbering somewhere else, reduce further register pressure by avoiding
2442 // allocation of a register for the current method pointer like on x86 baseline.
2443 // TODO: remove this once all the issues with register saving/restoring are
2444 // sorted out.
2445 LocationSummary* locations = invoke->GetLocations();
2446 Location location = locations->InAt(invoke->GetCurrentMethodInputIndex());
2447 if (location.IsUnallocated() && location.GetPolicy() == Location::kRequiresRegister) {
2448 locations->SetInAt(invoke->GetCurrentMethodInputIndex(), Location::NoLocation());
2449 }
2450}
2451
Chris Larsen3039e382015-08-26 07:54:08 -07002452static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS64* codegen) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002453 if (invoke->GetLocations()->Intrinsified()) {
Chris Larsen3039e382015-08-26 07:54:08 -07002454 IntrinsicCodeGeneratorMIPS64 intrinsic(codegen);
2455 intrinsic.Dispatch(invoke);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002456 return true;
2457 }
2458 return false;
2459}
2460
2461void CodeGeneratorMIPS64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
2462 // All registers are assumed to be correctly set up per the calling convention.
2463
Vladimir Marko58155012015-08-19 12:49:41 +00002464 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
2465 switch (invoke->GetMethodLoadKind()) {
2466 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
2467 // temp = thread->string_init_entrypoint
2468 __ LoadFromOffset(kLoadDoubleword,
2469 temp.AsRegister<GpuRegister>(),
2470 TR,
2471 invoke->GetStringInitOffset());
2472 break;
2473 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
2474 callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
2475 break;
2476 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
2477 __ LoadConst64(temp.AsRegister<GpuRegister>(), invoke->GetMethodAddress());
2478 break;
2479 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
2480 // TODO: Implement this type. (Needs literal support.) At the moment, the
2481 // CompilerDriver will not direct the backend to use this type for MIPS.
2482 LOG(FATAL) << "Unsupported!";
2483 UNREACHABLE();
2484 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative:
2485 // TODO: Implement this type. For the moment, we fall back to kDexCacheViaMethod.
2486 FALLTHROUGH_INTENDED;
2487 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
2488 Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
2489 GpuRegister reg = temp.AsRegister<GpuRegister>();
2490 GpuRegister method_reg;
2491 if (current_method.IsRegister()) {
2492 method_reg = current_method.AsRegister<GpuRegister>();
2493 } else {
2494 // TODO: use the appropriate DCHECK() here if possible.
2495 // DCHECK(invoke->GetLocations()->Intrinsified());
2496 DCHECK(!current_method.IsValid());
2497 method_reg = reg;
2498 __ Ld(reg, SP, kCurrentMethodStackOffset);
2499 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002500
Vladimir Marko58155012015-08-19 12:49:41 +00002501 // temp = temp->dex_cache_resolved_methods_;
Vladimir Marko05792b92015-08-03 11:56:49 +01002502 __ LoadFromOffset(kLoadDoubleword,
Vladimir Marko58155012015-08-19 12:49:41 +00002503 reg,
2504 method_reg,
Vladimir Marko05792b92015-08-03 11:56:49 +01002505 ArtMethod::DexCacheResolvedMethodsOffset(kMips64PointerSize).Int32Value());
Vladimir Marko58155012015-08-19 12:49:41 +00002506 // temp = temp[index_in_cache]
2507 uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index;
2508 __ LoadFromOffset(kLoadDoubleword,
2509 reg,
2510 reg,
2511 CodeGenerator::GetCachePointerOffset(index_in_cache));
2512 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -07002513 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002514 }
2515
Vladimir Marko58155012015-08-19 12:49:41 +00002516 switch (invoke->GetCodePtrLocation()) {
2517 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
2518 __ Jalr(&frame_entry_label_, T9);
2519 break;
2520 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
2521 // LR = invoke->GetDirectCodePtr();
2522 __ LoadConst64(T9, invoke->GetDirectCodePtr());
2523 // LR()
2524 __ Jalr(T9);
2525 break;
2526 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
2527 // TODO: Implement kCallPCRelative. For the moment, we fall back to kMethodCode.
2528 FALLTHROUGH_INTENDED;
2529 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
2530 // TODO: Implement kDirectCodeFixup. For the moment, we fall back to kMethodCode.
2531 FALLTHROUGH_INTENDED;
2532 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
2533 // T9 = callee_method->entry_point_from_quick_compiled_code_;
2534 __ LoadFromOffset(kLoadDoubleword,
2535 T9,
2536 callee_method.AsRegister<GpuRegister>(),
2537 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
2538 kMips64WordSize).Int32Value());
2539 // T9()
2540 __ Jalr(T9);
2541 break;
2542 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002543 DCHECK(!IsLeafMethod());
2544}
2545
2546void InstructionCodeGeneratorMIPS64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
2547 // When we do not run baseline, explicit clinit checks triggered by static
2548 // invokes must have been pruned by art::PrepareForRegisterAllocation.
2549 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
2550
2551 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2552 return;
2553 }
2554
2555 LocationSummary* locations = invoke->GetLocations();
2556 codegen_->GenerateStaticOrDirectCall(invoke,
2557 locations->HasTemps()
2558 ? locations->GetTemp(0)
2559 : Location::NoLocation());
2560 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2561}
2562
2563void InstructionCodeGeneratorMIPS64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Chris Larsen3039e382015-08-26 07:54:08 -07002564 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2565 return;
2566 }
2567
Alexey Frunze4dda3372015-06-01 18:31:49 -07002568 LocationSummary* locations = invoke->GetLocations();
2569 Location receiver = locations->InAt(0);
2570 GpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<GpuRegister>();
2571 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
2572 invoke->GetVTableIndex(), kMips64PointerSize).SizeValue();
2573 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2574 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64WordSize);
2575
2576 // temp = object->GetClass();
2577 DCHECK(receiver.IsRegister());
2578 __ LoadFromOffset(kLoadUnsignedWord, temp, receiver.AsRegister<GpuRegister>(), class_offset);
2579 codegen_->MaybeRecordImplicitNullCheck(invoke);
2580 // temp = temp->GetMethodAt(method_offset);
2581 __ LoadFromOffset(kLoadDoubleword, temp, temp, method_offset);
2582 // T9 = temp->GetEntryPoint();
2583 __ LoadFromOffset(kLoadDoubleword, T9, temp, entry_point.Int32Value());
2584 // T9();
2585 __ Jalr(T9);
2586 DCHECK(!codegen_->IsLeafMethod());
2587 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2588}
2589
2590void LocationsBuilderMIPS64::VisitLoadClass(HLoadClass* cls) {
Calin Juravle98893e12015-10-02 21:05:03 +01002591 InvokeRuntimeCallingConvention calling_convention;
2592 CodeGenerator::CreateLoadClassLocationSummary(
2593 cls,
2594 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
2595 Location::RegisterLocation(A0));
Alexey Frunze4dda3372015-06-01 18:31:49 -07002596}
2597
2598void InstructionCodeGeneratorMIPS64::VisitLoadClass(HLoadClass* cls) {
2599 LocationSummary* locations = cls->GetLocations();
Calin Juravle98893e12015-10-02 21:05:03 +01002600 if (cls->NeedsAccessCheck()) {
2601 codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex());
2602 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess),
2603 cls,
2604 cls->GetDexPc(),
2605 nullptr);
Calin Juravle580b6092015-10-06 17:35:58 +01002606 return;
2607 }
2608
2609 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2610 GpuRegister current_method = locations->InAt(0).AsRegister<GpuRegister>();
2611 if (cls->IsReferrersClass()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002612 DCHECK(!cls->CanCallRuntime());
2613 DCHECK(!cls->MustGenerateClinitCheck());
2614 __ LoadFromOffset(kLoadUnsignedWord, out, current_method,
2615 ArtMethod::DeclaringClassOffset().Int32Value());
2616 } else {
2617 DCHECK(cls->CanCallRuntime());
Vladimir Marko05792b92015-08-03 11:56:49 +01002618 __ LoadFromOffset(kLoadDoubleword, out, current_method,
2619 ArtMethod::DexCacheResolvedTypesOffset(kMips64PointerSize).Int32Value());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002620 __ LoadFromOffset(kLoadUnsignedWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Vladimir Marko05792b92015-08-03 11:56:49 +01002621 // TODO: We will need a read barrier here.
Alexey Frunze4dda3372015-06-01 18:31:49 -07002622 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS64(
2623 cls,
2624 cls,
2625 cls->GetDexPc(),
2626 cls->MustGenerateClinitCheck());
2627 codegen_->AddSlowPath(slow_path);
2628 __ Beqzc(out, slow_path->GetEntryLabel());
2629 if (cls->MustGenerateClinitCheck()) {
2630 GenerateClassInitializationCheck(slow_path, out);
2631 } else {
2632 __ Bind(slow_path->GetExitLabel());
2633 }
2634 }
2635}
2636
David Brazdilcb1c0552015-08-04 16:22:25 +01002637static int32_t GetExceptionTlsOffset() {
2638 return Thread::ExceptionOffset<kMips64WordSize>().Int32Value();
2639}
2640
Alexey Frunze4dda3372015-06-01 18:31:49 -07002641void LocationsBuilderMIPS64::VisitLoadException(HLoadException* load) {
2642 LocationSummary* locations =
2643 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2644 locations->SetOut(Location::RequiresRegister());
2645}
2646
2647void InstructionCodeGeneratorMIPS64::VisitLoadException(HLoadException* load) {
2648 GpuRegister out = load->GetLocations()->Out().AsRegister<GpuRegister>();
David Brazdilcb1c0552015-08-04 16:22:25 +01002649 __ LoadFromOffset(kLoadUnsignedWord, out, TR, GetExceptionTlsOffset());
2650}
2651
2652void LocationsBuilderMIPS64::VisitClearException(HClearException* clear) {
2653 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
2654}
2655
2656void InstructionCodeGeneratorMIPS64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
2657 __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002658}
2659
2660void LocationsBuilderMIPS64::VisitLoadLocal(HLoadLocal* load) {
2661 load->SetLocations(nullptr);
2662}
2663
2664void InstructionCodeGeneratorMIPS64::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) {
2665 // Nothing to do, this is driven by the code generator.
2666}
2667
2668void LocationsBuilderMIPS64::VisitLoadString(HLoadString* load) {
2669 LocationSummary* locations =
2670 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2671 locations->SetInAt(0, Location::RequiresRegister());
2672 locations->SetOut(Location::RequiresRegister());
2673}
2674
2675void InstructionCodeGeneratorMIPS64::VisitLoadString(HLoadString* load) {
2676 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS64(load);
2677 codegen_->AddSlowPath(slow_path);
2678
2679 LocationSummary* locations = load->GetLocations();
2680 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
2681 GpuRegister current_method = locations->InAt(0).AsRegister<GpuRegister>();
2682 __ LoadFromOffset(kLoadUnsignedWord, out, current_method,
2683 ArtMethod::DeclaringClassOffset().Int32Value());
Vladimir Marko05792b92015-08-03 11:56:49 +01002684 __ LoadFromOffset(kLoadDoubleword, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Alexey Frunze4dda3372015-06-01 18:31:49 -07002685 __ LoadFromOffset(kLoadUnsignedWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
Vladimir Marko05792b92015-08-03 11:56:49 +01002686 // TODO: We will need a read barrier here.
Alexey Frunze4dda3372015-06-01 18:31:49 -07002687 __ Beqzc(out, slow_path->GetEntryLabel());
2688 __ Bind(slow_path->GetExitLabel());
2689}
2690
2691void LocationsBuilderMIPS64::VisitLocal(HLocal* local) {
2692 local->SetLocations(nullptr);
2693}
2694
2695void InstructionCodeGeneratorMIPS64::VisitLocal(HLocal* local) {
2696 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
2697}
2698
2699void LocationsBuilderMIPS64::VisitLongConstant(HLongConstant* constant) {
2700 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2701 locations->SetOut(Location::ConstantLocation(constant));
2702}
2703
2704void InstructionCodeGeneratorMIPS64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
2705 // Will be generated at use site.
2706}
2707
2708void LocationsBuilderMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) {
2709 LocationSummary* locations =
2710 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2711 InvokeRuntimeCallingConvention calling_convention;
2712 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2713}
2714
2715void InstructionCodeGeneratorMIPS64::VisitMonitorOperation(HMonitorOperation* instruction) {
2716 codegen_->InvokeRuntime(instruction->IsEnter()
2717 ? QUICK_ENTRY_POINT(pLockObject)
2718 : QUICK_ENTRY_POINT(pUnlockObject),
2719 instruction,
2720 instruction->GetDexPc(),
2721 nullptr);
2722 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
2723}
2724
2725void LocationsBuilderMIPS64::VisitMul(HMul* mul) {
2726 LocationSummary* locations =
2727 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2728 switch (mul->GetResultType()) {
2729 case Primitive::kPrimInt:
2730 case Primitive::kPrimLong:
2731 locations->SetInAt(0, Location::RequiresRegister());
2732 locations->SetInAt(1, Location::RequiresRegister());
2733 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2734 break;
2735
2736 case Primitive::kPrimFloat:
2737 case Primitive::kPrimDouble:
2738 locations->SetInAt(0, Location::RequiresFpuRegister());
2739 locations->SetInAt(1, Location::RequiresFpuRegister());
2740 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2741 break;
2742
2743 default:
2744 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2745 }
2746}
2747
2748void InstructionCodeGeneratorMIPS64::VisitMul(HMul* instruction) {
2749 Primitive::Type type = instruction->GetType();
2750 LocationSummary* locations = instruction->GetLocations();
2751
2752 switch (type) {
2753 case Primitive::kPrimInt:
2754 case Primitive::kPrimLong: {
2755 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2756 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
2757 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
2758 if (type == Primitive::kPrimInt)
2759 __ MulR6(dst, lhs, rhs);
2760 else
2761 __ Dmul(dst, lhs, rhs);
2762 break;
2763 }
2764 case Primitive::kPrimFloat:
2765 case Primitive::kPrimDouble: {
2766 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
2767 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
2768 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
2769 if (type == Primitive::kPrimFloat)
2770 __ MulS(dst, lhs, rhs);
2771 else
2772 __ MulD(dst, lhs, rhs);
2773 break;
2774 }
2775 default:
2776 LOG(FATAL) << "Unexpected mul type " << type;
2777 }
2778}
2779
2780void LocationsBuilderMIPS64::VisitNeg(HNeg* neg) {
2781 LocationSummary* locations =
2782 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
2783 switch (neg->GetResultType()) {
2784 case Primitive::kPrimInt:
2785 case Primitive::kPrimLong:
2786 locations->SetInAt(0, Location::RequiresRegister());
2787 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2788 break;
2789
2790 case Primitive::kPrimFloat:
2791 case Primitive::kPrimDouble:
2792 locations->SetInAt(0, Location::RequiresFpuRegister());
2793 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2794 break;
2795
2796 default:
2797 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2798 }
2799}
2800
2801void InstructionCodeGeneratorMIPS64::VisitNeg(HNeg* instruction) {
2802 Primitive::Type type = instruction->GetType();
2803 LocationSummary* locations = instruction->GetLocations();
2804
2805 switch (type) {
2806 case Primitive::kPrimInt:
2807 case Primitive::kPrimLong: {
2808 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2809 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
2810 if (type == Primitive::kPrimInt)
2811 __ Subu(dst, ZERO, src);
2812 else
2813 __ Dsubu(dst, ZERO, src);
2814 break;
2815 }
2816 case Primitive::kPrimFloat:
2817 case Primitive::kPrimDouble: {
2818 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
2819 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
2820 if (type == Primitive::kPrimFloat)
2821 __ NegS(dst, src);
2822 else
2823 __ NegD(dst, src);
2824 break;
2825 }
2826 default:
2827 LOG(FATAL) << "Unexpected neg type " << type;
2828 }
2829}
2830
2831void LocationsBuilderMIPS64::VisitNewArray(HNewArray* instruction) {
2832 LocationSummary* locations =
2833 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2834 InvokeRuntimeCallingConvention calling_convention;
2835 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2836 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
2837 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2838 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2839}
2840
2841void InstructionCodeGeneratorMIPS64::VisitNewArray(HNewArray* instruction) {
2842 LocationSummary* locations = instruction->GetLocations();
2843 // Move an uint16_t value to a register.
2844 __ LoadConst32(locations->GetTemp(0).AsRegister<GpuRegister>(), instruction->GetTypeIndex());
Calin Juravle175dc732015-08-25 15:42:32 +01002845 codegen_->InvokeRuntime(instruction->GetEntrypoint(),
2846 instruction,
2847 instruction->GetDexPc(),
2848 nullptr);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002849 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>();
2850}
2851
2852void LocationsBuilderMIPS64::VisitNewInstance(HNewInstance* instruction) {
2853 LocationSummary* locations =
2854 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2855 InvokeRuntimeCallingConvention calling_convention;
2856 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2857 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2858 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
2859}
2860
2861void InstructionCodeGeneratorMIPS64::VisitNewInstance(HNewInstance* instruction) {
2862 LocationSummary* locations = instruction->GetLocations();
2863 // Move an uint16_t value to a register.
2864 __ LoadConst32(locations->GetTemp(0).AsRegister<GpuRegister>(), instruction->GetTypeIndex());
Calin Juravle175dc732015-08-25 15:42:32 +01002865 codegen_->InvokeRuntime(instruction->GetEntrypoint(),
2866 instruction,
2867 instruction->GetDexPc(),
2868 nullptr);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002869 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
2870}
2871
2872void LocationsBuilderMIPS64::VisitNot(HNot* instruction) {
2873 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2874 locations->SetInAt(0, Location::RequiresRegister());
2875 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2876}
2877
2878void InstructionCodeGeneratorMIPS64::VisitNot(HNot* instruction) {
2879 Primitive::Type type = instruction->GetType();
2880 LocationSummary* locations = instruction->GetLocations();
2881
2882 switch (type) {
2883 case Primitive::kPrimInt:
2884 case Primitive::kPrimLong: {
2885 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
2886 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
2887 __ Nor(dst, src, ZERO);
2888 break;
2889 }
2890
2891 default:
2892 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
2893 }
2894}
2895
2896void LocationsBuilderMIPS64::VisitBooleanNot(HBooleanNot* instruction) {
2897 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2898 locations->SetInAt(0, Location::RequiresRegister());
2899 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2900}
2901
2902void InstructionCodeGeneratorMIPS64::VisitBooleanNot(HBooleanNot* instruction) {
2903 LocationSummary* locations = instruction->GetLocations();
2904 __ Xori(locations->Out().AsRegister<GpuRegister>(),
2905 locations->InAt(0).AsRegister<GpuRegister>(),
2906 1);
2907}
2908
2909void LocationsBuilderMIPS64::VisitNullCheck(HNullCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00002910 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
2911 ? LocationSummary::kCallOnSlowPath
2912 : LocationSummary::kNoCall;
2913 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002914 locations->SetInAt(0, Location::RequiresRegister());
2915 if (instruction->HasUses()) {
2916 locations->SetOut(Location::SameAsFirstInput());
2917 }
2918}
2919
2920void InstructionCodeGeneratorMIPS64::GenerateImplicitNullCheck(HNullCheck* instruction) {
2921 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2922 return;
2923 }
2924 Location obj = instruction->GetLocations()->InAt(0);
2925
2926 __ Lw(ZERO, obj.AsRegister<GpuRegister>(), 0);
2927 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2928}
2929
2930void InstructionCodeGeneratorMIPS64::GenerateExplicitNullCheck(HNullCheck* instruction) {
2931 SlowPathCodeMIPS64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS64(instruction);
2932 codegen_->AddSlowPath(slow_path);
2933
2934 Location obj = instruction->GetLocations()->InAt(0);
2935
2936 __ Beqzc(obj.AsRegister<GpuRegister>(), slow_path->GetEntryLabel());
2937}
2938
2939void InstructionCodeGeneratorMIPS64::VisitNullCheck(HNullCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00002940 if (codegen_->IsImplicitNullCheckAllowed(instruction)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002941 GenerateImplicitNullCheck(instruction);
2942 } else {
2943 GenerateExplicitNullCheck(instruction);
2944 }
2945}
2946
2947void LocationsBuilderMIPS64::VisitOr(HOr* instruction) {
2948 HandleBinaryOp(instruction);
2949}
2950
2951void InstructionCodeGeneratorMIPS64::VisitOr(HOr* instruction) {
2952 HandleBinaryOp(instruction);
2953}
2954
2955void LocationsBuilderMIPS64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
2956 LOG(FATAL) << "Unreachable";
2957}
2958
2959void InstructionCodeGeneratorMIPS64::VisitParallelMove(HParallelMove* instruction) {
2960 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2961}
2962
2963void LocationsBuilderMIPS64::VisitParameterValue(HParameterValue* instruction) {
2964 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2965 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2966 if (location.IsStackSlot()) {
2967 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2968 } else if (location.IsDoubleStackSlot()) {
2969 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2970 }
2971 locations->SetOut(location);
2972}
2973
2974void InstructionCodeGeneratorMIPS64::VisitParameterValue(HParameterValue* instruction
2975 ATTRIBUTE_UNUSED) {
2976 // Nothing to do, the parameter is already at its location.
2977}
2978
2979void LocationsBuilderMIPS64::VisitCurrentMethod(HCurrentMethod* instruction) {
2980 LocationSummary* locations =
2981 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2982 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
2983}
2984
2985void InstructionCodeGeneratorMIPS64::VisitCurrentMethod(HCurrentMethod* instruction
2986 ATTRIBUTE_UNUSED) {
2987 // Nothing to do, the method is already at its location.
2988}
2989
2990void LocationsBuilderMIPS64::VisitPhi(HPhi* instruction) {
2991 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2992 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2993 locations->SetInAt(i, Location::Any());
2994 }
2995 locations->SetOut(Location::Any());
2996}
2997
2998void InstructionCodeGeneratorMIPS64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
2999 LOG(FATAL) << "Unreachable";
3000}
3001
3002void LocationsBuilderMIPS64::VisitRem(HRem* rem) {
3003 Primitive::Type type = rem->GetResultType();
3004 LocationSummary::CallKind call_kind =
3005 Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall;
3006 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
3007
3008 switch (type) {
3009 case Primitive::kPrimInt:
3010 case Primitive::kPrimLong:
3011 locations->SetInAt(0, Location::RequiresRegister());
3012 locations->SetInAt(1, Location::RequiresRegister());
3013 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3014 break;
3015
3016 case Primitive::kPrimFloat:
3017 case Primitive::kPrimDouble: {
3018 InvokeRuntimeCallingConvention calling_convention;
3019 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
3020 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
3021 locations->SetOut(calling_convention.GetReturnLocation(type));
3022 break;
3023 }
3024
3025 default:
3026 LOG(FATAL) << "Unexpected rem type " << type;
3027 }
3028}
3029
3030void InstructionCodeGeneratorMIPS64::VisitRem(HRem* instruction) {
3031 Primitive::Type type = instruction->GetType();
3032 LocationSummary* locations = instruction->GetLocations();
3033
3034 switch (type) {
3035 case Primitive::kPrimInt:
3036 case Primitive::kPrimLong: {
3037 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3038 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
3039 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
3040 if (type == Primitive::kPrimInt)
3041 __ ModR6(dst, lhs, rhs);
3042 else
3043 __ Dmod(dst, lhs, rhs);
3044 break;
3045 }
3046
3047 case Primitive::kPrimFloat:
3048 case Primitive::kPrimDouble: {
3049 int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf)
3050 : QUICK_ENTRY_POINT(pFmod);
3051 codegen_->InvokeRuntime(entry_offset, instruction, instruction->GetDexPc(), nullptr);
3052 break;
3053 }
3054 default:
3055 LOG(FATAL) << "Unexpected rem type " << type;
3056 }
3057}
3058
3059void LocationsBuilderMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
3060 memory_barrier->SetLocations(nullptr);
3061}
3062
3063void InstructionCodeGeneratorMIPS64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
3064 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
3065}
3066
3067void LocationsBuilderMIPS64::VisitReturn(HReturn* ret) {
3068 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret);
3069 Primitive::Type return_type = ret->InputAt(0)->GetType();
3070 locations->SetInAt(0, Mips64ReturnLocation(return_type));
3071}
3072
3073void InstructionCodeGeneratorMIPS64::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
3074 codegen_->GenerateFrameExit();
3075}
3076
3077void LocationsBuilderMIPS64::VisitReturnVoid(HReturnVoid* ret) {
3078 ret->SetLocations(nullptr);
3079}
3080
3081void InstructionCodeGeneratorMIPS64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
3082 codegen_->GenerateFrameExit();
3083}
3084
3085void LocationsBuilderMIPS64::VisitShl(HShl* shl) {
3086 HandleShift(shl);
3087}
3088
3089void InstructionCodeGeneratorMIPS64::VisitShl(HShl* shl) {
3090 HandleShift(shl);
3091}
3092
3093void LocationsBuilderMIPS64::VisitShr(HShr* shr) {
3094 HandleShift(shr);
3095}
3096
3097void InstructionCodeGeneratorMIPS64::VisitShr(HShr* shr) {
3098 HandleShift(shr);
3099}
3100
3101void LocationsBuilderMIPS64::VisitStoreLocal(HStoreLocal* store) {
3102 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store);
3103 Primitive::Type field_type = store->InputAt(1)->GetType();
3104 switch (field_type) {
3105 case Primitive::kPrimNot:
3106 case Primitive::kPrimBoolean:
3107 case Primitive::kPrimByte:
3108 case Primitive::kPrimChar:
3109 case Primitive::kPrimShort:
3110 case Primitive::kPrimInt:
3111 case Primitive::kPrimFloat:
3112 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
3113 break;
3114
3115 case Primitive::kPrimLong:
3116 case Primitive::kPrimDouble:
3117 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
3118 break;
3119
3120 default:
3121 LOG(FATAL) << "Unimplemented local type " << field_type;
3122 }
3123}
3124
3125void InstructionCodeGeneratorMIPS64::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) {
3126}
3127
3128void LocationsBuilderMIPS64::VisitSub(HSub* instruction) {
3129 HandleBinaryOp(instruction);
3130}
3131
3132void InstructionCodeGeneratorMIPS64::VisitSub(HSub* instruction) {
3133 HandleBinaryOp(instruction);
3134}
3135
3136void LocationsBuilderMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3137 HandleFieldGet(instruction, instruction->GetFieldInfo());
3138}
3139
3140void InstructionCodeGeneratorMIPS64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3141 HandleFieldGet(instruction, instruction->GetFieldInfo());
3142}
3143
3144void LocationsBuilderMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3145 HandleFieldSet(instruction, instruction->GetFieldInfo());
3146}
3147
3148void InstructionCodeGeneratorMIPS64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3149 HandleFieldSet(instruction, instruction->GetFieldInfo());
3150}
3151
Calin Juravlee460d1d2015-09-29 04:52:17 +01003152void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldGet(
3153 HUnresolvedInstanceFieldGet* instruction) {
3154 FieldAccessCallingConventionMIPS64 calling_convention;
3155 codegen_->CreateUnresolvedFieldLocationSummary(
3156 instruction, instruction->GetFieldType(), calling_convention);
3157}
3158
3159void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldGet(
3160 HUnresolvedInstanceFieldGet* instruction) {
3161 FieldAccessCallingConventionMIPS64 calling_convention;
3162 codegen_->GenerateUnresolvedFieldAccess(instruction,
3163 instruction->GetFieldType(),
3164 instruction->GetFieldIndex(),
3165 instruction->GetDexPc(),
3166 calling_convention);
3167}
3168
3169void LocationsBuilderMIPS64::VisitUnresolvedInstanceFieldSet(
3170 HUnresolvedInstanceFieldSet* instruction) {
3171 FieldAccessCallingConventionMIPS64 calling_convention;
3172 codegen_->CreateUnresolvedFieldLocationSummary(
3173 instruction, instruction->GetFieldType(), calling_convention);
3174}
3175
3176void InstructionCodeGeneratorMIPS64::VisitUnresolvedInstanceFieldSet(
3177 HUnresolvedInstanceFieldSet* instruction) {
3178 FieldAccessCallingConventionMIPS64 calling_convention;
3179 codegen_->GenerateUnresolvedFieldAccess(instruction,
3180 instruction->GetFieldType(),
3181 instruction->GetFieldIndex(),
3182 instruction->GetDexPc(),
3183 calling_convention);
3184}
3185
3186void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldGet(
3187 HUnresolvedStaticFieldGet* instruction) {
3188 FieldAccessCallingConventionMIPS64 calling_convention;
3189 codegen_->CreateUnresolvedFieldLocationSummary(
3190 instruction, instruction->GetFieldType(), calling_convention);
3191}
3192
3193void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldGet(
3194 HUnresolvedStaticFieldGet* instruction) {
3195 FieldAccessCallingConventionMIPS64 calling_convention;
3196 codegen_->GenerateUnresolvedFieldAccess(instruction,
3197 instruction->GetFieldType(),
3198 instruction->GetFieldIndex(),
3199 instruction->GetDexPc(),
3200 calling_convention);
3201}
3202
3203void LocationsBuilderMIPS64::VisitUnresolvedStaticFieldSet(
3204 HUnresolvedStaticFieldSet* instruction) {
3205 FieldAccessCallingConventionMIPS64 calling_convention;
3206 codegen_->CreateUnresolvedFieldLocationSummary(
3207 instruction, instruction->GetFieldType(), calling_convention);
3208}
3209
3210void InstructionCodeGeneratorMIPS64::VisitUnresolvedStaticFieldSet(
3211 HUnresolvedStaticFieldSet* instruction) {
3212 FieldAccessCallingConventionMIPS64 calling_convention;
3213 codegen_->GenerateUnresolvedFieldAccess(instruction,
3214 instruction->GetFieldType(),
3215 instruction->GetFieldIndex(),
3216 instruction->GetDexPc(),
3217 calling_convention);
3218}
3219
Alexey Frunze4dda3372015-06-01 18:31:49 -07003220void LocationsBuilderMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) {
3221 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3222}
3223
3224void InstructionCodeGeneratorMIPS64::VisitSuspendCheck(HSuspendCheck* instruction) {
3225 HBasicBlock* block = instruction->GetBlock();
3226 if (block->GetLoopInformation() != nullptr) {
3227 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3228 // The back edge will generate the suspend check.
3229 return;
3230 }
3231 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3232 // The goto will generate the suspend check.
3233 return;
3234 }
3235 GenerateSuspendCheck(instruction, nullptr);
3236}
3237
3238void LocationsBuilderMIPS64::VisitTemporary(HTemporary* temp) {
3239 temp->SetLocations(nullptr);
3240}
3241
3242void InstructionCodeGeneratorMIPS64::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) {
3243 // Nothing to do, this is driven by the code generator.
3244}
3245
3246void LocationsBuilderMIPS64::VisitThrow(HThrow* instruction) {
3247 LocationSummary* locations =
3248 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3249 InvokeRuntimeCallingConvention calling_convention;
3250 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3251}
3252
3253void InstructionCodeGeneratorMIPS64::VisitThrow(HThrow* instruction) {
3254 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException),
3255 instruction,
3256 instruction->GetDexPc(),
3257 nullptr);
3258 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
3259}
3260
3261void LocationsBuilderMIPS64::VisitTypeConversion(HTypeConversion* conversion) {
3262 Primitive::Type input_type = conversion->GetInputType();
3263 Primitive::Type result_type = conversion->GetResultType();
3264 DCHECK_NE(input_type, result_type);
3265
3266 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
3267 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
3268 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
3269 }
3270
3271 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
3272 if ((Primitive::IsFloatingPointType(result_type) && input_type == Primitive::kPrimLong) ||
3273 (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type))) {
3274 call_kind = LocationSummary::kCall;
3275 }
3276
3277 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
3278
3279 if (call_kind == LocationSummary::kNoCall) {
3280 if (Primitive::IsFloatingPointType(input_type)) {
3281 locations->SetInAt(0, Location::RequiresFpuRegister());
3282 } else {
3283 locations->SetInAt(0, Location::RequiresRegister());
3284 }
3285
3286 if (Primitive::IsFloatingPointType(result_type)) {
3287 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3288 } else {
3289 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3290 }
3291 } else {
3292 InvokeRuntimeCallingConvention calling_convention;
3293
3294 if (Primitive::IsFloatingPointType(input_type)) {
3295 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
3296 } else {
3297 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3298 }
3299
3300 locations->SetOut(calling_convention.GetReturnLocation(result_type));
3301 }
3302}
3303
3304void InstructionCodeGeneratorMIPS64::VisitTypeConversion(HTypeConversion* conversion) {
3305 LocationSummary* locations = conversion->GetLocations();
3306 Primitive::Type result_type = conversion->GetResultType();
3307 Primitive::Type input_type = conversion->GetInputType();
3308
3309 DCHECK_NE(input_type, result_type);
3310
3311 if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
3312 GpuRegister dst = locations->Out().AsRegister<GpuRegister>();
3313 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
3314
3315 switch (result_type) {
3316 case Primitive::kPrimChar:
3317 __ Andi(dst, src, 0xFFFF);
3318 break;
3319 case Primitive::kPrimByte:
3320 // long is never converted into types narrower than int directly,
3321 // so SEB and SEH can be used without ever causing unpredictable results
3322 // on 64-bit inputs
3323 DCHECK(input_type != Primitive::kPrimLong);
3324 __ Seb(dst, src);
3325 break;
3326 case Primitive::kPrimShort:
3327 // long is never converted into types narrower than int directly,
3328 // so SEB and SEH can be used without ever causing unpredictable results
3329 // on 64-bit inputs
3330 DCHECK(input_type != Primitive::kPrimLong);
3331 __ Seh(dst, src);
3332 break;
3333 case Primitive::kPrimInt:
3334 case Primitive::kPrimLong:
3335 // Sign-extend 32-bit int into bits 32 through 63 for
3336 // int-to-long and long-to-int conversions
3337 __ Sll(dst, src, 0);
3338 break;
3339
3340 default:
3341 LOG(FATAL) << "Unexpected type conversion from " << input_type
3342 << " to " << result_type;
3343 }
3344 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
3345 if (input_type != Primitive::kPrimLong) {
3346 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
3347 GpuRegister src = locations->InAt(0).AsRegister<GpuRegister>();
3348 __ Mtc1(src, FTMP);
3349 if (result_type == Primitive::kPrimFloat) {
3350 __ Cvtsw(dst, FTMP);
3351 } else {
3352 __ Cvtdw(dst, FTMP);
3353 }
3354 } else {
3355 int32_t entry_offset = (result_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pL2f)
3356 : QUICK_ENTRY_POINT(pL2d);
3357 codegen_->InvokeRuntime(entry_offset,
3358 conversion,
3359 conversion->GetDexPc(),
3360 nullptr);
3361 }
3362 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
3363 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
3364 int32_t entry_offset;
3365 if (result_type != Primitive::kPrimLong) {
3366 entry_offset = (input_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pF2iz)
3367 : QUICK_ENTRY_POINT(pD2iz);
3368 } else {
3369 entry_offset = (input_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pF2l)
3370 : QUICK_ENTRY_POINT(pD2l);
3371 }
3372 codegen_->InvokeRuntime(entry_offset,
3373 conversion,
3374 conversion->GetDexPc(),
3375 nullptr);
3376 } else if (Primitive::IsFloatingPointType(result_type) &&
3377 Primitive::IsFloatingPointType(input_type)) {
3378 FpuRegister dst = locations->Out().AsFpuRegister<FpuRegister>();
3379 FpuRegister src = locations->InAt(0).AsFpuRegister<FpuRegister>();
3380 if (result_type == Primitive::kPrimFloat) {
3381 __ Cvtsd(dst, src);
3382 } else {
3383 __ Cvtds(dst, src);
3384 }
3385 } else {
3386 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
3387 << " to " << result_type;
3388 }
3389}
3390
3391void LocationsBuilderMIPS64::VisitUShr(HUShr* ushr) {
3392 HandleShift(ushr);
3393}
3394
3395void InstructionCodeGeneratorMIPS64::VisitUShr(HUShr* ushr) {
3396 HandleShift(ushr);
3397}
3398
3399void LocationsBuilderMIPS64::VisitXor(HXor* instruction) {
3400 HandleBinaryOp(instruction);
3401}
3402
3403void InstructionCodeGeneratorMIPS64::VisitXor(HXor* instruction) {
3404 HandleBinaryOp(instruction);
3405}
3406
3407void LocationsBuilderMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
3408 // Nothing to do, this should be removed during prepare for register allocator.
3409 LOG(FATAL) << "Unreachable";
3410}
3411
3412void InstructionCodeGeneratorMIPS64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
3413 // Nothing to do, this should be removed during prepare for register allocator.
3414 LOG(FATAL) << "Unreachable";
3415}
3416
3417void LocationsBuilderMIPS64::VisitEqual(HEqual* comp) {
3418 VisitCondition(comp);
3419}
3420
3421void InstructionCodeGeneratorMIPS64::VisitEqual(HEqual* comp) {
3422 VisitCondition(comp);
3423}
3424
3425void LocationsBuilderMIPS64::VisitNotEqual(HNotEqual* comp) {
3426 VisitCondition(comp);
3427}
3428
3429void InstructionCodeGeneratorMIPS64::VisitNotEqual(HNotEqual* comp) {
3430 VisitCondition(comp);
3431}
3432
3433void LocationsBuilderMIPS64::VisitLessThan(HLessThan* comp) {
3434 VisitCondition(comp);
3435}
3436
3437void InstructionCodeGeneratorMIPS64::VisitLessThan(HLessThan* comp) {
3438 VisitCondition(comp);
3439}
3440
3441void LocationsBuilderMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
3442 VisitCondition(comp);
3443}
3444
3445void InstructionCodeGeneratorMIPS64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
3446 VisitCondition(comp);
3447}
3448
3449void LocationsBuilderMIPS64::VisitGreaterThan(HGreaterThan* comp) {
3450 VisitCondition(comp);
3451}
3452
3453void InstructionCodeGeneratorMIPS64::VisitGreaterThan(HGreaterThan* comp) {
3454 VisitCondition(comp);
3455}
3456
3457void LocationsBuilderMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
3458 VisitCondition(comp);
3459}
3460
3461void InstructionCodeGeneratorMIPS64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
3462 VisitCondition(comp);
3463}
3464
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +01003465void LocationsBuilderMIPS64::VisitFakeString(HFakeString* instruction) {
3466 DCHECK(codegen_->IsBaseline());
3467 LocationSummary* locations =
3468 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3469 locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant()));
3470}
3471
3472void InstructionCodeGeneratorMIPS64::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) {
3473 DCHECK(codegen_->IsBaseline());
3474 // Will be generated at use site.
3475}
3476
Mark Mendellfe57faa2015-09-18 09:26:15 -04003477// Simple implementation of packed switch - generate cascaded compare/jumps.
3478void LocationsBuilderMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) {
3479 LocationSummary* locations =
3480 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
3481 locations->SetInAt(0, Location::RequiresRegister());
3482}
3483
3484void InstructionCodeGeneratorMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) {
3485 int32_t lower_bound = switch_instr->GetStartValue();
3486 int32_t num_entries = switch_instr->GetNumEntries();
3487 LocationSummary* locations = switch_instr->GetLocations();
3488 GpuRegister value_reg = locations->InAt(0).AsRegister<GpuRegister>();
3489 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
3490
3491 // Create a series of compare/jumps.
3492 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
3493 for (int32_t i = 0; i < num_entries; i++) {
3494 int32_t case_value = lower_bound + i;
Vladimir Markoec7802a2015-10-01 20:57:57 +01003495 Label* succ = codegen_->GetLabelOf(successors[i]);
Mark Mendellfe57faa2015-09-18 09:26:15 -04003496 if (case_value == 0) {
3497 __ Beqzc(value_reg, succ);
3498 } else {
3499 __ LoadConst32(TMP, case_value);
3500 __ Beqc(value_reg, TMP, succ);
3501 }
3502 }
3503
3504 // And the default for any other value.
3505 if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) {
3506 __ B(codegen_->GetLabelOf(default_block));
3507 }
3508}
3509
Alexey Frunze4dda3372015-06-01 18:31:49 -07003510} // namespace mips64
3511} // namespace art