blob: 92e9cd90674ba917102d03ad6c29c0e3403528fb [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());
Serban Constantinescufca16662016-07-14 09:21:59 +0100421 mips_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000422 CheckEntrypointTypes<kQuickDeoptimize, void, void>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200423 }
424
425 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; }
426
427 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200428 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS);
429};
430
431CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph,
432 const MipsInstructionSetFeatures& isa_features,
433 const CompilerOptions& compiler_options,
434 OptimizingCompilerStats* stats)
435 : CodeGenerator(graph,
436 kNumberOfCoreRegisters,
437 kNumberOfFRegisters,
438 kNumberOfRegisterPairs,
439 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
440 arraysize(kCoreCalleeSaves)),
441 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
442 arraysize(kFpuCalleeSaves)),
443 compiler_options,
444 stats),
445 block_labels_(nullptr),
446 location_builder_(graph, this),
447 instruction_visitor_(graph, this),
448 move_resolver_(graph->GetArena(), this),
Vladimir Marko93205e32016-04-13 11:59:46 +0100449 assembler_(graph->GetArena(), &isa_features),
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700450 isa_features_(isa_features),
Alexey Frunze06a46c42016-07-19 15:00:40 -0700451 uint32_literals_(std::less<uint32_t>(),
452 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700453 method_patches_(MethodReferenceComparator(),
454 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
455 call_patches_(MethodReferenceComparator(),
456 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunze06a46c42016-07-19 15:00:40 -0700457 pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
458 boot_image_string_patches_(StringReferenceValueComparator(),
459 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
460 pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
461 boot_image_type_patches_(TypeReferenceValueComparator(),
462 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
463 pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
464 boot_image_address_patches_(std::less<uint32_t>(),
465 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
466 clobbered_ra_(false) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200467 // Save RA (containing the return address) to mimic Quick.
468 AddAllocatedRegister(Location::RegisterLocation(RA));
469}
470
471#undef __
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100472// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
473#define __ down_cast<MipsAssembler*>(GetAssembler())-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -0700474#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value()
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200475
476void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) {
477 // Ensure that we fix up branches.
478 __ FinalizeCode();
479
480 // Adjust native pc offsets in stack maps.
481 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
482 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
483 uint32_t new_position = __ GetAdjustedPosition(old_position);
484 DCHECK_GE(new_position, old_position);
485 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
486 }
487
488 // Adjust pc offsets for the disassembly information.
489 if (disasm_info_ != nullptr) {
490 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
491 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
492 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
493 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
494 it.second.start = __ GetAdjustedPosition(it.second.start);
495 it.second.end = __ GetAdjustedPosition(it.second.end);
496 }
497 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
498 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
499 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
500 }
501 }
502
503 CodeGenerator::Finalize(allocator);
504}
505
506MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const {
507 return codegen_->GetAssembler();
508}
509
510void ParallelMoveResolverMIPS::EmitMove(size_t index) {
511 DCHECK_LT(index, moves_.size());
512 MoveOperands* move = moves_[index];
513 codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType());
514}
515
516void ParallelMoveResolverMIPS::EmitSwap(size_t index) {
517 DCHECK_LT(index, moves_.size());
518 MoveOperands* move = moves_[index];
519 Primitive::Type type = move->GetType();
520 Location loc1 = move->GetDestination();
521 Location loc2 = move->GetSource();
522
523 DCHECK(!loc1.IsConstant());
524 DCHECK(!loc2.IsConstant());
525
526 if (loc1.Equals(loc2)) {
527 return;
528 }
529
530 if (loc1.IsRegister() && loc2.IsRegister()) {
531 // Swap 2 GPRs.
532 Register r1 = loc1.AsRegister<Register>();
533 Register r2 = loc2.AsRegister<Register>();
534 __ Move(TMP, r2);
535 __ Move(r2, r1);
536 __ Move(r1, TMP);
537 } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) {
538 FRegister f1 = loc1.AsFpuRegister<FRegister>();
539 FRegister f2 = loc2.AsFpuRegister<FRegister>();
540 if (type == Primitive::kPrimFloat) {
541 __ MovS(FTMP, f2);
542 __ MovS(f2, f1);
543 __ MovS(f1, FTMP);
544 } else {
545 DCHECK_EQ(type, Primitive::kPrimDouble);
546 __ MovD(FTMP, f2);
547 __ MovD(f2, f1);
548 __ MovD(f1, FTMP);
549 }
550 } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) ||
551 (loc1.IsFpuRegister() && loc2.IsRegister())) {
552 // Swap FPR and GPR.
553 DCHECK_EQ(type, Primitive::kPrimFloat); // Can only swap a float.
554 FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
555 : loc2.AsFpuRegister<FRegister>();
556 Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>()
557 : loc2.AsRegister<Register>();
558 __ Move(TMP, r2);
559 __ Mfc1(r2, f1);
560 __ Mtc1(TMP, f1);
561 } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) {
562 // Swap 2 GPR register pairs.
563 Register r1 = loc1.AsRegisterPairLow<Register>();
564 Register r2 = loc2.AsRegisterPairLow<Register>();
565 __ Move(TMP, r2);
566 __ Move(r2, r1);
567 __ Move(r1, TMP);
568 r1 = loc1.AsRegisterPairHigh<Register>();
569 r2 = loc2.AsRegisterPairHigh<Register>();
570 __ Move(TMP, r2);
571 __ Move(r2, r1);
572 __ Move(r1, TMP);
573 } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) ||
574 (loc1.IsFpuRegister() && loc2.IsRegisterPair())) {
575 // Swap FPR and GPR register pair.
576 DCHECK_EQ(type, Primitive::kPrimDouble);
577 FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
578 : loc2.AsFpuRegister<FRegister>();
579 Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>()
580 : loc2.AsRegisterPairLow<Register>();
581 Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>()
582 : loc2.AsRegisterPairHigh<Register>();
583 // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and
584 // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR
585 // unpredictable and the following mfch1 will fail.
586 __ Mfc1(TMP, f1);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800587 __ MoveFromFpuHigh(AT, f1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200588 __ Mtc1(r2_l, f1);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800589 __ MoveToFpuHigh(r2_h, f1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200590 __ Move(r2_l, TMP);
591 __ Move(r2_h, AT);
592 } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) {
593 Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false);
594 } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) {
595 Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true);
David Brazdilcc0f3112016-01-28 17:14:52 +0000596 } else if ((loc1.IsRegister() && loc2.IsStackSlot()) ||
597 (loc1.IsStackSlot() && loc2.IsRegister())) {
598 Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>()
599 : loc2.AsRegister<Register>();
600 intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex()
601 : loc2.GetStackIndex();
602 __ Move(TMP, reg);
603 __ LoadFromOffset(kLoadWord, reg, SP, offset);
604 __ StoreToOffset(kStoreWord, TMP, SP, offset);
605 } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) ||
606 (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) {
607 Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>()
608 : loc2.AsRegisterPairLow<Register>();
609 Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>()
610 : loc2.AsRegisterPairHigh<Register>();
611 intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex()
612 : loc2.GetStackIndex();
613 intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize)
614 : loc2.GetHighStackIndex(kMipsWordSize);
615 __ Move(TMP, reg_l);
David Brazdilcc0f3112016-01-28 17:14:52 +0000616 __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l);
David Brazdilcc0f3112016-01-28 17:14:52 +0000617 __ StoreToOffset(kStoreWord, TMP, SP, offset_l);
David Brazdil04d3e872016-01-29 09:50:09 +0000618 __ Move(TMP, reg_h);
619 __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h);
620 __ StoreToOffset(kStoreWord, TMP, SP, offset_h);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200621 } else {
622 LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported";
623 }
624}
625
626void ParallelMoveResolverMIPS::RestoreScratch(int reg) {
627 __ Pop(static_cast<Register>(reg));
628}
629
630void ParallelMoveResolverMIPS::SpillScratch(int reg) {
631 __ Push(static_cast<Register>(reg));
632}
633
634void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) {
635 // Allocate a scratch register other than TMP, if available.
636 // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be
637 // automatically unspilled when the scratch scope object is destroyed).
638 ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters());
639 // If V0 spills onto the stack, SP-relative offsets need to be adjusted.
640 int stack_offset = ensure_scratch.IsSpilled() ? kMipsWordSize : 0;
641 for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) {
642 __ LoadFromOffset(kLoadWord,
643 Register(ensure_scratch.GetRegister()),
644 SP,
645 index1 + stack_offset);
646 __ LoadFromOffset(kLoadWord,
647 TMP,
648 SP,
649 index2 + stack_offset);
650 __ StoreToOffset(kStoreWord,
651 Register(ensure_scratch.GetRegister()),
652 SP,
653 index2 + stack_offset);
654 __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset);
655 }
656}
657
Alexey Frunze73296a72016-06-03 22:51:46 -0700658void CodeGeneratorMIPS::ComputeSpillMask() {
659 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
660 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
661 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
662 // If there're FPU callee-saved registers and there's an odd number of GPR callee-saved
663 // registers, include the ZERO register to force alignment of FPU callee-saved registers
664 // within the stack frame.
665 if ((fpu_spill_mask_ != 0) && (POPCOUNT(core_spill_mask_) % 2 != 0)) {
666 core_spill_mask_ |= (1 << ZERO);
667 }
Alexey Frunze58320ce2016-08-30 21:40:46 -0700668}
669
670bool CodeGeneratorMIPS::HasAllocatedCalleeSaveRegisters() const {
Alexey Frunze06a46c42016-07-19 15:00:40 -0700671 // If RA is clobbered by PC-relative operations on R2 and it's the only spilled register
Alexey Frunze58320ce2016-08-30 21:40:46 -0700672 // (this can happen in leaf methods), force CodeGenerator::InitializeCodeGeneration()
673 // into the path that creates a stack frame so that RA can be explicitly saved and restored.
674 // RA can't otherwise be saved/restored when it's the only spilled register.
Alexey Frunze06a46c42016-07-19 15:00:40 -0700675 // TODO: Can this be improved? It causes creation of a stack frame (while RA might be
676 // saved in an unused temporary register) and saving of RA and the current method pointer
677 // in the frame.
Alexey Frunze58320ce2016-08-30 21:40:46 -0700678 return CodeGenerator::HasAllocatedCalleeSaveRegisters() || clobbered_ra_;
Alexey Frunze73296a72016-06-03 22:51:46 -0700679}
680
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200681static dwarf::Reg DWARFReg(Register reg) {
682 return dwarf::Reg::MipsCore(static_cast<int>(reg));
683}
684
685// TODO: mapping of floating-point registers to DWARF.
686
687void CodeGeneratorMIPS::GenerateFrameEntry() {
688 __ Bind(&frame_entry_label_);
689
690 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips) || !IsLeafMethod();
691
692 if (do_overflow_check) {
693 __ LoadFromOffset(kLoadWord,
694 ZERO,
695 SP,
696 -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips)));
697 RecordPcInfo(nullptr, 0);
698 }
699
700 if (HasEmptyFrame()) {
Alexey Frunze58320ce2016-08-30 21:40:46 -0700701 CHECK_EQ(fpu_spill_mask_, 0u);
702 CHECK_EQ(core_spill_mask_, 1u << RA);
703 CHECK(!clobbered_ra_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200704 return;
705 }
706
707 // Make sure the frame size isn't unreasonably large.
708 if (GetFrameSize() > GetStackOverflowReservedBytes(kMips)) {
709 LOG(FATAL) << "Stack frame larger than " << GetStackOverflowReservedBytes(kMips) << " bytes";
710 }
711
712 // Spill callee-saved registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200713
Alexey Frunze73296a72016-06-03 22:51:46 -0700714 uint32_t ofs = GetFrameSize();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200715 __ IncreaseFrameSize(ofs);
716
Alexey Frunze73296a72016-06-03 22:51:46 -0700717 for (uint32_t mask = core_spill_mask_; mask != 0; ) {
718 Register reg = static_cast<Register>(MostSignificantBit(mask));
719 mask ^= 1u << reg;
720 ofs -= kMipsWordSize;
721 // The ZERO register is only included for alignment.
722 if (reg != ZERO) {
723 __ StoreToOffset(kStoreWord, reg, SP, ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200724 __ cfi().RelOffset(DWARFReg(reg), ofs);
725 }
726 }
727
Alexey Frunze73296a72016-06-03 22:51:46 -0700728 for (uint32_t mask = fpu_spill_mask_; mask != 0; ) {
729 FRegister reg = static_cast<FRegister>(MostSignificantBit(mask));
730 mask ^= 1u << reg;
731 ofs -= kMipsDoublewordSize;
732 __ StoreDToOffset(reg, SP, ofs);
733 // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200734 }
735
Alexey Frunze73296a72016-06-03 22:51:46 -0700736 // Store the current method pointer.
Alexey Frunze58320ce2016-08-30 21:40:46 -0700737 // TODO: can we not do this if RequiresCurrentMethod() returns false?
Alexey Frunze73296a72016-06-03 22:51:46 -0700738 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, kCurrentMethodStackOffset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200739}
740
741void CodeGeneratorMIPS::GenerateFrameExit() {
742 __ cfi().RememberState();
743
744 if (!HasEmptyFrame()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200745 // Restore callee-saved registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200746
Alexey Frunze73296a72016-06-03 22:51:46 -0700747 // For better instruction scheduling restore RA before other registers.
748 uint32_t ofs = GetFrameSize();
749 for (uint32_t mask = core_spill_mask_; mask != 0; ) {
750 Register reg = static_cast<Register>(MostSignificantBit(mask));
751 mask ^= 1u << reg;
752 ofs -= kMipsWordSize;
753 // The ZERO register is only included for alignment.
754 if (reg != ZERO) {
755 __ LoadFromOffset(kLoadWord, reg, SP, ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200756 __ cfi().Restore(DWARFReg(reg));
757 }
758 }
759
Alexey Frunze73296a72016-06-03 22:51:46 -0700760 for (uint32_t mask = fpu_spill_mask_; mask != 0; ) {
761 FRegister reg = static_cast<FRegister>(MostSignificantBit(mask));
762 mask ^= 1u << reg;
763 ofs -= kMipsDoublewordSize;
764 __ LoadDFromOffset(reg, SP, ofs);
765 // TODO: __ cfi().Restore(DWARFReg(reg));
766 }
767
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700768 size_t frame_size = GetFrameSize();
769 // Adjust the stack pointer in the delay slot if doing so doesn't break CFI.
770 bool exchange = IsInt<16>(static_cast<int32_t>(frame_size));
771 bool reordering = __ SetReorder(false);
772 if (exchange) {
773 __ Jr(RA);
774 __ DecreaseFrameSize(frame_size); // Single instruction in delay slot.
775 } else {
776 __ DecreaseFrameSize(frame_size);
777 __ Jr(RA);
778 __ Nop(); // In delay slot.
779 }
780 __ SetReorder(reordering);
781 } else {
782 __ Jr(RA);
783 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200784 }
785
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200786 __ cfi().RestoreState();
787 __ cfi().DefCFAOffset(GetFrameSize());
788}
789
790void CodeGeneratorMIPS::Bind(HBasicBlock* block) {
791 __ Bind(GetLabelOf(block));
792}
793
794void CodeGeneratorMIPS::MoveLocation(Location dst, Location src, Primitive::Type dst_type) {
795 if (src.Equals(dst)) {
796 return;
797 }
798
799 if (src.IsConstant()) {
800 MoveConstant(dst, src.GetConstant());
801 } else {
802 if (Primitive::Is64BitType(dst_type)) {
803 Move64(dst, src);
804 } else {
805 Move32(dst, src);
806 }
807 }
808}
809
810void CodeGeneratorMIPS::Move32(Location destination, Location source) {
811 if (source.Equals(destination)) {
812 return;
813 }
814
815 if (destination.IsRegister()) {
816 if (source.IsRegister()) {
817 __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>());
818 } else if (source.IsFpuRegister()) {
819 __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>());
820 } else {
821 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
822 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
823 }
824 } else if (destination.IsFpuRegister()) {
825 if (source.IsRegister()) {
826 __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>());
827 } else if (source.IsFpuRegister()) {
828 __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>());
829 } else {
830 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
831 __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
832 }
833 } else {
834 DCHECK(destination.IsStackSlot()) << destination;
835 if (source.IsRegister()) {
836 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
837 } else if (source.IsFpuRegister()) {
838 __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex());
839 } else {
840 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
841 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
842 __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex());
843 }
844 }
845}
846
847void CodeGeneratorMIPS::Move64(Location destination, Location source) {
848 if (source.Equals(destination)) {
849 return;
850 }
851
852 if (destination.IsRegisterPair()) {
853 if (source.IsRegisterPair()) {
854 __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
855 __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
856 } else if (source.IsFpuRegister()) {
857 Register dst_high = destination.AsRegisterPairHigh<Register>();
858 Register dst_low = destination.AsRegisterPairLow<Register>();
859 FRegister src = source.AsFpuRegister<FRegister>();
860 __ Mfc1(dst_low, src);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800861 __ MoveFromFpuHigh(dst_high, src);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200862 } else {
863 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
864 int32_t off = source.GetStackIndex();
865 Register r = destination.AsRegisterPairLow<Register>();
866 __ LoadFromOffset(kLoadDoubleword, r, SP, off);
867 }
868 } else if (destination.IsFpuRegister()) {
869 if (source.IsRegisterPair()) {
870 FRegister dst = destination.AsFpuRegister<FRegister>();
871 Register src_high = source.AsRegisterPairHigh<Register>();
872 Register src_low = source.AsRegisterPairLow<Register>();
873 __ Mtc1(src_low, dst);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800874 __ MoveToFpuHigh(src_high, dst);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200875 } else if (source.IsFpuRegister()) {
876 __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>());
877 } else {
878 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
879 __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
880 }
881 } else {
882 DCHECK(destination.IsDoubleStackSlot()) << destination;
883 int32_t off = destination.GetStackIndex();
884 if (source.IsRegisterPair()) {
885 __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, off);
886 } else if (source.IsFpuRegister()) {
887 __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, off);
888 } else {
889 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
890 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
891 __ StoreToOffset(kStoreWord, TMP, SP, off);
892 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4);
893 __ StoreToOffset(kStoreWord, TMP, SP, off + 4);
894 }
895 }
896}
897
898void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) {
899 if (c->IsIntConstant() || c->IsNullConstant()) {
900 // Move 32 bit constant.
901 int32_t value = GetInt32ValueOf(c);
902 if (destination.IsRegister()) {
903 Register dst = destination.AsRegister<Register>();
904 __ LoadConst32(dst, value);
905 } else {
906 DCHECK(destination.IsStackSlot())
907 << "Cannot move " << c->DebugName() << " to " << destination;
908 __ StoreConst32ToOffset(value, SP, destination.GetStackIndex(), TMP);
909 }
910 } else if (c->IsLongConstant()) {
911 // Move 64 bit constant.
912 int64_t value = GetInt64ValueOf(c);
913 if (destination.IsRegisterPair()) {
914 Register r_h = destination.AsRegisterPairHigh<Register>();
915 Register r_l = destination.AsRegisterPairLow<Register>();
916 __ LoadConst64(r_h, r_l, value);
917 } else {
918 DCHECK(destination.IsDoubleStackSlot())
919 << "Cannot move " << c->DebugName() << " to " << destination;
920 __ StoreConst64ToOffset(value, SP, destination.GetStackIndex(), TMP);
921 }
922 } else if (c->IsFloatConstant()) {
923 // Move 32 bit float constant.
924 int32_t value = GetInt32ValueOf(c);
925 if (destination.IsFpuRegister()) {
926 __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP);
927 } else {
928 DCHECK(destination.IsStackSlot())
929 << "Cannot move " << c->DebugName() << " to " << destination;
930 __ StoreConst32ToOffset(value, SP, destination.GetStackIndex(), TMP);
931 }
932 } else {
933 // Move 64 bit double constant.
934 DCHECK(c->IsDoubleConstant()) << c->DebugName();
935 int64_t value = GetInt64ValueOf(c);
936 if (destination.IsFpuRegister()) {
937 FRegister fd = destination.AsFpuRegister<FRegister>();
938 __ LoadDConst64(fd, value, TMP);
939 } else {
940 DCHECK(destination.IsDoubleStackSlot())
941 << "Cannot move " << c->DebugName() << " to " << destination;
942 __ StoreConst64ToOffset(value, SP, destination.GetStackIndex(), TMP);
943 }
944 }
945}
946
947void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) {
948 DCHECK(destination.IsRegister());
949 Register dst = destination.AsRegister<Register>();
950 __ LoadConst32(dst, value);
951}
952
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200953void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) {
954 if (location.IsRegister()) {
955 locations->AddTemp(location);
Alexey Frunzec9e94f32015-10-26 16:11:39 -0700956 } else if (location.IsRegisterPair()) {
957 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>()));
958 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>()));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200959 } else {
960 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
961 }
962}
963
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700964void CodeGeneratorMIPS::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) {
965 DCHECK(linker_patches->empty());
966 size_t size =
967 method_patches_.size() +
968 call_patches_.size() +
Alexey Frunze06a46c42016-07-19 15:00:40 -0700969 pc_relative_dex_cache_patches_.size() +
970 pc_relative_string_patches_.size() +
971 pc_relative_type_patches_.size() +
972 boot_image_string_patches_.size() +
973 boot_image_type_patches_.size() +
974 boot_image_address_patches_.size();
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700975 linker_patches->reserve(size);
976 for (const auto& entry : method_patches_) {
977 const MethodReference& target_method = entry.first;
978 Literal* literal = entry.second;
979 DCHECK(literal->GetLabel()->IsBound());
980 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
981 linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset,
982 target_method.dex_file,
983 target_method.dex_method_index));
984 }
985 for (const auto& entry : call_patches_) {
986 const MethodReference& target_method = entry.first;
987 Literal* literal = entry.second;
988 DCHECK(literal->GetLabel()->IsBound());
989 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
990 linker_patches->push_back(LinkerPatch::CodePatch(literal_offset,
991 target_method.dex_file,
992 target_method.dex_method_index));
993 }
994 for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) {
995 const DexFile& dex_file = info.target_dex_file;
996 size_t base_element_offset = info.offset_or_index;
997 DCHECK(info.high_label.IsBound());
998 uint32_t high_offset = __ GetLabelLocation(&info.high_label);
999 DCHECK(info.pc_rel_label.IsBound());
1000 uint32_t pc_rel_offset = __ GetLabelLocation(&info.pc_rel_label);
1001 linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(high_offset,
1002 &dex_file,
1003 pc_rel_offset,
1004 base_element_offset));
1005 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07001006 for (const PcRelativePatchInfo& info : pc_relative_string_patches_) {
1007 const DexFile& dex_file = info.target_dex_file;
1008 size_t string_index = info.offset_or_index;
1009 DCHECK(info.high_label.IsBound());
1010 uint32_t high_offset = __ GetLabelLocation(&info.high_label);
1011 // On R2 we use HMipsComputeBaseMethodAddress and patch relative to
1012 // the assembler's base label used for PC-relative literals.
1013 uint32_t pc_rel_offset = info.pc_rel_label.IsBound()
1014 ? __ GetLabelLocation(&info.pc_rel_label)
1015 : __ GetPcRelBaseLabelLocation();
1016 linker_patches->push_back(LinkerPatch::RelativeStringPatch(high_offset,
1017 &dex_file,
1018 pc_rel_offset,
1019 string_index));
1020 }
1021 for (const PcRelativePatchInfo& info : pc_relative_type_patches_) {
1022 const DexFile& dex_file = info.target_dex_file;
1023 size_t type_index = info.offset_or_index;
1024 DCHECK(info.high_label.IsBound());
1025 uint32_t high_offset = __ GetLabelLocation(&info.high_label);
1026 // On R2 we use HMipsComputeBaseMethodAddress and patch relative to
1027 // the assembler's base label used for PC-relative literals.
1028 uint32_t pc_rel_offset = info.pc_rel_label.IsBound()
1029 ? __ GetLabelLocation(&info.pc_rel_label)
1030 : __ GetPcRelBaseLabelLocation();
1031 linker_patches->push_back(LinkerPatch::RelativeTypePatch(high_offset,
1032 &dex_file,
1033 pc_rel_offset,
1034 type_index));
1035 }
1036 for (const auto& entry : boot_image_string_patches_) {
1037 const StringReference& target_string = entry.first;
1038 Literal* literal = entry.second;
1039 DCHECK(literal->GetLabel()->IsBound());
1040 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1041 linker_patches->push_back(LinkerPatch::StringPatch(literal_offset,
1042 target_string.dex_file,
1043 target_string.string_index));
1044 }
1045 for (const auto& entry : boot_image_type_patches_) {
1046 const TypeReference& target_type = entry.first;
1047 Literal* literal = entry.second;
1048 DCHECK(literal->GetLabel()->IsBound());
1049 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1050 linker_patches->push_back(LinkerPatch::TypePatch(literal_offset,
1051 target_type.dex_file,
1052 target_type.type_index));
1053 }
1054 for (const auto& entry : boot_image_address_patches_) {
1055 DCHECK(GetCompilerOptions().GetIncludePatchInformation());
1056 Literal* literal = entry.second;
1057 DCHECK(literal->GetLabel()->IsBound());
1058 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1059 linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset));
1060 }
1061}
1062
1063CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeStringPatch(
1064 const DexFile& dex_file, uint32_t string_index) {
1065 return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_);
1066}
1067
1068CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeTypePatch(
1069 const DexFile& dex_file, uint32_t type_index) {
1070 return NewPcRelativePatch(dex_file, type_index, &pc_relative_type_patches_);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001071}
1072
1073CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeDexCacheArrayPatch(
1074 const DexFile& dex_file, uint32_t element_offset) {
1075 return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_);
1076}
1077
1078CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativePatch(
1079 const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) {
1080 patches->emplace_back(dex_file, offset_or_index);
1081 return &patches->back();
1082}
1083
Alexey Frunze06a46c42016-07-19 15:00:40 -07001084Literal* CodeGeneratorMIPS::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) {
1085 return map->GetOrCreate(
1086 value,
1087 [this, value]() { return __ NewLiteral<uint32_t>(value); });
1088}
1089
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001090Literal* CodeGeneratorMIPS::DeduplicateMethodLiteral(MethodReference target_method,
1091 MethodToLiteralMap* map) {
1092 return map->GetOrCreate(
1093 target_method,
1094 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1095}
1096
1097Literal* CodeGeneratorMIPS::DeduplicateMethodAddressLiteral(MethodReference target_method) {
1098 return DeduplicateMethodLiteral(target_method, &method_patches_);
1099}
1100
1101Literal* CodeGeneratorMIPS::DeduplicateMethodCodeLiteral(MethodReference target_method) {
1102 return DeduplicateMethodLiteral(target_method, &call_patches_);
1103}
1104
Alexey Frunze06a46c42016-07-19 15:00:40 -07001105Literal* CodeGeneratorMIPS::DeduplicateBootImageStringLiteral(const DexFile& dex_file,
1106 uint32_t string_index) {
1107 return boot_image_string_patches_.GetOrCreate(
1108 StringReference(&dex_file, string_index),
1109 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1110}
1111
1112Literal* CodeGeneratorMIPS::DeduplicateBootImageTypeLiteral(const DexFile& dex_file,
1113 uint32_t type_index) {
1114 return boot_image_type_patches_.GetOrCreate(
1115 TypeReference(&dex_file, type_index),
1116 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1117}
1118
1119Literal* CodeGeneratorMIPS::DeduplicateBootImageAddressLiteral(uint32_t address) {
1120 bool needs_patch = GetCompilerOptions().GetIncludePatchInformation();
1121 Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_;
1122 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map);
1123}
1124
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001125void CodeGeneratorMIPS::MarkGCCard(Register object, Register value) {
1126 MipsLabel done;
1127 Register card = AT;
1128 Register temp = TMP;
1129 __ Beqz(value, &done);
1130 __ LoadFromOffset(kLoadWord,
1131 card,
1132 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001133 Thread::CardTableOffset<kMipsPointerSize>().Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001134 __ Srl(temp, object, gc::accounting::CardTable::kCardShift);
1135 __ Addu(temp, card, temp);
1136 __ Sb(card, temp, 0);
1137 __ Bind(&done);
1138}
1139
David Brazdil58282f42016-01-14 12:45:10 +00001140void CodeGeneratorMIPS::SetupBlockedRegisters() const {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001141 // Don't allocate the dalvik style register pair passing.
1142 blocked_register_pairs_[A1_A2] = true;
1143
1144 // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated.
1145 blocked_core_registers_[ZERO] = true;
1146 blocked_core_registers_[K0] = true;
1147 blocked_core_registers_[K1] = true;
1148 blocked_core_registers_[GP] = true;
1149 blocked_core_registers_[SP] = true;
1150 blocked_core_registers_[RA] = true;
1151
1152 // AT and TMP(T8) are used as temporary/scratch registers
1153 // (similar to how AT is used by MIPS assemblers).
1154 blocked_core_registers_[AT] = true;
1155 blocked_core_registers_[TMP] = true;
1156 blocked_fpu_registers_[FTMP] = true;
1157
1158 // Reserve suspend and thread registers.
1159 blocked_core_registers_[S0] = true;
1160 blocked_core_registers_[TR] = true;
1161
1162 // Reserve T9 for function calls
1163 blocked_core_registers_[T9] = true;
1164
1165 // Reserve odd-numbered FPU registers.
1166 for (size_t i = 1; i < kNumberOfFRegisters; i += 2) {
1167 blocked_fpu_registers_[i] = true;
1168 }
1169
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02001170 if (GetGraph()->IsDebuggable()) {
1171 // Stubs do not save callee-save floating point registers. If the graph
1172 // is debuggable, we need to deal with these registers differently. For
1173 // now, just block them.
1174 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
1175 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
1176 }
1177 }
1178
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001179 UpdateBlockedPairRegisters();
1180}
1181
1182void CodeGeneratorMIPS::UpdateBlockedPairRegisters() const {
1183 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
1184 MipsManagedRegister current =
1185 MipsManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
1186 if (blocked_core_registers_[current.AsRegisterPairLow()]
1187 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
1188 blocked_register_pairs_[i] = true;
1189 }
1190 }
1191}
1192
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001193size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
1194 __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index);
1195 return kMipsWordSize;
1196}
1197
1198size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
1199 __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index);
1200 return kMipsWordSize;
1201}
1202
1203size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1204 __ StoreDToOffset(FRegister(reg_id), SP, stack_index);
1205 return kMipsDoublewordSize;
1206}
1207
1208size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1209 __ LoadDFromOffset(FRegister(reg_id), SP, stack_index);
1210 return kMipsDoublewordSize;
1211}
1212
1213void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const {
Vladimir Marko623a7a22016-02-02 18:14:52 +00001214 stream << Register(reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001215}
1216
1217void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Vladimir Marko623a7a22016-02-02 18:14:52 +00001218 stream << FRegister(reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001219}
1220
Serban Constantinescufca16662016-07-14 09:21:59 +01001221constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16;
1222
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001223void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint,
1224 HInstruction* instruction,
1225 uint32_t dex_pc,
1226 SlowPathCode* slow_path) {
Serban Constantinescufca16662016-07-14 09:21:59 +01001227 ValidateInvokeRuntime(instruction, slow_path);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001228 bool reordering = __ SetReorder(false);
Serban Constantinescufca16662016-07-14 09:21:59 +01001229 __ LoadFromOffset(kLoadWord, T9, TR, GetThreadOffset<kMipsPointerSize>(entrypoint).Int32Value());
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001230 __ Jalr(T9);
Serban Constantinescufca16662016-07-14 09:21:59 +01001231 if (IsDirectEntrypoint(entrypoint)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001232 // Reserve argument space on stack (for $a0-$a3) for
1233 // entrypoints that directly reference native implementations.
1234 // Called function may use this space to store $a0-$a3 regs.
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001235 __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001236 __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001237 } else {
1238 __ Nop(); // In delay slot.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001239 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001240 __ SetReorder(reordering);
Serban Constantinescufca16662016-07-14 09:21:59 +01001241 if (EntrypointRequiresStackMap(entrypoint)) {
1242 RecordPcInfo(instruction, dex_pc, slow_path);
1243 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001244}
1245
1246void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path,
1247 Register class_reg) {
1248 __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value());
1249 __ LoadConst32(AT, mirror::Class::kStatusInitialized);
1250 __ Blt(TMP, AT, slow_path->GetEntryLabel());
1251 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
1252 __ Sync(0);
1253 __ Bind(slow_path->GetExitLabel());
1254}
1255
1256void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) {
1257 __ Sync(0); // Only stype 0 is supported.
1258}
1259
1260void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction,
1261 HBasicBlock* successor) {
1262 SuspendCheckSlowPathMIPS* slow_path =
1263 new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS(instruction, successor);
1264 codegen_->AddSlowPath(slow_path);
1265
1266 __ LoadFromOffset(kLoadUnsignedHalfword,
1267 TMP,
1268 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001269 Thread::ThreadFlagsOffset<kMipsPointerSize>().Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001270 if (successor == nullptr) {
1271 __ Bnez(TMP, slow_path->GetEntryLabel());
1272 __ Bind(slow_path->GetReturnLabel());
1273 } else {
1274 __ Beqz(TMP, codegen_->GetLabelOf(successor));
1275 __ B(slow_path->GetEntryLabel());
1276 // slow_path will return to GetLabelOf(successor).
1277 }
1278}
1279
1280InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph,
1281 CodeGeneratorMIPS* codegen)
Aart Bik42249c32016-01-07 15:33:50 -08001282 : InstructionCodeGenerator(graph, codegen),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001283 assembler_(codegen->GetAssembler()),
1284 codegen_(codegen) {}
1285
1286void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) {
1287 DCHECK_EQ(instruction->InputCount(), 2U);
1288 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1289 Primitive::Type type = instruction->GetResultType();
1290 switch (type) {
1291 case Primitive::kPrimInt: {
1292 locations->SetInAt(0, Location::RequiresRegister());
1293 HInstruction* right = instruction->InputAt(1);
1294 bool can_use_imm = false;
1295 if (right->IsConstant()) {
1296 int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant());
1297 if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) {
1298 can_use_imm = IsUint<16>(imm);
1299 } else if (instruction->IsAdd()) {
1300 can_use_imm = IsInt<16>(imm);
1301 } else {
1302 DCHECK(instruction->IsSub());
1303 can_use_imm = IsInt<16>(-imm);
1304 }
1305 }
1306 if (can_use_imm)
1307 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1308 else
1309 locations->SetInAt(1, Location::RequiresRegister());
1310 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1311 break;
1312 }
1313
1314 case Primitive::kPrimLong: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001315 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001316 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1317 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001318 break;
1319 }
1320
1321 case Primitive::kPrimFloat:
1322 case Primitive::kPrimDouble:
1323 DCHECK(instruction->IsAdd() || instruction->IsSub());
1324 locations->SetInAt(0, Location::RequiresFpuRegister());
1325 locations->SetInAt(1, Location::RequiresFpuRegister());
1326 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1327 break;
1328
1329 default:
1330 LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type;
1331 }
1332}
1333
1334void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) {
1335 Primitive::Type type = instruction->GetType();
1336 LocationSummary* locations = instruction->GetLocations();
1337
1338 switch (type) {
1339 case Primitive::kPrimInt: {
1340 Register dst = locations->Out().AsRegister<Register>();
1341 Register lhs = locations->InAt(0).AsRegister<Register>();
1342 Location rhs_location = locations->InAt(1);
1343
1344 Register rhs_reg = ZERO;
1345 int32_t rhs_imm = 0;
1346 bool use_imm = rhs_location.IsConstant();
1347 if (use_imm) {
1348 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
1349 } else {
1350 rhs_reg = rhs_location.AsRegister<Register>();
1351 }
1352
1353 if (instruction->IsAnd()) {
1354 if (use_imm)
1355 __ Andi(dst, lhs, rhs_imm);
1356 else
1357 __ And(dst, lhs, rhs_reg);
1358 } else if (instruction->IsOr()) {
1359 if (use_imm)
1360 __ Ori(dst, lhs, rhs_imm);
1361 else
1362 __ Or(dst, lhs, rhs_reg);
1363 } else if (instruction->IsXor()) {
1364 if (use_imm)
1365 __ Xori(dst, lhs, rhs_imm);
1366 else
1367 __ Xor(dst, lhs, rhs_reg);
1368 } else if (instruction->IsAdd()) {
1369 if (use_imm)
1370 __ Addiu(dst, lhs, rhs_imm);
1371 else
1372 __ Addu(dst, lhs, rhs_reg);
1373 } else {
1374 DCHECK(instruction->IsSub());
1375 if (use_imm)
1376 __ Addiu(dst, lhs, -rhs_imm);
1377 else
1378 __ Subu(dst, lhs, rhs_reg);
1379 }
1380 break;
1381 }
1382
1383 case Primitive::kPrimLong: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001384 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
1385 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
1386 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
1387 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001388 Location rhs_location = locations->InAt(1);
1389 bool use_imm = rhs_location.IsConstant();
1390 if (!use_imm) {
1391 Register rhs_high = rhs_location.AsRegisterPairHigh<Register>();
1392 Register rhs_low = rhs_location.AsRegisterPairLow<Register>();
1393 if (instruction->IsAnd()) {
1394 __ And(dst_low, lhs_low, rhs_low);
1395 __ And(dst_high, lhs_high, rhs_high);
1396 } else if (instruction->IsOr()) {
1397 __ Or(dst_low, lhs_low, rhs_low);
1398 __ Or(dst_high, lhs_high, rhs_high);
1399 } else if (instruction->IsXor()) {
1400 __ Xor(dst_low, lhs_low, rhs_low);
1401 __ Xor(dst_high, lhs_high, rhs_high);
1402 } else if (instruction->IsAdd()) {
1403 if (lhs_low == rhs_low) {
1404 // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs.
1405 __ Slt(TMP, lhs_low, ZERO);
1406 __ Addu(dst_low, lhs_low, rhs_low);
1407 } else {
1408 __ Addu(dst_low, lhs_low, rhs_low);
1409 // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged.
1410 __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low);
1411 }
1412 __ Addu(dst_high, lhs_high, rhs_high);
1413 __ Addu(dst_high, dst_high, TMP);
1414 } else {
1415 DCHECK(instruction->IsSub());
1416 __ Sltu(TMP, lhs_low, rhs_low);
1417 __ Subu(dst_low, lhs_low, rhs_low);
1418 __ Subu(dst_high, lhs_high, rhs_high);
1419 __ Subu(dst_high, dst_high, TMP);
1420 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001421 } else {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001422 int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant());
1423 if (instruction->IsOr()) {
1424 uint32_t low = Low32Bits(value);
1425 uint32_t high = High32Bits(value);
1426 if (IsUint<16>(low)) {
1427 if (dst_low != lhs_low || low != 0) {
1428 __ Ori(dst_low, lhs_low, low);
1429 }
1430 } else {
1431 __ LoadConst32(TMP, low);
1432 __ Or(dst_low, lhs_low, TMP);
1433 }
1434 if (IsUint<16>(high)) {
1435 if (dst_high != lhs_high || high != 0) {
1436 __ Ori(dst_high, lhs_high, high);
1437 }
1438 } else {
1439 if (high != low) {
1440 __ LoadConst32(TMP, high);
1441 }
1442 __ Or(dst_high, lhs_high, TMP);
1443 }
1444 } else if (instruction->IsXor()) {
1445 uint32_t low = Low32Bits(value);
1446 uint32_t high = High32Bits(value);
1447 if (IsUint<16>(low)) {
1448 if (dst_low != lhs_low || low != 0) {
1449 __ Xori(dst_low, lhs_low, low);
1450 }
1451 } else {
1452 __ LoadConst32(TMP, low);
1453 __ Xor(dst_low, lhs_low, TMP);
1454 }
1455 if (IsUint<16>(high)) {
1456 if (dst_high != lhs_high || high != 0) {
1457 __ Xori(dst_high, lhs_high, high);
1458 }
1459 } else {
1460 if (high != low) {
1461 __ LoadConst32(TMP, high);
1462 }
1463 __ Xor(dst_high, lhs_high, TMP);
1464 }
1465 } else if (instruction->IsAnd()) {
1466 uint32_t low = Low32Bits(value);
1467 uint32_t high = High32Bits(value);
1468 if (IsUint<16>(low)) {
1469 __ Andi(dst_low, lhs_low, low);
1470 } else if (low != 0xFFFFFFFF) {
1471 __ LoadConst32(TMP, low);
1472 __ And(dst_low, lhs_low, TMP);
1473 } else if (dst_low != lhs_low) {
1474 __ Move(dst_low, lhs_low);
1475 }
1476 if (IsUint<16>(high)) {
1477 __ Andi(dst_high, lhs_high, high);
1478 } else if (high != 0xFFFFFFFF) {
1479 if (high != low) {
1480 __ LoadConst32(TMP, high);
1481 }
1482 __ And(dst_high, lhs_high, TMP);
1483 } else if (dst_high != lhs_high) {
1484 __ Move(dst_high, lhs_high);
1485 }
1486 } else {
1487 if (instruction->IsSub()) {
1488 value = -value;
1489 } else {
1490 DCHECK(instruction->IsAdd());
1491 }
1492 int32_t low = Low32Bits(value);
1493 int32_t high = High32Bits(value);
1494 if (IsInt<16>(low)) {
1495 if (dst_low != lhs_low || low != 0) {
1496 __ Addiu(dst_low, lhs_low, low);
1497 }
1498 if (low != 0) {
1499 __ Sltiu(AT, dst_low, low);
1500 }
1501 } else {
1502 __ LoadConst32(TMP, low);
1503 __ Addu(dst_low, lhs_low, TMP);
1504 __ Sltu(AT, dst_low, TMP);
1505 }
1506 if (IsInt<16>(high)) {
1507 if (dst_high != lhs_high || high != 0) {
1508 __ Addiu(dst_high, lhs_high, high);
1509 }
1510 } else {
1511 if (high != low) {
1512 __ LoadConst32(TMP, high);
1513 }
1514 __ Addu(dst_high, lhs_high, TMP);
1515 }
1516 if (low != 0) {
1517 __ Addu(dst_high, dst_high, AT);
1518 }
1519 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001520 }
1521 break;
1522 }
1523
1524 case Primitive::kPrimFloat:
1525 case Primitive::kPrimDouble: {
1526 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
1527 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
1528 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
1529 if (instruction->IsAdd()) {
1530 if (type == Primitive::kPrimFloat) {
1531 __ AddS(dst, lhs, rhs);
1532 } else {
1533 __ AddD(dst, lhs, rhs);
1534 }
1535 } else {
1536 DCHECK(instruction->IsSub());
1537 if (type == Primitive::kPrimFloat) {
1538 __ SubS(dst, lhs, rhs);
1539 } else {
1540 __ SubD(dst, lhs, rhs);
1541 }
1542 }
1543 break;
1544 }
1545
1546 default:
1547 LOG(FATAL) << "Unexpected binary operation type " << type;
1548 }
1549}
1550
1551void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001552 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001553
1554 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1555 Primitive::Type type = instr->GetResultType();
1556 switch (type) {
1557 case Primitive::kPrimInt:
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001558 locations->SetInAt(0, Location::RequiresRegister());
1559 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1560 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1561 break;
1562 case Primitive::kPrimLong:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001563 locations->SetInAt(0, Location::RequiresRegister());
1564 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1565 locations->SetOut(Location::RequiresRegister());
1566 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001567 default:
1568 LOG(FATAL) << "Unexpected shift type " << type;
1569 }
1570}
1571
1572static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte;
1573
1574void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001575 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001576 LocationSummary* locations = instr->GetLocations();
1577 Primitive::Type type = instr->GetType();
1578
1579 Location rhs_location = locations->InAt(1);
1580 bool use_imm = rhs_location.IsConstant();
1581 Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>();
1582 int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0;
Roland Levillain5b5b9312016-03-22 14:57:31 +00001583 const uint32_t shift_mask =
1584 (type == Primitive::kPrimInt) ? kMaxIntShiftDistance : kMaxLongShiftDistance;
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001585 const uint32_t shift_value = rhs_imm & shift_mask;
Alexey Frunze92d90602015-12-18 18:16:36 -08001586 // Are the INS (Insert Bit Field) and ROTR instructions supported?
1587 bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001588
1589 switch (type) {
1590 case Primitive::kPrimInt: {
1591 Register dst = locations->Out().AsRegister<Register>();
1592 Register lhs = locations->InAt(0).AsRegister<Register>();
1593 if (use_imm) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001594 if (shift_value == 0) {
1595 if (dst != lhs) {
1596 __ Move(dst, lhs);
1597 }
1598 } else if (instr->IsShl()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001599 __ Sll(dst, lhs, shift_value);
1600 } else if (instr->IsShr()) {
1601 __ Sra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001602 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001603 __ Srl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001604 } else {
1605 if (has_ins_rotr) {
1606 __ Rotr(dst, lhs, shift_value);
1607 } else {
1608 __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask);
1609 __ Srl(dst, lhs, shift_value);
1610 __ Or(dst, dst, TMP);
1611 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001612 }
1613 } else {
1614 if (instr->IsShl()) {
1615 __ Sllv(dst, lhs, rhs_reg);
1616 } else if (instr->IsShr()) {
1617 __ Srav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001618 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001619 __ Srlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001620 } else {
1621 if (has_ins_rotr) {
1622 __ Rotrv(dst, lhs, rhs_reg);
1623 } else {
1624 __ Subu(TMP, ZERO, rhs_reg);
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001625 // 32-bit shift instructions use the 5 least significant bits of the shift count, so
1626 // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case
1627 // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out
1628 // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`,
1629 // IOW, the OR'd values are equal.
Alexey Frunze92d90602015-12-18 18:16:36 -08001630 __ Sllv(TMP, lhs, TMP);
1631 __ Srlv(dst, lhs, rhs_reg);
1632 __ Or(dst, dst, TMP);
1633 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001634 }
1635 }
1636 break;
1637 }
1638
1639 case Primitive::kPrimLong: {
1640 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
1641 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
1642 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
1643 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
1644 if (use_imm) {
1645 if (shift_value == 0) {
1646 codegen_->Move64(locations->Out(), locations->InAt(0));
1647 } else if (shift_value < kMipsBitsPerWord) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001648 if (has_ins_rotr) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001649 if (instr->IsShl()) {
1650 __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value);
1651 __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value);
1652 __ Sll(dst_low, lhs_low, shift_value);
1653 } else if (instr->IsShr()) {
1654 __ Srl(dst_low, lhs_low, shift_value);
1655 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1656 __ Sra(dst_high, lhs_high, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001657 } else if (instr->IsUShr()) {
1658 __ Srl(dst_low, lhs_low, shift_value);
1659 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1660 __ Srl(dst_high, lhs_high, shift_value);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001661 } else {
1662 __ Srl(dst_low, lhs_low, shift_value);
1663 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1664 __ Srl(dst_high, lhs_high, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001665 __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001666 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001667 } else {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001668 if (instr->IsShl()) {
1669 __ Sll(dst_low, lhs_low, shift_value);
1670 __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value);
1671 __ Sll(dst_high, lhs_high, shift_value);
1672 __ Or(dst_high, dst_high, TMP);
1673 } else if (instr->IsShr()) {
1674 __ Sra(dst_high, lhs_high, shift_value);
1675 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value);
1676 __ Srl(dst_low, lhs_low, shift_value);
1677 __ Or(dst_low, dst_low, TMP);
Alexey Frunze92d90602015-12-18 18:16:36 -08001678 } else if (instr->IsUShr()) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001679 __ Srl(dst_high, lhs_high, shift_value);
1680 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value);
1681 __ Srl(dst_low, lhs_low, shift_value);
1682 __ Or(dst_low, dst_low, TMP);
Alexey Frunze92d90602015-12-18 18:16:36 -08001683 } else {
1684 __ Srl(TMP, lhs_low, shift_value);
1685 __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value);
1686 __ Or(dst_low, dst_low, TMP);
1687 __ Srl(TMP, lhs_high, shift_value);
1688 __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value);
1689 __ Or(dst_high, dst_high, TMP);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001690 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001691 }
1692 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001693 const uint32_t shift_value_high = shift_value - kMipsBitsPerWord;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001694 if (instr->IsShl()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001695 __ Sll(dst_high, lhs_low, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001696 __ Move(dst_low, ZERO);
1697 } else if (instr->IsShr()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001698 __ Sra(dst_low, lhs_high, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001699 __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1);
Alexey Frunze92d90602015-12-18 18:16:36 -08001700 } else if (instr->IsUShr()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001701 __ Srl(dst_low, lhs_high, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001702 __ Move(dst_high, ZERO);
Alexey Frunze92d90602015-12-18 18:16:36 -08001703 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001704 if (shift_value == kMipsBitsPerWord) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001705 // 64-bit rotation by 32 is just a swap.
1706 __ Move(dst_low, lhs_high);
1707 __ Move(dst_high, lhs_low);
1708 } else {
1709 if (has_ins_rotr) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001710 __ Srl(dst_low, lhs_high, shift_value_high);
1711 __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high);
1712 __ Srl(dst_high, lhs_low, shift_value_high);
1713 __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001714 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001715 __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high);
1716 __ Srl(dst_low, lhs_high, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001717 __ Or(dst_low, dst_low, TMP);
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001718 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high);
1719 __ Srl(dst_high, lhs_low, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001720 __ Or(dst_high, dst_high, TMP);
1721 }
1722 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001723 }
1724 }
1725 } else {
1726 MipsLabel done;
1727 if (instr->IsShl()) {
1728 __ Sllv(dst_low, lhs_low, rhs_reg);
1729 __ Nor(AT, ZERO, rhs_reg);
1730 __ Srl(TMP, lhs_low, 1);
1731 __ Srlv(TMP, TMP, AT);
1732 __ Sllv(dst_high, lhs_high, rhs_reg);
1733 __ Or(dst_high, dst_high, TMP);
1734 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1735 __ Beqz(TMP, &done);
1736 __ Move(dst_high, dst_low);
1737 __ Move(dst_low, ZERO);
1738 } else if (instr->IsShr()) {
1739 __ Srav(dst_high, lhs_high, rhs_reg);
1740 __ Nor(AT, ZERO, rhs_reg);
1741 __ Sll(TMP, lhs_high, 1);
1742 __ Sllv(TMP, TMP, AT);
1743 __ Srlv(dst_low, lhs_low, rhs_reg);
1744 __ Or(dst_low, dst_low, TMP);
1745 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1746 __ Beqz(TMP, &done);
1747 __ Move(dst_low, dst_high);
1748 __ Sra(dst_high, dst_high, 31);
Alexey Frunze92d90602015-12-18 18:16:36 -08001749 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001750 __ Srlv(dst_high, lhs_high, rhs_reg);
1751 __ Nor(AT, ZERO, rhs_reg);
1752 __ Sll(TMP, lhs_high, 1);
1753 __ Sllv(TMP, TMP, AT);
1754 __ Srlv(dst_low, lhs_low, rhs_reg);
1755 __ Or(dst_low, dst_low, TMP);
1756 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1757 __ Beqz(TMP, &done);
1758 __ Move(dst_low, dst_high);
1759 __ Move(dst_high, ZERO);
Alexey Frunze92d90602015-12-18 18:16:36 -08001760 } else {
1761 __ Nor(AT, ZERO, rhs_reg);
1762 __ Srlv(TMP, lhs_low, rhs_reg);
1763 __ Sll(dst_low, lhs_high, 1);
1764 __ Sllv(dst_low, dst_low, AT);
1765 __ Or(dst_low, dst_low, TMP);
1766 __ Srlv(TMP, lhs_high, rhs_reg);
1767 __ Sll(dst_high, lhs_low, 1);
1768 __ Sllv(dst_high, dst_high, AT);
1769 __ Or(dst_high, dst_high, TMP);
1770 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1771 __ Beqz(TMP, &done);
1772 __ Move(TMP, dst_high);
1773 __ Move(dst_high, dst_low);
1774 __ Move(dst_low, TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001775 }
1776 __ Bind(&done);
1777 }
1778 break;
1779 }
1780
1781 default:
1782 LOG(FATAL) << "Unexpected shift operation type " << type;
1783 }
1784}
1785
1786void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) {
1787 HandleBinaryOp(instruction);
1788}
1789
1790void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) {
1791 HandleBinaryOp(instruction);
1792}
1793
1794void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) {
1795 HandleBinaryOp(instruction);
1796}
1797
1798void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) {
1799 HandleBinaryOp(instruction);
1800}
1801
1802void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) {
1803 LocationSummary* locations =
1804 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1805 locations->SetInAt(0, Location::RequiresRegister());
1806 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1807 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1808 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1809 } else {
1810 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1811 }
1812}
1813
Alexey Frunze2923db72016-08-20 01:55:47 -07001814auto InstructionCodeGeneratorMIPS::GetImplicitNullChecker(HInstruction* instruction) {
1815 auto null_checker = [this, instruction]() {
1816 this->codegen_->MaybeRecordImplicitNullCheck(instruction);
1817 };
1818 return null_checker;
1819}
1820
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001821void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) {
1822 LocationSummary* locations = instruction->GetLocations();
1823 Register obj = locations->InAt(0).AsRegister<Register>();
1824 Location index = locations->InAt(1);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01001825 uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction);
Alexey Frunze2923db72016-08-20 01:55:47 -07001826 auto null_checker = GetImplicitNullChecker(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001827
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01001828 Primitive::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001829 switch (type) {
1830 case Primitive::kPrimBoolean: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001831 Register out = locations->Out().AsRegister<Register>();
1832 if (index.IsConstant()) {
1833 size_t offset =
1834 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001835 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001836 } else {
1837 __ Addu(TMP, obj, index.AsRegister<Register>());
Alexey Frunze2923db72016-08-20 01:55:47 -07001838 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001839 }
1840 break;
1841 }
1842
1843 case Primitive::kPrimByte: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001844 Register out = locations->Out().AsRegister<Register>();
1845 if (index.IsConstant()) {
1846 size_t offset =
1847 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001848 __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001849 } else {
1850 __ Addu(TMP, obj, index.AsRegister<Register>());
Alexey Frunze2923db72016-08-20 01:55:47 -07001851 __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001852 }
1853 break;
1854 }
1855
1856 case Primitive::kPrimShort: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001857 Register out = locations->Out().AsRegister<Register>();
1858 if (index.IsConstant()) {
1859 size_t offset =
1860 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001861 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001862 } else {
1863 __ Sll(TMP, index.AsRegister<Register>(), TIMES_2);
1864 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001865 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001866 }
1867 break;
1868 }
1869
1870 case Primitive::kPrimChar: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001871 Register out = locations->Out().AsRegister<Register>();
1872 if (index.IsConstant()) {
1873 size_t offset =
1874 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001875 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001876 } else {
1877 __ Sll(TMP, index.AsRegister<Register>(), TIMES_2);
1878 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001879 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001880 }
1881 break;
1882 }
1883
1884 case Primitive::kPrimInt:
1885 case Primitive::kPrimNot: {
1886 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001887 Register out = locations->Out().AsRegister<Register>();
1888 if (index.IsConstant()) {
1889 size_t offset =
1890 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001891 __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001892 } else {
1893 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
1894 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001895 __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001896 }
1897 break;
1898 }
1899
1900 case Primitive::kPrimLong: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001901 Register out = locations->Out().AsRegisterPairLow<Register>();
1902 if (index.IsConstant()) {
1903 size_t offset =
1904 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001905 __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001906 } else {
1907 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
1908 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001909 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001910 }
1911 break;
1912 }
1913
1914 case Primitive::kPrimFloat: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001915 FRegister out = locations->Out().AsFpuRegister<FRegister>();
1916 if (index.IsConstant()) {
1917 size_t offset =
1918 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001919 __ LoadSFromOffset(out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001920 } else {
1921 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
1922 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001923 __ LoadSFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001924 }
1925 break;
1926 }
1927
1928 case Primitive::kPrimDouble: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001929 FRegister out = locations->Out().AsFpuRegister<FRegister>();
1930 if (index.IsConstant()) {
1931 size_t offset =
1932 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001933 __ LoadDFromOffset(out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001934 } else {
1935 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
1936 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001937 __ LoadDFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001938 }
1939 break;
1940 }
1941
1942 case Primitive::kPrimVoid:
1943 LOG(FATAL) << "Unreachable type " << instruction->GetType();
1944 UNREACHABLE();
1945 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001946}
1947
1948void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) {
1949 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1950 locations->SetInAt(0, Location::RequiresRegister());
1951 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1952}
1953
1954void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) {
1955 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01001956 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001957 Register obj = locations->InAt(0).AsRegister<Register>();
1958 Register out = locations->Out().AsRegister<Register>();
1959 __ LoadFromOffset(kLoadWord, out, obj, offset);
1960 codegen_->MaybeRecordImplicitNullCheck(instruction);
1961}
1962
1963void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) {
Pavle Batuta934808f2015-11-03 13:23:54 +01001964 bool needs_runtime_call = instruction->NeedsTypeCheck();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001965 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1966 instruction,
Serban Constantinescu54ff4822016-07-07 18:03:19 +01001967 needs_runtime_call ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall);
Pavle Batuta934808f2015-11-03 13:23:54 +01001968 if (needs_runtime_call) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001969 InvokeRuntimeCallingConvention calling_convention;
1970 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1971 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1972 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1973 } else {
1974 locations->SetInAt(0, Location::RequiresRegister());
1975 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1976 if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
1977 locations->SetInAt(2, Location::RequiresFpuRegister());
1978 } else {
1979 locations->SetInAt(2, Location::RequiresRegister());
1980 }
1981 }
1982}
1983
1984void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) {
1985 LocationSummary* locations = instruction->GetLocations();
1986 Register obj = locations->InAt(0).AsRegister<Register>();
1987 Location index = locations->InAt(1);
1988 Primitive::Type value_type = instruction->GetComponentType();
1989 bool needs_runtime_call = locations->WillCall();
1990 bool needs_write_barrier =
1991 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Alexey Frunze2923db72016-08-20 01:55:47 -07001992 auto null_checker = GetImplicitNullChecker(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001993
1994 switch (value_type) {
1995 case Primitive::kPrimBoolean:
1996 case Primitive::kPrimByte: {
1997 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
1998 Register value = locations->InAt(2).AsRegister<Register>();
1999 if (index.IsConstant()) {
2000 size_t offset =
2001 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002002 __ StoreToOffset(kStoreByte, value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002003 } else {
2004 __ Addu(TMP, obj, index.AsRegister<Register>());
Alexey Frunze2923db72016-08-20 01:55:47 -07002005 __ StoreToOffset(kStoreByte, value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002006 }
2007 break;
2008 }
2009
2010 case Primitive::kPrimShort:
2011 case Primitive::kPrimChar: {
2012 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
2013 Register value = locations->InAt(2).AsRegister<Register>();
2014 if (index.IsConstant()) {
2015 size_t offset =
2016 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002017 __ StoreToOffset(kStoreHalfword, value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002018 } else {
2019 __ Sll(TMP, index.AsRegister<Register>(), TIMES_2);
2020 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002021 __ StoreToOffset(kStoreHalfword, value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002022 }
2023 break;
2024 }
2025
2026 case Primitive::kPrimInt:
2027 case Primitive::kPrimNot: {
2028 if (!needs_runtime_call) {
2029 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
2030 Register value = locations->InAt(2).AsRegister<Register>();
2031 if (index.IsConstant()) {
2032 size_t offset =
2033 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002034 __ StoreToOffset(kStoreWord, value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002035 } else {
2036 DCHECK(index.IsRegister()) << index;
2037 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
2038 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002039 __ StoreToOffset(kStoreWord, value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002040 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002041 if (needs_write_barrier) {
2042 DCHECK_EQ(value_type, Primitive::kPrimNot);
2043 codegen_->MarkGCCard(obj, value);
2044 }
2045 } else {
2046 DCHECK_EQ(value_type, Primitive::kPrimNot);
Serban Constantinescufca16662016-07-14 09:21:59 +01002047 codegen_->InvokeRuntime(kQuickAputObject, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002048 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
2049 }
2050 break;
2051 }
2052
2053 case Primitive::kPrimLong: {
2054 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
2055 Register value = locations->InAt(2).AsRegisterPairLow<Register>();
2056 if (index.IsConstant()) {
2057 size_t offset =
2058 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002059 __ StoreToOffset(kStoreDoubleword, value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002060 } else {
2061 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
2062 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002063 __ StoreToOffset(kStoreDoubleword, value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002064 }
2065 break;
2066 }
2067
2068 case Primitive::kPrimFloat: {
2069 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
2070 FRegister value = locations->InAt(2).AsFpuRegister<FRegister>();
2071 DCHECK(locations->InAt(2).IsFpuRegister());
2072 if (index.IsConstant()) {
2073 size_t offset =
2074 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002075 __ StoreSToOffset(value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002076 } else {
2077 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
2078 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002079 __ StoreSToOffset(value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002080 }
2081 break;
2082 }
2083
2084 case Primitive::kPrimDouble: {
2085 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
2086 FRegister value = locations->InAt(2).AsFpuRegister<FRegister>();
2087 DCHECK(locations->InAt(2).IsFpuRegister());
2088 if (index.IsConstant()) {
2089 size_t offset =
2090 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002091 __ StoreDToOffset(value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002092 } else {
2093 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
2094 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002095 __ StoreDToOffset(value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002096 }
2097 break;
2098 }
2099
2100 case Primitive::kPrimVoid:
2101 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2102 UNREACHABLE();
2103 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002104}
2105
2106void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) {
2107 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
2108 ? LocationSummary::kCallOnSlowPath
2109 : LocationSummary::kNoCall;
2110 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
2111 locations->SetInAt(0, Location::RequiresRegister());
2112 locations->SetInAt(1, Location::RequiresRegister());
2113 if (instruction->HasUses()) {
2114 locations->SetOut(Location::SameAsFirstInput());
2115 }
2116}
2117
2118void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) {
2119 LocationSummary* locations = instruction->GetLocations();
2120 BoundsCheckSlowPathMIPS* slow_path =
2121 new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS(instruction);
2122 codegen_->AddSlowPath(slow_path);
2123
2124 Register index = locations->InAt(0).AsRegister<Register>();
2125 Register length = locations->InAt(1).AsRegister<Register>();
2126
2127 // length is limited by the maximum positive signed 32-bit integer.
2128 // Unsigned comparison of length and index checks for index < 0
2129 // and for length <= index simultaneously.
2130 __ Bgeu(index, length, slow_path->GetEntryLabel());
2131}
2132
2133void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) {
2134 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
2135 instruction,
2136 LocationSummary::kCallOnSlowPath);
2137 locations->SetInAt(0, Location::RequiresRegister());
2138 locations->SetInAt(1, Location::RequiresRegister());
2139 // Note that TypeCheckSlowPathMIPS uses this register too.
2140 locations->AddTemp(Location::RequiresRegister());
2141}
2142
2143void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) {
2144 LocationSummary* locations = instruction->GetLocations();
2145 Register obj = locations->InAt(0).AsRegister<Register>();
2146 Register cls = locations->InAt(1).AsRegister<Register>();
2147 Register obj_cls = locations->GetTemp(0).AsRegister<Register>();
2148
2149 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction);
2150 codegen_->AddSlowPath(slow_path);
2151
2152 // TODO: avoid this check if we know obj is not null.
2153 __ Beqz(obj, slow_path->GetExitLabel());
2154 // Compare the class of `obj` with `cls`.
2155 __ LoadFromOffset(kLoadWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value());
2156 __ Bne(obj_cls, cls, slow_path->GetEntryLabel());
2157 __ Bind(slow_path->GetExitLabel());
2158}
2159
2160void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) {
2161 LocationSummary* locations =
2162 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2163 locations->SetInAt(0, Location::RequiresRegister());
2164 if (check->HasUses()) {
2165 locations->SetOut(Location::SameAsFirstInput());
2166 }
2167}
2168
2169void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) {
2170 // We assume the class is not null.
2171 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS(
2172 check->GetLoadClass(),
2173 check,
2174 check->GetDexPc(),
2175 true);
2176 codegen_->AddSlowPath(slow_path);
2177 GenerateClassInitializationCheck(slow_path,
2178 check->GetLocations()->InAt(0).AsRegister<Register>());
2179}
2180
2181void LocationsBuilderMIPS::VisitCompare(HCompare* compare) {
2182 Primitive::Type in_type = compare->InputAt(0)->GetType();
2183
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002184 LocationSummary* locations =
2185 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002186
2187 switch (in_type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00002188 case Primitive::kPrimBoolean:
2189 case Primitive::kPrimByte:
2190 case Primitive::kPrimShort:
2191 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08002192 case Primitive::kPrimInt:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002193 case Primitive::kPrimLong:
2194 locations->SetInAt(0, Location::RequiresRegister());
2195 locations->SetInAt(1, Location::RequiresRegister());
2196 // Output overlaps because it is written before doing the low comparison.
2197 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
2198 break;
2199
2200 case Primitive::kPrimFloat:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002201 case Primitive::kPrimDouble:
2202 locations->SetInAt(0, Location::RequiresFpuRegister());
2203 locations->SetInAt(1, Location::RequiresFpuRegister());
2204 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002205 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002206
2207 default:
2208 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
2209 }
2210}
2211
2212void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) {
2213 LocationSummary* locations = instruction->GetLocations();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002214 Register res = locations->Out().AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002215 Primitive::Type in_type = instruction->InputAt(0)->GetType();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002216 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002217
2218 // 0 if: left == right
2219 // 1 if: left > right
2220 // -1 if: left < right
2221 switch (in_type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00002222 case Primitive::kPrimBoolean:
2223 case Primitive::kPrimByte:
2224 case Primitive::kPrimShort:
2225 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08002226 case Primitive::kPrimInt: {
2227 Register lhs = locations->InAt(0).AsRegister<Register>();
2228 Register rhs = locations->InAt(1).AsRegister<Register>();
2229 __ Slt(TMP, lhs, rhs);
2230 __ Slt(res, rhs, lhs);
2231 __ Subu(res, res, TMP);
2232 break;
2233 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002234 case Primitive::kPrimLong: {
2235 MipsLabel done;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002236 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
2237 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
2238 Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>();
2239 Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>();
2240 // TODO: more efficient (direct) comparison with a constant.
2241 __ Slt(TMP, lhs_high, rhs_high);
2242 __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt.
2243 __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ].
2244 __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal.
2245 __ Sltu(TMP, lhs_low, rhs_low);
2246 __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt.
2247 __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ].
2248 __ Bind(&done);
2249 break;
2250 }
2251
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002252 case Primitive::kPrimFloat: {
Roland Levillain32ca3752016-02-17 16:49:37 +00002253 bool gt_bias = instruction->IsGtBias();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002254 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2255 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2256 MipsLabel done;
2257 if (isR6) {
2258 __ CmpEqS(FTMP, lhs, rhs);
2259 __ LoadConst32(res, 0);
2260 __ Bc1nez(FTMP, &done);
2261 if (gt_bias) {
2262 __ CmpLtS(FTMP, lhs, rhs);
2263 __ LoadConst32(res, -1);
2264 __ Bc1nez(FTMP, &done);
2265 __ LoadConst32(res, 1);
2266 } else {
2267 __ CmpLtS(FTMP, rhs, lhs);
2268 __ LoadConst32(res, 1);
2269 __ Bc1nez(FTMP, &done);
2270 __ LoadConst32(res, -1);
2271 }
2272 } else {
2273 if (gt_bias) {
2274 __ ColtS(0, lhs, rhs);
2275 __ LoadConst32(res, -1);
2276 __ Bc1t(0, &done);
2277 __ CeqS(0, lhs, rhs);
2278 __ LoadConst32(res, 1);
2279 __ Movt(res, ZERO, 0);
2280 } else {
2281 __ ColtS(0, rhs, lhs);
2282 __ LoadConst32(res, 1);
2283 __ Bc1t(0, &done);
2284 __ CeqS(0, lhs, rhs);
2285 __ LoadConst32(res, -1);
2286 __ Movt(res, ZERO, 0);
2287 }
2288 }
2289 __ Bind(&done);
2290 break;
2291 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002292 case Primitive::kPrimDouble: {
Roland Levillain32ca3752016-02-17 16:49:37 +00002293 bool gt_bias = instruction->IsGtBias();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002294 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2295 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2296 MipsLabel done;
2297 if (isR6) {
2298 __ CmpEqD(FTMP, lhs, rhs);
2299 __ LoadConst32(res, 0);
2300 __ Bc1nez(FTMP, &done);
2301 if (gt_bias) {
2302 __ CmpLtD(FTMP, lhs, rhs);
2303 __ LoadConst32(res, -1);
2304 __ Bc1nez(FTMP, &done);
2305 __ LoadConst32(res, 1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002306 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002307 __ CmpLtD(FTMP, rhs, lhs);
2308 __ LoadConst32(res, 1);
2309 __ Bc1nez(FTMP, &done);
2310 __ LoadConst32(res, -1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002311 }
2312 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002313 if (gt_bias) {
2314 __ ColtD(0, lhs, rhs);
2315 __ LoadConst32(res, -1);
2316 __ Bc1t(0, &done);
2317 __ CeqD(0, lhs, rhs);
2318 __ LoadConst32(res, 1);
2319 __ Movt(res, ZERO, 0);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002320 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002321 __ ColtD(0, rhs, lhs);
2322 __ LoadConst32(res, 1);
2323 __ Bc1t(0, &done);
2324 __ CeqD(0, lhs, rhs);
2325 __ LoadConst32(res, -1);
2326 __ Movt(res, ZERO, 0);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002327 }
2328 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002329 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002330 break;
2331 }
2332
2333 default:
2334 LOG(FATAL) << "Unimplemented compare type " << in_type;
2335 }
2336}
2337
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002338void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002339 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002340 switch (instruction->InputAt(0)->GetType()) {
2341 default:
2342 case Primitive::kPrimLong:
2343 locations->SetInAt(0, Location::RequiresRegister());
2344 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2345 break;
2346
2347 case Primitive::kPrimFloat:
2348 case Primitive::kPrimDouble:
2349 locations->SetInAt(0, Location::RequiresFpuRegister());
2350 locations->SetInAt(1, Location::RequiresFpuRegister());
2351 break;
2352 }
David Brazdilb3e773e2016-01-26 11:28:37 +00002353 if (!instruction->IsEmittedAtUseSite()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002354 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2355 }
2356}
2357
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002358void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) {
David Brazdilb3e773e2016-01-26 11:28:37 +00002359 if (instruction->IsEmittedAtUseSite()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002360 return;
2361 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002362
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002363 Primitive::Type type = instruction->InputAt(0)->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002364 LocationSummary* locations = instruction->GetLocations();
2365 Register dst = locations->Out().AsRegister<Register>();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002366 MipsLabel true_label;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002367
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002368 switch (type) {
2369 default:
2370 // Integer case.
2371 GenerateIntCompare(instruction->GetCondition(), locations);
2372 return;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002373
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002374 case Primitive::kPrimLong:
2375 // TODO: don't use branches.
2376 GenerateLongCompareAndBranch(instruction->GetCondition(), locations, &true_label);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002377 break;
2378
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002379 case Primitive::kPrimFloat:
2380 case Primitive::kPrimDouble:
2381 // TODO: don't use branches.
2382 GenerateFpCompareAndBranch(instruction->GetCondition(),
2383 instruction->IsGtBias(),
2384 type,
2385 locations,
2386 &true_label);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002387 break;
2388 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002389
2390 // Convert the branches into the result.
2391 MipsLabel done;
2392
2393 // False case: result = 0.
2394 __ LoadConst32(dst, 0);
2395 __ B(&done);
2396
2397 // True case: result = 1.
2398 __ Bind(&true_label);
2399 __ LoadConst32(dst, 1);
2400 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002401}
2402
Alexey Frunze7e99e052015-11-24 19:28:01 -08002403void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2404 DCHECK(instruction->IsDiv() || instruction->IsRem());
2405 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2406
2407 LocationSummary* locations = instruction->GetLocations();
2408 Location second = locations->InAt(1);
2409 DCHECK(second.IsConstant());
2410
2411 Register out = locations->Out().AsRegister<Register>();
2412 Register dividend = locations->InAt(0).AsRegister<Register>();
2413 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2414 DCHECK(imm == 1 || imm == -1);
2415
2416 if (instruction->IsRem()) {
2417 __ Move(out, ZERO);
2418 } else {
2419 if (imm == -1) {
2420 __ Subu(out, ZERO, dividend);
2421 } else if (out != dividend) {
2422 __ Move(out, dividend);
2423 }
2424 }
2425}
2426
2427void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2428 DCHECK(instruction->IsDiv() || instruction->IsRem());
2429 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2430
2431 LocationSummary* locations = instruction->GetLocations();
2432 Location second = locations->InAt(1);
2433 DCHECK(second.IsConstant());
2434
2435 Register out = locations->Out().AsRegister<Register>();
2436 Register dividend = locations->InAt(0).AsRegister<Register>();
2437 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002438 uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm));
Alexey Frunze7e99e052015-11-24 19:28:01 -08002439 int ctz_imm = CTZ(abs_imm);
2440
2441 if (instruction->IsDiv()) {
2442 if (ctz_imm == 1) {
2443 // Fast path for division by +/-2, which is very common.
2444 __ Srl(TMP, dividend, 31);
2445 } else {
2446 __ Sra(TMP, dividend, 31);
2447 __ Srl(TMP, TMP, 32 - ctz_imm);
2448 }
2449 __ Addu(out, dividend, TMP);
2450 __ Sra(out, out, ctz_imm);
2451 if (imm < 0) {
2452 __ Subu(out, ZERO, out);
2453 }
2454 } else {
2455 if (ctz_imm == 1) {
2456 // Fast path for modulo +/-2, which is very common.
2457 __ Sra(TMP, dividend, 31);
2458 __ Subu(out, dividend, TMP);
2459 __ Andi(out, out, 1);
2460 __ Addu(out, out, TMP);
2461 } else {
2462 __ Sra(TMP, dividend, 31);
2463 __ Srl(TMP, TMP, 32 - ctz_imm);
2464 __ Addu(out, dividend, TMP);
2465 if (IsUint<16>(abs_imm - 1)) {
2466 __ Andi(out, out, abs_imm - 1);
2467 } else {
2468 __ Sll(out, out, 32 - ctz_imm);
2469 __ Srl(out, out, 32 - ctz_imm);
2470 }
2471 __ Subu(out, out, TMP);
2472 }
2473 }
2474}
2475
2476void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2477 DCHECK(instruction->IsDiv() || instruction->IsRem());
2478 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2479
2480 LocationSummary* locations = instruction->GetLocations();
2481 Location second = locations->InAt(1);
2482 DCHECK(second.IsConstant());
2483
2484 Register out = locations->Out().AsRegister<Register>();
2485 Register dividend = locations->InAt(0).AsRegister<Register>();
2486 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2487
2488 int64_t magic;
2489 int shift;
2490 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2491
2492 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
2493
2494 __ LoadConst32(TMP, magic);
2495 if (isR6) {
2496 __ MuhR6(TMP, dividend, TMP);
2497 } else {
2498 __ MultR2(dividend, TMP);
2499 __ Mfhi(TMP);
2500 }
2501 if (imm > 0 && magic < 0) {
2502 __ Addu(TMP, TMP, dividend);
2503 } else if (imm < 0 && magic > 0) {
2504 __ Subu(TMP, TMP, dividend);
2505 }
2506
2507 if (shift != 0) {
2508 __ Sra(TMP, TMP, shift);
2509 }
2510
2511 if (instruction->IsDiv()) {
2512 __ Sra(out, TMP, 31);
2513 __ Subu(out, TMP, out);
2514 } else {
2515 __ Sra(AT, TMP, 31);
2516 __ Subu(AT, TMP, AT);
2517 __ LoadConst32(TMP, imm);
2518 if (isR6) {
2519 __ MulR6(TMP, AT, TMP);
2520 } else {
2521 __ MulR2(TMP, AT, TMP);
2522 }
2523 __ Subu(out, dividend, TMP);
2524 }
2525}
2526
2527void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) {
2528 DCHECK(instruction->IsDiv() || instruction->IsRem());
2529 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2530
2531 LocationSummary* locations = instruction->GetLocations();
2532 Register out = locations->Out().AsRegister<Register>();
2533 Location second = locations->InAt(1);
2534
2535 if (second.IsConstant()) {
2536 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2537 if (imm == 0) {
2538 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2539 } else if (imm == 1 || imm == -1) {
2540 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002541 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08002542 DivRemByPowerOfTwo(instruction);
2543 } else {
2544 DCHECK(imm <= -2 || imm >= 2);
2545 GenerateDivRemWithAnyConstant(instruction);
2546 }
2547 } else {
2548 Register dividend = locations->InAt(0).AsRegister<Register>();
2549 Register divisor = second.AsRegister<Register>();
2550 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
2551 if (instruction->IsDiv()) {
2552 if (isR6) {
2553 __ DivR6(out, dividend, divisor);
2554 } else {
2555 __ DivR2(out, dividend, divisor);
2556 }
2557 } else {
2558 if (isR6) {
2559 __ ModR6(out, dividend, divisor);
2560 } else {
2561 __ ModR2(out, dividend, divisor);
2562 }
2563 }
2564 }
2565}
2566
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002567void LocationsBuilderMIPS::VisitDiv(HDiv* div) {
2568 Primitive::Type type = div->GetResultType();
2569 LocationSummary::CallKind call_kind = (type == Primitive::kPrimLong)
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002570 ? LocationSummary::kCallOnMainOnly
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002571 : LocationSummary::kNoCall;
2572
2573 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2574
2575 switch (type) {
2576 case Primitive::kPrimInt:
2577 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze7e99e052015-11-24 19:28:01 -08002578 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002579 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2580 break;
2581
2582 case Primitive::kPrimLong: {
2583 InvokeRuntimeCallingConvention calling_convention;
2584 locations->SetInAt(0, Location::RegisterPairLocation(
2585 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2586 locations->SetInAt(1, Location::RegisterPairLocation(
2587 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2588 locations->SetOut(calling_convention.GetReturnLocation(type));
2589 break;
2590 }
2591
2592 case Primitive::kPrimFloat:
2593 case Primitive::kPrimDouble:
2594 locations->SetInAt(0, Location::RequiresFpuRegister());
2595 locations->SetInAt(1, Location::RequiresFpuRegister());
2596 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2597 break;
2598
2599 default:
2600 LOG(FATAL) << "Unexpected div type " << type;
2601 }
2602}
2603
2604void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) {
2605 Primitive::Type type = instruction->GetType();
2606 LocationSummary* locations = instruction->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002607
2608 switch (type) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08002609 case Primitive::kPrimInt:
2610 GenerateDivRemIntegral(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002611 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002612 case Primitive::kPrimLong: {
Serban Constantinescufca16662016-07-14 09:21:59 +01002613 codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002614 CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>();
2615 break;
2616 }
2617 case Primitive::kPrimFloat:
2618 case Primitive::kPrimDouble: {
2619 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
2620 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2621 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2622 if (type == Primitive::kPrimFloat) {
2623 __ DivS(dst, lhs, rhs);
2624 } else {
2625 __ DivD(dst, lhs, rhs);
2626 }
2627 break;
2628 }
2629 default:
2630 LOG(FATAL) << "Unexpected div type " << type;
2631 }
2632}
2633
2634void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2635 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
2636 ? LocationSummary::kCallOnSlowPath
2637 : LocationSummary::kNoCall;
2638 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
2639 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
2640 if (instruction->HasUses()) {
2641 locations->SetOut(Location::SameAsFirstInput());
2642 }
2643}
2644
2645void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2646 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS(instruction);
2647 codegen_->AddSlowPath(slow_path);
2648 Location value = instruction->GetLocations()->InAt(0);
2649 Primitive::Type type = instruction->GetType();
2650
2651 switch (type) {
Nicolas Geoffraye5671612016-03-16 11:03:54 +00002652 case Primitive::kPrimBoolean:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002653 case Primitive::kPrimByte:
2654 case Primitive::kPrimChar:
2655 case Primitive::kPrimShort:
2656 case Primitive::kPrimInt: {
2657 if (value.IsConstant()) {
2658 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2659 __ B(slow_path->GetEntryLabel());
2660 } else {
2661 // A division by a non-null constant is valid. We don't need to perform
2662 // any check, so simply fall through.
2663 }
2664 } else {
2665 DCHECK(value.IsRegister()) << value;
2666 __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel());
2667 }
2668 break;
2669 }
2670 case Primitive::kPrimLong: {
2671 if (value.IsConstant()) {
2672 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2673 __ B(slow_path->GetEntryLabel());
2674 } else {
2675 // A division by a non-null constant is valid. We don't need to perform
2676 // any check, so simply fall through.
2677 }
2678 } else {
2679 DCHECK(value.IsRegisterPair()) << value;
2680 __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>());
2681 __ Beqz(TMP, slow_path->GetEntryLabel());
2682 }
2683 break;
2684 }
2685 default:
2686 LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck.";
2687 }
2688}
2689
2690void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) {
2691 LocationSummary* locations =
2692 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2693 locations->SetOut(Location::ConstantLocation(constant));
2694}
2695
2696void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) {
2697 // Will be generated at use site.
2698}
2699
2700void LocationsBuilderMIPS::VisitExit(HExit* exit) {
2701 exit->SetLocations(nullptr);
2702}
2703
2704void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
2705}
2706
2707void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) {
2708 LocationSummary* locations =
2709 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2710 locations->SetOut(Location::ConstantLocation(constant));
2711}
2712
2713void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
2714 // Will be generated at use site.
2715}
2716
2717void LocationsBuilderMIPS::VisitGoto(HGoto* got) {
2718 got->SetLocations(nullptr);
2719}
2720
2721void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) {
2722 DCHECK(!successor->IsExitBlock());
2723 HBasicBlock* block = got->GetBlock();
2724 HInstruction* previous = got->GetPrevious();
2725 HLoopInformation* info = block->GetLoopInformation();
2726
2727 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
2728 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
2729 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
2730 return;
2731 }
2732 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
2733 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
2734 }
2735 if (!codegen_->GoesToNextBlock(block, successor)) {
2736 __ B(codegen_->GetLabelOf(successor));
2737 }
2738}
2739
2740void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) {
2741 HandleGoto(got, got->GetSuccessor());
2742}
2743
2744void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) {
2745 try_boundary->SetLocations(nullptr);
2746}
2747
2748void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) {
2749 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
2750 if (!successor->IsExitBlock()) {
2751 HandleGoto(try_boundary, successor);
2752 }
2753}
2754
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002755void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond,
2756 LocationSummary* locations) {
2757 Register dst = locations->Out().AsRegister<Register>();
2758 Register lhs = locations->InAt(0).AsRegister<Register>();
2759 Location rhs_location = locations->InAt(1);
2760 Register rhs_reg = ZERO;
2761 int64_t rhs_imm = 0;
2762 bool use_imm = rhs_location.IsConstant();
2763 if (use_imm) {
2764 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2765 } else {
2766 rhs_reg = rhs_location.AsRegister<Register>();
2767 }
2768
2769 switch (cond) {
2770 case kCondEQ:
2771 case kCondNE:
2772 if (use_imm && IsUint<16>(rhs_imm)) {
2773 __ Xori(dst, lhs, rhs_imm);
2774 } else {
2775 if (use_imm) {
2776 rhs_reg = TMP;
2777 __ LoadConst32(rhs_reg, rhs_imm);
2778 }
2779 __ Xor(dst, lhs, rhs_reg);
2780 }
2781 if (cond == kCondEQ) {
2782 __ Sltiu(dst, dst, 1);
2783 } else {
2784 __ Sltu(dst, ZERO, dst);
2785 }
2786 break;
2787
2788 case kCondLT:
2789 case kCondGE:
2790 if (use_imm && IsInt<16>(rhs_imm)) {
2791 __ Slti(dst, lhs, rhs_imm);
2792 } else {
2793 if (use_imm) {
2794 rhs_reg = TMP;
2795 __ LoadConst32(rhs_reg, rhs_imm);
2796 }
2797 __ Slt(dst, lhs, rhs_reg);
2798 }
2799 if (cond == kCondGE) {
2800 // Simulate lhs >= rhs via !(lhs < rhs) since there's
2801 // only the slt instruction but no sge.
2802 __ Xori(dst, dst, 1);
2803 }
2804 break;
2805
2806 case kCondLE:
2807 case kCondGT:
2808 if (use_imm && IsInt<16>(rhs_imm + 1)) {
2809 // Simulate lhs <= rhs via lhs < rhs + 1.
2810 __ Slti(dst, lhs, rhs_imm + 1);
2811 if (cond == kCondGT) {
2812 // Simulate lhs > rhs via !(lhs <= rhs) since there's
2813 // only the slti instruction but no sgti.
2814 __ Xori(dst, dst, 1);
2815 }
2816 } else {
2817 if (use_imm) {
2818 rhs_reg = TMP;
2819 __ LoadConst32(rhs_reg, rhs_imm);
2820 }
2821 __ Slt(dst, rhs_reg, lhs);
2822 if (cond == kCondLE) {
2823 // Simulate lhs <= rhs via !(rhs < lhs) since there's
2824 // only the slt instruction but no sle.
2825 __ Xori(dst, dst, 1);
2826 }
2827 }
2828 break;
2829
2830 case kCondB:
2831 case kCondAE:
2832 if (use_imm && IsInt<16>(rhs_imm)) {
2833 // Sltiu sign-extends its 16-bit immediate operand before
2834 // the comparison and thus lets us compare directly with
2835 // unsigned values in the ranges [0, 0x7fff] and
2836 // [0xffff8000, 0xffffffff].
2837 __ Sltiu(dst, lhs, rhs_imm);
2838 } else {
2839 if (use_imm) {
2840 rhs_reg = TMP;
2841 __ LoadConst32(rhs_reg, rhs_imm);
2842 }
2843 __ Sltu(dst, lhs, rhs_reg);
2844 }
2845 if (cond == kCondAE) {
2846 // Simulate lhs >= rhs via !(lhs < rhs) since there's
2847 // only the sltu instruction but no sgeu.
2848 __ Xori(dst, dst, 1);
2849 }
2850 break;
2851
2852 case kCondBE:
2853 case kCondA:
2854 if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
2855 // Simulate lhs <= rhs via lhs < rhs + 1.
2856 // Note that this only works if rhs + 1 does not overflow
2857 // to 0, hence the check above.
2858 // Sltiu sign-extends its 16-bit immediate operand before
2859 // the comparison and thus lets us compare directly with
2860 // unsigned values in the ranges [0, 0x7fff] and
2861 // [0xffff8000, 0xffffffff].
2862 __ Sltiu(dst, lhs, rhs_imm + 1);
2863 if (cond == kCondA) {
2864 // Simulate lhs > rhs via !(lhs <= rhs) since there's
2865 // only the sltiu instruction but no sgtiu.
2866 __ Xori(dst, dst, 1);
2867 }
2868 } else {
2869 if (use_imm) {
2870 rhs_reg = TMP;
2871 __ LoadConst32(rhs_reg, rhs_imm);
2872 }
2873 __ Sltu(dst, rhs_reg, lhs);
2874 if (cond == kCondBE) {
2875 // Simulate lhs <= rhs via !(rhs < lhs) since there's
2876 // only the sltu instruction but no sleu.
2877 __ Xori(dst, dst, 1);
2878 }
2879 }
2880 break;
2881 }
2882}
2883
2884void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond,
2885 LocationSummary* locations,
2886 MipsLabel* label) {
2887 Register lhs = locations->InAt(0).AsRegister<Register>();
2888 Location rhs_location = locations->InAt(1);
2889 Register rhs_reg = ZERO;
2890 int32_t rhs_imm = 0;
2891 bool use_imm = rhs_location.IsConstant();
2892 if (use_imm) {
2893 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2894 } else {
2895 rhs_reg = rhs_location.AsRegister<Register>();
2896 }
2897
2898 if (use_imm && rhs_imm == 0) {
2899 switch (cond) {
2900 case kCondEQ:
2901 case kCondBE: // <= 0 if zero
2902 __ Beqz(lhs, label);
2903 break;
2904 case kCondNE:
2905 case kCondA: // > 0 if non-zero
2906 __ Bnez(lhs, label);
2907 break;
2908 case kCondLT:
2909 __ Bltz(lhs, label);
2910 break;
2911 case kCondGE:
2912 __ Bgez(lhs, label);
2913 break;
2914 case kCondLE:
2915 __ Blez(lhs, label);
2916 break;
2917 case kCondGT:
2918 __ Bgtz(lhs, label);
2919 break;
2920 case kCondB: // always false
2921 break;
2922 case kCondAE: // always true
2923 __ B(label);
2924 break;
2925 }
2926 } else {
2927 if (use_imm) {
2928 // TODO: more efficient comparison with 16-bit constants without loading them into TMP.
2929 rhs_reg = TMP;
2930 __ LoadConst32(rhs_reg, rhs_imm);
2931 }
2932 switch (cond) {
2933 case kCondEQ:
2934 __ Beq(lhs, rhs_reg, label);
2935 break;
2936 case kCondNE:
2937 __ Bne(lhs, rhs_reg, label);
2938 break;
2939 case kCondLT:
2940 __ Blt(lhs, rhs_reg, label);
2941 break;
2942 case kCondGE:
2943 __ Bge(lhs, rhs_reg, label);
2944 break;
2945 case kCondLE:
2946 __ Bge(rhs_reg, lhs, label);
2947 break;
2948 case kCondGT:
2949 __ Blt(rhs_reg, lhs, label);
2950 break;
2951 case kCondB:
2952 __ Bltu(lhs, rhs_reg, label);
2953 break;
2954 case kCondAE:
2955 __ Bgeu(lhs, rhs_reg, label);
2956 break;
2957 case kCondBE:
2958 __ Bgeu(rhs_reg, lhs, label);
2959 break;
2960 case kCondA:
2961 __ Bltu(rhs_reg, lhs, label);
2962 break;
2963 }
2964 }
2965}
2966
2967void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond,
2968 LocationSummary* locations,
2969 MipsLabel* label) {
2970 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
2971 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
2972 Location rhs_location = locations->InAt(1);
2973 Register rhs_high = ZERO;
2974 Register rhs_low = ZERO;
2975 int64_t imm = 0;
2976 uint32_t imm_high = 0;
2977 uint32_t imm_low = 0;
2978 bool use_imm = rhs_location.IsConstant();
2979 if (use_imm) {
2980 imm = rhs_location.GetConstant()->AsLongConstant()->GetValue();
2981 imm_high = High32Bits(imm);
2982 imm_low = Low32Bits(imm);
2983 } else {
2984 rhs_high = rhs_location.AsRegisterPairHigh<Register>();
2985 rhs_low = rhs_location.AsRegisterPairLow<Register>();
2986 }
2987
2988 if (use_imm && imm == 0) {
2989 switch (cond) {
2990 case kCondEQ:
2991 case kCondBE: // <= 0 if zero
2992 __ Or(TMP, lhs_high, lhs_low);
2993 __ Beqz(TMP, label);
2994 break;
2995 case kCondNE:
2996 case kCondA: // > 0 if non-zero
2997 __ Or(TMP, lhs_high, lhs_low);
2998 __ Bnez(TMP, label);
2999 break;
3000 case kCondLT:
3001 __ Bltz(lhs_high, label);
3002 break;
3003 case kCondGE:
3004 __ Bgez(lhs_high, label);
3005 break;
3006 case kCondLE:
3007 __ Or(TMP, lhs_high, lhs_low);
3008 __ Sra(AT, lhs_high, 31);
3009 __ Bgeu(AT, TMP, label);
3010 break;
3011 case kCondGT:
3012 __ Or(TMP, lhs_high, lhs_low);
3013 __ Sra(AT, lhs_high, 31);
3014 __ Bltu(AT, TMP, label);
3015 break;
3016 case kCondB: // always false
3017 break;
3018 case kCondAE: // always true
3019 __ B(label);
3020 break;
3021 }
3022 } else if (use_imm) {
3023 // TODO: more efficient comparison with constants without loading them into TMP/AT.
3024 switch (cond) {
3025 case kCondEQ:
3026 __ LoadConst32(TMP, imm_high);
3027 __ Xor(TMP, TMP, lhs_high);
3028 __ LoadConst32(AT, imm_low);
3029 __ Xor(AT, AT, lhs_low);
3030 __ Or(TMP, TMP, AT);
3031 __ Beqz(TMP, label);
3032 break;
3033 case kCondNE:
3034 __ LoadConst32(TMP, imm_high);
3035 __ Xor(TMP, TMP, lhs_high);
3036 __ LoadConst32(AT, imm_low);
3037 __ Xor(AT, AT, lhs_low);
3038 __ Or(TMP, TMP, AT);
3039 __ Bnez(TMP, label);
3040 break;
3041 case kCondLT:
3042 __ LoadConst32(TMP, imm_high);
3043 __ Blt(lhs_high, TMP, label);
3044 __ Slt(TMP, TMP, lhs_high);
3045 __ LoadConst32(AT, imm_low);
3046 __ Sltu(AT, lhs_low, AT);
3047 __ Blt(TMP, AT, label);
3048 break;
3049 case kCondGE:
3050 __ LoadConst32(TMP, imm_high);
3051 __ Blt(TMP, lhs_high, label);
3052 __ Slt(TMP, lhs_high, TMP);
3053 __ LoadConst32(AT, imm_low);
3054 __ Sltu(AT, lhs_low, AT);
3055 __ Or(TMP, TMP, AT);
3056 __ Beqz(TMP, label);
3057 break;
3058 case kCondLE:
3059 __ LoadConst32(TMP, imm_high);
3060 __ Blt(lhs_high, TMP, label);
3061 __ Slt(TMP, TMP, lhs_high);
3062 __ LoadConst32(AT, imm_low);
3063 __ Sltu(AT, AT, lhs_low);
3064 __ Or(TMP, TMP, AT);
3065 __ Beqz(TMP, label);
3066 break;
3067 case kCondGT:
3068 __ LoadConst32(TMP, imm_high);
3069 __ Blt(TMP, lhs_high, label);
3070 __ Slt(TMP, lhs_high, TMP);
3071 __ LoadConst32(AT, imm_low);
3072 __ Sltu(AT, AT, lhs_low);
3073 __ Blt(TMP, AT, label);
3074 break;
3075 case kCondB:
3076 __ LoadConst32(TMP, imm_high);
3077 __ Bltu(lhs_high, TMP, label);
3078 __ Sltu(TMP, TMP, lhs_high);
3079 __ LoadConst32(AT, imm_low);
3080 __ Sltu(AT, lhs_low, AT);
3081 __ Blt(TMP, AT, label);
3082 break;
3083 case kCondAE:
3084 __ LoadConst32(TMP, imm_high);
3085 __ Bltu(TMP, lhs_high, label);
3086 __ Sltu(TMP, lhs_high, TMP);
3087 __ LoadConst32(AT, imm_low);
3088 __ Sltu(AT, lhs_low, AT);
3089 __ Or(TMP, TMP, AT);
3090 __ Beqz(TMP, label);
3091 break;
3092 case kCondBE:
3093 __ LoadConst32(TMP, imm_high);
3094 __ Bltu(lhs_high, TMP, label);
3095 __ Sltu(TMP, TMP, lhs_high);
3096 __ LoadConst32(AT, imm_low);
3097 __ Sltu(AT, AT, lhs_low);
3098 __ Or(TMP, TMP, AT);
3099 __ Beqz(TMP, label);
3100 break;
3101 case kCondA:
3102 __ LoadConst32(TMP, imm_high);
3103 __ Bltu(TMP, lhs_high, label);
3104 __ Sltu(TMP, lhs_high, TMP);
3105 __ LoadConst32(AT, imm_low);
3106 __ Sltu(AT, AT, lhs_low);
3107 __ Blt(TMP, AT, label);
3108 break;
3109 }
3110 } else {
3111 switch (cond) {
3112 case kCondEQ:
3113 __ Xor(TMP, lhs_high, rhs_high);
3114 __ Xor(AT, lhs_low, rhs_low);
3115 __ Or(TMP, TMP, AT);
3116 __ Beqz(TMP, label);
3117 break;
3118 case kCondNE:
3119 __ Xor(TMP, lhs_high, rhs_high);
3120 __ Xor(AT, lhs_low, rhs_low);
3121 __ Or(TMP, TMP, AT);
3122 __ Bnez(TMP, label);
3123 break;
3124 case kCondLT:
3125 __ Blt(lhs_high, rhs_high, label);
3126 __ Slt(TMP, rhs_high, lhs_high);
3127 __ Sltu(AT, lhs_low, rhs_low);
3128 __ Blt(TMP, AT, label);
3129 break;
3130 case kCondGE:
3131 __ Blt(rhs_high, lhs_high, label);
3132 __ Slt(TMP, lhs_high, rhs_high);
3133 __ Sltu(AT, lhs_low, rhs_low);
3134 __ Or(TMP, TMP, AT);
3135 __ Beqz(TMP, label);
3136 break;
3137 case kCondLE:
3138 __ Blt(lhs_high, rhs_high, label);
3139 __ Slt(TMP, rhs_high, lhs_high);
3140 __ Sltu(AT, rhs_low, lhs_low);
3141 __ Or(TMP, TMP, AT);
3142 __ Beqz(TMP, label);
3143 break;
3144 case kCondGT:
3145 __ Blt(rhs_high, lhs_high, label);
3146 __ Slt(TMP, lhs_high, rhs_high);
3147 __ Sltu(AT, rhs_low, lhs_low);
3148 __ Blt(TMP, AT, label);
3149 break;
3150 case kCondB:
3151 __ Bltu(lhs_high, rhs_high, label);
3152 __ Sltu(TMP, rhs_high, lhs_high);
3153 __ Sltu(AT, lhs_low, rhs_low);
3154 __ Blt(TMP, AT, label);
3155 break;
3156 case kCondAE:
3157 __ Bltu(rhs_high, lhs_high, label);
3158 __ Sltu(TMP, lhs_high, rhs_high);
3159 __ Sltu(AT, lhs_low, rhs_low);
3160 __ Or(TMP, TMP, AT);
3161 __ Beqz(TMP, label);
3162 break;
3163 case kCondBE:
3164 __ Bltu(lhs_high, rhs_high, label);
3165 __ Sltu(TMP, rhs_high, lhs_high);
3166 __ Sltu(AT, rhs_low, lhs_low);
3167 __ Or(TMP, TMP, AT);
3168 __ Beqz(TMP, label);
3169 break;
3170 case kCondA:
3171 __ Bltu(rhs_high, lhs_high, label);
3172 __ Sltu(TMP, lhs_high, rhs_high);
3173 __ Sltu(AT, rhs_low, lhs_low);
3174 __ Blt(TMP, AT, label);
3175 break;
3176 }
3177 }
3178}
3179
3180void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond,
3181 bool gt_bias,
3182 Primitive::Type type,
3183 LocationSummary* locations,
3184 MipsLabel* label) {
3185 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
3186 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
3187 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
3188 if (type == Primitive::kPrimFloat) {
3189 if (isR6) {
3190 switch (cond) {
3191 case kCondEQ:
3192 __ CmpEqS(FTMP, lhs, rhs);
3193 __ Bc1nez(FTMP, label);
3194 break;
3195 case kCondNE:
3196 __ CmpEqS(FTMP, lhs, rhs);
3197 __ Bc1eqz(FTMP, label);
3198 break;
3199 case kCondLT:
3200 if (gt_bias) {
3201 __ CmpLtS(FTMP, lhs, rhs);
3202 } else {
3203 __ CmpUltS(FTMP, lhs, rhs);
3204 }
3205 __ Bc1nez(FTMP, label);
3206 break;
3207 case kCondLE:
3208 if (gt_bias) {
3209 __ CmpLeS(FTMP, lhs, rhs);
3210 } else {
3211 __ CmpUleS(FTMP, lhs, rhs);
3212 }
3213 __ Bc1nez(FTMP, label);
3214 break;
3215 case kCondGT:
3216 if (gt_bias) {
3217 __ CmpUltS(FTMP, rhs, lhs);
3218 } else {
3219 __ CmpLtS(FTMP, rhs, lhs);
3220 }
3221 __ Bc1nez(FTMP, label);
3222 break;
3223 case kCondGE:
3224 if (gt_bias) {
3225 __ CmpUleS(FTMP, rhs, lhs);
3226 } else {
3227 __ CmpLeS(FTMP, rhs, lhs);
3228 }
3229 __ Bc1nez(FTMP, label);
3230 break;
3231 default:
3232 LOG(FATAL) << "Unexpected non-floating-point condition";
3233 }
3234 } else {
3235 switch (cond) {
3236 case kCondEQ:
3237 __ CeqS(0, lhs, rhs);
3238 __ Bc1t(0, label);
3239 break;
3240 case kCondNE:
3241 __ CeqS(0, lhs, rhs);
3242 __ Bc1f(0, label);
3243 break;
3244 case kCondLT:
3245 if (gt_bias) {
3246 __ ColtS(0, lhs, rhs);
3247 } else {
3248 __ CultS(0, lhs, rhs);
3249 }
3250 __ Bc1t(0, label);
3251 break;
3252 case kCondLE:
3253 if (gt_bias) {
3254 __ ColeS(0, lhs, rhs);
3255 } else {
3256 __ CuleS(0, lhs, rhs);
3257 }
3258 __ Bc1t(0, label);
3259 break;
3260 case kCondGT:
3261 if (gt_bias) {
3262 __ CultS(0, rhs, lhs);
3263 } else {
3264 __ ColtS(0, rhs, lhs);
3265 }
3266 __ Bc1t(0, label);
3267 break;
3268 case kCondGE:
3269 if (gt_bias) {
3270 __ CuleS(0, rhs, lhs);
3271 } else {
3272 __ ColeS(0, rhs, lhs);
3273 }
3274 __ Bc1t(0, label);
3275 break;
3276 default:
3277 LOG(FATAL) << "Unexpected non-floating-point condition";
3278 }
3279 }
3280 } else {
3281 DCHECK_EQ(type, Primitive::kPrimDouble);
3282 if (isR6) {
3283 switch (cond) {
3284 case kCondEQ:
3285 __ CmpEqD(FTMP, lhs, rhs);
3286 __ Bc1nez(FTMP, label);
3287 break;
3288 case kCondNE:
3289 __ CmpEqD(FTMP, lhs, rhs);
3290 __ Bc1eqz(FTMP, label);
3291 break;
3292 case kCondLT:
3293 if (gt_bias) {
3294 __ CmpLtD(FTMP, lhs, rhs);
3295 } else {
3296 __ CmpUltD(FTMP, lhs, rhs);
3297 }
3298 __ Bc1nez(FTMP, label);
3299 break;
3300 case kCondLE:
3301 if (gt_bias) {
3302 __ CmpLeD(FTMP, lhs, rhs);
3303 } else {
3304 __ CmpUleD(FTMP, lhs, rhs);
3305 }
3306 __ Bc1nez(FTMP, label);
3307 break;
3308 case kCondGT:
3309 if (gt_bias) {
3310 __ CmpUltD(FTMP, rhs, lhs);
3311 } else {
3312 __ CmpLtD(FTMP, rhs, lhs);
3313 }
3314 __ Bc1nez(FTMP, label);
3315 break;
3316 case kCondGE:
3317 if (gt_bias) {
3318 __ CmpUleD(FTMP, rhs, lhs);
3319 } else {
3320 __ CmpLeD(FTMP, rhs, lhs);
3321 }
3322 __ Bc1nez(FTMP, label);
3323 break;
3324 default:
3325 LOG(FATAL) << "Unexpected non-floating-point condition";
3326 }
3327 } else {
3328 switch (cond) {
3329 case kCondEQ:
3330 __ CeqD(0, lhs, rhs);
3331 __ Bc1t(0, label);
3332 break;
3333 case kCondNE:
3334 __ CeqD(0, lhs, rhs);
3335 __ Bc1f(0, label);
3336 break;
3337 case kCondLT:
3338 if (gt_bias) {
3339 __ ColtD(0, lhs, rhs);
3340 } else {
3341 __ CultD(0, lhs, rhs);
3342 }
3343 __ Bc1t(0, label);
3344 break;
3345 case kCondLE:
3346 if (gt_bias) {
3347 __ ColeD(0, lhs, rhs);
3348 } else {
3349 __ CuleD(0, lhs, rhs);
3350 }
3351 __ Bc1t(0, label);
3352 break;
3353 case kCondGT:
3354 if (gt_bias) {
3355 __ CultD(0, rhs, lhs);
3356 } else {
3357 __ ColtD(0, rhs, lhs);
3358 }
3359 __ Bc1t(0, label);
3360 break;
3361 case kCondGE:
3362 if (gt_bias) {
3363 __ CuleD(0, rhs, lhs);
3364 } else {
3365 __ ColeD(0, rhs, lhs);
3366 }
3367 __ Bc1t(0, label);
3368 break;
3369 default:
3370 LOG(FATAL) << "Unexpected non-floating-point condition";
3371 }
3372 }
3373 }
3374}
3375
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003376void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00003377 size_t condition_input_index,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003378 MipsLabel* true_target,
David Brazdil0debae72015-11-12 18:37:00 +00003379 MipsLabel* false_target) {
3380 HInstruction* cond = instruction->InputAt(condition_input_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003381
David Brazdil0debae72015-11-12 18:37:00 +00003382 if (true_target == nullptr && false_target == nullptr) {
3383 // Nothing to do. The code always falls through.
3384 return;
3385 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00003386 // Constant condition, statically compared against "true" (integer value 1).
3387 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00003388 if (true_target != nullptr) {
3389 __ B(true_target);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003390 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003391 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00003392 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00003393 if (false_target != nullptr) {
3394 __ B(false_target);
3395 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003396 }
David Brazdil0debae72015-11-12 18:37:00 +00003397 return;
3398 }
3399
3400 // The following code generates these patterns:
3401 // (1) true_target == nullptr && false_target != nullptr
3402 // - opposite condition true => branch to false_target
3403 // (2) true_target != nullptr && false_target == nullptr
3404 // - condition true => branch to true_target
3405 // (3) true_target != nullptr && false_target != nullptr
3406 // - condition true => branch to true_target
3407 // - branch to false_target
3408 if (IsBooleanValueOrMaterializedCondition(cond)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003409 // The condition instruction has been materialized, compare the output to 0.
David Brazdil0debae72015-11-12 18:37:00 +00003410 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003411 DCHECK(cond_val.IsRegister());
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003412 if (true_target == nullptr) {
David Brazdil0debae72015-11-12 18:37:00 +00003413 __ Beqz(cond_val.AsRegister<Register>(), false_target);
3414 } else {
3415 __ Bnez(cond_val.AsRegister<Register>(), true_target);
3416 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003417 } else {
3418 // The condition instruction has not been materialized, use its inputs as
3419 // the comparison and its condition as the branch condition.
David Brazdil0debae72015-11-12 18:37:00 +00003420 HCondition* condition = cond->AsCondition();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003421 Primitive::Type type = condition->InputAt(0)->GetType();
3422 LocationSummary* locations = cond->GetLocations();
3423 IfCondition if_cond = condition->GetCondition();
3424 MipsLabel* branch_target = true_target;
David Brazdil0debae72015-11-12 18:37:00 +00003425
David Brazdil0debae72015-11-12 18:37:00 +00003426 if (true_target == nullptr) {
3427 if_cond = condition->GetOppositeCondition();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003428 branch_target = false_target;
David Brazdil0debae72015-11-12 18:37:00 +00003429 }
3430
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003431 switch (type) {
3432 default:
3433 GenerateIntCompareAndBranch(if_cond, locations, branch_target);
3434 break;
3435 case Primitive::kPrimLong:
3436 GenerateLongCompareAndBranch(if_cond, locations, branch_target);
3437 break;
3438 case Primitive::kPrimFloat:
3439 case Primitive::kPrimDouble:
3440 GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target);
3441 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003442 }
3443 }
David Brazdil0debae72015-11-12 18:37:00 +00003444
3445 // If neither branch falls through (case 3), the conditional branch to `true_target`
3446 // was already emitted (case 2) and we need to emit a jump to `false_target`.
3447 if (true_target != nullptr && false_target != nullptr) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003448 __ B(false_target);
3449 }
3450}
3451
3452void LocationsBuilderMIPS::VisitIf(HIf* if_instr) {
3453 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
David Brazdil0debae72015-11-12 18:37:00 +00003454 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003455 locations->SetInAt(0, Location::RequiresRegister());
3456 }
3457}
3458
3459void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00003460 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
3461 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
3462 MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
3463 nullptr : codegen_->GetLabelOf(true_successor);
3464 MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
3465 nullptr : codegen_->GetLabelOf(false_successor);
3466 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003467}
3468
3469void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) {
3470 LocationSummary* locations = new (GetGraph()->GetArena())
3471 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
Vladimir Marko239d6ea2016-09-05 10:44:04 +01003472 locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers.
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) {
Nicolas Geoffray0719b5b2016-09-12 22:05:33 +00004859 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 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004867}
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