blob: e0de03bf8f5c004f2fb9b443397cb5c065fca344 [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"
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020023#include "entrypoints/quick/quick_entrypoints.h"
24#include "entrypoints/quick/quick_entrypoints_enum.h"
25#include "gc/accounting/card_table.h"
26#include "intrinsics.h"
Chris Larsen701566a2015-10-27 15:29:13 -070027#include "intrinsics_mips.h"
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020028#include "mirror/array-inl.h"
29#include "mirror/class-inl.h"
30#include "offsets.h"
31#include "thread.h"
32#include "utils/assembler.h"
33#include "utils/mips/assembler_mips.h"
34#include "utils/stack_checks.h"
35
36namespace art {
37namespace mips {
38
39static constexpr int kCurrentMethodStackOffset = 0;
40static constexpr Register kMethodRegisterArgument = A0;
41
Alexey Frunzee3fb2452016-05-10 16:08:05 -070042// We'll maximize the range of a single load instruction for dex cache array accesses
43// by aligning offset -32768 with the offset of the first used element.
44static constexpr uint32_t kDexCacheArrayLwOffset = 0x8000;
45
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020046Location MipsReturnLocation(Primitive::Type return_type) {
47 switch (return_type) {
48 case Primitive::kPrimBoolean:
49 case Primitive::kPrimByte:
50 case Primitive::kPrimChar:
51 case Primitive::kPrimShort:
52 case Primitive::kPrimInt:
53 case Primitive::kPrimNot:
54 return Location::RegisterLocation(V0);
55
56 case Primitive::kPrimLong:
57 return Location::RegisterPairLocation(V0, V1);
58
59 case Primitive::kPrimFloat:
60 case Primitive::kPrimDouble:
61 return Location::FpuRegisterLocation(F0);
62
63 case Primitive::kPrimVoid:
64 return Location();
65 }
66 UNREACHABLE();
67}
68
69Location InvokeDexCallingConventionVisitorMIPS::GetReturnLocation(Primitive::Type type) const {
70 return MipsReturnLocation(type);
71}
72
73Location InvokeDexCallingConventionVisitorMIPS::GetMethodLocation() const {
74 return Location::RegisterLocation(kMethodRegisterArgument);
75}
76
77Location InvokeDexCallingConventionVisitorMIPS::GetNextLocation(Primitive::Type type) {
78 Location next_location;
79
80 switch (type) {
81 case Primitive::kPrimBoolean:
82 case Primitive::kPrimByte:
83 case Primitive::kPrimChar:
84 case Primitive::kPrimShort:
85 case Primitive::kPrimInt:
86 case Primitive::kPrimNot: {
87 uint32_t gp_index = gp_index_++;
88 if (gp_index < calling_convention.GetNumberOfRegisters()) {
89 next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index));
90 } else {
91 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
92 next_location = Location::StackSlot(stack_offset);
93 }
94 break;
95 }
96
97 case Primitive::kPrimLong: {
98 uint32_t gp_index = gp_index_;
99 gp_index_ += 2;
100 if (gp_index + 1 < calling_convention.GetNumberOfRegisters()) {
101 if (calling_convention.GetRegisterAt(gp_index) == A1) {
102 gp_index_++; // Skip A1, and use A2_A3 instead.
103 gp_index++;
104 }
105 Register low_even = calling_convention.GetRegisterAt(gp_index);
106 Register high_odd = calling_convention.GetRegisterAt(gp_index + 1);
107 DCHECK_EQ(low_even + 1, high_odd);
108 next_location = Location::RegisterPairLocation(low_even, high_odd);
109 } else {
110 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
111 next_location = Location::DoubleStackSlot(stack_offset);
112 }
113 break;
114 }
115
116 // Note: both float and double types are stored in even FPU registers. On 32 bit FPU, double
117 // will take up the even/odd pair, while floats are stored in even regs only.
118 // On 64 bit FPU, both double and float are stored in even registers only.
119 case Primitive::kPrimFloat:
120 case Primitive::kPrimDouble: {
121 uint32_t float_index = float_index_++;
122 if (float_index < calling_convention.GetNumberOfFpuRegisters()) {
123 next_location = Location::FpuRegisterLocation(
124 calling_convention.GetFpuRegisterAt(float_index));
125 } else {
126 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
127 next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
128 : Location::StackSlot(stack_offset);
129 }
130 break;
131 }
132
133 case Primitive::kPrimVoid:
134 LOG(FATAL) << "Unexpected parameter type " << type;
135 break;
136 }
137
138 // Space on the stack is reserved for all arguments.
139 stack_index_ += Primitive::Is64BitType(type) ? 2 : 1;
140
141 return next_location;
142}
143
144Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type type) {
145 return MipsReturnLocation(type);
146}
147
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100148// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
149#define __ down_cast<CodeGeneratorMIPS*>(codegen)->GetAssembler()-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -0700150#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value()
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200151
152class BoundsCheckSlowPathMIPS : public SlowPathCodeMIPS {
153 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000154 explicit BoundsCheckSlowPathMIPS(HBoundsCheck* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200155
156 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
157 LocationSummary* locations = instruction_->GetLocations();
158 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
159 __ Bind(GetEntryLabel());
160 if (instruction_->CanThrowIntoCatchBlock()) {
161 // Live registers will be restored in the catch block if caught.
162 SaveLiveRegisters(codegen, instruction_->GetLocations());
163 }
164 // We're moving two locations to locations that could overlap, so we need a parallel
165 // move resolver.
166 InvokeRuntimeCallingConvention calling_convention;
167 codegen->EmitParallelMoves(locations->InAt(0),
168 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
169 Primitive::kPrimInt,
170 locations->InAt(1),
171 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
172 Primitive::kPrimInt);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100173 uint32_t entry_point_offset = instruction_->AsBoundsCheck()->IsStringCharAt()
174 ? QUICK_ENTRY_POINT(pThrowStringBounds)
175 : QUICK_ENTRY_POINT(pThrowArrayBounds);
176 mips_codegen->InvokeRuntime(entry_point_offset,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200177 instruction_,
178 instruction_->GetDexPc(),
179 this,
180 IsDirectEntrypoint(kQuickThrowArrayBounds));
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100181 CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200182 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
183 }
184
185 bool IsFatal() const OVERRIDE { return true; }
186
187 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS"; }
188
189 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200190 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS);
191};
192
193class DivZeroCheckSlowPathMIPS : public SlowPathCodeMIPS {
194 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000195 explicit DivZeroCheckSlowPathMIPS(HDivZeroCheck* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200196
197 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
198 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
199 __ Bind(GetEntryLabel());
200 if (instruction_->CanThrowIntoCatchBlock()) {
201 // Live registers will be restored in the catch block if caught.
202 SaveLiveRegisters(codegen, instruction_->GetLocations());
203 }
204 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero),
205 instruction_,
206 instruction_->GetDexPc(),
207 this,
208 IsDirectEntrypoint(kQuickThrowDivZero));
209 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
210 }
211
212 bool IsFatal() const OVERRIDE { return true; }
213
214 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS"; }
215
216 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200217 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS);
218};
219
220class LoadClassSlowPathMIPS : public SlowPathCodeMIPS {
221 public:
222 LoadClassSlowPathMIPS(HLoadClass* cls,
223 HInstruction* at,
224 uint32_t dex_pc,
225 bool do_clinit)
David Srbecky9cd6d372016-02-09 15:24:47 +0000226 : SlowPathCodeMIPS(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200227 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
228 }
229
230 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
231 LocationSummary* locations = at_->GetLocations();
232 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
233
234 __ Bind(GetEntryLabel());
235 SaveLiveRegisters(codegen, locations);
236
237 InvokeRuntimeCallingConvention calling_convention;
238 __ LoadConst32(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
239
240 int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
241 : QUICK_ENTRY_POINT(pInitializeType);
242 bool direct = do_clinit_ ? IsDirectEntrypoint(kQuickInitializeStaticStorage)
243 : IsDirectEntrypoint(kQuickInitializeType);
244
245 mips_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this, direct);
246 if (do_clinit_) {
247 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
248 } else {
249 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
250 }
251
252 // Move the class to the desired location.
253 Location out = locations->Out();
254 if (out.IsValid()) {
255 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
256 Primitive::Type type = at_->GetType();
257 mips_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type);
258 }
259
260 RestoreLiveRegisters(codegen, locations);
261 __ B(GetExitLabel());
262 }
263
264 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS"; }
265
266 private:
267 // The class this slow path will load.
268 HLoadClass* const cls_;
269
270 // The instruction where this slow path is happening.
271 // (Might be the load class or an initialization check).
272 HInstruction* const at_;
273
274 // The dex PC of `at_`.
275 const uint32_t dex_pc_;
276
277 // Whether to initialize the class.
278 const bool do_clinit_;
279
280 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS);
281};
282
283class LoadStringSlowPathMIPS : public SlowPathCodeMIPS {
284 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000285 explicit LoadStringSlowPathMIPS(HLoadString* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200286
287 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
288 LocationSummary* locations = instruction_->GetLocations();
289 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
290 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
291
292 __ Bind(GetEntryLabel());
293 SaveLiveRegisters(codegen, locations);
294
295 InvokeRuntimeCallingConvention calling_convention;
David Srbecky9cd6d372016-02-09 15:24:47 +0000296 const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex();
297 __ LoadConst32(calling_convention.GetRegisterAt(0), string_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200298 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString),
299 instruction_,
300 instruction_->GetDexPc(),
301 this,
302 IsDirectEntrypoint(kQuickResolveString));
303 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
304 Primitive::Type type = instruction_->GetType();
305 mips_codegen->MoveLocation(locations->Out(),
306 calling_convention.GetReturnLocation(type),
307 type);
308
309 RestoreLiveRegisters(codegen, locations);
310 __ B(GetExitLabel());
311 }
312
313 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS"; }
314
315 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200316 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS);
317};
318
319class NullCheckSlowPathMIPS : public SlowPathCodeMIPS {
320 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000321 explicit NullCheckSlowPathMIPS(HNullCheck* instr) : SlowPathCodeMIPS(instr) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200322
323 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
324 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
325 __ Bind(GetEntryLabel());
326 if (instruction_->CanThrowIntoCatchBlock()) {
327 // Live registers will be restored in the catch block if caught.
328 SaveLiveRegisters(codegen, instruction_->GetLocations());
329 }
330 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer),
331 instruction_,
332 instruction_->GetDexPc(),
333 this,
334 IsDirectEntrypoint(kQuickThrowNullPointer));
335 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
336 }
337
338 bool IsFatal() const OVERRIDE { return true; }
339
340 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS"; }
341
342 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200343 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS);
344};
345
346class SuspendCheckSlowPathMIPS : public SlowPathCodeMIPS {
347 public:
348 SuspendCheckSlowPathMIPS(HSuspendCheck* instruction, HBasicBlock* successor)
David Srbecky9cd6d372016-02-09 15:24:47 +0000349 : SlowPathCodeMIPS(instruction), successor_(successor) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200350
351 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
352 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
353 __ Bind(GetEntryLabel());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200354 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend),
355 instruction_,
356 instruction_->GetDexPc(),
357 this,
358 IsDirectEntrypoint(kQuickTestSuspend));
359 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200360 if (successor_ == nullptr) {
361 __ B(GetReturnLabel());
362 } else {
363 __ B(mips_codegen->GetLabelOf(successor_));
364 }
365 }
366
367 MipsLabel* GetReturnLabel() {
368 DCHECK(successor_ == nullptr);
369 return &return_label_;
370 }
371
372 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS"; }
373
374 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200375 // If not null, the block to branch to after the suspend check.
376 HBasicBlock* const successor_;
377
378 // If `successor_` is null, the label to branch to after the suspend check.
379 MipsLabel return_label_;
380
381 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS);
382};
383
384class TypeCheckSlowPathMIPS : public SlowPathCodeMIPS {
385 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000386 explicit TypeCheckSlowPathMIPS(HInstruction* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200387
388 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
389 LocationSummary* locations = instruction_->GetLocations();
390 Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) : locations->Out();
391 uint32_t dex_pc = instruction_->GetDexPc();
392 DCHECK(instruction_->IsCheckCast()
393 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
394 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
395
396 __ Bind(GetEntryLabel());
397 SaveLiveRegisters(codegen, locations);
398
399 // We're moving two locations to locations that could overlap, so we need a parallel
400 // move resolver.
401 InvokeRuntimeCallingConvention calling_convention;
402 codegen->EmitParallelMoves(locations->InAt(1),
403 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
404 Primitive::kPrimNot,
405 object_class,
406 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
407 Primitive::kPrimNot);
408
409 if (instruction_->IsInstanceOf()) {
410 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial),
411 instruction_,
412 dex_pc,
413 this,
414 IsDirectEntrypoint(kQuickInstanceofNonTrivial));
Roland Levillain888d0672015-11-23 18:53:50 +0000415 CheckEntrypointTypes<
Andreas Gampe67409972016-07-19 22:34:53 -0700416 kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200417 Primitive::Type ret_type = instruction_->GetType();
418 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
419 mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200420 } else {
421 DCHECK(instruction_->IsCheckCast());
422 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast),
423 instruction_,
424 dex_pc,
425 this,
426 IsDirectEntrypoint(kQuickCheckCast));
427 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
428 }
429
430 RestoreLiveRegisters(codegen, locations);
431 __ B(GetExitLabel());
432 }
433
434 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; }
435
436 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200437 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS);
438};
439
440class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS {
441 public:
Aart Bik42249c32016-01-07 15:33:50 -0800442 explicit DeoptimizationSlowPathMIPS(HDeoptimize* instruction)
David Srbecky9cd6d372016-02-09 15:24:47 +0000443 : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200444
445 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Aart Bik42249c32016-01-07 15:33:50 -0800446 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200447 __ Bind(GetEntryLabel());
448 SaveLiveRegisters(codegen, instruction_->GetLocations());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200449 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize),
450 instruction_,
Aart Bik42249c32016-01-07 15:33:50 -0800451 instruction_->GetDexPc(),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200452 this,
453 IsDirectEntrypoint(kQuickDeoptimize));
Roland Levillain888d0672015-11-23 18:53:50 +0000454 CheckEntrypointTypes<kQuickDeoptimize, void, void>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200455 }
456
457 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; }
458
459 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200460 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS);
461};
462
463CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph,
464 const MipsInstructionSetFeatures& isa_features,
465 const CompilerOptions& compiler_options,
466 OptimizingCompilerStats* stats)
467 : CodeGenerator(graph,
468 kNumberOfCoreRegisters,
469 kNumberOfFRegisters,
470 kNumberOfRegisterPairs,
471 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
472 arraysize(kCoreCalleeSaves)),
473 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
474 arraysize(kFpuCalleeSaves)),
475 compiler_options,
476 stats),
477 block_labels_(nullptr),
478 location_builder_(graph, this),
479 instruction_visitor_(graph, this),
480 move_resolver_(graph->GetArena(), this),
Vladimir Marko93205e32016-04-13 11:59:46 +0100481 assembler_(graph->GetArena(), &isa_features),
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700482 isa_features_(isa_features),
Alexey Frunze06a46c42016-07-19 15:00:40 -0700483 uint32_literals_(std::less<uint32_t>(),
484 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700485 method_patches_(MethodReferenceComparator(),
486 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
487 call_patches_(MethodReferenceComparator(),
488 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunze06a46c42016-07-19 15:00:40 -0700489 pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
490 boot_image_string_patches_(StringReferenceValueComparator(),
491 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
492 pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
493 boot_image_type_patches_(TypeReferenceValueComparator(),
494 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
495 pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
496 boot_image_address_patches_(std::less<uint32_t>(),
497 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
498 clobbered_ra_(false) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200499 // Save RA (containing the return address) to mimic Quick.
500 AddAllocatedRegister(Location::RegisterLocation(RA));
501}
502
503#undef __
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100504// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
505#define __ down_cast<MipsAssembler*>(GetAssembler())-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -0700506#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value()
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200507
508void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) {
509 // Ensure that we fix up branches.
510 __ FinalizeCode();
511
512 // Adjust native pc offsets in stack maps.
513 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
514 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
515 uint32_t new_position = __ GetAdjustedPosition(old_position);
516 DCHECK_GE(new_position, old_position);
517 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
518 }
519
520 // Adjust pc offsets for the disassembly information.
521 if (disasm_info_ != nullptr) {
522 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
523 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
524 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
525 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
526 it.second.start = __ GetAdjustedPosition(it.second.start);
527 it.second.end = __ GetAdjustedPosition(it.second.end);
528 }
529 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
530 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
531 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
532 }
533 }
534
535 CodeGenerator::Finalize(allocator);
536}
537
538MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const {
539 return codegen_->GetAssembler();
540}
541
542void ParallelMoveResolverMIPS::EmitMove(size_t index) {
543 DCHECK_LT(index, moves_.size());
544 MoveOperands* move = moves_[index];
545 codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType());
546}
547
548void ParallelMoveResolverMIPS::EmitSwap(size_t index) {
549 DCHECK_LT(index, moves_.size());
550 MoveOperands* move = moves_[index];
551 Primitive::Type type = move->GetType();
552 Location loc1 = move->GetDestination();
553 Location loc2 = move->GetSource();
554
555 DCHECK(!loc1.IsConstant());
556 DCHECK(!loc2.IsConstant());
557
558 if (loc1.Equals(loc2)) {
559 return;
560 }
561
562 if (loc1.IsRegister() && loc2.IsRegister()) {
563 // Swap 2 GPRs.
564 Register r1 = loc1.AsRegister<Register>();
565 Register r2 = loc2.AsRegister<Register>();
566 __ Move(TMP, r2);
567 __ Move(r2, r1);
568 __ Move(r1, TMP);
569 } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) {
570 FRegister f1 = loc1.AsFpuRegister<FRegister>();
571 FRegister f2 = loc2.AsFpuRegister<FRegister>();
572 if (type == Primitive::kPrimFloat) {
573 __ MovS(FTMP, f2);
574 __ MovS(f2, f1);
575 __ MovS(f1, FTMP);
576 } else {
577 DCHECK_EQ(type, Primitive::kPrimDouble);
578 __ MovD(FTMP, f2);
579 __ MovD(f2, f1);
580 __ MovD(f1, FTMP);
581 }
582 } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) ||
583 (loc1.IsFpuRegister() && loc2.IsRegister())) {
584 // Swap FPR and GPR.
585 DCHECK_EQ(type, Primitive::kPrimFloat); // Can only swap a float.
586 FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
587 : loc2.AsFpuRegister<FRegister>();
588 Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>()
589 : loc2.AsRegister<Register>();
590 __ Move(TMP, r2);
591 __ Mfc1(r2, f1);
592 __ Mtc1(TMP, f1);
593 } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) {
594 // Swap 2 GPR register pairs.
595 Register r1 = loc1.AsRegisterPairLow<Register>();
596 Register r2 = loc2.AsRegisterPairLow<Register>();
597 __ Move(TMP, r2);
598 __ Move(r2, r1);
599 __ Move(r1, TMP);
600 r1 = loc1.AsRegisterPairHigh<Register>();
601 r2 = loc2.AsRegisterPairHigh<Register>();
602 __ Move(TMP, r2);
603 __ Move(r2, r1);
604 __ Move(r1, TMP);
605 } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) ||
606 (loc1.IsFpuRegister() && loc2.IsRegisterPair())) {
607 // Swap FPR and GPR register pair.
608 DCHECK_EQ(type, Primitive::kPrimDouble);
609 FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
610 : loc2.AsFpuRegister<FRegister>();
611 Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>()
612 : loc2.AsRegisterPairLow<Register>();
613 Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>()
614 : loc2.AsRegisterPairHigh<Register>();
615 // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and
616 // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR
617 // unpredictable and the following mfch1 will fail.
618 __ Mfc1(TMP, f1);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800619 __ MoveFromFpuHigh(AT, f1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200620 __ Mtc1(r2_l, f1);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800621 __ MoveToFpuHigh(r2_h, f1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200622 __ Move(r2_l, TMP);
623 __ Move(r2_h, AT);
624 } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) {
625 Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false);
626 } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) {
627 Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true);
David Brazdilcc0f3112016-01-28 17:14:52 +0000628 } else if ((loc1.IsRegister() && loc2.IsStackSlot()) ||
629 (loc1.IsStackSlot() && loc2.IsRegister())) {
630 Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>()
631 : loc2.AsRegister<Register>();
632 intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex()
633 : loc2.GetStackIndex();
634 __ Move(TMP, reg);
635 __ LoadFromOffset(kLoadWord, reg, SP, offset);
636 __ StoreToOffset(kStoreWord, TMP, SP, offset);
637 } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) ||
638 (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) {
639 Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>()
640 : loc2.AsRegisterPairLow<Register>();
641 Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>()
642 : loc2.AsRegisterPairHigh<Register>();
643 intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex()
644 : loc2.GetStackIndex();
645 intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize)
646 : loc2.GetHighStackIndex(kMipsWordSize);
647 __ Move(TMP, reg_l);
David Brazdilcc0f3112016-01-28 17:14:52 +0000648 __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l);
David Brazdilcc0f3112016-01-28 17:14:52 +0000649 __ StoreToOffset(kStoreWord, TMP, SP, offset_l);
David Brazdil04d3e872016-01-29 09:50:09 +0000650 __ Move(TMP, reg_h);
651 __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h);
652 __ StoreToOffset(kStoreWord, TMP, SP, offset_h);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200653 } else {
654 LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported";
655 }
656}
657
658void ParallelMoveResolverMIPS::RestoreScratch(int reg) {
659 __ Pop(static_cast<Register>(reg));
660}
661
662void ParallelMoveResolverMIPS::SpillScratch(int reg) {
663 __ Push(static_cast<Register>(reg));
664}
665
666void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) {
667 // Allocate a scratch register other than TMP, if available.
668 // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be
669 // automatically unspilled when the scratch scope object is destroyed).
670 ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters());
671 // If V0 spills onto the stack, SP-relative offsets need to be adjusted.
672 int stack_offset = ensure_scratch.IsSpilled() ? kMipsWordSize : 0;
673 for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) {
674 __ LoadFromOffset(kLoadWord,
675 Register(ensure_scratch.GetRegister()),
676 SP,
677 index1 + stack_offset);
678 __ LoadFromOffset(kLoadWord,
679 TMP,
680 SP,
681 index2 + stack_offset);
682 __ StoreToOffset(kStoreWord,
683 Register(ensure_scratch.GetRegister()),
684 SP,
685 index2 + stack_offset);
686 __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset);
687 }
688}
689
Alexey Frunze73296a72016-06-03 22:51:46 -0700690void CodeGeneratorMIPS::ComputeSpillMask() {
691 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
692 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
693 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
694 // If there're FPU callee-saved registers and there's an odd number of GPR callee-saved
695 // registers, include the ZERO register to force alignment of FPU callee-saved registers
696 // within the stack frame.
697 if ((fpu_spill_mask_ != 0) && (POPCOUNT(core_spill_mask_) % 2 != 0)) {
698 core_spill_mask_ |= (1 << ZERO);
699 }
Alexey Frunze06a46c42016-07-19 15:00:40 -0700700 // If RA is clobbered by PC-relative operations on R2 and it's the only spilled register
701 // (this can happen in leaf methods), artificially spill the ZERO register in order to
702 // force explicit saving and restoring of RA. RA isn't saved/restored when it's the only
703 // spilled register.
704 // TODO: Can this be improved? It causes creation of a stack frame (while RA might be
705 // saved in an unused temporary register) and saving of RA and the current method pointer
706 // in the frame.
707 if (clobbered_ra_ && core_spill_mask_ == (1u << RA) && fpu_spill_mask_ == 0) {
708 core_spill_mask_ |= (1 << ZERO);
709 }
Alexey Frunze73296a72016-06-03 22:51:46 -0700710}
711
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200712static dwarf::Reg DWARFReg(Register reg) {
713 return dwarf::Reg::MipsCore(static_cast<int>(reg));
714}
715
716// TODO: mapping of floating-point registers to DWARF.
717
718void CodeGeneratorMIPS::GenerateFrameEntry() {
719 __ Bind(&frame_entry_label_);
720
721 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips) || !IsLeafMethod();
722
723 if (do_overflow_check) {
724 __ LoadFromOffset(kLoadWord,
725 ZERO,
726 SP,
727 -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips)));
728 RecordPcInfo(nullptr, 0);
729 }
730
731 if (HasEmptyFrame()) {
732 return;
733 }
734
735 // Make sure the frame size isn't unreasonably large.
736 if (GetFrameSize() > GetStackOverflowReservedBytes(kMips)) {
737 LOG(FATAL) << "Stack frame larger than " << GetStackOverflowReservedBytes(kMips) << " bytes";
738 }
739
740 // Spill callee-saved registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200741
Alexey Frunze73296a72016-06-03 22:51:46 -0700742 uint32_t ofs = GetFrameSize();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200743 __ IncreaseFrameSize(ofs);
744
Alexey Frunze73296a72016-06-03 22:51:46 -0700745 for (uint32_t mask = core_spill_mask_; mask != 0; ) {
746 Register reg = static_cast<Register>(MostSignificantBit(mask));
747 mask ^= 1u << reg;
748 ofs -= kMipsWordSize;
749 // The ZERO register is only included for alignment.
750 if (reg != ZERO) {
751 __ StoreToOffset(kStoreWord, reg, SP, ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200752 __ cfi().RelOffset(DWARFReg(reg), ofs);
753 }
754 }
755
Alexey Frunze73296a72016-06-03 22:51:46 -0700756 for (uint32_t mask = fpu_spill_mask_; mask != 0; ) {
757 FRegister reg = static_cast<FRegister>(MostSignificantBit(mask));
758 mask ^= 1u << reg;
759 ofs -= kMipsDoublewordSize;
760 __ StoreDToOffset(reg, SP, ofs);
761 // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200762 }
763
Alexey Frunze73296a72016-06-03 22:51:46 -0700764 // Store the current method pointer.
765 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, kCurrentMethodStackOffset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200766}
767
768void CodeGeneratorMIPS::GenerateFrameExit() {
769 __ cfi().RememberState();
770
771 if (!HasEmptyFrame()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200772 // Restore callee-saved registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200773
Alexey Frunze73296a72016-06-03 22:51:46 -0700774 // For better instruction scheduling restore RA before other registers.
775 uint32_t ofs = GetFrameSize();
776 for (uint32_t mask = core_spill_mask_; mask != 0; ) {
777 Register reg = static_cast<Register>(MostSignificantBit(mask));
778 mask ^= 1u << reg;
779 ofs -= kMipsWordSize;
780 // The ZERO register is only included for alignment.
781 if (reg != ZERO) {
782 __ LoadFromOffset(kLoadWord, reg, SP, ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200783 __ cfi().Restore(DWARFReg(reg));
784 }
785 }
786
Alexey Frunze73296a72016-06-03 22:51:46 -0700787 for (uint32_t mask = fpu_spill_mask_; mask != 0; ) {
788 FRegister reg = static_cast<FRegister>(MostSignificantBit(mask));
789 mask ^= 1u << reg;
790 ofs -= kMipsDoublewordSize;
791 __ LoadDFromOffset(reg, SP, ofs);
792 // TODO: __ cfi().Restore(DWARFReg(reg));
793 }
794
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700795 size_t frame_size = GetFrameSize();
796 // Adjust the stack pointer in the delay slot if doing so doesn't break CFI.
797 bool exchange = IsInt<16>(static_cast<int32_t>(frame_size));
798 bool reordering = __ SetReorder(false);
799 if (exchange) {
800 __ Jr(RA);
801 __ DecreaseFrameSize(frame_size); // Single instruction in delay slot.
802 } else {
803 __ DecreaseFrameSize(frame_size);
804 __ Jr(RA);
805 __ Nop(); // In delay slot.
806 }
807 __ SetReorder(reordering);
808 } else {
809 __ Jr(RA);
810 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200811 }
812
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200813 __ cfi().RestoreState();
814 __ cfi().DefCFAOffset(GetFrameSize());
815}
816
817void CodeGeneratorMIPS::Bind(HBasicBlock* block) {
818 __ Bind(GetLabelOf(block));
819}
820
821void CodeGeneratorMIPS::MoveLocation(Location dst, Location src, Primitive::Type dst_type) {
822 if (src.Equals(dst)) {
823 return;
824 }
825
826 if (src.IsConstant()) {
827 MoveConstant(dst, src.GetConstant());
828 } else {
829 if (Primitive::Is64BitType(dst_type)) {
830 Move64(dst, src);
831 } else {
832 Move32(dst, src);
833 }
834 }
835}
836
837void CodeGeneratorMIPS::Move32(Location destination, Location source) {
838 if (source.Equals(destination)) {
839 return;
840 }
841
842 if (destination.IsRegister()) {
843 if (source.IsRegister()) {
844 __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>());
845 } else if (source.IsFpuRegister()) {
846 __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>());
847 } else {
848 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
849 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
850 }
851 } else if (destination.IsFpuRegister()) {
852 if (source.IsRegister()) {
853 __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>());
854 } else if (source.IsFpuRegister()) {
855 __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>());
856 } else {
857 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
858 __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
859 }
860 } else {
861 DCHECK(destination.IsStackSlot()) << destination;
862 if (source.IsRegister()) {
863 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
864 } else if (source.IsFpuRegister()) {
865 __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex());
866 } else {
867 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
868 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
869 __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex());
870 }
871 }
872}
873
874void CodeGeneratorMIPS::Move64(Location destination, Location source) {
875 if (source.Equals(destination)) {
876 return;
877 }
878
879 if (destination.IsRegisterPair()) {
880 if (source.IsRegisterPair()) {
881 __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
882 __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
883 } else if (source.IsFpuRegister()) {
884 Register dst_high = destination.AsRegisterPairHigh<Register>();
885 Register dst_low = destination.AsRegisterPairLow<Register>();
886 FRegister src = source.AsFpuRegister<FRegister>();
887 __ Mfc1(dst_low, src);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800888 __ MoveFromFpuHigh(dst_high, src);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200889 } else {
890 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
891 int32_t off = source.GetStackIndex();
892 Register r = destination.AsRegisterPairLow<Register>();
893 __ LoadFromOffset(kLoadDoubleword, r, SP, off);
894 }
895 } else if (destination.IsFpuRegister()) {
896 if (source.IsRegisterPair()) {
897 FRegister dst = destination.AsFpuRegister<FRegister>();
898 Register src_high = source.AsRegisterPairHigh<Register>();
899 Register src_low = source.AsRegisterPairLow<Register>();
900 __ Mtc1(src_low, dst);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800901 __ MoveToFpuHigh(src_high, dst);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200902 } else if (source.IsFpuRegister()) {
903 __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>());
904 } else {
905 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
906 __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
907 }
908 } else {
909 DCHECK(destination.IsDoubleStackSlot()) << destination;
910 int32_t off = destination.GetStackIndex();
911 if (source.IsRegisterPair()) {
912 __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, off);
913 } else if (source.IsFpuRegister()) {
914 __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, off);
915 } else {
916 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
917 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
918 __ StoreToOffset(kStoreWord, TMP, SP, off);
919 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4);
920 __ StoreToOffset(kStoreWord, TMP, SP, off + 4);
921 }
922 }
923}
924
925void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) {
926 if (c->IsIntConstant() || c->IsNullConstant()) {
927 // Move 32 bit constant.
928 int32_t value = GetInt32ValueOf(c);
929 if (destination.IsRegister()) {
930 Register dst = destination.AsRegister<Register>();
931 __ LoadConst32(dst, value);
932 } else {
933 DCHECK(destination.IsStackSlot())
934 << "Cannot move " << c->DebugName() << " to " << destination;
935 __ StoreConst32ToOffset(value, SP, destination.GetStackIndex(), TMP);
936 }
937 } else if (c->IsLongConstant()) {
938 // Move 64 bit constant.
939 int64_t value = GetInt64ValueOf(c);
940 if (destination.IsRegisterPair()) {
941 Register r_h = destination.AsRegisterPairHigh<Register>();
942 Register r_l = destination.AsRegisterPairLow<Register>();
943 __ LoadConst64(r_h, r_l, value);
944 } else {
945 DCHECK(destination.IsDoubleStackSlot())
946 << "Cannot move " << c->DebugName() << " to " << destination;
947 __ StoreConst64ToOffset(value, SP, destination.GetStackIndex(), TMP);
948 }
949 } else if (c->IsFloatConstant()) {
950 // Move 32 bit float constant.
951 int32_t value = GetInt32ValueOf(c);
952 if (destination.IsFpuRegister()) {
953 __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP);
954 } else {
955 DCHECK(destination.IsStackSlot())
956 << "Cannot move " << c->DebugName() << " to " << destination;
957 __ StoreConst32ToOffset(value, SP, destination.GetStackIndex(), TMP);
958 }
959 } else {
960 // Move 64 bit double constant.
961 DCHECK(c->IsDoubleConstant()) << c->DebugName();
962 int64_t value = GetInt64ValueOf(c);
963 if (destination.IsFpuRegister()) {
964 FRegister fd = destination.AsFpuRegister<FRegister>();
965 __ LoadDConst64(fd, value, TMP);
966 } else {
967 DCHECK(destination.IsDoubleStackSlot())
968 << "Cannot move " << c->DebugName() << " to " << destination;
969 __ StoreConst64ToOffset(value, SP, destination.GetStackIndex(), TMP);
970 }
971 }
972}
973
974void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) {
975 DCHECK(destination.IsRegister());
976 Register dst = destination.AsRegister<Register>();
977 __ LoadConst32(dst, value);
978}
979
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200980void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) {
981 if (location.IsRegister()) {
982 locations->AddTemp(location);
Alexey Frunzec9e94f32015-10-26 16:11:39 -0700983 } else if (location.IsRegisterPair()) {
984 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>()));
985 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>()));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200986 } else {
987 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
988 }
989}
990
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700991void CodeGeneratorMIPS::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) {
992 DCHECK(linker_patches->empty());
993 size_t size =
994 method_patches_.size() +
995 call_patches_.size() +
Alexey Frunze06a46c42016-07-19 15:00:40 -0700996 pc_relative_dex_cache_patches_.size() +
997 pc_relative_string_patches_.size() +
998 pc_relative_type_patches_.size() +
999 boot_image_string_patches_.size() +
1000 boot_image_type_patches_.size() +
1001 boot_image_address_patches_.size();
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001002 linker_patches->reserve(size);
1003 for (const auto& entry : method_patches_) {
1004 const MethodReference& target_method = entry.first;
1005 Literal* literal = entry.second;
1006 DCHECK(literal->GetLabel()->IsBound());
1007 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1008 linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset,
1009 target_method.dex_file,
1010 target_method.dex_method_index));
1011 }
1012 for (const auto& entry : call_patches_) {
1013 const MethodReference& target_method = entry.first;
1014 Literal* literal = entry.second;
1015 DCHECK(literal->GetLabel()->IsBound());
1016 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1017 linker_patches->push_back(LinkerPatch::CodePatch(literal_offset,
1018 target_method.dex_file,
1019 target_method.dex_method_index));
1020 }
1021 for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) {
1022 const DexFile& dex_file = info.target_dex_file;
1023 size_t base_element_offset = info.offset_or_index;
1024 DCHECK(info.high_label.IsBound());
1025 uint32_t high_offset = __ GetLabelLocation(&info.high_label);
1026 DCHECK(info.pc_rel_label.IsBound());
1027 uint32_t pc_rel_offset = __ GetLabelLocation(&info.pc_rel_label);
1028 linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(high_offset,
1029 &dex_file,
1030 pc_rel_offset,
1031 base_element_offset));
1032 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07001033 for (const PcRelativePatchInfo& info : pc_relative_string_patches_) {
1034 const DexFile& dex_file = info.target_dex_file;
1035 size_t string_index = info.offset_or_index;
1036 DCHECK(info.high_label.IsBound());
1037 uint32_t high_offset = __ GetLabelLocation(&info.high_label);
1038 // On R2 we use HMipsComputeBaseMethodAddress and patch relative to
1039 // the assembler's base label used for PC-relative literals.
1040 uint32_t pc_rel_offset = info.pc_rel_label.IsBound()
1041 ? __ GetLabelLocation(&info.pc_rel_label)
1042 : __ GetPcRelBaseLabelLocation();
1043 linker_patches->push_back(LinkerPatch::RelativeStringPatch(high_offset,
1044 &dex_file,
1045 pc_rel_offset,
1046 string_index));
1047 }
1048 for (const PcRelativePatchInfo& info : pc_relative_type_patches_) {
1049 const DexFile& dex_file = info.target_dex_file;
1050 size_t type_index = info.offset_or_index;
1051 DCHECK(info.high_label.IsBound());
1052 uint32_t high_offset = __ GetLabelLocation(&info.high_label);
1053 // On R2 we use HMipsComputeBaseMethodAddress and patch relative to
1054 // the assembler's base label used for PC-relative literals.
1055 uint32_t pc_rel_offset = info.pc_rel_label.IsBound()
1056 ? __ GetLabelLocation(&info.pc_rel_label)
1057 : __ GetPcRelBaseLabelLocation();
1058 linker_patches->push_back(LinkerPatch::RelativeTypePatch(high_offset,
1059 &dex_file,
1060 pc_rel_offset,
1061 type_index));
1062 }
1063 for (const auto& entry : boot_image_string_patches_) {
1064 const StringReference& target_string = entry.first;
1065 Literal* literal = entry.second;
1066 DCHECK(literal->GetLabel()->IsBound());
1067 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1068 linker_patches->push_back(LinkerPatch::StringPatch(literal_offset,
1069 target_string.dex_file,
1070 target_string.string_index));
1071 }
1072 for (const auto& entry : boot_image_type_patches_) {
1073 const TypeReference& target_type = entry.first;
1074 Literal* literal = entry.second;
1075 DCHECK(literal->GetLabel()->IsBound());
1076 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1077 linker_patches->push_back(LinkerPatch::TypePatch(literal_offset,
1078 target_type.dex_file,
1079 target_type.type_index));
1080 }
1081 for (const auto& entry : boot_image_address_patches_) {
1082 DCHECK(GetCompilerOptions().GetIncludePatchInformation());
1083 Literal* literal = entry.second;
1084 DCHECK(literal->GetLabel()->IsBound());
1085 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1086 linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset));
1087 }
1088}
1089
1090CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeStringPatch(
1091 const DexFile& dex_file, uint32_t string_index) {
1092 return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_);
1093}
1094
1095CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeTypePatch(
1096 const DexFile& dex_file, uint32_t type_index) {
1097 return NewPcRelativePatch(dex_file, type_index, &pc_relative_type_patches_);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001098}
1099
1100CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeDexCacheArrayPatch(
1101 const DexFile& dex_file, uint32_t element_offset) {
1102 return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_);
1103}
1104
1105CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativePatch(
1106 const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) {
1107 patches->emplace_back(dex_file, offset_or_index);
1108 return &patches->back();
1109}
1110
Alexey Frunze06a46c42016-07-19 15:00:40 -07001111Literal* CodeGeneratorMIPS::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) {
1112 return map->GetOrCreate(
1113 value,
1114 [this, value]() { return __ NewLiteral<uint32_t>(value); });
1115}
1116
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001117Literal* CodeGeneratorMIPS::DeduplicateMethodLiteral(MethodReference target_method,
1118 MethodToLiteralMap* map) {
1119 return map->GetOrCreate(
1120 target_method,
1121 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1122}
1123
1124Literal* CodeGeneratorMIPS::DeduplicateMethodAddressLiteral(MethodReference target_method) {
1125 return DeduplicateMethodLiteral(target_method, &method_patches_);
1126}
1127
1128Literal* CodeGeneratorMIPS::DeduplicateMethodCodeLiteral(MethodReference target_method) {
1129 return DeduplicateMethodLiteral(target_method, &call_patches_);
1130}
1131
Alexey Frunze06a46c42016-07-19 15:00:40 -07001132Literal* CodeGeneratorMIPS::DeduplicateBootImageStringLiteral(const DexFile& dex_file,
1133 uint32_t string_index) {
1134 return boot_image_string_patches_.GetOrCreate(
1135 StringReference(&dex_file, string_index),
1136 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1137}
1138
1139Literal* CodeGeneratorMIPS::DeduplicateBootImageTypeLiteral(const DexFile& dex_file,
1140 uint32_t type_index) {
1141 return boot_image_type_patches_.GetOrCreate(
1142 TypeReference(&dex_file, type_index),
1143 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1144}
1145
1146Literal* CodeGeneratorMIPS::DeduplicateBootImageAddressLiteral(uint32_t address) {
1147 bool needs_patch = GetCompilerOptions().GetIncludePatchInformation();
1148 Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_;
1149 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map);
1150}
1151
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001152void CodeGeneratorMIPS::MarkGCCard(Register object, Register value) {
1153 MipsLabel done;
1154 Register card = AT;
1155 Register temp = TMP;
1156 __ Beqz(value, &done);
1157 __ LoadFromOffset(kLoadWord,
1158 card,
1159 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001160 Thread::CardTableOffset<kMipsPointerSize>().Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001161 __ Srl(temp, object, gc::accounting::CardTable::kCardShift);
1162 __ Addu(temp, card, temp);
1163 __ Sb(card, temp, 0);
1164 __ Bind(&done);
1165}
1166
David Brazdil58282f42016-01-14 12:45:10 +00001167void CodeGeneratorMIPS::SetupBlockedRegisters() const {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001168 // Don't allocate the dalvik style register pair passing.
1169 blocked_register_pairs_[A1_A2] = true;
1170
1171 // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated.
1172 blocked_core_registers_[ZERO] = true;
1173 blocked_core_registers_[K0] = true;
1174 blocked_core_registers_[K1] = true;
1175 blocked_core_registers_[GP] = true;
1176 blocked_core_registers_[SP] = true;
1177 blocked_core_registers_[RA] = true;
1178
1179 // AT and TMP(T8) are used as temporary/scratch registers
1180 // (similar to how AT is used by MIPS assemblers).
1181 blocked_core_registers_[AT] = true;
1182 blocked_core_registers_[TMP] = true;
1183 blocked_fpu_registers_[FTMP] = true;
1184
1185 // Reserve suspend and thread registers.
1186 blocked_core_registers_[S0] = true;
1187 blocked_core_registers_[TR] = true;
1188
1189 // Reserve T9 for function calls
1190 blocked_core_registers_[T9] = true;
1191
1192 // Reserve odd-numbered FPU registers.
1193 for (size_t i = 1; i < kNumberOfFRegisters; i += 2) {
1194 blocked_fpu_registers_[i] = true;
1195 }
1196
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02001197 if (GetGraph()->IsDebuggable()) {
1198 // Stubs do not save callee-save floating point registers. If the graph
1199 // is debuggable, we need to deal with these registers differently. For
1200 // now, just block them.
1201 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
1202 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
1203 }
1204 }
1205
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001206 UpdateBlockedPairRegisters();
1207}
1208
1209void CodeGeneratorMIPS::UpdateBlockedPairRegisters() const {
1210 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
1211 MipsManagedRegister current =
1212 MipsManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
1213 if (blocked_core_registers_[current.AsRegisterPairLow()]
1214 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
1215 blocked_register_pairs_[i] = true;
1216 }
1217 }
1218}
1219
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001220size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
1221 __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index);
1222 return kMipsWordSize;
1223}
1224
1225size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
1226 __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index);
1227 return kMipsWordSize;
1228}
1229
1230size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1231 __ StoreDToOffset(FRegister(reg_id), SP, stack_index);
1232 return kMipsDoublewordSize;
1233}
1234
1235size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1236 __ LoadDFromOffset(FRegister(reg_id), SP, stack_index);
1237 return kMipsDoublewordSize;
1238}
1239
1240void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const {
Vladimir Marko623a7a22016-02-02 18:14:52 +00001241 stream << Register(reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001242}
1243
1244void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Vladimir Marko623a7a22016-02-02 18:14:52 +00001245 stream << FRegister(reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001246}
1247
1248void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint,
1249 HInstruction* instruction,
1250 uint32_t dex_pc,
1251 SlowPathCode* slow_path) {
Andreas Gampe542451c2016-07-26 09:02:02 -07001252 InvokeRuntime(GetThreadOffset<kMipsPointerSize>(entrypoint).Int32Value(),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001253 instruction,
1254 dex_pc,
1255 slow_path,
1256 IsDirectEntrypoint(entrypoint));
1257}
1258
1259constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16;
1260
1261void CodeGeneratorMIPS::InvokeRuntime(int32_t entry_point_offset,
1262 HInstruction* instruction,
1263 uint32_t dex_pc,
1264 SlowPathCode* slow_path,
1265 bool is_direct_entrypoint) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001266 bool reordering = __ SetReorder(false);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001267 __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset);
1268 __ Jalr(T9);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001269 if (is_direct_entrypoint) {
1270 // Reserve argument space on stack (for $a0-$a3) for
1271 // entrypoints that directly reference native implementations.
1272 // Called function may use this space to store $a0-$a3 regs.
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001273 __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001274 __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001275 } else {
1276 __ Nop(); // In delay slot.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001277 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001278 __ SetReorder(reordering);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001279 RecordPcInfo(instruction, dex_pc, slow_path);
1280}
1281
1282void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path,
1283 Register class_reg) {
1284 __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value());
1285 __ LoadConst32(AT, mirror::Class::kStatusInitialized);
1286 __ Blt(TMP, AT, slow_path->GetEntryLabel());
1287 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
1288 __ Sync(0);
1289 __ Bind(slow_path->GetExitLabel());
1290}
1291
1292void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) {
1293 __ Sync(0); // Only stype 0 is supported.
1294}
1295
1296void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction,
1297 HBasicBlock* successor) {
1298 SuspendCheckSlowPathMIPS* slow_path =
1299 new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS(instruction, successor);
1300 codegen_->AddSlowPath(slow_path);
1301
1302 __ LoadFromOffset(kLoadUnsignedHalfword,
1303 TMP,
1304 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001305 Thread::ThreadFlagsOffset<kMipsPointerSize>().Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001306 if (successor == nullptr) {
1307 __ Bnez(TMP, slow_path->GetEntryLabel());
1308 __ Bind(slow_path->GetReturnLabel());
1309 } else {
1310 __ Beqz(TMP, codegen_->GetLabelOf(successor));
1311 __ B(slow_path->GetEntryLabel());
1312 // slow_path will return to GetLabelOf(successor).
1313 }
1314}
1315
1316InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph,
1317 CodeGeneratorMIPS* codegen)
Aart Bik42249c32016-01-07 15:33:50 -08001318 : InstructionCodeGenerator(graph, codegen),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001319 assembler_(codegen->GetAssembler()),
1320 codegen_(codegen) {}
1321
1322void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) {
1323 DCHECK_EQ(instruction->InputCount(), 2U);
1324 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1325 Primitive::Type type = instruction->GetResultType();
1326 switch (type) {
1327 case Primitive::kPrimInt: {
1328 locations->SetInAt(0, Location::RequiresRegister());
1329 HInstruction* right = instruction->InputAt(1);
1330 bool can_use_imm = false;
1331 if (right->IsConstant()) {
1332 int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant());
1333 if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) {
1334 can_use_imm = IsUint<16>(imm);
1335 } else if (instruction->IsAdd()) {
1336 can_use_imm = IsInt<16>(imm);
1337 } else {
1338 DCHECK(instruction->IsSub());
1339 can_use_imm = IsInt<16>(-imm);
1340 }
1341 }
1342 if (can_use_imm)
1343 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1344 else
1345 locations->SetInAt(1, Location::RequiresRegister());
1346 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1347 break;
1348 }
1349
1350 case Primitive::kPrimLong: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001351 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001352 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1353 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001354 break;
1355 }
1356
1357 case Primitive::kPrimFloat:
1358 case Primitive::kPrimDouble:
1359 DCHECK(instruction->IsAdd() || instruction->IsSub());
1360 locations->SetInAt(0, Location::RequiresFpuRegister());
1361 locations->SetInAt(1, Location::RequiresFpuRegister());
1362 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1363 break;
1364
1365 default:
1366 LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type;
1367 }
1368}
1369
1370void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) {
1371 Primitive::Type type = instruction->GetType();
1372 LocationSummary* locations = instruction->GetLocations();
1373
1374 switch (type) {
1375 case Primitive::kPrimInt: {
1376 Register dst = locations->Out().AsRegister<Register>();
1377 Register lhs = locations->InAt(0).AsRegister<Register>();
1378 Location rhs_location = locations->InAt(1);
1379
1380 Register rhs_reg = ZERO;
1381 int32_t rhs_imm = 0;
1382 bool use_imm = rhs_location.IsConstant();
1383 if (use_imm) {
1384 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
1385 } else {
1386 rhs_reg = rhs_location.AsRegister<Register>();
1387 }
1388
1389 if (instruction->IsAnd()) {
1390 if (use_imm)
1391 __ Andi(dst, lhs, rhs_imm);
1392 else
1393 __ And(dst, lhs, rhs_reg);
1394 } else if (instruction->IsOr()) {
1395 if (use_imm)
1396 __ Ori(dst, lhs, rhs_imm);
1397 else
1398 __ Or(dst, lhs, rhs_reg);
1399 } else if (instruction->IsXor()) {
1400 if (use_imm)
1401 __ Xori(dst, lhs, rhs_imm);
1402 else
1403 __ Xor(dst, lhs, rhs_reg);
1404 } else if (instruction->IsAdd()) {
1405 if (use_imm)
1406 __ Addiu(dst, lhs, rhs_imm);
1407 else
1408 __ Addu(dst, lhs, rhs_reg);
1409 } else {
1410 DCHECK(instruction->IsSub());
1411 if (use_imm)
1412 __ Addiu(dst, lhs, -rhs_imm);
1413 else
1414 __ Subu(dst, lhs, rhs_reg);
1415 }
1416 break;
1417 }
1418
1419 case Primitive::kPrimLong: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001420 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
1421 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
1422 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
1423 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001424 Location rhs_location = locations->InAt(1);
1425 bool use_imm = rhs_location.IsConstant();
1426 if (!use_imm) {
1427 Register rhs_high = rhs_location.AsRegisterPairHigh<Register>();
1428 Register rhs_low = rhs_location.AsRegisterPairLow<Register>();
1429 if (instruction->IsAnd()) {
1430 __ And(dst_low, lhs_low, rhs_low);
1431 __ And(dst_high, lhs_high, rhs_high);
1432 } else if (instruction->IsOr()) {
1433 __ Or(dst_low, lhs_low, rhs_low);
1434 __ Or(dst_high, lhs_high, rhs_high);
1435 } else if (instruction->IsXor()) {
1436 __ Xor(dst_low, lhs_low, rhs_low);
1437 __ Xor(dst_high, lhs_high, rhs_high);
1438 } else if (instruction->IsAdd()) {
1439 if (lhs_low == rhs_low) {
1440 // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs.
1441 __ Slt(TMP, lhs_low, ZERO);
1442 __ Addu(dst_low, lhs_low, rhs_low);
1443 } else {
1444 __ Addu(dst_low, lhs_low, rhs_low);
1445 // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged.
1446 __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low);
1447 }
1448 __ Addu(dst_high, lhs_high, rhs_high);
1449 __ Addu(dst_high, dst_high, TMP);
1450 } else {
1451 DCHECK(instruction->IsSub());
1452 __ Sltu(TMP, lhs_low, rhs_low);
1453 __ Subu(dst_low, lhs_low, rhs_low);
1454 __ Subu(dst_high, lhs_high, rhs_high);
1455 __ Subu(dst_high, dst_high, TMP);
1456 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001457 } else {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001458 int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant());
1459 if (instruction->IsOr()) {
1460 uint32_t low = Low32Bits(value);
1461 uint32_t high = High32Bits(value);
1462 if (IsUint<16>(low)) {
1463 if (dst_low != lhs_low || low != 0) {
1464 __ Ori(dst_low, lhs_low, low);
1465 }
1466 } else {
1467 __ LoadConst32(TMP, low);
1468 __ Or(dst_low, lhs_low, TMP);
1469 }
1470 if (IsUint<16>(high)) {
1471 if (dst_high != lhs_high || high != 0) {
1472 __ Ori(dst_high, lhs_high, high);
1473 }
1474 } else {
1475 if (high != low) {
1476 __ LoadConst32(TMP, high);
1477 }
1478 __ Or(dst_high, lhs_high, TMP);
1479 }
1480 } else if (instruction->IsXor()) {
1481 uint32_t low = Low32Bits(value);
1482 uint32_t high = High32Bits(value);
1483 if (IsUint<16>(low)) {
1484 if (dst_low != lhs_low || low != 0) {
1485 __ Xori(dst_low, lhs_low, low);
1486 }
1487 } else {
1488 __ LoadConst32(TMP, low);
1489 __ Xor(dst_low, lhs_low, TMP);
1490 }
1491 if (IsUint<16>(high)) {
1492 if (dst_high != lhs_high || high != 0) {
1493 __ Xori(dst_high, lhs_high, high);
1494 }
1495 } else {
1496 if (high != low) {
1497 __ LoadConst32(TMP, high);
1498 }
1499 __ Xor(dst_high, lhs_high, TMP);
1500 }
1501 } else if (instruction->IsAnd()) {
1502 uint32_t low = Low32Bits(value);
1503 uint32_t high = High32Bits(value);
1504 if (IsUint<16>(low)) {
1505 __ Andi(dst_low, lhs_low, low);
1506 } else if (low != 0xFFFFFFFF) {
1507 __ LoadConst32(TMP, low);
1508 __ And(dst_low, lhs_low, TMP);
1509 } else if (dst_low != lhs_low) {
1510 __ Move(dst_low, lhs_low);
1511 }
1512 if (IsUint<16>(high)) {
1513 __ Andi(dst_high, lhs_high, high);
1514 } else if (high != 0xFFFFFFFF) {
1515 if (high != low) {
1516 __ LoadConst32(TMP, high);
1517 }
1518 __ And(dst_high, lhs_high, TMP);
1519 } else if (dst_high != lhs_high) {
1520 __ Move(dst_high, lhs_high);
1521 }
1522 } else {
1523 if (instruction->IsSub()) {
1524 value = -value;
1525 } else {
1526 DCHECK(instruction->IsAdd());
1527 }
1528 int32_t low = Low32Bits(value);
1529 int32_t high = High32Bits(value);
1530 if (IsInt<16>(low)) {
1531 if (dst_low != lhs_low || low != 0) {
1532 __ Addiu(dst_low, lhs_low, low);
1533 }
1534 if (low != 0) {
1535 __ Sltiu(AT, dst_low, low);
1536 }
1537 } else {
1538 __ LoadConst32(TMP, low);
1539 __ Addu(dst_low, lhs_low, TMP);
1540 __ Sltu(AT, dst_low, TMP);
1541 }
1542 if (IsInt<16>(high)) {
1543 if (dst_high != lhs_high || high != 0) {
1544 __ Addiu(dst_high, lhs_high, high);
1545 }
1546 } else {
1547 if (high != low) {
1548 __ LoadConst32(TMP, high);
1549 }
1550 __ Addu(dst_high, lhs_high, TMP);
1551 }
1552 if (low != 0) {
1553 __ Addu(dst_high, dst_high, AT);
1554 }
1555 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001556 }
1557 break;
1558 }
1559
1560 case Primitive::kPrimFloat:
1561 case Primitive::kPrimDouble: {
1562 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
1563 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
1564 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
1565 if (instruction->IsAdd()) {
1566 if (type == Primitive::kPrimFloat) {
1567 __ AddS(dst, lhs, rhs);
1568 } else {
1569 __ AddD(dst, lhs, rhs);
1570 }
1571 } else {
1572 DCHECK(instruction->IsSub());
1573 if (type == Primitive::kPrimFloat) {
1574 __ SubS(dst, lhs, rhs);
1575 } else {
1576 __ SubD(dst, lhs, rhs);
1577 }
1578 }
1579 break;
1580 }
1581
1582 default:
1583 LOG(FATAL) << "Unexpected binary operation type " << type;
1584 }
1585}
1586
1587void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001588 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001589
1590 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1591 Primitive::Type type = instr->GetResultType();
1592 switch (type) {
1593 case Primitive::kPrimInt:
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001594 locations->SetInAt(0, Location::RequiresRegister());
1595 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1596 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1597 break;
1598 case Primitive::kPrimLong:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001599 locations->SetInAt(0, Location::RequiresRegister());
1600 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1601 locations->SetOut(Location::RequiresRegister());
1602 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001603 default:
1604 LOG(FATAL) << "Unexpected shift type " << type;
1605 }
1606}
1607
1608static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte;
1609
1610void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001611 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001612 LocationSummary* locations = instr->GetLocations();
1613 Primitive::Type type = instr->GetType();
1614
1615 Location rhs_location = locations->InAt(1);
1616 bool use_imm = rhs_location.IsConstant();
1617 Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>();
1618 int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0;
Roland Levillain5b5b9312016-03-22 14:57:31 +00001619 const uint32_t shift_mask =
1620 (type == Primitive::kPrimInt) ? kMaxIntShiftDistance : kMaxLongShiftDistance;
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001621 const uint32_t shift_value = rhs_imm & shift_mask;
Alexey Frunze92d90602015-12-18 18:16:36 -08001622 // Are the INS (Insert Bit Field) and ROTR instructions supported?
1623 bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001624
1625 switch (type) {
1626 case Primitive::kPrimInt: {
1627 Register dst = locations->Out().AsRegister<Register>();
1628 Register lhs = locations->InAt(0).AsRegister<Register>();
1629 if (use_imm) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001630 if (shift_value == 0) {
1631 if (dst != lhs) {
1632 __ Move(dst, lhs);
1633 }
1634 } else if (instr->IsShl()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001635 __ Sll(dst, lhs, shift_value);
1636 } else if (instr->IsShr()) {
1637 __ Sra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001638 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001639 __ Srl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001640 } else {
1641 if (has_ins_rotr) {
1642 __ Rotr(dst, lhs, shift_value);
1643 } else {
1644 __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask);
1645 __ Srl(dst, lhs, shift_value);
1646 __ Or(dst, dst, TMP);
1647 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001648 }
1649 } else {
1650 if (instr->IsShl()) {
1651 __ Sllv(dst, lhs, rhs_reg);
1652 } else if (instr->IsShr()) {
1653 __ Srav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001654 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001655 __ Srlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001656 } else {
1657 if (has_ins_rotr) {
1658 __ Rotrv(dst, lhs, rhs_reg);
1659 } else {
1660 __ Subu(TMP, ZERO, rhs_reg);
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001661 // 32-bit shift instructions use the 5 least significant bits of the shift count, so
1662 // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case
1663 // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out
1664 // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`,
1665 // IOW, the OR'd values are equal.
Alexey Frunze92d90602015-12-18 18:16:36 -08001666 __ Sllv(TMP, lhs, TMP);
1667 __ Srlv(dst, lhs, rhs_reg);
1668 __ Or(dst, dst, TMP);
1669 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001670 }
1671 }
1672 break;
1673 }
1674
1675 case Primitive::kPrimLong: {
1676 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
1677 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
1678 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
1679 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
1680 if (use_imm) {
1681 if (shift_value == 0) {
1682 codegen_->Move64(locations->Out(), locations->InAt(0));
1683 } else if (shift_value < kMipsBitsPerWord) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001684 if (has_ins_rotr) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001685 if (instr->IsShl()) {
1686 __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value);
1687 __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value);
1688 __ Sll(dst_low, lhs_low, shift_value);
1689 } else if (instr->IsShr()) {
1690 __ Srl(dst_low, lhs_low, shift_value);
1691 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1692 __ Sra(dst_high, lhs_high, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001693 } else if (instr->IsUShr()) {
1694 __ Srl(dst_low, lhs_low, shift_value);
1695 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1696 __ Srl(dst_high, lhs_high, shift_value);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001697 } else {
1698 __ Srl(dst_low, lhs_low, shift_value);
1699 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1700 __ Srl(dst_high, lhs_high, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001701 __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001702 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001703 } else {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001704 if (instr->IsShl()) {
1705 __ Sll(dst_low, lhs_low, shift_value);
1706 __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value);
1707 __ Sll(dst_high, lhs_high, shift_value);
1708 __ Or(dst_high, dst_high, TMP);
1709 } else if (instr->IsShr()) {
1710 __ Sra(dst_high, lhs_high, shift_value);
1711 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value);
1712 __ Srl(dst_low, lhs_low, shift_value);
1713 __ Or(dst_low, dst_low, TMP);
Alexey Frunze92d90602015-12-18 18:16:36 -08001714 } else if (instr->IsUShr()) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001715 __ Srl(dst_high, lhs_high, shift_value);
1716 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value);
1717 __ Srl(dst_low, lhs_low, shift_value);
1718 __ Or(dst_low, dst_low, TMP);
Alexey Frunze92d90602015-12-18 18:16:36 -08001719 } else {
1720 __ Srl(TMP, lhs_low, shift_value);
1721 __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value);
1722 __ Or(dst_low, dst_low, TMP);
1723 __ Srl(TMP, lhs_high, shift_value);
1724 __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value);
1725 __ Or(dst_high, dst_high, TMP);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001726 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001727 }
1728 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001729 const uint32_t shift_value_high = shift_value - kMipsBitsPerWord;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001730 if (instr->IsShl()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001731 __ Sll(dst_high, lhs_low, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001732 __ Move(dst_low, ZERO);
1733 } else if (instr->IsShr()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001734 __ Sra(dst_low, lhs_high, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001735 __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1);
Alexey Frunze92d90602015-12-18 18:16:36 -08001736 } else if (instr->IsUShr()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001737 __ Srl(dst_low, lhs_high, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001738 __ Move(dst_high, ZERO);
Alexey Frunze92d90602015-12-18 18:16:36 -08001739 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001740 if (shift_value == kMipsBitsPerWord) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001741 // 64-bit rotation by 32 is just a swap.
1742 __ Move(dst_low, lhs_high);
1743 __ Move(dst_high, lhs_low);
1744 } else {
1745 if (has_ins_rotr) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001746 __ Srl(dst_low, lhs_high, shift_value_high);
1747 __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high);
1748 __ Srl(dst_high, lhs_low, shift_value_high);
1749 __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001750 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001751 __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high);
1752 __ Srl(dst_low, lhs_high, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001753 __ Or(dst_low, dst_low, TMP);
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001754 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high);
1755 __ Srl(dst_high, lhs_low, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001756 __ Or(dst_high, dst_high, TMP);
1757 }
1758 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001759 }
1760 }
1761 } else {
1762 MipsLabel done;
1763 if (instr->IsShl()) {
1764 __ Sllv(dst_low, lhs_low, rhs_reg);
1765 __ Nor(AT, ZERO, rhs_reg);
1766 __ Srl(TMP, lhs_low, 1);
1767 __ Srlv(TMP, TMP, AT);
1768 __ Sllv(dst_high, lhs_high, rhs_reg);
1769 __ Or(dst_high, dst_high, TMP);
1770 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1771 __ Beqz(TMP, &done);
1772 __ Move(dst_high, dst_low);
1773 __ Move(dst_low, ZERO);
1774 } else if (instr->IsShr()) {
1775 __ Srav(dst_high, lhs_high, rhs_reg);
1776 __ Nor(AT, ZERO, rhs_reg);
1777 __ Sll(TMP, lhs_high, 1);
1778 __ Sllv(TMP, TMP, AT);
1779 __ Srlv(dst_low, lhs_low, rhs_reg);
1780 __ Or(dst_low, dst_low, TMP);
1781 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1782 __ Beqz(TMP, &done);
1783 __ Move(dst_low, dst_high);
1784 __ Sra(dst_high, dst_high, 31);
Alexey Frunze92d90602015-12-18 18:16:36 -08001785 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001786 __ Srlv(dst_high, lhs_high, rhs_reg);
1787 __ Nor(AT, ZERO, rhs_reg);
1788 __ Sll(TMP, lhs_high, 1);
1789 __ Sllv(TMP, TMP, AT);
1790 __ Srlv(dst_low, lhs_low, rhs_reg);
1791 __ Or(dst_low, dst_low, TMP);
1792 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1793 __ Beqz(TMP, &done);
1794 __ Move(dst_low, dst_high);
1795 __ Move(dst_high, ZERO);
Alexey Frunze92d90602015-12-18 18:16:36 -08001796 } else {
1797 __ Nor(AT, ZERO, rhs_reg);
1798 __ Srlv(TMP, lhs_low, rhs_reg);
1799 __ Sll(dst_low, lhs_high, 1);
1800 __ Sllv(dst_low, dst_low, AT);
1801 __ Or(dst_low, dst_low, TMP);
1802 __ Srlv(TMP, lhs_high, rhs_reg);
1803 __ Sll(dst_high, lhs_low, 1);
1804 __ Sllv(dst_high, dst_high, AT);
1805 __ Or(dst_high, dst_high, TMP);
1806 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1807 __ Beqz(TMP, &done);
1808 __ Move(TMP, dst_high);
1809 __ Move(dst_high, dst_low);
1810 __ Move(dst_low, TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001811 }
1812 __ Bind(&done);
1813 }
1814 break;
1815 }
1816
1817 default:
1818 LOG(FATAL) << "Unexpected shift operation type " << type;
1819 }
1820}
1821
1822void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) {
1823 HandleBinaryOp(instruction);
1824}
1825
1826void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) {
1827 HandleBinaryOp(instruction);
1828}
1829
1830void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) {
1831 HandleBinaryOp(instruction);
1832}
1833
1834void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) {
1835 HandleBinaryOp(instruction);
1836}
1837
1838void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) {
1839 LocationSummary* locations =
1840 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1841 locations->SetInAt(0, Location::RequiresRegister());
1842 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1843 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1844 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1845 } else {
1846 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1847 }
1848}
1849
Alexey Frunze2923db72016-08-20 01:55:47 -07001850auto InstructionCodeGeneratorMIPS::GetImplicitNullChecker(HInstruction* instruction) {
1851 auto null_checker = [this, instruction]() {
1852 this->codegen_->MaybeRecordImplicitNullCheck(instruction);
1853 };
1854 return null_checker;
1855}
1856
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001857void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) {
1858 LocationSummary* locations = instruction->GetLocations();
1859 Register obj = locations->InAt(0).AsRegister<Register>();
1860 Location index = locations->InAt(1);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01001861 uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction);
Alexey Frunze2923db72016-08-20 01:55:47 -07001862 auto null_checker = GetImplicitNullChecker(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001863
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01001864 Primitive::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001865 switch (type) {
1866 case Primitive::kPrimBoolean: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001867 Register out = locations->Out().AsRegister<Register>();
1868 if (index.IsConstant()) {
1869 size_t offset =
1870 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001871 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001872 } else {
1873 __ Addu(TMP, obj, index.AsRegister<Register>());
Alexey Frunze2923db72016-08-20 01:55:47 -07001874 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001875 }
1876 break;
1877 }
1878
1879 case Primitive::kPrimByte: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001880 Register out = locations->Out().AsRegister<Register>();
1881 if (index.IsConstant()) {
1882 size_t offset =
1883 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001884 __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001885 } else {
1886 __ Addu(TMP, obj, index.AsRegister<Register>());
Alexey Frunze2923db72016-08-20 01:55:47 -07001887 __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001888 }
1889 break;
1890 }
1891
1892 case Primitive::kPrimShort: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001893 Register out = locations->Out().AsRegister<Register>();
1894 if (index.IsConstant()) {
1895 size_t offset =
1896 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001897 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001898 } else {
1899 __ Sll(TMP, index.AsRegister<Register>(), TIMES_2);
1900 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001901 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001902 }
1903 break;
1904 }
1905
1906 case Primitive::kPrimChar: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001907 Register out = locations->Out().AsRegister<Register>();
1908 if (index.IsConstant()) {
1909 size_t offset =
1910 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001911 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001912 } else {
1913 __ Sll(TMP, index.AsRegister<Register>(), TIMES_2);
1914 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001915 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001916 }
1917 break;
1918 }
1919
1920 case Primitive::kPrimInt:
1921 case Primitive::kPrimNot: {
1922 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001923 Register out = locations->Out().AsRegister<Register>();
1924 if (index.IsConstant()) {
1925 size_t offset =
1926 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001927 __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001928 } else {
1929 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
1930 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001931 __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001932 }
1933 break;
1934 }
1935
1936 case Primitive::kPrimLong: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001937 Register out = locations->Out().AsRegisterPairLow<Register>();
1938 if (index.IsConstant()) {
1939 size_t offset =
1940 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001941 __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001942 } else {
1943 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
1944 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001945 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001946 }
1947 break;
1948 }
1949
1950 case Primitive::kPrimFloat: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001951 FRegister out = locations->Out().AsFpuRegister<FRegister>();
1952 if (index.IsConstant()) {
1953 size_t offset =
1954 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001955 __ LoadSFromOffset(out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001956 } else {
1957 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
1958 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001959 __ LoadSFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001960 }
1961 break;
1962 }
1963
1964 case Primitive::kPrimDouble: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001965 FRegister out = locations->Out().AsFpuRegister<FRegister>();
1966 if (index.IsConstant()) {
1967 size_t offset =
1968 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001969 __ LoadDFromOffset(out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001970 } else {
1971 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
1972 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001973 __ LoadDFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001974 }
1975 break;
1976 }
1977
1978 case Primitive::kPrimVoid:
1979 LOG(FATAL) << "Unreachable type " << instruction->GetType();
1980 UNREACHABLE();
1981 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001982}
1983
1984void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) {
1985 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1986 locations->SetInAt(0, Location::RequiresRegister());
1987 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1988}
1989
1990void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) {
1991 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01001992 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001993 Register obj = locations->InAt(0).AsRegister<Register>();
1994 Register out = locations->Out().AsRegister<Register>();
1995 __ LoadFromOffset(kLoadWord, out, obj, offset);
1996 codegen_->MaybeRecordImplicitNullCheck(instruction);
1997}
1998
1999void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) {
Pavle Batuta934808f2015-11-03 13:23:54 +01002000 bool needs_runtime_call = instruction->NeedsTypeCheck();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002001 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
2002 instruction,
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002003 needs_runtime_call ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall);
Pavle Batuta934808f2015-11-03 13:23:54 +01002004 if (needs_runtime_call) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002005 InvokeRuntimeCallingConvention calling_convention;
2006 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2007 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2008 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2009 } else {
2010 locations->SetInAt(0, Location::RequiresRegister());
2011 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2012 if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
2013 locations->SetInAt(2, Location::RequiresFpuRegister());
2014 } else {
2015 locations->SetInAt(2, Location::RequiresRegister());
2016 }
2017 }
2018}
2019
2020void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) {
2021 LocationSummary* locations = instruction->GetLocations();
2022 Register obj = locations->InAt(0).AsRegister<Register>();
2023 Location index = locations->InAt(1);
2024 Primitive::Type value_type = instruction->GetComponentType();
2025 bool needs_runtime_call = locations->WillCall();
2026 bool needs_write_barrier =
2027 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Alexey Frunze2923db72016-08-20 01:55:47 -07002028 auto null_checker = GetImplicitNullChecker(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002029
2030 switch (value_type) {
2031 case Primitive::kPrimBoolean:
2032 case Primitive::kPrimByte: {
2033 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
2034 Register value = locations->InAt(2).AsRegister<Register>();
2035 if (index.IsConstant()) {
2036 size_t offset =
2037 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002038 __ StoreToOffset(kStoreByte, value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002039 } else {
2040 __ Addu(TMP, obj, index.AsRegister<Register>());
Alexey Frunze2923db72016-08-20 01:55:47 -07002041 __ StoreToOffset(kStoreByte, value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002042 }
2043 break;
2044 }
2045
2046 case Primitive::kPrimShort:
2047 case Primitive::kPrimChar: {
2048 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
2049 Register value = locations->InAt(2).AsRegister<Register>();
2050 if (index.IsConstant()) {
2051 size_t offset =
2052 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002053 __ StoreToOffset(kStoreHalfword, value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002054 } else {
2055 __ Sll(TMP, index.AsRegister<Register>(), TIMES_2);
2056 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002057 __ StoreToOffset(kStoreHalfword, value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002058 }
2059 break;
2060 }
2061
2062 case Primitive::kPrimInt:
2063 case Primitive::kPrimNot: {
2064 if (!needs_runtime_call) {
2065 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
2066 Register value = locations->InAt(2).AsRegister<Register>();
2067 if (index.IsConstant()) {
2068 size_t offset =
2069 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002070 __ StoreToOffset(kStoreWord, value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002071 } else {
2072 DCHECK(index.IsRegister()) << index;
2073 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
2074 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002075 __ StoreToOffset(kStoreWord, value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002076 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002077 if (needs_write_barrier) {
2078 DCHECK_EQ(value_type, Primitive::kPrimNot);
2079 codegen_->MarkGCCard(obj, value);
2080 }
2081 } else {
2082 DCHECK_EQ(value_type, Primitive::kPrimNot);
2083 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
2084 instruction,
2085 instruction->GetDexPc(),
2086 nullptr,
2087 IsDirectEntrypoint(kQuickAputObject));
2088 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
2089 }
2090 break;
2091 }
2092
2093 case Primitive::kPrimLong: {
2094 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
2095 Register value = locations->InAt(2).AsRegisterPairLow<Register>();
2096 if (index.IsConstant()) {
2097 size_t offset =
2098 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002099 __ StoreToOffset(kStoreDoubleword, value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002100 } else {
2101 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
2102 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002103 __ StoreToOffset(kStoreDoubleword, value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002104 }
2105 break;
2106 }
2107
2108 case Primitive::kPrimFloat: {
2109 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
2110 FRegister value = locations->InAt(2).AsFpuRegister<FRegister>();
2111 DCHECK(locations->InAt(2).IsFpuRegister());
2112 if (index.IsConstant()) {
2113 size_t offset =
2114 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002115 __ StoreSToOffset(value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002116 } else {
2117 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
2118 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002119 __ StoreSToOffset(value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002120 }
2121 break;
2122 }
2123
2124 case Primitive::kPrimDouble: {
2125 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
2126 FRegister value = locations->InAt(2).AsFpuRegister<FRegister>();
2127 DCHECK(locations->InAt(2).IsFpuRegister());
2128 if (index.IsConstant()) {
2129 size_t offset =
2130 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07002131 __ StoreDToOffset(value, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002132 } else {
2133 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
2134 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07002135 __ StoreDToOffset(value, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002136 }
2137 break;
2138 }
2139
2140 case Primitive::kPrimVoid:
2141 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2142 UNREACHABLE();
2143 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002144}
2145
2146void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) {
2147 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
2148 ? LocationSummary::kCallOnSlowPath
2149 : LocationSummary::kNoCall;
2150 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
2151 locations->SetInAt(0, Location::RequiresRegister());
2152 locations->SetInAt(1, Location::RequiresRegister());
2153 if (instruction->HasUses()) {
2154 locations->SetOut(Location::SameAsFirstInput());
2155 }
2156}
2157
2158void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) {
2159 LocationSummary* locations = instruction->GetLocations();
2160 BoundsCheckSlowPathMIPS* slow_path =
2161 new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS(instruction);
2162 codegen_->AddSlowPath(slow_path);
2163
2164 Register index = locations->InAt(0).AsRegister<Register>();
2165 Register length = locations->InAt(1).AsRegister<Register>();
2166
2167 // length is limited by the maximum positive signed 32-bit integer.
2168 // Unsigned comparison of length and index checks for index < 0
2169 // and for length <= index simultaneously.
2170 __ Bgeu(index, length, slow_path->GetEntryLabel());
2171}
2172
2173void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) {
2174 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
2175 instruction,
2176 LocationSummary::kCallOnSlowPath);
2177 locations->SetInAt(0, Location::RequiresRegister());
2178 locations->SetInAt(1, Location::RequiresRegister());
2179 // Note that TypeCheckSlowPathMIPS uses this register too.
2180 locations->AddTemp(Location::RequiresRegister());
2181}
2182
2183void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) {
2184 LocationSummary* locations = instruction->GetLocations();
2185 Register obj = locations->InAt(0).AsRegister<Register>();
2186 Register cls = locations->InAt(1).AsRegister<Register>();
2187 Register obj_cls = locations->GetTemp(0).AsRegister<Register>();
2188
2189 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction);
2190 codegen_->AddSlowPath(slow_path);
2191
2192 // TODO: avoid this check if we know obj is not null.
2193 __ Beqz(obj, slow_path->GetExitLabel());
2194 // Compare the class of `obj` with `cls`.
2195 __ LoadFromOffset(kLoadWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value());
2196 __ Bne(obj_cls, cls, slow_path->GetEntryLabel());
2197 __ Bind(slow_path->GetExitLabel());
2198}
2199
2200void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) {
2201 LocationSummary* locations =
2202 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2203 locations->SetInAt(0, Location::RequiresRegister());
2204 if (check->HasUses()) {
2205 locations->SetOut(Location::SameAsFirstInput());
2206 }
2207}
2208
2209void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) {
2210 // We assume the class is not null.
2211 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS(
2212 check->GetLoadClass(),
2213 check,
2214 check->GetDexPc(),
2215 true);
2216 codegen_->AddSlowPath(slow_path);
2217 GenerateClassInitializationCheck(slow_path,
2218 check->GetLocations()->InAt(0).AsRegister<Register>());
2219}
2220
2221void LocationsBuilderMIPS::VisitCompare(HCompare* compare) {
2222 Primitive::Type in_type = compare->InputAt(0)->GetType();
2223
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002224 LocationSummary* locations =
2225 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002226
2227 switch (in_type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00002228 case Primitive::kPrimBoolean:
2229 case Primitive::kPrimByte:
2230 case Primitive::kPrimShort:
2231 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08002232 case Primitive::kPrimInt:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002233 case Primitive::kPrimLong:
2234 locations->SetInAt(0, Location::RequiresRegister());
2235 locations->SetInAt(1, Location::RequiresRegister());
2236 // Output overlaps because it is written before doing the low comparison.
2237 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
2238 break;
2239
2240 case Primitive::kPrimFloat:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002241 case Primitive::kPrimDouble:
2242 locations->SetInAt(0, Location::RequiresFpuRegister());
2243 locations->SetInAt(1, Location::RequiresFpuRegister());
2244 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002245 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002246
2247 default:
2248 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
2249 }
2250}
2251
2252void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) {
2253 LocationSummary* locations = instruction->GetLocations();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002254 Register res = locations->Out().AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002255 Primitive::Type in_type = instruction->InputAt(0)->GetType();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002256 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002257
2258 // 0 if: left == right
2259 // 1 if: left > right
2260 // -1 if: left < right
2261 switch (in_type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00002262 case Primitive::kPrimBoolean:
2263 case Primitive::kPrimByte:
2264 case Primitive::kPrimShort:
2265 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08002266 case Primitive::kPrimInt: {
2267 Register lhs = locations->InAt(0).AsRegister<Register>();
2268 Register rhs = locations->InAt(1).AsRegister<Register>();
2269 __ Slt(TMP, lhs, rhs);
2270 __ Slt(res, rhs, lhs);
2271 __ Subu(res, res, TMP);
2272 break;
2273 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002274 case Primitive::kPrimLong: {
2275 MipsLabel done;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002276 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
2277 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
2278 Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>();
2279 Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>();
2280 // TODO: more efficient (direct) comparison with a constant.
2281 __ Slt(TMP, lhs_high, rhs_high);
2282 __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt.
2283 __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ].
2284 __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal.
2285 __ Sltu(TMP, lhs_low, rhs_low);
2286 __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt.
2287 __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ].
2288 __ Bind(&done);
2289 break;
2290 }
2291
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002292 case Primitive::kPrimFloat: {
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 __ CmpEqS(FTMP, lhs, rhs);
2299 __ LoadConst32(res, 0);
2300 __ Bc1nez(FTMP, &done);
2301 if (gt_bias) {
2302 __ CmpLtS(FTMP, lhs, rhs);
2303 __ LoadConst32(res, -1);
2304 __ Bc1nez(FTMP, &done);
2305 __ LoadConst32(res, 1);
2306 } else {
2307 __ CmpLtS(FTMP, rhs, lhs);
2308 __ LoadConst32(res, 1);
2309 __ Bc1nez(FTMP, &done);
2310 __ LoadConst32(res, -1);
2311 }
2312 } else {
2313 if (gt_bias) {
2314 __ ColtS(0, lhs, rhs);
2315 __ LoadConst32(res, -1);
2316 __ Bc1t(0, &done);
2317 __ CeqS(0, lhs, rhs);
2318 __ LoadConst32(res, 1);
2319 __ Movt(res, ZERO, 0);
2320 } else {
2321 __ ColtS(0, rhs, lhs);
2322 __ LoadConst32(res, 1);
2323 __ Bc1t(0, &done);
2324 __ CeqS(0, lhs, rhs);
2325 __ LoadConst32(res, -1);
2326 __ Movt(res, ZERO, 0);
2327 }
2328 }
2329 __ Bind(&done);
2330 break;
2331 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002332 case Primitive::kPrimDouble: {
Roland Levillain32ca3752016-02-17 16:49:37 +00002333 bool gt_bias = instruction->IsGtBias();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002334 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2335 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2336 MipsLabel done;
2337 if (isR6) {
2338 __ CmpEqD(FTMP, lhs, rhs);
2339 __ LoadConst32(res, 0);
2340 __ Bc1nez(FTMP, &done);
2341 if (gt_bias) {
2342 __ CmpLtD(FTMP, lhs, rhs);
2343 __ LoadConst32(res, -1);
2344 __ Bc1nez(FTMP, &done);
2345 __ LoadConst32(res, 1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002346 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002347 __ CmpLtD(FTMP, rhs, lhs);
2348 __ LoadConst32(res, 1);
2349 __ Bc1nez(FTMP, &done);
2350 __ LoadConst32(res, -1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002351 }
2352 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002353 if (gt_bias) {
2354 __ ColtD(0, lhs, rhs);
2355 __ LoadConst32(res, -1);
2356 __ Bc1t(0, &done);
2357 __ CeqD(0, lhs, rhs);
2358 __ LoadConst32(res, 1);
2359 __ Movt(res, ZERO, 0);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002360 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002361 __ ColtD(0, rhs, lhs);
2362 __ LoadConst32(res, 1);
2363 __ Bc1t(0, &done);
2364 __ CeqD(0, lhs, rhs);
2365 __ LoadConst32(res, -1);
2366 __ Movt(res, ZERO, 0);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002367 }
2368 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002369 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002370 break;
2371 }
2372
2373 default:
2374 LOG(FATAL) << "Unimplemented compare type " << in_type;
2375 }
2376}
2377
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002378void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002379 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002380 switch (instruction->InputAt(0)->GetType()) {
2381 default:
2382 case Primitive::kPrimLong:
2383 locations->SetInAt(0, Location::RequiresRegister());
2384 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2385 break;
2386
2387 case Primitive::kPrimFloat:
2388 case Primitive::kPrimDouble:
2389 locations->SetInAt(0, Location::RequiresFpuRegister());
2390 locations->SetInAt(1, Location::RequiresFpuRegister());
2391 break;
2392 }
David Brazdilb3e773e2016-01-26 11:28:37 +00002393 if (!instruction->IsEmittedAtUseSite()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002394 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2395 }
2396}
2397
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002398void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) {
David Brazdilb3e773e2016-01-26 11:28:37 +00002399 if (instruction->IsEmittedAtUseSite()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002400 return;
2401 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002402
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002403 Primitive::Type type = instruction->InputAt(0)->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002404 LocationSummary* locations = instruction->GetLocations();
2405 Register dst = locations->Out().AsRegister<Register>();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002406 MipsLabel true_label;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002407
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002408 switch (type) {
2409 default:
2410 // Integer case.
2411 GenerateIntCompare(instruction->GetCondition(), locations);
2412 return;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002413
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002414 case Primitive::kPrimLong:
2415 // TODO: don't use branches.
2416 GenerateLongCompareAndBranch(instruction->GetCondition(), locations, &true_label);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002417 break;
2418
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002419 case Primitive::kPrimFloat:
2420 case Primitive::kPrimDouble:
2421 // TODO: don't use branches.
2422 GenerateFpCompareAndBranch(instruction->GetCondition(),
2423 instruction->IsGtBias(),
2424 type,
2425 locations,
2426 &true_label);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002427 break;
2428 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002429
2430 // Convert the branches into the result.
2431 MipsLabel done;
2432
2433 // False case: result = 0.
2434 __ LoadConst32(dst, 0);
2435 __ B(&done);
2436
2437 // True case: result = 1.
2438 __ Bind(&true_label);
2439 __ LoadConst32(dst, 1);
2440 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002441}
2442
Alexey Frunze7e99e052015-11-24 19:28:01 -08002443void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2444 DCHECK(instruction->IsDiv() || instruction->IsRem());
2445 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2446
2447 LocationSummary* locations = instruction->GetLocations();
2448 Location second = locations->InAt(1);
2449 DCHECK(second.IsConstant());
2450
2451 Register out = locations->Out().AsRegister<Register>();
2452 Register dividend = locations->InAt(0).AsRegister<Register>();
2453 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2454 DCHECK(imm == 1 || imm == -1);
2455
2456 if (instruction->IsRem()) {
2457 __ Move(out, ZERO);
2458 } else {
2459 if (imm == -1) {
2460 __ Subu(out, ZERO, dividend);
2461 } else if (out != dividend) {
2462 __ Move(out, dividend);
2463 }
2464 }
2465}
2466
2467void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2468 DCHECK(instruction->IsDiv() || instruction->IsRem());
2469 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2470
2471 LocationSummary* locations = instruction->GetLocations();
2472 Location second = locations->InAt(1);
2473 DCHECK(second.IsConstant());
2474
2475 Register out = locations->Out().AsRegister<Register>();
2476 Register dividend = locations->InAt(0).AsRegister<Register>();
2477 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002478 uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm));
Alexey Frunze7e99e052015-11-24 19:28:01 -08002479 int ctz_imm = CTZ(abs_imm);
2480
2481 if (instruction->IsDiv()) {
2482 if (ctz_imm == 1) {
2483 // Fast path for division by +/-2, which is very common.
2484 __ Srl(TMP, dividend, 31);
2485 } else {
2486 __ Sra(TMP, dividend, 31);
2487 __ Srl(TMP, TMP, 32 - ctz_imm);
2488 }
2489 __ Addu(out, dividend, TMP);
2490 __ Sra(out, out, ctz_imm);
2491 if (imm < 0) {
2492 __ Subu(out, ZERO, out);
2493 }
2494 } else {
2495 if (ctz_imm == 1) {
2496 // Fast path for modulo +/-2, which is very common.
2497 __ Sra(TMP, dividend, 31);
2498 __ Subu(out, dividend, TMP);
2499 __ Andi(out, out, 1);
2500 __ Addu(out, out, TMP);
2501 } else {
2502 __ Sra(TMP, dividend, 31);
2503 __ Srl(TMP, TMP, 32 - ctz_imm);
2504 __ Addu(out, dividend, TMP);
2505 if (IsUint<16>(abs_imm - 1)) {
2506 __ Andi(out, out, abs_imm - 1);
2507 } else {
2508 __ Sll(out, out, 32 - ctz_imm);
2509 __ Srl(out, out, 32 - ctz_imm);
2510 }
2511 __ Subu(out, out, TMP);
2512 }
2513 }
2514}
2515
2516void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2517 DCHECK(instruction->IsDiv() || instruction->IsRem());
2518 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2519
2520 LocationSummary* locations = instruction->GetLocations();
2521 Location second = locations->InAt(1);
2522 DCHECK(second.IsConstant());
2523
2524 Register out = locations->Out().AsRegister<Register>();
2525 Register dividend = locations->InAt(0).AsRegister<Register>();
2526 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2527
2528 int64_t magic;
2529 int shift;
2530 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2531
2532 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
2533
2534 __ LoadConst32(TMP, magic);
2535 if (isR6) {
2536 __ MuhR6(TMP, dividend, TMP);
2537 } else {
2538 __ MultR2(dividend, TMP);
2539 __ Mfhi(TMP);
2540 }
2541 if (imm > 0 && magic < 0) {
2542 __ Addu(TMP, TMP, dividend);
2543 } else if (imm < 0 && magic > 0) {
2544 __ Subu(TMP, TMP, dividend);
2545 }
2546
2547 if (shift != 0) {
2548 __ Sra(TMP, TMP, shift);
2549 }
2550
2551 if (instruction->IsDiv()) {
2552 __ Sra(out, TMP, 31);
2553 __ Subu(out, TMP, out);
2554 } else {
2555 __ Sra(AT, TMP, 31);
2556 __ Subu(AT, TMP, AT);
2557 __ LoadConst32(TMP, imm);
2558 if (isR6) {
2559 __ MulR6(TMP, AT, TMP);
2560 } else {
2561 __ MulR2(TMP, AT, TMP);
2562 }
2563 __ Subu(out, dividend, TMP);
2564 }
2565}
2566
2567void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) {
2568 DCHECK(instruction->IsDiv() || instruction->IsRem());
2569 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2570
2571 LocationSummary* locations = instruction->GetLocations();
2572 Register out = locations->Out().AsRegister<Register>();
2573 Location second = locations->InAt(1);
2574
2575 if (second.IsConstant()) {
2576 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2577 if (imm == 0) {
2578 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2579 } else if (imm == 1 || imm == -1) {
2580 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002581 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08002582 DivRemByPowerOfTwo(instruction);
2583 } else {
2584 DCHECK(imm <= -2 || imm >= 2);
2585 GenerateDivRemWithAnyConstant(instruction);
2586 }
2587 } else {
2588 Register dividend = locations->InAt(0).AsRegister<Register>();
2589 Register divisor = second.AsRegister<Register>();
2590 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
2591 if (instruction->IsDiv()) {
2592 if (isR6) {
2593 __ DivR6(out, dividend, divisor);
2594 } else {
2595 __ DivR2(out, dividend, divisor);
2596 }
2597 } else {
2598 if (isR6) {
2599 __ ModR6(out, dividend, divisor);
2600 } else {
2601 __ ModR2(out, dividend, divisor);
2602 }
2603 }
2604 }
2605}
2606
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002607void LocationsBuilderMIPS::VisitDiv(HDiv* div) {
2608 Primitive::Type type = div->GetResultType();
2609 LocationSummary::CallKind call_kind = (type == Primitive::kPrimLong)
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002610 ? LocationSummary::kCallOnMainOnly
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002611 : LocationSummary::kNoCall;
2612
2613 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2614
2615 switch (type) {
2616 case Primitive::kPrimInt:
2617 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze7e99e052015-11-24 19:28:01 -08002618 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002619 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2620 break;
2621
2622 case Primitive::kPrimLong: {
2623 InvokeRuntimeCallingConvention calling_convention;
2624 locations->SetInAt(0, Location::RegisterPairLocation(
2625 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2626 locations->SetInAt(1, Location::RegisterPairLocation(
2627 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2628 locations->SetOut(calling_convention.GetReturnLocation(type));
2629 break;
2630 }
2631
2632 case Primitive::kPrimFloat:
2633 case Primitive::kPrimDouble:
2634 locations->SetInAt(0, Location::RequiresFpuRegister());
2635 locations->SetInAt(1, Location::RequiresFpuRegister());
2636 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2637 break;
2638
2639 default:
2640 LOG(FATAL) << "Unexpected div type " << type;
2641 }
2642}
2643
2644void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) {
2645 Primitive::Type type = instruction->GetType();
2646 LocationSummary* locations = instruction->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002647
2648 switch (type) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08002649 case Primitive::kPrimInt:
2650 GenerateDivRemIntegral(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002651 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002652 case Primitive::kPrimLong: {
2653 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv),
2654 instruction,
2655 instruction->GetDexPc(),
2656 nullptr,
2657 IsDirectEntrypoint(kQuickLdiv));
2658 CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>();
2659 break;
2660 }
2661 case Primitive::kPrimFloat:
2662 case Primitive::kPrimDouble: {
2663 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
2664 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2665 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2666 if (type == Primitive::kPrimFloat) {
2667 __ DivS(dst, lhs, rhs);
2668 } else {
2669 __ DivD(dst, lhs, rhs);
2670 }
2671 break;
2672 }
2673 default:
2674 LOG(FATAL) << "Unexpected div type " << type;
2675 }
2676}
2677
2678void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2679 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
2680 ? LocationSummary::kCallOnSlowPath
2681 : LocationSummary::kNoCall;
2682 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
2683 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
2684 if (instruction->HasUses()) {
2685 locations->SetOut(Location::SameAsFirstInput());
2686 }
2687}
2688
2689void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2690 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS(instruction);
2691 codegen_->AddSlowPath(slow_path);
2692 Location value = instruction->GetLocations()->InAt(0);
2693 Primitive::Type type = instruction->GetType();
2694
2695 switch (type) {
Nicolas Geoffraye5671612016-03-16 11:03:54 +00002696 case Primitive::kPrimBoolean:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002697 case Primitive::kPrimByte:
2698 case Primitive::kPrimChar:
2699 case Primitive::kPrimShort:
2700 case Primitive::kPrimInt: {
2701 if (value.IsConstant()) {
2702 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2703 __ B(slow_path->GetEntryLabel());
2704 } else {
2705 // A division by a non-null constant is valid. We don't need to perform
2706 // any check, so simply fall through.
2707 }
2708 } else {
2709 DCHECK(value.IsRegister()) << value;
2710 __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel());
2711 }
2712 break;
2713 }
2714 case Primitive::kPrimLong: {
2715 if (value.IsConstant()) {
2716 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2717 __ B(slow_path->GetEntryLabel());
2718 } else {
2719 // A division by a non-null constant is valid. We don't need to perform
2720 // any check, so simply fall through.
2721 }
2722 } else {
2723 DCHECK(value.IsRegisterPair()) << value;
2724 __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>());
2725 __ Beqz(TMP, slow_path->GetEntryLabel());
2726 }
2727 break;
2728 }
2729 default:
2730 LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck.";
2731 }
2732}
2733
2734void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) {
2735 LocationSummary* locations =
2736 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2737 locations->SetOut(Location::ConstantLocation(constant));
2738}
2739
2740void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) {
2741 // Will be generated at use site.
2742}
2743
2744void LocationsBuilderMIPS::VisitExit(HExit* exit) {
2745 exit->SetLocations(nullptr);
2746}
2747
2748void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
2749}
2750
2751void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) {
2752 LocationSummary* locations =
2753 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2754 locations->SetOut(Location::ConstantLocation(constant));
2755}
2756
2757void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
2758 // Will be generated at use site.
2759}
2760
2761void LocationsBuilderMIPS::VisitGoto(HGoto* got) {
2762 got->SetLocations(nullptr);
2763}
2764
2765void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) {
2766 DCHECK(!successor->IsExitBlock());
2767 HBasicBlock* block = got->GetBlock();
2768 HInstruction* previous = got->GetPrevious();
2769 HLoopInformation* info = block->GetLoopInformation();
2770
2771 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
2772 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
2773 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
2774 return;
2775 }
2776 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
2777 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
2778 }
2779 if (!codegen_->GoesToNextBlock(block, successor)) {
2780 __ B(codegen_->GetLabelOf(successor));
2781 }
2782}
2783
2784void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) {
2785 HandleGoto(got, got->GetSuccessor());
2786}
2787
2788void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) {
2789 try_boundary->SetLocations(nullptr);
2790}
2791
2792void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) {
2793 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
2794 if (!successor->IsExitBlock()) {
2795 HandleGoto(try_boundary, successor);
2796 }
2797}
2798
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002799void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond,
2800 LocationSummary* locations) {
2801 Register dst = locations->Out().AsRegister<Register>();
2802 Register lhs = locations->InAt(0).AsRegister<Register>();
2803 Location rhs_location = locations->InAt(1);
2804 Register rhs_reg = ZERO;
2805 int64_t rhs_imm = 0;
2806 bool use_imm = rhs_location.IsConstant();
2807 if (use_imm) {
2808 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2809 } else {
2810 rhs_reg = rhs_location.AsRegister<Register>();
2811 }
2812
2813 switch (cond) {
2814 case kCondEQ:
2815 case kCondNE:
2816 if (use_imm && IsUint<16>(rhs_imm)) {
2817 __ Xori(dst, lhs, rhs_imm);
2818 } else {
2819 if (use_imm) {
2820 rhs_reg = TMP;
2821 __ LoadConst32(rhs_reg, rhs_imm);
2822 }
2823 __ Xor(dst, lhs, rhs_reg);
2824 }
2825 if (cond == kCondEQ) {
2826 __ Sltiu(dst, dst, 1);
2827 } else {
2828 __ Sltu(dst, ZERO, dst);
2829 }
2830 break;
2831
2832 case kCondLT:
2833 case kCondGE:
2834 if (use_imm && IsInt<16>(rhs_imm)) {
2835 __ Slti(dst, lhs, rhs_imm);
2836 } else {
2837 if (use_imm) {
2838 rhs_reg = TMP;
2839 __ LoadConst32(rhs_reg, rhs_imm);
2840 }
2841 __ Slt(dst, lhs, rhs_reg);
2842 }
2843 if (cond == kCondGE) {
2844 // Simulate lhs >= rhs via !(lhs < rhs) since there's
2845 // only the slt instruction but no sge.
2846 __ Xori(dst, dst, 1);
2847 }
2848 break;
2849
2850 case kCondLE:
2851 case kCondGT:
2852 if (use_imm && IsInt<16>(rhs_imm + 1)) {
2853 // Simulate lhs <= rhs via lhs < rhs + 1.
2854 __ Slti(dst, lhs, rhs_imm + 1);
2855 if (cond == kCondGT) {
2856 // Simulate lhs > rhs via !(lhs <= rhs) since there's
2857 // only the slti instruction but no sgti.
2858 __ Xori(dst, dst, 1);
2859 }
2860 } else {
2861 if (use_imm) {
2862 rhs_reg = TMP;
2863 __ LoadConst32(rhs_reg, rhs_imm);
2864 }
2865 __ Slt(dst, rhs_reg, lhs);
2866 if (cond == kCondLE) {
2867 // Simulate lhs <= rhs via !(rhs < lhs) since there's
2868 // only the slt instruction but no sle.
2869 __ Xori(dst, dst, 1);
2870 }
2871 }
2872 break;
2873
2874 case kCondB:
2875 case kCondAE:
2876 if (use_imm && IsInt<16>(rhs_imm)) {
2877 // Sltiu sign-extends its 16-bit immediate operand before
2878 // the comparison and thus lets us compare directly with
2879 // unsigned values in the ranges [0, 0x7fff] and
2880 // [0xffff8000, 0xffffffff].
2881 __ Sltiu(dst, lhs, rhs_imm);
2882 } else {
2883 if (use_imm) {
2884 rhs_reg = TMP;
2885 __ LoadConst32(rhs_reg, rhs_imm);
2886 }
2887 __ Sltu(dst, lhs, rhs_reg);
2888 }
2889 if (cond == kCondAE) {
2890 // Simulate lhs >= rhs via !(lhs < rhs) since there's
2891 // only the sltu instruction but no sgeu.
2892 __ Xori(dst, dst, 1);
2893 }
2894 break;
2895
2896 case kCondBE:
2897 case kCondA:
2898 if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
2899 // Simulate lhs <= rhs via lhs < rhs + 1.
2900 // Note that this only works if rhs + 1 does not overflow
2901 // to 0, hence the check above.
2902 // Sltiu sign-extends its 16-bit immediate operand before
2903 // the comparison and thus lets us compare directly with
2904 // unsigned values in the ranges [0, 0x7fff] and
2905 // [0xffff8000, 0xffffffff].
2906 __ Sltiu(dst, lhs, rhs_imm + 1);
2907 if (cond == kCondA) {
2908 // Simulate lhs > rhs via !(lhs <= rhs) since there's
2909 // only the sltiu instruction but no sgtiu.
2910 __ Xori(dst, dst, 1);
2911 }
2912 } else {
2913 if (use_imm) {
2914 rhs_reg = TMP;
2915 __ LoadConst32(rhs_reg, rhs_imm);
2916 }
2917 __ Sltu(dst, rhs_reg, lhs);
2918 if (cond == kCondBE) {
2919 // Simulate lhs <= rhs via !(rhs < lhs) since there's
2920 // only the sltu instruction but no sleu.
2921 __ Xori(dst, dst, 1);
2922 }
2923 }
2924 break;
2925 }
2926}
2927
2928void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond,
2929 LocationSummary* locations,
2930 MipsLabel* label) {
2931 Register lhs = locations->InAt(0).AsRegister<Register>();
2932 Location rhs_location = locations->InAt(1);
2933 Register rhs_reg = ZERO;
2934 int32_t rhs_imm = 0;
2935 bool use_imm = rhs_location.IsConstant();
2936 if (use_imm) {
2937 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2938 } else {
2939 rhs_reg = rhs_location.AsRegister<Register>();
2940 }
2941
2942 if (use_imm && rhs_imm == 0) {
2943 switch (cond) {
2944 case kCondEQ:
2945 case kCondBE: // <= 0 if zero
2946 __ Beqz(lhs, label);
2947 break;
2948 case kCondNE:
2949 case kCondA: // > 0 if non-zero
2950 __ Bnez(lhs, label);
2951 break;
2952 case kCondLT:
2953 __ Bltz(lhs, label);
2954 break;
2955 case kCondGE:
2956 __ Bgez(lhs, label);
2957 break;
2958 case kCondLE:
2959 __ Blez(lhs, label);
2960 break;
2961 case kCondGT:
2962 __ Bgtz(lhs, label);
2963 break;
2964 case kCondB: // always false
2965 break;
2966 case kCondAE: // always true
2967 __ B(label);
2968 break;
2969 }
2970 } else {
2971 if (use_imm) {
2972 // TODO: more efficient comparison with 16-bit constants without loading them into TMP.
2973 rhs_reg = TMP;
2974 __ LoadConst32(rhs_reg, rhs_imm);
2975 }
2976 switch (cond) {
2977 case kCondEQ:
2978 __ Beq(lhs, rhs_reg, label);
2979 break;
2980 case kCondNE:
2981 __ Bne(lhs, rhs_reg, label);
2982 break;
2983 case kCondLT:
2984 __ Blt(lhs, rhs_reg, label);
2985 break;
2986 case kCondGE:
2987 __ Bge(lhs, rhs_reg, label);
2988 break;
2989 case kCondLE:
2990 __ Bge(rhs_reg, lhs, label);
2991 break;
2992 case kCondGT:
2993 __ Blt(rhs_reg, lhs, label);
2994 break;
2995 case kCondB:
2996 __ Bltu(lhs, rhs_reg, label);
2997 break;
2998 case kCondAE:
2999 __ Bgeu(lhs, rhs_reg, label);
3000 break;
3001 case kCondBE:
3002 __ Bgeu(rhs_reg, lhs, label);
3003 break;
3004 case kCondA:
3005 __ Bltu(rhs_reg, lhs, label);
3006 break;
3007 }
3008 }
3009}
3010
3011void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond,
3012 LocationSummary* locations,
3013 MipsLabel* label) {
3014 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
3015 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
3016 Location rhs_location = locations->InAt(1);
3017 Register rhs_high = ZERO;
3018 Register rhs_low = ZERO;
3019 int64_t imm = 0;
3020 uint32_t imm_high = 0;
3021 uint32_t imm_low = 0;
3022 bool use_imm = rhs_location.IsConstant();
3023 if (use_imm) {
3024 imm = rhs_location.GetConstant()->AsLongConstant()->GetValue();
3025 imm_high = High32Bits(imm);
3026 imm_low = Low32Bits(imm);
3027 } else {
3028 rhs_high = rhs_location.AsRegisterPairHigh<Register>();
3029 rhs_low = rhs_location.AsRegisterPairLow<Register>();
3030 }
3031
3032 if (use_imm && imm == 0) {
3033 switch (cond) {
3034 case kCondEQ:
3035 case kCondBE: // <= 0 if zero
3036 __ Or(TMP, lhs_high, lhs_low);
3037 __ Beqz(TMP, label);
3038 break;
3039 case kCondNE:
3040 case kCondA: // > 0 if non-zero
3041 __ Or(TMP, lhs_high, lhs_low);
3042 __ Bnez(TMP, label);
3043 break;
3044 case kCondLT:
3045 __ Bltz(lhs_high, label);
3046 break;
3047 case kCondGE:
3048 __ Bgez(lhs_high, label);
3049 break;
3050 case kCondLE:
3051 __ Or(TMP, lhs_high, lhs_low);
3052 __ Sra(AT, lhs_high, 31);
3053 __ Bgeu(AT, TMP, label);
3054 break;
3055 case kCondGT:
3056 __ Or(TMP, lhs_high, lhs_low);
3057 __ Sra(AT, lhs_high, 31);
3058 __ Bltu(AT, TMP, label);
3059 break;
3060 case kCondB: // always false
3061 break;
3062 case kCondAE: // always true
3063 __ B(label);
3064 break;
3065 }
3066 } else if (use_imm) {
3067 // TODO: more efficient comparison with constants without loading them into TMP/AT.
3068 switch (cond) {
3069 case kCondEQ:
3070 __ LoadConst32(TMP, imm_high);
3071 __ Xor(TMP, TMP, lhs_high);
3072 __ LoadConst32(AT, imm_low);
3073 __ Xor(AT, AT, lhs_low);
3074 __ Or(TMP, TMP, AT);
3075 __ Beqz(TMP, label);
3076 break;
3077 case kCondNE:
3078 __ LoadConst32(TMP, imm_high);
3079 __ Xor(TMP, TMP, lhs_high);
3080 __ LoadConst32(AT, imm_low);
3081 __ Xor(AT, AT, lhs_low);
3082 __ Or(TMP, TMP, AT);
3083 __ Bnez(TMP, label);
3084 break;
3085 case kCondLT:
3086 __ LoadConst32(TMP, imm_high);
3087 __ Blt(lhs_high, TMP, label);
3088 __ Slt(TMP, TMP, lhs_high);
3089 __ LoadConst32(AT, imm_low);
3090 __ Sltu(AT, lhs_low, AT);
3091 __ Blt(TMP, AT, label);
3092 break;
3093 case kCondGE:
3094 __ LoadConst32(TMP, imm_high);
3095 __ Blt(TMP, lhs_high, label);
3096 __ Slt(TMP, lhs_high, TMP);
3097 __ LoadConst32(AT, imm_low);
3098 __ Sltu(AT, lhs_low, AT);
3099 __ Or(TMP, TMP, AT);
3100 __ Beqz(TMP, label);
3101 break;
3102 case kCondLE:
3103 __ LoadConst32(TMP, imm_high);
3104 __ Blt(lhs_high, TMP, label);
3105 __ Slt(TMP, TMP, lhs_high);
3106 __ LoadConst32(AT, imm_low);
3107 __ Sltu(AT, AT, lhs_low);
3108 __ Or(TMP, TMP, AT);
3109 __ Beqz(TMP, label);
3110 break;
3111 case kCondGT:
3112 __ LoadConst32(TMP, imm_high);
3113 __ Blt(TMP, lhs_high, label);
3114 __ Slt(TMP, lhs_high, TMP);
3115 __ LoadConst32(AT, imm_low);
3116 __ Sltu(AT, AT, lhs_low);
3117 __ Blt(TMP, AT, label);
3118 break;
3119 case kCondB:
3120 __ LoadConst32(TMP, imm_high);
3121 __ Bltu(lhs_high, TMP, label);
3122 __ Sltu(TMP, TMP, lhs_high);
3123 __ LoadConst32(AT, imm_low);
3124 __ Sltu(AT, lhs_low, AT);
3125 __ Blt(TMP, AT, label);
3126 break;
3127 case kCondAE:
3128 __ LoadConst32(TMP, imm_high);
3129 __ Bltu(TMP, lhs_high, label);
3130 __ Sltu(TMP, lhs_high, TMP);
3131 __ LoadConst32(AT, imm_low);
3132 __ Sltu(AT, lhs_low, AT);
3133 __ Or(TMP, TMP, AT);
3134 __ Beqz(TMP, label);
3135 break;
3136 case kCondBE:
3137 __ LoadConst32(TMP, imm_high);
3138 __ Bltu(lhs_high, TMP, label);
3139 __ Sltu(TMP, TMP, lhs_high);
3140 __ LoadConst32(AT, imm_low);
3141 __ Sltu(AT, AT, lhs_low);
3142 __ Or(TMP, TMP, AT);
3143 __ Beqz(TMP, label);
3144 break;
3145 case kCondA:
3146 __ LoadConst32(TMP, imm_high);
3147 __ Bltu(TMP, lhs_high, label);
3148 __ Sltu(TMP, lhs_high, TMP);
3149 __ LoadConst32(AT, imm_low);
3150 __ Sltu(AT, AT, lhs_low);
3151 __ Blt(TMP, AT, label);
3152 break;
3153 }
3154 } else {
3155 switch (cond) {
3156 case kCondEQ:
3157 __ Xor(TMP, lhs_high, rhs_high);
3158 __ Xor(AT, lhs_low, rhs_low);
3159 __ Or(TMP, TMP, AT);
3160 __ Beqz(TMP, label);
3161 break;
3162 case kCondNE:
3163 __ Xor(TMP, lhs_high, rhs_high);
3164 __ Xor(AT, lhs_low, rhs_low);
3165 __ Or(TMP, TMP, AT);
3166 __ Bnez(TMP, label);
3167 break;
3168 case kCondLT:
3169 __ Blt(lhs_high, rhs_high, label);
3170 __ Slt(TMP, rhs_high, lhs_high);
3171 __ Sltu(AT, lhs_low, rhs_low);
3172 __ Blt(TMP, AT, label);
3173 break;
3174 case kCondGE:
3175 __ Blt(rhs_high, lhs_high, label);
3176 __ Slt(TMP, lhs_high, rhs_high);
3177 __ Sltu(AT, lhs_low, rhs_low);
3178 __ Or(TMP, TMP, AT);
3179 __ Beqz(TMP, label);
3180 break;
3181 case kCondLE:
3182 __ Blt(lhs_high, rhs_high, label);
3183 __ Slt(TMP, rhs_high, lhs_high);
3184 __ Sltu(AT, rhs_low, lhs_low);
3185 __ Or(TMP, TMP, AT);
3186 __ Beqz(TMP, label);
3187 break;
3188 case kCondGT:
3189 __ Blt(rhs_high, lhs_high, label);
3190 __ Slt(TMP, lhs_high, rhs_high);
3191 __ Sltu(AT, rhs_low, lhs_low);
3192 __ Blt(TMP, AT, label);
3193 break;
3194 case kCondB:
3195 __ Bltu(lhs_high, rhs_high, label);
3196 __ Sltu(TMP, rhs_high, lhs_high);
3197 __ Sltu(AT, lhs_low, rhs_low);
3198 __ Blt(TMP, AT, label);
3199 break;
3200 case kCondAE:
3201 __ Bltu(rhs_high, lhs_high, label);
3202 __ Sltu(TMP, lhs_high, rhs_high);
3203 __ Sltu(AT, lhs_low, rhs_low);
3204 __ Or(TMP, TMP, AT);
3205 __ Beqz(TMP, label);
3206 break;
3207 case kCondBE:
3208 __ Bltu(lhs_high, rhs_high, label);
3209 __ Sltu(TMP, rhs_high, lhs_high);
3210 __ Sltu(AT, rhs_low, lhs_low);
3211 __ Or(TMP, TMP, AT);
3212 __ Beqz(TMP, label);
3213 break;
3214 case kCondA:
3215 __ Bltu(rhs_high, lhs_high, label);
3216 __ Sltu(TMP, lhs_high, rhs_high);
3217 __ Sltu(AT, rhs_low, lhs_low);
3218 __ Blt(TMP, AT, label);
3219 break;
3220 }
3221 }
3222}
3223
3224void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond,
3225 bool gt_bias,
3226 Primitive::Type type,
3227 LocationSummary* locations,
3228 MipsLabel* label) {
3229 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
3230 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
3231 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
3232 if (type == Primitive::kPrimFloat) {
3233 if (isR6) {
3234 switch (cond) {
3235 case kCondEQ:
3236 __ CmpEqS(FTMP, lhs, rhs);
3237 __ Bc1nez(FTMP, label);
3238 break;
3239 case kCondNE:
3240 __ CmpEqS(FTMP, lhs, rhs);
3241 __ Bc1eqz(FTMP, label);
3242 break;
3243 case kCondLT:
3244 if (gt_bias) {
3245 __ CmpLtS(FTMP, lhs, rhs);
3246 } else {
3247 __ CmpUltS(FTMP, lhs, rhs);
3248 }
3249 __ Bc1nez(FTMP, label);
3250 break;
3251 case kCondLE:
3252 if (gt_bias) {
3253 __ CmpLeS(FTMP, lhs, rhs);
3254 } else {
3255 __ CmpUleS(FTMP, lhs, rhs);
3256 }
3257 __ Bc1nez(FTMP, label);
3258 break;
3259 case kCondGT:
3260 if (gt_bias) {
3261 __ CmpUltS(FTMP, rhs, lhs);
3262 } else {
3263 __ CmpLtS(FTMP, rhs, lhs);
3264 }
3265 __ Bc1nez(FTMP, label);
3266 break;
3267 case kCondGE:
3268 if (gt_bias) {
3269 __ CmpUleS(FTMP, rhs, lhs);
3270 } else {
3271 __ CmpLeS(FTMP, rhs, lhs);
3272 }
3273 __ Bc1nez(FTMP, label);
3274 break;
3275 default:
3276 LOG(FATAL) << "Unexpected non-floating-point condition";
3277 }
3278 } else {
3279 switch (cond) {
3280 case kCondEQ:
3281 __ CeqS(0, lhs, rhs);
3282 __ Bc1t(0, label);
3283 break;
3284 case kCondNE:
3285 __ CeqS(0, lhs, rhs);
3286 __ Bc1f(0, label);
3287 break;
3288 case kCondLT:
3289 if (gt_bias) {
3290 __ ColtS(0, lhs, rhs);
3291 } else {
3292 __ CultS(0, lhs, rhs);
3293 }
3294 __ Bc1t(0, label);
3295 break;
3296 case kCondLE:
3297 if (gt_bias) {
3298 __ ColeS(0, lhs, rhs);
3299 } else {
3300 __ CuleS(0, lhs, rhs);
3301 }
3302 __ Bc1t(0, label);
3303 break;
3304 case kCondGT:
3305 if (gt_bias) {
3306 __ CultS(0, rhs, lhs);
3307 } else {
3308 __ ColtS(0, rhs, lhs);
3309 }
3310 __ Bc1t(0, label);
3311 break;
3312 case kCondGE:
3313 if (gt_bias) {
3314 __ CuleS(0, rhs, lhs);
3315 } else {
3316 __ ColeS(0, rhs, lhs);
3317 }
3318 __ Bc1t(0, label);
3319 break;
3320 default:
3321 LOG(FATAL) << "Unexpected non-floating-point condition";
3322 }
3323 }
3324 } else {
3325 DCHECK_EQ(type, Primitive::kPrimDouble);
3326 if (isR6) {
3327 switch (cond) {
3328 case kCondEQ:
3329 __ CmpEqD(FTMP, lhs, rhs);
3330 __ Bc1nez(FTMP, label);
3331 break;
3332 case kCondNE:
3333 __ CmpEqD(FTMP, lhs, rhs);
3334 __ Bc1eqz(FTMP, label);
3335 break;
3336 case kCondLT:
3337 if (gt_bias) {
3338 __ CmpLtD(FTMP, lhs, rhs);
3339 } else {
3340 __ CmpUltD(FTMP, lhs, rhs);
3341 }
3342 __ Bc1nez(FTMP, label);
3343 break;
3344 case kCondLE:
3345 if (gt_bias) {
3346 __ CmpLeD(FTMP, lhs, rhs);
3347 } else {
3348 __ CmpUleD(FTMP, lhs, rhs);
3349 }
3350 __ Bc1nez(FTMP, label);
3351 break;
3352 case kCondGT:
3353 if (gt_bias) {
3354 __ CmpUltD(FTMP, rhs, lhs);
3355 } else {
3356 __ CmpLtD(FTMP, rhs, lhs);
3357 }
3358 __ Bc1nez(FTMP, label);
3359 break;
3360 case kCondGE:
3361 if (gt_bias) {
3362 __ CmpUleD(FTMP, rhs, lhs);
3363 } else {
3364 __ CmpLeD(FTMP, rhs, lhs);
3365 }
3366 __ Bc1nez(FTMP, label);
3367 break;
3368 default:
3369 LOG(FATAL) << "Unexpected non-floating-point condition";
3370 }
3371 } else {
3372 switch (cond) {
3373 case kCondEQ:
3374 __ CeqD(0, lhs, rhs);
3375 __ Bc1t(0, label);
3376 break;
3377 case kCondNE:
3378 __ CeqD(0, lhs, rhs);
3379 __ Bc1f(0, label);
3380 break;
3381 case kCondLT:
3382 if (gt_bias) {
3383 __ ColtD(0, lhs, rhs);
3384 } else {
3385 __ CultD(0, lhs, rhs);
3386 }
3387 __ Bc1t(0, label);
3388 break;
3389 case kCondLE:
3390 if (gt_bias) {
3391 __ ColeD(0, lhs, rhs);
3392 } else {
3393 __ CuleD(0, lhs, rhs);
3394 }
3395 __ Bc1t(0, label);
3396 break;
3397 case kCondGT:
3398 if (gt_bias) {
3399 __ CultD(0, rhs, lhs);
3400 } else {
3401 __ ColtD(0, rhs, lhs);
3402 }
3403 __ Bc1t(0, label);
3404 break;
3405 case kCondGE:
3406 if (gt_bias) {
3407 __ CuleD(0, rhs, lhs);
3408 } else {
3409 __ ColeD(0, rhs, lhs);
3410 }
3411 __ Bc1t(0, label);
3412 break;
3413 default:
3414 LOG(FATAL) << "Unexpected non-floating-point condition";
3415 }
3416 }
3417 }
3418}
3419
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003420void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00003421 size_t condition_input_index,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003422 MipsLabel* true_target,
David Brazdil0debae72015-11-12 18:37:00 +00003423 MipsLabel* false_target) {
3424 HInstruction* cond = instruction->InputAt(condition_input_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003425
David Brazdil0debae72015-11-12 18:37:00 +00003426 if (true_target == nullptr && false_target == nullptr) {
3427 // Nothing to do. The code always falls through.
3428 return;
3429 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00003430 // Constant condition, statically compared against "true" (integer value 1).
3431 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00003432 if (true_target != nullptr) {
3433 __ B(true_target);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003434 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003435 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00003436 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00003437 if (false_target != nullptr) {
3438 __ B(false_target);
3439 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003440 }
David Brazdil0debae72015-11-12 18:37:00 +00003441 return;
3442 }
3443
3444 // The following code generates these patterns:
3445 // (1) true_target == nullptr && false_target != nullptr
3446 // - opposite condition true => branch to false_target
3447 // (2) true_target != nullptr && false_target == nullptr
3448 // - condition true => branch to true_target
3449 // (3) true_target != nullptr && false_target != nullptr
3450 // - condition true => branch to true_target
3451 // - branch to false_target
3452 if (IsBooleanValueOrMaterializedCondition(cond)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003453 // The condition instruction has been materialized, compare the output to 0.
David Brazdil0debae72015-11-12 18:37:00 +00003454 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003455 DCHECK(cond_val.IsRegister());
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003456 if (true_target == nullptr) {
David Brazdil0debae72015-11-12 18:37:00 +00003457 __ Beqz(cond_val.AsRegister<Register>(), false_target);
3458 } else {
3459 __ Bnez(cond_val.AsRegister<Register>(), true_target);
3460 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003461 } else {
3462 // The condition instruction has not been materialized, use its inputs as
3463 // the comparison and its condition as the branch condition.
David Brazdil0debae72015-11-12 18:37:00 +00003464 HCondition* condition = cond->AsCondition();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003465 Primitive::Type type = condition->InputAt(0)->GetType();
3466 LocationSummary* locations = cond->GetLocations();
3467 IfCondition if_cond = condition->GetCondition();
3468 MipsLabel* branch_target = true_target;
David Brazdil0debae72015-11-12 18:37:00 +00003469
David Brazdil0debae72015-11-12 18:37:00 +00003470 if (true_target == nullptr) {
3471 if_cond = condition->GetOppositeCondition();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003472 branch_target = false_target;
David Brazdil0debae72015-11-12 18:37:00 +00003473 }
3474
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003475 switch (type) {
3476 default:
3477 GenerateIntCompareAndBranch(if_cond, locations, branch_target);
3478 break;
3479 case Primitive::kPrimLong:
3480 GenerateLongCompareAndBranch(if_cond, locations, branch_target);
3481 break;
3482 case Primitive::kPrimFloat:
3483 case Primitive::kPrimDouble:
3484 GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target);
3485 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003486 }
3487 }
David Brazdil0debae72015-11-12 18:37:00 +00003488
3489 // If neither branch falls through (case 3), the conditional branch to `true_target`
3490 // was already emitted (case 2) and we need to emit a jump to `false_target`.
3491 if (true_target != nullptr && false_target != nullptr) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003492 __ B(false_target);
3493 }
3494}
3495
3496void LocationsBuilderMIPS::VisitIf(HIf* if_instr) {
3497 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
David Brazdil0debae72015-11-12 18:37:00 +00003498 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003499 locations->SetInAt(0, Location::RequiresRegister());
3500 }
3501}
3502
3503void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00003504 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
3505 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
3506 MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
3507 nullptr : codegen_->GetLabelOf(true_successor);
3508 MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
3509 nullptr : codegen_->GetLabelOf(false_successor);
3510 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003511}
3512
3513void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) {
3514 LocationSummary* locations = new (GetGraph()->GetArena())
3515 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
David Brazdil0debae72015-11-12 18:37:00 +00003516 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003517 locations->SetInAt(0, Location::RequiresRegister());
3518 }
3519}
3520
3521void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08003522 SlowPathCodeMIPS* slow_path =
3523 deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00003524 GenerateTestAndBranch(deoptimize,
3525 /* condition_input_index */ 0,
3526 slow_path->GetEntryLabel(),
3527 /* false_target */ nullptr);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003528}
3529
David Brazdil74eb1b22015-12-14 11:44:01 +00003530void LocationsBuilderMIPS::VisitSelect(HSelect* select) {
3531 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select);
3532 if (Primitive::IsFloatingPointType(select->GetType())) {
3533 locations->SetInAt(0, Location::RequiresFpuRegister());
3534 locations->SetInAt(1, Location::RequiresFpuRegister());
3535 } else {
3536 locations->SetInAt(0, Location::RequiresRegister());
3537 locations->SetInAt(1, Location::RequiresRegister());
3538 }
3539 if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) {
3540 locations->SetInAt(2, Location::RequiresRegister());
3541 }
3542 locations->SetOut(Location::SameAsFirstInput());
3543}
3544
3545void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) {
3546 LocationSummary* locations = select->GetLocations();
3547 MipsLabel false_target;
3548 GenerateTestAndBranch(select,
3549 /* condition_input_index */ 2,
3550 /* true_target */ nullptr,
3551 &false_target);
3552 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
3553 __ Bind(&false_target);
3554}
3555
David Srbecky0cf44932015-12-09 14:09:59 +00003556void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) {
3557 new (GetGraph()->GetArena()) LocationSummary(info);
3558}
3559
David Srbeckyd28f4a02016-03-14 17:14:24 +00003560void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) {
3561 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00003562}
3563
3564void CodeGeneratorMIPS::GenerateNop() {
3565 __ Nop();
David Srbecky0cf44932015-12-09 14:09:59 +00003566}
3567
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003568void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3569 Primitive::Type field_type = field_info.GetFieldType();
3570 bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble);
3571 bool generate_volatile = field_info.IsVolatile() && is_wide;
3572 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003573 instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003574
3575 locations->SetInAt(0, Location::RequiresRegister());
3576 if (generate_volatile) {
3577 InvokeRuntimeCallingConvention calling_convention;
3578 // need A0 to hold base + offset
3579 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3580 if (field_type == Primitive::kPrimLong) {
3581 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimLong));
3582 } else {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02003583 // Use Location::Any() to prevent situations when running out of available fp registers.
3584 locations->SetOut(Location::Any());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003585 // Need some temp core regs since FP results are returned in core registers
3586 Location reg = calling_convention.GetReturnLocation(Primitive::kPrimLong);
3587 locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>()));
3588 locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>()));
3589 }
3590 } else {
3591 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3592 locations->SetOut(Location::RequiresFpuRegister());
3593 } else {
3594 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3595 }
3596 }
3597}
3598
3599void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction,
3600 const FieldInfo& field_info,
3601 uint32_t dex_pc) {
3602 Primitive::Type type = field_info.GetFieldType();
3603 LocationSummary* locations = instruction->GetLocations();
3604 Register obj = locations->InAt(0).AsRegister<Register>();
3605 LoadOperandType load_type = kLoadUnsignedByte;
3606 bool is_volatile = field_info.IsVolatile();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003607 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Alexey Frunze2923db72016-08-20 01:55:47 -07003608 auto null_checker = GetImplicitNullChecker(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003609
3610 switch (type) {
3611 case Primitive::kPrimBoolean:
3612 load_type = kLoadUnsignedByte;
3613 break;
3614 case Primitive::kPrimByte:
3615 load_type = kLoadSignedByte;
3616 break;
3617 case Primitive::kPrimShort:
3618 load_type = kLoadSignedHalfword;
3619 break;
3620 case Primitive::kPrimChar:
3621 load_type = kLoadUnsignedHalfword;
3622 break;
3623 case Primitive::kPrimInt:
3624 case Primitive::kPrimFloat:
3625 case Primitive::kPrimNot:
3626 load_type = kLoadWord;
3627 break;
3628 case Primitive::kPrimLong:
3629 case Primitive::kPrimDouble:
3630 load_type = kLoadDoubleword;
3631 break;
3632 case Primitive::kPrimVoid:
3633 LOG(FATAL) << "Unreachable type " << type;
3634 UNREACHABLE();
3635 }
3636
3637 if (is_volatile && load_type == kLoadDoubleword) {
3638 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003639 __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003640 // Do implicit Null check
3641 __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0);
3642 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3643 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pA64Load),
3644 instruction,
3645 dex_pc,
3646 nullptr,
3647 IsDirectEntrypoint(kQuickA64Load));
3648 CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>();
3649 if (type == Primitive::kPrimDouble) {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02003650 // FP results are returned in core registers. Need to move them.
3651 Location out = locations->Out();
3652 if (out.IsFpuRegister()) {
3653 __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), out.AsFpuRegister<FRegister>());
3654 __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(),
3655 out.AsFpuRegister<FRegister>());
3656 } else {
3657 DCHECK(out.IsDoubleStackSlot());
3658 __ StoreToOffset(kStoreWord,
3659 locations->GetTemp(1).AsRegister<Register>(),
3660 SP,
3661 out.GetStackIndex());
3662 __ StoreToOffset(kStoreWord,
3663 locations->GetTemp(2).AsRegister<Register>(),
3664 SP,
3665 out.GetStackIndex() + 4);
3666 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003667 }
3668 } else {
3669 if (!Primitive::IsFloatingPointType(type)) {
3670 Register dst;
3671 if (type == Primitive::kPrimLong) {
3672 DCHECK(locations->Out().IsRegisterPair());
3673 dst = locations->Out().AsRegisterPairLow<Register>();
3674 } else {
3675 DCHECK(locations->Out().IsRegister());
3676 dst = locations->Out().AsRegister<Register>();
3677 }
Alexey Frunze2923db72016-08-20 01:55:47 -07003678 __ LoadFromOffset(load_type, dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003679 } else {
3680 DCHECK(locations->Out().IsFpuRegister());
3681 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
3682 if (type == Primitive::kPrimFloat) {
Alexey Frunze2923db72016-08-20 01:55:47 -07003683 __ LoadSFromOffset(dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003684 } else {
Alexey Frunze2923db72016-08-20 01:55:47 -07003685 __ LoadDFromOffset(dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003686 }
3687 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003688 }
3689
3690 if (is_volatile) {
3691 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3692 }
3693}
3694
3695void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3696 Primitive::Type field_type = field_info.GetFieldType();
3697 bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble);
3698 bool generate_volatile = field_info.IsVolatile() && is_wide;
3699 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003700 instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003701
3702 locations->SetInAt(0, Location::RequiresRegister());
3703 if (generate_volatile) {
3704 InvokeRuntimeCallingConvention calling_convention;
3705 // need A0 to hold base + offset
3706 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3707 if (field_type == Primitive::kPrimLong) {
3708 locations->SetInAt(1, Location::RegisterPairLocation(
3709 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
3710 } else {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02003711 // Use Location::Any() to prevent situations when running out of available fp registers.
3712 locations->SetInAt(1, Location::Any());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003713 // Pass FP parameters in core registers.
3714 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
3715 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3)));
3716 }
3717 } else {
3718 if (Primitive::IsFloatingPointType(field_type)) {
3719 locations->SetInAt(1, Location::RequiresFpuRegister());
3720 } else {
3721 locations->SetInAt(1, Location::RequiresRegister());
3722 }
3723 }
3724}
3725
3726void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction,
3727 const FieldInfo& field_info,
3728 uint32_t dex_pc) {
3729 Primitive::Type type = field_info.GetFieldType();
3730 LocationSummary* locations = instruction->GetLocations();
3731 Register obj = locations->InAt(0).AsRegister<Register>();
3732 StoreOperandType store_type = kStoreByte;
3733 bool is_volatile = field_info.IsVolatile();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003734 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Alexey Frunze2923db72016-08-20 01:55:47 -07003735 auto null_checker = GetImplicitNullChecker(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003736
3737 switch (type) {
3738 case Primitive::kPrimBoolean:
3739 case Primitive::kPrimByte:
3740 store_type = kStoreByte;
3741 break;
3742 case Primitive::kPrimShort:
3743 case Primitive::kPrimChar:
3744 store_type = kStoreHalfword;
3745 break;
3746 case Primitive::kPrimInt:
3747 case Primitive::kPrimFloat:
3748 case Primitive::kPrimNot:
3749 store_type = kStoreWord;
3750 break;
3751 case Primitive::kPrimLong:
3752 case Primitive::kPrimDouble:
3753 store_type = kStoreDoubleword;
3754 break;
3755 case Primitive::kPrimVoid:
3756 LOG(FATAL) << "Unreachable type " << type;
3757 UNREACHABLE();
3758 }
3759
3760 if (is_volatile) {
3761 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3762 }
3763
3764 if (is_volatile && store_type == kStoreDoubleword) {
3765 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003766 __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003767 // Do implicit Null check.
3768 __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0);
3769 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3770 if (type == Primitive::kPrimDouble) {
3771 // Pass FP parameters in core registers.
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02003772 Location in = locations->InAt(1);
3773 if (in.IsFpuRegister()) {
3774 __ Mfc1(locations->GetTemp(1).AsRegister<Register>(), in.AsFpuRegister<FRegister>());
3775 __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(),
3776 in.AsFpuRegister<FRegister>());
3777 } else if (in.IsDoubleStackSlot()) {
3778 __ LoadFromOffset(kLoadWord,
3779 locations->GetTemp(1).AsRegister<Register>(),
3780 SP,
3781 in.GetStackIndex());
3782 __ LoadFromOffset(kLoadWord,
3783 locations->GetTemp(2).AsRegister<Register>(),
3784 SP,
3785 in.GetStackIndex() + 4);
3786 } else {
3787 DCHECK(in.IsConstant());
3788 DCHECK(in.GetConstant()->IsDoubleConstant());
3789 int64_t value = bit_cast<int64_t, double>(in.GetConstant()->AsDoubleConstant()->GetValue());
3790 __ LoadConst64(locations->GetTemp(2).AsRegister<Register>(),
3791 locations->GetTemp(1).AsRegister<Register>(),
3792 value);
3793 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003794 }
3795 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pA64Store),
3796 instruction,
3797 dex_pc,
3798 nullptr,
3799 IsDirectEntrypoint(kQuickA64Store));
3800 CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>();
3801 } else {
3802 if (!Primitive::IsFloatingPointType(type)) {
3803 Register src;
3804 if (type == Primitive::kPrimLong) {
3805 DCHECK(locations->InAt(1).IsRegisterPair());
3806 src = locations->InAt(1).AsRegisterPairLow<Register>();
3807 } else {
3808 DCHECK(locations->InAt(1).IsRegister());
3809 src = locations->InAt(1).AsRegister<Register>();
3810 }
Alexey Frunze2923db72016-08-20 01:55:47 -07003811 __ StoreToOffset(store_type, src, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003812 } else {
3813 DCHECK(locations->InAt(1).IsFpuRegister());
3814 FRegister src = locations->InAt(1).AsFpuRegister<FRegister>();
3815 if (type == Primitive::kPrimFloat) {
Alexey Frunze2923db72016-08-20 01:55:47 -07003816 __ StoreSToOffset(src, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003817 } else {
Alexey Frunze2923db72016-08-20 01:55:47 -07003818 __ StoreDToOffset(src, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003819 }
3820 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003821 }
3822
3823 // TODO: memory barriers?
3824 if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) {
3825 DCHECK(locations->InAt(1).IsRegister());
3826 Register src = locations->InAt(1).AsRegister<Register>();
3827 codegen_->MarkGCCard(obj, src);
3828 }
3829
3830 if (is_volatile) {
3831 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3832 }
3833}
3834
3835void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3836 HandleFieldGet(instruction, instruction->GetFieldInfo());
3837}
3838
3839void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3840 HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
3841}
3842
3843void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3844 HandleFieldSet(instruction, instruction->GetFieldInfo());
3845}
3846
3847void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3848 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
3849}
3850
Alexey Frunze06a46c42016-07-19 15:00:40 -07003851void InstructionCodeGeneratorMIPS::GenerateGcRootFieldLoad(
3852 HInstruction* instruction ATTRIBUTE_UNUSED,
3853 Location root,
3854 Register obj,
3855 uint32_t offset) {
3856 Register root_reg = root.AsRegister<Register>();
3857 if (kEmitCompilerReadBarrier) {
3858 UNIMPLEMENTED(FATAL) << "for read barrier";
3859 } else {
3860 // Plain GC root load with no read barrier.
3861 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
3862 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
3863 // Note that GC roots are not affected by heap poisoning, thus we
3864 // do not have to unpoison `root_reg` here.
3865 }
3866}
3867
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003868void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) {
3869 LocationSummary::CallKind call_kind =
3870 instruction->IsExactCheck() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
3871 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3872 locations->SetInAt(0, Location::RequiresRegister());
3873 locations->SetInAt(1, Location::RequiresRegister());
3874 // The output does overlap inputs.
3875 // Note that TypeCheckSlowPathMIPS uses this register too.
3876 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3877}
3878
3879void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) {
3880 LocationSummary* locations = instruction->GetLocations();
3881 Register obj = locations->InAt(0).AsRegister<Register>();
3882 Register cls = locations->InAt(1).AsRegister<Register>();
3883 Register out = locations->Out().AsRegister<Register>();
3884
3885 MipsLabel done;
3886
3887 // Return 0 if `obj` is null.
3888 // TODO: Avoid this check if we know `obj` is not null.
3889 __ Move(out, ZERO);
3890 __ Beqz(obj, &done);
3891
3892 // Compare the class of `obj` with `cls`.
3893 __ LoadFromOffset(kLoadWord, out, obj, mirror::Object::ClassOffset().Int32Value());
3894 if (instruction->IsExactCheck()) {
3895 // Classes must be equal for the instanceof to succeed.
3896 __ Xor(out, out, cls);
3897 __ Sltiu(out, out, 1);
3898 } else {
3899 // If the classes are not equal, we go into a slow path.
3900 DCHECK(locations->OnlyCallsOnSlowPath());
3901 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction);
3902 codegen_->AddSlowPath(slow_path);
3903 __ Bne(out, cls, slow_path->GetEntryLabel());
3904 __ LoadConst32(out, 1);
3905 __ Bind(slow_path->GetExitLabel());
3906 }
3907
3908 __ Bind(&done);
3909}
3910
3911void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) {
3912 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
3913 locations->SetOut(Location::ConstantLocation(constant));
3914}
3915
3916void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
3917 // Will be generated at use site.
3918}
3919
3920void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) {
3921 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
3922 locations->SetOut(Location::ConstantLocation(constant));
3923}
3924
3925void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
3926 // Will be generated at use site.
3927}
3928
3929void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) {
3930 InvokeDexCallingConventionVisitorMIPS calling_convention_visitor;
3931 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
3932}
3933
3934void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) {
3935 HandleInvoke(invoke);
3936 // The register T0 is required to be used for the hidden argument in
3937 // art_quick_imt_conflict_trampoline, so add the hidden argument.
3938 invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0));
3939}
3940
3941void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) {
3942 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
3943 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003944 Location receiver = invoke->GetLocations()->InAt(0);
3945 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07003946 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003947
3948 // Set the hidden argument.
3949 __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
3950 invoke->GetDexMethodIndex());
3951
3952 // temp = object->GetClass();
3953 if (receiver.IsStackSlot()) {
3954 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
3955 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
3956 } else {
3957 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
3958 }
3959 codegen_->MaybeRecordImplicitNullCheck(invoke);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00003960 __ LoadFromOffset(kLoadWord, temp, temp,
3961 mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value());
3962 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00003963 invoke->GetImtIndex(), kMipsPointerSize));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003964 // temp = temp->GetImtEntryAt(method_offset);
3965 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
3966 // T9 = temp->GetEntryPoint();
3967 __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value());
3968 // T9();
3969 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003970 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003971 DCHECK(!codegen_->IsLeafMethod());
3972 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
3973}
3974
3975void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Chris Larsen701566a2015-10-27 15:29:13 -07003976 IntrinsicLocationsBuilderMIPS intrinsic(codegen_);
3977 if (intrinsic.TryDispatch(invoke)) {
3978 return;
3979 }
3980
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003981 HandleInvoke(invoke);
3982}
3983
3984void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00003985 // Explicit clinit checks triggered by static invokes must have been pruned by
3986 // art::PrepareForRegisterAllocation.
3987 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003988
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003989 HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind();
3990 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation();
3991 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
3992
3993 // kDirectAddressWithFixup and kCallDirectWithFixup need no extra input on R6 because
3994 // R6 has PC-relative addressing.
3995 bool has_extra_input = !isR6 &&
3996 ((method_load_kind == HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) ||
3997 (code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup));
3998
3999 if (invoke->HasPcRelativeDexCache()) {
4000 // kDexCachePcRelative is mutually exclusive with
4001 // kDirectAddressWithFixup/kCallDirectWithFixup.
4002 CHECK(!has_extra_input);
4003 has_extra_input = true;
4004 }
4005
Chris Larsen701566a2015-10-27 15:29:13 -07004006 IntrinsicLocationsBuilderMIPS intrinsic(codegen_);
4007 if (intrinsic.TryDispatch(invoke)) {
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004008 if (invoke->GetLocations()->CanCall() && has_extra_input) {
4009 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any());
4010 }
Chris Larsen701566a2015-10-27 15:29:13 -07004011 return;
4012 }
4013
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004014 HandleInvoke(invoke);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004015
4016 // Add the extra input register if either the dex cache array base register
4017 // or the PC-relative base register for accessing literals is needed.
4018 if (has_extra_input) {
4019 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister());
4020 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004021}
4022
Chris Larsen701566a2015-10-27 15:29:13 -07004023static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004024 if (invoke->GetLocations()->Intrinsified()) {
Chris Larsen701566a2015-10-27 15:29:13 -07004025 IntrinsicCodeGeneratorMIPS intrinsic(codegen);
4026 intrinsic.Dispatch(invoke);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004027 return true;
4028 }
4029 return false;
4030}
4031
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004032HLoadString::LoadKind CodeGeneratorMIPS::GetSupportedLoadStringKind(
Alexey Frunze06a46c42016-07-19 15:00:40 -07004033 HLoadString::LoadKind desired_string_load_kind) {
4034 if (kEmitCompilerReadBarrier) {
4035 UNIMPLEMENTED(FATAL) << "for read barrier";
4036 }
4037 // We disable PC-relative load when there is an irreducible loop, as the optimization
4038 // is incompatible with it.
4039 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
4040 bool fallback_load = has_irreducible_loops;
4041 switch (desired_string_load_kind) {
4042 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
4043 DCHECK(!GetCompilerOptions().GetCompilePic());
4044 break;
4045 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
4046 DCHECK(GetCompilerOptions().GetCompilePic());
4047 break;
4048 case HLoadString::LoadKind::kBootImageAddress:
4049 break;
4050 case HLoadString::LoadKind::kDexCacheAddress:
4051 DCHECK(Runtime::Current()->UseJitCompilation());
4052 fallback_load = false;
4053 break;
4054 case HLoadString::LoadKind::kDexCachePcRelative:
4055 DCHECK(!Runtime::Current()->UseJitCompilation());
4056 // TODO: Create as many MipsDexCacheArraysBase instructions as needed for methods
4057 // with irreducible loops.
4058 break;
4059 case HLoadString::LoadKind::kDexCacheViaMethod:
4060 fallback_load = false;
4061 break;
4062 }
4063 if (fallback_load) {
4064 desired_string_load_kind = HLoadString::LoadKind::kDexCacheViaMethod;
4065 }
4066 return desired_string_load_kind;
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004067}
4068
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004069HLoadClass::LoadKind CodeGeneratorMIPS::GetSupportedLoadClassKind(
4070 HLoadClass::LoadKind desired_class_load_kind) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07004071 if (kEmitCompilerReadBarrier) {
4072 UNIMPLEMENTED(FATAL) << "for read barrier";
4073 }
4074 // We disable pc-relative load when there is an irreducible loop, as the optimization
4075 // is incompatible with it.
4076 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
4077 bool fallback_load = has_irreducible_loops;
4078 switch (desired_class_load_kind) {
4079 case HLoadClass::LoadKind::kReferrersClass:
4080 fallback_load = false;
4081 break;
4082 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
4083 DCHECK(!GetCompilerOptions().GetCompilePic());
4084 break;
4085 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
4086 DCHECK(GetCompilerOptions().GetCompilePic());
4087 break;
4088 case HLoadClass::LoadKind::kBootImageAddress:
4089 break;
4090 case HLoadClass::LoadKind::kDexCacheAddress:
4091 DCHECK(Runtime::Current()->UseJitCompilation());
4092 fallback_load = false;
4093 break;
4094 case HLoadClass::LoadKind::kDexCachePcRelative:
4095 DCHECK(!Runtime::Current()->UseJitCompilation());
4096 // TODO: Create as many MipsDexCacheArraysBase instructions as needed for methods
4097 // with irreducible loops.
4098 break;
4099 case HLoadClass::LoadKind::kDexCacheViaMethod:
4100 fallback_load = false;
4101 break;
4102 }
4103 if (fallback_load) {
4104 desired_class_load_kind = HLoadClass::LoadKind::kDexCacheViaMethod;
4105 }
4106 return desired_class_load_kind;
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004107}
4108
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004109Register CodeGeneratorMIPS::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke,
4110 Register temp) {
4111 CHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u);
4112 Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
4113 if (!invoke->GetLocations()->Intrinsified()) {
4114 return location.AsRegister<Register>();
4115 }
4116 // For intrinsics we allow any location, so it may be on the stack.
4117 if (!location.IsRegister()) {
4118 __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex());
4119 return temp;
4120 }
4121 // For register locations, check if the register was saved. If so, get it from the stack.
4122 // Note: There is a chance that the register was saved but not overwritten, so we could
4123 // save one load. However, since this is just an intrinsic slow path we prefer this
4124 // simple and more robust approach rather that trying to determine if that's the case.
4125 SlowPathCode* slow_path = GetCurrentSlowPath();
4126 DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path.
4127 if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) {
4128 int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>());
4129 __ LoadFromOffset(kLoadWord, temp, SP, stack_offset);
4130 return temp;
4131 }
4132 return location.AsRegister<Register>();
4133}
4134
Vladimir Markodc151b22015-10-15 18:02:30 +01004135HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch(
4136 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
4137 MethodReference target_method ATTRIBUTE_UNUSED) {
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004138 HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info;
4139 // We disable PC-relative load when there is an irreducible loop, as the optimization
4140 // is incompatible with it.
4141 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
4142 bool fallback_load = true;
4143 bool fallback_call = true;
4144 switch (dispatch_info.method_load_kind) {
Vladimir Markodc151b22015-10-15 18:02:30 +01004145 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
4146 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004147 fallback_load = has_irreducible_loops;
4148 break;
Vladimir Markodc151b22015-10-15 18:02:30 +01004149 default:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004150 fallback_load = false;
Vladimir Markodc151b22015-10-15 18:02:30 +01004151 break;
4152 }
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004153 switch (dispatch_info.code_ptr_location) {
Vladimir Markodc151b22015-10-15 18:02:30 +01004154 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004155 fallback_call = has_irreducible_loops;
4156 break;
Vladimir Markodc151b22015-10-15 18:02:30 +01004157 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004158 // TODO: Implement this type.
4159 break;
Vladimir Markodc151b22015-10-15 18:02:30 +01004160 default:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004161 fallback_call = false;
4162 break;
Vladimir Markodc151b22015-10-15 18:02:30 +01004163 }
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004164 if (fallback_load) {
4165 dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod;
4166 dispatch_info.method_load_data = 0;
4167 }
4168 if (fallback_call) {
4169 dispatch_info.code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod;
4170 dispatch_info.direct_code_ptr = 0;
4171 }
4172 return dispatch_info;
Vladimir Markodc151b22015-10-15 18:02:30 +01004173}
4174
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004175void CodeGeneratorMIPS::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
4176 // All registers are assumed to be correctly set up per the calling convention.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004177 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004178 HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind();
4179 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation();
4180 bool isR6 = isa_features_.IsR6();
4181 // kDirectAddressWithFixup and kCallDirectWithFixup have no extra input on R6 because
4182 // R6 has PC-relative addressing.
4183 bool has_extra_input = invoke->HasPcRelativeDexCache() ||
4184 (!isR6 &&
4185 ((method_load_kind == HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) ||
4186 (code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup)));
4187 Register base_reg = has_extra_input
4188 ? GetInvokeStaticOrDirectExtraParameter(invoke, temp.AsRegister<Register>())
4189 : ZERO;
4190
4191 // For better instruction scheduling we load the direct code pointer before the method pointer.
4192 switch (code_ptr_location) {
4193 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
4194 // T9 = invoke->GetDirectCodePtr();
4195 __ LoadConst32(T9, invoke->GetDirectCodePtr());
4196 break;
4197 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
4198 // T9 = code address from literal pool with link-time patch.
4199 __ LoadLiteral(T9, base_reg, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod()));
4200 break;
4201 default:
4202 break;
4203 }
4204
4205 switch (method_load_kind) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004206 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
4207 // temp = thread->string_init_entrypoint
4208 __ LoadFromOffset(kLoadWord,
4209 temp.AsRegister<Register>(),
4210 TR,
4211 invoke->GetStringInitOffset());
4212 break;
4213 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00004214 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004215 break;
4216 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
4217 __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress());
4218 break;
4219 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004220 __ LoadLiteral(temp.AsRegister<Register>(),
4221 base_reg,
4222 DeduplicateMethodAddressLiteral(invoke->GetTargetMethod()));
4223 break;
4224 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: {
4225 HMipsDexCacheArraysBase* base =
4226 invoke->InputAt(invoke->GetSpecialInputIndex())->AsMipsDexCacheArraysBase();
4227 int32_t offset =
4228 invoke->GetDexCacheArrayOffset() - base->GetElementOffset() - kDexCacheArrayLwOffset;
4229 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset);
4230 break;
4231 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004232 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
Vladimir Markoc53c0792015-11-19 15:48:33 +00004233 Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004234 Register reg = temp.AsRegister<Register>();
4235 Register method_reg;
4236 if (current_method.IsRegister()) {
4237 method_reg = current_method.AsRegister<Register>();
4238 } else {
4239 // TODO: use the appropriate DCHECK() here if possible.
4240 // DCHECK(invoke->GetLocations()->Intrinsified());
4241 DCHECK(!current_method.IsValid());
4242 method_reg = reg;
4243 __ Lw(reg, SP, kCurrentMethodStackOffset);
4244 }
4245
4246 // temp = temp->dex_cache_resolved_methods_;
4247 __ LoadFromOffset(kLoadWord,
4248 reg,
4249 method_reg,
4250 ArtMethod::DexCacheResolvedMethodsOffset(kMipsPointerSize).Int32Value());
Vladimir Marko40ecb122016-04-06 17:33:41 +01004251 // temp = temp[index_in_cache];
4252 // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file.
4253 uint32_t index_in_cache = invoke->GetDexMethodIndex();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004254 __ LoadFromOffset(kLoadWord,
4255 reg,
4256 reg,
4257 CodeGenerator::GetCachePointerOffset(index_in_cache));
4258 break;
4259 }
4260 }
4261
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004262 switch (code_ptr_location) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004263 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004264 __ Bal(&frame_entry_label_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004265 break;
4266 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004267 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
4268 // T9 prepared above for better instruction scheduling.
4269 // T9()
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004270 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004271 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004272 break;
Vladimir Markodc151b22015-10-15 18:02:30 +01004273 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004274 // TODO: Implement this type.
Vladimir Markodc151b22015-10-15 18:02:30 +01004275 // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch().
4276 LOG(FATAL) << "Unsupported";
4277 UNREACHABLE();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004278 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
4279 // T9 = callee_method->entry_point_from_quick_compiled_code_;
Goran Jakovljevic1a878372015-10-26 14:28:52 +01004280 __ LoadFromOffset(kLoadWord,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004281 T9,
4282 callee_method.AsRegister<Register>(),
4283 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07004284 kMipsPointerSize).Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004285 // T9()
4286 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004287 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004288 break;
4289 }
4290 DCHECK(!IsLeafMethod());
4291}
4292
4293void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00004294 // Explicit clinit checks triggered by static invokes must have been pruned by
4295 // art::PrepareForRegisterAllocation.
4296 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004297
4298 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
4299 return;
4300 }
4301
4302 LocationSummary* locations = invoke->GetLocations();
4303 codegen_->GenerateStaticOrDirectCall(invoke,
4304 locations->HasTemps()
4305 ? locations->GetTemp(0)
4306 : Location::NoLocation());
4307 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
4308}
4309
Chris Larsen3acee732015-11-18 13:31:08 -08004310void CodeGeneratorMIPS::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004311 LocationSummary* locations = invoke->GetLocations();
4312 Location receiver = locations->InAt(0);
Chris Larsen3acee732015-11-18 13:31:08 -08004313 Register temp = temp_location.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004314 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
4315 invoke->GetVTableIndex(), kMipsPointerSize).SizeValue();
4316 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07004317 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004318
4319 // temp = object->GetClass();
Chris Larsen3acee732015-11-18 13:31:08 -08004320 DCHECK(receiver.IsRegister());
4321 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
4322 MaybeRecordImplicitNullCheck(invoke);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004323 // temp = temp->GetMethodAt(method_offset);
4324 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
4325 // T9 = temp->GetEntryPoint();
4326 __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value());
4327 // T9();
4328 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004329 __ NopIfNoReordering();
Chris Larsen3acee732015-11-18 13:31:08 -08004330}
4331
4332void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) {
4333 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
4334 return;
4335 }
4336
4337 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004338 DCHECK(!codegen_->IsLeafMethod());
4339 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
4340}
4341
4342void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07004343 if (cls->NeedsAccessCheck()) {
4344 InvokeRuntimeCallingConvention calling_convention;
4345 CodeGenerator::CreateLoadClassLocationSummary(
4346 cls,
4347 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
4348 Location::RegisterLocation(V0),
4349 /* code_generator_supports_read_barrier */ false); // TODO: revisit this bool.
4350 return;
4351 }
4352
4353 LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier)
4354 ? LocationSummary::kCallOnSlowPath
4355 : LocationSummary::kNoCall;
4356 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
4357 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
4358 switch (load_kind) {
4359 // We need an extra register for PC-relative literals on R2.
4360 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
4361 case HLoadClass::LoadKind::kBootImageAddress:
4362 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
4363 if (codegen_->GetInstructionSetFeatures().IsR6()) {
4364 break;
4365 }
4366 FALLTHROUGH_INTENDED;
4367 // We need an extra register for PC-relative dex cache accesses.
4368 case HLoadClass::LoadKind::kDexCachePcRelative:
4369 case HLoadClass::LoadKind::kReferrersClass:
4370 case HLoadClass::LoadKind::kDexCacheViaMethod:
4371 locations->SetInAt(0, Location::RequiresRegister());
4372 break;
4373 default:
4374 break;
4375 }
4376 locations->SetOut(Location::RequiresRegister());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004377}
4378
4379void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) {
4380 LocationSummary* locations = cls->GetLocations();
Pavle Batutae87a7182015-10-28 13:10:42 +01004381 if (cls->NeedsAccessCheck()) {
4382 codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex());
4383 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess),
4384 cls,
4385 cls->GetDexPc(),
4386 nullptr,
4387 IsDirectEntrypoint(kQuickInitializeTypeAndVerifyAccess));
Roland Levillain888d0672015-11-23 18:53:50 +00004388 CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>();
Pavle Batutae87a7182015-10-28 13:10:42 +01004389 return;
4390 }
4391
Alexey Frunze06a46c42016-07-19 15:00:40 -07004392 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
4393 Location out_loc = locations->Out();
4394 Register out = out_loc.AsRegister<Register>();
4395 Register base_or_current_method_reg;
4396 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
4397 switch (load_kind) {
4398 // We need an extra register for PC-relative literals on R2.
4399 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
4400 case HLoadClass::LoadKind::kBootImageAddress:
4401 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
4402 base_or_current_method_reg = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>();
4403 break;
4404 // We need an extra register for PC-relative dex cache accesses.
4405 case HLoadClass::LoadKind::kDexCachePcRelative:
4406 case HLoadClass::LoadKind::kReferrersClass:
4407 case HLoadClass::LoadKind::kDexCacheViaMethod:
4408 base_or_current_method_reg = locations->InAt(0).AsRegister<Register>();
4409 break;
4410 default:
4411 base_or_current_method_reg = ZERO;
4412 break;
4413 }
Nicolas Geoffray42e372e2015-11-24 15:48:56 +00004414
Alexey Frunze06a46c42016-07-19 15:00:40 -07004415 bool generate_null_check = false;
4416 switch (load_kind) {
4417 case HLoadClass::LoadKind::kReferrersClass: {
4418 DCHECK(!cls->CanCallRuntime());
4419 DCHECK(!cls->MustGenerateClinitCheck());
4420 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
4421 GenerateGcRootFieldLoad(cls,
4422 out_loc,
4423 base_or_current_method_reg,
4424 ArtMethod::DeclaringClassOffset().Int32Value());
4425 break;
4426 }
4427 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
4428 DCHECK(!kEmitCompilerReadBarrier);
4429 __ LoadLiteral(out,
4430 base_or_current_method_reg,
4431 codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(),
4432 cls->GetTypeIndex()));
4433 break;
4434 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: {
4435 DCHECK(!kEmitCompilerReadBarrier);
4436 CodeGeneratorMIPS::PcRelativePatchInfo* info =
4437 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004438 bool reordering = __ SetReorder(false);
Alexey Frunze06a46c42016-07-19 15:00:40 -07004439 if (isR6) {
4440 __ Bind(&info->high_label);
4441 __ Bind(&info->pc_rel_label);
4442 // Add a 32-bit offset to PC.
4443 __ Auipc(out, /* placeholder */ 0x1234);
4444 __ Addiu(out, out, /* placeholder */ 0x5678);
Nicolas Geoffray42e372e2015-11-24 15:48:56 +00004445 } else {
Alexey Frunze06a46c42016-07-19 15:00:40 -07004446 __ Bind(&info->high_label);
4447 __ Lui(out, /* placeholder */ 0x1234);
4448 // We do not bind info->pc_rel_label here, we'll use the assembler's label
4449 // for PC-relative literals and the base from HMipsComputeBaseMethodAddress.
4450 __ Ori(out, out, /* placeholder */ 0x5678);
4451 // Add a 32-bit offset to PC.
4452 __ Addu(out, out, base_or_current_method_reg);
Nicolas Geoffray42e372e2015-11-24 15:48:56 +00004453 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004454 __ SetReorder(reordering);
Alexey Frunze06a46c42016-07-19 15:00:40 -07004455 break;
4456 }
4457 case HLoadClass::LoadKind::kBootImageAddress: {
4458 DCHECK(!kEmitCompilerReadBarrier);
4459 DCHECK_NE(cls->GetAddress(), 0u);
4460 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
4461 __ LoadLiteral(out,
4462 base_or_current_method_reg,
4463 codegen_->DeduplicateBootImageAddressLiteral(address));
4464 break;
4465 }
4466 case HLoadClass::LoadKind::kDexCacheAddress: {
4467 DCHECK_NE(cls->GetAddress(), 0u);
4468 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
4469 static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes.");
4470 DCHECK_ALIGNED(cls->GetAddress(), 4u);
4471 int16_t offset = Low16Bits(address);
4472 uint32_t base_address = address - offset; // This accounts for offset sign extension.
4473 __ Lui(out, High16Bits(base_address));
4474 // /* GcRoot<mirror::Class> */ out = *(base_address + offset)
4475 GenerateGcRootFieldLoad(cls, out_loc, out, offset);
4476 generate_null_check = !cls->IsInDexCache();
4477 break;
4478 }
4479 case HLoadClass::LoadKind::kDexCachePcRelative: {
4480 HMipsDexCacheArraysBase* base = cls->InputAt(0)->AsMipsDexCacheArraysBase();
4481 int32_t offset =
4482 cls->GetDexCacheElementOffset() - base->GetElementOffset() - kDexCacheArrayLwOffset;
4483 // /* GcRoot<mirror::Class> */ out = *(dex_cache_arrays_base + offset)
4484 GenerateGcRootFieldLoad(cls, out_loc, base_or_current_method_reg, offset);
4485 generate_null_check = !cls->IsInDexCache();
4486 break;
4487 }
4488 case HLoadClass::LoadKind::kDexCacheViaMethod: {
4489 // /* GcRoot<mirror::Class>[] */ out =
4490 // current_method.ptr_sized_fields_->dex_cache_resolved_types_
4491 __ LoadFromOffset(kLoadWord,
4492 out,
4493 base_or_current_method_reg,
4494 ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value());
4495 // /* GcRoot<mirror::Class> */ out = out[type_index]
4496 size_t offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex());
4497 GenerateGcRootFieldLoad(cls, out_loc, out, offset);
4498 generate_null_check = !cls->IsInDexCache();
4499 }
4500 }
4501
4502 if (generate_null_check || cls->MustGenerateClinitCheck()) {
4503 DCHECK(cls->CanCallRuntime());
4504 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS(
4505 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
4506 codegen_->AddSlowPath(slow_path);
4507 if (generate_null_check) {
4508 __ Beqz(out, slow_path->GetEntryLabel());
4509 }
4510 if (cls->MustGenerateClinitCheck()) {
4511 GenerateClassInitializationCheck(slow_path, out);
4512 } else {
4513 __ Bind(slow_path->GetExitLabel());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004514 }
4515 }
4516}
4517
4518static int32_t GetExceptionTlsOffset() {
Andreas Gampe542451c2016-07-26 09:02:02 -07004519 return Thread::ExceptionOffset<kMipsPointerSize>().Int32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004520}
4521
4522void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) {
4523 LocationSummary* locations =
4524 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4525 locations->SetOut(Location::RequiresRegister());
4526}
4527
4528void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) {
4529 Register out = load->GetLocations()->Out().AsRegister<Register>();
4530 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
4531}
4532
4533void LocationsBuilderMIPS::VisitClearException(HClearException* clear) {
4534 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
4535}
4536
4537void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
4538 __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset());
4539}
4540
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004541void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07004542 LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier)
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004543 ? LocationSummary::kCallOnSlowPath
4544 : LocationSummary::kNoCall;
Nicolas Geoffray917d0162015-11-24 18:25:35 +00004545 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind);
Alexey Frunze06a46c42016-07-19 15:00:40 -07004546 HLoadString::LoadKind load_kind = load->GetLoadKind();
4547 switch (load_kind) {
4548 // We need an extra register for PC-relative literals on R2.
4549 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
4550 case HLoadString::LoadKind::kBootImageAddress:
4551 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
4552 if (codegen_->GetInstructionSetFeatures().IsR6()) {
4553 break;
4554 }
4555 FALLTHROUGH_INTENDED;
4556 // We need an extra register for PC-relative dex cache accesses.
4557 case HLoadString::LoadKind::kDexCachePcRelative:
4558 case HLoadString::LoadKind::kDexCacheViaMethod:
4559 locations->SetInAt(0, Location::RequiresRegister());
4560 break;
4561 default:
4562 break;
4563 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004564 locations->SetOut(Location::RequiresRegister());
4565}
4566
4567void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07004568 HLoadString::LoadKind load_kind = load->GetLoadKind();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004569 LocationSummary* locations = load->GetLocations();
Alexey Frunze06a46c42016-07-19 15:00:40 -07004570 Location out_loc = locations->Out();
4571 Register out = out_loc.AsRegister<Register>();
4572 Register base_or_current_method_reg;
4573 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
4574 switch (load_kind) {
4575 // We need an extra register for PC-relative literals on R2.
4576 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
4577 case HLoadString::LoadKind::kBootImageAddress:
4578 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
4579 base_or_current_method_reg = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>();
4580 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07004581 default:
4582 base_or_current_method_reg = ZERO;
4583 break;
4584 }
4585
4586 switch (load_kind) {
4587 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
4588 DCHECK(!kEmitCompilerReadBarrier);
4589 __ LoadLiteral(out,
4590 base_or_current_method_reg,
4591 codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(),
4592 load->GetStringIndex()));
4593 return; // No dex cache slow path.
4594 case HLoadString::LoadKind::kBootImageLinkTimePcRelative: {
4595 DCHECK(!kEmitCompilerReadBarrier);
4596 CodeGeneratorMIPS::PcRelativePatchInfo* info =
4597 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004598 bool reordering = __ SetReorder(false);
Alexey Frunze06a46c42016-07-19 15:00:40 -07004599 if (isR6) {
4600 __ Bind(&info->high_label);
4601 __ Bind(&info->pc_rel_label);
4602 // Add a 32-bit offset to PC.
4603 __ Auipc(out, /* placeholder */ 0x1234);
4604 __ Addiu(out, out, /* placeholder */ 0x5678);
4605 } else {
4606 __ Bind(&info->high_label);
4607 __ Lui(out, /* placeholder */ 0x1234);
4608 // We do not bind info->pc_rel_label here, we'll use the assembler's label
4609 // for PC-relative literals and the base from HMipsComputeBaseMethodAddress.
4610 __ Ori(out, out, /* placeholder */ 0x5678);
4611 // Add a 32-bit offset to PC.
4612 __ Addu(out, out, base_or_current_method_reg);
4613 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004614 __ SetReorder(reordering);
Alexey Frunze06a46c42016-07-19 15:00:40 -07004615 return; // No dex cache slow path.
4616 }
4617 case HLoadString::LoadKind::kBootImageAddress: {
4618 DCHECK(!kEmitCompilerReadBarrier);
4619 DCHECK_NE(load->GetAddress(), 0u);
4620 uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress());
4621 __ LoadLiteral(out,
4622 base_or_current_method_reg,
4623 codegen_->DeduplicateBootImageAddressLiteral(address));
4624 return; // No dex cache slow path.
4625 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07004626 default:
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07004627 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07004628 }
Nicolas Geoffray917d0162015-11-24 18:25:35 +00004629
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07004630 // TODO: Re-add the compiler code to do string dex cache lookup again.
4631 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS(load);
4632 codegen_->AddSlowPath(slow_path);
4633 __ B(slow_path->GetEntryLabel());
4634 __ Bind(slow_path->GetExitLabel());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004635}
4636
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004637void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) {
4638 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
4639 locations->SetOut(Location::ConstantLocation(constant));
4640}
4641
4642void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
4643 // Will be generated at use site.
4644}
4645
4646void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) {
4647 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004648 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004649 InvokeRuntimeCallingConvention calling_convention;
4650 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4651}
4652
4653void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) {
4654 if (instruction->IsEnter()) {
4655 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLockObject),
4656 instruction,
4657 instruction->GetDexPc(),
4658 nullptr,
4659 IsDirectEntrypoint(kQuickLockObject));
4660 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
4661 } else {
4662 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pUnlockObject),
4663 instruction,
4664 instruction->GetDexPc(),
4665 nullptr,
4666 IsDirectEntrypoint(kQuickUnlockObject));
4667 }
4668 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
4669}
4670
4671void LocationsBuilderMIPS::VisitMul(HMul* mul) {
4672 LocationSummary* locations =
4673 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
4674 switch (mul->GetResultType()) {
4675 case Primitive::kPrimInt:
4676 case Primitive::kPrimLong:
4677 locations->SetInAt(0, Location::RequiresRegister());
4678 locations->SetInAt(1, Location::RequiresRegister());
4679 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4680 break;
4681
4682 case Primitive::kPrimFloat:
4683 case Primitive::kPrimDouble:
4684 locations->SetInAt(0, Location::RequiresFpuRegister());
4685 locations->SetInAt(1, Location::RequiresFpuRegister());
4686 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
4687 break;
4688
4689 default:
4690 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
4691 }
4692}
4693
4694void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) {
4695 Primitive::Type type = instruction->GetType();
4696 LocationSummary* locations = instruction->GetLocations();
4697 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
4698
4699 switch (type) {
4700 case Primitive::kPrimInt: {
4701 Register dst = locations->Out().AsRegister<Register>();
4702 Register lhs = locations->InAt(0).AsRegister<Register>();
4703 Register rhs = locations->InAt(1).AsRegister<Register>();
4704
4705 if (isR6) {
4706 __ MulR6(dst, lhs, rhs);
4707 } else {
4708 __ MulR2(dst, lhs, rhs);
4709 }
4710 break;
4711 }
4712 case Primitive::kPrimLong: {
4713 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
4714 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
4715 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4716 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
4717 Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>();
4718 Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>();
4719
4720 // Extra checks to protect caused by the existance of A1_A2.
4721 // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo:
4722 // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2).
4723 DCHECK_NE(dst_high, lhs_low);
4724 DCHECK_NE(dst_high, rhs_low);
4725
4726 // A_B * C_D
4727 // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ]
4728 // dst_lo: [ low(B*D) ]
4729 // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result.
4730
4731 if (isR6) {
4732 __ MulR6(TMP, lhs_high, rhs_low);
4733 __ MulR6(dst_high, lhs_low, rhs_high);
4734 __ Addu(dst_high, dst_high, TMP);
4735 __ MuhuR6(TMP, lhs_low, rhs_low);
4736 __ Addu(dst_high, dst_high, TMP);
4737 __ MulR6(dst_low, lhs_low, rhs_low);
4738 } else {
4739 __ MulR2(TMP, lhs_high, rhs_low);
4740 __ MulR2(dst_high, lhs_low, rhs_high);
4741 __ Addu(dst_high, dst_high, TMP);
4742 __ MultuR2(lhs_low, rhs_low);
4743 __ Mfhi(TMP);
4744 __ Addu(dst_high, dst_high, TMP);
4745 __ Mflo(dst_low);
4746 }
4747 break;
4748 }
4749 case Primitive::kPrimFloat:
4750 case Primitive::kPrimDouble: {
4751 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
4752 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
4753 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
4754 if (type == Primitive::kPrimFloat) {
4755 __ MulS(dst, lhs, rhs);
4756 } else {
4757 __ MulD(dst, lhs, rhs);
4758 }
4759 break;
4760 }
4761 default:
4762 LOG(FATAL) << "Unexpected mul type " << type;
4763 }
4764}
4765
4766void LocationsBuilderMIPS::VisitNeg(HNeg* neg) {
4767 LocationSummary* locations =
4768 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
4769 switch (neg->GetResultType()) {
4770 case Primitive::kPrimInt:
4771 case Primitive::kPrimLong:
4772 locations->SetInAt(0, Location::RequiresRegister());
4773 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4774 break;
4775
4776 case Primitive::kPrimFloat:
4777 case Primitive::kPrimDouble:
4778 locations->SetInAt(0, Location::RequiresFpuRegister());
4779 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
4780 break;
4781
4782 default:
4783 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
4784 }
4785}
4786
4787void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) {
4788 Primitive::Type type = instruction->GetType();
4789 LocationSummary* locations = instruction->GetLocations();
4790
4791 switch (type) {
4792 case Primitive::kPrimInt: {
4793 Register dst = locations->Out().AsRegister<Register>();
4794 Register src = locations->InAt(0).AsRegister<Register>();
4795 __ Subu(dst, ZERO, src);
4796 break;
4797 }
4798 case Primitive::kPrimLong: {
4799 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
4800 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
4801 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4802 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
4803 __ Subu(dst_low, ZERO, src_low);
4804 __ Sltu(TMP, ZERO, dst_low);
4805 __ Subu(dst_high, ZERO, src_high);
4806 __ Subu(dst_high, dst_high, TMP);
4807 break;
4808 }
4809 case Primitive::kPrimFloat:
4810 case Primitive::kPrimDouble: {
4811 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
4812 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
4813 if (type == Primitive::kPrimFloat) {
4814 __ NegS(dst, src);
4815 } else {
4816 __ NegD(dst, src);
4817 }
4818 break;
4819 }
4820 default:
4821 LOG(FATAL) << "Unexpected neg type " << type;
4822 }
4823}
4824
4825void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) {
4826 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004827 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004828 InvokeRuntimeCallingConvention calling_convention;
4829 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4830 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
4831 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
4832 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
4833}
4834
4835void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) {
4836 InvokeRuntimeCallingConvention calling_convention;
4837 Register current_method_register = calling_convention.GetRegisterAt(2);
4838 __ Lw(current_method_register, SP, kCurrentMethodStackOffset);
4839 // Move an uint16_t value to a register.
4840 __ LoadConst32(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
4841 codegen_->InvokeRuntime(
Andreas Gampe542451c2016-07-26 09:02:02 -07004842 GetThreadOffset<kMipsPointerSize>(instruction->GetEntrypoint()).Int32Value(),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004843 instruction,
4844 instruction->GetDexPc(),
4845 nullptr,
4846 IsDirectEntrypoint(kQuickAllocArrayWithAccessCheck));
4847 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
4848 void*, uint32_t, int32_t, ArtMethod*>();
4849}
4850
4851void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) {
4852 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004853 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004854 InvokeRuntimeCallingConvention calling_convention;
David Brazdil6de19382016-01-08 17:37:10 +00004855 if (instruction->IsStringAlloc()) {
4856 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
4857 } else {
4858 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4859 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
4860 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004861 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
4862}
4863
4864void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) {
David Brazdil6de19382016-01-08 17:37:10 +00004865 if (instruction->IsStringAlloc()) {
4866 // String is allocated through StringFactory. Call NewEmptyString entry point.
4867 Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>();
Andreas Gampe542451c2016-07-26 09:02:02 -07004868 MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
David Brazdil6de19382016-01-08 17:37:10 +00004869 __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
4870 __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value());
4871 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004872 __ NopIfNoReordering();
David Brazdil6de19382016-01-08 17:37:10 +00004873 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
4874 } else {
4875 codegen_->InvokeRuntime(
Andreas Gampe542451c2016-07-26 09:02:02 -07004876 GetThreadOffset<kMipsPointerSize>(instruction->GetEntrypoint()).Int32Value(),
David Brazdil6de19382016-01-08 17:37:10 +00004877 instruction,
4878 instruction->GetDexPc(),
4879 nullptr,
4880 IsDirectEntrypoint(kQuickAllocObjectWithAccessCheck));
4881 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
4882 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004883}
4884
4885void LocationsBuilderMIPS::VisitNot(HNot* instruction) {
4886 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
4887 locations->SetInAt(0, Location::RequiresRegister());
4888 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4889}
4890
4891void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) {
4892 Primitive::Type type = instruction->GetType();
4893 LocationSummary* locations = instruction->GetLocations();
4894
4895 switch (type) {
4896 case Primitive::kPrimInt: {
4897 Register dst = locations->Out().AsRegister<Register>();
4898 Register src = locations->InAt(0).AsRegister<Register>();
4899 __ Nor(dst, src, ZERO);
4900 break;
4901 }
4902
4903 case Primitive::kPrimLong: {
4904 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
4905 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
4906 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4907 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
4908 __ Nor(dst_high, src_high, ZERO);
4909 __ Nor(dst_low, src_low, ZERO);
4910 break;
4911 }
4912
4913 default:
4914 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
4915 }
4916}
4917
4918void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) {
4919 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
4920 locations->SetInAt(0, Location::RequiresRegister());
4921 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4922}
4923
4924void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) {
4925 LocationSummary* locations = instruction->GetLocations();
4926 __ Xori(locations->Out().AsRegister<Register>(),
4927 locations->InAt(0).AsRegister<Register>(),
4928 1);
4929}
4930
4931void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) {
4932 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
4933 ? LocationSummary::kCallOnSlowPath
4934 : LocationSummary::kNoCall;
4935 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
4936 locations->SetInAt(0, Location::RequiresRegister());
4937 if (instruction->HasUses()) {
4938 locations->SetOut(Location::SameAsFirstInput());
4939 }
4940}
4941
Calin Juravle2ae48182016-03-16 14:05:09 +00004942void CodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) {
4943 if (CanMoveNullCheckToUser(instruction)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004944 return;
4945 }
4946 Location obj = instruction->GetLocations()->InAt(0);
4947
4948 __ Lw(ZERO, obj.AsRegister<Register>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00004949 RecordPcInfo(instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004950}
4951
Calin Juravle2ae48182016-03-16 14:05:09 +00004952void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004953 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00004954 AddSlowPath(slow_path);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004955
4956 Location obj = instruction->GetLocations()->InAt(0);
4957
4958 __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
4959}
4960
4961void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00004962 codegen_->GenerateNullCheck(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004963}
4964
4965void LocationsBuilderMIPS::VisitOr(HOr* instruction) {
4966 HandleBinaryOp(instruction);
4967}
4968
4969void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) {
4970 HandleBinaryOp(instruction);
4971}
4972
4973void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
4974 LOG(FATAL) << "Unreachable";
4975}
4976
4977void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) {
4978 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
4979}
4980
4981void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) {
4982 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
4983 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
4984 if (location.IsStackSlot()) {
4985 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
4986 } else if (location.IsDoubleStackSlot()) {
4987 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
4988 }
4989 locations->SetOut(location);
4990}
4991
4992void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction
4993 ATTRIBUTE_UNUSED) {
4994 // Nothing to do, the parameter is already at its location.
4995}
4996
4997void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) {
4998 LocationSummary* locations =
4999 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
5000 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
5001}
5002
5003void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction
5004 ATTRIBUTE_UNUSED) {
5005 // Nothing to do, the method is already at its location.
5006}
5007
5008void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) {
5009 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Vladimir Marko372f10e2016-05-17 16:30:10 +01005010 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005011 locations->SetInAt(i, Location::Any());
5012 }
5013 locations->SetOut(Location::Any());
5014}
5015
5016void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
5017 LOG(FATAL) << "Unreachable";
5018}
5019
5020void LocationsBuilderMIPS::VisitRem(HRem* rem) {
5021 Primitive::Type type = rem->GetResultType();
5022 LocationSummary::CallKind call_kind =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01005023 (type == Primitive::kPrimInt) ? LocationSummary::kNoCall : LocationSummary::kCallOnMainOnly;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005024 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
5025
5026 switch (type) {
5027 case Primitive::kPrimInt:
5028 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze7e99e052015-11-24 19:28:01 -08005029 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005030 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
5031 break;
5032
5033 case Primitive::kPrimLong: {
5034 InvokeRuntimeCallingConvention calling_convention;
5035 locations->SetInAt(0, Location::RegisterPairLocation(
5036 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
5037 locations->SetInAt(1, Location::RegisterPairLocation(
5038 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
5039 locations->SetOut(calling_convention.GetReturnLocation(type));
5040 break;
5041 }
5042
5043 case Primitive::kPrimFloat:
5044 case Primitive::kPrimDouble: {
5045 InvokeRuntimeCallingConvention calling_convention;
5046 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
5047 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
5048 locations->SetOut(calling_convention.GetReturnLocation(type));
5049 break;
5050 }
5051
5052 default:
5053 LOG(FATAL) << "Unexpected rem type " << type;
5054 }
5055}
5056
5057void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) {
5058 Primitive::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005059
5060 switch (type) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08005061 case Primitive::kPrimInt:
5062 GenerateDivRemIntegral(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005063 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005064 case Primitive::kPrimLong: {
5065 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod),
5066 instruction,
5067 instruction->GetDexPc(),
5068 nullptr,
5069 IsDirectEntrypoint(kQuickLmod));
5070 CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>();
5071 break;
5072 }
5073 case Primitive::kPrimFloat: {
5074 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf),
5075 instruction, instruction->GetDexPc(),
5076 nullptr,
5077 IsDirectEntrypoint(kQuickFmodf));
Roland Levillain888d0672015-11-23 18:53:50 +00005078 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005079 break;
5080 }
5081 case Primitive::kPrimDouble: {
5082 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod),
5083 instruction, instruction->GetDexPc(),
5084 nullptr,
5085 IsDirectEntrypoint(kQuickFmod));
Roland Levillain888d0672015-11-23 18:53:50 +00005086 CheckEntrypointTypes<kQuickFmod, double, double, double>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005087 break;
5088 }
5089 default:
5090 LOG(FATAL) << "Unexpected rem type " << type;
5091 }
5092}
5093
5094void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
5095 memory_barrier->SetLocations(nullptr);
5096}
5097
5098void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
5099 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
5100}
5101
5102void LocationsBuilderMIPS::VisitReturn(HReturn* ret) {
5103 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret);
5104 Primitive::Type return_type = ret->InputAt(0)->GetType();
5105 locations->SetInAt(0, MipsReturnLocation(return_type));
5106}
5107
5108void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
5109 codegen_->GenerateFrameExit();
5110}
5111
5112void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) {
5113 ret->SetLocations(nullptr);
5114}
5115
5116void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
5117 codegen_->GenerateFrameExit();
5118}
5119
Alexey Frunze92d90602015-12-18 18:16:36 -08005120void LocationsBuilderMIPS::VisitRor(HRor* ror) {
5121 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00005122}
5123
Alexey Frunze92d90602015-12-18 18:16:36 -08005124void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) {
5125 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00005126}
5127
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005128void LocationsBuilderMIPS::VisitShl(HShl* shl) {
5129 HandleShift(shl);
5130}
5131
5132void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) {
5133 HandleShift(shl);
5134}
5135
5136void LocationsBuilderMIPS::VisitShr(HShr* shr) {
5137 HandleShift(shr);
5138}
5139
5140void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) {
5141 HandleShift(shr);
5142}
5143
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005144void LocationsBuilderMIPS::VisitSub(HSub* instruction) {
5145 HandleBinaryOp(instruction);
5146}
5147
5148void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) {
5149 HandleBinaryOp(instruction);
5150}
5151
5152void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) {
5153 HandleFieldGet(instruction, instruction->GetFieldInfo());
5154}
5155
5156void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) {
5157 HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
5158}
5159
5160void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) {
5161 HandleFieldSet(instruction, instruction->GetFieldInfo());
5162}
5163
5164void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) {
5165 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
5166}
5167
5168void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet(
5169 HUnresolvedInstanceFieldGet* instruction) {
5170 FieldAccessCallingConventionMIPS calling_convention;
5171 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
5172 instruction->GetFieldType(),
5173 calling_convention);
5174}
5175
5176void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet(
5177 HUnresolvedInstanceFieldGet* instruction) {
5178 FieldAccessCallingConventionMIPS calling_convention;
5179 codegen_->GenerateUnresolvedFieldAccess(instruction,
5180 instruction->GetFieldType(),
5181 instruction->GetFieldIndex(),
5182 instruction->GetDexPc(),
5183 calling_convention);
5184}
5185
5186void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet(
5187 HUnresolvedInstanceFieldSet* instruction) {
5188 FieldAccessCallingConventionMIPS calling_convention;
5189 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
5190 instruction->GetFieldType(),
5191 calling_convention);
5192}
5193
5194void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet(
5195 HUnresolvedInstanceFieldSet* instruction) {
5196 FieldAccessCallingConventionMIPS calling_convention;
5197 codegen_->GenerateUnresolvedFieldAccess(instruction,
5198 instruction->GetFieldType(),
5199 instruction->GetFieldIndex(),
5200 instruction->GetDexPc(),
5201 calling_convention);
5202}
5203
5204void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet(
5205 HUnresolvedStaticFieldGet* instruction) {
5206 FieldAccessCallingConventionMIPS calling_convention;
5207 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
5208 instruction->GetFieldType(),
5209 calling_convention);
5210}
5211
5212void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet(
5213 HUnresolvedStaticFieldGet* instruction) {
5214 FieldAccessCallingConventionMIPS calling_convention;
5215 codegen_->GenerateUnresolvedFieldAccess(instruction,
5216 instruction->GetFieldType(),
5217 instruction->GetFieldIndex(),
5218 instruction->GetDexPc(),
5219 calling_convention);
5220}
5221
5222void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet(
5223 HUnresolvedStaticFieldSet* instruction) {
5224 FieldAccessCallingConventionMIPS calling_convention;
5225 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
5226 instruction->GetFieldType(),
5227 calling_convention);
5228}
5229
5230void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet(
5231 HUnresolvedStaticFieldSet* instruction) {
5232 FieldAccessCallingConventionMIPS calling_convention;
5233 codegen_->GenerateUnresolvedFieldAccess(instruction,
5234 instruction->GetFieldType(),
5235 instruction->GetFieldIndex(),
5236 instruction->GetDexPc(),
5237 calling_convention);
5238}
5239
5240void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) {
5241 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
5242}
5243
5244void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) {
5245 HBasicBlock* block = instruction->GetBlock();
5246 if (block->GetLoopInformation() != nullptr) {
5247 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
5248 // The back edge will generate the suspend check.
5249 return;
5250 }
5251 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
5252 // The goto will generate the suspend check.
5253 return;
5254 }
5255 GenerateSuspendCheck(instruction, nullptr);
5256}
5257
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005258void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) {
5259 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01005260 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005261 InvokeRuntimeCallingConvention calling_convention;
5262 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
5263}
5264
5265void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) {
5266 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException),
5267 instruction,
5268 instruction->GetDexPc(),
5269 nullptr,
5270 IsDirectEntrypoint(kQuickDeliverException));
5271 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
5272}
5273
5274void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) {
5275 Primitive::Type input_type = conversion->GetInputType();
5276 Primitive::Type result_type = conversion->GetResultType();
5277 DCHECK_NE(input_type, result_type);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005278 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005279
5280 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
5281 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
5282 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
5283 }
5284
5285 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005286 if (!isR6 &&
5287 ((Primitive::IsFloatingPointType(result_type) && input_type == Primitive::kPrimLong) ||
5288 (result_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(input_type)))) {
Serban Constantinescu54ff4822016-07-07 18:03:19 +01005289 call_kind = LocationSummary::kCallOnMainOnly;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005290 }
5291
5292 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
5293
5294 if (call_kind == LocationSummary::kNoCall) {
5295 if (Primitive::IsFloatingPointType(input_type)) {
5296 locations->SetInAt(0, Location::RequiresFpuRegister());
5297 } else {
5298 locations->SetInAt(0, Location::RequiresRegister());
5299 }
5300
5301 if (Primitive::IsFloatingPointType(result_type)) {
5302 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
5303 } else {
5304 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
5305 }
5306 } else {
5307 InvokeRuntimeCallingConvention calling_convention;
5308
5309 if (Primitive::IsFloatingPointType(input_type)) {
5310 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
5311 } else {
5312 DCHECK_EQ(input_type, Primitive::kPrimLong);
5313 locations->SetInAt(0, Location::RegisterPairLocation(
5314 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
5315 }
5316
5317 locations->SetOut(calling_convention.GetReturnLocation(result_type));
5318 }
5319}
5320
5321void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) {
5322 LocationSummary* locations = conversion->GetLocations();
5323 Primitive::Type result_type = conversion->GetResultType();
5324 Primitive::Type input_type = conversion->GetInputType();
5325 bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005326 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005327
5328 DCHECK_NE(input_type, result_type);
5329
5330 if (result_type == Primitive::kPrimLong && Primitive::IsIntegralType(input_type)) {
5331 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
5332 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
5333 Register src = locations->InAt(0).AsRegister<Register>();
5334
Alexey Frunzea871ef12016-06-27 15:20:11 -07005335 if (dst_low != src) {
5336 __ Move(dst_low, src);
5337 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005338 __ Sra(dst_high, src, 31);
5339 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
5340 Register dst = locations->Out().AsRegister<Register>();
5341 Register src = (input_type == Primitive::kPrimLong)
5342 ? locations->InAt(0).AsRegisterPairLow<Register>()
5343 : locations->InAt(0).AsRegister<Register>();
5344
5345 switch (result_type) {
5346 case Primitive::kPrimChar:
5347 __ Andi(dst, src, 0xFFFF);
5348 break;
5349 case Primitive::kPrimByte:
5350 if (has_sign_extension) {
5351 __ Seb(dst, src);
5352 } else {
5353 __ Sll(dst, src, 24);
5354 __ Sra(dst, dst, 24);
5355 }
5356 break;
5357 case Primitive::kPrimShort:
5358 if (has_sign_extension) {
5359 __ Seh(dst, src);
5360 } else {
5361 __ Sll(dst, src, 16);
5362 __ Sra(dst, dst, 16);
5363 }
5364 break;
5365 case Primitive::kPrimInt:
Alexey Frunzea871ef12016-06-27 15:20:11 -07005366 if (dst != src) {
5367 __ Move(dst, src);
5368 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005369 break;
5370
5371 default:
5372 LOG(FATAL) << "Unexpected type conversion from " << input_type
5373 << " to " << result_type;
5374 }
5375 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005376 if (input_type == Primitive::kPrimLong) {
5377 if (isR6) {
5378 // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary
5379 // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction.
5380 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
5381 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
5382 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
5383 __ Mtc1(src_low, FTMP);
5384 __ Mthc1(src_high, FTMP);
5385 if (result_type == Primitive::kPrimFloat) {
5386 __ Cvtsl(dst, FTMP);
5387 } else {
5388 __ Cvtdl(dst, FTMP);
5389 }
5390 } else {
5391 int32_t entry_offset = (result_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pL2f)
5392 : QUICK_ENTRY_POINT(pL2d);
5393 bool direct = (result_type == Primitive::kPrimFloat) ? IsDirectEntrypoint(kQuickL2f)
5394 : IsDirectEntrypoint(kQuickL2d);
5395 codegen_->InvokeRuntime(entry_offset,
5396 conversion,
5397 conversion->GetDexPc(),
5398 nullptr,
5399 direct);
5400 if (result_type == Primitive::kPrimFloat) {
5401 CheckEntrypointTypes<kQuickL2f, float, int64_t>();
5402 } else {
5403 CheckEntrypointTypes<kQuickL2d, double, int64_t>();
5404 }
5405 }
5406 } else {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005407 Register src = locations->InAt(0).AsRegister<Register>();
5408 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
5409 __ Mtc1(src, FTMP);
5410 if (result_type == Primitive::kPrimFloat) {
5411 __ Cvtsw(dst, FTMP);
5412 } else {
5413 __ Cvtdw(dst, FTMP);
5414 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005415 }
5416 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
5417 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005418 if (result_type == Primitive::kPrimLong) {
5419 if (isR6) {
5420 // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary
5421 // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction.
5422 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
5423 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
5424 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
5425 MipsLabel truncate;
5426 MipsLabel done;
5427
5428 // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive
5429 // value when the input is either a NaN or is outside of the range of the output type
5430 // after the truncation. IOW, the three special cases (NaN, too small, too big) produce
5431 // the same result.
5432 //
5433 // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum
5434 // value of the output type if the input is outside of the range after the truncation or
5435 // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct
5436 // results. This matches the desired float/double-to-int/long conversion exactly.
5437 //
5438 // So, NAN2008 affects handling of negative values and NaNs by the truncate instruction.
5439 //
5440 // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate
5441 // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6,
5442 // even though it must be NAN2008=1 on R6.
5443 //
5444 // The code takes care of the different behaviors by first comparing the input to the
5445 // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int).
5446 // If the input is greater than or equal to the minimum, it procedes to the truncate
5447 // instruction, which will handle such an input the same way irrespective of NAN2008.
5448 // Otherwise the input is compared to itself to determine whether it is a NaN or not
5449 // in order to return either zero or the minimum value.
5450 //
5451 // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the
5452 // truncate instruction for MIPS64R6.
5453 if (input_type == Primitive::kPrimFloat) {
5454 uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int64_t>::min());
5455 __ LoadConst32(TMP, min_val);
5456 __ Mtc1(TMP, FTMP);
5457 __ CmpLeS(FTMP, FTMP, src);
5458 } else {
5459 uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int64_t>::min());
5460 __ LoadConst32(TMP, High32Bits(min_val));
5461 __ Mtc1(ZERO, FTMP);
5462 __ Mthc1(TMP, FTMP);
5463 __ CmpLeD(FTMP, FTMP, src);
5464 }
5465
5466 __ Bc1nez(FTMP, &truncate);
5467
5468 if (input_type == Primitive::kPrimFloat) {
5469 __ CmpEqS(FTMP, src, src);
5470 } else {
5471 __ CmpEqD(FTMP, src, src);
5472 }
5473 __ Move(dst_low, ZERO);
5474 __ LoadConst32(dst_high, std::numeric_limits<int32_t>::min());
5475 __ Mfc1(TMP, FTMP);
5476 __ And(dst_high, dst_high, TMP);
5477
5478 __ B(&done);
5479
5480 __ Bind(&truncate);
5481
5482 if (input_type == Primitive::kPrimFloat) {
5483 __ TruncLS(FTMP, src);
5484 } else {
5485 __ TruncLD(FTMP, src);
5486 }
5487 __ Mfc1(dst_low, FTMP);
5488 __ Mfhc1(dst_high, FTMP);
5489
5490 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005491 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005492 int32_t entry_offset = (input_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pF2l)
5493 : QUICK_ENTRY_POINT(pD2l);
5494 bool direct = (result_type == Primitive::kPrimFloat) ? IsDirectEntrypoint(kQuickF2l)
5495 : IsDirectEntrypoint(kQuickD2l);
5496 codegen_->InvokeRuntime(entry_offset, conversion, conversion->GetDexPc(), nullptr, direct);
5497 if (input_type == Primitive::kPrimFloat) {
5498 CheckEntrypointTypes<kQuickF2l, int64_t, float>();
5499 } else {
5500 CheckEntrypointTypes<kQuickD2l, int64_t, double>();
5501 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005502 }
5503 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005504 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
5505 Register dst = locations->Out().AsRegister<Register>();
5506 MipsLabel truncate;
5507 MipsLabel done;
5508
5509 // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate
5510 // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6,
5511 // even though it must be NAN2008=1 on R6.
5512 //
5513 // For details see the large comment above for the truncation of float/double to long on R6.
5514 //
5515 // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the
5516 // truncate instruction for MIPS64R6.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005517 if (input_type == Primitive::kPrimFloat) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005518 uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min());
5519 __ LoadConst32(TMP, min_val);
5520 __ Mtc1(TMP, FTMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005521 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005522 uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min());
5523 __ LoadConst32(TMP, High32Bits(min_val));
5524 __ Mtc1(ZERO, FTMP);
Alexey Frunzea871ef12016-06-27 15:20:11 -07005525 __ MoveToFpuHigh(TMP, FTMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005526 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005527
5528 if (isR6) {
5529 if (input_type == Primitive::kPrimFloat) {
5530 __ CmpLeS(FTMP, FTMP, src);
5531 } else {
5532 __ CmpLeD(FTMP, FTMP, src);
5533 }
5534 __ Bc1nez(FTMP, &truncate);
5535
5536 if (input_type == Primitive::kPrimFloat) {
5537 __ CmpEqS(FTMP, src, src);
5538 } else {
5539 __ CmpEqD(FTMP, src, src);
5540 }
5541 __ LoadConst32(dst, std::numeric_limits<int32_t>::min());
5542 __ Mfc1(TMP, FTMP);
5543 __ And(dst, dst, TMP);
5544 } else {
5545 if (input_type == Primitive::kPrimFloat) {
5546 __ ColeS(0, FTMP, src);
5547 } else {
5548 __ ColeD(0, FTMP, src);
5549 }
5550 __ Bc1t(0, &truncate);
5551
5552 if (input_type == Primitive::kPrimFloat) {
5553 __ CeqS(0, src, src);
5554 } else {
5555 __ CeqD(0, src, src);
5556 }
5557 __ LoadConst32(dst, std::numeric_limits<int32_t>::min());
5558 __ Movf(dst, ZERO, 0);
5559 }
5560
5561 __ B(&done);
5562
5563 __ Bind(&truncate);
5564
5565 if (input_type == Primitive::kPrimFloat) {
5566 __ TruncWS(FTMP, src);
5567 } else {
5568 __ TruncWD(FTMP, src);
5569 }
5570 __ Mfc1(dst, FTMP);
5571
5572 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005573 }
5574 } else if (Primitive::IsFloatingPointType(result_type) &&
5575 Primitive::IsFloatingPointType(input_type)) {
5576 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
5577 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
5578 if (result_type == Primitive::kPrimFloat) {
5579 __ Cvtsd(dst, src);
5580 } else {
5581 __ Cvtds(dst, src);
5582 }
5583 } else {
5584 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
5585 << " to " << result_type;
5586 }
5587}
5588
5589void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) {
5590 HandleShift(ushr);
5591}
5592
5593void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) {
5594 HandleShift(ushr);
5595}
5596
5597void LocationsBuilderMIPS::VisitXor(HXor* instruction) {
5598 HandleBinaryOp(instruction);
5599}
5600
5601void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) {
5602 HandleBinaryOp(instruction);
5603}
5604
5605void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
5606 // Nothing to do, this should be removed during prepare for register allocator.
5607 LOG(FATAL) << "Unreachable";
5608}
5609
5610void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
5611 // Nothing to do, this should be removed during prepare for register allocator.
5612 LOG(FATAL) << "Unreachable";
5613}
5614
5615void LocationsBuilderMIPS::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005616 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005617}
5618
5619void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005620 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005621}
5622
5623void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005624 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005625}
5626
5627void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005628 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005629}
5630
5631void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005632 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005633}
5634
5635void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005636 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005637}
5638
5639void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005640 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005641}
5642
5643void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005644 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005645}
5646
5647void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005648 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005649}
5650
5651void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005652 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005653}
5654
5655void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005656 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005657}
5658
5659void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005660 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005661}
5662
5663void LocationsBuilderMIPS::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005664 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005665}
5666
5667void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005668 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005669}
5670
5671void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005672 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005673}
5674
5675void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005676 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005677}
5678
5679void LocationsBuilderMIPS::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005680 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005681}
5682
5683void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005684 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005685}
5686
5687void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005688 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005689}
5690
5691void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005692 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005693}
5694
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005695void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
5696 LocationSummary* locations =
5697 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
5698 locations->SetInAt(0, Location::RequiresRegister());
5699}
5700
5701void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
5702 int32_t lower_bound = switch_instr->GetStartValue();
5703 int32_t num_entries = switch_instr->GetNumEntries();
5704 LocationSummary* locations = switch_instr->GetLocations();
5705 Register value_reg = locations->InAt(0).AsRegister<Register>();
5706 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
5707
5708 // Create a set of compare/jumps.
Vladimir Markof3e0ee22015-12-17 15:23:13 +00005709 Register temp_reg = TMP;
5710 __ Addiu32(temp_reg, value_reg, -lower_bound);
5711 // Jump to default if index is negative
5712 // Note: We don't check the case that index is positive while value < lower_bound, because in
5713 // this case, index >= num_entries must be true. So that we can save one branch instruction.
5714 __ Bltz(temp_reg, codegen_->GetLabelOf(default_block));
5715
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005716 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00005717 // Jump to successors[0] if value == lower_bound.
5718 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0]));
5719 int32_t last_index = 0;
5720 for (; num_entries - last_index > 2; last_index += 2) {
5721 __ Addiu(temp_reg, temp_reg, -2);
5722 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
5723 __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
5724 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
5725 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2]));
5726 }
5727 if (num_entries - last_index == 2) {
5728 // The last missing case_value.
5729 __ Addiu(temp_reg, temp_reg, -1);
5730 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005731 }
5732
Vladimir Markof3e0ee22015-12-17 15:23:13 +00005733 // And the default for any other value.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005734 if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) {
5735 __ B(codegen_->GetLabelOf(default_block));
5736 }
5737}
5738
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005739void LocationsBuilderMIPS::VisitMipsComputeBaseMethodAddress(
5740 HMipsComputeBaseMethodAddress* insn) {
5741 LocationSummary* locations =
5742 new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall);
5743 locations->SetOut(Location::RequiresRegister());
5744}
5745
5746void InstructionCodeGeneratorMIPS::VisitMipsComputeBaseMethodAddress(
5747 HMipsComputeBaseMethodAddress* insn) {
5748 LocationSummary* locations = insn->GetLocations();
5749 Register reg = locations->Out().AsRegister<Register>();
5750
5751 CHECK(!codegen_->GetInstructionSetFeatures().IsR6());
5752
5753 // Generate a dummy PC-relative call to obtain PC.
5754 __ Nal();
5755 // Grab the return address off RA.
5756 __ Move(reg, RA);
Alexey Frunze06a46c42016-07-19 15:00:40 -07005757 // TODO: Can we share this code with that of VisitMipsDexCacheArraysBase()?
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005758
5759 // Remember this offset (the obtained PC value) for later use with constant area.
5760 __ BindPcRelBaseLabel();
5761}
5762
5763void LocationsBuilderMIPS::VisitMipsDexCacheArraysBase(HMipsDexCacheArraysBase* base) {
5764 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base);
5765 locations->SetOut(Location::RequiresRegister());
5766}
5767
5768void InstructionCodeGeneratorMIPS::VisitMipsDexCacheArraysBase(HMipsDexCacheArraysBase* base) {
5769 Register reg = base->GetLocations()->Out().AsRegister<Register>();
5770 CodeGeneratorMIPS::PcRelativePatchInfo* info =
5771 codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07005772 bool reordering = __ SetReorder(false);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005773 if (codegen_->GetInstructionSetFeatures().IsR6()) {
5774 __ Bind(&info->high_label);
5775 __ Bind(&info->pc_rel_label);
5776 // Add a 32-bit offset to PC.
5777 __ Auipc(reg, /* placeholder */ 0x1234);
5778 __ Addiu(reg, reg, /* placeholder */ 0x5678);
5779 } else {
5780 // Generate a dummy PC-relative call to obtain PC.
5781 __ Nal();
5782 __ Bind(&info->high_label);
5783 __ Lui(reg, /* placeholder */ 0x1234);
5784 __ Bind(&info->pc_rel_label);
5785 __ Ori(reg, reg, /* placeholder */ 0x5678);
5786 // Add a 32-bit offset to PC.
5787 __ Addu(reg, reg, RA);
Alexey Frunze06a46c42016-07-19 15:00:40 -07005788 // TODO: Can we share this code with that of VisitMipsComputeBaseMethodAddress()?
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005789 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -07005790 __ SetReorder(reordering);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07005791}
5792
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005793void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
5794 // The trampoline uses the same calling convention as dex calling conventions,
5795 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
5796 // the method_idx.
5797 HandleInvoke(invoke);
5798}
5799
5800void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
5801 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
5802}
5803
Roland Levillain2aba7cd2016-02-03 12:27:20 +00005804void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) {
5805 LocationSummary* locations =
5806 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
5807 locations->SetInAt(0, Location::RequiresRegister());
5808 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00005809}
5810
Roland Levillain2aba7cd2016-02-03 12:27:20 +00005811void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) {
5812 LocationSummary* locations = instruction->GetLocations();
Vladimir Markoa1de9182016-02-25 11:37:38 +00005813 if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01005814 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
Roland Levillain2aba7cd2016-02-03 12:27:20 +00005815 instruction->GetIndex(), kMipsPointerSize).SizeValue();
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01005816 __ LoadFromOffset(kLoadWord,
5817 locations->Out().AsRegister<Register>(),
5818 locations->InAt(0).AsRegister<Register>(),
5819 method_offset);
Roland Levillain2aba7cd2016-02-03 12:27:20 +00005820 } else {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01005821 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00005822 instruction->GetIndex(), kMipsPointerSize));
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00005823 __ LoadFromOffset(kLoadWord,
5824 locations->Out().AsRegister<Register>(),
5825 locations->InAt(0).AsRegister<Register>(),
5826 mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value());
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01005827 __ LoadFromOffset(kLoadWord,
5828 locations->Out().AsRegister<Register>(),
5829 locations->Out().AsRegister<Register>(),
5830 method_offset);
Roland Levillain2aba7cd2016-02-03 12:27:20 +00005831 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00005832}
5833
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005834#undef __
5835#undef QUICK_ENTRY_POINT
5836
5837} // namespace mips
5838} // namespace art