blob: 36bb55ab12e3fa9c8a26ec40fdc07017c5723da3 [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);
Serban Constantinescufca16662016-07-14 09:21:59 +0100174 QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt()
175 ? kQuickThrowStringBounds
176 : kQuickThrowArrayBounds;
177 mips_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100178 CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200179 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
180 }
181
182 bool IsFatal() const OVERRIDE { return true; }
183
184 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS"; }
185
186 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200187 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS);
188};
189
190class DivZeroCheckSlowPathMIPS : public SlowPathCodeMIPS {
191 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000192 explicit DivZeroCheckSlowPathMIPS(HDivZeroCheck* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200193
194 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
195 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
196 __ Bind(GetEntryLabel());
197 if (instruction_->CanThrowIntoCatchBlock()) {
198 // Live registers will be restored in the catch block if caught.
199 SaveLiveRegisters(codegen, instruction_->GetLocations());
200 }
Serban Constantinescufca16662016-07-14 09:21:59 +0100201 mips_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200202 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
203 }
204
205 bool IsFatal() const OVERRIDE { return true; }
206
207 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS"; }
208
209 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200210 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS);
211};
212
213class LoadClassSlowPathMIPS : public SlowPathCodeMIPS {
214 public:
215 LoadClassSlowPathMIPS(HLoadClass* cls,
216 HInstruction* at,
217 uint32_t dex_pc,
218 bool do_clinit)
David Srbecky9cd6d372016-02-09 15:24:47 +0000219 : SlowPathCodeMIPS(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200220 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
221 }
222
223 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
224 LocationSummary* locations = at_->GetLocations();
225 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
226
227 __ Bind(GetEntryLabel());
228 SaveLiveRegisters(codegen, locations);
229
230 InvokeRuntimeCallingConvention calling_convention;
231 __ LoadConst32(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
232
Serban Constantinescufca16662016-07-14 09:21:59 +0100233 QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage
234 : kQuickInitializeType;
235 mips_codegen->InvokeRuntime(entrypoint, at_, dex_pc_, this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200236 if (do_clinit_) {
237 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
238 } else {
239 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
240 }
241
242 // Move the class to the desired location.
243 Location out = locations->Out();
244 if (out.IsValid()) {
245 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
246 Primitive::Type type = at_->GetType();
247 mips_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type);
248 }
249
250 RestoreLiveRegisters(codegen, locations);
251 __ B(GetExitLabel());
252 }
253
254 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS"; }
255
256 private:
257 // The class this slow path will load.
258 HLoadClass* const cls_;
259
260 // The instruction where this slow path is happening.
261 // (Might be the load class or an initialization check).
262 HInstruction* const at_;
263
264 // The dex PC of `at_`.
265 const uint32_t dex_pc_;
266
267 // Whether to initialize the class.
268 const bool do_clinit_;
269
270 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS);
271};
272
273class LoadStringSlowPathMIPS : public SlowPathCodeMIPS {
274 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000275 explicit LoadStringSlowPathMIPS(HLoadString* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200276
277 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
278 LocationSummary* locations = instruction_->GetLocations();
279 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
280 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
281
282 __ Bind(GetEntryLabel());
283 SaveLiveRegisters(codegen, locations);
284
285 InvokeRuntimeCallingConvention calling_convention;
David Srbecky9cd6d372016-02-09 15:24:47 +0000286 const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex();
287 __ LoadConst32(calling_convention.GetRegisterAt(0), string_index);
Serban Constantinescufca16662016-07-14 09:21:59 +0100288 mips_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200289 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
290 Primitive::Type type = instruction_->GetType();
291 mips_codegen->MoveLocation(locations->Out(),
292 calling_convention.GetReturnLocation(type),
293 type);
294
295 RestoreLiveRegisters(codegen, locations);
296 __ B(GetExitLabel());
297 }
298
299 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS"; }
300
301 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200302 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS);
303};
304
305class NullCheckSlowPathMIPS : public SlowPathCodeMIPS {
306 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000307 explicit NullCheckSlowPathMIPS(HNullCheck* instr) : SlowPathCodeMIPS(instr) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200308
309 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
310 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
311 __ Bind(GetEntryLabel());
312 if (instruction_->CanThrowIntoCatchBlock()) {
313 // Live registers will be restored in the catch block if caught.
314 SaveLiveRegisters(codegen, instruction_->GetLocations());
315 }
Serban Constantinescufca16662016-07-14 09:21:59 +0100316 mips_codegen->InvokeRuntime(kQuickThrowNullPointer,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200317 instruction_,
318 instruction_->GetDexPc(),
Serban Constantinescufca16662016-07-14 09:21:59 +0100319 this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200320 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
321 }
322
323 bool IsFatal() const OVERRIDE { return true; }
324
325 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS"; }
326
327 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200328 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS);
329};
330
331class SuspendCheckSlowPathMIPS : public SlowPathCodeMIPS {
332 public:
333 SuspendCheckSlowPathMIPS(HSuspendCheck* instruction, HBasicBlock* successor)
David Srbecky9cd6d372016-02-09 15:24:47 +0000334 : SlowPathCodeMIPS(instruction), successor_(successor) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200335
336 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
337 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
338 __ Bind(GetEntryLabel());
Serban Constantinescufca16662016-07-14 09:21:59 +0100339 mips_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200340 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200341 if (successor_ == nullptr) {
342 __ B(GetReturnLabel());
343 } else {
344 __ B(mips_codegen->GetLabelOf(successor_));
345 }
346 }
347
348 MipsLabel* GetReturnLabel() {
349 DCHECK(successor_ == nullptr);
350 return &return_label_;
351 }
352
353 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS"; }
354
355 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200356 // If not null, the block to branch to after the suspend check.
357 HBasicBlock* const successor_;
358
359 // If `successor_` is null, the label to branch to after the suspend check.
360 MipsLabel return_label_;
361
362 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS);
363};
364
365class TypeCheckSlowPathMIPS : public SlowPathCodeMIPS {
366 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000367 explicit TypeCheckSlowPathMIPS(HInstruction* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200368
369 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
370 LocationSummary* locations = instruction_->GetLocations();
371 Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) : locations->Out();
372 uint32_t dex_pc = instruction_->GetDexPc();
373 DCHECK(instruction_->IsCheckCast()
374 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
375 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
376
377 __ Bind(GetEntryLabel());
378 SaveLiveRegisters(codegen, locations);
379
380 // We're moving two locations to locations that could overlap, so we need a parallel
381 // move resolver.
382 InvokeRuntimeCallingConvention calling_convention;
383 codegen->EmitParallelMoves(locations->InAt(1),
384 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
385 Primitive::kPrimNot,
386 object_class,
387 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
388 Primitive::kPrimNot);
389
390 if (instruction_->IsInstanceOf()) {
Serban Constantinescufca16662016-07-14 09:21:59 +0100391 mips_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this);
Roland Levillain888d0672015-11-23 18:53:50 +0000392 CheckEntrypointTypes<
Andreas Gampe67409972016-07-19 22:34:53 -0700393 kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200394 Primitive::Type ret_type = instruction_->GetType();
395 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
396 mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200397 } else {
398 DCHECK(instruction_->IsCheckCast());
Serban Constantinescufca16662016-07-14 09:21:59 +0100399 mips_codegen->InvokeRuntime(kQuickCheckCast, instruction_, dex_pc, this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200400 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
401 }
402
403 RestoreLiveRegisters(codegen, locations);
404 __ B(GetExitLabel());
405 }
406
407 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; }
408
409 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200410 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS);
411};
412
413class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS {
414 public:
Aart Bik42249c32016-01-07 15:33:50 -0800415 explicit DeoptimizationSlowPathMIPS(HDeoptimize* instruction)
David Srbecky9cd6d372016-02-09 15:24:47 +0000416 : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200417
418 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Aart Bik42249c32016-01-07 15:33:50 -0800419 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200420 __ Bind(GetEntryLabel());
421 SaveLiveRegisters(codegen, instruction_->GetLocations());
Serban Constantinescufca16662016-07-14 09:21:59 +0100422 mips_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000423 CheckEntrypointTypes<kQuickDeoptimize, void, void>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200424 }
425
426 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; }
427
428 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200429 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS);
430};
431
432CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph,
433 const MipsInstructionSetFeatures& isa_features,
434 const CompilerOptions& compiler_options,
435 OptimizingCompilerStats* stats)
436 : CodeGenerator(graph,
437 kNumberOfCoreRegisters,
438 kNumberOfFRegisters,
439 kNumberOfRegisterPairs,
440 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
441 arraysize(kCoreCalleeSaves)),
442 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
443 arraysize(kFpuCalleeSaves)),
444 compiler_options,
445 stats),
446 block_labels_(nullptr),
447 location_builder_(graph, this),
448 instruction_visitor_(graph, this),
449 move_resolver_(graph->GetArena(), this),
Vladimir Marko93205e32016-04-13 11:59:46 +0100450 assembler_(graph->GetArena(), &isa_features),
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700451 isa_features_(isa_features),
Alexey Frunze06a46c42016-07-19 15:00:40 -0700452 uint32_literals_(std::less<uint32_t>(),
453 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700454 method_patches_(MethodReferenceComparator(),
455 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
456 call_patches_(MethodReferenceComparator(),
457 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunze06a46c42016-07-19 15:00:40 -0700458 pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
459 boot_image_string_patches_(StringReferenceValueComparator(),
460 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
461 pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
462 boot_image_type_patches_(TypeReferenceValueComparator(),
463 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
464 pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
465 boot_image_address_patches_(std::less<uint32_t>(),
466 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
467 clobbered_ra_(false) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200468 // Save RA (containing the return address) to mimic Quick.
469 AddAllocatedRegister(Location::RegisterLocation(RA));
470}
471
472#undef __
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100473// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
474#define __ down_cast<MipsAssembler*>(GetAssembler())-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -0700475#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value()
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200476
477void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) {
478 // Ensure that we fix up branches.
479 __ FinalizeCode();
480
481 // Adjust native pc offsets in stack maps.
482 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
483 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
484 uint32_t new_position = __ GetAdjustedPosition(old_position);
485 DCHECK_GE(new_position, old_position);
486 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
487 }
488
489 // Adjust pc offsets for the disassembly information.
490 if (disasm_info_ != nullptr) {
491 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
492 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
493 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
494 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
495 it.second.start = __ GetAdjustedPosition(it.second.start);
496 it.second.end = __ GetAdjustedPosition(it.second.end);
497 }
498 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
499 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
500 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
501 }
502 }
503
504 CodeGenerator::Finalize(allocator);
505}
506
507MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const {
508 return codegen_->GetAssembler();
509}
510
511void ParallelMoveResolverMIPS::EmitMove(size_t index) {
512 DCHECK_LT(index, moves_.size());
513 MoveOperands* move = moves_[index];
514 codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType());
515}
516
517void ParallelMoveResolverMIPS::EmitSwap(size_t index) {
518 DCHECK_LT(index, moves_.size());
519 MoveOperands* move = moves_[index];
520 Primitive::Type type = move->GetType();
521 Location loc1 = move->GetDestination();
522 Location loc2 = move->GetSource();
523
524 DCHECK(!loc1.IsConstant());
525 DCHECK(!loc2.IsConstant());
526
527 if (loc1.Equals(loc2)) {
528 return;
529 }
530
531 if (loc1.IsRegister() && loc2.IsRegister()) {
532 // Swap 2 GPRs.
533 Register r1 = loc1.AsRegister<Register>();
534 Register r2 = loc2.AsRegister<Register>();
535 __ Move(TMP, r2);
536 __ Move(r2, r1);
537 __ Move(r1, TMP);
538 } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) {
539 FRegister f1 = loc1.AsFpuRegister<FRegister>();
540 FRegister f2 = loc2.AsFpuRegister<FRegister>();
541 if (type == Primitive::kPrimFloat) {
542 __ MovS(FTMP, f2);
543 __ MovS(f2, f1);
544 __ MovS(f1, FTMP);
545 } else {
546 DCHECK_EQ(type, Primitive::kPrimDouble);
547 __ MovD(FTMP, f2);
548 __ MovD(f2, f1);
549 __ MovD(f1, FTMP);
550 }
551 } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) ||
552 (loc1.IsFpuRegister() && loc2.IsRegister())) {
553 // Swap FPR and GPR.
554 DCHECK_EQ(type, Primitive::kPrimFloat); // Can only swap a float.
555 FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
556 : loc2.AsFpuRegister<FRegister>();
557 Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>()
558 : loc2.AsRegister<Register>();
559 __ Move(TMP, r2);
560 __ Mfc1(r2, f1);
561 __ Mtc1(TMP, f1);
562 } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) {
563 // Swap 2 GPR register pairs.
564 Register r1 = loc1.AsRegisterPairLow<Register>();
565 Register r2 = loc2.AsRegisterPairLow<Register>();
566 __ Move(TMP, r2);
567 __ Move(r2, r1);
568 __ Move(r1, TMP);
569 r1 = loc1.AsRegisterPairHigh<Register>();
570 r2 = loc2.AsRegisterPairHigh<Register>();
571 __ Move(TMP, r2);
572 __ Move(r2, r1);
573 __ Move(r1, TMP);
574 } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) ||
575 (loc1.IsFpuRegister() && loc2.IsRegisterPair())) {
576 // Swap FPR and GPR register pair.
577 DCHECK_EQ(type, Primitive::kPrimDouble);
578 FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
579 : loc2.AsFpuRegister<FRegister>();
580 Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>()
581 : loc2.AsRegisterPairLow<Register>();
582 Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>()
583 : loc2.AsRegisterPairHigh<Register>();
584 // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and
585 // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR
586 // unpredictable and the following mfch1 will fail.
587 __ Mfc1(TMP, f1);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800588 __ MoveFromFpuHigh(AT, f1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200589 __ Mtc1(r2_l, f1);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800590 __ MoveToFpuHigh(r2_h, f1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200591 __ Move(r2_l, TMP);
592 __ Move(r2_h, AT);
593 } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) {
594 Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false);
595 } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) {
596 Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true);
David Brazdilcc0f3112016-01-28 17:14:52 +0000597 } else if ((loc1.IsRegister() && loc2.IsStackSlot()) ||
598 (loc1.IsStackSlot() && loc2.IsRegister())) {
599 Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>()
600 : loc2.AsRegister<Register>();
601 intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex()
602 : loc2.GetStackIndex();
603 __ Move(TMP, reg);
604 __ LoadFromOffset(kLoadWord, reg, SP, offset);
605 __ StoreToOffset(kStoreWord, TMP, SP, offset);
606 } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) ||
607 (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) {
608 Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>()
609 : loc2.AsRegisterPairLow<Register>();
610 Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>()
611 : loc2.AsRegisterPairHigh<Register>();
612 intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex()
613 : loc2.GetStackIndex();
614 intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize)
615 : loc2.GetHighStackIndex(kMipsWordSize);
616 __ Move(TMP, reg_l);
David Brazdilcc0f3112016-01-28 17:14:52 +0000617 __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l);
David Brazdilcc0f3112016-01-28 17:14:52 +0000618 __ StoreToOffset(kStoreWord, TMP, SP, offset_l);
David Brazdil04d3e872016-01-29 09:50:09 +0000619 __ Move(TMP, reg_h);
620 __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h);
621 __ StoreToOffset(kStoreWord, TMP, SP, offset_h);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200622 } else {
623 LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported";
624 }
625}
626
627void ParallelMoveResolverMIPS::RestoreScratch(int reg) {
628 __ Pop(static_cast<Register>(reg));
629}
630
631void ParallelMoveResolverMIPS::SpillScratch(int reg) {
632 __ Push(static_cast<Register>(reg));
633}
634
635void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) {
636 // Allocate a scratch register other than TMP, if available.
637 // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be
638 // automatically unspilled when the scratch scope object is destroyed).
639 ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters());
640 // If V0 spills onto the stack, SP-relative offsets need to be adjusted.
641 int stack_offset = ensure_scratch.IsSpilled() ? kMipsWordSize : 0;
642 for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) {
643 __ LoadFromOffset(kLoadWord,
644 Register(ensure_scratch.GetRegister()),
645 SP,
646 index1 + stack_offset);
647 __ LoadFromOffset(kLoadWord,
648 TMP,
649 SP,
650 index2 + stack_offset);
651 __ StoreToOffset(kStoreWord,
652 Register(ensure_scratch.GetRegister()),
653 SP,
654 index2 + stack_offset);
655 __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset);
656 }
657}
658
Alexey Frunze73296a72016-06-03 22:51:46 -0700659void CodeGeneratorMIPS::ComputeSpillMask() {
660 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
661 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
662 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
663 // If there're FPU callee-saved registers and there's an odd number of GPR callee-saved
664 // registers, include the ZERO register to force alignment of FPU callee-saved registers
665 // within the stack frame.
666 if ((fpu_spill_mask_ != 0) && (POPCOUNT(core_spill_mask_) % 2 != 0)) {
667 core_spill_mask_ |= (1 << ZERO);
668 }
Alexey Frunze58320ce2016-08-30 21:40:46 -0700669}
670
671bool CodeGeneratorMIPS::HasAllocatedCalleeSaveRegisters() const {
Alexey Frunze06a46c42016-07-19 15:00:40 -0700672 // If RA is clobbered by PC-relative operations on R2 and it's the only spilled register
Alexey Frunze58320ce2016-08-30 21:40:46 -0700673 // (this can happen in leaf methods), force CodeGenerator::InitializeCodeGeneration()
674 // into the path that creates a stack frame so that RA can be explicitly saved and restored.
675 // RA can't otherwise be saved/restored when it's the only spilled register.
Alexey Frunze06a46c42016-07-19 15:00:40 -0700676 // TODO: Can this be improved? It causes creation of a stack frame (while RA might be
677 // saved in an unused temporary register) and saving of RA and the current method pointer
678 // in the frame.
Alexey Frunze58320ce2016-08-30 21:40:46 -0700679 return CodeGenerator::HasAllocatedCalleeSaveRegisters() || clobbered_ra_;
Alexey Frunze73296a72016-06-03 22:51:46 -0700680}
681
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200682static dwarf::Reg DWARFReg(Register reg) {
683 return dwarf::Reg::MipsCore(static_cast<int>(reg));
684}
685
686// TODO: mapping of floating-point registers to DWARF.
687
688void CodeGeneratorMIPS::GenerateFrameEntry() {
689 __ Bind(&frame_entry_label_);
690
691 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips) || !IsLeafMethod();
692
693 if (do_overflow_check) {
694 __ LoadFromOffset(kLoadWord,
695 ZERO,
696 SP,
697 -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips)));
698 RecordPcInfo(nullptr, 0);
699 }
700
701 if (HasEmptyFrame()) {
Alexey Frunze58320ce2016-08-30 21:40:46 -0700702 CHECK_EQ(fpu_spill_mask_, 0u);
703 CHECK_EQ(core_spill_mask_, 1u << RA);
704 CHECK(!clobbered_ra_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200705 return;
706 }
707
708 // Make sure the frame size isn't unreasonably large.
709 if (GetFrameSize() > GetStackOverflowReservedBytes(kMips)) {
710 LOG(FATAL) << "Stack frame larger than " << GetStackOverflowReservedBytes(kMips) << " bytes";
711 }
712
713 // Spill callee-saved registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200714
Alexey Frunze73296a72016-06-03 22:51:46 -0700715 uint32_t ofs = GetFrameSize();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200716 __ IncreaseFrameSize(ofs);
717
Alexey Frunze73296a72016-06-03 22:51:46 -0700718 for (uint32_t mask = core_spill_mask_; mask != 0; ) {
719 Register reg = static_cast<Register>(MostSignificantBit(mask));
720 mask ^= 1u << reg;
721 ofs -= kMipsWordSize;
722 // The ZERO register is only included for alignment.
723 if (reg != ZERO) {
724 __ StoreToOffset(kStoreWord, reg, SP, ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200725 __ cfi().RelOffset(DWARFReg(reg), ofs);
726 }
727 }
728
Alexey Frunze73296a72016-06-03 22:51:46 -0700729 for (uint32_t mask = fpu_spill_mask_; mask != 0; ) {
730 FRegister reg = static_cast<FRegister>(MostSignificantBit(mask));
731 mask ^= 1u << reg;
732 ofs -= kMipsDoublewordSize;
733 __ StoreDToOffset(reg, SP, ofs);
734 // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200735 }
736
Alexey Frunze73296a72016-06-03 22:51:46 -0700737 // Store the current method pointer.
Alexey Frunze58320ce2016-08-30 21:40:46 -0700738 // TODO: can we not do this if RequiresCurrentMethod() returns false?
Alexey Frunze73296a72016-06-03 22:51:46 -0700739 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, kCurrentMethodStackOffset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200740}
741
742void CodeGeneratorMIPS::GenerateFrameExit() {
743 __ cfi().RememberState();
744
745 if (!HasEmptyFrame()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200746 // Restore callee-saved registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200747
Alexey Frunze73296a72016-06-03 22:51:46 -0700748 // For better instruction scheduling restore RA before other registers.
749 uint32_t ofs = GetFrameSize();
750 for (uint32_t mask = core_spill_mask_; mask != 0; ) {
751 Register reg = static_cast<Register>(MostSignificantBit(mask));
752 mask ^= 1u << reg;
753 ofs -= kMipsWordSize;
754 // The ZERO register is only included for alignment.
755 if (reg != ZERO) {
756 __ LoadFromOffset(kLoadWord, reg, SP, ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200757 __ cfi().Restore(DWARFReg(reg));
758 }
759 }
760
Alexey Frunze73296a72016-06-03 22:51:46 -0700761 for (uint32_t mask = fpu_spill_mask_; mask != 0; ) {
762 FRegister reg = static_cast<FRegister>(MostSignificantBit(mask));
763 mask ^= 1u << reg;
764 ofs -= kMipsDoublewordSize;
765 __ LoadDFromOffset(reg, SP, ofs);
766 // TODO: __ cfi().Restore(DWARFReg(reg));
767 }
768
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700769 size_t frame_size = GetFrameSize();
770 // Adjust the stack pointer in the delay slot if doing so doesn't break CFI.
771 bool exchange = IsInt<16>(static_cast<int32_t>(frame_size));
772 bool reordering = __ SetReorder(false);
773 if (exchange) {
774 __ Jr(RA);
775 __ DecreaseFrameSize(frame_size); // Single instruction in delay slot.
776 } else {
777 __ DecreaseFrameSize(frame_size);
778 __ Jr(RA);
779 __ Nop(); // In delay slot.
780 }
781 __ SetReorder(reordering);
782 } else {
783 __ Jr(RA);
784 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200785 }
786
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200787 __ cfi().RestoreState();
788 __ cfi().DefCFAOffset(GetFrameSize());
789}
790
791void CodeGeneratorMIPS::Bind(HBasicBlock* block) {
792 __ Bind(GetLabelOf(block));
793}
794
795void CodeGeneratorMIPS::MoveLocation(Location dst, Location src, Primitive::Type dst_type) {
796 if (src.Equals(dst)) {
797 return;
798 }
799
800 if (src.IsConstant()) {
801 MoveConstant(dst, src.GetConstant());
802 } else {
803 if (Primitive::Is64BitType(dst_type)) {
804 Move64(dst, src);
805 } else {
806 Move32(dst, src);
807 }
808 }
809}
810
811void CodeGeneratorMIPS::Move32(Location destination, Location source) {
812 if (source.Equals(destination)) {
813 return;
814 }
815
816 if (destination.IsRegister()) {
817 if (source.IsRegister()) {
818 __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>());
819 } else if (source.IsFpuRegister()) {
820 __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>());
821 } else {
822 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
823 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
824 }
825 } else if (destination.IsFpuRegister()) {
826 if (source.IsRegister()) {
827 __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>());
828 } else if (source.IsFpuRegister()) {
829 __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>());
830 } else {
831 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
832 __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
833 }
834 } else {
835 DCHECK(destination.IsStackSlot()) << destination;
836 if (source.IsRegister()) {
837 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
838 } else if (source.IsFpuRegister()) {
839 __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex());
840 } else {
841 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
842 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
843 __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex());
844 }
845 }
846}
847
848void CodeGeneratorMIPS::Move64(Location destination, Location source) {
849 if (source.Equals(destination)) {
850 return;
851 }
852
853 if (destination.IsRegisterPair()) {
854 if (source.IsRegisterPair()) {
855 __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
856 __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
857 } else if (source.IsFpuRegister()) {
858 Register dst_high = destination.AsRegisterPairHigh<Register>();
859 Register dst_low = destination.AsRegisterPairLow<Register>();
860 FRegister src = source.AsFpuRegister<FRegister>();
861 __ Mfc1(dst_low, src);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800862 __ MoveFromFpuHigh(dst_high, src);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200863 } else {
864 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
865 int32_t off = source.GetStackIndex();
866 Register r = destination.AsRegisterPairLow<Register>();
867 __ LoadFromOffset(kLoadDoubleword, r, SP, off);
868 }
869 } else if (destination.IsFpuRegister()) {
870 if (source.IsRegisterPair()) {
871 FRegister dst = destination.AsFpuRegister<FRegister>();
872 Register src_high = source.AsRegisterPairHigh<Register>();
873 Register src_low = source.AsRegisterPairLow<Register>();
874 __ Mtc1(src_low, dst);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800875 __ MoveToFpuHigh(src_high, dst);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200876 } else if (source.IsFpuRegister()) {
877 __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>());
878 } else {
879 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
880 __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
881 }
882 } else {
883 DCHECK(destination.IsDoubleStackSlot()) << destination;
884 int32_t off = destination.GetStackIndex();
885 if (source.IsRegisterPair()) {
886 __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, off);
887 } else if (source.IsFpuRegister()) {
888 __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, off);
889 } else {
890 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
891 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
892 __ StoreToOffset(kStoreWord, TMP, SP, off);
893 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4);
894 __ StoreToOffset(kStoreWord, TMP, SP, off + 4);
895 }
896 }
897}
898
899void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) {
900 if (c->IsIntConstant() || c->IsNullConstant()) {
901 // Move 32 bit constant.
902 int32_t value = GetInt32ValueOf(c);
903 if (destination.IsRegister()) {
904 Register dst = destination.AsRegister<Register>();
905 __ LoadConst32(dst, value);
906 } else {
907 DCHECK(destination.IsStackSlot())
908 << "Cannot move " << c->DebugName() << " to " << destination;
909 __ StoreConst32ToOffset(value, SP, destination.GetStackIndex(), TMP);
910 }
911 } else if (c->IsLongConstant()) {
912 // Move 64 bit constant.
913 int64_t value = GetInt64ValueOf(c);
914 if (destination.IsRegisterPair()) {
915 Register r_h = destination.AsRegisterPairHigh<Register>();
916 Register r_l = destination.AsRegisterPairLow<Register>();
917 __ LoadConst64(r_h, r_l, value);
918 } else {
919 DCHECK(destination.IsDoubleStackSlot())
920 << "Cannot move " << c->DebugName() << " to " << destination;
921 __ StoreConst64ToOffset(value, SP, destination.GetStackIndex(), TMP);
922 }
923 } else if (c->IsFloatConstant()) {
924 // Move 32 bit float constant.
925 int32_t value = GetInt32ValueOf(c);
926 if (destination.IsFpuRegister()) {
927 __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP);
928 } else {
929 DCHECK(destination.IsStackSlot())
930 << "Cannot move " << c->DebugName() << " to " << destination;
931 __ StoreConst32ToOffset(value, SP, destination.GetStackIndex(), TMP);
932 }
933 } else {
934 // Move 64 bit double constant.
935 DCHECK(c->IsDoubleConstant()) << c->DebugName();
936 int64_t value = GetInt64ValueOf(c);
937 if (destination.IsFpuRegister()) {
938 FRegister fd = destination.AsFpuRegister<FRegister>();
939 __ LoadDConst64(fd, value, TMP);
940 } else {
941 DCHECK(destination.IsDoubleStackSlot())
942 << "Cannot move " << c->DebugName() << " to " << destination;
943 __ StoreConst64ToOffset(value, SP, destination.GetStackIndex(), TMP);
944 }
945 }
946}
947
948void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) {
949 DCHECK(destination.IsRegister());
950 Register dst = destination.AsRegister<Register>();
951 __ LoadConst32(dst, value);
952}
953
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200954void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) {
955 if (location.IsRegister()) {
956 locations->AddTemp(location);
Alexey Frunzec9e94f32015-10-26 16:11:39 -0700957 } else if (location.IsRegisterPair()) {
958 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>()));
959 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>()));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200960 } else {
961 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
962 }
963}
964
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700965void CodeGeneratorMIPS::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) {
966 DCHECK(linker_patches->empty());
967 size_t size =
968 method_patches_.size() +
969 call_patches_.size() +
Alexey Frunze06a46c42016-07-19 15:00:40 -0700970 pc_relative_dex_cache_patches_.size() +
971 pc_relative_string_patches_.size() +
972 pc_relative_type_patches_.size() +
973 boot_image_string_patches_.size() +
974 boot_image_type_patches_.size() +
975 boot_image_address_patches_.size();
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700976 linker_patches->reserve(size);
977 for (const auto& entry : method_patches_) {
978 const MethodReference& target_method = entry.first;
979 Literal* literal = entry.second;
980 DCHECK(literal->GetLabel()->IsBound());
981 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
982 linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset,
983 target_method.dex_file,
984 target_method.dex_method_index));
985 }
986 for (const auto& entry : call_patches_) {
987 const MethodReference& target_method = entry.first;
988 Literal* literal = entry.second;
989 DCHECK(literal->GetLabel()->IsBound());
990 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
991 linker_patches->push_back(LinkerPatch::CodePatch(literal_offset,
992 target_method.dex_file,
993 target_method.dex_method_index));
994 }
995 for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) {
996 const DexFile& dex_file = info.target_dex_file;
997 size_t base_element_offset = info.offset_or_index;
998 DCHECK(info.high_label.IsBound());
999 uint32_t high_offset = __ GetLabelLocation(&info.high_label);
1000 DCHECK(info.pc_rel_label.IsBound());
1001 uint32_t pc_rel_offset = __ GetLabelLocation(&info.pc_rel_label);
1002 linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(high_offset,
1003 &dex_file,
1004 pc_rel_offset,
1005 base_element_offset));
1006 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07001007 for (const PcRelativePatchInfo& info : pc_relative_string_patches_) {
1008 const DexFile& dex_file = info.target_dex_file;
1009 size_t string_index = info.offset_or_index;
1010 DCHECK(info.high_label.IsBound());
1011 uint32_t high_offset = __ GetLabelLocation(&info.high_label);
1012 // On R2 we use HMipsComputeBaseMethodAddress and patch relative to
1013 // the assembler's base label used for PC-relative literals.
1014 uint32_t pc_rel_offset = info.pc_rel_label.IsBound()
1015 ? __ GetLabelLocation(&info.pc_rel_label)
1016 : __ GetPcRelBaseLabelLocation();
1017 linker_patches->push_back(LinkerPatch::RelativeStringPatch(high_offset,
1018 &dex_file,
1019 pc_rel_offset,
1020 string_index));
1021 }
1022 for (const PcRelativePatchInfo& info : pc_relative_type_patches_) {
1023 const DexFile& dex_file = info.target_dex_file;
1024 size_t type_index = info.offset_or_index;
1025 DCHECK(info.high_label.IsBound());
1026 uint32_t high_offset = __ GetLabelLocation(&info.high_label);
1027 // On R2 we use HMipsComputeBaseMethodAddress and patch relative to
1028 // the assembler's base label used for PC-relative literals.
1029 uint32_t pc_rel_offset = info.pc_rel_label.IsBound()
1030 ? __ GetLabelLocation(&info.pc_rel_label)
1031 : __ GetPcRelBaseLabelLocation();
1032 linker_patches->push_back(LinkerPatch::RelativeTypePatch(high_offset,
1033 &dex_file,
1034 pc_rel_offset,
1035 type_index));
1036 }
1037 for (const auto& entry : boot_image_string_patches_) {
1038 const StringReference& target_string = entry.first;
1039 Literal* literal = entry.second;
1040 DCHECK(literal->GetLabel()->IsBound());
1041 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1042 linker_patches->push_back(LinkerPatch::StringPatch(literal_offset,
1043 target_string.dex_file,
1044 target_string.string_index));
1045 }
1046 for (const auto& entry : boot_image_type_patches_) {
1047 const TypeReference& target_type = entry.first;
1048 Literal* literal = entry.second;
1049 DCHECK(literal->GetLabel()->IsBound());
1050 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1051 linker_patches->push_back(LinkerPatch::TypePatch(literal_offset,
1052 target_type.dex_file,
1053 target_type.type_index));
1054 }
1055 for (const auto& entry : boot_image_address_patches_) {
1056 DCHECK(GetCompilerOptions().GetIncludePatchInformation());
1057 Literal* literal = entry.second;
1058 DCHECK(literal->GetLabel()->IsBound());
1059 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1060 linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset));
1061 }
1062}
1063
1064CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeStringPatch(
1065 const DexFile& dex_file, uint32_t string_index) {
1066 return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_);
1067}
1068
1069CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeTypePatch(
1070 const DexFile& dex_file, uint32_t type_index) {
1071 return NewPcRelativePatch(dex_file, type_index, &pc_relative_type_patches_);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001072}
1073
1074CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeDexCacheArrayPatch(
1075 const DexFile& dex_file, uint32_t element_offset) {
1076 return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_);
1077}
1078
1079CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativePatch(
1080 const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) {
1081 patches->emplace_back(dex_file, offset_or_index);
1082 return &patches->back();
1083}
1084
Alexey Frunze06a46c42016-07-19 15:00:40 -07001085Literal* CodeGeneratorMIPS::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) {
1086 return map->GetOrCreate(
1087 value,
1088 [this, value]() { return __ NewLiteral<uint32_t>(value); });
1089}
1090
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001091Literal* CodeGeneratorMIPS::DeduplicateMethodLiteral(MethodReference target_method,
1092 MethodToLiteralMap* map) {
1093 return map->GetOrCreate(
1094 target_method,
1095 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1096}
1097
1098Literal* CodeGeneratorMIPS::DeduplicateMethodAddressLiteral(MethodReference target_method) {
1099 return DeduplicateMethodLiteral(target_method, &method_patches_);
1100}
1101
1102Literal* CodeGeneratorMIPS::DeduplicateMethodCodeLiteral(MethodReference target_method) {
1103 return DeduplicateMethodLiteral(target_method, &call_patches_);
1104}
1105
Alexey Frunze06a46c42016-07-19 15:00:40 -07001106Literal* CodeGeneratorMIPS::DeduplicateBootImageStringLiteral(const DexFile& dex_file,
1107 uint32_t string_index) {
1108 return boot_image_string_patches_.GetOrCreate(
1109 StringReference(&dex_file, string_index),
1110 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1111}
1112
1113Literal* CodeGeneratorMIPS::DeduplicateBootImageTypeLiteral(const DexFile& dex_file,
1114 uint32_t type_index) {
1115 return boot_image_type_patches_.GetOrCreate(
1116 TypeReference(&dex_file, type_index),
1117 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1118}
1119
1120Literal* CodeGeneratorMIPS::DeduplicateBootImageAddressLiteral(uint32_t address) {
1121 bool needs_patch = GetCompilerOptions().GetIncludePatchInformation();
1122 Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_;
1123 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map);
1124}
1125
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001126void CodeGeneratorMIPS::MarkGCCard(Register object, Register value) {
1127 MipsLabel done;
1128 Register card = AT;
1129 Register temp = TMP;
1130 __ Beqz(value, &done);
1131 __ LoadFromOffset(kLoadWord,
1132 card,
1133 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001134 Thread::CardTableOffset<kMipsPointerSize>().Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001135 __ Srl(temp, object, gc::accounting::CardTable::kCardShift);
1136 __ Addu(temp, card, temp);
1137 __ Sb(card, temp, 0);
1138 __ Bind(&done);
1139}
1140
David Brazdil58282f42016-01-14 12:45:10 +00001141void CodeGeneratorMIPS::SetupBlockedRegisters() const {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001142 // Don't allocate the dalvik style register pair passing.
1143 blocked_register_pairs_[A1_A2] = true;
1144
1145 // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated.
1146 blocked_core_registers_[ZERO] = true;
1147 blocked_core_registers_[K0] = true;
1148 blocked_core_registers_[K1] = true;
1149 blocked_core_registers_[GP] = true;
1150 blocked_core_registers_[SP] = true;
1151 blocked_core_registers_[RA] = true;
1152
1153 // AT and TMP(T8) are used as temporary/scratch registers
1154 // (similar to how AT is used by MIPS assemblers).
1155 blocked_core_registers_[AT] = true;
1156 blocked_core_registers_[TMP] = true;
1157 blocked_fpu_registers_[FTMP] = true;
1158
1159 // Reserve suspend and thread registers.
1160 blocked_core_registers_[S0] = true;
1161 blocked_core_registers_[TR] = true;
1162
1163 // Reserve T9 for function calls
1164 blocked_core_registers_[T9] = true;
1165
1166 // Reserve odd-numbered FPU registers.
1167 for (size_t i = 1; i < kNumberOfFRegisters; i += 2) {
1168 blocked_fpu_registers_[i] = true;
1169 }
1170
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02001171 if (GetGraph()->IsDebuggable()) {
1172 // Stubs do not save callee-save floating point registers. If the graph
1173 // is debuggable, we need to deal with these registers differently. For
1174 // now, just block them.
1175 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
1176 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
1177 }
1178 }
1179
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001180 UpdateBlockedPairRegisters();
1181}
1182
1183void CodeGeneratorMIPS::UpdateBlockedPairRegisters() const {
1184 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
1185 MipsManagedRegister current =
1186 MipsManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
1187 if (blocked_core_registers_[current.AsRegisterPairLow()]
1188 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
1189 blocked_register_pairs_[i] = true;
1190 }
1191 }
1192}
1193
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001194size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
1195 __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index);
1196 return kMipsWordSize;
1197}
1198
1199size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
1200 __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index);
1201 return kMipsWordSize;
1202}
1203
1204size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1205 __ StoreDToOffset(FRegister(reg_id), SP, stack_index);
1206 return kMipsDoublewordSize;
1207}
1208
1209size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1210 __ LoadDFromOffset(FRegister(reg_id), SP, stack_index);
1211 return kMipsDoublewordSize;
1212}
1213
1214void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const {
Vladimir Marko623a7a22016-02-02 18:14:52 +00001215 stream << Register(reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001216}
1217
1218void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Vladimir Marko623a7a22016-02-02 18:14:52 +00001219 stream << FRegister(reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001220}
1221
Serban Constantinescufca16662016-07-14 09:21:59 +01001222constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16;
1223
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001224void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint,
1225 HInstruction* instruction,
1226 uint32_t dex_pc,
1227 SlowPathCode* slow_path) {
Serban Constantinescufca16662016-07-14 09:21:59 +01001228 ValidateInvokeRuntime(instruction, slow_path);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001229 bool reordering = __ SetReorder(false);
Serban Constantinescufca16662016-07-14 09:21:59 +01001230 __ LoadFromOffset(kLoadWord, T9, TR, GetThreadOffset<kMipsPointerSize>(entrypoint).Int32Value());
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001231 __ Jalr(T9);
Serban Constantinescufca16662016-07-14 09:21:59 +01001232 if (IsDirectEntrypoint(entrypoint)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001233 // Reserve argument space on stack (for $a0-$a3) for
1234 // entrypoints that directly reference native implementations.
1235 // Called function may use this space to store $a0-$a3 regs.
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001236 __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001237 __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001238 } else {
1239 __ Nop(); // In delay slot.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001240 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001241 __ SetReorder(reordering);
Serban Constantinescufca16662016-07-14 09:21:59 +01001242 if (EntrypointRequiresStackMap(entrypoint)) {
1243 RecordPcInfo(instruction, dex_pc, slow_path);
1244 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001245}
1246
1247void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path,
1248 Register class_reg) {
1249 __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value());
1250 __ LoadConst32(AT, mirror::Class::kStatusInitialized);
1251 __ Blt(TMP, AT, slow_path->GetEntryLabel());
1252 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
1253 __ Sync(0);
1254 __ Bind(slow_path->GetExitLabel());
1255}
1256
1257void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) {
1258 __ Sync(0); // Only stype 0 is supported.
1259}
1260
1261void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction,
1262 HBasicBlock* successor) {
1263 SuspendCheckSlowPathMIPS* slow_path =
1264 new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS(instruction, successor);
1265 codegen_->AddSlowPath(slow_path);
1266
1267 __ LoadFromOffset(kLoadUnsignedHalfword,
1268 TMP,
1269 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001270 Thread::ThreadFlagsOffset<kMipsPointerSize>().Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001271 if (successor == nullptr) {
1272 __ Bnez(TMP, slow_path->GetEntryLabel());
1273 __ Bind(slow_path->GetReturnLabel());
1274 } else {
1275 __ Beqz(TMP, codegen_->GetLabelOf(successor));
1276 __ B(slow_path->GetEntryLabel());
1277 // slow_path will return to GetLabelOf(successor).
1278 }
1279}
1280
1281InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph,
1282 CodeGeneratorMIPS* codegen)
Aart Bik42249c32016-01-07 15:33:50 -08001283 : InstructionCodeGenerator(graph, codegen),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001284 assembler_(codegen->GetAssembler()),
1285 codegen_(codegen) {}
1286
1287void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) {
1288 DCHECK_EQ(instruction->InputCount(), 2U);
1289 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1290 Primitive::Type type = instruction->GetResultType();
1291 switch (type) {
1292 case Primitive::kPrimInt: {
1293 locations->SetInAt(0, Location::RequiresRegister());
1294 HInstruction* right = instruction->InputAt(1);
1295 bool can_use_imm = false;
1296 if (right->IsConstant()) {
1297 int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant());
1298 if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) {
1299 can_use_imm = IsUint<16>(imm);
1300 } else if (instruction->IsAdd()) {
1301 can_use_imm = IsInt<16>(imm);
1302 } else {
1303 DCHECK(instruction->IsSub());
1304 can_use_imm = IsInt<16>(-imm);
1305 }
1306 }
1307 if (can_use_imm)
1308 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1309 else
1310 locations->SetInAt(1, Location::RequiresRegister());
1311 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1312 break;
1313 }
1314
1315 case Primitive::kPrimLong: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001316 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001317 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1318 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001319 break;
1320 }
1321
1322 case Primitive::kPrimFloat:
1323 case Primitive::kPrimDouble:
1324 DCHECK(instruction->IsAdd() || instruction->IsSub());
1325 locations->SetInAt(0, Location::RequiresFpuRegister());
1326 locations->SetInAt(1, Location::RequiresFpuRegister());
1327 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1328 break;
1329
1330 default:
1331 LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type;
1332 }
1333}
1334
1335void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) {
1336 Primitive::Type type = instruction->GetType();
1337 LocationSummary* locations = instruction->GetLocations();
1338
1339 switch (type) {
1340 case Primitive::kPrimInt: {
1341 Register dst = locations->Out().AsRegister<Register>();
1342 Register lhs = locations->InAt(0).AsRegister<Register>();
1343 Location rhs_location = locations->InAt(1);
1344
1345 Register rhs_reg = ZERO;
1346 int32_t rhs_imm = 0;
1347 bool use_imm = rhs_location.IsConstant();
1348 if (use_imm) {
1349 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
1350 } else {
1351 rhs_reg = rhs_location.AsRegister<Register>();
1352 }
1353
1354 if (instruction->IsAnd()) {
1355 if (use_imm)
1356 __ Andi(dst, lhs, rhs_imm);
1357 else
1358 __ And(dst, lhs, rhs_reg);
1359 } else if (instruction->IsOr()) {
1360 if (use_imm)
1361 __ Ori(dst, lhs, rhs_imm);
1362 else
1363 __ Or(dst, lhs, rhs_reg);
1364 } else if (instruction->IsXor()) {
1365 if (use_imm)
1366 __ Xori(dst, lhs, rhs_imm);
1367 else
1368 __ Xor(dst, lhs, rhs_reg);
1369 } else if (instruction->IsAdd()) {
1370 if (use_imm)
1371 __ Addiu(dst, lhs, rhs_imm);
1372 else
1373 __ Addu(dst, lhs, rhs_reg);
1374 } else {
1375 DCHECK(instruction->IsSub());
1376 if (use_imm)
1377 __ Addiu(dst, lhs, -rhs_imm);
1378 else
1379 __ Subu(dst, lhs, rhs_reg);
1380 }
1381 break;
1382 }
1383
1384 case Primitive::kPrimLong: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001385 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
1386 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
1387 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
1388 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001389 Location rhs_location = locations->InAt(1);
1390 bool use_imm = rhs_location.IsConstant();
1391 if (!use_imm) {
1392 Register rhs_high = rhs_location.AsRegisterPairHigh<Register>();
1393 Register rhs_low = rhs_location.AsRegisterPairLow<Register>();
1394 if (instruction->IsAnd()) {
1395 __ And(dst_low, lhs_low, rhs_low);
1396 __ And(dst_high, lhs_high, rhs_high);
1397 } else if (instruction->IsOr()) {
1398 __ Or(dst_low, lhs_low, rhs_low);
1399 __ Or(dst_high, lhs_high, rhs_high);
1400 } else if (instruction->IsXor()) {
1401 __ Xor(dst_low, lhs_low, rhs_low);
1402 __ Xor(dst_high, lhs_high, rhs_high);
1403 } else if (instruction->IsAdd()) {
1404 if (lhs_low == rhs_low) {
1405 // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs.
1406 __ Slt(TMP, lhs_low, ZERO);
1407 __ Addu(dst_low, lhs_low, rhs_low);
1408 } else {
1409 __ Addu(dst_low, lhs_low, rhs_low);
1410 // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged.
1411 __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low);
1412 }
1413 __ Addu(dst_high, lhs_high, rhs_high);
1414 __ Addu(dst_high, dst_high, TMP);
1415 } else {
1416 DCHECK(instruction->IsSub());
1417 __ Sltu(TMP, lhs_low, rhs_low);
1418 __ Subu(dst_low, lhs_low, rhs_low);
1419 __ Subu(dst_high, lhs_high, rhs_high);
1420 __ Subu(dst_high, dst_high, TMP);
1421 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001422 } else {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001423 int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant());
1424 if (instruction->IsOr()) {
1425 uint32_t low = Low32Bits(value);
1426 uint32_t high = High32Bits(value);
1427 if (IsUint<16>(low)) {
1428 if (dst_low != lhs_low || low != 0) {
1429 __ Ori(dst_low, lhs_low, low);
1430 }
1431 } else {
1432 __ LoadConst32(TMP, low);
1433 __ Or(dst_low, lhs_low, TMP);
1434 }
1435 if (IsUint<16>(high)) {
1436 if (dst_high != lhs_high || high != 0) {
1437 __ Ori(dst_high, lhs_high, high);
1438 }
1439 } else {
1440 if (high != low) {
1441 __ LoadConst32(TMP, high);
1442 }
1443 __ Or(dst_high, lhs_high, TMP);
1444 }
1445 } else if (instruction->IsXor()) {
1446 uint32_t low = Low32Bits(value);
1447 uint32_t high = High32Bits(value);
1448 if (IsUint<16>(low)) {
1449 if (dst_low != lhs_low || low != 0) {
1450 __ Xori(dst_low, lhs_low, low);
1451 }
1452 } else {
1453 __ LoadConst32(TMP, low);
1454 __ Xor(dst_low, lhs_low, TMP);
1455 }
1456 if (IsUint<16>(high)) {
1457 if (dst_high != lhs_high || high != 0) {
1458 __ Xori(dst_high, lhs_high, high);
1459 }
1460 } else {
1461 if (high != low) {
1462 __ LoadConst32(TMP, high);
1463 }
1464 __ Xor(dst_high, lhs_high, TMP);
1465 }
1466 } else if (instruction->IsAnd()) {
1467 uint32_t low = Low32Bits(value);
1468 uint32_t high = High32Bits(value);
1469 if (IsUint<16>(low)) {
1470 __ Andi(dst_low, lhs_low, low);
1471 } else if (low != 0xFFFFFFFF) {
1472 __ LoadConst32(TMP, low);
1473 __ And(dst_low, lhs_low, TMP);
1474 } else if (dst_low != lhs_low) {
1475 __ Move(dst_low, lhs_low);
1476 }
1477 if (IsUint<16>(high)) {
1478 __ Andi(dst_high, lhs_high, high);
1479 } else if (high != 0xFFFFFFFF) {
1480 if (high != low) {
1481 __ LoadConst32(TMP, high);
1482 }
1483 __ And(dst_high, lhs_high, TMP);
1484 } else if (dst_high != lhs_high) {
1485 __ Move(dst_high, lhs_high);
1486 }
1487 } else {
1488 if (instruction->IsSub()) {
1489 value = -value;
1490 } else {
1491 DCHECK(instruction->IsAdd());
1492 }
1493 int32_t low = Low32Bits(value);
1494 int32_t high = High32Bits(value);
1495 if (IsInt<16>(low)) {
1496 if (dst_low != lhs_low || low != 0) {
1497 __ Addiu(dst_low, lhs_low, low);
1498 }
1499 if (low != 0) {
1500 __ Sltiu(AT, dst_low, low);
1501 }
1502 } else {
1503 __ LoadConst32(TMP, low);
1504 __ Addu(dst_low, lhs_low, TMP);
1505 __ Sltu(AT, dst_low, TMP);
1506 }
1507 if (IsInt<16>(high)) {
1508 if (dst_high != lhs_high || high != 0) {
1509 __ Addiu(dst_high, lhs_high, high);
1510 }
1511 } else {
1512 if (high != low) {
1513 __ LoadConst32(TMP, high);
1514 }
1515 __ Addu(dst_high, lhs_high, TMP);
1516 }
1517 if (low != 0) {
1518 __ Addu(dst_high, dst_high, AT);
1519 }
1520 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001521 }
1522 break;
1523 }
1524
1525 case Primitive::kPrimFloat:
1526 case Primitive::kPrimDouble: {
1527 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
1528 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
1529 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
1530 if (instruction->IsAdd()) {
1531 if (type == Primitive::kPrimFloat) {
1532 __ AddS(dst, lhs, rhs);
1533 } else {
1534 __ AddD(dst, lhs, rhs);
1535 }
1536 } else {
1537 DCHECK(instruction->IsSub());
1538 if (type == Primitive::kPrimFloat) {
1539 __ SubS(dst, lhs, rhs);
1540 } else {
1541 __ SubD(dst, lhs, rhs);
1542 }
1543 }
1544 break;
1545 }
1546
1547 default:
1548 LOG(FATAL) << "Unexpected binary operation type " << type;
1549 }
1550}
1551
1552void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001553 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001554
1555 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1556 Primitive::Type type = instr->GetResultType();
1557 switch (type) {
1558 case Primitive::kPrimInt:
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001559 locations->SetInAt(0, Location::RequiresRegister());
1560 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1561 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1562 break;
1563 case Primitive::kPrimLong:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001564 locations->SetInAt(0, Location::RequiresRegister());
1565 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1566 locations->SetOut(Location::RequiresRegister());
1567 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001568 default:
1569 LOG(FATAL) << "Unexpected shift type " << type;
1570 }
1571}
1572
1573static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte;
1574
1575void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001576 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001577 LocationSummary* locations = instr->GetLocations();
1578 Primitive::Type type = instr->GetType();
1579
1580 Location rhs_location = locations->InAt(1);
1581 bool use_imm = rhs_location.IsConstant();
1582 Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>();
1583 int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0;
Roland Levillain5b5b9312016-03-22 14:57:31 +00001584 const uint32_t shift_mask =
1585 (type == Primitive::kPrimInt) ? kMaxIntShiftDistance : kMaxLongShiftDistance;
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001586 const uint32_t shift_value = rhs_imm & shift_mask;
Alexey Frunze92d90602015-12-18 18:16:36 -08001587 // Are the INS (Insert Bit Field) and ROTR instructions supported?
1588 bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001589
1590 switch (type) {
1591 case Primitive::kPrimInt: {
1592 Register dst = locations->Out().AsRegister<Register>();
1593 Register lhs = locations->InAt(0).AsRegister<Register>();
1594 if (use_imm) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001595 if (shift_value == 0) {
1596 if (dst != lhs) {
1597 __ Move(dst, lhs);
1598 }
1599 } else if (instr->IsShl()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001600 __ Sll(dst, lhs, shift_value);
1601 } else if (instr->IsShr()) {
1602 __ Sra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001603 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001604 __ Srl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001605 } else {
1606 if (has_ins_rotr) {
1607 __ Rotr(dst, lhs, shift_value);
1608 } else {
1609 __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask);
1610 __ Srl(dst, lhs, shift_value);
1611 __ Or(dst, dst, TMP);
1612 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001613 }
1614 } else {
1615 if (instr->IsShl()) {
1616 __ Sllv(dst, lhs, rhs_reg);
1617 } else if (instr->IsShr()) {
1618 __ Srav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001619 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001620 __ Srlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001621 } else {
1622 if (has_ins_rotr) {
1623 __ Rotrv(dst, lhs, rhs_reg);
1624 } else {
1625 __ Subu(TMP, ZERO, rhs_reg);
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001626 // 32-bit shift instructions use the 5 least significant bits of the shift count, so
1627 // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case
1628 // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out
1629 // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`,
1630 // IOW, the OR'd values are equal.
Alexey Frunze92d90602015-12-18 18:16:36 -08001631 __ Sllv(TMP, lhs, TMP);
1632 __ Srlv(dst, lhs, rhs_reg);
1633 __ Or(dst, dst, TMP);
1634 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001635 }
1636 }
1637 break;
1638 }
1639
1640 case Primitive::kPrimLong: {
1641 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
1642 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
1643 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
1644 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
1645 if (use_imm) {
1646 if (shift_value == 0) {
1647 codegen_->Move64(locations->Out(), locations->InAt(0));
1648 } else if (shift_value < kMipsBitsPerWord) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001649 if (has_ins_rotr) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001650 if (instr->IsShl()) {
1651 __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value);
1652 __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value);
1653 __ Sll(dst_low, lhs_low, shift_value);
1654 } else if (instr->IsShr()) {
1655 __ Srl(dst_low, lhs_low, shift_value);
1656 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1657 __ Sra(dst_high, lhs_high, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001658 } else if (instr->IsUShr()) {
1659 __ Srl(dst_low, lhs_low, shift_value);
1660 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1661 __ Srl(dst_high, lhs_high, shift_value);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001662 } else {
1663 __ Srl(dst_low, lhs_low, shift_value);
1664 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1665 __ Srl(dst_high, lhs_high, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001666 __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001667 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001668 } else {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001669 if (instr->IsShl()) {
1670 __ Sll(dst_low, lhs_low, shift_value);
1671 __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value);
1672 __ Sll(dst_high, lhs_high, shift_value);
1673 __ Or(dst_high, dst_high, TMP);
1674 } else if (instr->IsShr()) {
1675 __ Sra(dst_high, lhs_high, shift_value);
1676 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value);
1677 __ Srl(dst_low, lhs_low, shift_value);
1678 __ Or(dst_low, dst_low, TMP);
Alexey Frunze92d90602015-12-18 18:16:36 -08001679 } else if (instr->IsUShr()) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001680 __ Srl(dst_high, lhs_high, shift_value);
1681 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value);
1682 __ Srl(dst_low, lhs_low, shift_value);
1683 __ Or(dst_low, dst_low, TMP);
Alexey Frunze92d90602015-12-18 18:16:36 -08001684 } else {
1685 __ Srl(TMP, lhs_low, shift_value);
1686 __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value);
1687 __ Or(dst_low, dst_low, TMP);
1688 __ Srl(TMP, lhs_high, shift_value);
1689 __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value);
1690 __ Or(dst_high, dst_high, TMP);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001691 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001692 }
1693 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001694 const uint32_t shift_value_high = shift_value - kMipsBitsPerWord;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001695 if (instr->IsShl()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001696 __ Sll(dst_high, lhs_low, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001697 __ Move(dst_low, ZERO);
1698 } else if (instr->IsShr()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001699 __ Sra(dst_low, lhs_high, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001700 __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1);
Alexey Frunze92d90602015-12-18 18:16:36 -08001701 } else if (instr->IsUShr()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001702 __ Srl(dst_low, lhs_high, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001703 __ Move(dst_high, ZERO);
Alexey Frunze92d90602015-12-18 18:16:36 -08001704 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001705 if (shift_value == kMipsBitsPerWord) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001706 // 64-bit rotation by 32 is just a swap.
1707 __ Move(dst_low, lhs_high);
1708 __ Move(dst_high, lhs_low);
1709 } else {
1710 if (has_ins_rotr) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001711 __ Srl(dst_low, lhs_high, shift_value_high);
1712 __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high);
1713 __ Srl(dst_high, lhs_low, shift_value_high);
1714 __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001715 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001716 __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high);
1717 __ Srl(dst_low, lhs_high, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001718 __ Or(dst_low, dst_low, TMP);
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001719 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high);
1720 __ Srl(dst_high, lhs_low, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001721 __ Or(dst_high, dst_high, TMP);
1722 }
1723 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001724 }
1725 }
1726 } else {
1727 MipsLabel done;
1728 if (instr->IsShl()) {
1729 __ Sllv(dst_low, lhs_low, rhs_reg);
1730 __ Nor(AT, ZERO, rhs_reg);
1731 __ Srl(TMP, lhs_low, 1);
1732 __ Srlv(TMP, TMP, AT);
1733 __ Sllv(dst_high, lhs_high, rhs_reg);
1734 __ Or(dst_high, dst_high, TMP);
1735 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1736 __ Beqz(TMP, &done);
1737 __ Move(dst_high, dst_low);
1738 __ Move(dst_low, ZERO);
1739 } else if (instr->IsShr()) {
1740 __ Srav(dst_high, lhs_high, rhs_reg);
1741 __ Nor(AT, ZERO, rhs_reg);
1742 __ Sll(TMP, lhs_high, 1);
1743 __ Sllv(TMP, TMP, AT);
1744 __ Srlv(dst_low, lhs_low, rhs_reg);
1745 __ Or(dst_low, dst_low, TMP);
1746 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1747 __ Beqz(TMP, &done);
1748 __ Move(dst_low, dst_high);
1749 __ Sra(dst_high, dst_high, 31);
Alexey Frunze92d90602015-12-18 18:16:36 -08001750 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001751 __ Srlv(dst_high, lhs_high, rhs_reg);
1752 __ Nor(AT, ZERO, rhs_reg);
1753 __ Sll(TMP, lhs_high, 1);
1754 __ Sllv(TMP, TMP, AT);
1755 __ Srlv(dst_low, lhs_low, rhs_reg);
1756 __ Or(dst_low, dst_low, TMP);
1757 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1758 __ Beqz(TMP, &done);
1759 __ Move(dst_low, dst_high);
1760 __ Move(dst_high, ZERO);
Alexey Frunze92d90602015-12-18 18:16:36 -08001761 } else {
1762 __ Nor(AT, ZERO, rhs_reg);
1763 __ Srlv(TMP, lhs_low, rhs_reg);
1764 __ Sll(dst_low, lhs_high, 1);
1765 __ Sllv(dst_low, dst_low, AT);
1766 __ Or(dst_low, dst_low, TMP);
1767 __ Srlv(TMP, lhs_high, rhs_reg);
1768 __ Sll(dst_high, lhs_low, 1);
1769 __ Sllv(dst_high, dst_high, AT);
1770 __ Or(dst_high, dst_high, TMP);
1771 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1772 __ Beqz(TMP, &done);
1773 __ Move(TMP, dst_high);
1774 __ Move(dst_high, dst_low);
1775 __ Move(dst_low, TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001776 }
1777 __ Bind(&done);
1778 }
1779 break;
1780 }
1781
1782 default:
1783 LOG(FATAL) << "Unexpected shift operation type " << type;
1784 }
1785}
1786
1787void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) {
1788 HandleBinaryOp(instruction);
1789}
1790
1791void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) {
1792 HandleBinaryOp(instruction);
1793}
1794
1795void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) {
1796 HandleBinaryOp(instruction);
1797}
1798
1799void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) {
1800 HandleBinaryOp(instruction);
1801}
1802
1803void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) {
1804 LocationSummary* locations =
1805 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1806 locations->SetInAt(0, Location::RequiresRegister());
1807 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1808 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1809 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1810 } else {
1811 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1812 }
1813}
1814
Alexey Frunze2923db72016-08-20 01:55:47 -07001815auto InstructionCodeGeneratorMIPS::GetImplicitNullChecker(HInstruction* instruction) {
1816 auto null_checker = [this, instruction]() {
1817 this->codegen_->MaybeRecordImplicitNullCheck(instruction);
1818 };
1819 return null_checker;
1820}
1821
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001822void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) {
1823 LocationSummary* locations = instruction->GetLocations();
1824 Register obj = locations->InAt(0).AsRegister<Register>();
1825 Location index = locations->InAt(1);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01001826 uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction);
Alexey Frunze2923db72016-08-20 01:55:47 -07001827 auto null_checker = GetImplicitNullChecker(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001828
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01001829 Primitive::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001830 switch (type) {
1831 case Primitive::kPrimBoolean: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001832 Register out = locations->Out().AsRegister<Register>();
1833 if (index.IsConstant()) {
1834 size_t offset =
1835 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001836 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001837 } else {
1838 __ Addu(TMP, obj, index.AsRegister<Register>());
Alexey Frunze2923db72016-08-20 01:55:47 -07001839 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001840 }
1841 break;
1842 }
1843
1844 case Primitive::kPrimByte: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001845 Register out = locations->Out().AsRegister<Register>();
1846 if (index.IsConstant()) {
1847 size_t offset =
1848 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001849 __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001850 } else {
1851 __ Addu(TMP, obj, index.AsRegister<Register>());
Alexey Frunze2923db72016-08-20 01:55:47 -07001852 __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001853 }
1854 break;
1855 }
1856
1857 case Primitive::kPrimShort: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001858 Register out = locations->Out().AsRegister<Register>();
1859 if (index.IsConstant()) {
1860 size_t offset =
1861 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001862 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001863 } else {
1864 __ Sll(TMP, index.AsRegister<Register>(), TIMES_2);
1865 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001866 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001867 }
1868 break;
1869 }
1870
1871 case Primitive::kPrimChar: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001872 Register out = locations->Out().AsRegister<Register>();
1873 if (index.IsConstant()) {
1874 size_t offset =
1875 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001876 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001877 } else {
1878 __ Sll(TMP, index.AsRegister<Register>(), TIMES_2);
1879 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001880 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001881 }
1882 break;
1883 }
1884
1885 case Primitive::kPrimInt:
1886 case Primitive::kPrimNot: {
1887 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001888 Register out = locations->Out().AsRegister<Register>();
1889 if (index.IsConstant()) {
1890 size_t offset =
1891 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001892 __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001893 } else {
1894 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
1895 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001896 __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001897 }
1898 break;
1899 }
1900
1901 case Primitive::kPrimLong: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001902 Register out = locations->Out().AsRegisterPairLow<Register>();
1903 if (index.IsConstant()) {
1904 size_t offset =
1905 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001906 __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001907 } else {
1908 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
1909 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001910 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001911 }
1912 break;
1913 }
1914
1915 case Primitive::kPrimFloat: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001916 FRegister out = locations->Out().AsFpuRegister<FRegister>();
1917 if (index.IsConstant()) {
1918 size_t offset =
1919 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001920 __ LoadSFromOffset(out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001921 } else {
1922 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
1923 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001924 __ LoadSFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001925 }
1926 break;
1927 }
1928
1929 case Primitive::kPrimDouble: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001930 FRegister out = locations->Out().AsFpuRegister<FRegister>();
1931 if (index.IsConstant()) {
1932 size_t offset =
1933 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001934 __ LoadDFromOffset(out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001935 } else {
1936 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
1937 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001938 __ LoadDFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001939 }
1940 break;
1941 }
1942
1943 case Primitive::kPrimVoid:
1944 LOG(FATAL) << "Unreachable type " << instruction->GetType();
1945 UNREACHABLE();
1946 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001947}
1948
1949void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) {
1950 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1951 locations->SetInAt(0, Location::RequiresRegister());
1952 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1953}
1954
1955void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) {
1956 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01001957 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001958 Register obj = locations->InAt(0).AsRegister<Register>();
1959 Register out = locations->Out().AsRegister<Register>();
1960 __ LoadFromOffset(kLoadWord, out, obj, offset);
1961 codegen_->MaybeRecordImplicitNullCheck(instruction);
1962}
1963
1964void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) {
Pavle Batuta934808f2015-11-03 13:23:54 +01001965 bool needs_runtime_call = instruction->NeedsTypeCheck();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001966 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1967 instruction,
Serban Constantinescu54ff4822016-07-07 18:03:19 +01001968 needs_runtime_call ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall);
Pavle Batuta934808f2015-11-03 13:23:54 +01001969 if (needs_runtime_call) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001970 InvokeRuntimeCallingConvention calling_convention;
1971 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1972 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1973 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1974 } else {
1975 locations->SetInAt(0, Location::RequiresRegister());
1976 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1977 if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
1978 locations->SetInAt(2, Location::RequiresFpuRegister());
1979 } else {
1980 locations->SetInAt(2, Location::RequiresRegister());
1981 }
1982 }
1983}
1984
1985void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) {
1986 LocationSummary* locations = instruction->GetLocations();
1987 Register obj = locations->InAt(0).AsRegister<Register>();
1988 Location index = locations->InAt(1);
1989 Primitive::Type value_type = instruction->GetComponentType();
1990 bool needs_runtime_call = locations->WillCall();
1991 bool needs_write_barrier =
1992 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Alexey Frunze2923db72016-08-20 01:55:47 -07001993 auto null_checker = GetImplicitNullChecker(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001994
1995 switch (value_type) {
1996 case Primitive::kPrimBoolean:
1997 case Primitive::kPrimByte: {
1998 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
1999 Register value = locations->InAt(2).AsRegister<Register>();
2000 if (index.IsConstant()) {
2001 size_t offset =
2002 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002003 __ StoreToOffset(kStoreByte, value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002004 } else {
2005 __ Addu(TMP, obj, index.AsRegister<Register>());
Alexey Frunze2923db72016-08-20 01:55:47 -07002006 __ StoreToOffset(kStoreByte, value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002007 }
2008 break;
2009 }
2010
2011 case Primitive::kPrimShort:
2012 case Primitive::kPrimChar: {
2013 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
2014 Register value = locations->InAt(2).AsRegister<Register>();
2015 if (index.IsConstant()) {
2016 size_t offset =
2017 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002018 __ StoreToOffset(kStoreHalfword, value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002019 } else {
2020 __ Sll(TMP, index.AsRegister<Register>(), TIMES_2);
2021 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002022 __ StoreToOffset(kStoreHalfword, value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002023 }
2024 break;
2025 }
2026
2027 case Primitive::kPrimInt:
2028 case Primitive::kPrimNot: {
2029 if (!needs_runtime_call) {
2030 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
2031 Register value = locations->InAt(2).AsRegister<Register>();
2032 if (index.IsConstant()) {
2033 size_t offset =
2034 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002035 __ StoreToOffset(kStoreWord, value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002036 } else {
2037 DCHECK(index.IsRegister()) << index;
2038 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
2039 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002040 __ StoreToOffset(kStoreWord, value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002041 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002042 if (needs_write_barrier) {
2043 DCHECK_EQ(value_type, Primitive::kPrimNot);
2044 codegen_->MarkGCCard(obj, value);
2045 }
2046 } else {
2047 DCHECK_EQ(value_type, Primitive::kPrimNot);
Serban Constantinescufca16662016-07-14 09:21:59 +01002048 codegen_->InvokeRuntime(kQuickAputObject, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002049 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
2050 }
2051 break;
2052 }
2053
2054 case Primitive::kPrimLong: {
2055 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
2056 Register value = locations->InAt(2).AsRegisterPairLow<Register>();
2057 if (index.IsConstant()) {
2058 size_t offset =
2059 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002060 __ StoreToOffset(kStoreDoubleword, value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002061 } else {
2062 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
2063 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002064 __ StoreToOffset(kStoreDoubleword, value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002065 }
2066 break;
2067 }
2068
2069 case Primitive::kPrimFloat: {
2070 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
2071 FRegister value = locations->InAt(2).AsFpuRegister<FRegister>();
2072 DCHECK(locations->InAt(2).IsFpuRegister());
2073 if (index.IsConstant()) {
2074 size_t offset =
2075 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002076 __ StoreSToOffset(value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002077 } else {
2078 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
2079 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002080 __ StoreSToOffset(value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002081 }
2082 break;
2083 }
2084
2085 case Primitive::kPrimDouble: {
2086 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
2087 FRegister value = locations->InAt(2).AsFpuRegister<FRegister>();
2088 DCHECK(locations->InAt(2).IsFpuRegister());
2089 if (index.IsConstant()) {
2090 size_t offset =
2091 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002092 __ StoreDToOffset(value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002093 } else {
2094 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
2095 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002096 __ StoreDToOffset(value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002097 }
2098 break;
2099 }
2100
2101 case Primitive::kPrimVoid:
2102 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2103 UNREACHABLE();
2104 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002105}
2106
2107void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) {
2108 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
2109 ? LocationSummary::kCallOnSlowPath
2110 : LocationSummary::kNoCall;
2111 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
2112 locations->SetInAt(0, Location::RequiresRegister());
2113 locations->SetInAt(1, Location::RequiresRegister());
2114 if (instruction->HasUses()) {
2115 locations->SetOut(Location::SameAsFirstInput());
2116 }
2117}
2118
2119void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) {
2120 LocationSummary* locations = instruction->GetLocations();
2121 BoundsCheckSlowPathMIPS* slow_path =
2122 new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS(instruction);
2123 codegen_->AddSlowPath(slow_path);
2124
2125 Register index = locations->InAt(0).AsRegister<Register>();
2126 Register length = locations->InAt(1).AsRegister<Register>();
2127
2128 // length is limited by the maximum positive signed 32-bit integer.
2129 // Unsigned comparison of length and index checks for index < 0
2130 // and for length <= index simultaneously.
2131 __ Bgeu(index, length, slow_path->GetEntryLabel());
2132}
2133
2134void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) {
2135 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
2136 instruction,
2137 LocationSummary::kCallOnSlowPath);
2138 locations->SetInAt(0, Location::RequiresRegister());
2139 locations->SetInAt(1, Location::RequiresRegister());
2140 // Note that TypeCheckSlowPathMIPS uses this register too.
2141 locations->AddTemp(Location::RequiresRegister());
2142}
2143
2144void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) {
2145 LocationSummary* locations = instruction->GetLocations();
2146 Register obj = locations->InAt(0).AsRegister<Register>();
2147 Register cls = locations->InAt(1).AsRegister<Register>();
2148 Register obj_cls = locations->GetTemp(0).AsRegister<Register>();
2149
2150 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction);
2151 codegen_->AddSlowPath(slow_path);
2152
2153 // TODO: avoid this check if we know obj is not null.
2154 __ Beqz(obj, slow_path->GetExitLabel());
2155 // Compare the class of `obj` with `cls`.
2156 __ LoadFromOffset(kLoadWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value());
2157 __ Bne(obj_cls, cls, slow_path->GetEntryLabel());
2158 __ Bind(slow_path->GetExitLabel());
2159}
2160
2161void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) {
2162 LocationSummary* locations =
2163 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2164 locations->SetInAt(0, Location::RequiresRegister());
2165 if (check->HasUses()) {
2166 locations->SetOut(Location::SameAsFirstInput());
2167 }
2168}
2169
2170void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) {
2171 // We assume the class is not null.
2172 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS(
2173 check->GetLoadClass(),
2174 check,
2175 check->GetDexPc(),
2176 true);
2177 codegen_->AddSlowPath(slow_path);
2178 GenerateClassInitializationCheck(slow_path,
2179 check->GetLocations()->InAt(0).AsRegister<Register>());
2180}
2181
2182void LocationsBuilderMIPS::VisitCompare(HCompare* compare) {
2183 Primitive::Type in_type = compare->InputAt(0)->GetType();
2184
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002185 LocationSummary* locations =
2186 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002187
2188 switch (in_type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00002189 case Primitive::kPrimBoolean:
2190 case Primitive::kPrimByte:
2191 case Primitive::kPrimShort:
2192 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08002193 case Primitive::kPrimInt:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002194 case Primitive::kPrimLong:
2195 locations->SetInAt(0, Location::RequiresRegister());
2196 locations->SetInAt(1, Location::RequiresRegister());
2197 // Output overlaps because it is written before doing the low comparison.
2198 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
2199 break;
2200
2201 case Primitive::kPrimFloat:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002202 case Primitive::kPrimDouble:
2203 locations->SetInAt(0, Location::RequiresFpuRegister());
2204 locations->SetInAt(1, Location::RequiresFpuRegister());
2205 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002206 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002207
2208 default:
2209 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
2210 }
2211}
2212
2213void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) {
2214 LocationSummary* locations = instruction->GetLocations();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002215 Register res = locations->Out().AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002216 Primitive::Type in_type = instruction->InputAt(0)->GetType();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002217 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002218
2219 // 0 if: left == right
2220 // 1 if: left > right
2221 // -1 if: left < right
2222 switch (in_type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00002223 case Primitive::kPrimBoolean:
2224 case Primitive::kPrimByte:
2225 case Primitive::kPrimShort:
2226 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08002227 case Primitive::kPrimInt: {
2228 Register lhs = locations->InAt(0).AsRegister<Register>();
2229 Register rhs = locations->InAt(1).AsRegister<Register>();
2230 __ Slt(TMP, lhs, rhs);
2231 __ Slt(res, rhs, lhs);
2232 __ Subu(res, res, TMP);
2233 break;
2234 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002235 case Primitive::kPrimLong: {
2236 MipsLabel done;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002237 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
2238 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
2239 Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>();
2240 Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>();
2241 // TODO: more efficient (direct) comparison with a constant.
2242 __ Slt(TMP, lhs_high, rhs_high);
2243 __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt.
2244 __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ].
2245 __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal.
2246 __ Sltu(TMP, lhs_low, rhs_low);
2247 __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt.
2248 __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ].
2249 __ Bind(&done);
2250 break;
2251 }
2252
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002253 case Primitive::kPrimFloat: {
Roland Levillain32ca3752016-02-17 16:49:37 +00002254 bool gt_bias = instruction->IsGtBias();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002255 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2256 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2257 MipsLabel done;
2258 if (isR6) {
2259 __ CmpEqS(FTMP, lhs, rhs);
2260 __ LoadConst32(res, 0);
2261 __ Bc1nez(FTMP, &done);
2262 if (gt_bias) {
2263 __ CmpLtS(FTMP, lhs, rhs);
2264 __ LoadConst32(res, -1);
2265 __ Bc1nez(FTMP, &done);
2266 __ LoadConst32(res, 1);
2267 } else {
2268 __ CmpLtS(FTMP, rhs, lhs);
2269 __ LoadConst32(res, 1);
2270 __ Bc1nez(FTMP, &done);
2271 __ LoadConst32(res, -1);
2272 }
2273 } else {
2274 if (gt_bias) {
2275 __ ColtS(0, lhs, rhs);
2276 __ LoadConst32(res, -1);
2277 __ Bc1t(0, &done);
2278 __ CeqS(0, lhs, rhs);
2279 __ LoadConst32(res, 1);
2280 __ Movt(res, ZERO, 0);
2281 } else {
2282 __ ColtS(0, rhs, lhs);
2283 __ LoadConst32(res, 1);
2284 __ Bc1t(0, &done);
2285 __ CeqS(0, lhs, rhs);
2286 __ LoadConst32(res, -1);
2287 __ Movt(res, ZERO, 0);
2288 }
2289 }
2290 __ Bind(&done);
2291 break;
2292 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002293 case Primitive::kPrimDouble: {
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 __ CmpEqD(FTMP, lhs, rhs);
2300 __ LoadConst32(res, 0);
2301 __ Bc1nez(FTMP, &done);
2302 if (gt_bias) {
2303 __ CmpLtD(FTMP, lhs, rhs);
2304 __ LoadConst32(res, -1);
2305 __ Bc1nez(FTMP, &done);
2306 __ LoadConst32(res, 1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002307 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002308 __ CmpLtD(FTMP, rhs, lhs);
2309 __ LoadConst32(res, 1);
2310 __ Bc1nez(FTMP, &done);
2311 __ LoadConst32(res, -1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002312 }
2313 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002314 if (gt_bias) {
2315 __ ColtD(0, lhs, rhs);
2316 __ LoadConst32(res, -1);
2317 __ Bc1t(0, &done);
2318 __ CeqD(0, lhs, rhs);
2319 __ LoadConst32(res, 1);
2320 __ Movt(res, ZERO, 0);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002321 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002322 __ ColtD(0, rhs, lhs);
2323 __ LoadConst32(res, 1);
2324 __ Bc1t(0, &done);
2325 __ CeqD(0, lhs, rhs);
2326 __ LoadConst32(res, -1);
2327 __ Movt(res, ZERO, 0);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002328 }
2329 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002330 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002331 break;
2332 }
2333
2334 default:
2335 LOG(FATAL) << "Unimplemented compare type " << in_type;
2336 }
2337}
2338
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002339void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002340 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002341 switch (instruction->InputAt(0)->GetType()) {
2342 default:
2343 case Primitive::kPrimLong:
2344 locations->SetInAt(0, Location::RequiresRegister());
2345 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2346 break;
2347
2348 case Primitive::kPrimFloat:
2349 case Primitive::kPrimDouble:
2350 locations->SetInAt(0, Location::RequiresFpuRegister());
2351 locations->SetInAt(1, Location::RequiresFpuRegister());
2352 break;
2353 }
David Brazdilb3e773e2016-01-26 11:28:37 +00002354 if (!instruction->IsEmittedAtUseSite()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002355 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2356 }
2357}
2358
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002359void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) {
David Brazdilb3e773e2016-01-26 11:28:37 +00002360 if (instruction->IsEmittedAtUseSite()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002361 return;
2362 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002363
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002364 Primitive::Type type = instruction->InputAt(0)->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002365 LocationSummary* locations = instruction->GetLocations();
2366 Register dst = locations->Out().AsRegister<Register>();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002367 MipsLabel true_label;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002368
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002369 switch (type) {
2370 default:
2371 // Integer case.
2372 GenerateIntCompare(instruction->GetCondition(), locations);
2373 return;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002374
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002375 case Primitive::kPrimLong:
2376 // TODO: don't use branches.
2377 GenerateLongCompareAndBranch(instruction->GetCondition(), locations, &true_label);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002378 break;
2379
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002380 case Primitive::kPrimFloat:
2381 case Primitive::kPrimDouble:
2382 // TODO: don't use branches.
2383 GenerateFpCompareAndBranch(instruction->GetCondition(),
2384 instruction->IsGtBias(),
2385 type,
2386 locations,
2387 &true_label);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002388 break;
2389 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002390
2391 // Convert the branches into the result.
2392 MipsLabel done;
2393
2394 // False case: result = 0.
2395 __ LoadConst32(dst, 0);
2396 __ B(&done);
2397
2398 // True case: result = 1.
2399 __ Bind(&true_label);
2400 __ LoadConst32(dst, 1);
2401 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002402}
2403
Alexey Frunze7e99e052015-11-24 19:28:01 -08002404void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2405 DCHECK(instruction->IsDiv() || instruction->IsRem());
2406 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2407
2408 LocationSummary* locations = instruction->GetLocations();
2409 Location second = locations->InAt(1);
2410 DCHECK(second.IsConstant());
2411
2412 Register out = locations->Out().AsRegister<Register>();
2413 Register dividend = locations->InAt(0).AsRegister<Register>();
2414 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2415 DCHECK(imm == 1 || imm == -1);
2416
2417 if (instruction->IsRem()) {
2418 __ Move(out, ZERO);
2419 } else {
2420 if (imm == -1) {
2421 __ Subu(out, ZERO, dividend);
2422 } else if (out != dividend) {
2423 __ Move(out, dividend);
2424 }
2425 }
2426}
2427
2428void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2429 DCHECK(instruction->IsDiv() || instruction->IsRem());
2430 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2431
2432 LocationSummary* locations = instruction->GetLocations();
2433 Location second = locations->InAt(1);
2434 DCHECK(second.IsConstant());
2435
2436 Register out = locations->Out().AsRegister<Register>();
2437 Register dividend = locations->InAt(0).AsRegister<Register>();
2438 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002439 uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm));
Alexey Frunze7e99e052015-11-24 19:28:01 -08002440 int ctz_imm = CTZ(abs_imm);
2441
2442 if (instruction->IsDiv()) {
2443 if (ctz_imm == 1) {
2444 // Fast path for division by +/-2, which is very common.
2445 __ Srl(TMP, dividend, 31);
2446 } else {
2447 __ Sra(TMP, dividend, 31);
2448 __ Srl(TMP, TMP, 32 - ctz_imm);
2449 }
2450 __ Addu(out, dividend, TMP);
2451 __ Sra(out, out, ctz_imm);
2452 if (imm < 0) {
2453 __ Subu(out, ZERO, out);
2454 }
2455 } else {
2456 if (ctz_imm == 1) {
2457 // Fast path for modulo +/-2, which is very common.
2458 __ Sra(TMP, dividend, 31);
2459 __ Subu(out, dividend, TMP);
2460 __ Andi(out, out, 1);
2461 __ Addu(out, out, TMP);
2462 } else {
2463 __ Sra(TMP, dividend, 31);
2464 __ Srl(TMP, TMP, 32 - ctz_imm);
2465 __ Addu(out, dividend, TMP);
2466 if (IsUint<16>(abs_imm - 1)) {
2467 __ Andi(out, out, abs_imm - 1);
2468 } else {
2469 __ Sll(out, out, 32 - ctz_imm);
2470 __ Srl(out, out, 32 - ctz_imm);
2471 }
2472 __ Subu(out, out, TMP);
2473 }
2474 }
2475}
2476
2477void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2478 DCHECK(instruction->IsDiv() || instruction->IsRem());
2479 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2480
2481 LocationSummary* locations = instruction->GetLocations();
2482 Location second = locations->InAt(1);
2483 DCHECK(second.IsConstant());
2484
2485 Register out = locations->Out().AsRegister<Register>();
2486 Register dividend = locations->InAt(0).AsRegister<Register>();
2487 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2488
2489 int64_t magic;
2490 int shift;
2491 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2492
2493 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
2494
2495 __ LoadConst32(TMP, magic);
2496 if (isR6) {
2497 __ MuhR6(TMP, dividend, TMP);
2498 } else {
2499 __ MultR2(dividend, TMP);
2500 __ Mfhi(TMP);
2501 }
2502 if (imm > 0 && magic < 0) {
2503 __ Addu(TMP, TMP, dividend);
2504 } else if (imm < 0 && magic > 0) {
2505 __ Subu(TMP, TMP, dividend);
2506 }
2507
2508 if (shift != 0) {
2509 __ Sra(TMP, TMP, shift);
2510 }
2511
2512 if (instruction->IsDiv()) {
2513 __ Sra(out, TMP, 31);
2514 __ Subu(out, TMP, out);
2515 } else {
2516 __ Sra(AT, TMP, 31);
2517 __ Subu(AT, TMP, AT);
2518 __ LoadConst32(TMP, imm);
2519 if (isR6) {
2520 __ MulR6(TMP, AT, TMP);
2521 } else {
2522 __ MulR2(TMP, AT, TMP);
2523 }
2524 __ Subu(out, dividend, TMP);
2525 }
2526}
2527
2528void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) {
2529 DCHECK(instruction->IsDiv() || instruction->IsRem());
2530 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2531
2532 LocationSummary* locations = instruction->GetLocations();
2533 Register out = locations->Out().AsRegister<Register>();
2534 Location second = locations->InAt(1);
2535
2536 if (second.IsConstant()) {
2537 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2538 if (imm == 0) {
2539 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2540 } else if (imm == 1 || imm == -1) {
2541 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002542 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08002543 DivRemByPowerOfTwo(instruction);
2544 } else {
2545 DCHECK(imm <= -2 || imm >= 2);
2546 GenerateDivRemWithAnyConstant(instruction);
2547 }
2548 } else {
2549 Register dividend = locations->InAt(0).AsRegister<Register>();
2550 Register divisor = second.AsRegister<Register>();
2551 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
2552 if (instruction->IsDiv()) {
2553 if (isR6) {
2554 __ DivR6(out, dividend, divisor);
2555 } else {
2556 __ DivR2(out, dividend, divisor);
2557 }
2558 } else {
2559 if (isR6) {
2560 __ ModR6(out, dividend, divisor);
2561 } else {
2562 __ ModR2(out, dividend, divisor);
2563 }
2564 }
2565 }
2566}
2567
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002568void LocationsBuilderMIPS::VisitDiv(HDiv* div) {
2569 Primitive::Type type = div->GetResultType();
2570 LocationSummary::CallKind call_kind = (type == Primitive::kPrimLong)
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002571 ? LocationSummary::kCallOnMainOnly
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002572 : LocationSummary::kNoCall;
2573
2574 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2575
2576 switch (type) {
2577 case Primitive::kPrimInt:
2578 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze7e99e052015-11-24 19:28:01 -08002579 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002580 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2581 break;
2582
2583 case Primitive::kPrimLong: {
2584 InvokeRuntimeCallingConvention calling_convention;
2585 locations->SetInAt(0, Location::RegisterPairLocation(
2586 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2587 locations->SetInAt(1, Location::RegisterPairLocation(
2588 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2589 locations->SetOut(calling_convention.GetReturnLocation(type));
2590 break;
2591 }
2592
2593 case Primitive::kPrimFloat:
2594 case Primitive::kPrimDouble:
2595 locations->SetInAt(0, Location::RequiresFpuRegister());
2596 locations->SetInAt(1, Location::RequiresFpuRegister());
2597 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2598 break;
2599
2600 default:
2601 LOG(FATAL) << "Unexpected div type " << type;
2602 }
2603}
2604
2605void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) {
2606 Primitive::Type type = instruction->GetType();
2607 LocationSummary* locations = instruction->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002608
2609 switch (type) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08002610 case Primitive::kPrimInt:
2611 GenerateDivRemIntegral(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002612 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002613 case Primitive::kPrimLong: {
Serban Constantinescufca16662016-07-14 09:21:59 +01002614 codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002615 CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>();
2616 break;
2617 }
2618 case Primitive::kPrimFloat:
2619 case Primitive::kPrimDouble: {
2620 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
2621 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2622 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2623 if (type == Primitive::kPrimFloat) {
2624 __ DivS(dst, lhs, rhs);
2625 } else {
2626 __ DivD(dst, lhs, rhs);
2627 }
2628 break;
2629 }
2630 default:
2631 LOG(FATAL) << "Unexpected div type " << type;
2632 }
2633}
2634
2635void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2636 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
2637 ? LocationSummary::kCallOnSlowPath
2638 : LocationSummary::kNoCall;
2639 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
2640 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
2641 if (instruction->HasUses()) {
2642 locations->SetOut(Location::SameAsFirstInput());
2643 }
2644}
2645
2646void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2647 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS(instruction);
2648 codegen_->AddSlowPath(slow_path);
2649 Location value = instruction->GetLocations()->InAt(0);
2650 Primitive::Type type = instruction->GetType();
2651
2652 switch (type) {
Nicolas Geoffraye5671612016-03-16 11:03:54 +00002653 case Primitive::kPrimBoolean:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002654 case Primitive::kPrimByte:
2655 case Primitive::kPrimChar:
2656 case Primitive::kPrimShort:
2657 case Primitive::kPrimInt: {
2658 if (value.IsConstant()) {
2659 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2660 __ B(slow_path->GetEntryLabel());
2661 } else {
2662 // A division by a non-null constant is valid. We don't need to perform
2663 // any check, so simply fall through.
2664 }
2665 } else {
2666 DCHECK(value.IsRegister()) << value;
2667 __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel());
2668 }
2669 break;
2670 }
2671 case Primitive::kPrimLong: {
2672 if (value.IsConstant()) {
2673 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2674 __ B(slow_path->GetEntryLabel());
2675 } else {
2676 // A division by a non-null constant is valid. We don't need to perform
2677 // any check, so simply fall through.
2678 }
2679 } else {
2680 DCHECK(value.IsRegisterPair()) << value;
2681 __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>());
2682 __ Beqz(TMP, slow_path->GetEntryLabel());
2683 }
2684 break;
2685 }
2686 default:
2687 LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck.";
2688 }
2689}
2690
2691void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) {
2692 LocationSummary* locations =
2693 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2694 locations->SetOut(Location::ConstantLocation(constant));
2695}
2696
2697void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) {
2698 // Will be generated at use site.
2699}
2700
2701void LocationsBuilderMIPS::VisitExit(HExit* exit) {
2702 exit->SetLocations(nullptr);
2703}
2704
2705void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
2706}
2707
2708void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) {
2709 LocationSummary* locations =
2710 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2711 locations->SetOut(Location::ConstantLocation(constant));
2712}
2713
2714void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
2715 // Will be generated at use site.
2716}
2717
2718void LocationsBuilderMIPS::VisitGoto(HGoto* got) {
2719 got->SetLocations(nullptr);
2720}
2721
2722void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) {
2723 DCHECK(!successor->IsExitBlock());
2724 HBasicBlock* block = got->GetBlock();
2725 HInstruction* previous = got->GetPrevious();
2726 HLoopInformation* info = block->GetLoopInformation();
2727
2728 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
2729 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
2730 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
2731 return;
2732 }
2733 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
2734 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
2735 }
2736 if (!codegen_->GoesToNextBlock(block, successor)) {
2737 __ B(codegen_->GetLabelOf(successor));
2738 }
2739}
2740
2741void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) {
2742 HandleGoto(got, got->GetSuccessor());
2743}
2744
2745void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) {
2746 try_boundary->SetLocations(nullptr);
2747}
2748
2749void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) {
2750 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
2751 if (!successor->IsExitBlock()) {
2752 HandleGoto(try_boundary, successor);
2753 }
2754}
2755
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002756void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond,
2757 LocationSummary* locations) {
2758 Register dst = locations->Out().AsRegister<Register>();
2759 Register lhs = locations->InAt(0).AsRegister<Register>();
2760 Location rhs_location = locations->InAt(1);
2761 Register rhs_reg = ZERO;
2762 int64_t rhs_imm = 0;
2763 bool use_imm = rhs_location.IsConstant();
2764 if (use_imm) {
2765 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2766 } else {
2767 rhs_reg = rhs_location.AsRegister<Register>();
2768 }
2769
2770 switch (cond) {
2771 case kCondEQ:
2772 case kCondNE:
2773 if (use_imm && IsUint<16>(rhs_imm)) {
2774 __ Xori(dst, lhs, rhs_imm);
2775 } else {
2776 if (use_imm) {
2777 rhs_reg = TMP;
2778 __ LoadConst32(rhs_reg, rhs_imm);
2779 }
2780 __ Xor(dst, lhs, rhs_reg);
2781 }
2782 if (cond == kCondEQ) {
2783 __ Sltiu(dst, dst, 1);
2784 } else {
2785 __ Sltu(dst, ZERO, dst);
2786 }
2787 break;
2788
2789 case kCondLT:
2790 case kCondGE:
2791 if (use_imm && IsInt<16>(rhs_imm)) {
2792 __ Slti(dst, lhs, rhs_imm);
2793 } else {
2794 if (use_imm) {
2795 rhs_reg = TMP;
2796 __ LoadConst32(rhs_reg, rhs_imm);
2797 }
2798 __ Slt(dst, lhs, rhs_reg);
2799 }
2800 if (cond == kCondGE) {
2801 // Simulate lhs >= rhs via !(lhs < rhs) since there's
2802 // only the slt instruction but no sge.
2803 __ Xori(dst, dst, 1);
2804 }
2805 break;
2806
2807 case kCondLE:
2808 case kCondGT:
2809 if (use_imm && IsInt<16>(rhs_imm + 1)) {
2810 // Simulate lhs <= rhs via lhs < rhs + 1.
2811 __ Slti(dst, lhs, rhs_imm + 1);
2812 if (cond == kCondGT) {
2813 // Simulate lhs > rhs via !(lhs <= rhs) since there's
2814 // only the slti instruction but no sgti.
2815 __ Xori(dst, dst, 1);
2816 }
2817 } else {
2818 if (use_imm) {
2819 rhs_reg = TMP;
2820 __ LoadConst32(rhs_reg, rhs_imm);
2821 }
2822 __ Slt(dst, rhs_reg, lhs);
2823 if (cond == kCondLE) {
2824 // Simulate lhs <= rhs via !(rhs < lhs) since there's
2825 // only the slt instruction but no sle.
2826 __ Xori(dst, dst, 1);
2827 }
2828 }
2829 break;
2830
2831 case kCondB:
2832 case kCondAE:
2833 if (use_imm && IsInt<16>(rhs_imm)) {
2834 // Sltiu sign-extends its 16-bit immediate operand before
2835 // the comparison and thus lets us compare directly with
2836 // unsigned values in the ranges [0, 0x7fff] and
2837 // [0xffff8000, 0xffffffff].
2838 __ Sltiu(dst, lhs, rhs_imm);
2839 } else {
2840 if (use_imm) {
2841 rhs_reg = TMP;
2842 __ LoadConst32(rhs_reg, rhs_imm);
2843 }
2844 __ Sltu(dst, lhs, rhs_reg);
2845 }
2846 if (cond == kCondAE) {
2847 // Simulate lhs >= rhs via !(lhs < rhs) since there's
2848 // only the sltu instruction but no sgeu.
2849 __ Xori(dst, dst, 1);
2850 }
2851 break;
2852
2853 case kCondBE:
2854 case kCondA:
2855 if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
2856 // Simulate lhs <= rhs via lhs < rhs + 1.
2857 // Note that this only works if rhs + 1 does not overflow
2858 // to 0, hence the check above.
2859 // Sltiu sign-extends its 16-bit immediate operand before
2860 // the comparison and thus lets us compare directly with
2861 // unsigned values in the ranges [0, 0x7fff] and
2862 // [0xffff8000, 0xffffffff].
2863 __ Sltiu(dst, lhs, rhs_imm + 1);
2864 if (cond == kCondA) {
2865 // Simulate lhs > rhs via !(lhs <= rhs) since there's
2866 // only the sltiu instruction but no sgtiu.
2867 __ Xori(dst, dst, 1);
2868 }
2869 } else {
2870 if (use_imm) {
2871 rhs_reg = TMP;
2872 __ LoadConst32(rhs_reg, rhs_imm);
2873 }
2874 __ Sltu(dst, rhs_reg, lhs);
2875 if (cond == kCondBE) {
2876 // Simulate lhs <= rhs via !(rhs < lhs) since there's
2877 // only the sltu instruction but no sleu.
2878 __ Xori(dst, dst, 1);
2879 }
2880 }
2881 break;
2882 }
2883}
2884
2885void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond,
2886 LocationSummary* locations,
2887 MipsLabel* label) {
2888 Register lhs = locations->InAt(0).AsRegister<Register>();
2889 Location rhs_location = locations->InAt(1);
2890 Register rhs_reg = ZERO;
2891 int32_t rhs_imm = 0;
2892 bool use_imm = rhs_location.IsConstant();
2893 if (use_imm) {
2894 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2895 } else {
2896 rhs_reg = rhs_location.AsRegister<Register>();
2897 }
2898
2899 if (use_imm && rhs_imm == 0) {
2900 switch (cond) {
2901 case kCondEQ:
2902 case kCondBE: // <= 0 if zero
2903 __ Beqz(lhs, label);
2904 break;
2905 case kCondNE:
2906 case kCondA: // > 0 if non-zero
2907 __ Bnez(lhs, label);
2908 break;
2909 case kCondLT:
2910 __ Bltz(lhs, label);
2911 break;
2912 case kCondGE:
2913 __ Bgez(lhs, label);
2914 break;
2915 case kCondLE:
2916 __ Blez(lhs, label);
2917 break;
2918 case kCondGT:
2919 __ Bgtz(lhs, label);
2920 break;
2921 case kCondB: // always false
2922 break;
2923 case kCondAE: // always true
2924 __ B(label);
2925 break;
2926 }
2927 } else {
2928 if (use_imm) {
2929 // TODO: more efficient comparison with 16-bit constants without loading them into TMP.
2930 rhs_reg = TMP;
2931 __ LoadConst32(rhs_reg, rhs_imm);
2932 }
2933 switch (cond) {
2934 case kCondEQ:
2935 __ Beq(lhs, rhs_reg, label);
2936 break;
2937 case kCondNE:
2938 __ Bne(lhs, rhs_reg, label);
2939 break;
2940 case kCondLT:
2941 __ Blt(lhs, rhs_reg, label);
2942 break;
2943 case kCondGE:
2944 __ Bge(lhs, rhs_reg, label);
2945 break;
2946 case kCondLE:
2947 __ Bge(rhs_reg, lhs, label);
2948 break;
2949 case kCondGT:
2950 __ Blt(rhs_reg, lhs, label);
2951 break;
2952 case kCondB:
2953 __ Bltu(lhs, rhs_reg, label);
2954 break;
2955 case kCondAE:
2956 __ Bgeu(lhs, rhs_reg, label);
2957 break;
2958 case kCondBE:
2959 __ Bgeu(rhs_reg, lhs, label);
2960 break;
2961 case kCondA:
2962 __ Bltu(rhs_reg, lhs, label);
2963 break;
2964 }
2965 }
2966}
2967
2968void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond,
2969 LocationSummary* locations,
2970 MipsLabel* label) {
2971 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
2972 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
2973 Location rhs_location = locations->InAt(1);
2974 Register rhs_high = ZERO;
2975 Register rhs_low = ZERO;
2976 int64_t imm = 0;
2977 uint32_t imm_high = 0;
2978 uint32_t imm_low = 0;
2979 bool use_imm = rhs_location.IsConstant();
2980 if (use_imm) {
2981 imm = rhs_location.GetConstant()->AsLongConstant()->GetValue();
2982 imm_high = High32Bits(imm);
2983 imm_low = Low32Bits(imm);
2984 } else {
2985 rhs_high = rhs_location.AsRegisterPairHigh<Register>();
2986 rhs_low = rhs_location.AsRegisterPairLow<Register>();
2987 }
2988
2989 if (use_imm && imm == 0) {
2990 switch (cond) {
2991 case kCondEQ:
2992 case kCondBE: // <= 0 if zero
2993 __ Or(TMP, lhs_high, lhs_low);
2994 __ Beqz(TMP, label);
2995 break;
2996 case kCondNE:
2997 case kCondA: // > 0 if non-zero
2998 __ Or(TMP, lhs_high, lhs_low);
2999 __ Bnez(TMP, label);
3000 break;
3001 case kCondLT:
3002 __ Bltz(lhs_high, label);
3003 break;
3004 case kCondGE:
3005 __ Bgez(lhs_high, label);
3006 break;
3007 case kCondLE:
3008 __ Or(TMP, lhs_high, lhs_low);
3009 __ Sra(AT, lhs_high, 31);
3010 __ Bgeu(AT, TMP, label);
3011 break;
3012 case kCondGT:
3013 __ Or(TMP, lhs_high, lhs_low);
3014 __ Sra(AT, lhs_high, 31);
3015 __ Bltu(AT, TMP, label);
3016 break;
3017 case kCondB: // always false
3018 break;
3019 case kCondAE: // always true
3020 __ B(label);
3021 break;
3022 }
3023 } else if (use_imm) {
3024 // TODO: more efficient comparison with constants without loading them into TMP/AT.
3025 switch (cond) {
3026 case kCondEQ:
3027 __ LoadConst32(TMP, imm_high);
3028 __ Xor(TMP, TMP, lhs_high);
3029 __ LoadConst32(AT, imm_low);
3030 __ Xor(AT, AT, lhs_low);
3031 __ Or(TMP, TMP, AT);
3032 __ Beqz(TMP, label);
3033 break;
3034 case kCondNE:
3035 __ LoadConst32(TMP, imm_high);
3036 __ Xor(TMP, TMP, lhs_high);
3037 __ LoadConst32(AT, imm_low);
3038 __ Xor(AT, AT, lhs_low);
3039 __ Or(TMP, TMP, AT);
3040 __ Bnez(TMP, label);
3041 break;
3042 case kCondLT:
3043 __ LoadConst32(TMP, imm_high);
3044 __ Blt(lhs_high, TMP, label);
3045 __ Slt(TMP, TMP, lhs_high);
3046 __ LoadConst32(AT, imm_low);
3047 __ Sltu(AT, lhs_low, AT);
3048 __ Blt(TMP, AT, label);
3049 break;
3050 case kCondGE:
3051 __ LoadConst32(TMP, imm_high);
3052 __ Blt(TMP, lhs_high, label);
3053 __ Slt(TMP, lhs_high, TMP);
3054 __ LoadConst32(AT, imm_low);
3055 __ Sltu(AT, lhs_low, AT);
3056 __ Or(TMP, TMP, AT);
3057 __ Beqz(TMP, label);
3058 break;
3059 case kCondLE:
3060 __ LoadConst32(TMP, imm_high);
3061 __ Blt(lhs_high, TMP, label);
3062 __ Slt(TMP, TMP, lhs_high);
3063 __ LoadConst32(AT, imm_low);
3064 __ Sltu(AT, AT, lhs_low);
3065 __ Or(TMP, TMP, AT);
3066 __ Beqz(TMP, label);
3067 break;
3068 case kCondGT:
3069 __ LoadConst32(TMP, imm_high);
3070 __ Blt(TMP, lhs_high, label);
3071 __ Slt(TMP, lhs_high, TMP);
3072 __ LoadConst32(AT, imm_low);
3073 __ Sltu(AT, AT, lhs_low);
3074 __ Blt(TMP, AT, label);
3075 break;
3076 case kCondB:
3077 __ LoadConst32(TMP, imm_high);
3078 __ Bltu(lhs_high, TMP, label);
3079 __ Sltu(TMP, TMP, lhs_high);
3080 __ LoadConst32(AT, imm_low);
3081 __ Sltu(AT, lhs_low, AT);
3082 __ Blt(TMP, AT, label);
3083 break;
3084 case kCondAE:
3085 __ LoadConst32(TMP, imm_high);
3086 __ Bltu(TMP, lhs_high, label);
3087 __ Sltu(TMP, lhs_high, TMP);
3088 __ LoadConst32(AT, imm_low);
3089 __ Sltu(AT, lhs_low, AT);
3090 __ Or(TMP, TMP, AT);
3091 __ Beqz(TMP, label);
3092 break;
3093 case kCondBE:
3094 __ LoadConst32(TMP, imm_high);
3095 __ Bltu(lhs_high, TMP, label);
3096 __ Sltu(TMP, TMP, lhs_high);
3097 __ LoadConst32(AT, imm_low);
3098 __ Sltu(AT, AT, lhs_low);
3099 __ Or(TMP, TMP, AT);
3100 __ Beqz(TMP, label);
3101 break;
3102 case kCondA:
3103 __ LoadConst32(TMP, imm_high);
3104 __ Bltu(TMP, lhs_high, label);
3105 __ Sltu(TMP, lhs_high, TMP);
3106 __ LoadConst32(AT, imm_low);
3107 __ Sltu(AT, AT, lhs_low);
3108 __ Blt(TMP, AT, label);
3109 break;
3110 }
3111 } else {
3112 switch (cond) {
3113 case kCondEQ:
3114 __ Xor(TMP, lhs_high, rhs_high);
3115 __ Xor(AT, lhs_low, rhs_low);
3116 __ Or(TMP, TMP, AT);
3117 __ Beqz(TMP, label);
3118 break;
3119 case kCondNE:
3120 __ Xor(TMP, lhs_high, rhs_high);
3121 __ Xor(AT, lhs_low, rhs_low);
3122 __ Or(TMP, TMP, AT);
3123 __ Bnez(TMP, label);
3124 break;
3125 case kCondLT:
3126 __ Blt(lhs_high, rhs_high, label);
3127 __ Slt(TMP, rhs_high, lhs_high);
3128 __ Sltu(AT, lhs_low, rhs_low);
3129 __ Blt(TMP, AT, label);
3130 break;
3131 case kCondGE:
3132 __ Blt(rhs_high, lhs_high, label);
3133 __ Slt(TMP, lhs_high, rhs_high);
3134 __ Sltu(AT, lhs_low, rhs_low);
3135 __ Or(TMP, TMP, AT);
3136 __ Beqz(TMP, label);
3137 break;
3138 case kCondLE:
3139 __ Blt(lhs_high, rhs_high, label);
3140 __ Slt(TMP, rhs_high, lhs_high);
3141 __ Sltu(AT, rhs_low, lhs_low);
3142 __ Or(TMP, TMP, AT);
3143 __ Beqz(TMP, label);
3144 break;
3145 case kCondGT:
3146 __ Blt(rhs_high, lhs_high, label);
3147 __ Slt(TMP, lhs_high, rhs_high);
3148 __ Sltu(AT, rhs_low, lhs_low);
3149 __ Blt(TMP, AT, label);
3150 break;
3151 case kCondB:
3152 __ Bltu(lhs_high, rhs_high, label);
3153 __ Sltu(TMP, rhs_high, lhs_high);
3154 __ Sltu(AT, lhs_low, rhs_low);
3155 __ Blt(TMP, AT, label);
3156 break;
3157 case kCondAE:
3158 __ Bltu(rhs_high, lhs_high, label);
3159 __ Sltu(TMP, lhs_high, rhs_high);
3160 __ Sltu(AT, lhs_low, rhs_low);
3161 __ Or(TMP, TMP, AT);
3162 __ Beqz(TMP, label);
3163 break;
3164 case kCondBE:
3165 __ Bltu(lhs_high, rhs_high, label);
3166 __ Sltu(TMP, rhs_high, lhs_high);
3167 __ Sltu(AT, rhs_low, lhs_low);
3168 __ Or(TMP, TMP, AT);
3169 __ Beqz(TMP, label);
3170 break;
3171 case kCondA:
3172 __ Bltu(rhs_high, lhs_high, label);
3173 __ Sltu(TMP, lhs_high, rhs_high);
3174 __ Sltu(AT, rhs_low, lhs_low);
3175 __ Blt(TMP, AT, label);
3176 break;
3177 }
3178 }
3179}
3180
3181void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond,
3182 bool gt_bias,
3183 Primitive::Type type,
3184 LocationSummary* locations,
3185 MipsLabel* label) {
3186 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
3187 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
3188 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
3189 if (type == Primitive::kPrimFloat) {
3190 if (isR6) {
3191 switch (cond) {
3192 case kCondEQ:
3193 __ CmpEqS(FTMP, lhs, rhs);
3194 __ Bc1nez(FTMP, label);
3195 break;
3196 case kCondNE:
3197 __ CmpEqS(FTMP, lhs, rhs);
3198 __ Bc1eqz(FTMP, label);
3199 break;
3200 case kCondLT:
3201 if (gt_bias) {
3202 __ CmpLtS(FTMP, lhs, rhs);
3203 } else {
3204 __ CmpUltS(FTMP, lhs, rhs);
3205 }
3206 __ Bc1nez(FTMP, label);
3207 break;
3208 case kCondLE:
3209 if (gt_bias) {
3210 __ CmpLeS(FTMP, lhs, rhs);
3211 } else {
3212 __ CmpUleS(FTMP, lhs, rhs);
3213 }
3214 __ Bc1nez(FTMP, label);
3215 break;
3216 case kCondGT:
3217 if (gt_bias) {
3218 __ CmpUltS(FTMP, rhs, lhs);
3219 } else {
3220 __ CmpLtS(FTMP, rhs, lhs);
3221 }
3222 __ Bc1nez(FTMP, label);
3223 break;
3224 case kCondGE:
3225 if (gt_bias) {
3226 __ CmpUleS(FTMP, rhs, lhs);
3227 } else {
3228 __ CmpLeS(FTMP, rhs, lhs);
3229 }
3230 __ Bc1nez(FTMP, label);
3231 break;
3232 default:
3233 LOG(FATAL) << "Unexpected non-floating-point condition";
3234 }
3235 } else {
3236 switch (cond) {
3237 case kCondEQ:
3238 __ CeqS(0, lhs, rhs);
3239 __ Bc1t(0, label);
3240 break;
3241 case kCondNE:
3242 __ CeqS(0, lhs, rhs);
3243 __ Bc1f(0, label);
3244 break;
3245 case kCondLT:
3246 if (gt_bias) {
3247 __ ColtS(0, lhs, rhs);
3248 } else {
3249 __ CultS(0, lhs, rhs);
3250 }
3251 __ Bc1t(0, label);
3252 break;
3253 case kCondLE:
3254 if (gt_bias) {
3255 __ ColeS(0, lhs, rhs);
3256 } else {
3257 __ CuleS(0, lhs, rhs);
3258 }
3259 __ Bc1t(0, label);
3260 break;
3261 case kCondGT:
3262 if (gt_bias) {
3263 __ CultS(0, rhs, lhs);
3264 } else {
3265 __ ColtS(0, rhs, lhs);
3266 }
3267 __ Bc1t(0, label);
3268 break;
3269 case kCondGE:
3270 if (gt_bias) {
3271 __ CuleS(0, rhs, lhs);
3272 } else {
3273 __ ColeS(0, rhs, lhs);
3274 }
3275 __ Bc1t(0, label);
3276 break;
3277 default:
3278 LOG(FATAL) << "Unexpected non-floating-point condition";
3279 }
3280 }
3281 } else {
3282 DCHECK_EQ(type, Primitive::kPrimDouble);
3283 if (isR6) {
3284 switch (cond) {
3285 case kCondEQ:
3286 __ CmpEqD(FTMP, lhs, rhs);
3287 __ Bc1nez(FTMP, label);
3288 break;
3289 case kCondNE:
3290 __ CmpEqD(FTMP, lhs, rhs);
3291 __ Bc1eqz(FTMP, label);
3292 break;
3293 case kCondLT:
3294 if (gt_bias) {
3295 __ CmpLtD(FTMP, lhs, rhs);
3296 } else {
3297 __ CmpUltD(FTMP, lhs, rhs);
3298 }
3299 __ Bc1nez(FTMP, label);
3300 break;
3301 case kCondLE:
3302 if (gt_bias) {
3303 __ CmpLeD(FTMP, lhs, rhs);
3304 } else {
3305 __ CmpUleD(FTMP, lhs, rhs);
3306 }
3307 __ Bc1nez(FTMP, label);
3308 break;
3309 case kCondGT:
3310 if (gt_bias) {
3311 __ CmpUltD(FTMP, rhs, lhs);
3312 } else {
3313 __ CmpLtD(FTMP, rhs, lhs);
3314 }
3315 __ Bc1nez(FTMP, label);
3316 break;
3317 case kCondGE:
3318 if (gt_bias) {
3319 __ CmpUleD(FTMP, rhs, lhs);
3320 } else {
3321 __ CmpLeD(FTMP, rhs, lhs);
3322 }
3323 __ Bc1nez(FTMP, label);
3324 break;
3325 default:
3326 LOG(FATAL) << "Unexpected non-floating-point condition";
3327 }
3328 } else {
3329 switch (cond) {
3330 case kCondEQ:
3331 __ CeqD(0, lhs, rhs);
3332 __ Bc1t(0, label);
3333 break;
3334 case kCondNE:
3335 __ CeqD(0, lhs, rhs);
3336 __ Bc1f(0, label);
3337 break;
3338 case kCondLT:
3339 if (gt_bias) {
3340 __ ColtD(0, lhs, rhs);
3341 } else {
3342 __ CultD(0, lhs, rhs);
3343 }
3344 __ Bc1t(0, label);
3345 break;
3346 case kCondLE:
3347 if (gt_bias) {
3348 __ ColeD(0, lhs, rhs);
3349 } else {
3350 __ CuleD(0, lhs, rhs);
3351 }
3352 __ Bc1t(0, label);
3353 break;
3354 case kCondGT:
3355 if (gt_bias) {
3356 __ CultD(0, rhs, lhs);
3357 } else {
3358 __ ColtD(0, rhs, lhs);
3359 }
3360 __ Bc1t(0, label);
3361 break;
3362 case kCondGE:
3363 if (gt_bias) {
3364 __ CuleD(0, rhs, lhs);
3365 } else {
3366 __ ColeD(0, rhs, lhs);
3367 }
3368 __ Bc1t(0, label);
3369 break;
3370 default:
3371 LOG(FATAL) << "Unexpected non-floating-point condition";
3372 }
3373 }
3374 }
3375}
3376
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003377void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00003378 size_t condition_input_index,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003379 MipsLabel* true_target,
David Brazdil0debae72015-11-12 18:37:00 +00003380 MipsLabel* false_target) {
3381 HInstruction* cond = instruction->InputAt(condition_input_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003382
David Brazdil0debae72015-11-12 18:37:00 +00003383 if (true_target == nullptr && false_target == nullptr) {
3384 // Nothing to do. The code always falls through.
3385 return;
3386 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00003387 // Constant condition, statically compared against "true" (integer value 1).
3388 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00003389 if (true_target != nullptr) {
3390 __ B(true_target);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003391 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003392 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00003393 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00003394 if (false_target != nullptr) {
3395 __ B(false_target);
3396 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003397 }
David Brazdil0debae72015-11-12 18:37:00 +00003398 return;
3399 }
3400
3401 // The following code generates these patterns:
3402 // (1) true_target == nullptr && false_target != nullptr
3403 // - opposite condition true => branch to false_target
3404 // (2) true_target != nullptr && false_target == nullptr
3405 // - condition true => branch to true_target
3406 // (3) true_target != nullptr && false_target != nullptr
3407 // - condition true => branch to true_target
3408 // - branch to false_target
3409 if (IsBooleanValueOrMaterializedCondition(cond)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003410 // The condition instruction has been materialized, compare the output to 0.
David Brazdil0debae72015-11-12 18:37:00 +00003411 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003412 DCHECK(cond_val.IsRegister());
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003413 if (true_target == nullptr) {
David Brazdil0debae72015-11-12 18:37:00 +00003414 __ Beqz(cond_val.AsRegister<Register>(), false_target);
3415 } else {
3416 __ Bnez(cond_val.AsRegister<Register>(), true_target);
3417 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003418 } else {
3419 // The condition instruction has not been materialized, use its inputs as
3420 // the comparison and its condition as the branch condition.
David Brazdil0debae72015-11-12 18:37:00 +00003421 HCondition* condition = cond->AsCondition();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003422 Primitive::Type type = condition->InputAt(0)->GetType();
3423 LocationSummary* locations = cond->GetLocations();
3424 IfCondition if_cond = condition->GetCondition();
3425 MipsLabel* branch_target = true_target;
David Brazdil0debae72015-11-12 18:37:00 +00003426
David Brazdil0debae72015-11-12 18:37:00 +00003427 if (true_target == nullptr) {
3428 if_cond = condition->GetOppositeCondition();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003429 branch_target = false_target;
David Brazdil0debae72015-11-12 18:37:00 +00003430 }
3431
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003432 switch (type) {
3433 default:
3434 GenerateIntCompareAndBranch(if_cond, locations, branch_target);
3435 break;
3436 case Primitive::kPrimLong:
3437 GenerateLongCompareAndBranch(if_cond, locations, branch_target);
3438 break;
3439 case Primitive::kPrimFloat:
3440 case Primitive::kPrimDouble:
3441 GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target);
3442 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003443 }
3444 }
David Brazdil0debae72015-11-12 18:37:00 +00003445
3446 // If neither branch falls through (case 3), the conditional branch to `true_target`
3447 // was already emitted (case 2) and we need to emit a jump to `false_target`.
3448 if (true_target != nullptr && false_target != nullptr) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003449 __ B(false_target);
3450 }
3451}
3452
3453void LocationsBuilderMIPS::VisitIf(HIf* if_instr) {
3454 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
David Brazdil0debae72015-11-12 18:37:00 +00003455 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003456 locations->SetInAt(0, Location::RequiresRegister());
3457 }
3458}
3459
3460void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00003461 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
3462 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
3463 MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
3464 nullptr : codegen_->GetLabelOf(true_successor);
3465 MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
3466 nullptr : codegen_->GetLabelOf(false_successor);
3467 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003468}
3469
3470void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) {
3471 LocationSummary* locations = new (GetGraph()->GetArena())
3472 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
David Brazdil0debae72015-11-12 18:37:00 +00003473 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003474 locations->SetInAt(0, Location::RequiresRegister());
3475 }
3476}
3477
3478void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08003479 SlowPathCodeMIPS* slow_path =
3480 deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00003481 GenerateTestAndBranch(deoptimize,
3482 /* condition_input_index */ 0,
3483 slow_path->GetEntryLabel(),
3484 /* false_target */ nullptr);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003485}
3486
David Brazdil74eb1b22015-12-14 11:44:01 +00003487void LocationsBuilderMIPS::VisitSelect(HSelect* select) {
3488 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select);
3489 if (Primitive::IsFloatingPointType(select->GetType())) {
3490 locations->SetInAt(0, Location::RequiresFpuRegister());
3491 locations->SetInAt(1, Location::RequiresFpuRegister());
3492 } else {
3493 locations->SetInAt(0, Location::RequiresRegister());
3494 locations->SetInAt(1, Location::RequiresRegister());
3495 }
3496 if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) {
3497 locations->SetInAt(2, Location::RequiresRegister());
3498 }
3499 locations->SetOut(Location::SameAsFirstInput());
3500}
3501
3502void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) {
3503 LocationSummary* locations = select->GetLocations();
3504 MipsLabel false_target;
3505 GenerateTestAndBranch(select,
3506 /* condition_input_index */ 2,
3507 /* true_target */ nullptr,
3508 &false_target);
3509 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
3510 __ Bind(&false_target);
3511}
3512
David Srbecky0cf44932015-12-09 14:09:59 +00003513void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) {
3514 new (GetGraph()->GetArena()) LocationSummary(info);
3515}
3516
David Srbeckyd28f4a02016-03-14 17:14:24 +00003517void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) {
3518 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00003519}
3520
3521void CodeGeneratorMIPS::GenerateNop() {
3522 __ Nop();
David Srbecky0cf44932015-12-09 14:09:59 +00003523}
3524
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003525void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3526 Primitive::Type field_type = field_info.GetFieldType();
3527 bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble);
3528 bool generate_volatile = field_info.IsVolatile() && is_wide;
3529 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003530 instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003531
3532 locations->SetInAt(0, Location::RequiresRegister());
3533 if (generate_volatile) {
3534 InvokeRuntimeCallingConvention calling_convention;
3535 // need A0 to hold base + offset
3536 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3537 if (field_type == Primitive::kPrimLong) {
3538 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimLong));
3539 } else {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02003540 // Use Location::Any() to prevent situations when running out of available fp registers.
3541 locations->SetOut(Location::Any());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003542 // Need some temp core regs since FP results are returned in core registers
3543 Location reg = calling_convention.GetReturnLocation(Primitive::kPrimLong);
3544 locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>()));
3545 locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>()));
3546 }
3547 } else {
3548 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3549 locations->SetOut(Location::RequiresFpuRegister());
3550 } else {
3551 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3552 }
3553 }
3554}
3555
3556void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction,
3557 const FieldInfo& field_info,
3558 uint32_t dex_pc) {
3559 Primitive::Type type = field_info.GetFieldType();
3560 LocationSummary* locations = instruction->GetLocations();
3561 Register obj = locations->InAt(0).AsRegister<Register>();
3562 LoadOperandType load_type = kLoadUnsignedByte;
3563 bool is_volatile = field_info.IsVolatile();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003564 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Alexey Frunze2923db72016-08-20 01:55:47 -07003565 auto null_checker = GetImplicitNullChecker(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003566
3567 switch (type) {
3568 case Primitive::kPrimBoolean:
3569 load_type = kLoadUnsignedByte;
3570 break;
3571 case Primitive::kPrimByte:
3572 load_type = kLoadSignedByte;
3573 break;
3574 case Primitive::kPrimShort:
3575 load_type = kLoadSignedHalfword;
3576 break;
3577 case Primitive::kPrimChar:
3578 load_type = kLoadUnsignedHalfword;
3579 break;
3580 case Primitive::kPrimInt:
3581 case Primitive::kPrimFloat:
3582 case Primitive::kPrimNot:
3583 load_type = kLoadWord;
3584 break;
3585 case Primitive::kPrimLong:
3586 case Primitive::kPrimDouble:
3587 load_type = kLoadDoubleword;
3588 break;
3589 case Primitive::kPrimVoid:
3590 LOG(FATAL) << "Unreachable type " << type;
3591 UNREACHABLE();
3592 }
3593
3594 if (is_volatile && load_type == kLoadDoubleword) {
3595 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003596 __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003597 // Do implicit Null check
3598 __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0);
3599 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Serban Constantinescufca16662016-07-14 09:21:59 +01003600 codegen_->InvokeRuntime(kQuickA64Load, instruction, dex_pc);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003601 CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>();
3602 if (type == Primitive::kPrimDouble) {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02003603 // FP results are returned in core registers. Need to move them.
3604 Location out = locations->Out();
3605 if (out.IsFpuRegister()) {
3606 __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), out.AsFpuRegister<FRegister>());
3607 __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(),
3608 out.AsFpuRegister<FRegister>());
3609 } else {
3610 DCHECK(out.IsDoubleStackSlot());
3611 __ StoreToOffset(kStoreWord,
3612 locations->GetTemp(1).AsRegister<Register>(),
3613 SP,
3614 out.GetStackIndex());
3615 __ StoreToOffset(kStoreWord,
3616 locations->GetTemp(2).AsRegister<Register>(),
3617 SP,
3618 out.GetStackIndex() + 4);
3619 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003620 }
3621 } else {
3622 if (!Primitive::IsFloatingPointType(type)) {
3623 Register dst;
3624 if (type == Primitive::kPrimLong) {
3625 DCHECK(locations->Out().IsRegisterPair());
3626 dst = locations->Out().AsRegisterPairLow<Register>();
3627 } else {
3628 DCHECK(locations->Out().IsRegister());
3629 dst = locations->Out().AsRegister<Register>();
3630 }
Alexey Frunze2923db72016-08-20 01:55:47 -07003631 __ LoadFromOffset(load_type, dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003632 } else {
3633 DCHECK(locations->Out().IsFpuRegister());
3634 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
3635 if (type == Primitive::kPrimFloat) {
Alexey Frunze2923db72016-08-20 01:55:47 -07003636 __ LoadSFromOffset(dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003637 } else {
Alexey Frunze2923db72016-08-20 01:55:47 -07003638 __ LoadDFromOffset(dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003639 }
3640 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003641 }
3642
3643 if (is_volatile) {
3644 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3645 }
3646}
3647
3648void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3649 Primitive::Type field_type = field_info.GetFieldType();
3650 bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble);
3651 bool generate_volatile = field_info.IsVolatile() && is_wide;
3652 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003653 instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003654
3655 locations->SetInAt(0, Location::RequiresRegister());
3656 if (generate_volatile) {
3657 InvokeRuntimeCallingConvention calling_convention;
3658 // need A0 to hold base + offset
3659 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3660 if (field_type == Primitive::kPrimLong) {
3661 locations->SetInAt(1, Location::RegisterPairLocation(
3662 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
3663 } else {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02003664 // Use Location::Any() to prevent situations when running out of available fp registers.
3665 locations->SetInAt(1, Location::Any());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003666 // Pass FP parameters in core registers.
3667 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
3668 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3)));
3669 }
3670 } else {
3671 if (Primitive::IsFloatingPointType(field_type)) {
3672 locations->SetInAt(1, Location::RequiresFpuRegister());
3673 } else {
3674 locations->SetInAt(1, Location::RequiresRegister());
3675 }
3676 }
3677}
3678
3679void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction,
3680 const FieldInfo& field_info,
3681 uint32_t dex_pc) {
3682 Primitive::Type type = field_info.GetFieldType();
3683 LocationSummary* locations = instruction->GetLocations();
3684 Register obj = locations->InAt(0).AsRegister<Register>();
3685 StoreOperandType store_type = kStoreByte;
3686 bool is_volatile = field_info.IsVolatile();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003687 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Alexey Frunze2923db72016-08-20 01:55:47 -07003688 auto null_checker = GetImplicitNullChecker(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003689
3690 switch (type) {
3691 case Primitive::kPrimBoolean:
3692 case Primitive::kPrimByte:
3693 store_type = kStoreByte;
3694 break;
3695 case Primitive::kPrimShort:
3696 case Primitive::kPrimChar:
3697 store_type = kStoreHalfword;
3698 break;
3699 case Primitive::kPrimInt:
3700 case Primitive::kPrimFloat:
3701 case Primitive::kPrimNot:
3702 store_type = kStoreWord;
3703 break;
3704 case Primitive::kPrimLong:
3705 case Primitive::kPrimDouble:
3706 store_type = kStoreDoubleword;
3707 break;
3708 case Primitive::kPrimVoid:
3709 LOG(FATAL) << "Unreachable type " << type;
3710 UNREACHABLE();
3711 }
3712
3713 if (is_volatile) {
3714 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3715 }
3716
3717 if (is_volatile && store_type == kStoreDoubleword) {
3718 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003719 __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003720 // Do implicit Null check.
3721 __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0);
3722 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3723 if (type == Primitive::kPrimDouble) {
3724 // Pass FP parameters in core registers.
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02003725 Location in = locations->InAt(1);
3726 if (in.IsFpuRegister()) {
3727 __ Mfc1(locations->GetTemp(1).AsRegister<Register>(), in.AsFpuRegister<FRegister>());
3728 __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(),
3729 in.AsFpuRegister<FRegister>());
3730 } else if (in.IsDoubleStackSlot()) {
3731 __ LoadFromOffset(kLoadWord,
3732 locations->GetTemp(1).AsRegister<Register>(),
3733 SP,
3734 in.GetStackIndex());
3735 __ LoadFromOffset(kLoadWord,
3736 locations->GetTemp(2).AsRegister<Register>(),
3737 SP,
3738 in.GetStackIndex() + 4);
3739 } else {
3740 DCHECK(in.IsConstant());
3741 DCHECK(in.GetConstant()->IsDoubleConstant());
3742 int64_t value = bit_cast<int64_t, double>(in.GetConstant()->AsDoubleConstant()->GetValue());
3743 __ LoadConst64(locations->GetTemp(2).AsRegister<Register>(),
3744 locations->GetTemp(1).AsRegister<Register>(),
3745 value);
3746 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003747 }
Serban Constantinescufca16662016-07-14 09:21:59 +01003748 codegen_->InvokeRuntime(kQuickA64Store, instruction, dex_pc);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003749 CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>();
3750 } else {
3751 if (!Primitive::IsFloatingPointType(type)) {
3752 Register src;
3753 if (type == Primitive::kPrimLong) {
3754 DCHECK(locations->InAt(1).IsRegisterPair());
3755 src = locations->InAt(1).AsRegisterPairLow<Register>();
3756 } else {
3757 DCHECK(locations->InAt(1).IsRegister());
3758 src = locations->InAt(1).AsRegister<Register>();
3759 }
Alexey Frunze2923db72016-08-20 01:55:47 -07003760 __ StoreToOffset(store_type, src, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003761 } else {
3762 DCHECK(locations->InAt(1).IsFpuRegister());
3763 FRegister src = locations->InAt(1).AsFpuRegister<FRegister>();
3764 if (type == Primitive::kPrimFloat) {
Alexey Frunze2923db72016-08-20 01:55:47 -07003765 __ StoreSToOffset(src, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003766 } else {
Alexey Frunze2923db72016-08-20 01:55:47 -07003767 __ StoreDToOffset(src, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003768 }
3769 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003770 }
3771
3772 // TODO: memory barriers?
3773 if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) {
3774 DCHECK(locations->InAt(1).IsRegister());
3775 Register src = locations->InAt(1).AsRegister<Register>();
3776 codegen_->MarkGCCard(obj, src);
3777 }
3778
3779 if (is_volatile) {
3780 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3781 }
3782}
3783
3784void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3785 HandleFieldGet(instruction, instruction->GetFieldInfo());
3786}
3787
3788void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3789 HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
3790}
3791
3792void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3793 HandleFieldSet(instruction, instruction->GetFieldInfo());
3794}
3795
3796void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3797 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
3798}
3799
Alexey Frunze06a46c42016-07-19 15:00:40 -07003800void InstructionCodeGeneratorMIPS::GenerateGcRootFieldLoad(
3801 HInstruction* instruction ATTRIBUTE_UNUSED,
3802 Location root,
3803 Register obj,
3804 uint32_t offset) {
3805 Register root_reg = root.AsRegister<Register>();
3806 if (kEmitCompilerReadBarrier) {
3807 UNIMPLEMENTED(FATAL) << "for read barrier";
3808 } else {
3809 // Plain GC root load with no read barrier.
3810 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
3811 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
3812 // Note that GC roots are not affected by heap poisoning, thus we
3813 // do not have to unpoison `root_reg` here.
3814 }
3815}
3816
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003817void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) {
3818 LocationSummary::CallKind call_kind =
3819 instruction->IsExactCheck() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
3820 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3821 locations->SetInAt(0, Location::RequiresRegister());
3822 locations->SetInAt(1, Location::RequiresRegister());
3823 // The output does overlap inputs.
3824 // Note that TypeCheckSlowPathMIPS uses this register too.
3825 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3826}
3827
3828void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) {
3829 LocationSummary* locations = instruction->GetLocations();
3830 Register obj = locations->InAt(0).AsRegister<Register>();
3831 Register cls = locations->InAt(1).AsRegister<Register>();
3832 Register out = locations->Out().AsRegister<Register>();
3833
3834 MipsLabel done;
3835
3836 // Return 0 if `obj` is null.
3837 // TODO: Avoid this check if we know `obj` is not null.
3838 __ Move(out, ZERO);
3839 __ Beqz(obj, &done);
3840
3841 // Compare the class of `obj` with `cls`.
3842 __ LoadFromOffset(kLoadWord, out, obj, mirror::Object::ClassOffset().Int32Value());
3843 if (instruction->IsExactCheck()) {
3844 // Classes must be equal for the instanceof to succeed.
3845 __ Xor(out, out, cls);
3846 __ Sltiu(out, out, 1);
3847 } else {
3848 // If the classes are not equal, we go into a slow path.
3849 DCHECK(locations->OnlyCallsOnSlowPath());
3850 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction);
3851 codegen_->AddSlowPath(slow_path);
3852 __ Bne(out, cls, slow_path->GetEntryLabel());
3853 __ LoadConst32(out, 1);
3854 __ Bind(slow_path->GetExitLabel());
3855 }
3856
3857 __ Bind(&done);
3858}
3859
3860void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) {
3861 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
3862 locations->SetOut(Location::ConstantLocation(constant));
3863}
3864
3865void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
3866 // Will be generated at use site.
3867}
3868
3869void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) {
3870 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
3871 locations->SetOut(Location::ConstantLocation(constant));
3872}
3873
3874void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
3875 // Will be generated at use site.
3876}
3877
3878void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) {
3879 InvokeDexCallingConventionVisitorMIPS calling_convention_visitor;
3880 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
3881}
3882
3883void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) {
3884 HandleInvoke(invoke);
3885 // The register T0 is required to be used for the hidden argument in
3886 // art_quick_imt_conflict_trampoline, so add the hidden argument.
3887 invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0));
3888}
3889
3890void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) {
3891 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
3892 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003893 Location receiver = invoke->GetLocations()->InAt(0);
3894 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07003895 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003896
3897 // Set the hidden argument.
3898 __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
3899 invoke->GetDexMethodIndex());
3900
3901 // temp = object->GetClass();
3902 if (receiver.IsStackSlot()) {
3903 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
3904 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
3905 } else {
3906 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
3907 }
3908 codegen_->MaybeRecordImplicitNullCheck(invoke);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00003909 __ LoadFromOffset(kLoadWord, temp, temp,
3910 mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value());
3911 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00003912 invoke->GetImtIndex(), kMipsPointerSize));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003913 // temp = temp->GetImtEntryAt(method_offset);
3914 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
3915 // T9 = temp->GetEntryPoint();
3916 __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value());
3917 // T9();
3918 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003919 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003920 DCHECK(!codegen_->IsLeafMethod());
3921 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
3922}
3923
3924void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Chris Larsen701566a2015-10-27 15:29:13 -07003925 IntrinsicLocationsBuilderMIPS intrinsic(codegen_);
3926 if (intrinsic.TryDispatch(invoke)) {
3927 return;
3928 }
3929
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003930 HandleInvoke(invoke);
3931}
3932
3933void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00003934 // Explicit clinit checks triggered by static invokes must have been pruned by
3935 // art::PrepareForRegisterAllocation.
3936 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003937
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003938 HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind();
3939 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation();
3940 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
3941
3942 // kDirectAddressWithFixup and kCallDirectWithFixup need no extra input on R6 because
3943 // R6 has PC-relative addressing.
3944 bool has_extra_input = !isR6 &&
3945 ((method_load_kind == HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) ||
3946 (code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup));
3947
3948 if (invoke->HasPcRelativeDexCache()) {
3949 // kDexCachePcRelative is mutually exclusive with
3950 // kDirectAddressWithFixup/kCallDirectWithFixup.
3951 CHECK(!has_extra_input);
3952 has_extra_input = true;
3953 }
3954
Chris Larsen701566a2015-10-27 15:29:13 -07003955 IntrinsicLocationsBuilderMIPS intrinsic(codegen_);
3956 if (intrinsic.TryDispatch(invoke)) {
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003957 if (invoke->GetLocations()->CanCall() && has_extra_input) {
3958 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any());
3959 }
Chris Larsen701566a2015-10-27 15:29:13 -07003960 return;
3961 }
3962
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003963 HandleInvoke(invoke);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003964
3965 // Add the extra input register if either the dex cache array base register
3966 // or the PC-relative base register for accessing literals is needed.
3967 if (has_extra_input) {
3968 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister());
3969 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003970}
3971
Chris Larsen701566a2015-10-27 15:29:13 -07003972static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003973 if (invoke->GetLocations()->Intrinsified()) {
Chris Larsen701566a2015-10-27 15:29:13 -07003974 IntrinsicCodeGeneratorMIPS intrinsic(codegen);
3975 intrinsic.Dispatch(invoke);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003976 return true;
3977 }
3978 return false;
3979}
3980
Vladimir Markocac5a7e2016-02-22 10:39:50 +00003981HLoadString::LoadKind CodeGeneratorMIPS::GetSupportedLoadStringKind(
Alexey Frunze06a46c42016-07-19 15:00:40 -07003982 HLoadString::LoadKind desired_string_load_kind) {
3983 if (kEmitCompilerReadBarrier) {
3984 UNIMPLEMENTED(FATAL) << "for read barrier";
3985 }
3986 // We disable PC-relative load when there is an irreducible loop, as the optimization
3987 // is incompatible with it.
3988 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
3989 bool fallback_load = has_irreducible_loops;
3990 switch (desired_string_load_kind) {
3991 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
3992 DCHECK(!GetCompilerOptions().GetCompilePic());
3993 break;
3994 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
3995 DCHECK(GetCompilerOptions().GetCompilePic());
3996 break;
3997 case HLoadString::LoadKind::kBootImageAddress:
3998 break;
3999 case HLoadString::LoadKind::kDexCacheAddress:
4000 DCHECK(Runtime::Current()->UseJitCompilation());
4001 fallback_load = false;
4002 break;
4003 case HLoadString::LoadKind::kDexCachePcRelative:
4004 DCHECK(!Runtime::Current()->UseJitCompilation());
4005 // TODO: Create as many MipsDexCacheArraysBase instructions as needed for methods
4006 // with irreducible loops.
4007 break;
4008 case HLoadString::LoadKind::kDexCacheViaMethod:
4009 fallback_load = false;
4010 break;
4011 }
4012 if (fallback_load) {
4013 desired_string_load_kind = HLoadString::LoadKind::kDexCacheViaMethod;
4014 }
4015 return desired_string_load_kind;
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004016}
4017
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004018HLoadClass::LoadKind CodeGeneratorMIPS::GetSupportedLoadClassKind(
4019 HLoadClass::LoadKind desired_class_load_kind) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07004020 if (kEmitCompilerReadBarrier) {
4021 UNIMPLEMENTED(FATAL) << "for read barrier";
4022 }
4023 // We disable pc-relative load when there is an irreducible loop, as the optimization
4024 // is incompatible with it.
4025 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
4026 bool fallback_load = has_irreducible_loops;
4027 switch (desired_class_load_kind) {
4028 case HLoadClass::LoadKind::kReferrersClass:
4029 fallback_load = false;
4030 break;
4031 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
4032 DCHECK(!GetCompilerOptions().GetCompilePic());
4033 break;
4034 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
4035 DCHECK(GetCompilerOptions().GetCompilePic());
4036 break;
4037 case HLoadClass::LoadKind::kBootImageAddress:
4038 break;
4039 case HLoadClass::LoadKind::kDexCacheAddress:
4040 DCHECK(Runtime::Current()->UseJitCompilation());
4041 fallback_load = false;
4042 break;
4043 case HLoadClass::LoadKind::kDexCachePcRelative:
4044 DCHECK(!Runtime::Current()->UseJitCompilation());
4045 // TODO: Create as many MipsDexCacheArraysBase instructions as needed for methods
4046 // with irreducible loops.
4047 break;
4048 case HLoadClass::LoadKind::kDexCacheViaMethod:
4049 fallback_load = false;
4050 break;
4051 }
4052 if (fallback_load) {
4053 desired_class_load_kind = HLoadClass::LoadKind::kDexCacheViaMethod;
4054 }
4055 return desired_class_load_kind;
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004056}
4057
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004058Register CodeGeneratorMIPS::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke,
4059 Register temp) {
4060 CHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u);
4061 Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
4062 if (!invoke->GetLocations()->Intrinsified()) {
4063 return location.AsRegister<Register>();
4064 }
4065 // For intrinsics we allow any location, so it may be on the stack.
4066 if (!location.IsRegister()) {
4067 __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex());
4068 return temp;
4069 }
4070 // For register locations, check if the register was saved. If so, get it from the stack.
4071 // Note: There is a chance that the register was saved but not overwritten, so we could
4072 // save one load. However, since this is just an intrinsic slow path we prefer this
4073 // simple and more robust approach rather that trying to determine if that's the case.
4074 SlowPathCode* slow_path = GetCurrentSlowPath();
4075 DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path.
4076 if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) {
4077 int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>());
4078 __ LoadFromOffset(kLoadWord, temp, SP, stack_offset);
4079 return temp;
4080 }
4081 return location.AsRegister<Register>();
4082}
4083
Vladimir Markodc151b22015-10-15 18:02:30 +01004084HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch(
4085 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
4086 MethodReference target_method ATTRIBUTE_UNUSED) {
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004087 HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info;
4088 // We disable PC-relative load when there is an irreducible loop, as the optimization
4089 // is incompatible with it.
4090 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
4091 bool fallback_load = true;
4092 bool fallback_call = true;
4093 switch (dispatch_info.method_load_kind) {
Vladimir Markodc151b22015-10-15 18:02:30 +01004094 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
4095 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004096 fallback_load = has_irreducible_loops;
4097 break;
Vladimir Markodc151b22015-10-15 18:02:30 +01004098 default:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004099 fallback_load = false;
Vladimir Markodc151b22015-10-15 18:02:30 +01004100 break;
4101 }
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004102 switch (dispatch_info.code_ptr_location) {
Vladimir Markodc151b22015-10-15 18:02:30 +01004103 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004104 fallback_call = has_irreducible_loops;
4105 break;
Vladimir Markodc151b22015-10-15 18:02:30 +01004106 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004107 // TODO: Implement this type.
4108 break;
Vladimir Markodc151b22015-10-15 18:02:30 +01004109 default:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004110 fallback_call = false;
4111 break;
Vladimir Markodc151b22015-10-15 18:02:30 +01004112 }
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004113 if (fallback_load) {
4114 dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod;
4115 dispatch_info.method_load_data = 0;
4116 }
4117 if (fallback_call) {
4118 dispatch_info.code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod;
4119 dispatch_info.direct_code_ptr = 0;
4120 }
4121 return dispatch_info;
Vladimir Markodc151b22015-10-15 18:02:30 +01004122}
4123
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004124void CodeGeneratorMIPS::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
4125 // All registers are assumed to be correctly set up per the calling convention.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004126 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004127 HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind();
4128 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation();
4129 bool isR6 = isa_features_.IsR6();
4130 // kDirectAddressWithFixup and kCallDirectWithFixup have no extra input on R6 because
4131 // R6 has PC-relative addressing.
4132 bool has_extra_input = invoke->HasPcRelativeDexCache() ||
4133 (!isR6 &&
4134 ((method_load_kind == HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) ||
4135 (code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup)));
4136 Register base_reg = has_extra_input
4137 ? GetInvokeStaticOrDirectExtraParameter(invoke, temp.AsRegister<Register>())
4138 : ZERO;
4139
4140 // For better instruction scheduling we load the direct code pointer before the method pointer.
4141 switch (code_ptr_location) {
4142 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
4143 // T9 = invoke->GetDirectCodePtr();
4144 __ LoadConst32(T9, invoke->GetDirectCodePtr());
4145 break;
4146 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
4147 // T9 = code address from literal pool with link-time patch.
4148 __ LoadLiteral(T9, base_reg, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod()));
4149 break;
4150 default:
4151 break;
4152 }
4153
4154 switch (method_load_kind) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004155 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
4156 // temp = thread->string_init_entrypoint
4157 __ LoadFromOffset(kLoadWord,
4158 temp.AsRegister<Register>(),
4159 TR,
4160 invoke->GetStringInitOffset());
4161 break;
4162 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00004163 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004164 break;
4165 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
4166 __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress());
4167 break;
4168 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004169 __ LoadLiteral(temp.AsRegister<Register>(),
4170 base_reg,
4171 DeduplicateMethodAddressLiteral(invoke->GetTargetMethod()));
4172 break;
4173 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: {
4174 HMipsDexCacheArraysBase* base =
4175 invoke->InputAt(invoke->GetSpecialInputIndex())->AsMipsDexCacheArraysBase();
4176 int32_t offset =
4177 invoke->GetDexCacheArrayOffset() - base->GetElementOffset() - kDexCacheArrayLwOffset;
4178 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset);
4179 break;
4180 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004181 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
Vladimir Markoc53c0792015-11-19 15:48:33 +00004182 Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004183 Register reg = temp.AsRegister<Register>();
4184 Register method_reg;
4185 if (current_method.IsRegister()) {
4186 method_reg = current_method.AsRegister<Register>();
4187 } else {
4188 // TODO: use the appropriate DCHECK() here if possible.
4189 // DCHECK(invoke->GetLocations()->Intrinsified());
4190 DCHECK(!current_method.IsValid());
4191 method_reg = reg;
4192 __ Lw(reg, SP, kCurrentMethodStackOffset);
4193 }
4194
4195 // temp = temp->dex_cache_resolved_methods_;
4196 __ LoadFromOffset(kLoadWord,
4197 reg,
4198 method_reg,
4199 ArtMethod::DexCacheResolvedMethodsOffset(kMipsPointerSize).Int32Value());
Vladimir Marko40ecb122016-04-06 17:33:41 +01004200 // temp = temp[index_in_cache];
4201 // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file.
4202 uint32_t index_in_cache = invoke->GetDexMethodIndex();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004203 __ LoadFromOffset(kLoadWord,
4204 reg,
4205 reg,
4206 CodeGenerator::GetCachePointerOffset(index_in_cache));
4207 break;
4208 }
4209 }
4210
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004211 switch (code_ptr_location) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004212 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004213 __ Bal(&frame_entry_label_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004214 break;
4215 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004216 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
4217 // T9 prepared above for better instruction scheduling.
4218 // T9()
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004219 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004220 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004221 break;
Vladimir Markodc151b22015-10-15 18:02:30 +01004222 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004223 // TODO: Implement this type.
Vladimir Markodc151b22015-10-15 18:02:30 +01004224 // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch().
4225 LOG(FATAL) << "Unsupported";
4226 UNREACHABLE();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004227 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
4228 // T9 = callee_method->entry_point_from_quick_compiled_code_;
Goran Jakovljevic1a878372015-10-26 14:28:52 +01004229 __ LoadFromOffset(kLoadWord,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004230 T9,
4231 callee_method.AsRegister<Register>(),
4232 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07004233 kMipsPointerSize).Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004234 // T9()
4235 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004236 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004237 break;
4238 }
4239 DCHECK(!IsLeafMethod());
4240}
4241
4242void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00004243 // Explicit clinit checks triggered by static invokes must have been pruned by
4244 // art::PrepareForRegisterAllocation.
4245 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004246
4247 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
4248 return;
4249 }
4250
4251 LocationSummary* locations = invoke->GetLocations();
4252 codegen_->GenerateStaticOrDirectCall(invoke,
4253 locations->HasTemps()
4254 ? locations->GetTemp(0)
4255 : Location::NoLocation());
4256 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
4257}
4258
Chris Larsen3acee732015-11-18 13:31:08 -08004259void CodeGeneratorMIPS::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004260 LocationSummary* locations = invoke->GetLocations();
4261 Location receiver = locations->InAt(0);
Chris Larsen3acee732015-11-18 13:31:08 -08004262 Register temp = temp_location.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004263 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
4264 invoke->GetVTableIndex(), kMipsPointerSize).SizeValue();
4265 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07004266 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004267
4268 // temp = object->GetClass();
Chris Larsen3acee732015-11-18 13:31:08 -08004269 DCHECK(receiver.IsRegister());
4270 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
4271 MaybeRecordImplicitNullCheck(invoke);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004272 // temp = temp->GetMethodAt(method_offset);
4273 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
4274 // T9 = temp->GetEntryPoint();
4275 __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value());
4276 // T9();
4277 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004278 __ NopIfNoReordering();
Chris Larsen3acee732015-11-18 13:31:08 -08004279}
4280
4281void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) {
4282 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
4283 return;
4284 }
4285
4286 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004287 DCHECK(!codegen_->IsLeafMethod());
4288 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
4289}
4290
4291void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07004292 if (cls->NeedsAccessCheck()) {
4293 InvokeRuntimeCallingConvention calling_convention;
4294 CodeGenerator::CreateLoadClassLocationSummary(
4295 cls,
4296 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
4297 Location::RegisterLocation(V0),
4298 /* code_generator_supports_read_barrier */ false); // TODO: revisit this bool.
4299 return;
4300 }
4301
4302 LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier)
4303 ? LocationSummary::kCallOnSlowPath
4304 : LocationSummary::kNoCall;
4305 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
4306 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
4307 switch (load_kind) {
4308 // We need an extra register for PC-relative literals on R2.
4309 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
4310 case HLoadClass::LoadKind::kBootImageAddress:
4311 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
4312 if (codegen_->GetInstructionSetFeatures().IsR6()) {
4313 break;
4314 }
4315 FALLTHROUGH_INTENDED;
4316 // We need an extra register for PC-relative dex cache accesses.
4317 case HLoadClass::LoadKind::kDexCachePcRelative:
4318 case HLoadClass::LoadKind::kReferrersClass:
4319 case HLoadClass::LoadKind::kDexCacheViaMethod:
4320 locations->SetInAt(0, Location::RequiresRegister());
4321 break;
4322 default:
4323 break;
4324 }
4325 locations->SetOut(Location::RequiresRegister());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004326}
4327
4328void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) {
4329 LocationSummary* locations = cls->GetLocations();
Pavle Batutae87a7182015-10-28 13:10:42 +01004330 if (cls->NeedsAccessCheck()) {
4331 codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex());
Serban Constantinescufca16662016-07-14 09:21:59 +01004332 codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00004333 CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>();
Pavle Batutae87a7182015-10-28 13:10:42 +01004334 return;
4335 }
4336
Alexey Frunze06a46c42016-07-19 15:00:40 -07004337 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
4338 Location out_loc = locations->Out();
4339 Register out = out_loc.AsRegister<Register>();
4340 Register base_or_current_method_reg;
4341 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
4342 switch (load_kind) {
4343 // We need an extra register for PC-relative literals on R2.
4344 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
4345 case HLoadClass::LoadKind::kBootImageAddress:
4346 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
4347 base_or_current_method_reg = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>();
4348 break;
4349 // We need an extra register for PC-relative dex cache accesses.
4350 case HLoadClass::LoadKind::kDexCachePcRelative:
4351 case HLoadClass::LoadKind::kReferrersClass:
4352 case HLoadClass::LoadKind::kDexCacheViaMethod:
4353 base_or_current_method_reg = locations->InAt(0).AsRegister<Register>();
4354 break;
4355 default:
4356 base_or_current_method_reg = ZERO;
4357 break;
4358 }
Nicolas Geoffray42e372e2015-11-24 15:48:56 +00004359
Alexey Frunze06a46c42016-07-19 15:00:40 -07004360 bool generate_null_check = false;
4361 switch (load_kind) {
4362 case HLoadClass::LoadKind::kReferrersClass: {
4363 DCHECK(!cls->CanCallRuntime());
4364 DCHECK(!cls->MustGenerateClinitCheck());
4365 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
4366 GenerateGcRootFieldLoad(cls,
4367 out_loc,
4368 base_or_current_method_reg,
4369 ArtMethod::DeclaringClassOffset().Int32Value());
4370 break;
4371 }
4372 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
4373 DCHECK(!kEmitCompilerReadBarrier);
4374 __ LoadLiteral(out,
4375 base_or_current_method_reg,
4376 codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(),
4377 cls->GetTypeIndex()));
4378 break;
4379 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: {
4380 DCHECK(!kEmitCompilerReadBarrier);
4381 CodeGeneratorMIPS::PcRelativePatchInfo* info =
4382 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004383 bool reordering = __ SetReorder(false);
Alexey Frunze06a46c42016-07-19 15:00:40 -07004384 if (isR6) {
4385 __ Bind(&info->high_label);
4386 __ Bind(&info->pc_rel_label);
4387 // Add a 32-bit offset to PC.
4388 __ Auipc(out, /* placeholder */ 0x1234);
4389 __ Addiu(out, out, /* placeholder */ 0x5678);
Nicolas Geoffray42e372e2015-11-24 15:48:56 +00004390 } else {
Alexey Frunze06a46c42016-07-19 15:00:40 -07004391 __ Bind(&info->high_label);
4392 __ Lui(out, /* placeholder */ 0x1234);
4393 // We do not bind info->pc_rel_label here, we'll use the assembler's label
4394 // for PC-relative literals and the base from HMipsComputeBaseMethodAddress.
4395 __ Ori(out, out, /* placeholder */ 0x5678);
4396 // Add a 32-bit offset to PC.
4397 __ Addu(out, out, base_or_current_method_reg);
Nicolas Geoffray42e372e2015-11-24 15:48:56 +00004398 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004399 __ SetReorder(reordering);
Alexey Frunze06a46c42016-07-19 15:00:40 -07004400 break;
4401 }
4402 case HLoadClass::LoadKind::kBootImageAddress: {
4403 DCHECK(!kEmitCompilerReadBarrier);
4404 DCHECK_NE(cls->GetAddress(), 0u);
4405 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
4406 __ LoadLiteral(out,
4407 base_or_current_method_reg,
4408 codegen_->DeduplicateBootImageAddressLiteral(address));
4409 break;
4410 }
4411 case HLoadClass::LoadKind::kDexCacheAddress: {
4412 DCHECK_NE(cls->GetAddress(), 0u);
4413 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
4414 static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes.");
4415 DCHECK_ALIGNED(cls->GetAddress(), 4u);
4416 int16_t offset = Low16Bits(address);
4417 uint32_t base_address = address - offset; // This accounts for offset sign extension.
4418 __ Lui(out, High16Bits(base_address));
4419 // /* GcRoot<mirror::Class> */ out = *(base_address + offset)
4420 GenerateGcRootFieldLoad(cls, out_loc, out, offset);
4421 generate_null_check = !cls->IsInDexCache();
4422 break;
4423 }
4424 case HLoadClass::LoadKind::kDexCachePcRelative: {
4425 HMipsDexCacheArraysBase* base = cls->InputAt(0)->AsMipsDexCacheArraysBase();
4426 int32_t offset =
4427 cls->GetDexCacheElementOffset() - base->GetElementOffset() - kDexCacheArrayLwOffset;
4428 // /* GcRoot<mirror::Class> */ out = *(dex_cache_arrays_base + offset)
4429 GenerateGcRootFieldLoad(cls, out_loc, base_or_current_method_reg, offset);
4430 generate_null_check = !cls->IsInDexCache();
4431 break;
4432 }
4433 case HLoadClass::LoadKind::kDexCacheViaMethod: {
4434 // /* GcRoot<mirror::Class>[] */ out =
4435 // current_method.ptr_sized_fields_->dex_cache_resolved_types_
4436 __ LoadFromOffset(kLoadWord,
4437 out,
4438 base_or_current_method_reg,
4439 ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value());
4440 // /* GcRoot<mirror::Class> */ out = out[type_index]
4441 size_t offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex());
4442 GenerateGcRootFieldLoad(cls, out_loc, out, offset);
4443 generate_null_check = !cls->IsInDexCache();
4444 }
4445 }
4446
4447 if (generate_null_check || cls->MustGenerateClinitCheck()) {
4448 DCHECK(cls->CanCallRuntime());
4449 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS(
4450 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
4451 codegen_->AddSlowPath(slow_path);
4452 if (generate_null_check) {
4453 __ Beqz(out, slow_path->GetEntryLabel());
4454 }
4455 if (cls->MustGenerateClinitCheck()) {
4456 GenerateClassInitializationCheck(slow_path, out);
4457 } else {
4458 __ Bind(slow_path->GetExitLabel());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004459 }
4460 }
4461}
4462
4463static int32_t GetExceptionTlsOffset() {
Andreas Gampe542451c2016-07-26 09:02:02 -07004464 return Thread::ExceptionOffset<kMipsPointerSize>().Int32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004465}
4466
4467void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) {
4468 LocationSummary* locations =
4469 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4470 locations->SetOut(Location::RequiresRegister());
4471}
4472
4473void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) {
4474 Register out = load->GetLocations()->Out().AsRegister<Register>();
4475 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
4476}
4477
4478void LocationsBuilderMIPS::VisitClearException(HClearException* clear) {
4479 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
4480}
4481
4482void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
4483 __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset());
4484}
4485
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004486void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07004487 LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier)
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004488 ? LocationSummary::kCallOnSlowPath
4489 : LocationSummary::kNoCall;
Nicolas Geoffray917d0162015-11-24 18:25:35 +00004490 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind);
Alexey Frunze06a46c42016-07-19 15:00:40 -07004491 HLoadString::LoadKind load_kind = load->GetLoadKind();
4492 switch (load_kind) {
4493 // We need an extra register for PC-relative literals on R2.
4494 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
4495 case HLoadString::LoadKind::kBootImageAddress:
4496 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
4497 if (codegen_->GetInstructionSetFeatures().IsR6()) {
4498 break;
4499 }
4500 FALLTHROUGH_INTENDED;
4501 // We need an extra register for PC-relative dex cache accesses.
4502 case HLoadString::LoadKind::kDexCachePcRelative:
4503 case HLoadString::LoadKind::kDexCacheViaMethod:
4504 locations->SetInAt(0, Location::RequiresRegister());
4505 break;
4506 default:
4507 break;
4508 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004509 locations->SetOut(Location::RequiresRegister());
4510}
4511
4512void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07004513 HLoadString::LoadKind load_kind = load->GetLoadKind();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004514 LocationSummary* locations = load->GetLocations();
Alexey Frunze06a46c42016-07-19 15:00:40 -07004515 Location out_loc = locations->Out();
4516 Register out = out_loc.AsRegister<Register>();
4517 Register base_or_current_method_reg;
4518 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
4519 switch (load_kind) {
4520 // We need an extra register for PC-relative literals on R2.
4521 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
4522 case HLoadString::LoadKind::kBootImageAddress:
4523 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
4524 base_or_current_method_reg = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>();
4525 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07004526 default:
4527 base_or_current_method_reg = ZERO;
4528 break;
4529 }
4530
4531 switch (load_kind) {
4532 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
4533 DCHECK(!kEmitCompilerReadBarrier);
4534 __ LoadLiteral(out,
4535 base_or_current_method_reg,
4536 codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(),
4537 load->GetStringIndex()));
4538 return; // No dex cache slow path.
4539 case HLoadString::LoadKind::kBootImageLinkTimePcRelative: {
4540 DCHECK(!kEmitCompilerReadBarrier);
4541 CodeGeneratorMIPS::PcRelativePatchInfo* info =
4542 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004543 bool reordering = __ SetReorder(false);
Alexey Frunze06a46c42016-07-19 15:00:40 -07004544 if (isR6) {
4545 __ Bind(&info->high_label);
4546 __ Bind(&info->pc_rel_label);
4547 // Add a 32-bit offset to PC.
4548 __ Auipc(out, /* placeholder */ 0x1234);
4549 __ Addiu(out, out, /* placeholder */ 0x5678);
4550 } else {
4551 __ Bind(&info->high_label);
4552 __ Lui(out, /* placeholder */ 0x1234);
4553 // We do not bind info->pc_rel_label here, we'll use the assembler's label
4554 // for PC-relative literals and the base from HMipsComputeBaseMethodAddress.
4555 __ Ori(out, out, /* placeholder */ 0x5678);
4556 // Add a 32-bit offset to PC.
4557 __ Addu(out, out, base_or_current_method_reg);
4558 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004559 __ SetReorder(reordering);
Alexey Frunze06a46c42016-07-19 15:00:40 -07004560 return; // No dex cache slow path.
4561 }
4562 case HLoadString::LoadKind::kBootImageAddress: {
4563 DCHECK(!kEmitCompilerReadBarrier);
4564 DCHECK_NE(load->GetAddress(), 0u);
4565 uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress());
4566 __ LoadLiteral(out,
4567 base_or_current_method_reg,
4568 codegen_->DeduplicateBootImageAddressLiteral(address));
4569 return; // No dex cache slow path.
4570 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07004571 default:
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07004572 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07004573 }
Nicolas Geoffray917d0162015-11-24 18:25:35 +00004574
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07004575 // TODO: Re-add the compiler code to do string dex cache lookup again.
4576 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS(load);
4577 codegen_->AddSlowPath(slow_path);
4578 __ B(slow_path->GetEntryLabel());
4579 __ Bind(slow_path->GetExitLabel());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004580}
4581
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004582void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) {
4583 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
4584 locations->SetOut(Location::ConstantLocation(constant));
4585}
4586
4587void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
4588 // Will be generated at use site.
4589}
4590
4591void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) {
4592 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004593 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004594 InvokeRuntimeCallingConvention calling_convention;
4595 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4596}
4597
4598void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) {
4599 if (instruction->IsEnter()) {
Serban Constantinescufca16662016-07-14 09:21:59 +01004600 codegen_->InvokeRuntime(kQuickLockObject, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004601 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
4602 } else {
Serban Constantinescufca16662016-07-14 09:21:59 +01004603 codegen_->InvokeRuntime(kQuickUnlockObject, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004604 }
4605 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
4606}
4607
4608void LocationsBuilderMIPS::VisitMul(HMul* mul) {
4609 LocationSummary* locations =
4610 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
4611 switch (mul->GetResultType()) {
4612 case Primitive::kPrimInt:
4613 case Primitive::kPrimLong:
4614 locations->SetInAt(0, Location::RequiresRegister());
4615 locations->SetInAt(1, Location::RequiresRegister());
4616 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4617 break;
4618
4619 case Primitive::kPrimFloat:
4620 case Primitive::kPrimDouble:
4621 locations->SetInAt(0, Location::RequiresFpuRegister());
4622 locations->SetInAt(1, Location::RequiresFpuRegister());
4623 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
4624 break;
4625
4626 default:
4627 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
4628 }
4629}
4630
4631void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) {
4632 Primitive::Type type = instruction->GetType();
4633 LocationSummary* locations = instruction->GetLocations();
4634 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
4635
4636 switch (type) {
4637 case Primitive::kPrimInt: {
4638 Register dst = locations->Out().AsRegister<Register>();
4639 Register lhs = locations->InAt(0).AsRegister<Register>();
4640 Register rhs = locations->InAt(1).AsRegister<Register>();
4641
4642 if (isR6) {
4643 __ MulR6(dst, lhs, rhs);
4644 } else {
4645 __ MulR2(dst, lhs, rhs);
4646 }
4647 break;
4648 }
4649 case Primitive::kPrimLong: {
4650 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
4651 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
4652 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4653 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
4654 Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>();
4655 Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>();
4656
4657 // Extra checks to protect caused by the existance of A1_A2.
4658 // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo:
4659 // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2).
4660 DCHECK_NE(dst_high, lhs_low);
4661 DCHECK_NE(dst_high, rhs_low);
4662
4663 // A_B * C_D
4664 // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ]
4665 // dst_lo: [ low(B*D) ]
4666 // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result.
4667
4668 if (isR6) {
4669 __ MulR6(TMP, lhs_high, rhs_low);
4670 __ MulR6(dst_high, lhs_low, rhs_high);
4671 __ Addu(dst_high, dst_high, TMP);
4672 __ MuhuR6(TMP, lhs_low, rhs_low);
4673 __ Addu(dst_high, dst_high, TMP);
4674 __ MulR6(dst_low, lhs_low, rhs_low);
4675 } else {
4676 __ MulR2(TMP, lhs_high, rhs_low);
4677 __ MulR2(dst_high, lhs_low, rhs_high);
4678 __ Addu(dst_high, dst_high, TMP);
4679 __ MultuR2(lhs_low, rhs_low);
4680 __ Mfhi(TMP);
4681 __ Addu(dst_high, dst_high, TMP);
4682 __ Mflo(dst_low);
4683 }
4684 break;
4685 }
4686 case Primitive::kPrimFloat:
4687 case Primitive::kPrimDouble: {
4688 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
4689 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
4690 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
4691 if (type == Primitive::kPrimFloat) {
4692 __ MulS(dst, lhs, rhs);
4693 } else {
4694 __ MulD(dst, lhs, rhs);
4695 }
4696 break;
4697 }
4698 default:
4699 LOG(FATAL) << "Unexpected mul type " << type;
4700 }
4701}
4702
4703void LocationsBuilderMIPS::VisitNeg(HNeg* neg) {
4704 LocationSummary* locations =
4705 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
4706 switch (neg->GetResultType()) {
4707 case Primitive::kPrimInt:
4708 case Primitive::kPrimLong:
4709 locations->SetInAt(0, Location::RequiresRegister());
4710 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4711 break;
4712
4713 case Primitive::kPrimFloat:
4714 case Primitive::kPrimDouble:
4715 locations->SetInAt(0, Location::RequiresFpuRegister());
4716 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
4717 break;
4718
4719 default:
4720 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
4721 }
4722}
4723
4724void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) {
4725 Primitive::Type type = instruction->GetType();
4726 LocationSummary* locations = instruction->GetLocations();
4727
4728 switch (type) {
4729 case Primitive::kPrimInt: {
4730 Register dst = locations->Out().AsRegister<Register>();
4731 Register src = locations->InAt(0).AsRegister<Register>();
4732 __ Subu(dst, ZERO, src);
4733 break;
4734 }
4735 case Primitive::kPrimLong: {
4736 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
4737 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
4738 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4739 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
4740 __ Subu(dst_low, ZERO, src_low);
4741 __ Sltu(TMP, ZERO, dst_low);
4742 __ Subu(dst_high, ZERO, src_high);
4743 __ Subu(dst_high, dst_high, TMP);
4744 break;
4745 }
4746 case Primitive::kPrimFloat:
4747 case Primitive::kPrimDouble: {
4748 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
4749 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
4750 if (type == Primitive::kPrimFloat) {
4751 __ NegS(dst, src);
4752 } else {
4753 __ NegD(dst, src);
4754 }
4755 break;
4756 }
4757 default:
4758 LOG(FATAL) << "Unexpected neg type " << type;
4759 }
4760}
4761
4762void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) {
4763 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004764 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004765 InvokeRuntimeCallingConvention calling_convention;
4766 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4767 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
4768 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
4769 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
4770}
4771
4772void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) {
4773 InvokeRuntimeCallingConvention calling_convention;
4774 Register current_method_register = calling_convention.GetRegisterAt(2);
4775 __ Lw(current_method_register, SP, kCurrentMethodStackOffset);
4776 // Move an uint16_t value to a register.
4777 __ LoadConst32(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Serban Constantinescufca16662016-07-14 09:21:59 +01004778 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004779 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
4780 void*, uint32_t, int32_t, ArtMethod*>();
4781}
4782
4783void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) {
4784 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004785 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004786 InvokeRuntimeCallingConvention calling_convention;
David Brazdil6de19382016-01-08 17:37:10 +00004787 if (instruction->IsStringAlloc()) {
4788 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
4789 } else {
4790 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4791 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
4792 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004793 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
4794}
4795
4796void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) {
David Brazdil6de19382016-01-08 17:37:10 +00004797 if (instruction->IsStringAlloc()) {
4798 // String is allocated through StringFactory. Call NewEmptyString entry point.
4799 Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>();
Andreas Gampe542451c2016-07-26 09:02:02 -07004800 MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
David Brazdil6de19382016-01-08 17:37:10 +00004801 __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
4802 __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value());
4803 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004804 __ NopIfNoReordering();
David Brazdil6de19382016-01-08 17:37:10 +00004805 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
4806 } else {
Serban Constantinescufca16662016-07-14 09:21:59 +01004807 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
David Brazdil6de19382016-01-08 17:37:10 +00004808 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
4809 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004810}
4811
4812void LocationsBuilderMIPS::VisitNot(HNot* instruction) {
4813 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
4814 locations->SetInAt(0, Location::RequiresRegister());
4815 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4816}
4817
4818void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) {
4819 Primitive::Type type = instruction->GetType();
4820 LocationSummary* locations = instruction->GetLocations();
4821
4822 switch (type) {
4823 case Primitive::kPrimInt: {
4824 Register dst = locations->Out().AsRegister<Register>();
4825 Register src = locations->InAt(0).AsRegister<Register>();
4826 __ Nor(dst, src, ZERO);
4827 break;
4828 }
4829
4830 case Primitive::kPrimLong: {
4831 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
4832 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
4833 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4834 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
4835 __ Nor(dst_high, src_high, ZERO);
4836 __ Nor(dst_low, src_low, ZERO);
4837 break;
4838 }
4839
4840 default:
4841 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
4842 }
4843}
4844
4845void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) {
4846 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
4847 locations->SetInAt(0, Location::RequiresRegister());
4848 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4849}
4850
4851void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) {
4852 LocationSummary* locations = instruction->GetLocations();
4853 __ Xori(locations->Out().AsRegister<Register>(),
4854 locations->InAt(0).AsRegister<Register>(),
4855 1);
4856}
4857
4858void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) {
4859 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
4860 ? LocationSummary::kCallOnSlowPath
4861 : LocationSummary::kNoCall;
4862 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
4863 locations->SetInAt(0, Location::RequiresRegister());
4864 if (instruction->HasUses()) {
4865 locations->SetOut(Location::SameAsFirstInput());
4866 }
4867}
4868
Calin Juravle2ae48182016-03-16 14:05:09 +00004869void CodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) {
4870 if (CanMoveNullCheckToUser(instruction)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004871 return;
4872 }
4873 Location obj = instruction->GetLocations()->InAt(0);
4874
4875 __ Lw(ZERO, obj.AsRegister<Register>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00004876 RecordPcInfo(instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004877}
4878
Calin Juravle2ae48182016-03-16 14:05:09 +00004879void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004880 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00004881 AddSlowPath(slow_path);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004882
4883 Location obj = instruction->GetLocations()->InAt(0);
4884
4885 __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
4886}
4887
4888void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00004889 codegen_->GenerateNullCheck(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004890}
4891
4892void LocationsBuilderMIPS::VisitOr(HOr* instruction) {
4893 HandleBinaryOp(instruction);
4894}
4895
4896void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) {
4897 HandleBinaryOp(instruction);
4898}
4899
4900void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
4901 LOG(FATAL) << "Unreachable";
4902}
4903
4904void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) {
4905 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
4906}
4907
4908void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) {
4909 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
4910 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
4911 if (location.IsStackSlot()) {
4912 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
4913 } else if (location.IsDoubleStackSlot()) {
4914 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
4915 }
4916 locations->SetOut(location);
4917}
4918
4919void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction
4920 ATTRIBUTE_UNUSED) {
4921 // Nothing to do, the parameter is already at its location.
4922}
4923
4924void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) {
4925 LocationSummary* locations =
4926 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4927 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
4928}
4929
4930void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction
4931 ATTRIBUTE_UNUSED) {
4932 // Nothing to do, the method is already at its location.
4933}
4934
4935void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) {
4936 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Vladimir Marko372f10e2016-05-17 16:30:10 +01004937 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004938 locations->SetInAt(i, Location::Any());
4939 }
4940 locations->SetOut(Location::Any());
4941}
4942
4943void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
4944 LOG(FATAL) << "Unreachable";
4945}
4946
4947void LocationsBuilderMIPS::VisitRem(HRem* rem) {
4948 Primitive::Type type = rem->GetResultType();
4949 LocationSummary::CallKind call_kind =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004950 (type == Primitive::kPrimInt) ? LocationSummary::kNoCall : LocationSummary::kCallOnMainOnly;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004951 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
4952
4953 switch (type) {
4954 case Primitive::kPrimInt:
4955 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze7e99e052015-11-24 19:28:01 -08004956 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004957 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4958 break;
4959
4960 case Primitive::kPrimLong: {
4961 InvokeRuntimeCallingConvention calling_convention;
4962 locations->SetInAt(0, Location::RegisterPairLocation(
4963 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
4964 locations->SetInAt(1, Location::RegisterPairLocation(
4965 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
4966 locations->SetOut(calling_convention.GetReturnLocation(type));
4967 break;
4968 }
4969
4970 case Primitive::kPrimFloat:
4971 case Primitive::kPrimDouble: {
4972 InvokeRuntimeCallingConvention calling_convention;
4973 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
4974 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
4975 locations->SetOut(calling_convention.GetReturnLocation(type));
4976 break;
4977 }
4978
4979 default:
4980 LOG(FATAL) << "Unexpected rem type " << type;
4981 }
4982}
4983
4984void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) {
4985 Primitive::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004986
4987 switch (type) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08004988 case Primitive::kPrimInt:
4989 GenerateDivRemIntegral(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004990 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004991 case Primitive::kPrimLong: {
Serban Constantinescufca16662016-07-14 09:21:59 +01004992 codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004993 CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>();
4994 break;
4995 }
4996 case Primitive::kPrimFloat: {
Serban Constantinescufca16662016-07-14 09:21:59 +01004997 codegen_->InvokeRuntime(kQuickFmodf, instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00004998 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004999 break;
5000 }
5001 case Primitive::kPrimDouble: {
Serban Constantinescufca16662016-07-14 09:21:59 +01005002 codegen_->InvokeRuntime(kQuickFmod, instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00005003 CheckEntrypointTypes<kQuickFmod, double, double, double>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005004 break;
5005 }
5006 default:
5007 LOG(FATAL) << "Unexpected rem type " << type;
5008 }
5009}
5010
5011void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
5012 memory_barrier->SetLocations(nullptr);
5013}
5014
5015void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
5016 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
5017}
5018
5019void LocationsBuilderMIPS::VisitReturn(HReturn* ret) {
5020 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret);
5021 Primitive::Type return_type = ret->InputAt(0)->GetType();
5022 locations->SetInAt(0, MipsReturnLocation(return_type));
5023}
5024
5025void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
5026 codegen_->GenerateFrameExit();
5027}
5028
5029void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) {
5030 ret->SetLocations(nullptr);
5031}
5032
5033void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
5034 codegen_->GenerateFrameExit();
5035}
5036
Alexey Frunze92d90602015-12-18 18:16:36 -08005037void LocationsBuilderMIPS::VisitRor(HRor* ror) {
5038 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00005039}
5040
Alexey Frunze92d90602015-12-18 18:16:36 -08005041void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) {
5042 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00005043}
5044
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005045void LocationsBuilderMIPS::VisitShl(HShl* shl) {
5046 HandleShift(shl);
5047}
5048
5049void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) {
5050 HandleShift(shl);
5051}
5052
5053void LocationsBuilderMIPS::VisitShr(HShr* shr) {
5054 HandleShift(shr);
5055}
5056
5057void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) {
5058 HandleShift(shr);
5059}
5060
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005061void LocationsBuilderMIPS::VisitSub(HSub* instruction) {
5062 HandleBinaryOp(instruction);
5063}
5064
5065void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) {
5066 HandleBinaryOp(instruction);
5067}
5068
5069void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) {
5070 HandleFieldGet(instruction, instruction->GetFieldInfo());
5071}
5072
5073void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) {
5074 HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
5075}
5076
5077void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) {
5078 HandleFieldSet(instruction, instruction->GetFieldInfo());
5079}
5080
5081void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) {
5082 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
5083}
5084
5085void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet(
5086 HUnresolvedInstanceFieldGet* instruction) {
5087 FieldAccessCallingConventionMIPS calling_convention;
5088 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
5089 instruction->GetFieldType(),
5090 calling_convention);
5091}
5092
5093void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet(
5094 HUnresolvedInstanceFieldGet* instruction) {
5095 FieldAccessCallingConventionMIPS calling_convention;
5096 codegen_->GenerateUnresolvedFieldAccess(instruction,
5097 instruction->GetFieldType(),
5098 instruction->GetFieldIndex(),
5099 instruction->GetDexPc(),
5100 calling_convention);
5101}
5102
5103void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet(
5104 HUnresolvedInstanceFieldSet* instruction) {
5105 FieldAccessCallingConventionMIPS calling_convention;
5106 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
5107 instruction->GetFieldType(),
5108 calling_convention);
5109}
5110
5111void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet(
5112 HUnresolvedInstanceFieldSet* instruction) {
5113 FieldAccessCallingConventionMIPS calling_convention;
5114 codegen_->GenerateUnresolvedFieldAccess(instruction,
5115 instruction->GetFieldType(),
5116 instruction->GetFieldIndex(),
5117 instruction->GetDexPc(),
5118 calling_convention);
5119}
5120
5121void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet(
5122 HUnresolvedStaticFieldGet* instruction) {
5123 FieldAccessCallingConventionMIPS calling_convention;
5124 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
5125 instruction->GetFieldType(),
5126 calling_convention);
5127}
5128
5129void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet(
5130 HUnresolvedStaticFieldGet* instruction) {
5131 FieldAccessCallingConventionMIPS calling_convention;
5132 codegen_->GenerateUnresolvedFieldAccess(instruction,
5133 instruction->GetFieldType(),
5134 instruction->GetFieldIndex(),
5135 instruction->GetDexPc(),
5136 calling_convention);
5137}
5138
5139void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet(
5140 HUnresolvedStaticFieldSet* instruction) {
5141 FieldAccessCallingConventionMIPS calling_convention;
5142 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
5143 instruction->GetFieldType(),
5144 calling_convention);
5145}
5146
5147void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet(
5148 HUnresolvedStaticFieldSet* instruction) {
5149 FieldAccessCallingConventionMIPS calling_convention;
5150 codegen_->GenerateUnresolvedFieldAccess(instruction,
5151 instruction->GetFieldType(),
5152 instruction->GetFieldIndex(),
5153 instruction->GetDexPc(),
5154 calling_convention);
5155}
5156
5157void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) {
Vladimir Marko70e97462016-08-09 11:04:26 +01005158 LocationSummary* locations =
5159 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
5160 locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005161}
5162
5163void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) {
5164 HBasicBlock* block = instruction->GetBlock();
5165 if (block->GetLoopInformation() != nullptr) {
5166 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
5167 // The back edge will generate the suspend check.
5168 return;
5169 }
5170 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
5171 // The goto will generate the suspend check.
5172 return;
5173 }
5174 GenerateSuspendCheck(instruction, nullptr);
5175}
5176
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005177void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) {
5178 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01005179 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005180 InvokeRuntimeCallingConvention calling_convention;
5181 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
5182}
5183
5184void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) {
Serban Constantinescufca16662016-07-14 09:21:59 +01005185 codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005186 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
5187}
5188
5189void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) {
5190 Primitive::Type input_type = conversion->GetInputType();
5191 Primitive::Type result_type = conversion->GetResultType();
5192 DCHECK_NE(input_type, result_type);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005193 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005194
5195 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
5196 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
5197 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
5198 }
5199
5200 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005201 if (!isR6 &&
5202 ((Primitive::IsFloatingPointType(result_type) && input_type == Primitive::kPrimLong) ||
5203 (result_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(input_type)))) {
Serban Constantinescu54ff4822016-07-07 18:03:19 +01005204 call_kind = LocationSummary::kCallOnMainOnly;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005205 }
5206
5207 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
5208
5209 if (call_kind == LocationSummary::kNoCall) {
5210 if (Primitive::IsFloatingPointType(input_type)) {
5211 locations->SetInAt(0, Location::RequiresFpuRegister());
5212 } else {
5213 locations->SetInAt(0, Location::RequiresRegister());
5214 }
5215
5216 if (Primitive::IsFloatingPointType(result_type)) {
5217 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
5218 } else {
5219 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
5220 }
5221 } else {
5222 InvokeRuntimeCallingConvention calling_convention;
5223
5224 if (Primitive::IsFloatingPointType(input_type)) {
5225 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
5226 } else {
5227 DCHECK_EQ(input_type, Primitive::kPrimLong);
5228 locations->SetInAt(0, Location::RegisterPairLocation(
5229 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
5230 }
5231
5232 locations->SetOut(calling_convention.GetReturnLocation(result_type));
5233 }
5234}
5235
5236void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) {
5237 LocationSummary* locations = conversion->GetLocations();
5238 Primitive::Type result_type = conversion->GetResultType();
5239 Primitive::Type input_type = conversion->GetInputType();
5240 bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005241 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005242
5243 DCHECK_NE(input_type, result_type);
5244
5245 if (result_type == Primitive::kPrimLong && Primitive::IsIntegralType(input_type)) {
5246 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
5247 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
5248 Register src = locations->InAt(0).AsRegister<Register>();
5249
Alexey Frunzea871ef12016-06-27 15:20:11 -07005250 if (dst_low != src) {
5251 __ Move(dst_low, src);
5252 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005253 __ Sra(dst_high, src, 31);
5254 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
5255 Register dst = locations->Out().AsRegister<Register>();
5256 Register src = (input_type == Primitive::kPrimLong)
5257 ? locations->InAt(0).AsRegisterPairLow<Register>()
5258 : locations->InAt(0).AsRegister<Register>();
5259
5260 switch (result_type) {
5261 case Primitive::kPrimChar:
5262 __ Andi(dst, src, 0xFFFF);
5263 break;
5264 case Primitive::kPrimByte:
5265 if (has_sign_extension) {
5266 __ Seb(dst, src);
5267 } else {
5268 __ Sll(dst, src, 24);
5269 __ Sra(dst, dst, 24);
5270 }
5271 break;
5272 case Primitive::kPrimShort:
5273 if (has_sign_extension) {
5274 __ Seh(dst, src);
5275 } else {
5276 __ Sll(dst, src, 16);
5277 __ Sra(dst, dst, 16);
5278 }
5279 break;
5280 case Primitive::kPrimInt:
Alexey Frunzea871ef12016-06-27 15:20:11 -07005281 if (dst != src) {
5282 __ Move(dst, src);
5283 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005284 break;
5285
5286 default:
5287 LOG(FATAL) << "Unexpected type conversion from " << input_type
5288 << " to " << result_type;
5289 }
5290 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005291 if (input_type == Primitive::kPrimLong) {
5292 if (isR6) {
5293 // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary
5294 // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction.
5295 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
5296 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
5297 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
5298 __ Mtc1(src_low, FTMP);
5299 __ Mthc1(src_high, FTMP);
5300 if (result_type == Primitive::kPrimFloat) {
5301 __ Cvtsl(dst, FTMP);
5302 } else {
5303 __ Cvtdl(dst, FTMP);
5304 }
5305 } else {
Serban Constantinescufca16662016-07-14 09:21:59 +01005306 QuickEntrypointEnum entrypoint = (result_type == Primitive::kPrimFloat) ? kQuickL2f
5307 : kQuickL2d;
5308 codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc());
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005309 if (result_type == Primitive::kPrimFloat) {
5310 CheckEntrypointTypes<kQuickL2f, float, int64_t>();
5311 } else {
5312 CheckEntrypointTypes<kQuickL2d, double, int64_t>();
5313 }
5314 }
5315 } else {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005316 Register src = locations->InAt(0).AsRegister<Register>();
5317 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
5318 __ Mtc1(src, FTMP);
5319 if (result_type == Primitive::kPrimFloat) {
5320 __ Cvtsw(dst, FTMP);
5321 } else {
5322 __ Cvtdw(dst, FTMP);
5323 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005324 }
5325 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
5326 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005327 if (result_type == Primitive::kPrimLong) {
5328 if (isR6) {
5329 // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary
5330 // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction.
5331 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
5332 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
5333 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
5334 MipsLabel truncate;
5335 MipsLabel done;
5336
5337 // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive
5338 // value when the input is either a NaN or is outside of the range of the output type
5339 // after the truncation. IOW, the three special cases (NaN, too small, too big) produce
5340 // the same result.
5341 //
5342 // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum
5343 // value of the output type if the input is outside of the range after the truncation or
5344 // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct
5345 // results. This matches the desired float/double-to-int/long conversion exactly.
5346 //
5347 // So, NAN2008 affects handling of negative values and NaNs by the truncate instruction.
5348 //
5349 // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate
5350 // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6,
5351 // even though it must be NAN2008=1 on R6.
5352 //
5353 // The code takes care of the different behaviors by first comparing the input to the
5354 // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int).
5355 // If the input is greater than or equal to the minimum, it procedes to the truncate
5356 // instruction, which will handle such an input the same way irrespective of NAN2008.
5357 // Otherwise the input is compared to itself to determine whether it is a NaN or not
5358 // in order to return either zero or the minimum value.
5359 //
5360 // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the
5361 // truncate instruction for MIPS64R6.
5362 if (input_type == Primitive::kPrimFloat) {
5363 uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int64_t>::min());
5364 __ LoadConst32(TMP, min_val);
5365 __ Mtc1(TMP, FTMP);
5366 __ CmpLeS(FTMP, FTMP, src);
5367 } else {
5368 uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int64_t>::min());
5369 __ LoadConst32(TMP, High32Bits(min_val));
5370 __ Mtc1(ZERO, FTMP);
5371 __ Mthc1(TMP, FTMP);
5372 __ CmpLeD(FTMP, FTMP, src);
5373 }
5374
5375 __ Bc1nez(FTMP, &truncate);
5376
5377 if (input_type == Primitive::kPrimFloat) {
5378 __ CmpEqS(FTMP, src, src);
5379 } else {
5380 __ CmpEqD(FTMP, src, src);
5381 }
5382 __ Move(dst_low, ZERO);
5383 __ LoadConst32(dst_high, std::numeric_limits<int32_t>::min());
5384 __ Mfc1(TMP, FTMP);
5385 __ And(dst_high, dst_high, TMP);
5386
5387 __ B(&done);
5388
5389 __ Bind(&truncate);
5390
5391 if (input_type == Primitive::kPrimFloat) {
5392 __ TruncLS(FTMP, src);
5393 } else {
5394 __ TruncLD(FTMP, src);
5395 }
5396 __ Mfc1(dst_low, FTMP);
5397 __ Mfhc1(dst_high, FTMP);
5398
5399 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005400 } else {
Serban Constantinescufca16662016-07-14 09:21:59 +01005401 QuickEntrypointEnum entrypoint = (input_type == Primitive::kPrimFloat) ? kQuickF2l
5402 : kQuickD2l;
5403 codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc());
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005404 if (input_type == Primitive::kPrimFloat) {
5405 CheckEntrypointTypes<kQuickF2l, int64_t, float>();
5406 } else {
5407 CheckEntrypointTypes<kQuickD2l, int64_t, double>();
5408 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005409 }
5410 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005411 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
5412 Register dst = locations->Out().AsRegister<Register>();
5413 MipsLabel truncate;
5414 MipsLabel done;
5415
5416 // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate
5417 // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6,
5418 // even though it must be NAN2008=1 on R6.
5419 //
5420 // For details see the large comment above for the truncation of float/double to long on R6.
5421 //
5422 // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the
5423 // truncate instruction for MIPS64R6.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005424 if (input_type == Primitive::kPrimFloat) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005425 uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min());
5426 __ LoadConst32(TMP, min_val);
5427 __ Mtc1(TMP, FTMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005428 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005429 uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min());
5430 __ LoadConst32(TMP, High32Bits(min_val));
5431 __ Mtc1(ZERO, FTMP);
Alexey Frunzea871ef12016-06-27 15:20:11 -07005432 __ MoveToFpuHigh(TMP, FTMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005433 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005434
5435 if (isR6) {
5436 if (input_type == Primitive::kPrimFloat) {
5437 __ CmpLeS(FTMP, FTMP, src);
5438 } else {
5439 __ CmpLeD(FTMP, FTMP, src);
5440 }
5441 __ Bc1nez(FTMP, &truncate);
5442
5443 if (input_type == Primitive::kPrimFloat) {
5444 __ CmpEqS(FTMP, src, src);
5445 } else {
5446 __ CmpEqD(FTMP, src, src);
5447 }
5448 __ LoadConst32(dst, std::numeric_limits<int32_t>::min());
5449 __ Mfc1(TMP, FTMP);
5450 __ And(dst, dst, TMP);
5451 } else {
5452 if (input_type == Primitive::kPrimFloat) {
5453 __ ColeS(0, FTMP, src);
5454 } else {
5455 __ ColeD(0, FTMP, src);
5456 }
5457 __ Bc1t(0, &truncate);
5458
5459 if (input_type == Primitive::kPrimFloat) {
5460 __ CeqS(0, src, src);
5461 } else {
5462 __ CeqD(0, src, src);
5463 }
5464 __ LoadConst32(dst, std::numeric_limits<int32_t>::min());
5465 __ Movf(dst, ZERO, 0);
5466 }
5467
5468 __ B(&done);
5469
5470 __ Bind(&truncate);
5471
5472 if (input_type == Primitive::kPrimFloat) {
5473 __ TruncWS(FTMP, src);
5474 } else {
5475 __ TruncWD(FTMP, src);
5476 }
5477 __ Mfc1(dst, FTMP);
5478
5479 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005480 }
5481 } else if (Primitive::IsFloatingPointType(result_type) &&
5482 Primitive::IsFloatingPointType(input_type)) {
5483 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
5484 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
5485 if (result_type == Primitive::kPrimFloat) {
5486 __ Cvtsd(dst, src);
5487 } else {
5488 __ Cvtds(dst, src);
5489 }
5490 } else {
5491 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
5492 << " to " << result_type;
5493 }
5494}
5495
5496void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) {
5497 HandleShift(ushr);
5498}
5499
5500void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) {
5501 HandleShift(ushr);
5502}
5503
5504void LocationsBuilderMIPS::VisitXor(HXor* instruction) {
5505 HandleBinaryOp(instruction);
5506}
5507
5508void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) {
5509 HandleBinaryOp(instruction);
5510}
5511
5512void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
5513 // Nothing to do, this should be removed during prepare for register allocator.
5514 LOG(FATAL) << "Unreachable";
5515}
5516
5517void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
5518 // Nothing to do, this should be removed during prepare for register allocator.
5519 LOG(FATAL) << "Unreachable";
5520}
5521
5522void LocationsBuilderMIPS::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005523 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005524}
5525
5526void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005527 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005528}
5529
5530void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005531 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005532}
5533
5534void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005535 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005536}
5537
5538void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005539 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005540}
5541
5542void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005543 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005544}
5545
5546void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005547 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005548}
5549
5550void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005551 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005552}
5553
5554void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005555 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005556}
5557
5558void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005559 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005560}
5561
5562void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005563 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005564}
5565
5566void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005567 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005568}
5569
5570void LocationsBuilderMIPS::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005571 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005572}
5573
5574void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005575 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005576}
5577
5578void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005579 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005580}
5581
5582void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005583 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005584}
5585
5586void LocationsBuilderMIPS::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005587 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005588}
5589
5590void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005591 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005592}
5593
5594void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005595 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005596}
5597
5598void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005599 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005600}
5601
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005602void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
5603 LocationSummary* locations =
5604 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
5605 locations->SetInAt(0, Location::RequiresRegister());
5606}
5607
5608void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
5609 int32_t lower_bound = switch_instr->GetStartValue();
5610 int32_t num_entries = switch_instr->GetNumEntries();
5611 LocationSummary* locations = switch_instr->GetLocations();
5612 Register value_reg = locations->InAt(0).AsRegister<Register>();
5613 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
5614
5615 // Create a set of compare/jumps.
Vladimir Markof3e0ee22015-12-17 15:23:13 +00005616 Register temp_reg = TMP;
5617 __ Addiu32(temp_reg, value_reg, -lower_bound);
5618 // Jump to default if index is negative
5619 // Note: We don't check the case that index is positive while value < lower_bound, because in
5620 // this case, index >= num_entries must be true. So that we can save one branch instruction.
5621 __ Bltz(temp_reg, codegen_->GetLabelOf(default_block));
5622
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005623 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00005624 // Jump to successors[0] if value == lower_bound.
5625 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0]));
5626 int32_t last_index = 0;
5627 for (; num_entries - last_index > 2; last_index += 2) {
5628 __ Addiu(temp_reg, temp_reg, -2);
5629 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
5630 __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
5631 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
5632 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2]));
5633 }
5634 if (num_entries - last_index == 2) {
5635 // The last missing case_value.
5636 __ Addiu(temp_reg, temp_reg, -1);
5637 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005638 }
5639
Vladimir Markof3e0ee22015-12-17 15:23:13 +00005640 // And the default for any other value.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005641 if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) {
5642 __ B(codegen_->GetLabelOf(default_block));
5643 }
5644}
5645
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005646void LocationsBuilderMIPS::VisitMipsComputeBaseMethodAddress(
5647 HMipsComputeBaseMethodAddress* insn) {
5648 LocationSummary* locations =
5649 new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall);
5650 locations->SetOut(Location::RequiresRegister());
5651}
5652
5653void InstructionCodeGeneratorMIPS::VisitMipsComputeBaseMethodAddress(
5654 HMipsComputeBaseMethodAddress* insn) {
5655 LocationSummary* locations = insn->GetLocations();
5656 Register reg = locations->Out().AsRegister<Register>();
5657
5658 CHECK(!codegen_->GetInstructionSetFeatures().IsR6());
5659
5660 // Generate a dummy PC-relative call to obtain PC.
5661 __ Nal();
5662 // Grab the return address off RA.
5663 __ Move(reg, RA);
Alexey Frunze06a46c42016-07-19 15:00:40 -07005664 // TODO: Can we share this code with that of VisitMipsDexCacheArraysBase()?
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005665
5666 // Remember this offset (the obtained PC value) for later use with constant area.
5667 __ BindPcRelBaseLabel();
5668}
5669
5670void LocationsBuilderMIPS::VisitMipsDexCacheArraysBase(HMipsDexCacheArraysBase* base) {
5671 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base);
5672 locations->SetOut(Location::RequiresRegister());
5673}
5674
5675void InstructionCodeGeneratorMIPS::VisitMipsDexCacheArraysBase(HMipsDexCacheArraysBase* base) {
5676 Register reg = base->GetLocations()->Out().AsRegister<Register>();
5677 CodeGeneratorMIPS::PcRelativePatchInfo* info =
5678 codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07005679 bool reordering = __ SetReorder(false);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005680 if (codegen_->GetInstructionSetFeatures().IsR6()) {
5681 __ Bind(&info->high_label);
5682 __ Bind(&info->pc_rel_label);
5683 // Add a 32-bit offset to PC.
5684 __ Auipc(reg, /* placeholder */ 0x1234);
5685 __ Addiu(reg, reg, /* placeholder */ 0x5678);
5686 } else {
5687 // Generate a dummy PC-relative call to obtain PC.
5688 __ Nal();
5689 __ Bind(&info->high_label);
5690 __ Lui(reg, /* placeholder */ 0x1234);
5691 __ Bind(&info->pc_rel_label);
5692 __ Ori(reg, reg, /* placeholder */ 0x5678);
5693 // Add a 32-bit offset to PC.
5694 __ Addu(reg, reg, RA);
Alexey Frunze06a46c42016-07-19 15:00:40 -07005695 // TODO: Can we share this code with that of VisitMipsComputeBaseMethodAddress()?
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005696 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -07005697 __ SetReorder(reordering);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005698}
5699
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005700void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
5701 // The trampoline uses the same calling convention as dex calling conventions,
5702 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
5703 // the method_idx.
5704 HandleInvoke(invoke);
5705}
5706
5707void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
5708 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
5709}
5710
Roland Levillain2aba7cd2016-02-03 12:27:20 +00005711void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) {
5712 LocationSummary* locations =
5713 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
5714 locations->SetInAt(0, Location::RequiresRegister());
5715 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00005716}
5717
Roland Levillain2aba7cd2016-02-03 12:27:20 +00005718void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) {
5719 LocationSummary* locations = instruction->GetLocations();
Vladimir Markoa1de9182016-02-25 11:37:38 +00005720 if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01005721 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
Roland Levillain2aba7cd2016-02-03 12:27:20 +00005722 instruction->GetIndex(), kMipsPointerSize).SizeValue();
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01005723 __ LoadFromOffset(kLoadWord,
5724 locations->Out().AsRegister<Register>(),
5725 locations->InAt(0).AsRegister<Register>(),
5726 method_offset);
Roland Levillain2aba7cd2016-02-03 12:27:20 +00005727 } else {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01005728 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00005729 instruction->GetIndex(), kMipsPointerSize));
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00005730 __ LoadFromOffset(kLoadWord,
5731 locations->Out().AsRegister<Register>(),
5732 locations->InAt(0).AsRegister<Register>(),
5733 mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value());
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01005734 __ LoadFromOffset(kLoadWord,
5735 locations->Out().AsRegister<Register>(),
5736 locations->Out().AsRegister<Register>(),
5737 method_offset);
Roland Levillain2aba7cd2016-02-03 12:27:20 +00005738 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00005739}
5740
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005741#undef __
5742#undef QUICK_ENTRY_POINT
5743
5744} // namespace mips
5745} // namespace art