blob: 8f2fc2687ed6cf21964c50e2ea16499c59d5a888 [file] [log] [blame]
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001/*
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_mips.h"
18
19#include "arch/mips/entrypoints_direct_mips.h"
20#include "arch/mips/instruction_set_features_mips.h"
21#include "art_method.h"
Chris Larsen701566a2015-10-27 15:29:13 -070022#include "code_generator_utils.h"
Vladimir Marko3a21e382016-09-02 12:38:38 +010023#include "compiled_method.h"
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020024#include "entrypoints/quick/quick_entrypoints.h"
25#include "entrypoints/quick/quick_entrypoints_enum.h"
26#include "gc/accounting/card_table.h"
27#include "intrinsics.h"
Chris Larsen701566a2015-10-27 15:29:13 -070028#include "intrinsics_mips.h"
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020029#include "mirror/array-inl.h"
30#include "mirror/class-inl.h"
31#include "offsets.h"
32#include "thread.h"
33#include "utils/assembler.h"
34#include "utils/mips/assembler_mips.h"
35#include "utils/stack_checks.h"
36
37namespace art {
38namespace mips {
39
40static constexpr int kCurrentMethodStackOffset = 0;
41static constexpr Register kMethodRegisterArgument = A0;
42
Alexey Frunzee3fb2452016-05-10 16:08:05 -070043// We'll maximize the range of a single load instruction for dex cache array accesses
44// by aligning offset -32768 with the offset of the first used element.
45static constexpr uint32_t kDexCacheArrayLwOffset = 0x8000;
46
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020047Location MipsReturnLocation(Primitive::Type return_type) {
48 switch (return_type) {
49 case Primitive::kPrimBoolean:
50 case Primitive::kPrimByte:
51 case Primitive::kPrimChar:
52 case Primitive::kPrimShort:
53 case Primitive::kPrimInt:
54 case Primitive::kPrimNot:
55 return Location::RegisterLocation(V0);
56
57 case Primitive::kPrimLong:
58 return Location::RegisterPairLocation(V0, V1);
59
60 case Primitive::kPrimFloat:
61 case Primitive::kPrimDouble:
62 return Location::FpuRegisterLocation(F0);
63
64 case Primitive::kPrimVoid:
65 return Location();
66 }
67 UNREACHABLE();
68}
69
70Location InvokeDexCallingConventionVisitorMIPS::GetReturnLocation(Primitive::Type type) const {
71 return MipsReturnLocation(type);
72}
73
74Location InvokeDexCallingConventionVisitorMIPS::GetMethodLocation() const {
75 return Location::RegisterLocation(kMethodRegisterArgument);
76}
77
78Location InvokeDexCallingConventionVisitorMIPS::GetNextLocation(Primitive::Type type) {
79 Location next_location;
80
81 switch (type) {
82 case Primitive::kPrimBoolean:
83 case Primitive::kPrimByte:
84 case Primitive::kPrimChar:
85 case Primitive::kPrimShort:
86 case Primitive::kPrimInt:
87 case Primitive::kPrimNot: {
88 uint32_t gp_index = gp_index_++;
89 if (gp_index < calling_convention.GetNumberOfRegisters()) {
90 next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index));
91 } else {
92 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
93 next_location = Location::StackSlot(stack_offset);
94 }
95 break;
96 }
97
98 case Primitive::kPrimLong: {
99 uint32_t gp_index = gp_index_;
100 gp_index_ += 2;
101 if (gp_index + 1 < calling_convention.GetNumberOfRegisters()) {
102 if (calling_convention.GetRegisterAt(gp_index) == A1) {
103 gp_index_++; // Skip A1, and use A2_A3 instead.
104 gp_index++;
105 }
106 Register low_even = calling_convention.GetRegisterAt(gp_index);
107 Register high_odd = calling_convention.GetRegisterAt(gp_index + 1);
108 DCHECK_EQ(low_even + 1, high_odd);
109 next_location = Location::RegisterPairLocation(low_even, high_odd);
110 } else {
111 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
112 next_location = Location::DoubleStackSlot(stack_offset);
113 }
114 break;
115 }
116
117 // Note: both float and double types are stored in even FPU registers. On 32 bit FPU, double
118 // will take up the even/odd pair, while floats are stored in even regs only.
119 // On 64 bit FPU, both double and float are stored in even registers only.
120 case Primitive::kPrimFloat:
121 case Primitive::kPrimDouble: {
122 uint32_t float_index = float_index_++;
123 if (float_index < calling_convention.GetNumberOfFpuRegisters()) {
124 next_location = Location::FpuRegisterLocation(
125 calling_convention.GetFpuRegisterAt(float_index));
126 } else {
127 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
128 next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
129 : Location::StackSlot(stack_offset);
130 }
131 break;
132 }
133
134 case Primitive::kPrimVoid:
135 LOG(FATAL) << "Unexpected parameter type " << type;
136 break;
137 }
138
139 // Space on the stack is reserved for all arguments.
140 stack_index_ += Primitive::Is64BitType(type) ? 2 : 1;
141
142 return next_location;
143}
144
145Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type type) {
146 return MipsReturnLocation(type);
147}
148
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100149// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
150#define __ down_cast<CodeGeneratorMIPS*>(codegen)->GetAssembler()-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -0700151#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value()
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200152
153class BoundsCheckSlowPathMIPS : public SlowPathCodeMIPS {
154 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000155 explicit BoundsCheckSlowPathMIPS(HBoundsCheck* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200156
157 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
158 LocationSummary* locations = instruction_->GetLocations();
159 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
160 __ Bind(GetEntryLabel());
161 if (instruction_->CanThrowIntoCatchBlock()) {
162 // Live registers will be restored in the catch block if caught.
163 SaveLiveRegisters(codegen, instruction_->GetLocations());
164 }
165 // We're moving two locations to locations that could overlap, so we need a parallel
166 // move resolver.
167 InvokeRuntimeCallingConvention calling_convention;
168 codegen->EmitParallelMoves(locations->InAt(0),
169 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
170 Primitive::kPrimInt,
171 locations->InAt(1),
172 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
173 Primitive::kPrimInt);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100174 uint32_t entry_point_offset = instruction_->AsBoundsCheck()->IsStringCharAt()
175 ? QUICK_ENTRY_POINT(pThrowStringBounds)
176 : QUICK_ENTRY_POINT(pThrowArrayBounds);
177 mips_codegen->InvokeRuntime(entry_point_offset,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200178 instruction_,
179 instruction_->GetDexPc(),
180 this,
181 IsDirectEntrypoint(kQuickThrowArrayBounds));
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100182 CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200183 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
184 }
185
186 bool IsFatal() const OVERRIDE { return true; }
187
188 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS"; }
189
190 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200191 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS);
192};
193
194class DivZeroCheckSlowPathMIPS : public SlowPathCodeMIPS {
195 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000196 explicit DivZeroCheckSlowPathMIPS(HDivZeroCheck* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200197
198 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
199 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
200 __ Bind(GetEntryLabel());
201 if (instruction_->CanThrowIntoCatchBlock()) {
202 // Live registers will be restored in the catch block if caught.
203 SaveLiveRegisters(codegen, instruction_->GetLocations());
204 }
205 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero),
206 instruction_,
207 instruction_->GetDexPc(),
208 this,
209 IsDirectEntrypoint(kQuickThrowDivZero));
210 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
211 }
212
213 bool IsFatal() const OVERRIDE { return true; }
214
215 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS"; }
216
217 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200218 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS);
219};
220
221class LoadClassSlowPathMIPS : public SlowPathCodeMIPS {
222 public:
223 LoadClassSlowPathMIPS(HLoadClass* cls,
224 HInstruction* at,
225 uint32_t dex_pc,
226 bool do_clinit)
David Srbecky9cd6d372016-02-09 15:24:47 +0000227 : SlowPathCodeMIPS(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200228 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
229 }
230
231 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
232 LocationSummary* locations = at_->GetLocations();
233 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
234
235 __ Bind(GetEntryLabel());
236 SaveLiveRegisters(codegen, locations);
237
238 InvokeRuntimeCallingConvention calling_convention;
239 __ LoadConst32(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
240
241 int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
242 : QUICK_ENTRY_POINT(pInitializeType);
243 bool direct = do_clinit_ ? IsDirectEntrypoint(kQuickInitializeStaticStorage)
244 : IsDirectEntrypoint(kQuickInitializeType);
245
246 mips_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this, direct);
247 if (do_clinit_) {
248 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
249 } else {
250 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
251 }
252
253 // Move the class to the desired location.
254 Location out = locations->Out();
255 if (out.IsValid()) {
256 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
257 Primitive::Type type = at_->GetType();
258 mips_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type);
259 }
260
261 RestoreLiveRegisters(codegen, locations);
262 __ B(GetExitLabel());
263 }
264
265 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS"; }
266
267 private:
268 // The class this slow path will load.
269 HLoadClass* const cls_;
270
271 // The instruction where this slow path is happening.
272 // (Might be the load class or an initialization check).
273 HInstruction* const at_;
274
275 // The dex PC of `at_`.
276 const uint32_t dex_pc_;
277
278 // Whether to initialize the class.
279 const bool do_clinit_;
280
281 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS);
282};
283
284class LoadStringSlowPathMIPS : public SlowPathCodeMIPS {
285 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000286 explicit LoadStringSlowPathMIPS(HLoadString* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200287
288 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
289 LocationSummary* locations = instruction_->GetLocations();
290 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
291 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
292
293 __ Bind(GetEntryLabel());
294 SaveLiveRegisters(codegen, locations);
295
296 InvokeRuntimeCallingConvention calling_convention;
David Srbecky9cd6d372016-02-09 15:24:47 +0000297 const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex();
298 __ LoadConst32(calling_convention.GetRegisterAt(0), string_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200299 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString),
300 instruction_,
301 instruction_->GetDexPc(),
302 this,
303 IsDirectEntrypoint(kQuickResolveString));
304 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
305 Primitive::Type type = instruction_->GetType();
306 mips_codegen->MoveLocation(locations->Out(),
307 calling_convention.GetReturnLocation(type),
308 type);
309
310 RestoreLiveRegisters(codegen, locations);
311 __ B(GetExitLabel());
312 }
313
314 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS"; }
315
316 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200317 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS);
318};
319
320class NullCheckSlowPathMIPS : public SlowPathCodeMIPS {
321 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000322 explicit NullCheckSlowPathMIPS(HNullCheck* instr) : SlowPathCodeMIPS(instr) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200323
324 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
325 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
326 __ Bind(GetEntryLabel());
327 if (instruction_->CanThrowIntoCatchBlock()) {
328 // Live registers will be restored in the catch block if caught.
329 SaveLiveRegisters(codegen, instruction_->GetLocations());
330 }
331 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer),
332 instruction_,
333 instruction_->GetDexPc(),
334 this,
335 IsDirectEntrypoint(kQuickThrowNullPointer));
336 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
337 }
338
339 bool IsFatal() const OVERRIDE { return true; }
340
341 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS"; }
342
343 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200344 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS);
345};
346
347class SuspendCheckSlowPathMIPS : public SlowPathCodeMIPS {
348 public:
349 SuspendCheckSlowPathMIPS(HSuspendCheck* instruction, HBasicBlock* successor)
David Srbecky9cd6d372016-02-09 15:24:47 +0000350 : SlowPathCodeMIPS(instruction), successor_(successor) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200351
352 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
353 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
354 __ Bind(GetEntryLabel());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200355 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend),
356 instruction_,
357 instruction_->GetDexPc(),
358 this,
359 IsDirectEntrypoint(kQuickTestSuspend));
360 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200361 if (successor_ == nullptr) {
362 __ B(GetReturnLabel());
363 } else {
364 __ B(mips_codegen->GetLabelOf(successor_));
365 }
366 }
367
368 MipsLabel* GetReturnLabel() {
369 DCHECK(successor_ == nullptr);
370 return &return_label_;
371 }
372
373 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS"; }
374
375 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200376 // If not null, the block to branch to after the suspend check.
377 HBasicBlock* const successor_;
378
379 // If `successor_` is null, the label to branch to after the suspend check.
380 MipsLabel return_label_;
381
382 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS);
383};
384
385class TypeCheckSlowPathMIPS : public SlowPathCodeMIPS {
386 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000387 explicit TypeCheckSlowPathMIPS(HInstruction* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200388
389 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
390 LocationSummary* locations = instruction_->GetLocations();
391 Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) : locations->Out();
392 uint32_t dex_pc = instruction_->GetDexPc();
393 DCHECK(instruction_->IsCheckCast()
394 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
395 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
396
397 __ Bind(GetEntryLabel());
398 SaveLiveRegisters(codegen, locations);
399
400 // We're moving two locations to locations that could overlap, so we need a parallel
401 // move resolver.
402 InvokeRuntimeCallingConvention calling_convention;
403 codegen->EmitParallelMoves(locations->InAt(1),
404 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
405 Primitive::kPrimNot,
406 object_class,
407 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
408 Primitive::kPrimNot);
409
410 if (instruction_->IsInstanceOf()) {
411 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial),
412 instruction_,
413 dex_pc,
414 this,
415 IsDirectEntrypoint(kQuickInstanceofNonTrivial));
Roland Levillain888d0672015-11-23 18:53:50 +0000416 CheckEntrypointTypes<
Andreas Gampe67409972016-07-19 22:34:53 -0700417 kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200418 Primitive::Type ret_type = instruction_->GetType();
419 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
420 mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200421 } else {
422 DCHECK(instruction_->IsCheckCast());
423 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast),
424 instruction_,
425 dex_pc,
426 this,
427 IsDirectEntrypoint(kQuickCheckCast));
428 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
429 }
430
431 RestoreLiveRegisters(codegen, locations);
432 __ B(GetExitLabel());
433 }
434
435 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; }
436
437 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200438 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS);
439};
440
441class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS {
442 public:
Aart Bik42249c32016-01-07 15:33:50 -0800443 explicit DeoptimizationSlowPathMIPS(HDeoptimize* instruction)
David Srbecky9cd6d372016-02-09 15:24:47 +0000444 : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200445
446 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Aart Bik42249c32016-01-07 15:33:50 -0800447 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200448 __ Bind(GetEntryLabel());
449 SaveLiveRegisters(codegen, instruction_->GetLocations());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200450 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize),
451 instruction_,
Aart Bik42249c32016-01-07 15:33:50 -0800452 instruction_->GetDexPc(),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200453 this,
454 IsDirectEntrypoint(kQuickDeoptimize));
Roland Levillain888d0672015-11-23 18:53:50 +0000455 CheckEntrypointTypes<kQuickDeoptimize, void, void>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200456 }
457
458 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; }
459
460 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200461 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS);
462};
463
464CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph,
465 const MipsInstructionSetFeatures& isa_features,
466 const CompilerOptions& compiler_options,
467 OptimizingCompilerStats* stats)
468 : CodeGenerator(graph,
469 kNumberOfCoreRegisters,
470 kNumberOfFRegisters,
471 kNumberOfRegisterPairs,
472 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
473 arraysize(kCoreCalleeSaves)),
474 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
475 arraysize(kFpuCalleeSaves)),
476 compiler_options,
477 stats),
478 block_labels_(nullptr),
479 location_builder_(graph, this),
480 instruction_visitor_(graph, this),
481 move_resolver_(graph->GetArena(), this),
Vladimir Marko93205e32016-04-13 11:59:46 +0100482 assembler_(graph->GetArena(), &isa_features),
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700483 isa_features_(isa_features),
Alexey Frunze06a46c42016-07-19 15:00:40 -0700484 uint32_literals_(std::less<uint32_t>(),
485 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700486 method_patches_(MethodReferenceComparator(),
487 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
488 call_patches_(MethodReferenceComparator(),
489 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunze06a46c42016-07-19 15:00:40 -0700490 pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
491 boot_image_string_patches_(StringReferenceValueComparator(),
492 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
493 pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
494 boot_image_type_patches_(TypeReferenceValueComparator(),
495 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
496 pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
497 boot_image_address_patches_(std::less<uint32_t>(),
498 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
499 clobbered_ra_(false) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200500 // Save RA (containing the return address) to mimic Quick.
501 AddAllocatedRegister(Location::RegisterLocation(RA));
502}
503
504#undef __
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100505// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
506#define __ down_cast<MipsAssembler*>(GetAssembler())-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -0700507#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value()
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200508
509void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) {
510 // Ensure that we fix up branches.
511 __ FinalizeCode();
512
513 // Adjust native pc offsets in stack maps.
514 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
515 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
516 uint32_t new_position = __ GetAdjustedPosition(old_position);
517 DCHECK_GE(new_position, old_position);
518 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
519 }
520
521 // Adjust pc offsets for the disassembly information.
522 if (disasm_info_ != nullptr) {
523 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
524 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
525 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
526 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
527 it.second.start = __ GetAdjustedPosition(it.second.start);
528 it.second.end = __ GetAdjustedPosition(it.second.end);
529 }
530 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
531 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
532 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
533 }
534 }
535
536 CodeGenerator::Finalize(allocator);
537}
538
539MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const {
540 return codegen_->GetAssembler();
541}
542
543void ParallelMoveResolverMIPS::EmitMove(size_t index) {
544 DCHECK_LT(index, moves_.size());
545 MoveOperands* move = moves_[index];
546 codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType());
547}
548
549void ParallelMoveResolverMIPS::EmitSwap(size_t index) {
550 DCHECK_LT(index, moves_.size());
551 MoveOperands* move = moves_[index];
552 Primitive::Type type = move->GetType();
553 Location loc1 = move->GetDestination();
554 Location loc2 = move->GetSource();
555
556 DCHECK(!loc1.IsConstant());
557 DCHECK(!loc2.IsConstant());
558
559 if (loc1.Equals(loc2)) {
560 return;
561 }
562
563 if (loc1.IsRegister() && loc2.IsRegister()) {
564 // Swap 2 GPRs.
565 Register r1 = loc1.AsRegister<Register>();
566 Register r2 = loc2.AsRegister<Register>();
567 __ Move(TMP, r2);
568 __ Move(r2, r1);
569 __ Move(r1, TMP);
570 } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) {
571 FRegister f1 = loc1.AsFpuRegister<FRegister>();
572 FRegister f2 = loc2.AsFpuRegister<FRegister>();
573 if (type == Primitive::kPrimFloat) {
574 __ MovS(FTMP, f2);
575 __ MovS(f2, f1);
576 __ MovS(f1, FTMP);
577 } else {
578 DCHECK_EQ(type, Primitive::kPrimDouble);
579 __ MovD(FTMP, f2);
580 __ MovD(f2, f1);
581 __ MovD(f1, FTMP);
582 }
583 } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) ||
584 (loc1.IsFpuRegister() && loc2.IsRegister())) {
585 // Swap FPR and GPR.
586 DCHECK_EQ(type, Primitive::kPrimFloat); // Can only swap a float.
587 FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
588 : loc2.AsFpuRegister<FRegister>();
589 Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>()
590 : loc2.AsRegister<Register>();
591 __ Move(TMP, r2);
592 __ Mfc1(r2, f1);
593 __ Mtc1(TMP, f1);
594 } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) {
595 // Swap 2 GPR register pairs.
596 Register r1 = loc1.AsRegisterPairLow<Register>();
597 Register r2 = loc2.AsRegisterPairLow<Register>();
598 __ Move(TMP, r2);
599 __ Move(r2, r1);
600 __ Move(r1, TMP);
601 r1 = loc1.AsRegisterPairHigh<Register>();
602 r2 = loc2.AsRegisterPairHigh<Register>();
603 __ Move(TMP, r2);
604 __ Move(r2, r1);
605 __ Move(r1, TMP);
606 } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) ||
607 (loc1.IsFpuRegister() && loc2.IsRegisterPair())) {
608 // Swap FPR and GPR register pair.
609 DCHECK_EQ(type, Primitive::kPrimDouble);
610 FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
611 : loc2.AsFpuRegister<FRegister>();
612 Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>()
613 : loc2.AsRegisterPairLow<Register>();
614 Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>()
615 : loc2.AsRegisterPairHigh<Register>();
616 // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and
617 // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR
618 // unpredictable and the following mfch1 will fail.
619 __ Mfc1(TMP, f1);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800620 __ MoveFromFpuHigh(AT, f1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200621 __ Mtc1(r2_l, f1);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800622 __ MoveToFpuHigh(r2_h, f1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200623 __ Move(r2_l, TMP);
624 __ Move(r2_h, AT);
625 } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) {
626 Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false);
627 } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) {
628 Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true);
David Brazdilcc0f3112016-01-28 17:14:52 +0000629 } else if ((loc1.IsRegister() && loc2.IsStackSlot()) ||
630 (loc1.IsStackSlot() && loc2.IsRegister())) {
631 Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>()
632 : loc2.AsRegister<Register>();
633 intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex()
634 : loc2.GetStackIndex();
635 __ Move(TMP, reg);
636 __ LoadFromOffset(kLoadWord, reg, SP, offset);
637 __ StoreToOffset(kStoreWord, TMP, SP, offset);
638 } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) ||
639 (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) {
640 Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>()
641 : loc2.AsRegisterPairLow<Register>();
642 Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>()
643 : loc2.AsRegisterPairHigh<Register>();
644 intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex()
645 : loc2.GetStackIndex();
646 intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize)
647 : loc2.GetHighStackIndex(kMipsWordSize);
648 __ Move(TMP, reg_l);
David Brazdilcc0f3112016-01-28 17:14:52 +0000649 __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l);
David Brazdilcc0f3112016-01-28 17:14:52 +0000650 __ StoreToOffset(kStoreWord, TMP, SP, offset_l);
David Brazdil04d3e872016-01-29 09:50:09 +0000651 __ Move(TMP, reg_h);
652 __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h);
653 __ StoreToOffset(kStoreWord, TMP, SP, offset_h);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200654 } else {
655 LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported";
656 }
657}
658
659void ParallelMoveResolverMIPS::RestoreScratch(int reg) {
660 __ Pop(static_cast<Register>(reg));
661}
662
663void ParallelMoveResolverMIPS::SpillScratch(int reg) {
664 __ Push(static_cast<Register>(reg));
665}
666
667void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) {
668 // Allocate a scratch register other than TMP, if available.
669 // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be
670 // automatically unspilled when the scratch scope object is destroyed).
671 ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters());
672 // If V0 spills onto the stack, SP-relative offsets need to be adjusted.
673 int stack_offset = ensure_scratch.IsSpilled() ? kMipsWordSize : 0;
674 for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) {
675 __ LoadFromOffset(kLoadWord,
676 Register(ensure_scratch.GetRegister()),
677 SP,
678 index1 + stack_offset);
679 __ LoadFromOffset(kLoadWord,
680 TMP,
681 SP,
682 index2 + stack_offset);
683 __ StoreToOffset(kStoreWord,
684 Register(ensure_scratch.GetRegister()),
685 SP,
686 index2 + stack_offset);
687 __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset);
688 }
689}
690
Alexey Frunze73296a72016-06-03 22:51:46 -0700691void CodeGeneratorMIPS::ComputeSpillMask() {
692 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
693 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
694 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
695 // If there're FPU callee-saved registers and there's an odd number of GPR callee-saved
696 // registers, include the ZERO register to force alignment of FPU callee-saved registers
697 // within the stack frame.
698 if ((fpu_spill_mask_ != 0) && (POPCOUNT(core_spill_mask_) % 2 != 0)) {
699 core_spill_mask_ |= (1 << ZERO);
700 }
Alexey Frunze06a46c42016-07-19 15:00:40 -0700701 // If RA is clobbered by PC-relative operations on R2 and it's the only spilled register
702 // (this can happen in leaf methods), artificially spill the ZERO register in order to
703 // force explicit saving and restoring of RA. RA isn't saved/restored when it's the only
704 // spilled register.
705 // TODO: Can this be improved? It causes creation of a stack frame (while RA might be
706 // saved in an unused temporary register) and saving of RA and the current method pointer
707 // in the frame.
708 if (clobbered_ra_ && core_spill_mask_ == (1u << RA) && fpu_spill_mask_ == 0) {
709 core_spill_mask_ |= (1 << ZERO);
710 }
Alexey Frunze73296a72016-06-03 22:51:46 -0700711}
712
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200713static dwarf::Reg DWARFReg(Register reg) {
714 return dwarf::Reg::MipsCore(static_cast<int>(reg));
715}
716
717// TODO: mapping of floating-point registers to DWARF.
718
719void CodeGeneratorMIPS::GenerateFrameEntry() {
720 __ Bind(&frame_entry_label_);
721
722 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips) || !IsLeafMethod();
723
724 if (do_overflow_check) {
725 __ LoadFromOffset(kLoadWord,
726 ZERO,
727 SP,
728 -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips)));
729 RecordPcInfo(nullptr, 0);
730 }
731
732 if (HasEmptyFrame()) {
733 return;
734 }
735
736 // Make sure the frame size isn't unreasonably large.
737 if (GetFrameSize() > GetStackOverflowReservedBytes(kMips)) {
738 LOG(FATAL) << "Stack frame larger than " << GetStackOverflowReservedBytes(kMips) << " bytes";
739 }
740
741 // Spill callee-saved registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200742
Alexey Frunze73296a72016-06-03 22:51:46 -0700743 uint32_t ofs = GetFrameSize();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200744 __ IncreaseFrameSize(ofs);
745
Alexey Frunze73296a72016-06-03 22:51:46 -0700746 for (uint32_t mask = core_spill_mask_; mask != 0; ) {
747 Register reg = static_cast<Register>(MostSignificantBit(mask));
748 mask ^= 1u << reg;
749 ofs -= kMipsWordSize;
750 // The ZERO register is only included for alignment.
751 if (reg != ZERO) {
752 __ StoreToOffset(kStoreWord, reg, SP, ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200753 __ cfi().RelOffset(DWARFReg(reg), ofs);
754 }
755 }
756
Alexey Frunze73296a72016-06-03 22:51:46 -0700757 for (uint32_t mask = fpu_spill_mask_; mask != 0; ) {
758 FRegister reg = static_cast<FRegister>(MostSignificantBit(mask));
759 mask ^= 1u << reg;
760 ofs -= kMipsDoublewordSize;
761 __ StoreDToOffset(reg, SP, ofs);
762 // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200763 }
764
Alexey Frunze73296a72016-06-03 22:51:46 -0700765 // Store the current method pointer.
766 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, kCurrentMethodStackOffset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200767}
768
769void CodeGeneratorMIPS::GenerateFrameExit() {
770 __ cfi().RememberState();
771
772 if (!HasEmptyFrame()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200773 // Restore callee-saved registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200774
Alexey Frunze73296a72016-06-03 22:51:46 -0700775 // For better instruction scheduling restore RA before other registers.
776 uint32_t ofs = GetFrameSize();
777 for (uint32_t mask = core_spill_mask_; mask != 0; ) {
778 Register reg = static_cast<Register>(MostSignificantBit(mask));
779 mask ^= 1u << reg;
780 ofs -= kMipsWordSize;
781 // The ZERO register is only included for alignment.
782 if (reg != ZERO) {
783 __ LoadFromOffset(kLoadWord, reg, SP, ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200784 __ cfi().Restore(DWARFReg(reg));
785 }
786 }
787
Alexey Frunze73296a72016-06-03 22:51:46 -0700788 for (uint32_t mask = fpu_spill_mask_; mask != 0; ) {
789 FRegister reg = static_cast<FRegister>(MostSignificantBit(mask));
790 mask ^= 1u << reg;
791 ofs -= kMipsDoublewordSize;
792 __ LoadDFromOffset(reg, SP, ofs);
793 // TODO: __ cfi().Restore(DWARFReg(reg));
794 }
795
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700796 size_t frame_size = GetFrameSize();
797 // Adjust the stack pointer in the delay slot if doing so doesn't break CFI.
798 bool exchange = IsInt<16>(static_cast<int32_t>(frame_size));
799 bool reordering = __ SetReorder(false);
800 if (exchange) {
801 __ Jr(RA);
802 __ DecreaseFrameSize(frame_size); // Single instruction in delay slot.
803 } else {
804 __ DecreaseFrameSize(frame_size);
805 __ Jr(RA);
806 __ Nop(); // In delay slot.
807 }
808 __ SetReorder(reordering);
809 } else {
810 __ Jr(RA);
811 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200812 }
813
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200814 __ cfi().RestoreState();
815 __ cfi().DefCFAOffset(GetFrameSize());
816}
817
818void CodeGeneratorMIPS::Bind(HBasicBlock* block) {
819 __ Bind(GetLabelOf(block));
820}
821
822void CodeGeneratorMIPS::MoveLocation(Location dst, Location src, Primitive::Type dst_type) {
823 if (src.Equals(dst)) {
824 return;
825 }
826
827 if (src.IsConstant()) {
828 MoveConstant(dst, src.GetConstant());
829 } else {
830 if (Primitive::Is64BitType(dst_type)) {
831 Move64(dst, src);
832 } else {
833 Move32(dst, src);
834 }
835 }
836}
837
838void CodeGeneratorMIPS::Move32(Location destination, Location source) {
839 if (source.Equals(destination)) {
840 return;
841 }
842
843 if (destination.IsRegister()) {
844 if (source.IsRegister()) {
845 __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>());
846 } else if (source.IsFpuRegister()) {
847 __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>());
848 } else {
849 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
850 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
851 }
852 } else if (destination.IsFpuRegister()) {
853 if (source.IsRegister()) {
854 __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>());
855 } else if (source.IsFpuRegister()) {
856 __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>());
857 } else {
858 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
859 __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
860 }
861 } else {
862 DCHECK(destination.IsStackSlot()) << destination;
863 if (source.IsRegister()) {
864 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
865 } else if (source.IsFpuRegister()) {
866 __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex());
867 } else {
868 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
869 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
870 __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex());
871 }
872 }
873}
874
875void CodeGeneratorMIPS::Move64(Location destination, Location source) {
876 if (source.Equals(destination)) {
877 return;
878 }
879
880 if (destination.IsRegisterPair()) {
881 if (source.IsRegisterPair()) {
882 __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
883 __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
884 } else if (source.IsFpuRegister()) {
885 Register dst_high = destination.AsRegisterPairHigh<Register>();
886 Register dst_low = destination.AsRegisterPairLow<Register>();
887 FRegister src = source.AsFpuRegister<FRegister>();
888 __ Mfc1(dst_low, src);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800889 __ MoveFromFpuHigh(dst_high, src);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200890 } else {
891 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
892 int32_t off = source.GetStackIndex();
893 Register r = destination.AsRegisterPairLow<Register>();
894 __ LoadFromOffset(kLoadDoubleword, r, SP, off);
895 }
896 } else if (destination.IsFpuRegister()) {
897 if (source.IsRegisterPair()) {
898 FRegister dst = destination.AsFpuRegister<FRegister>();
899 Register src_high = source.AsRegisterPairHigh<Register>();
900 Register src_low = source.AsRegisterPairLow<Register>();
901 __ Mtc1(src_low, dst);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800902 __ MoveToFpuHigh(src_high, dst);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200903 } else if (source.IsFpuRegister()) {
904 __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>());
905 } else {
906 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
907 __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
908 }
909 } else {
910 DCHECK(destination.IsDoubleStackSlot()) << destination;
911 int32_t off = destination.GetStackIndex();
912 if (source.IsRegisterPair()) {
913 __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, off);
914 } else if (source.IsFpuRegister()) {
915 __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, off);
916 } else {
917 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
918 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
919 __ StoreToOffset(kStoreWord, TMP, SP, off);
920 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4);
921 __ StoreToOffset(kStoreWord, TMP, SP, off + 4);
922 }
923 }
924}
925
926void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) {
927 if (c->IsIntConstant() || c->IsNullConstant()) {
928 // Move 32 bit constant.
929 int32_t value = GetInt32ValueOf(c);
930 if (destination.IsRegister()) {
931 Register dst = destination.AsRegister<Register>();
932 __ LoadConst32(dst, value);
933 } else {
934 DCHECK(destination.IsStackSlot())
935 << "Cannot move " << c->DebugName() << " to " << destination;
936 __ StoreConst32ToOffset(value, SP, destination.GetStackIndex(), TMP);
937 }
938 } else if (c->IsLongConstant()) {
939 // Move 64 bit constant.
940 int64_t value = GetInt64ValueOf(c);
941 if (destination.IsRegisterPair()) {
942 Register r_h = destination.AsRegisterPairHigh<Register>();
943 Register r_l = destination.AsRegisterPairLow<Register>();
944 __ LoadConst64(r_h, r_l, value);
945 } else {
946 DCHECK(destination.IsDoubleStackSlot())
947 << "Cannot move " << c->DebugName() << " to " << destination;
948 __ StoreConst64ToOffset(value, SP, destination.GetStackIndex(), TMP);
949 }
950 } else if (c->IsFloatConstant()) {
951 // Move 32 bit float constant.
952 int32_t value = GetInt32ValueOf(c);
953 if (destination.IsFpuRegister()) {
954 __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP);
955 } else {
956 DCHECK(destination.IsStackSlot())
957 << "Cannot move " << c->DebugName() << " to " << destination;
958 __ StoreConst32ToOffset(value, SP, destination.GetStackIndex(), TMP);
959 }
960 } else {
961 // Move 64 bit double constant.
962 DCHECK(c->IsDoubleConstant()) << c->DebugName();
963 int64_t value = GetInt64ValueOf(c);
964 if (destination.IsFpuRegister()) {
965 FRegister fd = destination.AsFpuRegister<FRegister>();
966 __ LoadDConst64(fd, value, TMP);
967 } else {
968 DCHECK(destination.IsDoubleStackSlot())
969 << "Cannot move " << c->DebugName() << " to " << destination;
970 __ StoreConst64ToOffset(value, SP, destination.GetStackIndex(), TMP);
971 }
972 }
973}
974
975void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) {
976 DCHECK(destination.IsRegister());
977 Register dst = destination.AsRegister<Register>();
978 __ LoadConst32(dst, value);
979}
980
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200981void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) {
982 if (location.IsRegister()) {
983 locations->AddTemp(location);
Alexey Frunzec9e94f32015-10-26 16:11:39 -0700984 } else if (location.IsRegisterPair()) {
985 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>()));
986 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>()));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200987 } else {
988 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
989 }
990}
991
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700992void CodeGeneratorMIPS::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) {
993 DCHECK(linker_patches->empty());
994 size_t size =
995 method_patches_.size() +
996 call_patches_.size() +
Alexey Frunze06a46c42016-07-19 15:00:40 -0700997 pc_relative_dex_cache_patches_.size() +
998 pc_relative_string_patches_.size() +
999 pc_relative_type_patches_.size() +
1000 boot_image_string_patches_.size() +
1001 boot_image_type_patches_.size() +
1002 boot_image_address_patches_.size();
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001003 linker_patches->reserve(size);
1004 for (const auto& entry : method_patches_) {
1005 const MethodReference& target_method = entry.first;
1006 Literal* literal = entry.second;
1007 DCHECK(literal->GetLabel()->IsBound());
1008 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1009 linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset,
1010 target_method.dex_file,
1011 target_method.dex_method_index));
1012 }
1013 for (const auto& entry : call_patches_) {
1014 const MethodReference& target_method = entry.first;
1015 Literal* literal = entry.second;
1016 DCHECK(literal->GetLabel()->IsBound());
1017 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1018 linker_patches->push_back(LinkerPatch::CodePatch(literal_offset,
1019 target_method.dex_file,
1020 target_method.dex_method_index));
1021 }
1022 for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) {
1023 const DexFile& dex_file = info.target_dex_file;
1024 size_t base_element_offset = info.offset_or_index;
1025 DCHECK(info.high_label.IsBound());
1026 uint32_t high_offset = __ GetLabelLocation(&info.high_label);
1027 DCHECK(info.pc_rel_label.IsBound());
1028 uint32_t pc_rel_offset = __ GetLabelLocation(&info.pc_rel_label);
1029 linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(high_offset,
1030 &dex_file,
1031 pc_rel_offset,
1032 base_element_offset));
1033 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07001034 for (const PcRelativePatchInfo& info : pc_relative_string_patches_) {
1035 const DexFile& dex_file = info.target_dex_file;
1036 size_t string_index = info.offset_or_index;
1037 DCHECK(info.high_label.IsBound());
1038 uint32_t high_offset = __ GetLabelLocation(&info.high_label);
1039 // On R2 we use HMipsComputeBaseMethodAddress and patch relative to
1040 // the assembler's base label used for PC-relative literals.
1041 uint32_t pc_rel_offset = info.pc_rel_label.IsBound()
1042 ? __ GetLabelLocation(&info.pc_rel_label)
1043 : __ GetPcRelBaseLabelLocation();
1044 linker_patches->push_back(LinkerPatch::RelativeStringPatch(high_offset,
1045 &dex_file,
1046 pc_rel_offset,
1047 string_index));
1048 }
1049 for (const PcRelativePatchInfo& info : pc_relative_type_patches_) {
1050 const DexFile& dex_file = info.target_dex_file;
1051 size_t type_index = info.offset_or_index;
1052 DCHECK(info.high_label.IsBound());
1053 uint32_t high_offset = __ GetLabelLocation(&info.high_label);
1054 // On R2 we use HMipsComputeBaseMethodAddress and patch relative to
1055 // the assembler's base label used for PC-relative literals.
1056 uint32_t pc_rel_offset = info.pc_rel_label.IsBound()
1057 ? __ GetLabelLocation(&info.pc_rel_label)
1058 : __ GetPcRelBaseLabelLocation();
1059 linker_patches->push_back(LinkerPatch::RelativeTypePatch(high_offset,
1060 &dex_file,
1061 pc_rel_offset,
1062 type_index));
1063 }
1064 for (const auto& entry : boot_image_string_patches_) {
1065 const StringReference& target_string = entry.first;
1066 Literal* literal = entry.second;
1067 DCHECK(literal->GetLabel()->IsBound());
1068 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1069 linker_patches->push_back(LinkerPatch::StringPatch(literal_offset,
1070 target_string.dex_file,
1071 target_string.string_index));
1072 }
1073 for (const auto& entry : boot_image_type_patches_) {
1074 const TypeReference& target_type = entry.first;
1075 Literal* literal = entry.second;
1076 DCHECK(literal->GetLabel()->IsBound());
1077 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1078 linker_patches->push_back(LinkerPatch::TypePatch(literal_offset,
1079 target_type.dex_file,
1080 target_type.type_index));
1081 }
1082 for (const auto& entry : boot_image_address_patches_) {
1083 DCHECK(GetCompilerOptions().GetIncludePatchInformation());
1084 Literal* literal = entry.second;
1085 DCHECK(literal->GetLabel()->IsBound());
1086 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1087 linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset));
1088 }
1089}
1090
1091CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeStringPatch(
1092 const DexFile& dex_file, uint32_t string_index) {
1093 return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_);
1094}
1095
1096CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeTypePatch(
1097 const DexFile& dex_file, uint32_t type_index) {
1098 return NewPcRelativePatch(dex_file, type_index, &pc_relative_type_patches_);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001099}
1100
1101CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeDexCacheArrayPatch(
1102 const DexFile& dex_file, uint32_t element_offset) {
1103 return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_);
1104}
1105
1106CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativePatch(
1107 const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) {
1108 patches->emplace_back(dex_file, offset_or_index);
1109 return &patches->back();
1110}
1111
Alexey Frunze06a46c42016-07-19 15:00:40 -07001112Literal* CodeGeneratorMIPS::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) {
1113 return map->GetOrCreate(
1114 value,
1115 [this, value]() { return __ NewLiteral<uint32_t>(value); });
1116}
1117
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001118Literal* CodeGeneratorMIPS::DeduplicateMethodLiteral(MethodReference target_method,
1119 MethodToLiteralMap* map) {
1120 return map->GetOrCreate(
1121 target_method,
1122 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1123}
1124
1125Literal* CodeGeneratorMIPS::DeduplicateMethodAddressLiteral(MethodReference target_method) {
1126 return DeduplicateMethodLiteral(target_method, &method_patches_);
1127}
1128
1129Literal* CodeGeneratorMIPS::DeduplicateMethodCodeLiteral(MethodReference target_method) {
1130 return DeduplicateMethodLiteral(target_method, &call_patches_);
1131}
1132
Alexey Frunze06a46c42016-07-19 15:00:40 -07001133Literal* CodeGeneratorMIPS::DeduplicateBootImageStringLiteral(const DexFile& dex_file,
1134 uint32_t string_index) {
1135 return boot_image_string_patches_.GetOrCreate(
1136 StringReference(&dex_file, string_index),
1137 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1138}
1139
1140Literal* CodeGeneratorMIPS::DeduplicateBootImageTypeLiteral(const DexFile& dex_file,
1141 uint32_t type_index) {
1142 return boot_image_type_patches_.GetOrCreate(
1143 TypeReference(&dex_file, type_index),
1144 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1145}
1146
1147Literal* CodeGeneratorMIPS::DeduplicateBootImageAddressLiteral(uint32_t address) {
1148 bool needs_patch = GetCompilerOptions().GetIncludePatchInformation();
1149 Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_;
1150 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map);
1151}
1152
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001153void CodeGeneratorMIPS::MarkGCCard(Register object, Register value) {
1154 MipsLabel done;
1155 Register card = AT;
1156 Register temp = TMP;
1157 __ Beqz(value, &done);
1158 __ LoadFromOffset(kLoadWord,
1159 card,
1160 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001161 Thread::CardTableOffset<kMipsPointerSize>().Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001162 __ Srl(temp, object, gc::accounting::CardTable::kCardShift);
1163 __ Addu(temp, card, temp);
1164 __ Sb(card, temp, 0);
1165 __ Bind(&done);
1166}
1167
David Brazdil58282f42016-01-14 12:45:10 +00001168void CodeGeneratorMIPS::SetupBlockedRegisters() const {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001169 // Don't allocate the dalvik style register pair passing.
1170 blocked_register_pairs_[A1_A2] = true;
1171
1172 // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated.
1173 blocked_core_registers_[ZERO] = true;
1174 blocked_core_registers_[K0] = true;
1175 blocked_core_registers_[K1] = true;
1176 blocked_core_registers_[GP] = true;
1177 blocked_core_registers_[SP] = true;
1178 blocked_core_registers_[RA] = true;
1179
1180 // AT and TMP(T8) are used as temporary/scratch registers
1181 // (similar to how AT is used by MIPS assemblers).
1182 blocked_core_registers_[AT] = true;
1183 blocked_core_registers_[TMP] = true;
1184 blocked_fpu_registers_[FTMP] = true;
1185
1186 // Reserve suspend and thread registers.
1187 blocked_core_registers_[S0] = true;
1188 blocked_core_registers_[TR] = true;
1189
1190 // Reserve T9 for function calls
1191 blocked_core_registers_[T9] = true;
1192
1193 // Reserve odd-numbered FPU registers.
1194 for (size_t i = 1; i < kNumberOfFRegisters; i += 2) {
1195 blocked_fpu_registers_[i] = true;
1196 }
1197
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02001198 if (GetGraph()->IsDebuggable()) {
1199 // Stubs do not save callee-save floating point registers. If the graph
1200 // is debuggable, we need to deal with these registers differently. For
1201 // now, just block them.
1202 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
1203 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
1204 }
1205 }
1206
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001207 UpdateBlockedPairRegisters();
1208}
1209
1210void CodeGeneratorMIPS::UpdateBlockedPairRegisters() const {
1211 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
1212 MipsManagedRegister current =
1213 MipsManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
1214 if (blocked_core_registers_[current.AsRegisterPairLow()]
1215 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
1216 blocked_register_pairs_[i] = true;
1217 }
1218 }
1219}
1220
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001221size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
1222 __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index);
1223 return kMipsWordSize;
1224}
1225
1226size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
1227 __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index);
1228 return kMipsWordSize;
1229}
1230
1231size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1232 __ StoreDToOffset(FRegister(reg_id), SP, stack_index);
1233 return kMipsDoublewordSize;
1234}
1235
1236size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1237 __ LoadDFromOffset(FRegister(reg_id), SP, stack_index);
1238 return kMipsDoublewordSize;
1239}
1240
1241void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const {
Vladimir Marko623a7a22016-02-02 18:14:52 +00001242 stream << Register(reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001243}
1244
1245void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Vladimir Marko623a7a22016-02-02 18:14:52 +00001246 stream << FRegister(reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001247}
1248
1249void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint,
1250 HInstruction* instruction,
1251 uint32_t dex_pc,
1252 SlowPathCode* slow_path) {
Andreas Gampe542451c2016-07-26 09:02:02 -07001253 InvokeRuntime(GetThreadOffset<kMipsPointerSize>(entrypoint).Int32Value(),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001254 instruction,
1255 dex_pc,
1256 slow_path,
1257 IsDirectEntrypoint(entrypoint));
1258}
1259
1260constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16;
1261
1262void CodeGeneratorMIPS::InvokeRuntime(int32_t entry_point_offset,
1263 HInstruction* instruction,
1264 uint32_t dex_pc,
1265 SlowPathCode* slow_path,
1266 bool is_direct_entrypoint) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001267 bool reordering = __ SetReorder(false);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001268 __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset);
1269 __ Jalr(T9);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001270 if (is_direct_entrypoint) {
1271 // Reserve argument space on stack (for $a0-$a3) for
1272 // entrypoints that directly reference native implementations.
1273 // Called function may use this space to store $a0-$a3 regs.
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001274 __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001275 __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001276 } else {
1277 __ Nop(); // In delay slot.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001278 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001279 __ SetReorder(reordering);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001280 RecordPcInfo(instruction, dex_pc, slow_path);
1281}
1282
1283void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path,
1284 Register class_reg) {
1285 __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value());
1286 __ LoadConst32(AT, mirror::Class::kStatusInitialized);
1287 __ Blt(TMP, AT, slow_path->GetEntryLabel());
1288 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
1289 __ Sync(0);
1290 __ Bind(slow_path->GetExitLabel());
1291}
1292
1293void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) {
1294 __ Sync(0); // Only stype 0 is supported.
1295}
1296
1297void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction,
1298 HBasicBlock* successor) {
1299 SuspendCheckSlowPathMIPS* slow_path =
1300 new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS(instruction, successor);
1301 codegen_->AddSlowPath(slow_path);
1302
1303 __ LoadFromOffset(kLoadUnsignedHalfword,
1304 TMP,
1305 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001306 Thread::ThreadFlagsOffset<kMipsPointerSize>().Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001307 if (successor == nullptr) {
1308 __ Bnez(TMP, slow_path->GetEntryLabel());
1309 __ Bind(slow_path->GetReturnLabel());
1310 } else {
1311 __ Beqz(TMP, codegen_->GetLabelOf(successor));
1312 __ B(slow_path->GetEntryLabel());
1313 // slow_path will return to GetLabelOf(successor).
1314 }
1315}
1316
1317InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph,
1318 CodeGeneratorMIPS* codegen)
Aart Bik42249c32016-01-07 15:33:50 -08001319 : InstructionCodeGenerator(graph, codegen),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001320 assembler_(codegen->GetAssembler()),
1321 codegen_(codegen) {}
1322
1323void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) {
1324 DCHECK_EQ(instruction->InputCount(), 2U);
1325 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1326 Primitive::Type type = instruction->GetResultType();
1327 switch (type) {
1328 case Primitive::kPrimInt: {
1329 locations->SetInAt(0, Location::RequiresRegister());
1330 HInstruction* right = instruction->InputAt(1);
1331 bool can_use_imm = false;
1332 if (right->IsConstant()) {
1333 int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant());
1334 if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) {
1335 can_use_imm = IsUint<16>(imm);
1336 } else if (instruction->IsAdd()) {
1337 can_use_imm = IsInt<16>(imm);
1338 } else {
1339 DCHECK(instruction->IsSub());
1340 can_use_imm = IsInt<16>(-imm);
1341 }
1342 }
1343 if (can_use_imm)
1344 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1345 else
1346 locations->SetInAt(1, Location::RequiresRegister());
1347 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1348 break;
1349 }
1350
1351 case Primitive::kPrimLong: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001352 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001353 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1354 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001355 break;
1356 }
1357
1358 case Primitive::kPrimFloat:
1359 case Primitive::kPrimDouble:
1360 DCHECK(instruction->IsAdd() || instruction->IsSub());
1361 locations->SetInAt(0, Location::RequiresFpuRegister());
1362 locations->SetInAt(1, Location::RequiresFpuRegister());
1363 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1364 break;
1365
1366 default:
1367 LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type;
1368 }
1369}
1370
1371void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) {
1372 Primitive::Type type = instruction->GetType();
1373 LocationSummary* locations = instruction->GetLocations();
1374
1375 switch (type) {
1376 case Primitive::kPrimInt: {
1377 Register dst = locations->Out().AsRegister<Register>();
1378 Register lhs = locations->InAt(0).AsRegister<Register>();
1379 Location rhs_location = locations->InAt(1);
1380
1381 Register rhs_reg = ZERO;
1382 int32_t rhs_imm = 0;
1383 bool use_imm = rhs_location.IsConstant();
1384 if (use_imm) {
1385 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
1386 } else {
1387 rhs_reg = rhs_location.AsRegister<Register>();
1388 }
1389
1390 if (instruction->IsAnd()) {
1391 if (use_imm)
1392 __ Andi(dst, lhs, rhs_imm);
1393 else
1394 __ And(dst, lhs, rhs_reg);
1395 } else if (instruction->IsOr()) {
1396 if (use_imm)
1397 __ Ori(dst, lhs, rhs_imm);
1398 else
1399 __ Or(dst, lhs, rhs_reg);
1400 } else if (instruction->IsXor()) {
1401 if (use_imm)
1402 __ Xori(dst, lhs, rhs_imm);
1403 else
1404 __ Xor(dst, lhs, rhs_reg);
1405 } else if (instruction->IsAdd()) {
1406 if (use_imm)
1407 __ Addiu(dst, lhs, rhs_imm);
1408 else
1409 __ Addu(dst, lhs, rhs_reg);
1410 } else {
1411 DCHECK(instruction->IsSub());
1412 if (use_imm)
1413 __ Addiu(dst, lhs, -rhs_imm);
1414 else
1415 __ Subu(dst, lhs, rhs_reg);
1416 }
1417 break;
1418 }
1419
1420 case Primitive::kPrimLong: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001421 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
1422 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
1423 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
1424 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001425 Location rhs_location = locations->InAt(1);
1426 bool use_imm = rhs_location.IsConstant();
1427 if (!use_imm) {
1428 Register rhs_high = rhs_location.AsRegisterPairHigh<Register>();
1429 Register rhs_low = rhs_location.AsRegisterPairLow<Register>();
1430 if (instruction->IsAnd()) {
1431 __ And(dst_low, lhs_low, rhs_low);
1432 __ And(dst_high, lhs_high, rhs_high);
1433 } else if (instruction->IsOr()) {
1434 __ Or(dst_low, lhs_low, rhs_low);
1435 __ Or(dst_high, lhs_high, rhs_high);
1436 } else if (instruction->IsXor()) {
1437 __ Xor(dst_low, lhs_low, rhs_low);
1438 __ Xor(dst_high, lhs_high, rhs_high);
1439 } else if (instruction->IsAdd()) {
1440 if (lhs_low == rhs_low) {
1441 // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs.
1442 __ Slt(TMP, lhs_low, ZERO);
1443 __ Addu(dst_low, lhs_low, rhs_low);
1444 } else {
1445 __ Addu(dst_low, lhs_low, rhs_low);
1446 // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged.
1447 __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low);
1448 }
1449 __ Addu(dst_high, lhs_high, rhs_high);
1450 __ Addu(dst_high, dst_high, TMP);
1451 } else {
1452 DCHECK(instruction->IsSub());
1453 __ Sltu(TMP, lhs_low, rhs_low);
1454 __ Subu(dst_low, lhs_low, rhs_low);
1455 __ Subu(dst_high, lhs_high, rhs_high);
1456 __ Subu(dst_high, dst_high, TMP);
1457 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001458 } else {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001459 int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant());
1460 if (instruction->IsOr()) {
1461 uint32_t low = Low32Bits(value);
1462 uint32_t high = High32Bits(value);
1463 if (IsUint<16>(low)) {
1464 if (dst_low != lhs_low || low != 0) {
1465 __ Ori(dst_low, lhs_low, low);
1466 }
1467 } else {
1468 __ LoadConst32(TMP, low);
1469 __ Or(dst_low, lhs_low, TMP);
1470 }
1471 if (IsUint<16>(high)) {
1472 if (dst_high != lhs_high || high != 0) {
1473 __ Ori(dst_high, lhs_high, high);
1474 }
1475 } else {
1476 if (high != low) {
1477 __ LoadConst32(TMP, high);
1478 }
1479 __ Or(dst_high, lhs_high, TMP);
1480 }
1481 } else if (instruction->IsXor()) {
1482 uint32_t low = Low32Bits(value);
1483 uint32_t high = High32Bits(value);
1484 if (IsUint<16>(low)) {
1485 if (dst_low != lhs_low || low != 0) {
1486 __ Xori(dst_low, lhs_low, low);
1487 }
1488 } else {
1489 __ LoadConst32(TMP, low);
1490 __ Xor(dst_low, lhs_low, TMP);
1491 }
1492 if (IsUint<16>(high)) {
1493 if (dst_high != lhs_high || high != 0) {
1494 __ Xori(dst_high, lhs_high, high);
1495 }
1496 } else {
1497 if (high != low) {
1498 __ LoadConst32(TMP, high);
1499 }
1500 __ Xor(dst_high, lhs_high, TMP);
1501 }
1502 } else if (instruction->IsAnd()) {
1503 uint32_t low = Low32Bits(value);
1504 uint32_t high = High32Bits(value);
1505 if (IsUint<16>(low)) {
1506 __ Andi(dst_low, lhs_low, low);
1507 } else if (low != 0xFFFFFFFF) {
1508 __ LoadConst32(TMP, low);
1509 __ And(dst_low, lhs_low, TMP);
1510 } else if (dst_low != lhs_low) {
1511 __ Move(dst_low, lhs_low);
1512 }
1513 if (IsUint<16>(high)) {
1514 __ Andi(dst_high, lhs_high, high);
1515 } else if (high != 0xFFFFFFFF) {
1516 if (high != low) {
1517 __ LoadConst32(TMP, high);
1518 }
1519 __ And(dst_high, lhs_high, TMP);
1520 } else if (dst_high != lhs_high) {
1521 __ Move(dst_high, lhs_high);
1522 }
1523 } else {
1524 if (instruction->IsSub()) {
1525 value = -value;
1526 } else {
1527 DCHECK(instruction->IsAdd());
1528 }
1529 int32_t low = Low32Bits(value);
1530 int32_t high = High32Bits(value);
1531 if (IsInt<16>(low)) {
1532 if (dst_low != lhs_low || low != 0) {
1533 __ Addiu(dst_low, lhs_low, low);
1534 }
1535 if (low != 0) {
1536 __ Sltiu(AT, dst_low, low);
1537 }
1538 } else {
1539 __ LoadConst32(TMP, low);
1540 __ Addu(dst_low, lhs_low, TMP);
1541 __ Sltu(AT, dst_low, TMP);
1542 }
1543 if (IsInt<16>(high)) {
1544 if (dst_high != lhs_high || high != 0) {
1545 __ Addiu(dst_high, lhs_high, high);
1546 }
1547 } else {
1548 if (high != low) {
1549 __ LoadConst32(TMP, high);
1550 }
1551 __ Addu(dst_high, lhs_high, TMP);
1552 }
1553 if (low != 0) {
1554 __ Addu(dst_high, dst_high, AT);
1555 }
1556 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001557 }
1558 break;
1559 }
1560
1561 case Primitive::kPrimFloat:
1562 case Primitive::kPrimDouble: {
1563 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
1564 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
1565 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
1566 if (instruction->IsAdd()) {
1567 if (type == Primitive::kPrimFloat) {
1568 __ AddS(dst, lhs, rhs);
1569 } else {
1570 __ AddD(dst, lhs, rhs);
1571 }
1572 } else {
1573 DCHECK(instruction->IsSub());
1574 if (type == Primitive::kPrimFloat) {
1575 __ SubS(dst, lhs, rhs);
1576 } else {
1577 __ SubD(dst, lhs, rhs);
1578 }
1579 }
1580 break;
1581 }
1582
1583 default:
1584 LOG(FATAL) << "Unexpected binary operation type " << type;
1585 }
1586}
1587
1588void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001589 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001590
1591 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1592 Primitive::Type type = instr->GetResultType();
1593 switch (type) {
1594 case Primitive::kPrimInt:
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001595 locations->SetInAt(0, Location::RequiresRegister());
1596 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1597 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1598 break;
1599 case Primitive::kPrimLong:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001600 locations->SetInAt(0, Location::RequiresRegister());
1601 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1602 locations->SetOut(Location::RequiresRegister());
1603 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001604 default:
1605 LOG(FATAL) << "Unexpected shift type " << type;
1606 }
1607}
1608
1609static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte;
1610
1611void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001612 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001613 LocationSummary* locations = instr->GetLocations();
1614 Primitive::Type type = instr->GetType();
1615
1616 Location rhs_location = locations->InAt(1);
1617 bool use_imm = rhs_location.IsConstant();
1618 Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>();
1619 int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0;
Roland Levillain5b5b9312016-03-22 14:57:31 +00001620 const uint32_t shift_mask =
1621 (type == Primitive::kPrimInt) ? kMaxIntShiftDistance : kMaxLongShiftDistance;
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001622 const uint32_t shift_value = rhs_imm & shift_mask;
Alexey Frunze92d90602015-12-18 18:16:36 -08001623 // Are the INS (Insert Bit Field) and ROTR instructions supported?
1624 bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001625
1626 switch (type) {
1627 case Primitive::kPrimInt: {
1628 Register dst = locations->Out().AsRegister<Register>();
1629 Register lhs = locations->InAt(0).AsRegister<Register>();
1630 if (use_imm) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001631 if (shift_value == 0) {
1632 if (dst != lhs) {
1633 __ Move(dst, lhs);
1634 }
1635 } else if (instr->IsShl()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001636 __ Sll(dst, lhs, shift_value);
1637 } else if (instr->IsShr()) {
1638 __ Sra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001639 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001640 __ Srl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001641 } else {
1642 if (has_ins_rotr) {
1643 __ Rotr(dst, lhs, shift_value);
1644 } else {
1645 __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask);
1646 __ Srl(dst, lhs, shift_value);
1647 __ Or(dst, dst, TMP);
1648 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001649 }
1650 } else {
1651 if (instr->IsShl()) {
1652 __ Sllv(dst, lhs, rhs_reg);
1653 } else if (instr->IsShr()) {
1654 __ Srav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001655 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001656 __ Srlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001657 } else {
1658 if (has_ins_rotr) {
1659 __ Rotrv(dst, lhs, rhs_reg);
1660 } else {
1661 __ Subu(TMP, ZERO, rhs_reg);
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001662 // 32-bit shift instructions use the 5 least significant bits of the shift count, so
1663 // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case
1664 // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out
1665 // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`,
1666 // IOW, the OR'd values are equal.
Alexey Frunze92d90602015-12-18 18:16:36 -08001667 __ Sllv(TMP, lhs, TMP);
1668 __ Srlv(dst, lhs, rhs_reg);
1669 __ Or(dst, dst, TMP);
1670 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001671 }
1672 }
1673 break;
1674 }
1675
1676 case Primitive::kPrimLong: {
1677 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
1678 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
1679 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
1680 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
1681 if (use_imm) {
1682 if (shift_value == 0) {
1683 codegen_->Move64(locations->Out(), locations->InAt(0));
1684 } else if (shift_value < kMipsBitsPerWord) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001685 if (has_ins_rotr) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001686 if (instr->IsShl()) {
1687 __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value);
1688 __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value);
1689 __ Sll(dst_low, lhs_low, shift_value);
1690 } else if (instr->IsShr()) {
1691 __ Srl(dst_low, lhs_low, shift_value);
1692 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1693 __ Sra(dst_high, lhs_high, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001694 } else if (instr->IsUShr()) {
1695 __ Srl(dst_low, lhs_low, shift_value);
1696 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1697 __ Srl(dst_high, lhs_high, shift_value);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001698 } else {
1699 __ Srl(dst_low, lhs_low, shift_value);
1700 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1701 __ Srl(dst_high, lhs_high, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001702 __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001703 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001704 } else {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001705 if (instr->IsShl()) {
1706 __ Sll(dst_low, lhs_low, shift_value);
1707 __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value);
1708 __ Sll(dst_high, lhs_high, shift_value);
1709 __ Or(dst_high, dst_high, TMP);
1710 } else if (instr->IsShr()) {
1711 __ Sra(dst_high, lhs_high, shift_value);
1712 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value);
1713 __ Srl(dst_low, lhs_low, shift_value);
1714 __ Or(dst_low, dst_low, TMP);
Alexey Frunze92d90602015-12-18 18:16:36 -08001715 } else if (instr->IsUShr()) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001716 __ Srl(dst_high, lhs_high, shift_value);
1717 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value);
1718 __ Srl(dst_low, lhs_low, shift_value);
1719 __ Or(dst_low, dst_low, TMP);
Alexey Frunze92d90602015-12-18 18:16:36 -08001720 } else {
1721 __ Srl(TMP, lhs_low, shift_value);
1722 __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value);
1723 __ Or(dst_low, dst_low, TMP);
1724 __ Srl(TMP, lhs_high, shift_value);
1725 __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value);
1726 __ Or(dst_high, dst_high, TMP);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001727 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001728 }
1729 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001730 const uint32_t shift_value_high = shift_value - kMipsBitsPerWord;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001731 if (instr->IsShl()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001732 __ Sll(dst_high, lhs_low, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001733 __ Move(dst_low, ZERO);
1734 } else if (instr->IsShr()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001735 __ Sra(dst_low, lhs_high, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001736 __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1);
Alexey Frunze92d90602015-12-18 18:16:36 -08001737 } else if (instr->IsUShr()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001738 __ Srl(dst_low, lhs_high, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001739 __ Move(dst_high, ZERO);
Alexey Frunze92d90602015-12-18 18:16:36 -08001740 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001741 if (shift_value == kMipsBitsPerWord) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001742 // 64-bit rotation by 32 is just a swap.
1743 __ Move(dst_low, lhs_high);
1744 __ Move(dst_high, lhs_low);
1745 } else {
1746 if (has_ins_rotr) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001747 __ Srl(dst_low, lhs_high, shift_value_high);
1748 __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high);
1749 __ Srl(dst_high, lhs_low, shift_value_high);
1750 __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001751 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001752 __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high);
1753 __ Srl(dst_low, lhs_high, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001754 __ Or(dst_low, dst_low, TMP);
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001755 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high);
1756 __ Srl(dst_high, lhs_low, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001757 __ Or(dst_high, dst_high, TMP);
1758 }
1759 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001760 }
1761 }
1762 } else {
1763 MipsLabel done;
1764 if (instr->IsShl()) {
1765 __ Sllv(dst_low, lhs_low, rhs_reg);
1766 __ Nor(AT, ZERO, rhs_reg);
1767 __ Srl(TMP, lhs_low, 1);
1768 __ Srlv(TMP, TMP, AT);
1769 __ Sllv(dst_high, lhs_high, rhs_reg);
1770 __ Or(dst_high, dst_high, TMP);
1771 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1772 __ Beqz(TMP, &done);
1773 __ Move(dst_high, dst_low);
1774 __ Move(dst_low, ZERO);
1775 } else if (instr->IsShr()) {
1776 __ Srav(dst_high, lhs_high, rhs_reg);
1777 __ Nor(AT, ZERO, rhs_reg);
1778 __ Sll(TMP, lhs_high, 1);
1779 __ Sllv(TMP, TMP, AT);
1780 __ Srlv(dst_low, lhs_low, rhs_reg);
1781 __ Or(dst_low, dst_low, TMP);
1782 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1783 __ Beqz(TMP, &done);
1784 __ Move(dst_low, dst_high);
1785 __ Sra(dst_high, dst_high, 31);
Alexey Frunze92d90602015-12-18 18:16:36 -08001786 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001787 __ Srlv(dst_high, lhs_high, rhs_reg);
1788 __ Nor(AT, ZERO, rhs_reg);
1789 __ Sll(TMP, lhs_high, 1);
1790 __ Sllv(TMP, TMP, AT);
1791 __ Srlv(dst_low, lhs_low, rhs_reg);
1792 __ Or(dst_low, dst_low, TMP);
1793 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1794 __ Beqz(TMP, &done);
1795 __ Move(dst_low, dst_high);
1796 __ Move(dst_high, ZERO);
Alexey Frunze92d90602015-12-18 18:16:36 -08001797 } else {
1798 __ Nor(AT, ZERO, rhs_reg);
1799 __ Srlv(TMP, lhs_low, rhs_reg);
1800 __ Sll(dst_low, lhs_high, 1);
1801 __ Sllv(dst_low, dst_low, AT);
1802 __ Or(dst_low, dst_low, TMP);
1803 __ Srlv(TMP, lhs_high, rhs_reg);
1804 __ Sll(dst_high, lhs_low, 1);
1805 __ Sllv(dst_high, dst_high, AT);
1806 __ Or(dst_high, dst_high, TMP);
1807 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1808 __ Beqz(TMP, &done);
1809 __ Move(TMP, dst_high);
1810 __ Move(dst_high, dst_low);
1811 __ Move(dst_low, TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001812 }
1813 __ Bind(&done);
1814 }
1815 break;
1816 }
1817
1818 default:
1819 LOG(FATAL) << "Unexpected shift operation type " << type;
1820 }
1821}
1822
1823void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) {
1824 HandleBinaryOp(instruction);
1825}
1826
1827void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) {
1828 HandleBinaryOp(instruction);
1829}
1830
1831void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) {
1832 HandleBinaryOp(instruction);
1833}
1834
1835void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) {
1836 HandleBinaryOp(instruction);
1837}
1838
1839void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) {
1840 LocationSummary* locations =
1841 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1842 locations->SetInAt(0, Location::RequiresRegister());
1843 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1844 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1845 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1846 } else {
1847 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1848 }
1849}
1850
Alexey Frunze2923db72016-08-20 01:55:47 -07001851auto InstructionCodeGeneratorMIPS::GetImplicitNullChecker(HInstruction* instruction) {
1852 auto null_checker = [this, instruction]() {
1853 this->codegen_->MaybeRecordImplicitNullCheck(instruction);
1854 };
1855 return null_checker;
1856}
1857
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001858void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) {
1859 LocationSummary* locations = instruction->GetLocations();
1860 Register obj = locations->InAt(0).AsRegister<Register>();
1861 Location index = locations->InAt(1);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01001862 uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction);
Alexey Frunze2923db72016-08-20 01:55:47 -07001863 auto null_checker = GetImplicitNullChecker(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001864
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01001865 Primitive::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001866 switch (type) {
1867 case Primitive::kPrimBoolean: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001868 Register out = locations->Out().AsRegister<Register>();
1869 if (index.IsConstant()) {
1870 size_t offset =
1871 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001872 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001873 } else {
1874 __ Addu(TMP, obj, index.AsRegister<Register>());
Alexey Frunze2923db72016-08-20 01:55:47 -07001875 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001876 }
1877 break;
1878 }
1879
1880 case Primitive::kPrimByte: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001881 Register out = locations->Out().AsRegister<Register>();
1882 if (index.IsConstant()) {
1883 size_t offset =
1884 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001885 __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001886 } else {
1887 __ Addu(TMP, obj, index.AsRegister<Register>());
Alexey Frunze2923db72016-08-20 01:55:47 -07001888 __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001889 }
1890 break;
1891 }
1892
1893 case Primitive::kPrimShort: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001894 Register out = locations->Out().AsRegister<Register>();
1895 if (index.IsConstant()) {
1896 size_t offset =
1897 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001898 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001899 } else {
1900 __ Sll(TMP, index.AsRegister<Register>(), TIMES_2);
1901 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001902 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001903 }
1904 break;
1905 }
1906
1907 case Primitive::kPrimChar: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001908 Register out = locations->Out().AsRegister<Register>();
1909 if (index.IsConstant()) {
1910 size_t offset =
1911 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001912 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001913 } else {
1914 __ Sll(TMP, index.AsRegister<Register>(), TIMES_2);
1915 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001916 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001917 }
1918 break;
1919 }
1920
1921 case Primitive::kPrimInt:
1922 case Primitive::kPrimNot: {
1923 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001924 Register out = locations->Out().AsRegister<Register>();
1925 if (index.IsConstant()) {
1926 size_t offset =
1927 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001928 __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001929 } else {
1930 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
1931 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001932 __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001933 }
1934 break;
1935 }
1936
1937 case Primitive::kPrimLong: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001938 Register out = locations->Out().AsRegisterPairLow<Register>();
1939 if (index.IsConstant()) {
1940 size_t offset =
1941 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001942 __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001943 } else {
1944 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
1945 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001946 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001947 }
1948 break;
1949 }
1950
1951 case Primitive::kPrimFloat: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001952 FRegister out = locations->Out().AsFpuRegister<FRegister>();
1953 if (index.IsConstant()) {
1954 size_t offset =
1955 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001956 __ LoadSFromOffset(out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001957 } else {
1958 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
1959 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001960 __ LoadSFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001961 }
1962 break;
1963 }
1964
1965 case Primitive::kPrimDouble: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001966 FRegister out = locations->Out().AsFpuRegister<FRegister>();
1967 if (index.IsConstant()) {
1968 size_t offset =
1969 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001970 __ LoadDFromOffset(out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001971 } else {
1972 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
1973 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001974 __ LoadDFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001975 }
1976 break;
1977 }
1978
1979 case Primitive::kPrimVoid:
1980 LOG(FATAL) << "Unreachable type " << instruction->GetType();
1981 UNREACHABLE();
1982 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001983}
1984
1985void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) {
1986 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1987 locations->SetInAt(0, Location::RequiresRegister());
1988 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1989}
1990
1991void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) {
1992 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01001993 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001994 Register obj = locations->InAt(0).AsRegister<Register>();
1995 Register out = locations->Out().AsRegister<Register>();
1996 __ LoadFromOffset(kLoadWord, out, obj, offset);
1997 codegen_->MaybeRecordImplicitNullCheck(instruction);
1998}
1999
2000void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) {
Pavle Batuta934808f2015-11-03 13:23:54 +01002001 bool needs_runtime_call = instruction->NeedsTypeCheck();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002002 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
2003 instruction,
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002004 needs_runtime_call ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall);
Pavle Batuta934808f2015-11-03 13:23:54 +01002005 if (needs_runtime_call) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002006 InvokeRuntimeCallingConvention calling_convention;
2007 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2008 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2009 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2010 } else {
2011 locations->SetInAt(0, Location::RequiresRegister());
2012 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2013 if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
2014 locations->SetInAt(2, Location::RequiresFpuRegister());
2015 } else {
2016 locations->SetInAt(2, Location::RequiresRegister());
2017 }
2018 }
2019}
2020
2021void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) {
2022 LocationSummary* locations = instruction->GetLocations();
2023 Register obj = locations->InAt(0).AsRegister<Register>();
2024 Location index = locations->InAt(1);
2025 Primitive::Type value_type = instruction->GetComponentType();
2026 bool needs_runtime_call = locations->WillCall();
2027 bool needs_write_barrier =
2028 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Alexey Frunze2923db72016-08-20 01:55:47 -07002029 auto null_checker = GetImplicitNullChecker(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002030
2031 switch (value_type) {
2032 case Primitive::kPrimBoolean:
2033 case Primitive::kPrimByte: {
2034 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
2035 Register value = locations->InAt(2).AsRegister<Register>();
2036 if (index.IsConstant()) {
2037 size_t offset =
2038 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002039 __ StoreToOffset(kStoreByte, value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002040 } else {
2041 __ Addu(TMP, obj, index.AsRegister<Register>());
Alexey Frunze2923db72016-08-20 01:55:47 -07002042 __ StoreToOffset(kStoreByte, value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002043 }
2044 break;
2045 }
2046
2047 case Primitive::kPrimShort:
2048 case Primitive::kPrimChar: {
2049 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
2050 Register value = locations->InAt(2).AsRegister<Register>();
2051 if (index.IsConstant()) {
2052 size_t offset =
2053 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002054 __ StoreToOffset(kStoreHalfword, value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002055 } else {
2056 __ Sll(TMP, index.AsRegister<Register>(), TIMES_2);
2057 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002058 __ StoreToOffset(kStoreHalfword, value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002059 }
2060 break;
2061 }
2062
2063 case Primitive::kPrimInt:
2064 case Primitive::kPrimNot: {
2065 if (!needs_runtime_call) {
2066 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
2067 Register value = locations->InAt(2).AsRegister<Register>();
2068 if (index.IsConstant()) {
2069 size_t offset =
2070 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002071 __ StoreToOffset(kStoreWord, value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002072 } else {
2073 DCHECK(index.IsRegister()) << index;
2074 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
2075 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002076 __ StoreToOffset(kStoreWord, value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002077 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002078 if (needs_write_barrier) {
2079 DCHECK_EQ(value_type, Primitive::kPrimNot);
2080 codegen_->MarkGCCard(obj, value);
2081 }
2082 } else {
2083 DCHECK_EQ(value_type, Primitive::kPrimNot);
2084 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
2085 instruction,
2086 instruction->GetDexPc(),
2087 nullptr,
2088 IsDirectEntrypoint(kQuickAputObject));
2089 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
2090 }
2091 break;
2092 }
2093
2094 case Primitive::kPrimLong: {
2095 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
2096 Register value = locations->InAt(2).AsRegisterPairLow<Register>();
2097 if (index.IsConstant()) {
2098 size_t offset =
2099 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002100 __ StoreToOffset(kStoreDoubleword, value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002101 } else {
2102 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
2103 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002104 __ StoreToOffset(kStoreDoubleword, value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002105 }
2106 break;
2107 }
2108
2109 case Primitive::kPrimFloat: {
2110 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
2111 FRegister value = locations->InAt(2).AsFpuRegister<FRegister>();
2112 DCHECK(locations->InAt(2).IsFpuRegister());
2113 if (index.IsConstant()) {
2114 size_t offset =
2115 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002116 __ StoreSToOffset(value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002117 } else {
2118 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
2119 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002120 __ StoreSToOffset(value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002121 }
2122 break;
2123 }
2124
2125 case Primitive::kPrimDouble: {
2126 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
2127 FRegister value = locations->InAt(2).AsFpuRegister<FRegister>();
2128 DCHECK(locations->InAt(2).IsFpuRegister());
2129 if (index.IsConstant()) {
2130 size_t offset =
2131 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002132 __ StoreDToOffset(value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002133 } else {
2134 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
2135 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002136 __ StoreDToOffset(value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002137 }
2138 break;
2139 }
2140
2141 case Primitive::kPrimVoid:
2142 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2143 UNREACHABLE();
2144 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002145}
2146
2147void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) {
2148 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
2149 ? LocationSummary::kCallOnSlowPath
2150 : LocationSummary::kNoCall;
2151 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
2152 locations->SetInAt(0, Location::RequiresRegister());
2153 locations->SetInAt(1, Location::RequiresRegister());
2154 if (instruction->HasUses()) {
2155 locations->SetOut(Location::SameAsFirstInput());
2156 }
2157}
2158
2159void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) {
2160 LocationSummary* locations = instruction->GetLocations();
2161 BoundsCheckSlowPathMIPS* slow_path =
2162 new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS(instruction);
2163 codegen_->AddSlowPath(slow_path);
2164
2165 Register index = locations->InAt(0).AsRegister<Register>();
2166 Register length = locations->InAt(1).AsRegister<Register>();
2167
2168 // length is limited by the maximum positive signed 32-bit integer.
2169 // Unsigned comparison of length and index checks for index < 0
2170 // and for length <= index simultaneously.
2171 __ Bgeu(index, length, slow_path->GetEntryLabel());
2172}
2173
2174void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) {
2175 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
2176 instruction,
2177 LocationSummary::kCallOnSlowPath);
2178 locations->SetInAt(0, Location::RequiresRegister());
2179 locations->SetInAt(1, Location::RequiresRegister());
2180 // Note that TypeCheckSlowPathMIPS uses this register too.
2181 locations->AddTemp(Location::RequiresRegister());
2182}
2183
2184void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) {
2185 LocationSummary* locations = instruction->GetLocations();
2186 Register obj = locations->InAt(0).AsRegister<Register>();
2187 Register cls = locations->InAt(1).AsRegister<Register>();
2188 Register obj_cls = locations->GetTemp(0).AsRegister<Register>();
2189
2190 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction);
2191 codegen_->AddSlowPath(slow_path);
2192
2193 // TODO: avoid this check if we know obj is not null.
2194 __ Beqz(obj, slow_path->GetExitLabel());
2195 // Compare the class of `obj` with `cls`.
2196 __ LoadFromOffset(kLoadWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value());
2197 __ Bne(obj_cls, cls, slow_path->GetEntryLabel());
2198 __ Bind(slow_path->GetExitLabel());
2199}
2200
2201void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) {
2202 LocationSummary* locations =
2203 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2204 locations->SetInAt(0, Location::RequiresRegister());
2205 if (check->HasUses()) {
2206 locations->SetOut(Location::SameAsFirstInput());
2207 }
2208}
2209
2210void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) {
2211 // We assume the class is not null.
2212 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS(
2213 check->GetLoadClass(),
2214 check,
2215 check->GetDexPc(),
2216 true);
2217 codegen_->AddSlowPath(slow_path);
2218 GenerateClassInitializationCheck(slow_path,
2219 check->GetLocations()->InAt(0).AsRegister<Register>());
2220}
2221
2222void LocationsBuilderMIPS::VisitCompare(HCompare* compare) {
2223 Primitive::Type in_type = compare->InputAt(0)->GetType();
2224
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002225 LocationSummary* locations =
2226 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002227
2228 switch (in_type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00002229 case Primitive::kPrimBoolean:
2230 case Primitive::kPrimByte:
2231 case Primitive::kPrimShort:
2232 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08002233 case Primitive::kPrimInt:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002234 case Primitive::kPrimLong:
2235 locations->SetInAt(0, Location::RequiresRegister());
2236 locations->SetInAt(1, Location::RequiresRegister());
2237 // Output overlaps because it is written before doing the low comparison.
2238 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
2239 break;
2240
2241 case Primitive::kPrimFloat:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002242 case Primitive::kPrimDouble:
2243 locations->SetInAt(0, Location::RequiresFpuRegister());
2244 locations->SetInAt(1, Location::RequiresFpuRegister());
2245 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002246 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002247
2248 default:
2249 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
2250 }
2251}
2252
2253void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) {
2254 LocationSummary* locations = instruction->GetLocations();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002255 Register res = locations->Out().AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002256 Primitive::Type in_type = instruction->InputAt(0)->GetType();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002257 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002258
2259 // 0 if: left == right
2260 // 1 if: left > right
2261 // -1 if: left < right
2262 switch (in_type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00002263 case Primitive::kPrimBoolean:
2264 case Primitive::kPrimByte:
2265 case Primitive::kPrimShort:
2266 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08002267 case Primitive::kPrimInt: {
2268 Register lhs = locations->InAt(0).AsRegister<Register>();
2269 Register rhs = locations->InAt(1).AsRegister<Register>();
2270 __ Slt(TMP, lhs, rhs);
2271 __ Slt(res, rhs, lhs);
2272 __ Subu(res, res, TMP);
2273 break;
2274 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002275 case Primitive::kPrimLong: {
2276 MipsLabel done;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002277 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
2278 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
2279 Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>();
2280 Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>();
2281 // TODO: more efficient (direct) comparison with a constant.
2282 __ Slt(TMP, lhs_high, rhs_high);
2283 __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt.
2284 __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ].
2285 __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal.
2286 __ Sltu(TMP, lhs_low, rhs_low);
2287 __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt.
2288 __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ].
2289 __ Bind(&done);
2290 break;
2291 }
2292
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002293 case Primitive::kPrimFloat: {
Roland Levillain32ca3752016-02-17 16:49:37 +00002294 bool gt_bias = instruction->IsGtBias();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002295 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2296 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2297 MipsLabel done;
2298 if (isR6) {
2299 __ CmpEqS(FTMP, lhs, rhs);
2300 __ LoadConst32(res, 0);
2301 __ Bc1nez(FTMP, &done);
2302 if (gt_bias) {
2303 __ CmpLtS(FTMP, lhs, rhs);
2304 __ LoadConst32(res, -1);
2305 __ Bc1nez(FTMP, &done);
2306 __ LoadConst32(res, 1);
2307 } else {
2308 __ CmpLtS(FTMP, rhs, lhs);
2309 __ LoadConst32(res, 1);
2310 __ Bc1nez(FTMP, &done);
2311 __ LoadConst32(res, -1);
2312 }
2313 } else {
2314 if (gt_bias) {
2315 __ ColtS(0, lhs, rhs);
2316 __ LoadConst32(res, -1);
2317 __ Bc1t(0, &done);
2318 __ CeqS(0, lhs, rhs);
2319 __ LoadConst32(res, 1);
2320 __ Movt(res, ZERO, 0);
2321 } else {
2322 __ ColtS(0, rhs, lhs);
2323 __ LoadConst32(res, 1);
2324 __ Bc1t(0, &done);
2325 __ CeqS(0, lhs, rhs);
2326 __ LoadConst32(res, -1);
2327 __ Movt(res, ZERO, 0);
2328 }
2329 }
2330 __ Bind(&done);
2331 break;
2332 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002333 case Primitive::kPrimDouble: {
Roland Levillain32ca3752016-02-17 16:49:37 +00002334 bool gt_bias = instruction->IsGtBias();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002335 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2336 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2337 MipsLabel done;
2338 if (isR6) {
2339 __ CmpEqD(FTMP, lhs, rhs);
2340 __ LoadConst32(res, 0);
2341 __ Bc1nez(FTMP, &done);
2342 if (gt_bias) {
2343 __ CmpLtD(FTMP, lhs, rhs);
2344 __ LoadConst32(res, -1);
2345 __ Bc1nez(FTMP, &done);
2346 __ LoadConst32(res, 1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002347 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002348 __ CmpLtD(FTMP, rhs, lhs);
2349 __ LoadConst32(res, 1);
2350 __ Bc1nez(FTMP, &done);
2351 __ LoadConst32(res, -1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002352 }
2353 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002354 if (gt_bias) {
2355 __ ColtD(0, lhs, rhs);
2356 __ LoadConst32(res, -1);
2357 __ Bc1t(0, &done);
2358 __ CeqD(0, lhs, rhs);
2359 __ LoadConst32(res, 1);
2360 __ Movt(res, ZERO, 0);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002361 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002362 __ ColtD(0, rhs, lhs);
2363 __ LoadConst32(res, 1);
2364 __ Bc1t(0, &done);
2365 __ CeqD(0, lhs, rhs);
2366 __ LoadConst32(res, -1);
2367 __ Movt(res, ZERO, 0);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002368 }
2369 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002370 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002371 break;
2372 }
2373
2374 default:
2375 LOG(FATAL) << "Unimplemented compare type " << in_type;
2376 }
2377}
2378
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002379void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002380 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002381 switch (instruction->InputAt(0)->GetType()) {
2382 default:
2383 case Primitive::kPrimLong:
2384 locations->SetInAt(0, Location::RequiresRegister());
2385 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2386 break;
2387
2388 case Primitive::kPrimFloat:
2389 case Primitive::kPrimDouble:
2390 locations->SetInAt(0, Location::RequiresFpuRegister());
2391 locations->SetInAt(1, Location::RequiresFpuRegister());
2392 break;
2393 }
David Brazdilb3e773e2016-01-26 11:28:37 +00002394 if (!instruction->IsEmittedAtUseSite()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002395 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2396 }
2397}
2398
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002399void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) {
David Brazdilb3e773e2016-01-26 11:28:37 +00002400 if (instruction->IsEmittedAtUseSite()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002401 return;
2402 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002403
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002404 Primitive::Type type = instruction->InputAt(0)->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002405 LocationSummary* locations = instruction->GetLocations();
2406 Register dst = locations->Out().AsRegister<Register>();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002407 MipsLabel true_label;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002408
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002409 switch (type) {
2410 default:
2411 // Integer case.
2412 GenerateIntCompare(instruction->GetCondition(), locations);
2413 return;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002414
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002415 case Primitive::kPrimLong:
2416 // TODO: don't use branches.
2417 GenerateLongCompareAndBranch(instruction->GetCondition(), locations, &true_label);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002418 break;
2419
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002420 case Primitive::kPrimFloat:
2421 case Primitive::kPrimDouble:
2422 // TODO: don't use branches.
2423 GenerateFpCompareAndBranch(instruction->GetCondition(),
2424 instruction->IsGtBias(),
2425 type,
2426 locations,
2427 &true_label);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002428 break;
2429 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002430
2431 // Convert the branches into the result.
2432 MipsLabel done;
2433
2434 // False case: result = 0.
2435 __ LoadConst32(dst, 0);
2436 __ B(&done);
2437
2438 // True case: result = 1.
2439 __ Bind(&true_label);
2440 __ LoadConst32(dst, 1);
2441 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002442}
2443
Alexey Frunze7e99e052015-11-24 19:28:01 -08002444void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2445 DCHECK(instruction->IsDiv() || instruction->IsRem());
2446 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2447
2448 LocationSummary* locations = instruction->GetLocations();
2449 Location second = locations->InAt(1);
2450 DCHECK(second.IsConstant());
2451
2452 Register out = locations->Out().AsRegister<Register>();
2453 Register dividend = locations->InAt(0).AsRegister<Register>();
2454 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2455 DCHECK(imm == 1 || imm == -1);
2456
2457 if (instruction->IsRem()) {
2458 __ Move(out, ZERO);
2459 } else {
2460 if (imm == -1) {
2461 __ Subu(out, ZERO, dividend);
2462 } else if (out != dividend) {
2463 __ Move(out, dividend);
2464 }
2465 }
2466}
2467
2468void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2469 DCHECK(instruction->IsDiv() || instruction->IsRem());
2470 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2471
2472 LocationSummary* locations = instruction->GetLocations();
2473 Location second = locations->InAt(1);
2474 DCHECK(second.IsConstant());
2475
2476 Register out = locations->Out().AsRegister<Register>();
2477 Register dividend = locations->InAt(0).AsRegister<Register>();
2478 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002479 uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm));
Alexey Frunze7e99e052015-11-24 19:28:01 -08002480 int ctz_imm = CTZ(abs_imm);
2481
2482 if (instruction->IsDiv()) {
2483 if (ctz_imm == 1) {
2484 // Fast path for division by +/-2, which is very common.
2485 __ Srl(TMP, dividend, 31);
2486 } else {
2487 __ Sra(TMP, dividend, 31);
2488 __ Srl(TMP, TMP, 32 - ctz_imm);
2489 }
2490 __ Addu(out, dividend, TMP);
2491 __ Sra(out, out, ctz_imm);
2492 if (imm < 0) {
2493 __ Subu(out, ZERO, out);
2494 }
2495 } else {
2496 if (ctz_imm == 1) {
2497 // Fast path for modulo +/-2, which is very common.
2498 __ Sra(TMP, dividend, 31);
2499 __ Subu(out, dividend, TMP);
2500 __ Andi(out, out, 1);
2501 __ Addu(out, out, TMP);
2502 } else {
2503 __ Sra(TMP, dividend, 31);
2504 __ Srl(TMP, TMP, 32 - ctz_imm);
2505 __ Addu(out, dividend, TMP);
2506 if (IsUint<16>(abs_imm - 1)) {
2507 __ Andi(out, out, abs_imm - 1);
2508 } else {
2509 __ Sll(out, out, 32 - ctz_imm);
2510 __ Srl(out, out, 32 - ctz_imm);
2511 }
2512 __ Subu(out, out, TMP);
2513 }
2514 }
2515}
2516
2517void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2518 DCHECK(instruction->IsDiv() || instruction->IsRem());
2519 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2520
2521 LocationSummary* locations = instruction->GetLocations();
2522 Location second = locations->InAt(1);
2523 DCHECK(second.IsConstant());
2524
2525 Register out = locations->Out().AsRegister<Register>();
2526 Register dividend = locations->InAt(0).AsRegister<Register>();
2527 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2528
2529 int64_t magic;
2530 int shift;
2531 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2532
2533 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
2534
2535 __ LoadConst32(TMP, magic);
2536 if (isR6) {
2537 __ MuhR6(TMP, dividend, TMP);
2538 } else {
2539 __ MultR2(dividend, TMP);
2540 __ Mfhi(TMP);
2541 }
2542 if (imm > 0 && magic < 0) {
2543 __ Addu(TMP, TMP, dividend);
2544 } else if (imm < 0 && magic > 0) {
2545 __ Subu(TMP, TMP, dividend);
2546 }
2547
2548 if (shift != 0) {
2549 __ Sra(TMP, TMP, shift);
2550 }
2551
2552 if (instruction->IsDiv()) {
2553 __ Sra(out, TMP, 31);
2554 __ Subu(out, TMP, out);
2555 } else {
2556 __ Sra(AT, TMP, 31);
2557 __ Subu(AT, TMP, AT);
2558 __ LoadConst32(TMP, imm);
2559 if (isR6) {
2560 __ MulR6(TMP, AT, TMP);
2561 } else {
2562 __ MulR2(TMP, AT, TMP);
2563 }
2564 __ Subu(out, dividend, TMP);
2565 }
2566}
2567
2568void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) {
2569 DCHECK(instruction->IsDiv() || instruction->IsRem());
2570 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2571
2572 LocationSummary* locations = instruction->GetLocations();
2573 Register out = locations->Out().AsRegister<Register>();
2574 Location second = locations->InAt(1);
2575
2576 if (second.IsConstant()) {
2577 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2578 if (imm == 0) {
2579 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2580 } else if (imm == 1 || imm == -1) {
2581 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002582 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08002583 DivRemByPowerOfTwo(instruction);
2584 } else {
2585 DCHECK(imm <= -2 || imm >= 2);
2586 GenerateDivRemWithAnyConstant(instruction);
2587 }
2588 } else {
2589 Register dividend = locations->InAt(0).AsRegister<Register>();
2590 Register divisor = second.AsRegister<Register>();
2591 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
2592 if (instruction->IsDiv()) {
2593 if (isR6) {
2594 __ DivR6(out, dividend, divisor);
2595 } else {
2596 __ DivR2(out, dividend, divisor);
2597 }
2598 } else {
2599 if (isR6) {
2600 __ ModR6(out, dividend, divisor);
2601 } else {
2602 __ ModR2(out, dividend, divisor);
2603 }
2604 }
2605 }
2606}
2607
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002608void LocationsBuilderMIPS::VisitDiv(HDiv* div) {
2609 Primitive::Type type = div->GetResultType();
2610 LocationSummary::CallKind call_kind = (type == Primitive::kPrimLong)
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002611 ? LocationSummary::kCallOnMainOnly
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002612 : LocationSummary::kNoCall;
2613
2614 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2615
2616 switch (type) {
2617 case Primitive::kPrimInt:
2618 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze7e99e052015-11-24 19:28:01 -08002619 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002620 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2621 break;
2622
2623 case Primitive::kPrimLong: {
2624 InvokeRuntimeCallingConvention calling_convention;
2625 locations->SetInAt(0, Location::RegisterPairLocation(
2626 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2627 locations->SetInAt(1, Location::RegisterPairLocation(
2628 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2629 locations->SetOut(calling_convention.GetReturnLocation(type));
2630 break;
2631 }
2632
2633 case Primitive::kPrimFloat:
2634 case Primitive::kPrimDouble:
2635 locations->SetInAt(0, Location::RequiresFpuRegister());
2636 locations->SetInAt(1, Location::RequiresFpuRegister());
2637 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2638 break;
2639
2640 default:
2641 LOG(FATAL) << "Unexpected div type " << type;
2642 }
2643}
2644
2645void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) {
2646 Primitive::Type type = instruction->GetType();
2647 LocationSummary* locations = instruction->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002648
2649 switch (type) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08002650 case Primitive::kPrimInt:
2651 GenerateDivRemIntegral(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002652 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002653 case Primitive::kPrimLong: {
2654 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv),
2655 instruction,
2656 instruction->GetDexPc(),
2657 nullptr,
2658 IsDirectEntrypoint(kQuickLdiv));
2659 CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>();
2660 break;
2661 }
2662 case Primitive::kPrimFloat:
2663 case Primitive::kPrimDouble: {
2664 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
2665 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2666 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2667 if (type == Primitive::kPrimFloat) {
2668 __ DivS(dst, lhs, rhs);
2669 } else {
2670 __ DivD(dst, lhs, rhs);
2671 }
2672 break;
2673 }
2674 default:
2675 LOG(FATAL) << "Unexpected div type " << type;
2676 }
2677}
2678
2679void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2680 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
2681 ? LocationSummary::kCallOnSlowPath
2682 : LocationSummary::kNoCall;
2683 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
2684 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
2685 if (instruction->HasUses()) {
2686 locations->SetOut(Location::SameAsFirstInput());
2687 }
2688}
2689
2690void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2691 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS(instruction);
2692 codegen_->AddSlowPath(slow_path);
2693 Location value = instruction->GetLocations()->InAt(0);
2694 Primitive::Type type = instruction->GetType();
2695
2696 switch (type) {
Nicolas Geoffraye5671612016-03-16 11:03:54 +00002697 case Primitive::kPrimBoolean:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002698 case Primitive::kPrimByte:
2699 case Primitive::kPrimChar:
2700 case Primitive::kPrimShort:
2701 case Primitive::kPrimInt: {
2702 if (value.IsConstant()) {
2703 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2704 __ B(slow_path->GetEntryLabel());
2705 } else {
2706 // A division by a non-null constant is valid. We don't need to perform
2707 // any check, so simply fall through.
2708 }
2709 } else {
2710 DCHECK(value.IsRegister()) << value;
2711 __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel());
2712 }
2713 break;
2714 }
2715 case Primitive::kPrimLong: {
2716 if (value.IsConstant()) {
2717 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2718 __ B(slow_path->GetEntryLabel());
2719 } else {
2720 // A division by a non-null constant is valid. We don't need to perform
2721 // any check, so simply fall through.
2722 }
2723 } else {
2724 DCHECK(value.IsRegisterPair()) << value;
2725 __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>());
2726 __ Beqz(TMP, slow_path->GetEntryLabel());
2727 }
2728 break;
2729 }
2730 default:
2731 LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck.";
2732 }
2733}
2734
2735void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) {
2736 LocationSummary* locations =
2737 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2738 locations->SetOut(Location::ConstantLocation(constant));
2739}
2740
2741void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) {
2742 // Will be generated at use site.
2743}
2744
2745void LocationsBuilderMIPS::VisitExit(HExit* exit) {
2746 exit->SetLocations(nullptr);
2747}
2748
2749void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
2750}
2751
2752void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) {
2753 LocationSummary* locations =
2754 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2755 locations->SetOut(Location::ConstantLocation(constant));
2756}
2757
2758void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
2759 // Will be generated at use site.
2760}
2761
2762void LocationsBuilderMIPS::VisitGoto(HGoto* got) {
2763 got->SetLocations(nullptr);
2764}
2765
2766void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) {
2767 DCHECK(!successor->IsExitBlock());
2768 HBasicBlock* block = got->GetBlock();
2769 HInstruction* previous = got->GetPrevious();
2770 HLoopInformation* info = block->GetLoopInformation();
2771
2772 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
2773 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
2774 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
2775 return;
2776 }
2777 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
2778 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
2779 }
2780 if (!codegen_->GoesToNextBlock(block, successor)) {
2781 __ B(codegen_->GetLabelOf(successor));
2782 }
2783}
2784
2785void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) {
2786 HandleGoto(got, got->GetSuccessor());
2787}
2788
2789void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) {
2790 try_boundary->SetLocations(nullptr);
2791}
2792
2793void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) {
2794 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
2795 if (!successor->IsExitBlock()) {
2796 HandleGoto(try_boundary, successor);
2797 }
2798}
2799
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002800void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond,
2801 LocationSummary* locations) {
2802 Register dst = locations->Out().AsRegister<Register>();
2803 Register lhs = locations->InAt(0).AsRegister<Register>();
2804 Location rhs_location = locations->InAt(1);
2805 Register rhs_reg = ZERO;
2806 int64_t rhs_imm = 0;
2807 bool use_imm = rhs_location.IsConstant();
2808 if (use_imm) {
2809 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2810 } else {
2811 rhs_reg = rhs_location.AsRegister<Register>();
2812 }
2813
2814 switch (cond) {
2815 case kCondEQ:
2816 case kCondNE:
2817 if (use_imm && IsUint<16>(rhs_imm)) {
2818 __ Xori(dst, lhs, rhs_imm);
2819 } else {
2820 if (use_imm) {
2821 rhs_reg = TMP;
2822 __ LoadConst32(rhs_reg, rhs_imm);
2823 }
2824 __ Xor(dst, lhs, rhs_reg);
2825 }
2826 if (cond == kCondEQ) {
2827 __ Sltiu(dst, dst, 1);
2828 } else {
2829 __ Sltu(dst, ZERO, dst);
2830 }
2831 break;
2832
2833 case kCondLT:
2834 case kCondGE:
2835 if (use_imm && IsInt<16>(rhs_imm)) {
2836 __ Slti(dst, lhs, rhs_imm);
2837 } else {
2838 if (use_imm) {
2839 rhs_reg = TMP;
2840 __ LoadConst32(rhs_reg, rhs_imm);
2841 }
2842 __ Slt(dst, lhs, rhs_reg);
2843 }
2844 if (cond == kCondGE) {
2845 // Simulate lhs >= rhs via !(lhs < rhs) since there's
2846 // only the slt instruction but no sge.
2847 __ Xori(dst, dst, 1);
2848 }
2849 break;
2850
2851 case kCondLE:
2852 case kCondGT:
2853 if (use_imm && IsInt<16>(rhs_imm + 1)) {
2854 // Simulate lhs <= rhs via lhs < rhs + 1.
2855 __ Slti(dst, lhs, rhs_imm + 1);
2856 if (cond == kCondGT) {
2857 // Simulate lhs > rhs via !(lhs <= rhs) since there's
2858 // only the slti instruction but no sgti.
2859 __ Xori(dst, dst, 1);
2860 }
2861 } else {
2862 if (use_imm) {
2863 rhs_reg = TMP;
2864 __ LoadConst32(rhs_reg, rhs_imm);
2865 }
2866 __ Slt(dst, rhs_reg, lhs);
2867 if (cond == kCondLE) {
2868 // Simulate lhs <= rhs via !(rhs < lhs) since there's
2869 // only the slt instruction but no sle.
2870 __ Xori(dst, dst, 1);
2871 }
2872 }
2873 break;
2874
2875 case kCondB:
2876 case kCondAE:
2877 if (use_imm && IsInt<16>(rhs_imm)) {
2878 // Sltiu sign-extends its 16-bit immediate operand before
2879 // the comparison and thus lets us compare directly with
2880 // unsigned values in the ranges [0, 0x7fff] and
2881 // [0xffff8000, 0xffffffff].
2882 __ Sltiu(dst, lhs, rhs_imm);
2883 } else {
2884 if (use_imm) {
2885 rhs_reg = TMP;
2886 __ LoadConst32(rhs_reg, rhs_imm);
2887 }
2888 __ Sltu(dst, lhs, rhs_reg);
2889 }
2890 if (cond == kCondAE) {
2891 // Simulate lhs >= rhs via !(lhs < rhs) since there's
2892 // only the sltu instruction but no sgeu.
2893 __ Xori(dst, dst, 1);
2894 }
2895 break;
2896
2897 case kCondBE:
2898 case kCondA:
2899 if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
2900 // Simulate lhs <= rhs via lhs < rhs + 1.
2901 // Note that this only works if rhs + 1 does not overflow
2902 // to 0, hence the check above.
2903 // Sltiu sign-extends its 16-bit immediate operand before
2904 // the comparison and thus lets us compare directly with
2905 // unsigned values in the ranges [0, 0x7fff] and
2906 // [0xffff8000, 0xffffffff].
2907 __ Sltiu(dst, lhs, rhs_imm + 1);
2908 if (cond == kCondA) {
2909 // Simulate lhs > rhs via !(lhs <= rhs) since there's
2910 // only the sltiu instruction but no sgtiu.
2911 __ Xori(dst, dst, 1);
2912 }
2913 } else {
2914 if (use_imm) {
2915 rhs_reg = TMP;
2916 __ LoadConst32(rhs_reg, rhs_imm);
2917 }
2918 __ Sltu(dst, rhs_reg, lhs);
2919 if (cond == kCondBE) {
2920 // Simulate lhs <= rhs via !(rhs < lhs) since there's
2921 // only the sltu instruction but no sleu.
2922 __ Xori(dst, dst, 1);
2923 }
2924 }
2925 break;
2926 }
2927}
2928
2929void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond,
2930 LocationSummary* locations,
2931 MipsLabel* label) {
2932 Register lhs = locations->InAt(0).AsRegister<Register>();
2933 Location rhs_location = locations->InAt(1);
2934 Register rhs_reg = ZERO;
2935 int32_t rhs_imm = 0;
2936 bool use_imm = rhs_location.IsConstant();
2937 if (use_imm) {
2938 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2939 } else {
2940 rhs_reg = rhs_location.AsRegister<Register>();
2941 }
2942
2943 if (use_imm && rhs_imm == 0) {
2944 switch (cond) {
2945 case kCondEQ:
2946 case kCondBE: // <= 0 if zero
2947 __ Beqz(lhs, label);
2948 break;
2949 case kCondNE:
2950 case kCondA: // > 0 if non-zero
2951 __ Bnez(lhs, label);
2952 break;
2953 case kCondLT:
2954 __ Bltz(lhs, label);
2955 break;
2956 case kCondGE:
2957 __ Bgez(lhs, label);
2958 break;
2959 case kCondLE:
2960 __ Blez(lhs, label);
2961 break;
2962 case kCondGT:
2963 __ Bgtz(lhs, label);
2964 break;
2965 case kCondB: // always false
2966 break;
2967 case kCondAE: // always true
2968 __ B(label);
2969 break;
2970 }
2971 } else {
2972 if (use_imm) {
2973 // TODO: more efficient comparison with 16-bit constants without loading them into TMP.
2974 rhs_reg = TMP;
2975 __ LoadConst32(rhs_reg, rhs_imm);
2976 }
2977 switch (cond) {
2978 case kCondEQ:
2979 __ Beq(lhs, rhs_reg, label);
2980 break;
2981 case kCondNE:
2982 __ Bne(lhs, rhs_reg, label);
2983 break;
2984 case kCondLT:
2985 __ Blt(lhs, rhs_reg, label);
2986 break;
2987 case kCondGE:
2988 __ Bge(lhs, rhs_reg, label);
2989 break;
2990 case kCondLE:
2991 __ Bge(rhs_reg, lhs, label);
2992 break;
2993 case kCondGT:
2994 __ Blt(rhs_reg, lhs, label);
2995 break;
2996 case kCondB:
2997 __ Bltu(lhs, rhs_reg, label);
2998 break;
2999 case kCondAE:
3000 __ Bgeu(lhs, rhs_reg, label);
3001 break;
3002 case kCondBE:
3003 __ Bgeu(rhs_reg, lhs, label);
3004 break;
3005 case kCondA:
3006 __ Bltu(rhs_reg, lhs, label);
3007 break;
3008 }
3009 }
3010}
3011
3012void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond,
3013 LocationSummary* locations,
3014 MipsLabel* label) {
3015 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
3016 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
3017 Location rhs_location = locations->InAt(1);
3018 Register rhs_high = ZERO;
3019 Register rhs_low = ZERO;
3020 int64_t imm = 0;
3021 uint32_t imm_high = 0;
3022 uint32_t imm_low = 0;
3023 bool use_imm = rhs_location.IsConstant();
3024 if (use_imm) {
3025 imm = rhs_location.GetConstant()->AsLongConstant()->GetValue();
3026 imm_high = High32Bits(imm);
3027 imm_low = Low32Bits(imm);
3028 } else {
3029 rhs_high = rhs_location.AsRegisterPairHigh<Register>();
3030 rhs_low = rhs_location.AsRegisterPairLow<Register>();
3031 }
3032
3033 if (use_imm && imm == 0) {
3034 switch (cond) {
3035 case kCondEQ:
3036 case kCondBE: // <= 0 if zero
3037 __ Or(TMP, lhs_high, lhs_low);
3038 __ Beqz(TMP, label);
3039 break;
3040 case kCondNE:
3041 case kCondA: // > 0 if non-zero
3042 __ Or(TMP, lhs_high, lhs_low);
3043 __ Bnez(TMP, label);
3044 break;
3045 case kCondLT:
3046 __ Bltz(lhs_high, label);
3047 break;
3048 case kCondGE:
3049 __ Bgez(lhs_high, label);
3050 break;
3051 case kCondLE:
3052 __ Or(TMP, lhs_high, lhs_low);
3053 __ Sra(AT, lhs_high, 31);
3054 __ Bgeu(AT, TMP, label);
3055 break;
3056 case kCondGT:
3057 __ Or(TMP, lhs_high, lhs_low);
3058 __ Sra(AT, lhs_high, 31);
3059 __ Bltu(AT, TMP, label);
3060 break;
3061 case kCondB: // always false
3062 break;
3063 case kCondAE: // always true
3064 __ B(label);
3065 break;
3066 }
3067 } else if (use_imm) {
3068 // TODO: more efficient comparison with constants without loading them into TMP/AT.
3069 switch (cond) {
3070 case kCondEQ:
3071 __ LoadConst32(TMP, imm_high);
3072 __ Xor(TMP, TMP, lhs_high);
3073 __ LoadConst32(AT, imm_low);
3074 __ Xor(AT, AT, lhs_low);
3075 __ Or(TMP, TMP, AT);
3076 __ Beqz(TMP, label);
3077 break;
3078 case kCondNE:
3079 __ LoadConst32(TMP, imm_high);
3080 __ Xor(TMP, TMP, lhs_high);
3081 __ LoadConst32(AT, imm_low);
3082 __ Xor(AT, AT, lhs_low);
3083 __ Or(TMP, TMP, AT);
3084 __ Bnez(TMP, label);
3085 break;
3086 case kCondLT:
3087 __ LoadConst32(TMP, imm_high);
3088 __ Blt(lhs_high, TMP, label);
3089 __ Slt(TMP, TMP, lhs_high);
3090 __ LoadConst32(AT, imm_low);
3091 __ Sltu(AT, lhs_low, AT);
3092 __ Blt(TMP, AT, label);
3093 break;
3094 case kCondGE:
3095 __ LoadConst32(TMP, imm_high);
3096 __ Blt(TMP, lhs_high, label);
3097 __ Slt(TMP, lhs_high, TMP);
3098 __ LoadConst32(AT, imm_low);
3099 __ Sltu(AT, lhs_low, AT);
3100 __ Or(TMP, TMP, AT);
3101 __ Beqz(TMP, label);
3102 break;
3103 case kCondLE:
3104 __ LoadConst32(TMP, imm_high);
3105 __ Blt(lhs_high, TMP, label);
3106 __ Slt(TMP, TMP, lhs_high);
3107 __ LoadConst32(AT, imm_low);
3108 __ Sltu(AT, AT, lhs_low);
3109 __ Or(TMP, TMP, AT);
3110 __ Beqz(TMP, label);
3111 break;
3112 case kCondGT:
3113 __ LoadConst32(TMP, imm_high);
3114 __ Blt(TMP, lhs_high, label);
3115 __ Slt(TMP, lhs_high, TMP);
3116 __ LoadConst32(AT, imm_low);
3117 __ Sltu(AT, AT, lhs_low);
3118 __ Blt(TMP, AT, label);
3119 break;
3120 case kCondB:
3121 __ LoadConst32(TMP, imm_high);
3122 __ Bltu(lhs_high, TMP, label);
3123 __ Sltu(TMP, TMP, lhs_high);
3124 __ LoadConst32(AT, imm_low);
3125 __ Sltu(AT, lhs_low, AT);
3126 __ Blt(TMP, AT, label);
3127 break;
3128 case kCondAE:
3129 __ LoadConst32(TMP, imm_high);
3130 __ Bltu(TMP, lhs_high, label);
3131 __ Sltu(TMP, lhs_high, TMP);
3132 __ LoadConst32(AT, imm_low);
3133 __ Sltu(AT, lhs_low, AT);
3134 __ Or(TMP, TMP, AT);
3135 __ Beqz(TMP, label);
3136 break;
3137 case kCondBE:
3138 __ LoadConst32(TMP, imm_high);
3139 __ Bltu(lhs_high, TMP, label);
3140 __ Sltu(TMP, TMP, lhs_high);
3141 __ LoadConst32(AT, imm_low);
3142 __ Sltu(AT, AT, lhs_low);
3143 __ Or(TMP, TMP, AT);
3144 __ Beqz(TMP, label);
3145 break;
3146 case kCondA:
3147 __ LoadConst32(TMP, imm_high);
3148 __ Bltu(TMP, lhs_high, label);
3149 __ Sltu(TMP, lhs_high, TMP);
3150 __ LoadConst32(AT, imm_low);
3151 __ Sltu(AT, AT, lhs_low);
3152 __ Blt(TMP, AT, label);
3153 break;
3154 }
3155 } else {
3156 switch (cond) {
3157 case kCondEQ:
3158 __ Xor(TMP, lhs_high, rhs_high);
3159 __ Xor(AT, lhs_low, rhs_low);
3160 __ Or(TMP, TMP, AT);
3161 __ Beqz(TMP, label);
3162 break;
3163 case kCondNE:
3164 __ Xor(TMP, lhs_high, rhs_high);
3165 __ Xor(AT, lhs_low, rhs_low);
3166 __ Or(TMP, TMP, AT);
3167 __ Bnez(TMP, label);
3168 break;
3169 case kCondLT:
3170 __ Blt(lhs_high, rhs_high, label);
3171 __ Slt(TMP, rhs_high, lhs_high);
3172 __ Sltu(AT, lhs_low, rhs_low);
3173 __ Blt(TMP, AT, label);
3174 break;
3175 case kCondGE:
3176 __ Blt(rhs_high, lhs_high, label);
3177 __ Slt(TMP, lhs_high, rhs_high);
3178 __ Sltu(AT, lhs_low, rhs_low);
3179 __ Or(TMP, TMP, AT);
3180 __ Beqz(TMP, label);
3181 break;
3182 case kCondLE:
3183 __ Blt(lhs_high, rhs_high, label);
3184 __ Slt(TMP, rhs_high, lhs_high);
3185 __ Sltu(AT, rhs_low, lhs_low);
3186 __ Or(TMP, TMP, AT);
3187 __ Beqz(TMP, label);
3188 break;
3189 case kCondGT:
3190 __ Blt(rhs_high, lhs_high, label);
3191 __ Slt(TMP, lhs_high, rhs_high);
3192 __ Sltu(AT, rhs_low, lhs_low);
3193 __ Blt(TMP, AT, label);
3194 break;
3195 case kCondB:
3196 __ Bltu(lhs_high, rhs_high, label);
3197 __ Sltu(TMP, rhs_high, lhs_high);
3198 __ Sltu(AT, lhs_low, rhs_low);
3199 __ Blt(TMP, AT, label);
3200 break;
3201 case kCondAE:
3202 __ Bltu(rhs_high, lhs_high, label);
3203 __ Sltu(TMP, lhs_high, rhs_high);
3204 __ Sltu(AT, lhs_low, rhs_low);
3205 __ Or(TMP, TMP, AT);
3206 __ Beqz(TMP, label);
3207 break;
3208 case kCondBE:
3209 __ Bltu(lhs_high, rhs_high, label);
3210 __ Sltu(TMP, rhs_high, lhs_high);
3211 __ Sltu(AT, rhs_low, lhs_low);
3212 __ Or(TMP, TMP, AT);
3213 __ Beqz(TMP, label);
3214 break;
3215 case kCondA:
3216 __ Bltu(rhs_high, lhs_high, label);
3217 __ Sltu(TMP, lhs_high, rhs_high);
3218 __ Sltu(AT, rhs_low, lhs_low);
3219 __ Blt(TMP, AT, label);
3220 break;
3221 }
3222 }
3223}
3224
3225void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond,
3226 bool gt_bias,
3227 Primitive::Type type,
3228 LocationSummary* locations,
3229 MipsLabel* label) {
3230 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
3231 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
3232 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
3233 if (type == Primitive::kPrimFloat) {
3234 if (isR6) {
3235 switch (cond) {
3236 case kCondEQ:
3237 __ CmpEqS(FTMP, lhs, rhs);
3238 __ Bc1nez(FTMP, label);
3239 break;
3240 case kCondNE:
3241 __ CmpEqS(FTMP, lhs, rhs);
3242 __ Bc1eqz(FTMP, label);
3243 break;
3244 case kCondLT:
3245 if (gt_bias) {
3246 __ CmpLtS(FTMP, lhs, rhs);
3247 } else {
3248 __ CmpUltS(FTMP, lhs, rhs);
3249 }
3250 __ Bc1nez(FTMP, label);
3251 break;
3252 case kCondLE:
3253 if (gt_bias) {
3254 __ CmpLeS(FTMP, lhs, rhs);
3255 } else {
3256 __ CmpUleS(FTMP, lhs, rhs);
3257 }
3258 __ Bc1nez(FTMP, label);
3259 break;
3260 case kCondGT:
3261 if (gt_bias) {
3262 __ CmpUltS(FTMP, rhs, lhs);
3263 } else {
3264 __ CmpLtS(FTMP, rhs, lhs);
3265 }
3266 __ Bc1nez(FTMP, label);
3267 break;
3268 case kCondGE:
3269 if (gt_bias) {
3270 __ CmpUleS(FTMP, rhs, lhs);
3271 } else {
3272 __ CmpLeS(FTMP, rhs, lhs);
3273 }
3274 __ Bc1nez(FTMP, label);
3275 break;
3276 default:
3277 LOG(FATAL) << "Unexpected non-floating-point condition";
3278 }
3279 } else {
3280 switch (cond) {
3281 case kCondEQ:
3282 __ CeqS(0, lhs, rhs);
3283 __ Bc1t(0, label);
3284 break;
3285 case kCondNE:
3286 __ CeqS(0, lhs, rhs);
3287 __ Bc1f(0, label);
3288 break;
3289 case kCondLT:
3290 if (gt_bias) {
3291 __ ColtS(0, lhs, rhs);
3292 } else {
3293 __ CultS(0, lhs, rhs);
3294 }
3295 __ Bc1t(0, label);
3296 break;
3297 case kCondLE:
3298 if (gt_bias) {
3299 __ ColeS(0, lhs, rhs);
3300 } else {
3301 __ CuleS(0, lhs, rhs);
3302 }
3303 __ Bc1t(0, label);
3304 break;
3305 case kCondGT:
3306 if (gt_bias) {
3307 __ CultS(0, rhs, lhs);
3308 } else {
3309 __ ColtS(0, rhs, lhs);
3310 }
3311 __ Bc1t(0, label);
3312 break;
3313 case kCondGE:
3314 if (gt_bias) {
3315 __ CuleS(0, rhs, lhs);
3316 } else {
3317 __ ColeS(0, rhs, lhs);
3318 }
3319 __ Bc1t(0, label);
3320 break;
3321 default:
3322 LOG(FATAL) << "Unexpected non-floating-point condition";
3323 }
3324 }
3325 } else {
3326 DCHECK_EQ(type, Primitive::kPrimDouble);
3327 if (isR6) {
3328 switch (cond) {
3329 case kCondEQ:
3330 __ CmpEqD(FTMP, lhs, rhs);
3331 __ Bc1nez(FTMP, label);
3332 break;
3333 case kCondNE:
3334 __ CmpEqD(FTMP, lhs, rhs);
3335 __ Bc1eqz(FTMP, label);
3336 break;
3337 case kCondLT:
3338 if (gt_bias) {
3339 __ CmpLtD(FTMP, lhs, rhs);
3340 } else {
3341 __ CmpUltD(FTMP, lhs, rhs);
3342 }
3343 __ Bc1nez(FTMP, label);
3344 break;
3345 case kCondLE:
3346 if (gt_bias) {
3347 __ CmpLeD(FTMP, lhs, rhs);
3348 } else {
3349 __ CmpUleD(FTMP, lhs, rhs);
3350 }
3351 __ Bc1nez(FTMP, label);
3352 break;
3353 case kCondGT:
3354 if (gt_bias) {
3355 __ CmpUltD(FTMP, rhs, lhs);
3356 } else {
3357 __ CmpLtD(FTMP, rhs, lhs);
3358 }
3359 __ Bc1nez(FTMP, label);
3360 break;
3361 case kCondGE:
3362 if (gt_bias) {
3363 __ CmpUleD(FTMP, rhs, lhs);
3364 } else {
3365 __ CmpLeD(FTMP, rhs, lhs);
3366 }
3367 __ Bc1nez(FTMP, label);
3368 break;
3369 default:
3370 LOG(FATAL) << "Unexpected non-floating-point condition";
3371 }
3372 } else {
3373 switch (cond) {
3374 case kCondEQ:
3375 __ CeqD(0, lhs, rhs);
3376 __ Bc1t(0, label);
3377 break;
3378 case kCondNE:
3379 __ CeqD(0, lhs, rhs);
3380 __ Bc1f(0, label);
3381 break;
3382 case kCondLT:
3383 if (gt_bias) {
3384 __ ColtD(0, lhs, rhs);
3385 } else {
3386 __ CultD(0, lhs, rhs);
3387 }
3388 __ Bc1t(0, label);
3389 break;
3390 case kCondLE:
3391 if (gt_bias) {
3392 __ ColeD(0, lhs, rhs);
3393 } else {
3394 __ CuleD(0, lhs, rhs);
3395 }
3396 __ Bc1t(0, label);
3397 break;
3398 case kCondGT:
3399 if (gt_bias) {
3400 __ CultD(0, rhs, lhs);
3401 } else {
3402 __ ColtD(0, rhs, lhs);
3403 }
3404 __ Bc1t(0, label);
3405 break;
3406 case kCondGE:
3407 if (gt_bias) {
3408 __ CuleD(0, rhs, lhs);
3409 } else {
3410 __ ColeD(0, rhs, lhs);
3411 }
3412 __ Bc1t(0, label);
3413 break;
3414 default:
3415 LOG(FATAL) << "Unexpected non-floating-point condition";
3416 }
3417 }
3418 }
3419}
3420
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003421void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00003422 size_t condition_input_index,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003423 MipsLabel* true_target,
David Brazdil0debae72015-11-12 18:37:00 +00003424 MipsLabel* false_target) {
3425 HInstruction* cond = instruction->InputAt(condition_input_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003426
David Brazdil0debae72015-11-12 18:37:00 +00003427 if (true_target == nullptr && false_target == nullptr) {
3428 // Nothing to do. The code always falls through.
3429 return;
3430 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00003431 // Constant condition, statically compared against "true" (integer value 1).
3432 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00003433 if (true_target != nullptr) {
3434 __ B(true_target);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003435 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003436 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00003437 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00003438 if (false_target != nullptr) {
3439 __ B(false_target);
3440 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003441 }
David Brazdil0debae72015-11-12 18:37:00 +00003442 return;
3443 }
3444
3445 // The following code generates these patterns:
3446 // (1) true_target == nullptr && false_target != nullptr
3447 // - opposite condition true => branch to false_target
3448 // (2) true_target != nullptr && false_target == nullptr
3449 // - condition true => branch to true_target
3450 // (3) true_target != nullptr && false_target != nullptr
3451 // - condition true => branch to true_target
3452 // - branch to false_target
3453 if (IsBooleanValueOrMaterializedCondition(cond)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003454 // The condition instruction has been materialized, compare the output to 0.
David Brazdil0debae72015-11-12 18:37:00 +00003455 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003456 DCHECK(cond_val.IsRegister());
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003457 if (true_target == nullptr) {
David Brazdil0debae72015-11-12 18:37:00 +00003458 __ Beqz(cond_val.AsRegister<Register>(), false_target);
3459 } else {
3460 __ Bnez(cond_val.AsRegister<Register>(), true_target);
3461 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003462 } else {
3463 // The condition instruction has not been materialized, use its inputs as
3464 // the comparison and its condition as the branch condition.
David Brazdil0debae72015-11-12 18:37:00 +00003465 HCondition* condition = cond->AsCondition();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003466 Primitive::Type type = condition->InputAt(0)->GetType();
3467 LocationSummary* locations = cond->GetLocations();
3468 IfCondition if_cond = condition->GetCondition();
3469 MipsLabel* branch_target = true_target;
David Brazdil0debae72015-11-12 18:37:00 +00003470
David Brazdil0debae72015-11-12 18:37:00 +00003471 if (true_target == nullptr) {
3472 if_cond = condition->GetOppositeCondition();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003473 branch_target = false_target;
David Brazdil0debae72015-11-12 18:37:00 +00003474 }
3475
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003476 switch (type) {
3477 default:
3478 GenerateIntCompareAndBranch(if_cond, locations, branch_target);
3479 break;
3480 case Primitive::kPrimLong:
3481 GenerateLongCompareAndBranch(if_cond, locations, branch_target);
3482 break;
3483 case Primitive::kPrimFloat:
3484 case Primitive::kPrimDouble:
3485 GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target);
3486 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003487 }
3488 }
David Brazdil0debae72015-11-12 18:37:00 +00003489
3490 // If neither branch falls through (case 3), the conditional branch to `true_target`
3491 // was already emitted (case 2) and we need to emit a jump to `false_target`.
3492 if (true_target != nullptr && false_target != nullptr) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003493 __ B(false_target);
3494 }
3495}
3496
3497void LocationsBuilderMIPS::VisitIf(HIf* if_instr) {
3498 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
David Brazdil0debae72015-11-12 18:37:00 +00003499 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003500 locations->SetInAt(0, Location::RequiresRegister());
3501 }
3502}
3503
3504void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00003505 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
3506 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
3507 MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
3508 nullptr : codegen_->GetLabelOf(true_successor);
3509 MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
3510 nullptr : codegen_->GetLabelOf(false_successor);
3511 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003512}
3513
3514void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) {
3515 LocationSummary* locations = new (GetGraph()->GetArena())
3516 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
David Brazdil0debae72015-11-12 18:37:00 +00003517 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003518 locations->SetInAt(0, Location::RequiresRegister());
3519 }
3520}
3521
3522void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08003523 SlowPathCodeMIPS* slow_path =
3524 deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00003525 GenerateTestAndBranch(deoptimize,
3526 /* condition_input_index */ 0,
3527 slow_path->GetEntryLabel(),
3528 /* false_target */ nullptr);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003529}
3530
David Brazdil74eb1b22015-12-14 11:44:01 +00003531void LocationsBuilderMIPS::VisitSelect(HSelect* select) {
3532 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select);
3533 if (Primitive::IsFloatingPointType(select->GetType())) {
3534 locations->SetInAt(0, Location::RequiresFpuRegister());
3535 locations->SetInAt(1, Location::RequiresFpuRegister());
3536 } else {
3537 locations->SetInAt(0, Location::RequiresRegister());
3538 locations->SetInAt(1, Location::RequiresRegister());
3539 }
3540 if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) {
3541 locations->SetInAt(2, Location::RequiresRegister());
3542 }
3543 locations->SetOut(Location::SameAsFirstInput());
3544}
3545
3546void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) {
3547 LocationSummary* locations = select->GetLocations();
3548 MipsLabel false_target;
3549 GenerateTestAndBranch(select,
3550 /* condition_input_index */ 2,
3551 /* true_target */ nullptr,
3552 &false_target);
3553 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
3554 __ Bind(&false_target);
3555}
3556
David Srbecky0cf44932015-12-09 14:09:59 +00003557void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) {
3558 new (GetGraph()->GetArena()) LocationSummary(info);
3559}
3560
David Srbeckyd28f4a02016-03-14 17:14:24 +00003561void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) {
3562 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00003563}
3564
3565void CodeGeneratorMIPS::GenerateNop() {
3566 __ Nop();
David Srbecky0cf44932015-12-09 14:09:59 +00003567}
3568
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003569void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3570 Primitive::Type field_type = field_info.GetFieldType();
3571 bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble);
3572 bool generate_volatile = field_info.IsVolatile() && is_wide;
3573 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003574 instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003575
3576 locations->SetInAt(0, Location::RequiresRegister());
3577 if (generate_volatile) {
3578 InvokeRuntimeCallingConvention calling_convention;
3579 // need A0 to hold base + offset
3580 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3581 if (field_type == Primitive::kPrimLong) {
3582 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimLong));
3583 } else {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02003584 // Use Location::Any() to prevent situations when running out of available fp registers.
3585 locations->SetOut(Location::Any());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003586 // Need some temp core regs since FP results are returned in core registers
3587 Location reg = calling_convention.GetReturnLocation(Primitive::kPrimLong);
3588 locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>()));
3589 locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>()));
3590 }
3591 } else {
3592 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3593 locations->SetOut(Location::RequiresFpuRegister());
3594 } else {
3595 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3596 }
3597 }
3598}
3599
3600void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction,
3601 const FieldInfo& field_info,
3602 uint32_t dex_pc) {
3603 Primitive::Type type = field_info.GetFieldType();
3604 LocationSummary* locations = instruction->GetLocations();
3605 Register obj = locations->InAt(0).AsRegister<Register>();
3606 LoadOperandType load_type = kLoadUnsignedByte;
3607 bool is_volatile = field_info.IsVolatile();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003608 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Alexey Frunze2923db72016-08-20 01:55:47 -07003609 auto null_checker = GetImplicitNullChecker(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003610
3611 switch (type) {
3612 case Primitive::kPrimBoolean:
3613 load_type = kLoadUnsignedByte;
3614 break;
3615 case Primitive::kPrimByte:
3616 load_type = kLoadSignedByte;
3617 break;
3618 case Primitive::kPrimShort:
3619 load_type = kLoadSignedHalfword;
3620 break;
3621 case Primitive::kPrimChar:
3622 load_type = kLoadUnsignedHalfword;
3623 break;
3624 case Primitive::kPrimInt:
3625 case Primitive::kPrimFloat:
3626 case Primitive::kPrimNot:
3627 load_type = kLoadWord;
3628 break;
3629 case Primitive::kPrimLong:
3630 case Primitive::kPrimDouble:
3631 load_type = kLoadDoubleword;
3632 break;
3633 case Primitive::kPrimVoid:
3634 LOG(FATAL) << "Unreachable type " << type;
3635 UNREACHABLE();
3636 }
3637
3638 if (is_volatile && load_type == kLoadDoubleword) {
3639 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003640 __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003641 // Do implicit Null check
3642 __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0);
3643 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3644 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pA64Load),
3645 instruction,
3646 dex_pc,
3647 nullptr,
3648 IsDirectEntrypoint(kQuickA64Load));
3649 CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>();
3650 if (type == Primitive::kPrimDouble) {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02003651 // FP results are returned in core registers. Need to move them.
3652 Location out = locations->Out();
3653 if (out.IsFpuRegister()) {
3654 __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), out.AsFpuRegister<FRegister>());
3655 __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(),
3656 out.AsFpuRegister<FRegister>());
3657 } else {
3658 DCHECK(out.IsDoubleStackSlot());
3659 __ StoreToOffset(kStoreWord,
3660 locations->GetTemp(1).AsRegister<Register>(),
3661 SP,
3662 out.GetStackIndex());
3663 __ StoreToOffset(kStoreWord,
3664 locations->GetTemp(2).AsRegister<Register>(),
3665 SP,
3666 out.GetStackIndex() + 4);
3667 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003668 }
3669 } else {
3670 if (!Primitive::IsFloatingPointType(type)) {
3671 Register dst;
3672 if (type == Primitive::kPrimLong) {
3673 DCHECK(locations->Out().IsRegisterPair());
3674 dst = locations->Out().AsRegisterPairLow<Register>();
3675 } else {
3676 DCHECK(locations->Out().IsRegister());
3677 dst = locations->Out().AsRegister<Register>();
3678 }
Alexey Frunze2923db72016-08-20 01:55:47 -07003679 __ LoadFromOffset(load_type, dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003680 } else {
3681 DCHECK(locations->Out().IsFpuRegister());
3682 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
3683 if (type == Primitive::kPrimFloat) {
Alexey Frunze2923db72016-08-20 01:55:47 -07003684 __ LoadSFromOffset(dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003685 } else {
Alexey Frunze2923db72016-08-20 01:55:47 -07003686 __ LoadDFromOffset(dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003687 }
3688 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003689 }
3690
3691 if (is_volatile) {
3692 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3693 }
3694}
3695
3696void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3697 Primitive::Type field_type = field_info.GetFieldType();
3698 bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble);
3699 bool generate_volatile = field_info.IsVolatile() && is_wide;
3700 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003701 instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003702
3703 locations->SetInAt(0, Location::RequiresRegister());
3704 if (generate_volatile) {
3705 InvokeRuntimeCallingConvention calling_convention;
3706 // need A0 to hold base + offset
3707 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3708 if (field_type == Primitive::kPrimLong) {
3709 locations->SetInAt(1, Location::RegisterPairLocation(
3710 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
3711 } else {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02003712 // Use Location::Any() to prevent situations when running out of available fp registers.
3713 locations->SetInAt(1, Location::Any());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003714 // Pass FP parameters in core registers.
3715 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
3716 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3)));
3717 }
3718 } else {
3719 if (Primitive::IsFloatingPointType(field_type)) {
3720 locations->SetInAt(1, Location::RequiresFpuRegister());
3721 } else {
3722 locations->SetInAt(1, Location::RequiresRegister());
3723 }
3724 }
3725}
3726
3727void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction,
3728 const FieldInfo& field_info,
3729 uint32_t dex_pc) {
3730 Primitive::Type type = field_info.GetFieldType();
3731 LocationSummary* locations = instruction->GetLocations();
3732 Register obj = locations->InAt(0).AsRegister<Register>();
3733 StoreOperandType store_type = kStoreByte;
3734 bool is_volatile = field_info.IsVolatile();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003735 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Alexey Frunze2923db72016-08-20 01:55:47 -07003736 auto null_checker = GetImplicitNullChecker(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003737
3738 switch (type) {
3739 case Primitive::kPrimBoolean:
3740 case Primitive::kPrimByte:
3741 store_type = kStoreByte;
3742 break;
3743 case Primitive::kPrimShort:
3744 case Primitive::kPrimChar:
3745 store_type = kStoreHalfword;
3746 break;
3747 case Primitive::kPrimInt:
3748 case Primitive::kPrimFloat:
3749 case Primitive::kPrimNot:
3750 store_type = kStoreWord;
3751 break;
3752 case Primitive::kPrimLong:
3753 case Primitive::kPrimDouble:
3754 store_type = kStoreDoubleword;
3755 break;
3756 case Primitive::kPrimVoid:
3757 LOG(FATAL) << "Unreachable type " << type;
3758 UNREACHABLE();
3759 }
3760
3761 if (is_volatile) {
3762 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3763 }
3764
3765 if (is_volatile && store_type == kStoreDoubleword) {
3766 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003767 __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003768 // Do implicit Null check.
3769 __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0);
3770 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3771 if (type == Primitive::kPrimDouble) {
3772 // Pass FP parameters in core registers.
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02003773 Location in = locations->InAt(1);
3774 if (in.IsFpuRegister()) {
3775 __ Mfc1(locations->GetTemp(1).AsRegister<Register>(), in.AsFpuRegister<FRegister>());
3776 __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(),
3777 in.AsFpuRegister<FRegister>());
3778 } else if (in.IsDoubleStackSlot()) {
3779 __ LoadFromOffset(kLoadWord,
3780 locations->GetTemp(1).AsRegister<Register>(),
3781 SP,
3782 in.GetStackIndex());
3783 __ LoadFromOffset(kLoadWord,
3784 locations->GetTemp(2).AsRegister<Register>(),
3785 SP,
3786 in.GetStackIndex() + 4);
3787 } else {
3788 DCHECK(in.IsConstant());
3789 DCHECK(in.GetConstant()->IsDoubleConstant());
3790 int64_t value = bit_cast<int64_t, double>(in.GetConstant()->AsDoubleConstant()->GetValue());
3791 __ LoadConst64(locations->GetTemp(2).AsRegister<Register>(),
3792 locations->GetTemp(1).AsRegister<Register>(),
3793 value);
3794 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003795 }
3796 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pA64Store),
3797 instruction,
3798 dex_pc,
3799 nullptr,
3800 IsDirectEntrypoint(kQuickA64Store));
3801 CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>();
3802 } else {
3803 if (!Primitive::IsFloatingPointType(type)) {
3804 Register src;
3805 if (type == Primitive::kPrimLong) {
3806 DCHECK(locations->InAt(1).IsRegisterPair());
3807 src = locations->InAt(1).AsRegisterPairLow<Register>();
3808 } else {
3809 DCHECK(locations->InAt(1).IsRegister());
3810 src = locations->InAt(1).AsRegister<Register>();
3811 }
Alexey Frunze2923db72016-08-20 01:55:47 -07003812 __ StoreToOffset(store_type, src, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003813 } else {
3814 DCHECK(locations->InAt(1).IsFpuRegister());
3815 FRegister src = locations->InAt(1).AsFpuRegister<FRegister>();
3816 if (type == Primitive::kPrimFloat) {
Alexey Frunze2923db72016-08-20 01:55:47 -07003817 __ StoreSToOffset(src, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003818 } else {
Alexey Frunze2923db72016-08-20 01:55:47 -07003819 __ StoreDToOffset(src, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003820 }
3821 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003822 }
3823
3824 // TODO: memory barriers?
3825 if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) {
3826 DCHECK(locations->InAt(1).IsRegister());
3827 Register src = locations->InAt(1).AsRegister<Register>();
3828 codegen_->MarkGCCard(obj, src);
3829 }
3830
3831 if (is_volatile) {
3832 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3833 }
3834}
3835
3836void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3837 HandleFieldGet(instruction, instruction->GetFieldInfo());
3838}
3839
3840void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3841 HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
3842}
3843
3844void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3845 HandleFieldSet(instruction, instruction->GetFieldInfo());
3846}
3847
3848void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3849 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
3850}
3851
Alexey Frunze06a46c42016-07-19 15:00:40 -07003852void InstructionCodeGeneratorMIPS::GenerateGcRootFieldLoad(
3853 HInstruction* instruction ATTRIBUTE_UNUSED,
3854 Location root,
3855 Register obj,
3856 uint32_t offset) {
3857 Register root_reg = root.AsRegister<Register>();
3858 if (kEmitCompilerReadBarrier) {
3859 UNIMPLEMENTED(FATAL) << "for read barrier";
3860 } else {
3861 // Plain GC root load with no read barrier.
3862 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
3863 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
3864 // Note that GC roots are not affected by heap poisoning, thus we
3865 // do not have to unpoison `root_reg` here.
3866 }
3867}
3868
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003869void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) {
3870 LocationSummary::CallKind call_kind =
3871 instruction->IsExactCheck() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
3872 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3873 locations->SetInAt(0, Location::RequiresRegister());
3874 locations->SetInAt(1, Location::RequiresRegister());
3875 // The output does overlap inputs.
3876 // Note that TypeCheckSlowPathMIPS uses this register too.
3877 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3878}
3879
3880void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) {
3881 LocationSummary* locations = instruction->GetLocations();
3882 Register obj = locations->InAt(0).AsRegister<Register>();
3883 Register cls = locations->InAt(1).AsRegister<Register>();
3884 Register out = locations->Out().AsRegister<Register>();
3885
3886 MipsLabel done;
3887
3888 // Return 0 if `obj` is null.
3889 // TODO: Avoid this check if we know `obj` is not null.
3890 __ Move(out, ZERO);
3891 __ Beqz(obj, &done);
3892
3893 // Compare the class of `obj` with `cls`.
3894 __ LoadFromOffset(kLoadWord, out, obj, mirror::Object::ClassOffset().Int32Value());
3895 if (instruction->IsExactCheck()) {
3896 // Classes must be equal for the instanceof to succeed.
3897 __ Xor(out, out, cls);
3898 __ Sltiu(out, out, 1);
3899 } else {
3900 // If the classes are not equal, we go into a slow path.
3901 DCHECK(locations->OnlyCallsOnSlowPath());
3902 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction);
3903 codegen_->AddSlowPath(slow_path);
3904 __ Bne(out, cls, slow_path->GetEntryLabel());
3905 __ LoadConst32(out, 1);
3906 __ Bind(slow_path->GetExitLabel());
3907 }
3908
3909 __ Bind(&done);
3910}
3911
3912void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) {
3913 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
3914 locations->SetOut(Location::ConstantLocation(constant));
3915}
3916
3917void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
3918 // Will be generated at use site.
3919}
3920
3921void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) {
3922 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
3923 locations->SetOut(Location::ConstantLocation(constant));
3924}
3925
3926void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
3927 // Will be generated at use site.
3928}
3929
3930void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) {
3931 InvokeDexCallingConventionVisitorMIPS calling_convention_visitor;
3932 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
3933}
3934
3935void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) {
3936 HandleInvoke(invoke);
3937 // The register T0 is required to be used for the hidden argument in
3938 // art_quick_imt_conflict_trampoline, so add the hidden argument.
3939 invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0));
3940}
3941
3942void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) {
3943 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
3944 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003945 Location receiver = invoke->GetLocations()->InAt(0);
3946 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07003947 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003948
3949 // Set the hidden argument.
3950 __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
3951 invoke->GetDexMethodIndex());
3952
3953 // temp = object->GetClass();
3954 if (receiver.IsStackSlot()) {
3955 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
3956 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
3957 } else {
3958 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
3959 }
3960 codegen_->MaybeRecordImplicitNullCheck(invoke);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00003961 __ LoadFromOffset(kLoadWord, temp, temp,
3962 mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value());
3963 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00003964 invoke->GetImtIndex(), kMipsPointerSize));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003965 // temp = temp->GetImtEntryAt(method_offset);
3966 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
3967 // T9 = temp->GetEntryPoint();
3968 __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value());
3969 // T9();
3970 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003971 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003972 DCHECK(!codegen_->IsLeafMethod());
3973 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
3974}
3975
3976void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Chris Larsen701566a2015-10-27 15:29:13 -07003977 IntrinsicLocationsBuilderMIPS intrinsic(codegen_);
3978 if (intrinsic.TryDispatch(invoke)) {
3979 return;
3980 }
3981
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003982 HandleInvoke(invoke);
3983}
3984
3985void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00003986 // Explicit clinit checks triggered by static invokes must have been pruned by
3987 // art::PrepareForRegisterAllocation.
3988 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003989
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003990 HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind();
3991 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation();
3992 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
3993
3994 // kDirectAddressWithFixup and kCallDirectWithFixup need no extra input on R6 because
3995 // R6 has PC-relative addressing.
3996 bool has_extra_input = !isR6 &&
3997 ((method_load_kind == HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) ||
3998 (code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup));
3999
4000 if (invoke->HasPcRelativeDexCache()) {
4001 // kDexCachePcRelative is mutually exclusive with
4002 // kDirectAddressWithFixup/kCallDirectWithFixup.
4003 CHECK(!has_extra_input);
4004 has_extra_input = true;
4005 }
4006
Chris Larsen701566a2015-10-27 15:29:13 -07004007 IntrinsicLocationsBuilderMIPS intrinsic(codegen_);
4008 if (intrinsic.TryDispatch(invoke)) {
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004009 if (invoke->GetLocations()->CanCall() && has_extra_input) {
4010 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any());
4011 }
Chris Larsen701566a2015-10-27 15:29:13 -07004012 return;
4013 }
4014
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004015 HandleInvoke(invoke);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004016
4017 // Add the extra input register if either the dex cache array base register
4018 // or the PC-relative base register for accessing literals is needed.
4019 if (has_extra_input) {
4020 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister());
4021 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004022}
4023
Chris Larsen701566a2015-10-27 15:29:13 -07004024static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004025 if (invoke->GetLocations()->Intrinsified()) {
Chris Larsen701566a2015-10-27 15:29:13 -07004026 IntrinsicCodeGeneratorMIPS intrinsic(codegen);
4027 intrinsic.Dispatch(invoke);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004028 return true;
4029 }
4030 return false;
4031}
4032
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004033HLoadString::LoadKind CodeGeneratorMIPS::GetSupportedLoadStringKind(
Alexey Frunze06a46c42016-07-19 15:00:40 -07004034 HLoadString::LoadKind desired_string_load_kind) {
4035 if (kEmitCompilerReadBarrier) {
4036 UNIMPLEMENTED(FATAL) << "for read barrier";
4037 }
4038 // We disable PC-relative load when there is an irreducible loop, as the optimization
4039 // is incompatible with it.
4040 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
4041 bool fallback_load = has_irreducible_loops;
4042 switch (desired_string_load_kind) {
4043 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
4044 DCHECK(!GetCompilerOptions().GetCompilePic());
4045 break;
4046 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
4047 DCHECK(GetCompilerOptions().GetCompilePic());
4048 break;
4049 case HLoadString::LoadKind::kBootImageAddress:
4050 break;
4051 case HLoadString::LoadKind::kDexCacheAddress:
4052 DCHECK(Runtime::Current()->UseJitCompilation());
4053 fallback_load = false;
4054 break;
4055 case HLoadString::LoadKind::kDexCachePcRelative:
4056 DCHECK(!Runtime::Current()->UseJitCompilation());
4057 // TODO: Create as many MipsDexCacheArraysBase instructions as needed for methods
4058 // with irreducible loops.
4059 break;
4060 case HLoadString::LoadKind::kDexCacheViaMethod:
4061 fallback_load = false;
4062 break;
4063 }
4064 if (fallback_load) {
4065 desired_string_load_kind = HLoadString::LoadKind::kDexCacheViaMethod;
4066 }
4067 return desired_string_load_kind;
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004068}
4069
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004070HLoadClass::LoadKind CodeGeneratorMIPS::GetSupportedLoadClassKind(
4071 HLoadClass::LoadKind desired_class_load_kind) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07004072 if (kEmitCompilerReadBarrier) {
4073 UNIMPLEMENTED(FATAL) << "for read barrier";
4074 }
4075 // We disable pc-relative load when there is an irreducible loop, as the optimization
4076 // is incompatible with it.
4077 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
4078 bool fallback_load = has_irreducible_loops;
4079 switch (desired_class_load_kind) {
4080 case HLoadClass::LoadKind::kReferrersClass:
4081 fallback_load = false;
4082 break;
4083 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
4084 DCHECK(!GetCompilerOptions().GetCompilePic());
4085 break;
4086 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
4087 DCHECK(GetCompilerOptions().GetCompilePic());
4088 break;
4089 case HLoadClass::LoadKind::kBootImageAddress:
4090 break;
4091 case HLoadClass::LoadKind::kDexCacheAddress:
4092 DCHECK(Runtime::Current()->UseJitCompilation());
4093 fallback_load = false;
4094 break;
4095 case HLoadClass::LoadKind::kDexCachePcRelative:
4096 DCHECK(!Runtime::Current()->UseJitCompilation());
4097 // TODO: Create as many MipsDexCacheArraysBase instructions as needed for methods
4098 // with irreducible loops.
4099 break;
4100 case HLoadClass::LoadKind::kDexCacheViaMethod:
4101 fallback_load = false;
4102 break;
4103 }
4104 if (fallback_load) {
4105 desired_class_load_kind = HLoadClass::LoadKind::kDexCacheViaMethod;
4106 }
4107 return desired_class_load_kind;
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004108}
4109
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004110Register CodeGeneratorMIPS::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke,
4111 Register temp) {
4112 CHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u);
4113 Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
4114 if (!invoke->GetLocations()->Intrinsified()) {
4115 return location.AsRegister<Register>();
4116 }
4117 // For intrinsics we allow any location, so it may be on the stack.
4118 if (!location.IsRegister()) {
4119 __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex());
4120 return temp;
4121 }
4122 // For register locations, check if the register was saved. If so, get it from the stack.
4123 // Note: There is a chance that the register was saved but not overwritten, so we could
4124 // save one load. However, since this is just an intrinsic slow path we prefer this
4125 // simple and more robust approach rather that trying to determine if that's the case.
4126 SlowPathCode* slow_path = GetCurrentSlowPath();
4127 DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path.
4128 if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) {
4129 int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>());
4130 __ LoadFromOffset(kLoadWord, temp, SP, stack_offset);
4131 return temp;
4132 }
4133 return location.AsRegister<Register>();
4134}
4135
Vladimir Markodc151b22015-10-15 18:02:30 +01004136HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch(
4137 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
4138 MethodReference target_method ATTRIBUTE_UNUSED) {
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004139 HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info;
4140 // We disable PC-relative load when there is an irreducible loop, as the optimization
4141 // is incompatible with it.
4142 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
4143 bool fallback_load = true;
4144 bool fallback_call = true;
4145 switch (dispatch_info.method_load_kind) {
Vladimir Markodc151b22015-10-15 18:02:30 +01004146 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
4147 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004148 fallback_load = has_irreducible_loops;
4149 break;
Vladimir Markodc151b22015-10-15 18:02:30 +01004150 default:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004151 fallback_load = false;
Vladimir Markodc151b22015-10-15 18:02:30 +01004152 break;
4153 }
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004154 switch (dispatch_info.code_ptr_location) {
Vladimir Markodc151b22015-10-15 18:02:30 +01004155 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004156 fallback_call = has_irreducible_loops;
4157 break;
Vladimir Markodc151b22015-10-15 18:02:30 +01004158 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004159 // TODO: Implement this type.
4160 break;
Vladimir Markodc151b22015-10-15 18:02:30 +01004161 default:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004162 fallback_call = false;
4163 break;
Vladimir Markodc151b22015-10-15 18:02:30 +01004164 }
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004165 if (fallback_load) {
4166 dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod;
4167 dispatch_info.method_load_data = 0;
4168 }
4169 if (fallback_call) {
4170 dispatch_info.code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod;
4171 dispatch_info.direct_code_ptr = 0;
4172 }
4173 return dispatch_info;
Vladimir Markodc151b22015-10-15 18:02:30 +01004174}
4175
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004176void CodeGeneratorMIPS::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
4177 // All registers are assumed to be correctly set up per the calling convention.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004178 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004179 HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind();
4180 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation();
4181 bool isR6 = isa_features_.IsR6();
4182 // kDirectAddressWithFixup and kCallDirectWithFixup have no extra input on R6 because
4183 // R6 has PC-relative addressing.
4184 bool has_extra_input = invoke->HasPcRelativeDexCache() ||
4185 (!isR6 &&
4186 ((method_load_kind == HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) ||
4187 (code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup)));
4188 Register base_reg = has_extra_input
4189 ? GetInvokeStaticOrDirectExtraParameter(invoke, temp.AsRegister<Register>())
4190 : ZERO;
4191
4192 // For better instruction scheduling we load the direct code pointer before the method pointer.
4193 switch (code_ptr_location) {
4194 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
4195 // T9 = invoke->GetDirectCodePtr();
4196 __ LoadConst32(T9, invoke->GetDirectCodePtr());
4197 break;
4198 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
4199 // T9 = code address from literal pool with link-time patch.
4200 __ LoadLiteral(T9, base_reg, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod()));
4201 break;
4202 default:
4203 break;
4204 }
4205
4206 switch (method_load_kind) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004207 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
4208 // temp = thread->string_init_entrypoint
4209 __ LoadFromOffset(kLoadWord,
4210 temp.AsRegister<Register>(),
4211 TR,
4212 invoke->GetStringInitOffset());
4213 break;
4214 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00004215 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004216 break;
4217 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
4218 __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress());
4219 break;
4220 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004221 __ LoadLiteral(temp.AsRegister<Register>(),
4222 base_reg,
4223 DeduplicateMethodAddressLiteral(invoke->GetTargetMethod()));
4224 break;
4225 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: {
4226 HMipsDexCacheArraysBase* base =
4227 invoke->InputAt(invoke->GetSpecialInputIndex())->AsMipsDexCacheArraysBase();
4228 int32_t offset =
4229 invoke->GetDexCacheArrayOffset() - base->GetElementOffset() - kDexCacheArrayLwOffset;
4230 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset);
4231 break;
4232 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004233 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
Vladimir Markoc53c0792015-11-19 15:48:33 +00004234 Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004235 Register reg = temp.AsRegister<Register>();
4236 Register method_reg;
4237 if (current_method.IsRegister()) {
4238 method_reg = current_method.AsRegister<Register>();
4239 } else {
4240 // TODO: use the appropriate DCHECK() here if possible.
4241 // DCHECK(invoke->GetLocations()->Intrinsified());
4242 DCHECK(!current_method.IsValid());
4243 method_reg = reg;
4244 __ Lw(reg, SP, kCurrentMethodStackOffset);
4245 }
4246
4247 // temp = temp->dex_cache_resolved_methods_;
4248 __ LoadFromOffset(kLoadWord,
4249 reg,
4250 method_reg,
4251 ArtMethod::DexCacheResolvedMethodsOffset(kMipsPointerSize).Int32Value());
Vladimir Marko40ecb122016-04-06 17:33:41 +01004252 // temp = temp[index_in_cache];
4253 // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file.
4254 uint32_t index_in_cache = invoke->GetDexMethodIndex();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004255 __ LoadFromOffset(kLoadWord,
4256 reg,
4257 reg,
4258 CodeGenerator::GetCachePointerOffset(index_in_cache));
4259 break;
4260 }
4261 }
4262
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004263 switch (code_ptr_location) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004264 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004265 __ Bal(&frame_entry_label_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004266 break;
4267 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004268 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
4269 // T9 prepared above for better instruction scheduling.
4270 // T9()
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004271 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004272 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004273 break;
Vladimir Markodc151b22015-10-15 18:02:30 +01004274 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004275 // TODO: Implement this type.
Vladimir Markodc151b22015-10-15 18:02:30 +01004276 // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch().
4277 LOG(FATAL) << "Unsupported";
4278 UNREACHABLE();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004279 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
4280 // T9 = callee_method->entry_point_from_quick_compiled_code_;
Goran Jakovljevic1a878372015-10-26 14:28:52 +01004281 __ LoadFromOffset(kLoadWord,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004282 T9,
4283 callee_method.AsRegister<Register>(),
4284 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07004285 kMipsPointerSize).Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004286 // T9()
4287 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004288 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004289 break;
4290 }
4291 DCHECK(!IsLeafMethod());
4292}
4293
4294void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00004295 // Explicit clinit checks triggered by static invokes must have been pruned by
4296 // art::PrepareForRegisterAllocation.
4297 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004298
4299 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
4300 return;
4301 }
4302
4303 LocationSummary* locations = invoke->GetLocations();
4304 codegen_->GenerateStaticOrDirectCall(invoke,
4305 locations->HasTemps()
4306 ? locations->GetTemp(0)
4307 : Location::NoLocation());
4308 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
4309}
4310
Chris Larsen3acee732015-11-18 13:31:08 -08004311void CodeGeneratorMIPS::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004312 LocationSummary* locations = invoke->GetLocations();
4313 Location receiver = locations->InAt(0);
Chris Larsen3acee732015-11-18 13:31:08 -08004314 Register temp = temp_location.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004315 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
4316 invoke->GetVTableIndex(), kMipsPointerSize).SizeValue();
4317 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07004318 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004319
4320 // temp = object->GetClass();
Chris Larsen3acee732015-11-18 13:31:08 -08004321 DCHECK(receiver.IsRegister());
4322 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
4323 MaybeRecordImplicitNullCheck(invoke);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004324 // temp = temp->GetMethodAt(method_offset);
4325 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
4326 // T9 = temp->GetEntryPoint();
4327 __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value());
4328 // T9();
4329 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004330 __ NopIfNoReordering();
Chris Larsen3acee732015-11-18 13:31:08 -08004331}
4332
4333void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) {
4334 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
4335 return;
4336 }
4337
4338 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004339 DCHECK(!codegen_->IsLeafMethod());
4340 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
4341}
4342
4343void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07004344 if (cls->NeedsAccessCheck()) {
4345 InvokeRuntimeCallingConvention calling_convention;
4346 CodeGenerator::CreateLoadClassLocationSummary(
4347 cls,
4348 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
4349 Location::RegisterLocation(V0),
4350 /* code_generator_supports_read_barrier */ false); // TODO: revisit this bool.
4351 return;
4352 }
4353
4354 LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier)
4355 ? LocationSummary::kCallOnSlowPath
4356 : LocationSummary::kNoCall;
4357 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
4358 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
4359 switch (load_kind) {
4360 // We need an extra register for PC-relative literals on R2.
4361 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
4362 case HLoadClass::LoadKind::kBootImageAddress:
4363 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
4364 if (codegen_->GetInstructionSetFeatures().IsR6()) {
4365 break;
4366 }
4367 FALLTHROUGH_INTENDED;
4368 // We need an extra register for PC-relative dex cache accesses.
4369 case HLoadClass::LoadKind::kDexCachePcRelative:
4370 case HLoadClass::LoadKind::kReferrersClass:
4371 case HLoadClass::LoadKind::kDexCacheViaMethod:
4372 locations->SetInAt(0, Location::RequiresRegister());
4373 break;
4374 default:
4375 break;
4376 }
4377 locations->SetOut(Location::RequiresRegister());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004378}
4379
4380void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) {
4381 LocationSummary* locations = cls->GetLocations();
Pavle Batutae87a7182015-10-28 13:10:42 +01004382 if (cls->NeedsAccessCheck()) {
4383 codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex());
4384 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess),
4385 cls,
4386 cls->GetDexPc(),
4387 nullptr,
4388 IsDirectEntrypoint(kQuickInitializeTypeAndVerifyAccess));
Roland Levillain888d0672015-11-23 18:53:50 +00004389 CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>();
Pavle Batutae87a7182015-10-28 13:10:42 +01004390 return;
4391 }
4392
Alexey Frunze06a46c42016-07-19 15:00:40 -07004393 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
4394 Location out_loc = locations->Out();
4395 Register out = out_loc.AsRegister<Register>();
4396 Register base_or_current_method_reg;
4397 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
4398 switch (load_kind) {
4399 // We need an extra register for PC-relative literals on R2.
4400 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
4401 case HLoadClass::LoadKind::kBootImageAddress:
4402 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
4403 base_or_current_method_reg = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>();
4404 break;
4405 // We need an extra register for PC-relative dex cache accesses.
4406 case HLoadClass::LoadKind::kDexCachePcRelative:
4407 case HLoadClass::LoadKind::kReferrersClass:
4408 case HLoadClass::LoadKind::kDexCacheViaMethod:
4409 base_or_current_method_reg = locations->InAt(0).AsRegister<Register>();
4410 break;
4411 default:
4412 base_or_current_method_reg = ZERO;
4413 break;
4414 }
Nicolas Geoffray42e372e2015-11-24 15:48:56 +00004415
Alexey Frunze06a46c42016-07-19 15:00:40 -07004416 bool generate_null_check = false;
4417 switch (load_kind) {
4418 case HLoadClass::LoadKind::kReferrersClass: {
4419 DCHECK(!cls->CanCallRuntime());
4420 DCHECK(!cls->MustGenerateClinitCheck());
4421 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
4422 GenerateGcRootFieldLoad(cls,
4423 out_loc,
4424 base_or_current_method_reg,
4425 ArtMethod::DeclaringClassOffset().Int32Value());
4426 break;
4427 }
4428 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
4429 DCHECK(!kEmitCompilerReadBarrier);
4430 __ LoadLiteral(out,
4431 base_or_current_method_reg,
4432 codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(),
4433 cls->GetTypeIndex()));
4434 break;
4435 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: {
4436 DCHECK(!kEmitCompilerReadBarrier);
4437 CodeGeneratorMIPS::PcRelativePatchInfo* info =
4438 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004439 bool reordering = __ SetReorder(false);
Alexey Frunze06a46c42016-07-19 15:00:40 -07004440 if (isR6) {
4441 __ Bind(&info->high_label);
4442 __ Bind(&info->pc_rel_label);
4443 // Add a 32-bit offset to PC.
4444 __ Auipc(out, /* placeholder */ 0x1234);
4445 __ Addiu(out, out, /* placeholder */ 0x5678);
Nicolas Geoffray42e372e2015-11-24 15:48:56 +00004446 } else {
Alexey Frunze06a46c42016-07-19 15:00:40 -07004447 __ Bind(&info->high_label);
4448 __ Lui(out, /* placeholder */ 0x1234);
4449 // We do not bind info->pc_rel_label here, we'll use the assembler's label
4450 // for PC-relative literals and the base from HMipsComputeBaseMethodAddress.
4451 __ Ori(out, out, /* placeholder */ 0x5678);
4452 // Add a 32-bit offset to PC.
4453 __ Addu(out, out, base_or_current_method_reg);
Nicolas Geoffray42e372e2015-11-24 15:48:56 +00004454 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004455 __ SetReorder(reordering);
Alexey Frunze06a46c42016-07-19 15:00:40 -07004456 break;
4457 }
4458 case HLoadClass::LoadKind::kBootImageAddress: {
4459 DCHECK(!kEmitCompilerReadBarrier);
4460 DCHECK_NE(cls->GetAddress(), 0u);
4461 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
4462 __ LoadLiteral(out,
4463 base_or_current_method_reg,
4464 codegen_->DeduplicateBootImageAddressLiteral(address));
4465 break;
4466 }
4467 case HLoadClass::LoadKind::kDexCacheAddress: {
4468 DCHECK_NE(cls->GetAddress(), 0u);
4469 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
4470 static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes.");
4471 DCHECK_ALIGNED(cls->GetAddress(), 4u);
4472 int16_t offset = Low16Bits(address);
4473 uint32_t base_address = address - offset; // This accounts for offset sign extension.
4474 __ Lui(out, High16Bits(base_address));
4475 // /* GcRoot<mirror::Class> */ out = *(base_address + offset)
4476 GenerateGcRootFieldLoad(cls, out_loc, out, offset);
4477 generate_null_check = !cls->IsInDexCache();
4478 break;
4479 }
4480 case HLoadClass::LoadKind::kDexCachePcRelative: {
4481 HMipsDexCacheArraysBase* base = cls->InputAt(0)->AsMipsDexCacheArraysBase();
4482 int32_t offset =
4483 cls->GetDexCacheElementOffset() - base->GetElementOffset() - kDexCacheArrayLwOffset;
4484 // /* GcRoot<mirror::Class> */ out = *(dex_cache_arrays_base + offset)
4485 GenerateGcRootFieldLoad(cls, out_loc, base_or_current_method_reg, offset);
4486 generate_null_check = !cls->IsInDexCache();
4487 break;
4488 }
4489 case HLoadClass::LoadKind::kDexCacheViaMethod: {
4490 // /* GcRoot<mirror::Class>[] */ out =
4491 // current_method.ptr_sized_fields_->dex_cache_resolved_types_
4492 __ LoadFromOffset(kLoadWord,
4493 out,
4494 base_or_current_method_reg,
4495 ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value());
4496 // /* GcRoot<mirror::Class> */ out = out[type_index]
4497 size_t offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex());
4498 GenerateGcRootFieldLoad(cls, out_loc, out, offset);
4499 generate_null_check = !cls->IsInDexCache();
4500 }
4501 }
4502
4503 if (generate_null_check || cls->MustGenerateClinitCheck()) {
4504 DCHECK(cls->CanCallRuntime());
4505 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS(
4506 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
4507 codegen_->AddSlowPath(slow_path);
4508 if (generate_null_check) {
4509 __ Beqz(out, slow_path->GetEntryLabel());
4510 }
4511 if (cls->MustGenerateClinitCheck()) {
4512 GenerateClassInitializationCheck(slow_path, out);
4513 } else {
4514 __ Bind(slow_path->GetExitLabel());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004515 }
4516 }
4517}
4518
4519static int32_t GetExceptionTlsOffset() {
Andreas Gampe542451c2016-07-26 09:02:02 -07004520 return Thread::ExceptionOffset<kMipsPointerSize>().Int32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004521}
4522
4523void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) {
4524 LocationSummary* locations =
4525 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4526 locations->SetOut(Location::RequiresRegister());
4527}
4528
4529void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) {
4530 Register out = load->GetLocations()->Out().AsRegister<Register>();
4531 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
4532}
4533
4534void LocationsBuilderMIPS::VisitClearException(HClearException* clear) {
4535 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
4536}
4537
4538void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
4539 __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset());
4540}
4541
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004542void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07004543 LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier)
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004544 ? LocationSummary::kCallOnSlowPath
4545 : LocationSummary::kNoCall;
Nicolas Geoffray917d0162015-11-24 18:25:35 +00004546 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind);
Alexey Frunze06a46c42016-07-19 15:00:40 -07004547 HLoadString::LoadKind load_kind = load->GetLoadKind();
4548 switch (load_kind) {
4549 // We need an extra register for PC-relative literals on R2.
4550 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
4551 case HLoadString::LoadKind::kBootImageAddress:
4552 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
4553 if (codegen_->GetInstructionSetFeatures().IsR6()) {
4554 break;
4555 }
4556 FALLTHROUGH_INTENDED;
4557 // We need an extra register for PC-relative dex cache accesses.
4558 case HLoadString::LoadKind::kDexCachePcRelative:
4559 case HLoadString::LoadKind::kDexCacheViaMethod:
4560 locations->SetInAt(0, Location::RequiresRegister());
4561 break;
4562 default:
4563 break;
4564 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004565 locations->SetOut(Location::RequiresRegister());
4566}
4567
4568void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07004569 HLoadString::LoadKind load_kind = load->GetLoadKind();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004570 LocationSummary* locations = load->GetLocations();
Alexey Frunze06a46c42016-07-19 15:00:40 -07004571 Location out_loc = locations->Out();
4572 Register out = out_loc.AsRegister<Register>();
4573 Register base_or_current_method_reg;
4574 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
4575 switch (load_kind) {
4576 // We need an extra register for PC-relative literals on R2.
4577 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
4578 case HLoadString::LoadKind::kBootImageAddress:
4579 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
4580 base_or_current_method_reg = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>();
4581 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07004582 default:
4583 base_or_current_method_reg = ZERO;
4584 break;
4585 }
4586
4587 switch (load_kind) {
4588 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
4589 DCHECK(!kEmitCompilerReadBarrier);
4590 __ LoadLiteral(out,
4591 base_or_current_method_reg,
4592 codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(),
4593 load->GetStringIndex()));
4594 return; // No dex cache slow path.
4595 case HLoadString::LoadKind::kBootImageLinkTimePcRelative: {
4596 DCHECK(!kEmitCompilerReadBarrier);
4597 CodeGeneratorMIPS::PcRelativePatchInfo* info =
4598 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004599 bool reordering = __ SetReorder(false);
Alexey Frunze06a46c42016-07-19 15:00:40 -07004600 if (isR6) {
4601 __ Bind(&info->high_label);
4602 __ Bind(&info->pc_rel_label);
4603 // Add a 32-bit offset to PC.
4604 __ Auipc(out, /* placeholder */ 0x1234);
4605 __ Addiu(out, out, /* placeholder */ 0x5678);
4606 } else {
4607 __ Bind(&info->high_label);
4608 __ Lui(out, /* placeholder */ 0x1234);
4609 // We do not bind info->pc_rel_label here, we'll use the assembler's label
4610 // for PC-relative literals and the base from HMipsComputeBaseMethodAddress.
4611 __ Ori(out, out, /* placeholder */ 0x5678);
4612 // Add a 32-bit offset to PC.
4613 __ Addu(out, out, base_or_current_method_reg);
4614 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004615 __ SetReorder(reordering);
Alexey Frunze06a46c42016-07-19 15:00:40 -07004616 return; // No dex cache slow path.
4617 }
4618 case HLoadString::LoadKind::kBootImageAddress: {
4619 DCHECK(!kEmitCompilerReadBarrier);
4620 DCHECK_NE(load->GetAddress(), 0u);
4621 uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress());
4622 __ LoadLiteral(out,
4623 base_or_current_method_reg,
4624 codegen_->DeduplicateBootImageAddressLiteral(address));
4625 return; // No dex cache slow path.
4626 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07004627 default:
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07004628 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07004629 }
Nicolas Geoffray917d0162015-11-24 18:25:35 +00004630
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07004631 // TODO: Re-add the compiler code to do string dex cache lookup again.
4632 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS(load);
4633 codegen_->AddSlowPath(slow_path);
4634 __ B(slow_path->GetEntryLabel());
4635 __ Bind(slow_path->GetExitLabel());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004636}
4637
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004638void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) {
4639 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
4640 locations->SetOut(Location::ConstantLocation(constant));
4641}
4642
4643void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
4644 // Will be generated at use site.
4645}
4646
4647void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) {
4648 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004649 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004650 InvokeRuntimeCallingConvention calling_convention;
4651 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4652}
4653
4654void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) {
4655 if (instruction->IsEnter()) {
4656 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLockObject),
4657 instruction,
4658 instruction->GetDexPc(),
4659 nullptr,
4660 IsDirectEntrypoint(kQuickLockObject));
4661 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
4662 } else {
4663 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pUnlockObject),
4664 instruction,
4665 instruction->GetDexPc(),
4666 nullptr,
4667 IsDirectEntrypoint(kQuickUnlockObject));
4668 }
4669 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
4670}
4671
4672void LocationsBuilderMIPS::VisitMul(HMul* mul) {
4673 LocationSummary* locations =
4674 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
4675 switch (mul->GetResultType()) {
4676 case Primitive::kPrimInt:
4677 case Primitive::kPrimLong:
4678 locations->SetInAt(0, Location::RequiresRegister());
4679 locations->SetInAt(1, Location::RequiresRegister());
4680 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4681 break;
4682
4683 case Primitive::kPrimFloat:
4684 case Primitive::kPrimDouble:
4685 locations->SetInAt(0, Location::RequiresFpuRegister());
4686 locations->SetInAt(1, Location::RequiresFpuRegister());
4687 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
4688 break;
4689
4690 default:
4691 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
4692 }
4693}
4694
4695void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) {
4696 Primitive::Type type = instruction->GetType();
4697 LocationSummary* locations = instruction->GetLocations();
4698 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
4699
4700 switch (type) {
4701 case Primitive::kPrimInt: {
4702 Register dst = locations->Out().AsRegister<Register>();
4703 Register lhs = locations->InAt(0).AsRegister<Register>();
4704 Register rhs = locations->InAt(1).AsRegister<Register>();
4705
4706 if (isR6) {
4707 __ MulR6(dst, lhs, rhs);
4708 } else {
4709 __ MulR2(dst, lhs, rhs);
4710 }
4711 break;
4712 }
4713 case Primitive::kPrimLong: {
4714 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
4715 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
4716 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4717 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
4718 Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>();
4719 Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>();
4720
4721 // Extra checks to protect caused by the existance of A1_A2.
4722 // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo:
4723 // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2).
4724 DCHECK_NE(dst_high, lhs_low);
4725 DCHECK_NE(dst_high, rhs_low);
4726
4727 // A_B * C_D
4728 // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ]
4729 // dst_lo: [ low(B*D) ]
4730 // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result.
4731
4732 if (isR6) {
4733 __ MulR6(TMP, lhs_high, rhs_low);
4734 __ MulR6(dst_high, lhs_low, rhs_high);
4735 __ Addu(dst_high, dst_high, TMP);
4736 __ MuhuR6(TMP, lhs_low, rhs_low);
4737 __ Addu(dst_high, dst_high, TMP);
4738 __ MulR6(dst_low, lhs_low, rhs_low);
4739 } else {
4740 __ MulR2(TMP, lhs_high, rhs_low);
4741 __ MulR2(dst_high, lhs_low, rhs_high);
4742 __ Addu(dst_high, dst_high, TMP);
4743 __ MultuR2(lhs_low, rhs_low);
4744 __ Mfhi(TMP);
4745 __ Addu(dst_high, dst_high, TMP);
4746 __ Mflo(dst_low);
4747 }
4748 break;
4749 }
4750 case Primitive::kPrimFloat:
4751 case Primitive::kPrimDouble: {
4752 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
4753 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
4754 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
4755 if (type == Primitive::kPrimFloat) {
4756 __ MulS(dst, lhs, rhs);
4757 } else {
4758 __ MulD(dst, lhs, rhs);
4759 }
4760 break;
4761 }
4762 default:
4763 LOG(FATAL) << "Unexpected mul type " << type;
4764 }
4765}
4766
4767void LocationsBuilderMIPS::VisitNeg(HNeg* neg) {
4768 LocationSummary* locations =
4769 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
4770 switch (neg->GetResultType()) {
4771 case Primitive::kPrimInt:
4772 case Primitive::kPrimLong:
4773 locations->SetInAt(0, Location::RequiresRegister());
4774 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4775 break;
4776
4777 case Primitive::kPrimFloat:
4778 case Primitive::kPrimDouble:
4779 locations->SetInAt(0, Location::RequiresFpuRegister());
4780 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
4781 break;
4782
4783 default:
4784 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
4785 }
4786}
4787
4788void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) {
4789 Primitive::Type type = instruction->GetType();
4790 LocationSummary* locations = instruction->GetLocations();
4791
4792 switch (type) {
4793 case Primitive::kPrimInt: {
4794 Register dst = locations->Out().AsRegister<Register>();
4795 Register src = locations->InAt(0).AsRegister<Register>();
4796 __ Subu(dst, ZERO, src);
4797 break;
4798 }
4799 case Primitive::kPrimLong: {
4800 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
4801 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
4802 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4803 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
4804 __ Subu(dst_low, ZERO, src_low);
4805 __ Sltu(TMP, ZERO, dst_low);
4806 __ Subu(dst_high, ZERO, src_high);
4807 __ Subu(dst_high, dst_high, TMP);
4808 break;
4809 }
4810 case Primitive::kPrimFloat:
4811 case Primitive::kPrimDouble: {
4812 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
4813 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
4814 if (type == Primitive::kPrimFloat) {
4815 __ NegS(dst, src);
4816 } else {
4817 __ NegD(dst, src);
4818 }
4819 break;
4820 }
4821 default:
4822 LOG(FATAL) << "Unexpected neg type " << type;
4823 }
4824}
4825
4826void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) {
4827 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004828 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004829 InvokeRuntimeCallingConvention calling_convention;
4830 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4831 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
4832 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
4833 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
4834}
4835
4836void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) {
4837 InvokeRuntimeCallingConvention calling_convention;
4838 Register current_method_register = calling_convention.GetRegisterAt(2);
4839 __ Lw(current_method_register, SP, kCurrentMethodStackOffset);
4840 // Move an uint16_t value to a register.
4841 __ LoadConst32(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
4842 codegen_->InvokeRuntime(
Andreas Gampe542451c2016-07-26 09:02:02 -07004843 GetThreadOffset<kMipsPointerSize>(instruction->GetEntrypoint()).Int32Value(),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004844 instruction,
4845 instruction->GetDexPc(),
4846 nullptr,
4847 IsDirectEntrypoint(kQuickAllocArrayWithAccessCheck));
4848 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
4849 void*, uint32_t, int32_t, ArtMethod*>();
4850}
4851
4852void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) {
4853 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004854 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004855 InvokeRuntimeCallingConvention calling_convention;
David Brazdil6de19382016-01-08 17:37:10 +00004856 if (instruction->IsStringAlloc()) {
4857 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
4858 } else {
4859 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4860 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
4861 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004862 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
4863}
4864
4865void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) {
David Brazdil6de19382016-01-08 17:37:10 +00004866 if (instruction->IsStringAlloc()) {
4867 // String is allocated through StringFactory. Call NewEmptyString entry point.
4868 Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>();
Andreas Gampe542451c2016-07-26 09:02:02 -07004869 MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
David Brazdil6de19382016-01-08 17:37:10 +00004870 __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
4871 __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value());
4872 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004873 __ NopIfNoReordering();
David Brazdil6de19382016-01-08 17:37:10 +00004874 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
4875 } else {
4876 codegen_->InvokeRuntime(
Andreas Gampe542451c2016-07-26 09:02:02 -07004877 GetThreadOffset<kMipsPointerSize>(instruction->GetEntrypoint()).Int32Value(),
David Brazdil6de19382016-01-08 17:37:10 +00004878 instruction,
4879 instruction->GetDexPc(),
4880 nullptr,
4881 IsDirectEntrypoint(kQuickAllocObjectWithAccessCheck));
4882 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
4883 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004884}
4885
4886void LocationsBuilderMIPS::VisitNot(HNot* instruction) {
4887 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
4888 locations->SetInAt(0, Location::RequiresRegister());
4889 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4890}
4891
4892void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) {
4893 Primitive::Type type = instruction->GetType();
4894 LocationSummary* locations = instruction->GetLocations();
4895
4896 switch (type) {
4897 case Primitive::kPrimInt: {
4898 Register dst = locations->Out().AsRegister<Register>();
4899 Register src = locations->InAt(0).AsRegister<Register>();
4900 __ Nor(dst, src, ZERO);
4901 break;
4902 }
4903
4904 case Primitive::kPrimLong: {
4905 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
4906 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
4907 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4908 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
4909 __ Nor(dst_high, src_high, ZERO);
4910 __ Nor(dst_low, src_low, ZERO);
4911 break;
4912 }
4913
4914 default:
4915 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
4916 }
4917}
4918
4919void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) {
4920 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
4921 locations->SetInAt(0, Location::RequiresRegister());
4922 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4923}
4924
4925void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) {
4926 LocationSummary* locations = instruction->GetLocations();
4927 __ Xori(locations->Out().AsRegister<Register>(),
4928 locations->InAt(0).AsRegister<Register>(),
4929 1);
4930}
4931
4932void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) {
4933 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
4934 ? LocationSummary::kCallOnSlowPath
4935 : LocationSummary::kNoCall;
4936 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
4937 locations->SetInAt(0, Location::RequiresRegister());
4938 if (instruction->HasUses()) {
4939 locations->SetOut(Location::SameAsFirstInput());
4940 }
4941}
4942
Calin Juravle2ae48182016-03-16 14:05:09 +00004943void CodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) {
4944 if (CanMoveNullCheckToUser(instruction)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004945 return;
4946 }
4947 Location obj = instruction->GetLocations()->InAt(0);
4948
4949 __ Lw(ZERO, obj.AsRegister<Register>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00004950 RecordPcInfo(instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004951}
4952
Calin Juravle2ae48182016-03-16 14:05:09 +00004953void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004954 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00004955 AddSlowPath(slow_path);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004956
4957 Location obj = instruction->GetLocations()->InAt(0);
4958
4959 __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
4960}
4961
4962void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00004963 codegen_->GenerateNullCheck(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004964}
4965
4966void LocationsBuilderMIPS::VisitOr(HOr* instruction) {
4967 HandleBinaryOp(instruction);
4968}
4969
4970void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) {
4971 HandleBinaryOp(instruction);
4972}
4973
4974void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
4975 LOG(FATAL) << "Unreachable";
4976}
4977
4978void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) {
4979 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
4980}
4981
4982void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) {
4983 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
4984 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
4985 if (location.IsStackSlot()) {
4986 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
4987 } else if (location.IsDoubleStackSlot()) {
4988 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
4989 }
4990 locations->SetOut(location);
4991}
4992
4993void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction
4994 ATTRIBUTE_UNUSED) {
4995 // Nothing to do, the parameter is already at its location.
4996}
4997
4998void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) {
4999 LocationSummary* locations =
5000 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
5001 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
5002}
5003
5004void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction
5005 ATTRIBUTE_UNUSED) {
5006 // Nothing to do, the method is already at its location.
5007}
5008
5009void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) {
5010 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Vladimir Marko372f10e2016-05-17 16:30:10 +01005011 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005012 locations->SetInAt(i, Location::Any());
5013 }
5014 locations->SetOut(Location::Any());
5015}
5016
5017void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
5018 LOG(FATAL) << "Unreachable";
5019}
5020
5021void LocationsBuilderMIPS::VisitRem(HRem* rem) {
5022 Primitive::Type type = rem->GetResultType();
5023 LocationSummary::CallKind call_kind =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01005024 (type == Primitive::kPrimInt) ? LocationSummary::kNoCall : LocationSummary::kCallOnMainOnly;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005025 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
5026
5027 switch (type) {
5028 case Primitive::kPrimInt:
5029 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze7e99e052015-11-24 19:28:01 -08005030 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005031 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
5032 break;
5033
5034 case Primitive::kPrimLong: {
5035 InvokeRuntimeCallingConvention calling_convention;
5036 locations->SetInAt(0, Location::RegisterPairLocation(
5037 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
5038 locations->SetInAt(1, Location::RegisterPairLocation(
5039 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
5040 locations->SetOut(calling_convention.GetReturnLocation(type));
5041 break;
5042 }
5043
5044 case Primitive::kPrimFloat:
5045 case Primitive::kPrimDouble: {
5046 InvokeRuntimeCallingConvention calling_convention;
5047 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
5048 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
5049 locations->SetOut(calling_convention.GetReturnLocation(type));
5050 break;
5051 }
5052
5053 default:
5054 LOG(FATAL) << "Unexpected rem type " << type;
5055 }
5056}
5057
5058void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) {
5059 Primitive::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005060
5061 switch (type) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08005062 case Primitive::kPrimInt:
5063 GenerateDivRemIntegral(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005064 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005065 case Primitive::kPrimLong: {
5066 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod),
5067 instruction,
5068 instruction->GetDexPc(),
5069 nullptr,
5070 IsDirectEntrypoint(kQuickLmod));
5071 CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>();
5072 break;
5073 }
5074 case Primitive::kPrimFloat: {
5075 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf),
5076 instruction, instruction->GetDexPc(),
5077 nullptr,
5078 IsDirectEntrypoint(kQuickFmodf));
Roland Levillain888d0672015-11-23 18:53:50 +00005079 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005080 break;
5081 }
5082 case Primitive::kPrimDouble: {
5083 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod),
5084 instruction, instruction->GetDexPc(),
5085 nullptr,
5086 IsDirectEntrypoint(kQuickFmod));
Roland Levillain888d0672015-11-23 18:53:50 +00005087 CheckEntrypointTypes<kQuickFmod, double, double, double>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005088 break;
5089 }
5090 default:
5091 LOG(FATAL) << "Unexpected rem type " << type;
5092 }
5093}
5094
5095void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
5096 memory_barrier->SetLocations(nullptr);
5097}
5098
5099void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
5100 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
5101}
5102
5103void LocationsBuilderMIPS::VisitReturn(HReturn* ret) {
5104 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret);
5105 Primitive::Type return_type = ret->InputAt(0)->GetType();
5106 locations->SetInAt(0, MipsReturnLocation(return_type));
5107}
5108
5109void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
5110 codegen_->GenerateFrameExit();
5111}
5112
5113void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) {
5114 ret->SetLocations(nullptr);
5115}
5116
5117void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
5118 codegen_->GenerateFrameExit();
5119}
5120
Alexey Frunze92d90602015-12-18 18:16:36 -08005121void LocationsBuilderMIPS::VisitRor(HRor* ror) {
5122 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00005123}
5124
Alexey Frunze92d90602015-12-18 18:16:36 -08005125void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) {
5126 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00005127}
5128
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005129void LocationsBuilderMIPS::VisitShl(HShl* shl) {
5130 HandleShift(shl);
5131}
5132
5133void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) {
5134 HandleShift(shl);
5135}
5136
5137void LocationsBuilderMIPS::VisitShr(HShr* shr) {
5138 HandleShift(shr);
5139}
5140
5141void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) {
5142 HandleShift(shr);
5143}
5144
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005145void LocationsBuilderMIPS::VisitSub(HSub* instruction) {
5146 HandleBinaryOp(instruction);
5147}
5148
5149void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) {
5150 HandleBinaryOp(instruction);
5151}
5152
5153void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) {
5154 HandleFieldGet(instruction, instruction->GetFieldInfo());
5155}
5156
5157void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) {
5158 HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
5159}
5160
5161void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) {
5162 HandleFieldSet(instruction, instruction->GetFieldInfo());
5163}
5164
5165void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) {
5166 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
5167}
5168
5169void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet(
5170 HUnresolvedInstanceFieldGet* instruction) {
5171 FieldAccessCallingConventionMIPS calling_convention;
5172 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
5173 instruction->GetFieldType(),
5174 calling_convention);
5175}
5176
5177void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet(
5178 HUnresolvedInstanceFieldGet* instruction) {
5179 FieldAccessCallingConventionMIPS calling_convention;
5180 codegen_->GenerateUnresolvedFieldAccess(instruction,
5181 instruction->GetFieldType(),
5182 instruction->GetFieldIndex(),
5183 instruction->GetDexPc(),
5184 calling_convention);
5185}
5186
5187void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet(
5188 HUnresolvedInstanceFieldSet* instruction) {
5189 FieldAccessCallingConventionMIPS calling_convention;
5190 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
5191 instruction->GetFieldType(),
5192 calling_convention);
5193}
5194
5195void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet(
5196 HUnresolvedInstanceFieldSet* instruction) {
5197 FieldAccessCallingConventionMIPS calling_convention;
5198 codegen_->GenerateUnresolvedFieldAccess(instruction,
5199 instruction->GetFieldType(),
5200 instruction->GetFieldIndex(),
5201 instruction->GetDexPc(),
5202 calling_convention);
5203}
5204
5205void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet(
5206 HUnresolvedStaticFieldGet* instruction) {
5207 FieldAccessCallingConventionMIPS calling_convention;
5208 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
5209 instruction->GetFieldType(),
5210 calling_convention);
5211}
5212
5213void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet(
5214 HUnresolvedStaticFieldGet* instruction) {
5215 FieldAccessCallingConventionMIPS calling_convention;
5216 codegen_->GenerateUnresolvedFieldAccess(instruction,
5217 instruction->GetFieldType(),
5218 instruction->GetFieldIndex(),
5219 instruction->GetDexPc(),
5220 calling_convention);
5221}
5222
5223void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet(
5224 HUnresolvedStaticFieldSet* instruction) {
5225 FieldAccessCallingConventionMIPS calling_convention;
5226 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
5227 instruction->GetFieldType(),
5228 calling_convention);
5229}
5230
5231void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet(
5232 HUnresolvedStaticFieldSet* instruction) {
5233 FieldAccessCallingConventionMIPS calling_convention;
5234 codegen_->GenerateUnresolvedFieldAccess(instruction,
5235 instruction->GetFieldType(),
5236 instruction->GetFieldIndex(),
5237 instruction->GetDexPc(),
5238 calling_convention);
5239}
5240
5241void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) {
5242 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
5243}
5244
5245void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) {
5246 HBasicBlock* block = instruction->GetBlock();
5247 if (block->GetLoopInformation() != nullptr) {
5248 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
5249 // The back edge will generate the suspend check.
5250 return;
5251 }
5252 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
5253 // The goto will generate the suspend check.
5254 return;
5255 }
5256 GenerateSuspendCheck(instruction, nullptr);
5257}
5258
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005259void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) {
5260 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01005261 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005262 InvokeRuntimeCallingConvention calling_convention;
5263 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
5264}
5265
5266void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) {
5267 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException),
5268 instruction,
5269 instruction->GetDexPc(),
5270 nullptr,
5271 IsDirectEntrypoint(kQuickDeliverException));
5272 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
5273}
5274
5275void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) {
5276 Primitive::Type input_type = conversion->GetInputType();
5277 Primitive::Type result_type = conversion->GetResultType();
5278 DCHECK_NE(input_type, result_type);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005279 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005280
5281 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
5282 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
5283 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
5284 }
5285
5286 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005287 if (!isR6 &&
5288 ((Primitive::IsFloatingPointType(result_type) && input_type == Primitive::kPrimLong) ||
5289 (result_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(input_type)))) {
Serban Constantinescu54ff4822016-07-07 18:03:19 +01005290 call_kind = LocationSummary::kCallOnMainOnly;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005291 }
5292
5293 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
5294
5295 if (call_kind == LocationSummary::kNoCall) {
5296 if (Primitive::IsFloatingPointType(input_type)) {
5297 locations->SetInAt(0, Location::RequiresFpuRegister());
5298 } else {
5299 locations->SetInAt(0, Location::RequiresRegister());
5300 }
5301
5302 if (Primitive::IsFloatingPointType(result_type)) {
5303 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
5304 } else {
5305 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
5306 }
5307 } else {
5308 InvokeRuntimeCallingConvention calling_convention;
5309
5310 if (Primitive::IsFloatingPointType(input_type)) {
5311 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
5312 } else {
5313 DCHECK_EQ(input_type, Primitive::kPrimLong);
5314 locations->SetInAt(0, Location::RegisterPairLocation(
5315 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
5316 }
5317
5318 locations->SetOut(calling_convention.GetReturnLocation(result_type));
5319 }
5320}
5321
5322void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) {
5323 LocationSummary* locations = conversion->GetLocations();
5324 Primitive::Type result_type = conversion->GetResultType();
5325 Primitive::Type input_type = conversion->GetInputType();
5326 bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005327 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005328
5329 DCHECK_NE(input_type, result_type);
5330
5331 if (result_type == Primitive::kPrimLong && Primitive::IsIntegralType(input_type)) {
5332 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
5333 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
5334 Register src = locations->InAt(0).AsRegister<Register>();
5335
Alexey Frunzea871ef12016-06-27 15:20:11 -07005336 if (dst_low != src) {
5337 __ Move(dst_low, src);
5338 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005339 __ Sra(dst_high, src, 31);
5340 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
5341 Register dst = locations->Out().AsRegister<Register>();
5342 Register src = (input_type == Primitive::kPrimLong)
5343 ? locations->InAt(0).AsRegisterPairLow<Register>()
5344 : locations->InAt(0).AsRegister<Register>();
5345
5346 switch (result_type) {
5347 case Primitive::kPrimChar:
5348 __ Andi(dst, src, 0xFFFF);
5349 break;
5350 case Primitive::kPrimByte:
5351 if (has_sign_extension) {
5352 __ Seb(dst, src);
5353 } else {
5354 __ Sll(dst, src, 24);
5355 __ Sra(dst, dst, 24);
5356 }
5357 break;
5358 case Primitive::kPrimShort:
5359 if (has_sign_extension) {
5360 __ Seh(dst, src);
5361 } else {
5362 __ Sll(dst, src, 16);
5363 __ Sra(dst, dst, 16);
5364 }
5365 break;
5366 case Primitive::kPrimInt:
Alexey Frunzea871ef12016-06-27 15:20:11 -07005367 if (dst != src) {
5368 __ Move(dst, src);
5369 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005370 break;
5371
5372 default:
5373 LOG(FATAL) << "Unexpected type conversion from " << input_type
5374 << " to " << result_type;
5375 }
5376 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005377 if (input_type == Primitive::kPrimLong) {
5378 if (isR6) {
5379 // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary
5380 // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction.
5381 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
5382 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
5383 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
5384 __ Mtc1(src_low, FTMP);
5385 __ Mthc1(src_high, FTMP);
5386 if (result_type == Primitive::kPrimFloat) {
5387 __ Cvtsl(dst, FTMP);
5388 } else {
5389 __ Cvtdl(dst, FTMP);
5390 }
5391 } else {
5392 int32_t entry_offset = (result_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pL2f)
5393 : QUICK_ENTRY_POINT(pL2d);
5394 bool direct = (result_type == Primitive::kPrimFloat) ? IsDirectEntrypoint(kQuickL2f)
5395 : IsDirectEntrypoint(kQuickL2d);
5396 codegen_->InvokeRuntime(entry_offset,
5397 conversion,
5398 conversion->GetDexPc(),
5399 nullptr,
5400 direct);
5401 if (result_type == Primitive::kPrimFloat) {
5402 CheckEntrypointTypes<kQuickL2f, float, int64_t>();
5403 } else {
5404 CheckEntrypointTypes<kQuickL2d, double, int64_t>();
5405 }
5406 }
5407 } else {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005408 Register src = locations->InAt(0).AsRegister<Register>();
5409 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
5410 __ Mtc1(src, FTMP);
5411 if (result_type == Primitive::kPrimFloat) {
5412 __ Cvtsw(dst, FTMP);
5413 } else {
5414 __ Cvtdw(dst, FTMP);
5415 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005416 }
5417 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
5418 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005419 if (result_type == Primitive::kPrimLong) {
5420 if (isR6) {
5421 // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary
5422 // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction.
5423 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
5424 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
5425 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
5426 MipsLabel truncate;
5427 MipsLabel done;
5428
5429 // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive
5430 // value when the input is either a NaN or is outside of the range of the output type
5431 // after the truncation. IOW, the three special cases (NaN, too small, too big) produce
5432 // the same result.
5433 //
5434 // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum
5435 // value of the output type if the input is outside of the range after the truncation or
5436 // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct
5437 // results. This matches the desired float/double-to-int/long conversion exactly.
5438 //
5439 // So, NAN2008 affects handling of negative values and NaNs by the truncate instruction.
5440 //
5441 // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate
5442 // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6,
5443 // even though it must be NAN2008=1 on R6.
5444 //
5445 // The code takes care of the different behaviors by first comparing the input to the
5446 // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int).
5447 // If the input is greater than or equal to the minimum, it procedes to the truncate
5448 // instruction, which will handle such an input the same way irrespective of NAN2008.
5449 // Otherwise the input is compared to itself to determine whether it is a NaN or not
5450 // in order to return either zero or the minimum value.
5451 //
5452 // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the
5453 // truncate instruction for MIPS64R6.
5454 if (input_type == Primitive::kPrimFloat) {
5455 uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int64_t>::min());
5456 __ LoadConst32(TMP, min_val);
5457 __ Mtc1(TMP, FTMP);
5458 __ CmpLeS(FTMP, FTMP, src);
5459 } else {
5460 uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int64_t>::min());
5461 __ LoadConst32(TMP, High32Bits(min_val));
5462 __ Mtc1(ZERO, FTMP);
5463 __ Mthc1(TMP, FTMP);
5464 __ CmpLeD(FTMP, FTMP, src);
5465 }
5466
5467 __ Bc1nez(FTMP, &truncate);
5468
5469 if (input_type == Primitive::kPrimFloat) {
5470 __ CmpEqS(FTMP, src, src);
5471 } else {
5472 __ CmpEqD(FTMP, src, src);
5473 }
5474 __ Move(dst_low, ZERO);
5475 __ LoadConst32(dst_high, std::numeric_limits<int32_t>::min());
5476 __ Mfc1(TMP, FTMP);
5477 __ And(dst_high, dst_high, TMP);
5478
5479 __ B(&done);
5480
5481 __ Bind(&truncate);
5482
5483 if (input_type == Primitive::kPrimFloat) {
5484 __ TruncLS(FTMP, src);
5485 } else {
5486 __ TruncLD(FTMP, src);
5487 }
5488 __ Mfc1(dst_low, FTMP);
5489 __ Mfhc1(dst_high, FTMP);
5490
5491 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005492 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005493 int32_t entry_offset = (input_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pF2l)
5494 : QUICK_ENTRY_POINT(pD2l);
5495 bool direct = (result_type == Primitive::kPrimFloat) ? IsDirectEntrypoint(kQuickF2l)
5496 : IsDirectEntrypoint(kQuickD2l);
5497 codegen_->InvokeRuntime(entry_offset, conversion, conversion->GetDexPc(), nullptr, direct);
5498 if (input_type == Primitive::kPrimFloat) {
5499 CheckEntrypointTypes<kQuickF2l, int64_t, float>();
5500 } else {
5501 CheckEntrypointTypes<kQuickD2l, int64_t, double>();
5502 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005503 }
5504 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005505 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
5506 Register dst = locations->Out().AsRegister<Register>();
5507 MipsLabel truncate;
5508 MipsLabel done;
5509
5510 // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate
5511 // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6,
5512 // even though it must be NAN2008=1 on R6.
5513 //
5514 // For details see the large comment above for the truncation of float/double to long on R6.
5515 //
5516 // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the
5517 // truncate instruction for MIPS64R6.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005518 if (input_type == Primitive::kPrimFloat) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005519 uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min());
5520 __ LoadConst32(TMP, min_val);
5521 __ Mtc1(TMP, FTMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005522 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005523 uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min());
5524 __ LoadConst32(TMP, High32Bits(min_val));
5525 __ Mtc1(ZERO, FTMP);
Alexey Frunzea871ef12016-06-27 15:20:11 -07005526 __ MoveToFpuHigh(TMP, FTMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005527 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005528
5529 if (isR6) {
5530 if (input_type == Primitive::kPrimFloat) {
5531 __ CmpLeS(FTMP, FTMP, src);
5532 } else {
5533 __ CmpLeD(FTMP, FTMP, src);
5534 }
5535 __ Bc1nez(FTMP, &truncate);
5536
5537 if (input_type == Primitive::kPrimFloat) {
5538 __ CmpEqS(FTMP, src, src);
5539 } else {
5540 __ CmpEqD(FTMP, src, src);
5541 }
5542 __ LoadConst32(dst, std::numeric_limits<int32_t>::min());
5543 __ Mfc1(TMP, FTMP);
5544 __ And(dst, dst, TMP);
5545 } else {
5546 if (input_type == Primitive::kPrimFloat) {
5547 __ ColeS(0, FTMP, src);
5548 } else {
5549 __ ColeD(0, FTMP, src);
5550 }
5551 __ Bc1t(0, &truncate);
5552
5553 if (input_type == Primitive::kPrimFloat) {
5554 __ CeqS(0, src, src);
5555 } else {
5556 __ CeqD(0, src, src);
5557 }
5558 __ LoadConst32(dst, std::numeric_limits<int32_t>::min());
5559 __ Movf(dst, ZERO, 0);
5560 }
5561
5562 __ B(&done);
5563
5564 __ Bind(&truncate);
5565
5566 if (input_type == Primitive::kPrimFloat) {
5567 __ TruncWS(FTMP, src);
5568 } else {
5569 __ TruncWD(FTMP, src);
5570 }
5571 __ Mfc1(dst, FTMP);
5572
5573 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005574 }
5575 } else if (Primitive::IsFloatingPointType(result_type) &&
5576 Primitive::IsFloatingPointType(input_type)) {
5577 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
5578 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
5579 if (result_type == Primitive::kPrimFloat) {
5580 __ Cvtsd(dst, src);
5581 } else {
5582 __ Cvtds(dst, src);
5583 }
5584 } else {
5585 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
5586 << " to " << result_type;
5587 }
5588}
5589
5590void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) {
5591 HandleShift(ushr);
5592}
5593
5594void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) {
5595 HandleShift(ushr);
5596}
5597
5598void LocationsBuilderMIPS::VisitXor(HXor* instruction) {
5599 HandleBinaryOp(instruction);
5600}
5601
5602void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) {
5603 HandleBinaryOp(instruction);
5604}
5605
5606void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
5607 // Nothing to do, this should be removed during prepare for register allocator.
5608 LOG(FATAL) << "Unreachable";
5609}
5610
5611void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
5612 // Nothing to do, this should be removed during prepare for register allocator.
5613 LOG(FATAL) << "Unreachable";
5614}
5615
5616void LocationsBuilderMIPS::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005617 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005618}
5619
5620void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005621 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005622}
5623
5624void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005625 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005626}
5627
5628void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005629 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005630}
5631
5632void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005633 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005634}
5635
5636void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005637 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005638}
5639
5640void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005641 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005642}
5643
5644void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005645 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005646}
5647
5648void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005649 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005650}
5651
5652void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005653 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005654}
5655
5656void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005657 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005658}
5659
5660void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005661 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005662}
5663
5664void LocationsBuilderMIPS::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005665 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005666}
5667
5668void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005669 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005670}
5671
5672void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005673 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005674}
5675
5676void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005677 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005678}
5679
5680void LocationsBuilderMIPS::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005681 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005682}
5683
5684void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005685 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005686}
5687
5688void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005689 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005690}
5691
5692void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005693 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005694}
5695
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005696void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
5697 LocationSummary* locations =
5698 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
5699 locations->SetInAt(0, Location::RequiresRegister());
5700}
5701
5702void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
5703 int32_t lower_bound = switch_instr->GetStartValue();
5704 int32_t num_entries = switch_instr->GetNumEntries();
5705 LocationSummary* locations = switch_instr->GetLocations();
5706 Register value_reg = locations->InAt(0).AsRegister<Register>();
5707 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
5708
5709 // Create a set of compare/jumps.
Vladimir Markof3e0ee22015-12-17 15:23:13 +00005710 Register temp_reg = TMP;
5711 __ Addiu32(temp_reg, value_reg, -lower_bound);
5712 // Jump to default if index is negative
5713 // Note: We don't check the case that index is positive while value < lower_bound, because in
5714 // this case, index >= num_entries must be true. So that we can save one branch instruction.
5715 __ Bltz(temp_reg, codegen_->GetLabelOf(default_block));
5716
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005717 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00005718 // Jump to successors[0] if value == lower_bound.
5719 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0]));
5720 int32_t last_index = 0;
5721 for (; num_entries - last_index > 2; last_index += 2) {
5722 __ Addiu(temp_reg, temp_reg, -2);
5723 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
5724 __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
5725 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
5726 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2]));
5727 }
5728 if (num_entries - last_index == 2) {
5729 // The last missing case_value.
5730 __ Addiu(temp_reg, temp_reg, -1);
5731 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005732 }
5733
Vladimir Markof3e0ee22015-12-17 15:23:13 +00005734 // And the default for any other value.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005735 if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) {
5736 __ B(codegen_->GetLabelOf(default_block));
5737 }
5738}
5739
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005740void LocationsBuilderMIPS::VisitMipsComputeBaseMethodAddress(
5741 HMipsComputeBaseMethodAddress* insn) {
5742 LocationSummary* locations =
5743 new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall);
5744 locations->SetOut(Location::RequiresRegister());
5745}
5746
5747void InstructionCodeGeneratorMIPS::VisitMipsComputeBaseMethodAddress(
5748 HMipsComputeBaseMethodAddress* insn) {
5749 LocationSummary* locations = insn->GetLocations();
5750 Register reg = locations->Out().AsRegister<Register>();
5751
5752 CHECK(!codegen_->GetInstructionSetFeatures().IsR6());
5753
5754 // Generate a dummy PC-relative call to obtain PC.
5755 __ Nal();
5756 // Grab the return address off RA.
5757 __ Move(reg, RA);
Alexey Frunze06a46c42016-07-19 15:00:40 -07005758 // TODO: Can we share this code with that of VisitMipsDexCacheArraysBase()?
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005759
5760 // Remember this offset (the obtained PC value) for later use with constant area.
5761 __ BindPcRelBaseLabel();
5762}
5763
5764void LocationsBuilderMIPS::VisitMipsDexCacheArraysBase(HMipsDexCacheArraysBase* base) {
5765 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base);
5766 locations->SetOut(Location::RequiresRegister());
5767}
5768
5769void InstructionCodeGeneratorMIPS::VisitMipsDexCacheArraysBase(HMipsDexCacheArraysBase* base) {
5770 Register reg = base->GetLocations()->Out().AsRegister<Register>();
5771 CodeGeneratorMIPS::PcRelativePatchInfo* info =
5772 codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07005773 bool reordering = __ SetReorder(false);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005774 if (codegen_->GetInstructionSetFeatures().IsR6()) {
5775 __ Bind(&info->high_label);
5776 __ Bind(&info->pc_rel_label);
5777 // Add a 32-bit offset to PC.
5778 __ Auipc(reg, /* placeholder */ 0x1234);
5779 __ Addiu(reg, reg, /* placeholder */ 0x5678);
5780 } else {
5781 // Generate a dummy PC-relative call to obtain PC.
5782 __ Nal();
5783 __ Bind(&info->high_label);
5784 __ Lui(reg, /* placeholder */ 0x1234);
5785 __ Bind(&info->pc_rel_label);
5786 __ Ori(reg, reg, /* placeholder */ 0x5678);
5787 // Add a 32-bit offset to PC.
5788 __ Addu(reg, reg, RA);
Alexey Frunze06a46c42016-07-19 15:00:40 -07005789 // TODO: Can we share this code with that of VisitMipsComputeBaseMethodAddress()?
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005790 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -07005791 __ SetReorder(reordering);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005792}
5793
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005794void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
5795 // The trampoline uses the same calling convention as dex calling conventions,
5796 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
5797 // the method_idx.
5798 HandleInvoke(invoke);
5799}
5800
5801void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
5802 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
5803}
5804
Roland Levillain2aba7cd2016-02-03 12:27:20 +00005805void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) {
5806 LocationSummary* locations =
5807 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
5808 locations->SetInAt(0, Location::RequiresRegister());
5809 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00005810}
5811
Roland Levillain2aba7cd2016-02-03 12:27:20 +00005812void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) {
5813 LocationSummary* locations = instruction->GetLocations();
Vladimir Markoa1de9182016-02-25 11:37:38 +00005814 if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01005815 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
Roland Levillain2aba7cd2016-02-03 12:27:20 +00005816 instruction->GetIndex(), kMipsPointerSize).SizeValue();
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01005817 __ LoadFromOffset(kLoadWord,
5818 locations->Out().AsRegister<Register>(),
5819 locations->InAt(0).AsRegister<Register>(),
5820 method_offset);
Roland Levillain2aba7cd2016-02-03 12:27:20 +00005821 } else {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01005822 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00005823 instruction->GetIndex(), kMipsPointerSize));
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00005824 __ LoadFromOffset(kLoadWord,
5825 locations->Out().AsRegister<Register>(),
5826 locations->InAt(0).AsRegister<Register>(),
5827 mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value());
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01005828 __ LoadFromOffset(kLoadWord,
5829 locations->Out().AsRegister<Register>(),
5830 locations->Out().AsRegister<Register>(),
5831 method_offset);
Roland Levillain2aba7cd2016-02-03 12:27:20 +00005832 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00005833}
5834
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005835#undef __
5836#undef QUICK_ENTRY_POINT
5837
5838} // namespace mips
5839} // namespace art