blob: 4c9206320fccac3bb7bdfe95c04386108c26681f [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
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020042Location MipsReturnLocation(Primitive::Type return_type) {
43 switch (return_type) {
44 case Primitive::kPrimBoolean:
45 case Primitive::kPrimByte:
46 case Primitive::kPrimChar:
47 case Primitive::kPrimShort:
48 case Primitive::kPrimInt:
49 case Primitive::kPrimNot:
50 return Location::RegisterLocation(V0);
51
52 case Primitive::kPrimLong:
53 return Location::RegisterPairLocation(V0, V1);
54
55 case Primitive::kPrimFloat:
56 case Primitive::kPrimDouble:
57 return Location::FpuRegisterLocation(F0);
58
59 case Primitive::kPrimVoid:
60 return Location();
61 }
62 UNREACHABLE();
63}
64
65Location InvokeDexCallingConventionVisitorMIPS::GetReturnLocation(Primitive::Type type) const {
66 return MipsReturnLocation(type);
67}
68
69Location InvokeDexCallingConventionVisitorMIPS::GetMethodLocation() const {
70 return Location::RegisterLocation(kMethodRegisterArgument);
71}
72
73Location InvokeDexCallingConventionVisitorMIPS::GetNextLocation(Primitive::Type type) {
74 Location next_location;
75
76 switch (type) {
77 case Primitive::kPrimBoolean:
78 case Primitive::kPrimByte:
79 case Primitive::kPrimChar:
80 case Primitive::kPrimShort:
81 case Primitive::kPrimInt:
82 case Primitive::kPrimNot: {
83 uint32_t gp_index = gp_index_++;
84 if (gp_index < calling_convention.GetNumberOfRegisters()) {
85 next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index));
86 } else {
87 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
88 next_location = Location::StackSlot(stack_offset);
89 }
90 break;
91 }
92
93 case Primitive::kPrimLong: {
94 uint32_t gp_index = gp_index_;
95 gp_index_ += 2;
96 if (gp_index + 1 < calling_convention.GetNumberOfRegisters()) {
97 if (calling_convention.GetRegisterAt(gp_index) == A1) {
98 gp_index_++; // Skip A1, and use A2_A3 instead.
99 gp_index++;
100 }
101 Register low_even = calling_convention.GetRegisterAt(gp_index);
102 Register high_odd = calling_convention.GetRegisterAt(gp_index + 1);
103 DCHECK_EQ(low_even + 1, high_odd);
104 next_location = Location::RegisterPairLocation(low_even, high_odd);
105 } else {
106 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
107 next_location = Location::DoubleStackSlot(stack_offset);
108 }
109 break;
110 }
111
112 // Note: both float and double types are stored in even FPU registers. On 32 bit FPU, double
113 // will take up the even/odd pair, while floats are stored in even regs only.
114 // On 64 bit FPU, both double and float are stored in even registers only.
115 case Primitive::kPrimFloat:
116 case Primitive::kPrimDouble: {
117 uint32_t float_index = float_index_++;
118 if (float_index < calling_convention.GetNumberOfFpuRegisters()) {
119 next_location = Location::FpuRegisterLocation(
120 calling_convention.GetFpuRegisterAt(float_index));
121 } else {
122 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
123 next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
124 : Location::StackSlot(stack_offset);
125 }
126 break;
127 }
128
129 case Primitive::kPrimVoid:
130 LOG(FATAL) << "Unexpected parameter type " << type;
131 break;
132 }
133
134 // Space on the stack is reserved for all arguments.
135 stack_index_ += Primitive::Is64BitType(type) ? 2 : 1;
136
137 return next_location;
138}
139
140Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type type) {
141 return MipsReturnLocation(type);
142}
143
144#define __ down_cast<CodeGeneratorMIPS*>(codegen)->GetAssembler()->
145#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsWordSize, x).Int32Value()
146
147class BoundsCheckSlowPathMIPS : public SlowPathCodeMIPS {
148 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000149 explicit BoundsCheckSlowPathMIPS(HBoundsCheck* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200150
151 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
152 LocationSummary* locations = instruction_->GetLocations();
153 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
154 __ Bind(GetEntryLabel());
155 if (instruction_->CanThrowIntoCatchBlock()) {
156 // Live registers will be restored in the catch block if caught.
157 SaveLiveRegisters(codegen, instruction_->GetLocations());
158 }
159 // We're moving two locations to locations that could overlap, so we need a parallel
160 // move resolver.
161 InvokeRuntimeCallingConvention calling_convention;
162 codegen->EmitParallelMoves(locations->InAt(0),
163 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
164 Primitive::kPrimInt,
165 locations->InAt(1),
166 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
167 Primitive::kPrimInt);
168 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds),
169 instruction_,
170 instruction_->GetDexPc(),
171 this,
172 IsDirectEntrypoint(kQuickThrowArrayBounds));
173 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
174 }
175
176 bool IsFatal() const OVERRIDE { return true; }
177
178 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS"; }
179
180 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200181 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS);
182};
183
184class DivZeroCheckSlowPathMIPS : public SlowPathCodeMIPS {
185 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000186 explicit DivZeroCheckSlowPathMIPS(HDivZeroCheck* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200187
188 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
189 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
190 __ Bind(GetEntryLabel());
191 if (instruction_->CanThrowIntoCatchBlock()) {
192 // Live registers will be restored in the catch block if caught.
193 SaveLiveRegisters(codegen, instruction_->GetLocations());
194 }
195 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero),
196 instruction_,
197 instruction_->GetDexPc(),
198 this,
199 IsDirectEntrypoint(kQuickThrowDivZero));
200 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
201 }
202
203 bool IsFatal() const OVERRIDE { return true; }
204
205 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS"; }
206
207 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200208 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS);
209};
210
211class LoadClassSlowPathMIPS : public SlowPathCodeMIPS {
212 public:
213 LoadClassSlowPathMIPS(HLoadClass* cls,
214 HInstruction* at,
215 uint32_t dex_pc,
216 bool do_clinit)
David Srbecky9cd6d372016-02-09 15:24:47 +0000217 : SlowPathCodeMIPS(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200218 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
219 }
220
221 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
222 LocationSummary* locations = at_->GetLocations();
223 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
224
225 __ Bind(GetEntryLabel());
226 SaveLiveRegisters(codegen, locations);
227
228 InvokeRuntimeCallingConvention calling_convention;
229 __ LoadConst32(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
230
231 int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
232 : QUICK_ENTRY_POINT(pInitializeType);
233 bool direct = do_clinit_ ? IsDirectEntrypoint(kQuickInitializeStaticStorage)
234 : IsDirectEntrypoint(kQuickInitializeType);
235
236 mips_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this, direct);
237 if (do_clinit_) {
238 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
239 } else {
240 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
241 }
242
243 // Move the class to the desired location.
244 Location out = locations->Out();
245 if (out.IsValid()) {
246 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
247 Primitive::Type type = at_->GetType();
248 mips_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type);
249 }
250
251 RestoreLiveRegisters(codegen, locations);
252 __ B(GetExitLabel());
253 }
254
255 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS"; }
256
257 private:
258 // The class this slow path will load.
259 HLoadClass* const cls_;
260
261 // The instruction where this slow path is happening.
262 // (Might be the load class or an initialization check).
263 HInstruction* const at_;
264
265 // The dex PC of `at_`.
266 const uint32_t dex_pc_;
267
268 // Whether to initialize the class.
269 const bool do_clinit_;
270
271 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS);
272};
273
274class LoadStringSlowPathMIPS : public SlowPathCodeMIPS {
275 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000276 explicit LoadStringSlowPathMIPS(HLoadString* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200277
278 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
279 LocationSummary* locations = instruction_->GetLocations();
280 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
281 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
282
283 __ Bind(GetEntryLabel());
284 SaveLiveRegisters(codegen, locations);
285
286 InvokeRuntimeCallingConvention calling_convention;
David Srbecky9cd6d372016-02-09 15:24:47 +0000287 const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex();
288 __ LoadConst32(calling_convention.GetRegisterAt(0), string_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200289 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString),
290 instruction_,
291 instruction_->GetDexPc(),
292 this,
293 IsDirectEntrypoint(kQuickResolveString));
294 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
295 Primitive::Type type = instruction_->GetType();
296 mips_codegen->MoveLocation(locations->Out(),
297 calling_convention.GetReturnLocation(type),
298 type);
299
300 RestoreLiveRegisters(codegen, locations);
301 __ B(GetExitLabel());
302 }
303
304 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS"; }
305
306 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200307 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS);
308};
309
310class NullCheckSlowPathMIPS : public SlowPathCodeMIPS {
311 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000312 explicit NullCheckSlowPathMIPS(HNullCheck* instr) : SlowPathCodeMIPS(instr) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200313
314 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
315 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
316 __ Bind(GetEntryLabel());
317 if (instruction_->CanThrowIntoCatchBlock()) {
318 // Live registers will be restored in the catch block if caught.
319 SaveLiveRegisters(codegen, instruction_->GetLocations());
320 }
321 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer),
322 instruction_,
323 instruction_->GetDexPc(),
324 this,
325 IsDirectEntrypoint(kQuickThrowNullPointer));
326 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
327 }
328
329 bool IsFatal() const OVERRIDE { return true; }
330
331 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS"; }
332
333 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200334 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS);
335};
336
337class SuspendCheckSlowPathMIPS : public SlowPathCodeMIPS {
338 public:
339 SuspendCheckSlowPathMIPS(HSuspendCheck* instruction, HBasicBlock* successor)
David Srbecky9cd6d372016-02-09 15:24:47 +0000340 : SlowPathCodeMIPS(instruction), successor_(successor) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200341
342 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
343 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
344 __ Bind(GetEntryLabel());
345 SaveLiveRegisters(codegen, instruction_->GetLocations());
346 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend),
347 instruction_,
348 instruction_->GetDexPc(),
349 this,
350 IsDirectEntrypoint(kQuickTestSuspend));
351 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
352 RestoreLiveRegisters(codegen, instruction_->GetLocations());
353 if (successor_ == nullptr) {
354 __ B(GetReturnLabel());
355 } else {
356 __ B(mips_codegen->GetLabelOf(successor_));
357 }
358 }
359
360 MipsLabel* GetReturnLabel() {
361 DCHECK(successor_ == nullptr);
362 return &return_label_;
363 }
364
365 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS"; }
366
367 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200368 // If not null, the block to branch to after the suspend check.
369 HBasicBlock* const successor_;
370
371 // If `successor_` is null, the label to branch to after the suspend check.
372 MipsLabel return_label_;
373
374 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS);
375};
376
377class TypeCheckSlowPathMIPS : public SlowPathCodeMIPS {
378 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000379 explicit TypeCheckSlowPathMIPS(HInstruction* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200380
381 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
382 LocationSummary* locations = instruction_->GetLocations();
383 Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) : locations->Out();
384 uint32_t dex_pc = instruction_->GetDexPc();
385 DCHECK(instruction_->IsCheckCast()
386 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
387 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
388
389 __ Bind(GetEntryLabel());
390 SaveLiveRegisters(codegen, locations);
391
392 // We're moving two locations to locations that could overlap, so we need a parallel
393 // move resolver.
394 InvokeRuntimeCallingConvention calling_convention;
395 codegen->EmitParallelMoves(locations->InAt(1),
396 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
397 Primitive::kPrimNot,
398 object_class,
399 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
400 Primitive::kPrimNot);
401
402 if (instruction_->IsInstanceOf()) {
403 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial),
404 instruction_,
405 dex_pc,
406 this,
407 IsDirectEntrypoint(kQuickInstanceofNonTrivial));
Roland Levillain888d0672015-11-23 18:53:50 +0000408 CheckEntrypointTypes<
409 kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200410 Primitive::Type ret_type = instruction_->GetType();
411 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
412 mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200413 } else {
414 DCHECK(instruction_->IsCheckCast());
415 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast),
416 instruction_,
417 dex_pc,
418 this,
419 IsDirectEntrypoint(kQuickCheckCast));
420 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
421 }
422
423 RestoreLiveRegisters(codegen, locations);
424 __ B(GetExitLabel());
425 }
426
427 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; }
428
429 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200430 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS);
431};
432
433class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS {
434 public:
Aart Bik42249c32016-01-07 15:33:50 -0800435 explicit DeoptimizationSlowPathMIPS(HDeoptimize* instruction)
David Srbecky9cd6d372016-02-09 15:24:47 +0000436 : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200437
438 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Aart Bik42249c32016-01-07 15:33:50 -0800439 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200440 __ Bind(GetEntryLabel());
441 SaveLiveRegisters(codegen, instruction_->GetLocations());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200442 mips_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize),
443 instruction_,
Aart Bik42249c32016-01-07 15:33:50 -0800444 instruction_->GetDexPc(),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200445 this,
446 IsDirectEntrypoint(kQuickDeoptimize));
Roland Levillain888d0672015-11-23 18:53:50 +0000447 CheckEntrypointTypes<kQuickDeoptimize, void, void>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200448 }
449
450 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; }
451
452 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200453 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS);
454};
455
456CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph,
457 const MipsInstructionSetFeatures& isa_features,
458 const CompilerOptions& compiler_options,
459 OptimizingCompilerStats* stats)
460 : CodeGenerator(graph,
461 kNumberOfCoreRegisters,
462 kNumberOfFRegisters,
463 kNumberOfRegisterPairs,
464 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
465 arraysize(kCoreCalleeSaves)),
466 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
467 arraysize(kFpuCalleeSaves)),
468 compiler_options,
469 stats),
470 block_labels_(nullptr),
471 location_builder_(graph, this),
472 instruction_visitor_(graph, this),
473 move_resolver_(graph->GetArena(), this),
474 assembler_(&isa_features),
475 isa_features_(isa_features) {
476 // Save RA (containing the return address) to mimic Quick.
477 AddAllocatedRegister(Location::RegisterLocation(RA));
478}
479
480#undef __
481#define __ down_cast<MipsAssembler*>(GetAssembler())->
482#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsWordSize, x).Int32Value()
483
484void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) {
485 // Ensure that we fix up branches.
486 __ FinalizeCode();
487
488 // Adjust native pc offsets in stack maps.
489 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
490 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
491 uint32_t new_position = __ GetAdjustedPosition(old_position);
492 DCHECK_GE(new_position, old_position);
493 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
494 }
495
496 // Adjust pc offsets for the disassembly information.
497 if (disasm_info_ != nullptr) {
498 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
499 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
500 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
501 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
502 it.second.start = __ GetAdjustedPosition(it.second.start);
503 it.second.end = __ GetAdjustedPosition(it.second.end);
504 }
505 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
506 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
507 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
508 }
509 }
510
511 CodeGenerator::Finalize(allocator);
512}
513
514MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const {
515 return codegen_->GetAssembler();
516}
517
518void ParallelMoveResolverMIPS::EmitMove(size_t index) {
519 DCHECK_LT(index, moves_.size());
520 MoveOperands* move = moves_[index];
521 codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType());
522}
523
524void ParallelMoveResolverMIPS::EmitSwap(size_t index) {
525 DCHECK_LT(index, moves_.size());
526 MoveOperands* move = moves_[index];
527 Primitive::Type type = move->GetType();
528 Location loc1 = move->GetDestination();
529 Location loc2 = move->GetSource();
530
531 DCHECK(!loc1.IsConstant());
532 DCHECK(!loc2.IsConstant());
533
534 if (loc1.Equals(loc2)) {
535 return;
536 }
537
538 if (loc1.IsRegister() && loc2.IsRegister()) {
539 // Swap 2 GPRs.
540 Register r1 = loc1.AsRegister<Register>();
541 Register r2 = loc2.AsRegister<Register>();
542 __ Move(TMP, r2);
543 __ Move(r2, r1);
544 __ Move(r1, TMP);
545 } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) {
546 FRegister f1 = loc1.AsFpuRegister<FRegister>();
547 FRegister f2 = loc2.AsFpuRegister<FRegister>();
548 if (type == Primitive::kPrimFloat) {
549 __ MovS(FTMP, f2);
550 __ MovS(f2, f1);
551 __ MovS(f1, FTMP);
552 } else {
553 DCHECK_EQ(type, Primitive::kPrimDouble);
554 __ MovD(FTMP, f2);
555 __ MovD(f2, f1);
556 __ MovD(f1, FTMP);
557 }
558 } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) ||
559 (loc1.IsFpuRegister() && loc2.IsRegister())) {
560 // Swap FPR and GPR.
561 DCHECK_EQ(type, Primitive::kPrimFloat); // Can only swap a float.
562 FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
563 : loc2.AsFpuRegister<FRegister>();
564 Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>()
565 : loc2.AsRegister<Register>();
566 __ Move(TMP, r2);
567 __ Mfc1(r2, f1);
568 __ Mtc1(TMP, f1);
569 } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) {
570 // Swap 2 GPR register pairs.
571 Register r1 = loc1.AsRegisterPairLow<Register>();
572 Register r2 = loc2.AsRegisterPairLow<Register>();
573 __ Move(TMP, r2);
574 __ Move(r2, r1);
575 __ Move(r1, TMP);
576 r1 = loc1.AsRegisterPairHigh<Register>();
577 r2 = loc2.AsRegisterPairHigh<Register>();
578 __ Move(TMP, r2);
579 __ Move(r2, r1);
580 __ Move(r1, TMP);
581 } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) ||
582 (loc1.IsFpuRegister() && loc2.IsRegisterPair())) {
583 // Swap FPR and GPR register pair.
584 DCHECK_EQ(type, Primitive::kPrimDouble);
585 FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
586 : loc2.AsFpuRegister<FRegister>();
587 Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>()
588 : loc2.AsRegisterPairLow<Register>();
589 Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>()
590 : loc2.AsRegisterPairHigh<Register>();
591 // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and
592 // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR
593 // unpredictable and the following mfch1 will fail.
594 __ Mfc1(TMP, f1);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800595 __ MoveFromFpuHigh(AT, f1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200596 __ Mtc1(r2_l, f1);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800597 __ MoveToFpuHigh(r2_h, f1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200598 __ Move(r2_l, TMP);
599 __ Move(r2_h, AT);
600 } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) {
601 Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false);
602 } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) {
603 Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true);
David Brazdilcc0f3112016-01-28 17:14:52 +0000604 } else if ((loc1.IsRegister() && loc2.IsStackSlot()) ||
605 (loc1.IsStackSlot() && loc2.IsRegister())) {
606 Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>()
607 : loc2.AsRegister<Register>();
608 intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex()
609 : loc2.GetStackIndex();
610 __ Move(TMP, reg);
611 __ LoadFromOffset(kLoadWord, reg, SP, offset);
612 __ StoreToOffset(kStoreWord, TMP, SP, offset);
613 } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) ||
614 (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) {
615 Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>()
616 : loc2.AsRegisterPairLow<Register>();
617 Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>()
618 : loc2.AsRegisterPairHigh<Register>();
619 intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex()
620 : loc2.GetStackIndex();
621 intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize)
622 : loc2.GetHighStackIndex(kMipsWordSize);
623 __ Move(TMP, reg_l);
David Brazdilcc0f3112016-01-28 17:14:52 +0000624 __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l);
David Brazdilcc0f3112016-01-28 17:14:52 +0000625 __ StoreToOffset(kStoreWord, TMP, SP, offset_l);
David Brazdil04d3e872016-01-29 09:50:09 +0000626 __ Move(TMP, reg_h);
627 __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h);
628 __ StoreToOffset(kStoreWord, TMP, SP, offset_h);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200629 } else {
630 LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported";
631 }
632}
633
634void ParallelMoveResolverMIPS::RestoreScratch(int reg) {
635 __ Pop(static_cast<Register>(reg));
636}
637
638void ParallelMoveResolverMIPS::SpillScratch(int reg) {
639 __ Push(static_cast<Register>(reg));
640}
641
642void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) {
643 // Allocate a scratch register other than TMP, if available.
644 // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be
645 // automatically unspilled when the scratch scope object is destroyed).
646 ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters());
647 // If V0 spills onto the stack, SP-relative offsets need to be adjusted.
648 int stack_offset = ensure_scratch.IsSpilled() ? kMipsWordSize : 0;
649 for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) {
650 __ LoadFromOffset(kLoadWord,
651 Register(ensure_scratch.GetRegister()),
652 SP,
653 index1 + stack_offset);
654 __ LoadFromOffset(kLoadWord,
655 TMP,
656 SP,
657 index2 + stack_offset);
658 __ StoreToOffset(kStoreWord,
659 Register(ensure_scratch.GetRegister()),
660 SP,
661 index2 + stack_offset);
662 __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset);
663 }
664}
665
666static dwarf::Reg DWARFReg(Register reg) {
667 return dwarf::Reg::MipsCore(static_cast<int>(reg));
668}
669
670// TODO: mapping of floating-point registers to DWARF.
671
672void CodeGeneratorMIPS::GenerateFrameEntry() {
673 __ Bind(&frame_entry_label_);
674
675 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips) || !IsLeafMethod();
676
677 if (do_overflow_check) {
678 __ LoadFromOffset(kLoadWord,
679 ZERO,
680 SP,
681 -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips)));
682 RecordPcInfo(nullptr, 0);
683 }
684
685 if (HasEmptyFrame()) {
686 return;
687 }
688
689 // Make sure the frame size isn't unreasonably large.
690 if (GetFrameSize() > GetStackOverflowReservedBytes(kMips)) {
691 LOG(FATAL) << "Stack frame larger than " << GetStackOverflowReservedBytes(kMips) << " bytes";
692 }
693
694 // Spill callee-saved registers.
695 // Note that their cumulative size is small and they can be indexed using
696 // 16-bit offsets.
697
698 // TODO: increment/decrement SP in one step instead of two or remove this comment.
699
700 uint32_t ofs = FrameEntrySpillSize();
701 bool unaligned_float = ofs & 0x7;
702 bool fpu_32bit = isa_features_.Is32BitFloatingPoint();
703 __ IncreaseFrameSize(ofs);
704
705 for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) {
706 Register reg = kCoreCalleeSaves[i];
707 if (allocated_registers_.ContainsCoreRegister(reg)) {
708 ofs -= kMipsWordSize;
709 __ Sw(reg, SP, ofs);
710 __ cfi().RelOffset(DWARFReg(reg), ofs);
711 }
712 }
713
714 for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) {
715 FRegister reg = kFpuCalleeSaves[i];
716 if (allocated_registers_.ContainsFloatingPointRegister(reg)) {
717 ofs -= kMipsDoublewordSize;
718 // TODO: Change the frame to avoid unaligned accesses for fpu registers.
719 if (unaligned_float) {
720 if (fpu_32bit) {
721 __ Swc1(reg, SP, ofs);
722 __ Swc1(static_cast<FRegister>(reg + 1), SP, ofs + 4);
723 } else {
724 __ Mfhc1(TMP, reg);
725 __ Swc1(reg, SP, ofs);
726 __ Sw(TMP, SP, ofs + 4);
727 }
728 } else {
729 __ Sdc1(reg, SP, ofs);
730 }
731 // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs);
732 }
733 }
734
735 // Allocate the rest of the frame and store the current method pointer
736 // at its end.
737
738 __ IncreaseFrameSize(GetFrameSize() - FrameEntrySpillSize());
739
740 static_assert(IsInt<16>(kCurrentMethodStackOffset),
741 "kCurrentMethodStackOffset must fit into int16_t");
742 __ Sw(kMethodRegisterArgument, SP, kCurrentMethodStackOffset);
743}
744
745void CodeGeneratorMIPS::GenerateFrameExit() {
746 __ cfi().RememberState();
747
748 if (!HasEmptyFrame()) {
749 // Deallocate the rest of the frame.
750
751 __ DecreaseFrameSize(GetFrameSize() - FrameEntrySpillSize());
752
753 // Restore callee-saved registers.
754 // Note that their cumulative size is small and they can be indexed using
755 // 16-bit offsets.
756
757 // TODO: increment/decrement SP in one step instead of two or remove this comment.
758
759 uint32_t ofs = 0;
760 bool unaligned_float = FrameEntrySpillSize() & 0x7;
761 bool fpu_32bit = isa_features_.Is32BitFloatingPoint();
762
763 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
764 FRegister reg = kFpuCalleeSaves[i];
765 if (allocated_registers_.ContainsFloatingPointRegister(reg)) {
766 if (unaligned_float) {
767 if (fpu_32bit) {
768 __ Lwc1(reg, SP, ofs);
769 __ Lwc1(static_cast<FRegister>(reg + 1), SP, ofs + 4);
770 } else {
771 __ Lwc1(reg, SP, ofs);
772 __ Lw(TMP, SP, ofs + 4);
773 __ Mthc1(TMP, reg);
774 }
775 } else {
776 __ Ldc1(reg, SP, ofs);
777 }
778 ofs += kMipsDoublewordSize;
779 // TODO: __ cfi().Restore(DWARFReg(reg));
780 }
781 }
782
783 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
784 Register reg = kCoreCalleeSaves[i];
785 if (allocated_registers_.ContainsCoreRegister(reg)) {
786 __ Lw(reg, SP, ofs);
787 ofs += kMipsWordSize;
788 __ cfi().Restore(DWARFReg(reg));
789 }
790 }
791
792 DCHECK_EQ(ofs, FrameEntrySpillSize());
793 __ DecreaseFrameSize(ofs);
794 }
795
796 __ Jr(RA);
797 __ Nop();
798
799 __ cfi().RestoreState();
800 __ cfi().DefCFAOffset(GetFrameSize());
801}
802
803void CodeGeneratorMIPS::Bind(HBasicBlock* block) {
804 __ Bind(GetLabelOf(block));
805}
806
807void CodeGeneratorMIPS::MoveLocation(Location dst, Location src, Primitive::Type dst_type) {
808 if (src.Equals(dst)) {
809 return;
810 }
811
812 if (src.IsConstant()) {
813 MoveConstant(dst, src.GetConstant());
814 } else {
815 if (Primitive::Is64BitType(dst_type)) {
816 Move64(dst, src);
817 } else {
818 Move32(dst, src);
819 }
820 }
821}
822
823void CodeGeneratorMIPS::Move32(Location destination, Location source) {
824 if (source.Equals(destination)) {
825 return;
826 }
827
828 if (destination.IsRegister()) {
829 if (source.IsRegister()) {
830 __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>());
831 } else if (source.IsFpuRegister()) {
832 __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>());
833 } else {
834 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
835 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
836 }
837 } else if (destination.IsFpuRegister()) {
838 if (source.IsRegister()) {
839 __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>());
840 } else if (source.IsFpuRegister()) {
841 __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>());
842 } else {
843 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
844 __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
845 }
846 } else {
847 DCHECK(destination.IsStackSlot()) << destination;
848 if (source.IsRegister()) {
849 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
850 } else if (source.IsFpuRegister()) {
851 __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex());
852 } else {
853 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
854 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
855 __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex());
856 }
857 }
858}
859
860void CodeGeneratorMIPS::Move64(Location destination, Location source) {
861 if (source.Equals(destination)) {
862 return;
863 }
864
865 if (destination.IsRegisterPair()) {
866 if (source.IsRegisterPair()) {
867 __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
868 __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
869 } else if (source.IsFpuRegister()) {
870 Register dst_high = destination.AsRegisterPairHigh<Register>();
871 Register dst_low = destination.AsRegisterPairLow<Register>();
872 FRegister src = source.AsFpuRegister<FRegister>();
873 __ Mfc1(dst_low, src);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800874 __ MoveFromFpuHigh(dst_high, src);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200875 } else {
876 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
877 int32_t off = source.GetStackIndex();
878 Register r = destination.AsRegisterPairLow<Register>();
879 __ LoadFromOffset(kLoadDoubleword, r, SP, off);
880 }
881 } else if (destination.IsFpuRegister()) {
882 if (source.IsRegisterPair()) {
883 FRegister dst = destination.AsFpuRegister<FRegister>();
884 Register src_high = source.AsRegisterPairHigh<Register>();
885 Register src_low = source.AsRegisterPairLow<Register>();
886 __ Mtc1(src_low, dst);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800887 __ MoveToFpuHigh(src_high, dst);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200888 } else if (source.IsFpuRegister()) {
889 __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>());
890 } else {
891 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
892 __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
893 }
894 } else {
895 DCHECK(destination.IsDoubleStackSlot()) << destination;
896 int32_t off = destination.GetStackIndex();
897 if (source.IsRegisterPair()) {
898 __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, off);
899 } else if (source.IsFpuRegister()) {
900 __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, off);
901 } else {
902 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
903 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
904 __ StoreToOffset(kStoreWord, TMP, SP, off);
905 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4);
906 __ StoreToOffset(kStoreWord, TMP, SP, off + 4);
907 }
908 }
909}
910
911void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) {
912 if (c->IsIntConstant() || c->IsNullConstant()) {
913 // Move 32 bit constant.
914 int32_t value = GetInt32ValueOf(c);
915 if (destination.IsRegister()) {
916 Register dst = destination.AsRegister<Register>();
917 __ LoadConst32(dst, value);
918 } else {
919 DCHECK(destination.IsStackSlot())
920 << "Cannot move " << c->DebugName() << " to " << destination;
921 __ StoreConst32ToOffset(value, SP, destination.GetStackIndex(), TMP);
922 }
923 } else if (c->IsLongConstant()) {
924 // Move 64 bit constant.
925 int64_t value = GetInt64ValueOf(c);
926 if (destination.IsRegisterPair()) {
927 Register r_h = destination.AsRegisterPairHigh<Register>();
928 Register r_l = destination.AsRegisterPairLow<Register>();
929 __ LoadConst64(r_h, r_l, value);
930 } else {
931 DCHECK(destination.IsDoubleStackSlot())
932 << "Cannot move " << c->DebugName() << " to " << destination;
933 __ StoreConst64ToOffset(value, SP, destination.GetStackIndex(), TMP);
934 }
935 } else if (c->IsFloatConstant()) {
936 // Move 32 bit float constant.
937 int32_t value = GetInt32ValueOf(c);
938 if (destination.IsFpuRegister()) {
939 __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP);
940 } else {
941 DCHECK(destination.IsStackSlot())
942 << "Cannot move " << c->DebugName() << " to " << destination;
943 __ StoreConst32ToOffset(value, SP, destination.GetStackIndex(), TMP);
944 }
945 } else {
946 // Move 64 bit double constant.
947 DCHECK(c->IsDoubleConstant()) << c->DebugName();
948 int64_t value = GetInt64ValueOf(c);
949 if (destination.IsFpuRegister()) {
950 FRegister fd = destination.AsFpuRegister<FRegister>();
951 __ LoadDConst64(fd, value, TMP);
952 } else {
953 DCHECK(destination.IsDoubleStackSlot())
954 << "Cannot move " << c->DebugName() << " to " << destination;
955 __ StoreConst64ToOffset(value, SP, destination.GetStackIndex(), TMP);
956 }
957 }
958}
959
960void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) {
961 DCHECK(destination.IsRegister());
962 Register dst = destination.AsRegister<Register>();
963 __ LoadConst32(dst, value);
964}
965
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200966void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) {
967 if (location.IsRegister()) {
968 locations->AddTemp(location);
Alexey Frunzec9e94f32015-10-26 16:11:39 -0700969 } else if (location.IsRegisterPair()) {
970 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>()));
971 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>()));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200972 } else {
973 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
974 }
975}
976
977Location CodeGeneratorMIPS::GetStackLocation(HLoadLocal* load) const {
978 Primitive::Type type = load->GetType();
979
980 switch (type) {
981 case Primitive::kPrimNot:
982 case Primitive::kPrimInt:
983 case Primitive::kPrimFloat:
984 return Location::StackSlot(GetStackSlot(load->GetLocal()));
985
986 case Primitive::kPrimLong:
987 case Primitive::kPrimDouble:
988 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
989
990 case Primitive::kPrimBoolean:
991 case Primitive::kPrimByte:
992 case Primitive::kPrimChar:
993 case Primitive::kPrimShort:
994 case Primitive::kPrimVoid:
995 LOG(FATAL) << "Unexpected type " << type;
996 }
997
998 LOG(FATAL) << "Unreachable";
999 return Location::NoLocation();
1000}
1001
1002void CodeGeneratorMIPS::MarkGCCard(Register object, Register value) {
1003 MipsLabel done;
1004 Register card = AT;
1005 Register temp = TMP;
1006 __ Beqz(value, &done);
1007 __ LoadFromOffset(kLoadWord,
1008 card,
1009 TR,
1010 Thread::CardTableOffset<kMipsWordSize>().Int32Value());
1011 __ Srl(temp, object, gc::accounting::CardTable::kCardShift);
1012 __ Addu(temp, card, temp);
1013 __ Sb(card, temp, 0);
1014 __ Bind(&done);
1015}
1016
David Brazdil58282f42016-01-14 12:45:10 +00001017void CodeGeneratorMIPS::SetupBlockedRegisters() const {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001018 // Don't allocate the dalvik style register pair passing.
1019 blocked_register_pairs_[A1_A2] = true;
1020
1021 // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated.
1022 blocked_core_registers_[ZERO] = true;
1023 blocked_core_registers_[K0] = true;
1024 blocked_core_registers_[K1] = true;
1025 blocked_core_registers_[GP] = true;
1026 blocked_core_registers_[SP] = true;
1027 blocked_core_registers_[RA] = true;
1028
1029 // AT and TMP(T8) are used as temporary/scratch registers
1030 // (similar to how AT is used by MIPS assemblers).
1031 blocked_core_registers_[AT] = true;
1032 blocked_core_registers_[TMP] = true;
1033 blocked_fpu_registers_[FTMP] = true;
1034
1035 // Reserve suspend and thread registers.
1036 blocked_core_registers_[S0] = true;
1037 blocked_core_registers_[TR] = true;
1038
1039 // Reserve T9 for function calls
1040 blocked_core_registers_[T9] = true;
1041
1042 // Reserve odd-numbered FPU registers.
1043 for (size_t i = 1; i < kNumberOfFRegisters; i += 2) {
1044 blocked_fpu_registers_[i] = true;
1045 }
1046
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001047 UpdateBlockedPairRegisters();
1048}
1049
1050void CodeGeneratorMIPS::UpdateBlockedPairRegisters() const {
1051 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
1052 MipsManagedRegister current =
1053 MipsManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
1054 if (blocked_core_registers_[current.AsRegisterPairLow()]
1055 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
1056 blocked_register_pairs_[i] = true;
1057 }
1058 }
1059}
1060
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001061size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
1062 __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index);
1063 return kMipsWordSize;
1064}
1065
1066size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
1067 __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index);
1068 return kMipsWordSize;
1069}
1070
1071size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1072 __ StoreDToOffset(FRegister(reg_id), SP, stack_index);
1073 return kMipsDoublewordSize;
1074}
1075
1076size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1077 __ LoadDFromOffset(FRegister(reg_id), SP, stack_index);
1078 return kMipsDoublewordSize;
1079}
1080
1081void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const {
Vladimir Marko623a7a22016-02-02 18:14:52 +00001082 stream << Register(reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001083}
1084
1085void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Vladimir Marko623a7a22016-02-02 18:14:52 +00001086 stream << FRegister(reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001087}
1088
1089void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint,
1090 HInstruction* instruction,
1091 uint32_t dex_pc,
1092 SlowPathCode* slow_path) {
1093 InvokeRuntime(GetThreadOffset<kMipsWordSize>(entrypoint).Int32Value(),
1094 instruction,
1095 dex_pc,
1096 slow_path,
1097 IsDirectEntrypoint(entrypoint));
1098}
1099
1100constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16;
1101
1102void CodeGeneratorMIPS::InvokeRuntime(int32_t entry_point_offset,
1103 HInstruction* instruction,
1104 uint32_t dex_pc,
1105 SlowPathCode* slow_path,
1106 bool is_direct_entrypoint) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001107 __ LoadFromOffset(kLoadWord, T9, TR, entry_point_offset);
1108 __ Jalr(T9);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001109 if (is_direct_entrypoint) {
1110 // Reserve argument space on stack (for $a0-$a3) for
1111 // entrypoints that directly reference native implementations.
1112 // Called function may use this space to store $a0-$a3 regs.
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001113 __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001114 __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001115 } else {
1116 __ Nop(); // In delay slot.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001117 }
1118 RecordPcInfo(instruction, dex_pc, slow_path);
1119}
1120
1121void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path,
1122 Register class_reg) {
1123 __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value());
1124 __ LoadConst32(AT, mirror::Class::kStatusInitialized);
1125 __ Blt(TMP, AT, slow_path->GetEntryLabel());
1126 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
1127 __ Sync(0);
1128 __ Bind(slow_path->GetExitLabel());
1129}
1130
1131void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) {
1132 __ Sync(0); // Only stype 0 is supported.
1133}
1134
1135void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction,
1136 HBasicBlock* successor) {
1137 SuspendCheckSlowPathMIPS* slow_path =
1138 new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS(instruction, successor);
1139 codegen_->AddSlowPath(slow_path);
1140
1141 __ LoadFromOffset(kLoadUnsignedHalfword,
1142 TMP,
1143 TR,
1144 Thread::ThreadFlagsOffset<kMipsWordSize>().Int32Value());
1145 if (successor == nullptr) {
1146 __ Bnez(TMP, slow_path->GetEntryLabel());
1147 __ Bind(slow_path->GetReturnLabel());
1148 } else {
1149 __ Beqz(TMP, codegen_->GetLabelOf(successor));
1150 __ B(slow_path->GetEntryLabel());
1151 // slow_path will return to GetLabelOf(successor).
1152 }
1153}
1154
1155InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph,
1156 CodeGeneratorMIPS* codegen)
Aart Bik42249c32016-01-07 15:33:50 -08001157 : InstructionCodeGenerator(graph, codegen),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001158 assembler_(codegen->GetAssembler()),
1159 codegen_(codegen) {}
1160
1161void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) {
1162 DCHECK_EQ(instruction->InputCount(), 2U);
1163 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1164 Primitive::Type type = instruction->GetResultType();
1165 switch (type) {
1166 case Primitive::kPrimInt: {
1167 locations->SetInAt(0, Location::RequiresRegister());
1168 HInstruction* right = instruction->InputAt(1);
1169 bool can_use_imm = false;
1170 if (right->IsConstant()) {
1171 int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant());
1172 if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) {
1173 can_use_imm = IsUint<16>(imm);
1174 } else if (instruction->IsAdd()) {
1175 can_use_imm = IsInt<16>(imm);
1176 } else {
1177 DCHECK(instruction->IsSub());
1178 can_use_imm = IsInt<16>(-imm);
1179 }
1180 }
1181 if (can_use_imm)
1182 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1183 else
1184 locations->SetInAt(1, Location::RequiresRegister());
1185 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1186 break;
1187 }
1188
1189 case Primitive::kPrimLong: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001190 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001191 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1192 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001193 break;
1194 }
1195
1196 case Primitive::kPrimFloat:
1197 case Primitive::kPrimDouble:
1198 DCHECK(instruction->IsAdd() || instruction->IsSub());
1199 locations->SetInAt(0, Location::RequiresFpuRegister());
1200 locations->SetInAt(1, Location::RequiresFpuRegister());
1201 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1202 break;
1203
1204 default:
1205 LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type;
1206 }
1207}
1208
1209void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) {
1210 Primitive::Type type = instruction->GetType();
1211 LocationSummary* locations = instruction->GetLocations();
1212
1213 switch (type) {
1214 case Primitive::kPrimInt: {
1215 Register dst = locations->Out().AsRegister<Register>();
1216 Register lhs = locations->InAt(0).AsRegister<Register>();
1217 Location rhs_location = locations->InAt(1);
1218
1219 Register rhs_reg = ZERO;
1220 int32_t rhs_imm = 0;
1221 bool use_imm = rhs_location.IsConstant();
1222 if (use_imm) {
1223 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
1224 } else {
1225 rhs_reg = rhs_location.AsRegister<Register>();
1226 }
1227
1228 if (instruction->IsAnd()) {
1229 if (use_imm)
1230 __ Andi(dst, lhs, rhs_imm);
1231 else
1232 __ And(dst, lhs, rhs_reg);
1233 } else if (instruction->IsOr()) {
1234 if (use_imm)
1235 __ Ori(dst, lhs, rhs_imm);
1236 else
1237 __ Or(dst, lhs, rhs_reg);
1238 } else if (instruction->IsXor()) {
1239 if (use_imm)
1240 __ Xori(dst, lhs, rhs_imm);
1241 else
1242 __ Xor(dst, lhs, rhs_reg);
1243 } else if (instruction->IsAdd()) {
1244 if (use_imm)
1245 __ Addiu(dst, lhs, rhs_imm);
1246 else
1247 __ Addu(dst, lhs, rhs_reg);
1248 } else {
1249 DCHECK(instruction->IsSub());
1250 if (use_imm)
1251 __ Addiu(dst, lhs, -rhs_imm);
1252 else
1253 __ Subu(dst, lhs, rhs_reg);
1254 }
1255 break;
1256 }
1257
1258 case Primitive::kPrimLong: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001259 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
1260 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
1261 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
1262 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001263 Location rhs_location = locations->InAt(1);
1264 bool use_imm = rhs_location.IsConstant();
1265 if (!use_imm) {
1266 Register rhs_high = rhs_location.AsRegisterPairHigh<Register>();
1267 Register rhs_low = rhs_location.AsRegisterPairLow<Register>();
1268 if (instruction->IsAnd()) {
1269 __ And(dst_low, lhs_low, rhs_low);
1270 __ And(dst_high, lhs_high, rhs_high);
1271 } else if (instruction->IsOr()) {
1272 __ Or(dst_low, lhs_low, rhs_low);
1273 __ Or(dst_high, lhs_high, rhs_high);
1274 } else if (instruction->IsXor()) {
1275 __ Xor(dst_low, lhs_low, rhs_low);
1276 __ Xor(dst_high, lhs_high, rhs_high);
1277 } else if (instruction->IsAdd()) {
1278 if (lhs_low == rhs_low) {
1279 // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs.
1280 __ Slt(TMP, lhs_low, ZERO);
1281 __ Addu(dst_low, lhs_low, rhs_low);
1282 } else {
1283 __ Addu(dst_low, lhs_low, rhs_low);
1284 // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged.
1285 __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low);
1286 }
1287 __ Addu(dst_high, lhs_high, rhs_high);
1288 __ Addu(dst_high, dst_high, TMP);
1289 } else {
1290 DCHECK(instruction->IsSub());
1291 __ Sltu(TMP, lhs_low, rhs_low);
1292 __ Subu(dst_low, lhs_low, rhs_low);
1293 __ Subu(dst_high, lhs_high, rhs_high);
1294 __ Subu(dst_high, dst_high, TMP);
1295 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001296 } else {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001297 int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant());
1298 if (instruction->IsOr()) {
1299 uint32_t low = Low32Bits(value);
1300 uint32_t high = High32Bits(value);
1301 if (IsUint<16>(low)) {
1302 if (dst_low != lhs_low || low != 0) {
1303 __ Ori(dst_low, lhs_low, low);
1304 }
1305 } else {
1306 __ LoadConst32(TMP, low);
1307 __ Or(dst_low, lhs_low, TMP);
1308 }
1309 if (IsUint<16>(high)) {
1310 if (dst_high != lhs_high || high != 0) {
1311 __ Ori(dst_high, lhs_high, high);
1312 }
1313 } else {
1314 if (high != low) {
1315 __ LoadConst32(TMP, high);
1316 }
1317 __ Or(dst_high, lhs_high, TMP);
1318 }
1319 } else if (instruction->IsXor()) {
1320 uint32_t low = Low32Bits(value);
1321 uint32_t high = High32Bits(value);
1322 if (IsUint<16>(low)) {
1323 if (dst_low != lhs_low || low != 0) {
1324 __ Xori(dst_low, lhs_low, low);
1325 }
1326 } else {
1327 __ LoadConst32(TMP, low);
1328 __ Xor(dst_low, lhs_low, TMP);
1329 }
1330 if (IsUint<16>(high)) {
1331 if (dst_high != lhs_high || high != 0) {
1332 __ Xori(dst_high, lhs_high, high);
1333 }
1334 } else {
1335 if (high != low) {
1336 __ LoadConst32(TMP, high);
1337 }
1338 __ Xor(dst_high, lhs_high, TMP);
1339 }
1340 } else if (instruction->IsAnd()) {
1341 uint32_t low = Low32Bits(value);
1342 uint32_t high = High32Bits(value);
1343 if (IsUint<16>(low)) {
1344 __ Andi(dst_low, lhs_low, low);
1345 } else if (low != 0xFFFFFFFF) {
1346 __ LoadConst32(TMP, low);
1347 __ And(dst_low, lhs_low, TMP);
1348 } else if (dst_low != lhs_low) {
1349 __ Move(dst_low, lhs_low);
1350 }
1351 if (IsUint<16>(high)) {
1352 __ Andi(dst_high, lhs_high, high);
1353 } else if (high != 0xFFFFFFFF) {
1354 if (high != low) {
1355 __ LoadConst32(TMP, high);
1356 }
1357 __ And(dst_high, lhs_high, TMP);
1358 } else if (dst_high != lhs_high) {
1359 __ Move(dst_high, lhs_high);
1360 }
1361 } else {
1362 if (instruction->IsSub()) {
1363 value = -value;
1364 } else {
1365 DCHECK(instruction->IsAdd());
1366 }
1367 int32_t low = Low32Bits(value);
1368 int32_t high = High32Bits(value);
1369 if (IsInt<16>(low)) {
1370 if (dst_low != lhs_low || low != 0) {
1371 __ Addiu(dst_low, lhs_low, low);
1372 }
1373 if (low != 0) {
1374 __ Sltiu(AT, dst_low, low);
1375 }
1376 } else {
1377 __ LoadConst32(TMP, low);
1378 __ Addu(dst_low, lhs_low, TMP);
1379 __ Sltu(AT, dst_low, TMP);
1380 }
1381 if (IsInt<16>(high)) {
1382 if (dst_high != lhs_high || high != 0) {
1383 __ Addiu(dst_high, lhs_high, high);
1384 }
1385 } else {
1386 if (high != low) {
1387 __ LoadConst32(TMP, high);
1388 }
1389 __ Addu(dst_high, lhs_high, TMP);
1390 }
1391 if (low != 0) {
1392 __ Addu(dst_high, dst_high, AT);
1393 }
1394 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001395 }
1396 break;
1397 }
1398
1399 case Primitive::kPrimFloat:
1400 case Primitive::kPrimDouble: {
1401 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
1402 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
1403 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
1404 if (instruction->IsAdd()) {
1405 if (type == Primitive::kPrimFloat) {
1406 __ AddS(dst, lhs, rhs);
1407 } else {
1408 __ AddD(dst, lhs, rhs);
1409 }
1410 } else {
1411 DCHECK(instruction->IsSub());
1412 if (type == Primitive::kPrimFloat) {
1413 __ SubS(dst, lhs, rhs);
1414 } else {
1415 __ SubD(dst, lhs, rhs);
1416 }
1417 }
1418 break;
1419 }
1420
1421 default:
1422 LOG(FATAL) << "Unexpected binary operation type " << type;
1423 }
1424}
1425
1426void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001427 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001428
1429 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1430 Primitive::Type type = instr->GetResultType();
1431 switch (type) {
1432 case Primitive::kPrimInt:
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001433 locations->SetInAt(0, Location::RequiresRegister());
1434 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1435 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1436 break;
1437 case Primitive::kPrimLong:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001438 locations->SetInAt(0, Location::RequiresRegister());
1439 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1440 locations->SetOut(Location::RequiresRegister());
1441 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001442 default:
1443 LOG(FATAL) << "Unexpected shift type " << type;
1444 }
1445}
1446
1447static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte;
1448
1449void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001450 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001451 LocationSummary* locations = instr->GetLocations();
1452 Primitive::Type type = instr->GetType();
1453
1454 Location rhs_location = locations->InAt(1);
1455 bool use_imm = rhs_location.IsConstant();
1456 Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>();
1457 int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0;
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001458 const uint32_t shift_mask = (type == Primitive::kPrimInt)
1459 ? kMaxIntShiftValue
1460 : kMaxLongShiftValue;
1461 const uint32_t shift_value = rhs_imm & shift_mask;
Alexey Frunze92d90602015-12-18 18:16:36 -08001462 // Are the INS (Insert Bit Field) and ROTR instructions supported?
1463 bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001464
1465 switch (type) {
1466 case Primitive::kPrimInt: {
1467 Register dst = locations->Out().AsRegister<Register>();
1468 Register lhs = locations->InAt(0).AsRegister<Register>();
1469 if (use_imm) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001470 if (shift_value == 0) {
1471 if (dst != lhs) {
1472 __ Move(dst, lhs);
1473 }
1474 } else if (instr->IsShl()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001475 __ Sll(dst, lhs, shift_value);
1476 } else if (instr->IsShr()) {
1477 __ Sra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001478 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001479 __ Srl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001480 } else {
1481 if (has_ins_rotr) {
1482 __ Rotr(dst, lhs, shift_value);
1483 } else {
1484 __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask);
1485 __ Srl(dst, lhs, shift_value);
1486 __ Or(dst, dst, TMP);
1487 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001488 }
1489 } else {
1490 if (instr->IsShl()) {
1491 __ Sllv(dst, lhs, rhs_reg);
1492 } else if (instr->IsShr()) {
1493 __ Srav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001494 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001495 __ Srlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001496 } else {
1497 if (has_ins_rotr) {
1498 __ Rotrv(dst, lhs, rhs_reg);
1499 } else {
1500 __ Subu(TMP, ZERO, rhs_reg);
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001501 // 32-bit shift instructions use the 5 least significant bits of the shift count, so
1502 // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case
1503 // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out
1504 // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`,
1505 // IOW, the OR'd values are equal.
Alexey Frunze92d90602015-12-18 18:16:36 -08001506 __ Sllv(TMP, lhs, TMP);
1507 __ Srlv(dst, lhs, rhs_reg);
1508 __ Or(dst, dst, TMP);
1509 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001510 }
1511 }
1512 break;
1513 }
1514
1515 case Primitive::kPrimLong: {
1516 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
1517 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
1518 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
1519 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
1520 if (use_imm) {
1521 if (shift_value == 0) {
1522 codegen_->Move64(locations->Out(), locations->InAt(0));
1523 } else if (shift_value < kMipsBitsPerWord) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001524 if (has_ins_rotr) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001525 if (instr->IsShl()) {
1526 __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value);
1527 __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value);
1528 __ Sll(dst_low, lhs_low, shift_value);
1529 } else if (instr->IsShr()) {
1530 __ Srl(dst_low, lhs_low, shift_value);
1531 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1532 __ Sra(dst_high, lhs_high, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001533 } else if (instr->IsUShr()) {
1534 __ Srl(dst_low, lhs_low, shift_value);
1535 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1536 __ Srl(dst_high, lhs_high, shift_value);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001537 } else {
1538 __ Srl(dst_low, lhs_low, shift_value);
1539 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1540 __ Srl(dst_high, lhs_high, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001541 __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001542 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001543 } else {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001544 if (instr->IsShl()) {
1545 __ Sll(dst_low, lhs_low, shift_value);
1546 __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value);
1547 __ Sll(dst_high, lhs_high, shift_value);
1548 __ Or(dst_high, dst_high, TMP);
1549 } else if (instr->IsShr()) {
1550 __ Sra(dst_high, lhs_high, shift_value);
1551 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value);
1552 __ Srl(dst_low, lhs_low, shift_value);
1553 __ Or(dst_low, dst_low, TMP);
Alexey Frunze92d90602015-12-18 18:16:36 -08001554 } else if (instr->IsUShr()) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001555 __ Srl(dst_high, lhs_high, shift_value);
1556 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value);
1557 __ Srl(dst_low, lhs_low, shift_value);
1558 __ Or(dst_low, dst_low, TMP);
Alexey Frunze92d90602015-12-18 18:16:36 -08001559 } else {
1560 __ Srl(TMP, lhs_low, shift_value);
1561 __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value);
1562 __ Or(dst_low, dst_low, TMP);
1563 __ Srl(TMP, lhs_high, shift_value);
1564 __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value);
1565 __ Or(dst_high, dst_high, TMP);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001566 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001567 }
1568 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001569 const uint32_t shift_value_high = shift_value - kMipsBitsPerWord;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001570 if (instr->IsShl()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001571 __ Sll(dst_high, lhs_low, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001572 __ Move(dst_low, ZERO);
1573 } else if (instr->IsShr()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001574 __ Sra(dst_low, lhs_high, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001575 __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1);
Alexey Frunze92d90602015-12-18 18:16:36 -08001576 } else if (instr->IsUShr()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001577 __ Srl(dst_low, lhs_high, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001578 __ Move(dst_high, ZERO);
Alexey Frunze92d90602015-12-18 18:16:36 -08001579 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001580 if (shift_value == kMipsBitsPerWord) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001581 // 64-bit rotation by 32 is just a swap.
1582 __ Move(dst_low, lhs_high);
1583 __ Move(dst_high, lhs_low);
1584 } else {
1585 if (has_ins_rotr) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001586 __ Srl(dst_low, lhs_high, shift_value_high);
1587 __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high);
1588 __ Srl(dst_high, lhs_low, shift_value_high);
1589 __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001590 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001591 __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high);
1592 __ Srl(dst_low, lhs_high, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001593 __ Or(dst_low, dst_low, TMP);
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001594 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high);
1595 __ Srl(dst_high, lhs_low, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001596 __ Or(dst_high, dst_high, TMP);
1597 }
1598 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001599 }
1600 }
1601 } else {
1602 MipsLabel done;
1603 if (instr->IsShl()) {
1604 __ Sllv(dst_low, lhs_low, rhs_reg);
1605 __ Nor(AT, ZERO, rhs_reg);
1606 __ Srl(TMP, lhs_low, 1);
1607 __ Srlv(TMP, TMP, AT);
1608 __ Sllv(dst_high, lhs_high, rhs_reg);
1609 __ Or(dst_high, dst_high, TMP);
1610 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1611 __ Beqz(TMP, &done);
1612 __ Move(dst_high, dst_low);
1613 __ Move(dst_low, ZERO);
1614 } else if (instr->IsShr()) {
1615 __ Srav(dst_high, lhs_high, rhs_reg);
1616 __ Nor(AT, ZERO, rhs_reg);
1617 __ Sll(TMP, lhs_high, 1);
1618 __ Sllv(TMP, TMP, AT);
1619 __ Srlv(dst_low, lhs_low, rhs_reg);
1620 __ Or(dst_low, dst_low, TMP);
1621 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1622 __ Beqz(TMP, &done);
1623 __ Move(dst_low, dst_high);
1624 __ Sra(dst_high, dst_high, 31);
Alexey Frunze92d90602015-12-18 18:16:36 -08001625 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001626 __ Srlv(dst_high, lhs_high, rhs_reg);
1627 __ Nor(AT, ZERO, rhs_reg);
1628 __ Sll(TMP, lhs_high, 1);
1629 __ Sllv(TMP, TMP, AT);
1630 __ Srlv(dst_low, lhs_low, rhs_reg);
1631 __ Or(dst_low, dst_low, TMP);
1632 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1633 __ Beqz(TMP, &done);
1634 __ Move(dst_low, dst_high);
1635 __ Move(dst_high, ZERO);
Alexey Frunze92d90602015-12-18 18:16:36 -08001636 } else {
1637 __ Nor(AT, ZERO, rhs_reg);
1638 __ Srlv(TMP, lhs_low, rhs_reg);
1639 __ Sll(dst_low, lhs_high, 1);
1640 __ Sllv(dst_low, dst_low, AT);
1641 __ Or(dst_low, dst_low, TMP);
1642 __ Srlv(TMP, lhs_high, rhs_reg);
1643 __ Sll(dst_high, lhs_low, 1);
1644 __ Sllv(dst_high, dst_high, AT);
1645 __ Or(dst_high, dst_high, TMP);
1646 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1647 __ Beqz(TMP, &done);
1648 __ Move(TMP, dst_high);
1649 __ Move(dst_high, dst_low);
1650 __ Move(dst_low, TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001651 }
1652 __ Bind(&done);
1653 }
1654 break;
1655 }
1656
1657 default:
1658 LOG(FATAL) << "Unexpected shift operation type " << type;
1659 }
1660}
1661
1662void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) {
1663 HandleBinaryOp(instruction);
1664}
1665
1666void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) {
1667 HandleBinaryOp(instruction);
1668}
1669
1670void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) {
1671 HandleBinaryOp(instruction);
1672}
1673
1674void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) {
1675 HandleBinaryOp(instruction);
1676}
1677
1678void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) {
1679 LocationSummary* locations =
1680 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1681 locations->SetInAt(0, Location::RequiresRegister());
1682 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1683 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1684 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1685 } else {
1686 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1687 }
1688}
1689
1690void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) {
1691 LocationSummary* locations = instruction->GetLocations();
1692 Register obj = locations->InAt(0).AsRegister<Register>();
1693 Location index = locations->InAt(1);
1694 Primitive::Type type = instruction->GetType();
1695
1696 switch (type) {
1697 case Primitive::kPrimBoolean: {
1698 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
1699 Register out = locations->Out().AsRegister<Register>();
1700 if (index.IsConstant()) {
1701 size_t offset =
1702 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1703 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1704 } else {
1705 __ Addu(TMP, obj, index.AsRegister<Register>());
1706 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset);
1707 }
1708 break;
1709 }
1710
1711 case Primitive::kPrimByte: {
1712 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
1713 Register out = locations->Out().AsRegister<Register>();
1714 if (index.IsConstant()) {
1715 size_t offset =
1716 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1717 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1718 } else {
1719 __ Addu(TMP, obj, index.AsRegister<Register>());
1720 __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset);
1721 }
1722 break;
1723 }
1724
1725 case Primitive::kPrimShort: {
1726 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
1727 Register out = locations->Out().AsRegister<Register>();
1728 if (index.IsConstant()) {
1729 size_t offset =
1730 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1731 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1732 } else {
1733 __ Sll(TMP, index.AsRegister<Register>(), TIMES_2);
1734 __ Addu(TMP, obj, TMP);
1735 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset);
1736 }
1737 break;
1738 }
1739
1740 case Primitive::kPrimChar: {
1741 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
1742 Register out = locations->Out().AsRegister<Register>();
1743 if (index.IsConstant()) {
1744 size_t offset =
1745 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1746 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1747 } else {
1748 __ Sll(TMP, index.AsRegister<Register>(), TIMES_2);
1749 __ Addu(TMP, obj, TMP);
1750 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset);
1751 }
1752 break;
1753 }
1754
1755 case Primitive::kPrimInt:
1756 case Primitive::kPrimNot: {
1757 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
1758 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
1759 Register out = locations->Out().AsRegister<Register>();
1760 if (index.IsConstant()) {
1761 size_t offset =
1762 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1763 __ LoadFromOffset(kLoadWord, out, obj, offset);
1764 } else {
1765 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
1766 __ Addu(TMP, obj, TMP);
1767 __ LoadFromOffset(kLoadWord, out, TMP, data_offset);
1768 }
1769 break;
1770 }
1771
1772 case Primitive::kPrimLong: {
1773 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
1774 Register out = locations->Out().AsRegisterPairLow<Register>();
1775 if (index.IsConstant()) {
1776 size_t offset =
1777 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1778 __ LoadFromOffset(kLoadDoubleword, out, obj, offset);
1779 } else {
1780 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
1781 __ Addu(TMP, obj, TMP);
1782 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset);
1783 }
1784 break;
1785 }
1786
1787 case Primitive::kPrimFloat: {
1788 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
1789 FRegister out = locations->Out().AsFpuRegister<FRegister>();
1790 if (index.IsConstant()) {
1791 size_t offset =
1792 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1793 __ LoadSFromOffset(out, obj, offset);
1794 } else {
1795 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
1796 __ Addu(TMP, obj, TMP);
1797 __ LoadSFromOffset(out, TMP, data_offset);
1798 }
1799 break;
1800 }
1801
1802 case Primitive::kPrimDouble: {
1803 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
1804 FRegister out = locations->Out().AsFpuRegister<FRegister>();
1805 if (index.IsConstant()) {
1806 size_t offset =
1807 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1808 __ LoadDFromOffset(out, obj, offset);
1809 } else {
1810 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
1811 __ Addu(TMP, obj, TMP);
1812 __ LoadDFromOffset(out, TMP, data_offset);
1813 }
1814 break;
1815 }
1816
1817 case Primitive::kPrimVoid:
1818 LOG(FATAL) << "Unreachable type " << instruction->GetType();
1819 UNREACHABLE();
1820 }
1821 codegen_->MaybeRecordImplicitNullCheck(instruction);
1822}
1823
1824void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) {
1825 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1826 locations->SetInAt(0, Location::RequiresRegister());
1827 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1828}
1829
1830void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) {
1831 LocationSummary* locations = instruction->GetLocations();
1832 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
1833 Register obj = locations->InAt(0).AsRegister<Register>();
1834 Register out = locations->Out().AsRegister<Register>();
1835 __ LoadFromOffset(kLoadWord, out, obj, offset);
1836 codegen_->MaybeRecordImplicitNullCheck(instruction);
1837}
1838
1839void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) {
Pavle Batuta934808f2015-11-03 13:23:54 +01001840 bool needs_runtime_call = instruction->NeedsTypeCheck();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001841 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1842 instruction,
Pavle Batuta934808f2015-11-03 13:23:54 +01001843 needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
1844 if (needs_runtime_call) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001845 InvokeRuntimeCallingConvention calling_convention;
1846 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1847 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1848 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1849 } else {
1850 locations->SetInAt(0, Location::RequiresRegister());
1851 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1852 if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
1853 locations->SetInAt(2, Location::RequiresFpuRegister());
1854 } else {
1855 locations->SetInAt(2, Location::RequiresRegister());
1856 }
1857 }
1858}
1859
1860void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) {
1861 LocationSummary* locations = instruction->GetLocations();
1862 Register obj = locations->InAt(0).AsRegister<Register>();
1863 Location index = locations->InAt(1);
1864 Primitive::Type value_type = instruction->GetComponentType();
1865 bool needs_runtime_call = locations->WillCall();
1866 bool needs_write_barrier =
1867 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
1868
1869 switch (value_type) {
1870 case Primitive::kPrimBoolean:
1871 case Primitive::kPrimByte: {
1872 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
1873 Register value = locations->InAt(2).AsRegister<Register>();
1874 if (index.IsConstant()) {
1875 size_t offset =
1876 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1877 __ StoreToOffset(kStoreByte, value, obj, offset);
1878 } else {
1879 __ Addu(TMP, obj, index.AsRegister<Register>());
1880 __ StoreToOffset(kStoreByte, value, TMP, data_offset);
1881 }
1882 break;
1883 }
1884
1885 case Primitive::kPrimShort:
1886 case Primitive::kPrimChar: {
1887 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
1888 Register value = locations->InAt(2).AsRegister<Register>();
1889 if (index.IsConstant()) {
1890 size_t offset =
1891 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1892 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1893 } else {
1894 __ Sll(TMP, index.AsRegister<Register>(), TIMES_2);
1895 __ Addu(TMP, obj, TMP);
1896 __ StoreToOffset(kStoreHalfword, value, TMP, data_offset);
1897 }
1898 break;
1899 }
1900
1901 case Primitive::kPrimInt:
1902 case Primitive::kPrimNot: {
1903 if (!needs_runtime_call) {
1904 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
1905 Register value = locations->InAt(2).AsRegister<Register>();
1906 if (index.IsConstant()) {
1907 size_t offset =
1908 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1909 __ StoreToOffset(kStoreWord, value, obj, offset);
1910 } else {
1911 DCHECK(index.IsRegister()) << index;
1912 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
1913 __ Addu(TMP, obj, TMP);
1914 __ StoreToOffset(kStoreWord, value, TMP, data_offset);
1915 }
1916 codegen_->MaybeRecordImplicitNullCheck(instruction);
1917 if (needs_write_barrier) {
1918 DCHECK_EQ(value_type, Primitive::kPrimNot);
1919 codegen_->MarkGCCard(obj, value);
1920 }
1921 } else {
1922 DCHECK_EQ(value_type, Primitive::kPrimNot);
1923 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
1924 instruction,
1925 instruction->GetDexPc(),
1926 nullptr,
1927 IsDirectEntrypoint(kQuickAputObject));
1928 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
1929 }
1930 break;
1931 }
1932
1933 case Primitive::kPrimLong: {
1934 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
1935 Register value = locations->InAt(2).AsRegisterPairLow<Register>();
1936 if (index.IsConstant()) {
1937 size_t offset =
1938 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1939 __ StoreToOffset(kStoreDoubleword, value, obj, offset);
1940 } else {
1941 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
1942 __ Addu(TMP, obj, TMP);
1943 __ StoreToOffset(kStoreDoubleword, value, TMP, data_offset);
1944 }
1945 break;
1946 }
1947
1948 case Primitive::kPrimFloat: {
1949 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
1950 FRegister value = locations->InAt(2).AsFpuRegister<FRegister>();
1951 DCHECK(locations->InAt(2).IsFpuRegister());
1952 if (index.IsConstant()) {
1953 size_t offset =
1954 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1955 __ StoreSToOffset(value, obj, offset);
1956 } else {
1957 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
1958 __ Addu(TMP, obj, TMP);
1959 __ StoreSToOffset(value, TMP, data_offset);
1960 }
1961 break;
1962 }
1963
1964 case Primitive::kPrimDouble: {
1965 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
1966 FRegister value = locations->InAt(2).AsFpuRegister<FRegister>();
1967 DCHECK(locations->InAt(2).IsFpuRegister());
1968 if (index.IsConstant()) {
1969 size_t offset =
1970 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
1971 __ StoreDToOffset(value, obj, offset);
1972 } else {
1973 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
1974 __ Addu(TMP, obj, TMP);
1975 __ StoreDToOffset(value, TMP, data_offset);
1976 }
1977 break;
1978 }
1979
1980 case Primitive::kPrimVoid:
1981 LOG(FATAL) << "Unreachable type " << instruction->GetType();
1982 UNREACHABLE();
1983 }
1984
1985 // Ints and objects are handled in the switch.
1986 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
1987 codegen_->MaybeRecordImplicitNullCheck(instruction);
1988 }
1989}
1990
1991void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) {
1992 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
1993 ? LocationSummary::kCallOnSlowPath
1994 : LocationSummary::kNoCall;
1995 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
1996 locations->SetInAt(0, Location::RequiresRegister());
1997 locations->SetInAt(1, Location::RequiresRegister());
1998 if (instruction->HasUses()) {
1999 locations->SetOut(Location::SameAsFirstInput());
2000 }
2001}
2002
2003void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) {
2004 LocationSummary* locations = instruction->GetLocations();
2005 BoundsCheckSlowPathMIPS* slow_path =
2006 new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS(instruction);
2007 codegen_->AddSlowPath(slow_path);
2008
2009 Register index = locations->InAt(0).AsRegister<Register>();
2010 Register length = locations->InAt(1).AsRegister<Register>();
2011
2012 // length is limited by the maximum positive signed 32-bit integer.
2013 // Unsigned comparison of length and index checks for index < 0
2014 // and for length <= index simultaneously.
2015 __ Bgeu(index, length, slow_path->GetEntryLabel());
2016}
2017
2018void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) {
2019 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
2020 instruction,
2021 LocationSummary::kCallOnSlowPath);
2022 locations->SetInAt(0, Location::RequiresRegister());
2023 locations->SetInAt(1, Location::RequiresRegister());
2024 // Note that TypeCheckSlowPathMIPS uses this register too.
2025 locations->AddTemp(Location::RequiresRegister());
2026}
2027
2028void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) {
2029 LocationSummary* locations = instruction->GetLocations();
2030 Register obj = locations->InAt(0).AsRegister<Register>();
2031 Register cls = locations->InAt(1).AsRegister<Register>();
2032 Register obj_cls = locations->GetTemp(0).AsRegister<Register>();
2033
2034 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction);
2035 codegen_->AddSlowPath(slow_path);
2036
2037 // TODO: avoid this check if we know obj is not null.
2038 __ Beqz(obj, slow_path->GetExitLabel());
2039 // Compare the class of `obj` with `cls`.
2040 __ LoadFromOffset(kLoadWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value());
2041 __ Bne(obj_cls, cls, slow_path->GetEntryLabel());
2042 __ Bind(slow_path->GetExitLabel());
2043}
2044
2045void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) {
2046 LocationSummary* locations =
2047 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2048 locations->SetInAt(0, Location::RequiresRegister());
2049 if (check->HasUses()) {
2050 locations->SetOut(Location::SameAsFirstInput());
2051 }
2052}
2053
2054void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) {
2055 // We assume the class is not null.
2056 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS(
2057 check->GetLoadClass(),
2058 check,
2059 check->GetDexPc(),
2060 true);
2061 codegen_->AddSlowPath(slow_path);
2062 GenerateClassInitializationCheck(slow_path,
2063 check->GetLocations()->InAt(0).AsRegister<Register>());
2064}
2065
2066void LocationsBuilderMIPS::VisitCompare(HCompare* compare) {
2067 Primitive::Type in_type = compare->InputAt(0)->GetType();
2068
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002069 LocationSummary* locations =
2070 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002071
2072 switch (in_type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00002073 case Primitive::kPrimBoolean:
2074 case Primitive::kPrimByte:
2075 case Primitive::kPrimShort:
2076 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08002077 case Primitive::kPrimInt:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002078 case Primitive::kPrimLong:
2079 locations->SetInAt(0, Location::RequiresRegister());
2080 locations->SetInAt(1, Location::RequiresRegister());
2081 // Output overlaps because it is written before doing the low comparison.
2082 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
2083 break;
2084
2085 case Primitive::kPrimFloat:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002086 case Primitive::kPrimDouble:
2087 locations->SetInAt(0, Location::RequiresFpuRegister());
2088 locations->SetInAt(1, Location::RequiresFpuRegister());
2089 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002090 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002091
2092 default:
2093 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
2094 }
2095}
2096
2097void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) {
2098 LocationSummary* locations = instruction->GetLocations();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002099 Register res = locations->Out().AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002100 Primitive::Type in_type = instruction->InputAt(0)->GetType();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002101 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002102
2103 // 0 if: left == right
2104 // 1 if: left > right
2105 // -1 if: left < right
2106 switch (in_type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00002107 case Primitive::kPrimBoolean:
2108 case Primitive::kPrimByte:
2109 case Primitive::kPrimShort:
2110 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08002111 case Primitive::kPrimInt: {
2112 Register lhs = locations->InAt(0).AsRegister<Register>();
2113 Register rhs = locations->InAt(1).AsRegister<Register>();
2114 __ Slt(TMP, lhs, rhs);
2115 __ Slt(res, rhs, lhs);
2116 __ Subu(res, res, TMP);
2117 break;
2118 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002119 case Primitive::kPrimLong: {
2120 MipsLabel done;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002121 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
2122 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
2123 Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>();
2124 Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>();
2125 // TODO: more efficient (direct) comparison with a constant.
2126 __ Slt(TMP, lhs_high, rhs_high);
2127 __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt.
2128 __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ].
2129 __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal.
2130 __ Sltu(TMP, lhs_low, rhs_low);
2131 __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt.
2132 __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ].
2133 __ Bind(&done);
2134 break;
2135 }
2136
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002137 case Primitive::kPrimFloat: {
Roland Levillain32ca3752016-02-17 16:49:37 +00002138 bool gt_bias = instruction->IsGtBias();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002139 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2140 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2141 MipsLabel done;
2142 if (isR6) {
2143 __ CmpEqS(FTMP, lhs, rhs);
2144 __ LoadConst32(res, 0);
2145 __ Bc1nez(FTMP, &done);
2146 if (gt_bias) {
2147 __ CmpLtS(FTMP, lhs, rhs);
2148 __ LoadConst32(res, -1);
2149 __ Bc1nez(FTMP, &done);
2150 __ LoadConst32(res, 1);
2151 } else {
2152 __ CmpLtS(FTMP, rhs, lhs);
2153 __ LoadConst32(res, 1);
2154 __ Bc1nez(FTMP, &done);
2155 __ LoadConst32(res, -1);
2156 }
2157 } else {
2158 if (gt_bias) {
2159 __ ColtS(0, lhs, rhs);
2160 __ LoadConst32(res, -1);
2161 __ Bc1t(0, &done);
2162 __ CeqS(0, lhs, rhs);
2163 __ LoadConst32(res, 1);
2164 __ Movt(res, ZERO, 0);
2165 } else {
2166 __ ColtS(0, rhs, lhs);
2167 __ LoadConst32(res, 1);
2168 __ Bc1t(0, &done);
2169 __ CeqS(0, lhs, rhs);
2170 __ LoadConst32(res, -1);
2171 __ Movt(res, ZERO, 0);
2172 }
2173 }
2174 __ Bind(&done);
2175 break;
2176 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002177 case Primitive::kPrimDouble: {
Roland Levillain32ca3752016-02-17 16:49:37 +00002178 bool gt_bias = instruction->IsGtBias();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002179 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2180 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2181 MipsLabel done;
2182 if (isR6) {
2183 __ CmpEqD(FTMP, lhs, rhs);
2184 __ LoadConst32(res, 0);
2185 __ Bc1nez(FTMP, &done);
2186 if (gt_bias) {
2187 __ CmpLtD(FTMP, lhs, rhs);
2188 __ LoadConst32(res, -1);
2189 __ Bc1nez(FTMP, &done);
2190 __ LoadConst32(res, 1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002191 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002192 __ CmpLtD(FTMP, rhs, lhs);
2193 __ LoadConst32(res, 1);
2194 __ Bc1nez(FTMP, &done);
2195 __ LoadConst32(res, -1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002196 }
2197 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002198 if (gt_bias) {
2199 __ ColtD(0, lhs, rhs);
2200 __ LoadConst32(res, -1);
2201 __ Bc1t(0, &done);
2202 __ CeqD(0, lhs, rhs);
2203 __ LoadConst32(res, 1);
2204 __ Movt(res, ZERO, 0);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002205 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002206 __ ColtD(0, rhs, lhs);
2207 __ LoadConst32(res, 1);
2208 __ Bc1t(0, &done);
2209 __ CeqD(0, lhs, rhs);
2210 __ LoadConst32(res, -1);
2211 __ Movt(res, ZERO, 0);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002212 }
2213 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002214 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002215 break;
2216 }
2217
2218 default:
2219 LOG(FATAL) << "Unimplemented compare type " << in_type;
2220 }
2221}
2222
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002223void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002224 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002225 switch (instruction->InputAt(0)->GetType()) {
2226 default:
2227 case Primitive::kPrimLong:
2228 locations->SetInAt(0, Location::RequiresRegister());
2229 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2230 break;
2231
2232 case Primitive::kPrimFloat:
2233 case Primitive::kPrimDouble:
2234 locations->SetInAt(0, Location::RequiresFpuRegister());
2235 locations->SetInAt(1, Location::RequiresFpuRegister());
2236 break;
2237 }
David Brazdilb3e773e2016-01-26 11:28:37 +00002238 if (!instruction->IsEmittedAtUseSite()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002239 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2240 }
2241}
2242
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002243void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) {
David Brazdilb3e773e2016-01-26 11:28:37 +00002244 if (instruction->IsEmittedAtUseSite()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002245 return;
2246 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002247
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002248 Primitive::Type type = instruction->InputAt(0)->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002249 LocationSummary* locations = instruction->GetLocations();
2250 Register dst = locations->Out().AsRegister<Register>();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002251 MipsLabel true_label;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002252
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002253 switch (type) {
2254 default:
2255 // Integer case.
2256 GenerateIntCompare(instruction->GetCondition(), locations);
2257 return;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002258
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002259 case Primitive::kPrimLong:
2260 // TODO: don't use branches.
2261 GenerateLongCompareAndBranch(instruction->GetCondition(), locations, &true_label);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002262 break;
2263
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002264 case Primitive::kPrimFloat:
2265 case Primitive::kPrimDouble:
2266 // TODO: don't use branches.
2267 GenerateFpCompareAndBranch(instruction->GetCondition(),
2268 instruction->IsGtBias(),
2269 type,
2270 locations,
2271 &true_label);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002272 break;
2273 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002274
2275 // Convert the branches into the result.
2276 MipsLabel done;
2277
2278 // False case: result = 0.
2279 __ LoadConst32(dst, 0);
2280 __ B(&done);
2281
2282 // True case: result = 1.
2283 __ Bind(&true_label);
2284 __ LoadConst32(dst, 1);
2285 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002286}
2287
Alexey Frunze7e99e052015-11-24 19:28:01 -08002288void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2289 DCHECK(instruction->IsDiv() || instruction->IsRem());
2290 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2291
2292 LocationSummary* locations = instruction->GetLocations();
2293 Location second = locations->InAt(1);
2294 DCHECK(second.IsConstant());
2295
2296 Register out = locations->Out().AsRegister<Register>();
2297 Register dividend = locations->InAt(0).AsRegister<Register>();
2298 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2299 DCHECK(imm == 1 || imm == -1);
2300
2301 if (instruction->IsRem()) {
2302 __ Move(out, ZERO);
2303 } else {
2304 if (imm == -1) {
2305 __ Subu(out, ZERO, dividend);
2306 } else if (out != dividend) {
2307 __ Move(out, dividend);
2308 }
2309 }
2310}
2311
2312void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2313 DCHECK(instruction->IsDiv() || instruction->IsRem());
2314 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2315
2316 LocationSummary* locations = instruction->GetLocations();
2317 Location second = locations->InAt(1);
2318 DCHECK(second.IsConstant());
2319
2320 Register out = locations->Out().AsRegister<Register>();
2321 Register dividend = locations->InAt(0).AsRegister<Register>();
2322 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002323 uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm));
Alexey Frunze7e99e052015-11-24 19:28:01 -08002324 int ctz_imm = CTZ(abs_imm);
2325
2326 if (instruction->IsDiv()) {
2327 if (ctz_imm == 1) {
2328 // Fast path for division by +/-2, which is very common.
2329 __ Srl(TMP, dividend, 31);
2330 } else {
2331 __ Sra(TMP, dividend, 31);
2332 __ Srl(TMP, TMP, 32 - ctz_imm);
2333 }
2334 __ Addu(out, dividend, TMP);
2335 __ Sra(out, out, ctz_imm);
2336 if (imm < 0) {
2337 __ Subu(out, ZERO, out);
2338 }
2339 } else {
2340 if (ctz_imm == 1) {
2341 // Fast path for modulo +/-2, which is very common.
2342 __ Sra(TMP, dividend, 31);
2343 __ Subu(out, dividend, TMP);
2344 __ Andi(out, out, 1);
2345 __ Addu(out, out, TMP);
2346 } else {
2347 __ Sra(TMP, dividend, 31);
2348 __ Srl(TMP, TMP, 32 - ctz_imm);
2349 __ Addu(out, dividend, TMP);
2350 if (IsUint<16>(abs_imm - 1)) {
2351 __ Andi(out, out, abs_imm - 1);
2352 } else {
2353 __ Sll(out, out, 32 - ctz_imm);
2354 __ Srl(out, out, 32 - ctz_imm);
2355 }
2356 __ Subu(out, out, TMP);
2357 }
2358 }
2359}
2360
2361void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2362 DCHECK(instruction->IsDiv() || instruction->IsRem());
2363 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2364
2365 LocationSummary* locations = instruction->GetLocations();
2366 Location second = locations->InAt(1);
2367 DCHECK(second.IsConstant());
2368
2369 Register out = locations->Out().AsRegister<Register>();
2370 Register dividend = locations->InAt(0).AsRegister<Register>();
2371 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2372
2373 int64_t magic;
2374 int shift;
2375 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2376
2377 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
2378
2379 __ LoadConst32(TMP, magic);
2380 if (isR6) {
2381 __ MuhR6(TMP, dividend, TMP);
2382 } else {
2383 __ MultR2(dividend, TMP);
2384 __ Mfhi(TMP);
2385 }
2386 if (imm > 0 && magic < 0) {
2387 __ Addu(TMP, TMP, dividend);
2388 } else if (imm < 0 && magic > 0) {
2389 __ Subu(TMP, TMP, dividend);
2390 }
2391
2392 if (shift != 0) {
2393 __ Sra(TMP, TMP, shift);
2394 }
2395
2396 if (instruction->IsDiv()) {
2397 __ Sra(out, TMP, 31);
2398 __ Subu(out, TMP, out);
2399 } else {
2400 __ Sra(AT, TMP, 31);
2401 __ Subu(AT, TMP, AT);
2402 __ LoadConst32(TMP, imm);
2403 if (isR6) {
2404 __ MulR6(TMP, AT, TMP);
2405 } else {
2406 __ MulR2(TMP, AT, TMP);
2407 }
2408 __ Subu(out, dividend, TMP);
2409 }
2410}
2411
2412void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) {
2413 DCHECK(instruction->IsDiv() || instruction->IsRem());
2414 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2415
2416 LocationSummary* locations = instruction->GetLocations();
2417 Register out = locations->Out().AsRegister<Register>();
2418 Location second = locations->InAt(1);
2419
2420 if (second.IsConstant()) {
2421 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2422 if (imm == 0) {
2423 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2424 } else if (imm == 1 || imm == -1) {
2425 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002426 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08002427 DivRemByPowerOfTwo(instruction);
2428 } else {
2429 DCHECK(imm <= -2 || imm >= 2);
2430 GenerateDivRemWithAnyConstant(instruction);
2431 }
2432 } else {
2433 Register dividend = locations->InAt(0).AsRegister<Register>();
2434 Register divisor = second.AsRegister<Register>();
2435 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
2436 if (instruction->IsDiv()) {
2437 if (isR6) {
2438 __ DivR6(out, dividend, divisor);
2439 } else {
2440 __ DivR2(out, dividend, divisor);
2441 }
2442 } else {
2443 if (isR6) {
2444 __ ModR6(out, dividend, divisor);
2445 } else {
2446 __ ModR2(out, dividend, divisor);
2447 }
2448 }
2449 }
2450}
2451
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002452void LocationsBuilderMIPS::VisitDiv(HDiv* div) {
2453 Primitive::Type type = div->GetResultType();
2454 LocationSummary::CallKind call_kind = (type == Primitive::kPrimLong)
2455 ? LocationSummary::kCall
2456 : LocationSummary::kNoCall;
2457
2458 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2459
2460 switch (type) {
2461 case Primitive::kPrimInt:
2462 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze7e99e052015-11-24 19:28:01 -08002463 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002464 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2465 break;
2466
2467 case Primitive::kPrimLong: {
2468 InvokeRuntimeCallingConvention calling_convention;
2469 locations->SetInAt(0, Location::RegisterPairLocation(
2470 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2471 locations->SetInAt(1, Location::RegisterPairLocation(
2472 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2473 locations->SetOut(calling_convention.GetReturnLocation(type));
2474 break;
2475 }
2476
2477 case Primitive::kPrimFloat:
2478 case Primitive::kPrimDouble:
2479 locations->SetInAt(0, Location::RequiresFpuRegister());
2480 locations->SetInAt(1, Location::RequiresFpuRegister());
2481 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2482 break;
2483
2484 default:
2485 LOG(FATAL) << "Unexpected div type " << type;
2486 }
2487}
2488
2489void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) {
2490 Primitive::Type type = instruction->GetType();
2491 LocationSummary* locations = instruction->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002492
2493 switch (type) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08002494 case Primitive::kPrimInt:
2495 GenerateDivRemIntegral(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002496 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002497 case Primitive::kPrimLong: {
2498 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv),
2499 instruction,
2500 instruction->GetDexPc(),
2501 nullptr,
2502 IsDirectEntrypoint(kQuickLdiv));
2503 CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>();
2504 break;
2505 }
2506 case Primitive::kPrimFloat:
2507 case Primitive::kPrimDouble: {
2508 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
2509 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2510 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2511 if (type == Primitive::kPrimFloat) {
2512 __ DivS(dst, lhs, rhs);
2513 } else {
2514 __ DivD(dst, lhs, rhs);
2515 }
2516 break;
2517 }
2518 default:
2519 LOG(FATAL) << "Unexpected div type " << type;
2520 }
2521}
2522
2523void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2524 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
2525 ? LocationSummary::kCallOnSlowPath
2526 : LocationSummary::kNoCall;
2527 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
2528 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
2529 if (instruction->HasUses()) {
2530 locations->SetOut(Location::SameAsFirstInput());
2531 }
2532}
2533
2534void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2535 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS(instruction);
2536 codegen_->AddSlowPath(slow_path);
2537 Location value = instruction->GetLocations()->InAt(0);
2538 Primitive::Type type = instruction->GetType();
2539
2540 switch (type) {
Nicolas Geoffraye5671612016-03-16 11:03:54 +00002541 case Primitive::kPrimBoolean:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002542 case Primitive::kPrimByte:
2543 case Primitive::kPrimChar:
2544 case Primitive::kPrimShort:
2545 case Primitive::kPrimInt: {
2546 if (value.IsConstant()) {
2547 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2548 __ B(slow_path->GetEntryLabel());
2549 } else {
2550 // A division by a non-null constant is valid. We don't need to perform
2551 // any check, so simply fall through.
2552 }
2553 } else {
2554 DCHECK(value.IsRegister()) << value;
2555 __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel());
2556 }
2557 break;
2558 }
2559 case Primitive::kPrimLong: {
2560 if (value.IsConstant()) {
2561 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2562 __ B(slow_path->GetEntryLabel());
2563 } else {
2564 // A division by a non-null constant is valid. We don't need to perform
2565 // any check, so simply fall through.
2566 }
2567 } else {
2568 DCHECK(value.IsRegisterPair()) << value;
2569 __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>());
2570 __ Beqz(TMP, slow_path->GetEntryLabel());
2571 }
2572 break;
2573 }
2574 default:
2575 LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck.";
2576 }
2577}
2578
2579void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) {
2580 LocationSummary* locations =
2581 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2582 locations->SetOut(Location::ConstantLocation(constant));
2583}
2584
2585void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) {
2586 // Will be generated at use site.
2587}
2588
2589void LocationsBuilderMIPS::VisitExit(HExit* exit) {
2590 exit->SetLocations(nullptr);
2591}
2592
2593void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
2594}
2595
2596void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) {
2597 LocationSummary* locations =
2598 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2599 locations->SetOut(Location::ConstantLocation(constant));
2600}
2601
2602void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
2603 // Will be generated at use site.
2604}
2605
2606void LocationsBuilderMIPS::VisitGoto(HGoto* got) {
2607 got->SetLocations(nullptr);
2608}
2609
2610void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) {
2611 DCHECK(!successor->IsExitBlock());
2612 HBasicBlock* block = got->GetBlock();
2613 HInstruction* previous = got->GetPrevious();
2614 HLoopInformation* info = block->GetLoopInformation();
2615
2616 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
2617 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
2618 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
2619 return;
2620 }
2621 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
2622 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
2623 }
2624 if (!codegen_->GoesToNextBlock(block, successor)) {
2625 __ B(codegen_->GetLabelOf(successor));
2626 }
2627}
2628
2629void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) {
2630 HandleGoto(got, got->GetSuccessor());
2631}
2632
2633void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) {
2634 try_boundary->SetLocations(nullptr);
2635}
2636
2637void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) {
2638 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
2639 if (!successor->IsExitBlock()) {
2640 HandleGoto(try_boundary, successor);
2641 }
2642}
2643
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002644void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond,
2645 LocationSummary* locations) {
2646 Register dst = locations->Out().AsRegister<Register>();
2647 Register lhs = locations->InAt(0).AsRegister<Register>();
2648 Location rhs_location = locations->InAt(1);
2649 Register rhs_reg = ZERO;
2650 int64_t rhs_imm = 0;
2651 bool use_imm = rhs_location.IsConstant();
2652 if (use_imm) {
2653 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2654 } else {
2655 rhs_reg = rhs_location.AsRegister<Register>();
2656 }
2657
2658 switch (cond) {
2659 case kCondEQ:
2660 case kCondNE:
2661 if (use_imm && IsUint<16>(rhs_imm)) {
2662 __ Xori(dst, lhs, rhs_imm);
2663 } else {
2664 if (use_imm) {
2665 rhs_reg = TMP;
2666 __ LoadConst32(rhs_reg, rhs_imm);
2667 }
2668 __ Xor(dst, lhs, rhs_reg);
2669 }
2670 if (cond == kCondEQ) {
2671 __ Sltiu(dst, dst, 1);
2672 } else {
2673 __ Sltu(dst, ZERO, dst);
2674 }
2675 break;
2676
2677 case kCondLT:
2678 case kCondGE:
2679 if (use_imm && IsInt<16>(rhs_imm)) {
2680 __ Slti(dst, lhs, rhs_imm);
2681 } else {
2682 if (use_imm) {
2683 rhs_reg = TMP;
2684 __ LoadConst32(rhs_reg, rhs_imm);
2685 }
2686 __ Slt(dst, lhs, rhs_reg);
2687 }
2688 if (cond == kCondGE) {
2689 // Simulate lhs >= rhs via !(lhs < rhs) since there's
2690 // only the slt instruction but no sge.
2691 __ Xori(dst, dst, 1);
2692 }
2693 break;
2694
2695 case kCondLE:
2696 case kCondGT:
2697 if (use_imm && IsInt<16>(rhs_imm + 1)) {
2698 // Simulate lhs <= rhs via lhs < rhs + 1.
2699 __ Slti(dst, lhs, rhs_imm + 1);
2700 if (cond == kCondGT) {
2701 // Simulate lhs > rhs via !(lhs <= rhs) since there's
2702 // only the slti instruction but no sgti.
2703 __ Xori(dst, dst, 1);
2704 }
2705 } else {
2706 if (use_imm) {
2707 rhs_reg = TMP;
2708 __ LoadConst32(rhs_reg, rhs_imm);
2709 }
2710 __ Slt(dst, rhs_reg, lhs);
2711 if (cond == kCondLE) {
2712 // Simulate lhs <= rhs via !(rhs < lhs) since there's
2713 // only the slt instruction but no sle.
2714 __ Xori(dst, dst, 1);
2715 }
2716 }
2717 break;
2718
2719 case kCondB:
2720 case kCondAE:
2721 if (use_imm && IsInt<16>(rhs_imm)) {
2722 // Sltiu sign-extends its 16-bit immediate operand before
2723 // the comparison and thus lets us compare directly with
2724 // unsigned values in the ranges [0, 0x7fff] and
2725 // [0xffff8000, 0xffffffff].
2726 __ Sltiu(dst, lhs, rhs_imm);
2727 } else {
2728 if (use_imm) {
2729 rhs_reg = TMP;
2730 __ LoadConst32(rhs_reg, rhs_imm);
2731 }
2732 __ Sltu(dst, lhs, rhs_reg);
2733 }
2734 if (cond == kCondAE) {
2735 // Simulate lhs >= rhs via !(lhs < rhs) since there's
2736 // only the sltu instruction but no sgeu.
2737 __ Xori(dst, dst, 1);
2738 }
2739 break;
2740
2741 case kCondBE:
2742 case kCondA:
2743 if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
2744 // Simulate lhs <= rhs via lhs < rhs + 1.
2745 // Note that this only works if rhs + 1 does not overflow
2746 // to 0, hence the check above.
2747 // Sltiu sign-extends its 16-bit immediate operand before
2748 // the comparison and thus lets us compare directly with
2749 // unsigned values in the ranges [0, 0x7fff] and
2750 // [0xffff8000, 0xffffffff].
2751 __ Sltiu(dst, lhs, rhs_imm + 1);
2752 if (cond == kCondA) {
2753 // Simulate lhs > rhs via !(lhs <= rhs) since there's
2754 // only the sltiu instruction but no sgtiu.
2755 __ Xori(dst, dst, 1);
2756 }
2757 } else {
2758 if (use_imm) {
2759 rhs_reg = TMP;
2760 __ LoadConst32(rhs_reg, rhs_imm);
2761 }
2762 __ Sltu(dst, rhs_reg, lhs);
2763 if (cond == kCondBE) {
2764 // Simulate lhs <= rhs via !(rhs < lhs) since there's
2765 // only the sltu instruction but no sleu.
2766 __ Xori(dst, dst, 1);
2767 }
2768 }
2769 break;
2770 }
2771}
2772
2773void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond,
2774 LocationSummary* locations,
2775 MipsLabel* label) {
2776 Register lhs = locations->InAt(0).AsRegister<Register>();
2777 Location rhs_location = locations->InAt(1);
2778 Register rhs_reg = ZERO;
2779 int32_t rhs_imm = 0;
2780 bool use_imm = rhs_location.IsConstant();
2781 if (use_imm) {
2782 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2783 } else {
2784 rhs_reg = rhs_location.AsRegister<Register>();
2785 }
2786
2787 if (use_imm && rhs_imm == 0) {
2788 switch (cond) {
2789 case kCondEQ:
2790 case kCondBE: // <= 0 if zero
2791 __ Beqz(lhs, label);
2792 break;
2793 case kCondNE:
2794 case kCondA: // > 0 if non-zero
2795 __ Bnez(lhs, label);
2796 break;
2797 case kCondLT:
2798 __ Bltz(lhs, label);
2799 break;
2800 case kCondGE:
2801 __ Bgez(lhs, label);
2802 break;
2803 case kCondLE:
2804 __ Blez(lhs, label);
2805 break;
2806 case kCondGT:
2807 __ Bgtz(lhs, label);
2808 break;
2809 case kCondB: // always false
2810 break;
2811 case kCondAE: // always true
2812 __ B(label);
2813 break;
2814 }
2815 } else {
2816 if (use_imm) {
2817 // TODO: more efficient comparison with 16-bit constants without loading them into TMP.
2818 rhs_reg = TMP;
2819 __ LoadConst32(rhs_reg, rhs_imm);
2820 }
2821 switch (cond) {
2822 case kCondEQ:
2823 __ Beq(lhs, rhs_reg, label);
2824 break;
2825 case kCondNE:
2826 __ Bne(lhs, rhs_reg, label);
2827 break;
2828 case kCondLT:
2829 __ Blt(lhs, rhs_reg, label);
2830 break;
2831 case kCondGE:
2832 __ Bge(lhs, rhs_reg, label);
2833 break;
2834 case kCondLE:
2835 __ Bge(rhs_reg, lhs, label);
2836 break;
2837 case kCondGT:
2838 __ Blt(rhs_reg, lhs, label);
2839 break;
2840 case kCondB:
2841 __ Bltu(lhs, rhs_reg, label);
2842 break;
2843 case kCondAE:
2844 __ Bgeu(lhs, rhs_reg, label);
2845 break;
2846 case kCondBE:
2847 __ Bgeu(rhs_reg, lhs, label);
2848 break;
2849 case kCondA:
2850 __ Bltu(rhs_reg, lhs, label);
2851 break;
2852 }
2853 }
2854}
2855
2856void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond,
2857 LocationSummary* locations,
2858 MipsLabel* label) {
2859 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
2860 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
2861 Location rhs_location = locations->InAt(1);
2862 Register rhs_high = ZERO;
2863 Register rhs_low = ZERO;
2864 int64_t imm = 0;
2865 uint32_t imm_high = 0;
2866 uint32_t imm_low = 0;
2867 bool use_imm = rhs_location.IsConstant();
2868 if (use_imm) {
2869 imm = rhs_location.GetConstant()->AsLongConstant()->GetValue();
2870 imm_high = High32Bits(imm);
2871 imm_low = Low32Bits(imm);
2872 } else {
2873 rhs_high = rhs_location.AsRegisterPairHigh<Register>();
2874 rhs_low = rhs_location.AsRegisterPairLow<Register>();
2875 }
2876
2877 if (use_imm && imm == 0) {
2878 switch (cond) {
2879 case kCondEQ:
2880 case kCondBE: // <= 0 if zero
2881 __ Or(TMP, lhs_high, lhs_low);
2882 __ Beqz(TMP, label);
2883 break;
2884 case kCondNE:
2885 case kCondA: // > 0 if non-zero
2886 __ Or(TMP, lhs_high, lhs_low);
2887 __ Bnez(TMP, label);
2888 break;
2889 case kCondLT:
2890 __ Bltz(lhs_high, label);
2891 break;
2892 case kCondGE:
2893 __ Bgez(lhs_high, label);
2894 break;
2895 case kCondLE:
2896 __ Or(TMP, lhs_high, lhs_low);
2897 __ Sra(AT, lhs_high, 31);
2898 __ Bgeu(AT, TMP, label);
2899 break;
2900 case kCondGT:
2901 __ Or(TMP, lhs_high, lhs_low);
2902 __ Sra(AT, lhs_high, 31);
2903 __ Bltu(AT, TMP, label);
2904 break;
2905 case kCondB: // always false
2906 break;
2907 case kCondAE: // always true
2908 __ B(label);
2909 break;
2910 }
2911 } else if (use_imm) {
2912 // TODO: more efficient comparison with constants without loading them into TMP/AT.
2913 switch (cond) {
2914 case kCondEQ:
2915 __ LoadConst32(TMP, imm_high);
2916 __ Xor(TMP, TMP, lhs_high);
2917 __ LoadConst32(AT, imm_low);
2918 __ Xor(AT, AT, lhs_low);
2919 __ Or(TMP, TMP, AT);
2920 __ Beqz(TMP, label);
2921 break;
2922 case kCondNE:
2923 __ LoadConst32(TMP, imm_high);
2924 __ Xor(TMP, TMP, lhs_high);
2925 __ LoadConst32(AT, imm_low);
2926 __ Xor(AT, AT, lhs_low);
2927 __ Or(TMP, TMP, AT);
2928 __ Bnez(TMP, label);
2929 break;
2930 case kCondLT:
2931 __ LoadConst32(TMP, imm_high);
2932 __ Blt(lhs_high, TMP, label);
2933 __ Slt(TMP, TMP, lhs_high);
2934 __ LoadConst32(AT, imm_low);
2935 __ Sltu(AT, lhs_low, AT);
2936 __ Blt(TMP, AT, label);
2937 break;
2938 case kCondGE:
2939 __ LoadConst32(TMP, imm_high);
2940 __ Blt(TMP, lhs_high, label);
2941 __ Slt(TMP, lhs_high, TMP);
2942 __ LoadConst32(AT, imm_low);
2943 __ Sltu(AT, lhs_low, AT);
2944 __ Or(TMP, TMP, AT);
2945 __ Beqz(TMP, label);
2946 break;
2947 case kCondLE:
2948 __ LoadConst32(TMP, imm_high);
2949 __ Blt(lhs_high, TMP, label);
2950 __ Slt(TMP, TMP, lhs_high);
2951 __ LoadConst32(AT, imm_low);
2952 __ Sltu(AT, AT, lhs_low);
2953 __ Or(TMP, TMP, AT);
2954 __ Beqz(TMP, label);
2955 break;
2956 case kCondGT:
2957 __ LoadConst32(TMP, imm_high);
2958 __ Blt(TMP, lhs_high, label);
2959 __ Slt(TMP, lhs_high, TMP);
2960 __ LoadConst32(AT, imm_low);
2961 __ Sltu(AT, AT, lhs_low);
2962 __ Blt(TMP, AT, label);
2963 break;
2964 case kCondB:
2965 __ LoadConst32(TMP, imm_high);
2966 __ Bltu(lhs_high, TMP, label);
2967 __ Sltu(TMP, TMP, lhs_high);
2968 __ LoadConst32(AT, imm_low);
2969 __ Sltu(AT, lhs_low, AT);
2970 __ Blt(TMP, AT, label);
2971 break;
2972 case kCondAE:
2973 __ LoadConst32(TMP, imm_high);
2974 __ Bltu(TMP, lhs_high, label);
2975 __ Sltu(TMP, lhs_high, TMP);
2976 __ LoadConst32(AT, imm_low);
2977 __ Sltu(AT, lhs_low, AT);
2978 __ Or(TMP, TMP, AT);
2979 __ Beqz(TMP, label);
2980 break;
2981 case kCondBE:
2982 __ LoadConst32(TMP, imm_high);
2983 __ Bltu(lhs_high, TMP, label);
2984 __ Sltu(TMP, TMP, lhs_high);
2985 __ LoadConst32(AT, imm_low);
2986 __ Sltu(AT, AT, lhs_low);
2987 __ Or(TMP, TMP, AT);
2988 __ Beqz(TMP, label);
2989 break;
2990 case kCondA:
2991 __ LoadConst32(TMP, imm_high);
2992 __ Bltu(TMP, lhs_high, label);
2993 __ Sltu(TMP, lhs_high, TMP);
2994 __ LoadConst32(AT, imm_low);
2995 __ Sltu(AT, AT, lhs_low);
2996 __ Blt(TMP, AT, label);
2997 break;
2998 }
2999 } else {
3000 switch (cond) {
3001 case kCondEQ:
3002 __ Xor(TMP, lhs_high, rhs_high);
3003 __ Xor(AT, lhs_low, rhs_low);
3004 __ Or(TMP, TMP, AT);
3005 __ Beqz(TMP, label);
3006 break;
3007 case kCondNE:
3008 __ Xor(TMP, lhs_high, rhs_high);
3009 __ Xor(AT, lhs_low, rhs_low);
3010 __ Or(TMP, TMP, AT);
3011 __ Bnez(TMP, label);
3012 break;
3013 case kCondLT:
3014 __ Blt(lhs_high, rhs_high, label);
3015 __ Slt(TMP, rhs_high, lhs_high);
3016 __ Sltu(AT, lhs_low, rhs_low);
3017 __ Blt(TMP, AT, label);
3018 break;
3019 case kCondGE:
3020 __ Blt(rhs_high, lhs_high, label);
3021 __ Slt(TMP, lhs_high, rhs_high);
3022 __ Sltu(AT, lhs_low, rhs_low);
3023 __ Or(TMP, TMP, AT);
3024 __ Beqz(TMP, label);
3025 break;
3026 case kCondLE:
3027 __ Blt(lhs_high, rhs_high, label);
3028 __ Slt(TMP, rhs_high, lhs_high);
3029 __ Sltu(AT, rhs_low, lhs_low);
3030 __ Or(TMP, TMP, AT);
3031 __ Beqz(TMP, label);
3032 break;
3033 case kCondGT:
3034 __ Blt(rhs_high, lhs_high, label);
3035 __ Slt(TMP, lhs_high, rhs_high);
3036 __ Sltu(AT, rhs_low, lhs_low);
3037 __ Blt(TMP, AT, label);
3038 break;
3039 case kCondB:
3040 __ Bltu(lhs_high, rhs_high, label);
3041 __ Sltu(TMP, rhs_high, lhs_high);
3042 __ Sltu(AT, lhs_low, rhs_low);
3043 __ Blt(TMP, AT, label);
3044 break;
3045 case kCondAE:
3046 __ Bltu(rhs_high, lhs_high, label);
3047 __ Sltu(TMP, lhs_high, rhs_high);
3048 __ Sltu(AT, lhs_low, rhs_low);
3049 __ Or(TMP, TMP, AT);
3050 __ Beqz(TMP, label);
3051 break;
3052 case kCondBE:
3053 __ Bltu(lhs_high, rhs_high, label);
3054 __ Sltu(TMP, rhs_high, lhs_high);
3055 __ Sltu(AT, rhs_low, lhs_low);
3056 __ Or(TMP, TMP, AT);
3057 __ Beqz(TMP, label);
3058 break;
3059 case kCondA:
3060 __ Bltu(rhs_high, lhs_high, label);
3061 __ Sltu(TMP, lhs_high, rhs_high);
3062 __ Sltu(AT, rhs_low, lhs_low);
3063 __ Blt(TMP, AT, label);
3064 break;
3065 }
3066 }
3067}
3068
3069void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond,
3070 bool gt_bias,
3071 Primitive::Type type,
3072 LocationSummary* locations,
3073 MipsLabel* label) {
3074 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
3075 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
3076 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
3077 if (type == Primitive::kPrimFloat) {
3078 if (isR6) {
3079 switch (cond) {
3080 case kCondEQ:
3081 __ CmpEqS(FTMP, lhs, rhs);
3082 __ Bc1nez(FTMP, label);
3083 break;
3084 case kCondNE:
3085 __ CmpEqS(FTMP, lhs, rhs);
3086 __ Bc1eqz(FTMP, label);
3087 break;
3088 case kCondLT:
3089 if (gt_bias) {
3090 __ CmpLtS(FTMP, lhs, rhs);
3091 } else {
3092 __ CmpUltS(FTMP, lhs, rhs);
3093 }
3094 __ Bc1nez(FTMP, label);
3095 break;
3096 case kCondLE:
3097 if (gt_bias) {
3098 __ CmpLeS(FTMP, lhs, rhs);
3099 } else {
3100 __ CmpUleS(FTMP, lhs, rhs);
3101 }
3102 __ Bc1nez(FTMP, label);
3103 break;
3104 case kCondGT:
3105 if (gt_bias) {
3106 __ CmpUltS(FTMP, rhs, lhs);
3107 } else {
3108 __ CmpLtS(FTMP, rhs, lhs);
3109 }
3110 __ Bc1nez(FTMP, label);
3111 break;
3112 case kCondGE:
3113 if (gt_bias) {
3114 __ CmpUleS(FTMP, rhs, lhs);
3115 } else {
3116 __ CmpLeS(FTMP, rhs, lhs);
3117 }
3118 __ Bc1nez(FTMP, label);
3119 break;
3120 default:
3121 LOG(FATAL) << "Unexpected non-floating-point condition";
3122 }
3123 } else {
3124 switch (cond) {
3125 case kCondEQ:
3126 __ CeqS(0, lhs, rhs);
3127 __ Bc1t(0, label);
3128 break;
3129 case kCondNE:
3130 __ CeqS(0, lhs, rhs);
3131 __ Bc1f(0, label);
3132 break;
3133 case kCondLT:
3134 if (gt_bias) {
3135 __ ColtS(0, lhs, rhs);
3136 } else {
3137 __ CultS(0, lhs, rhs);
3138 }
3139 __ Bc1t(0, label);
3140 break;
3141 case kCondLE:
3142 if (gt_bias) {
3143 __ ColeS(0, lhs, rhs);
3144 } else {
3145 __ CuleS(0, lhs, rhs);
3146 }
3147 __ Bc1t(0, label);
3148 break;
3149 case kCondGT:
3150 if (gt_bias) {
3151 __ CultS(0, rhs, lhs);
3152 } else {
3153 __ ColtS(0, rhs, lhs);
3154 }
3155 __ Bc1t(0, label);
3156 break;
3157 case kCondGE:
3158 if (gt_bias) {
3159 __ CuleS(0, rhs, lhs);
3160 } else {
3161 __ ColeS(0, rhs, lhs);
3162 }
3163 __ Bc1t(0, label);
3164 break;
3165 default:
3166 LOG(FATAL) << "Unexpected non-floating-point condition";
3167 }
3168 }
3169 } else {
3170 DCHECK_EQ(type, Primitive::kPrimDouble);
3171 if (isR6) {
3172 switch (cond) {
3173 case kCondEQ:
3174 __ CmpEqD(FTMP, lhs, rhs);
3175 __ Bc1nez(FTMP, label);
3176 break;
3177 case kCondNE:
3178 __ CmpEqD(FTMP, lhs, rhs);
3179 __ Bc1eqz(FTMP, label);
3180 break;
3181 case kCondLT:
3182 if (gt_bias) {
3183 __ CmpLtD(FTMP, lhs, rhs);
3184 } else {
3185 __ CmpUltD(FTMP, lhs, rhs);
3186 }
3187 __ Bc1nez(FTMP, label);
3188 break;
3189 case kCondLE:
3190 if (gt_bias) {
3191 __ CmpLeD(FTMP, lhs, rhs);
3192 } else {
3193 __ CmpUleD(FTMP, lhs, rhs);
3194 }
3195 __ Bc1nez(FTMP, label);
3196 break;
3197 case kCondGT:
3198 if (gt_bias) {
3199 __ CmpUltD(FTMP, rhs, lhs);
3200 } else {
3201 __ CmpLtD(FTMP, rhs, lhs);
3202 }
3203 __ Bc1nez(FTMP, label);
3204 break;
3205 case kCondGE:
3206 if (gt_bias) {
3207 __ CmpUleD(FTMP, rhs, lhs);
3208 } else {
3209 __ CmpLeD(FTMP, rhs, lhs);
3210 }
3211 __ Bc1nez(FTMP, label);
3212 break;
3213 default:
3214 LOG(FATAL) << "Unexpected non-floating-point condition";
3215 }
3216 } else {
3217 switch (cond) {
3218 case kCondEQ:
3219 __ CeqD(0, lhs, rhs);
3220 __ Bc1t(0, label);
3221 break;
3222 case kCondNE:
3223 __ CeqD(0, lhs, rhs);
3224 __ Bc1f(0, label);
3225 break;
3226 case kCondLT:
3227 if (gt_bias) {
3228 __ ColtD(0, lhs, rhs);
3229 } else {
3230 __ CultD(0, lhs, rhs);
3231 }
3232 __ Bc1t(0, label);
3233 break;
3234 case kCondLE:
3235 if (gt_bias) {
3236 __ ColeD(0, lhs, rhs);
3237 } else {
3238 __ CuleD(0, lhs, rhs);
3239 }
3240 __ Bc1t(0, label);
3241 break;
3242 case kCondGT:
3243 if (gt_bias) {
3244 __ CultD(0, rhs, lhs);
3245 } else {
3246 __ ColtD(0, rhs, lhs);
3247 }
3248 __ Bc1t(0, label);
3249 break;
3250 case kCondGE:
3251 if (gt_bias) {
3252 __ CuleD(0, rhs, lhs);
3253 } else {
3254 __ ColeD(0, rhs, lhs);
3255 }
3256 __ Bc1t(0, label);
3257 break;
3258 default:
3259 LOG(FATAL) << "Unexpected non-floating-point condition";
3260 }
3261 }
3262 }
3263}
3264
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003265void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00003266 size_t condition_input_index,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003267 MipsLabel* true_target,
David Brazdil0debae72015-11-12 18:37:00 +00003268 MipsLabel* false_target) {
3269 HInstruction* cond = instruction->InputAt(condition_input_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003270
David Brazdil0debae72015-11-12 18:37:00 +00003271 if (true_target == nullptr && false_target == nullptr) {
3272 // Nothing to do. The code always falls through.
3273 return;
3274 } else if (cond->IsIntConstant()) {
3275 // Constant condition, statically compared against 1.
3276 if (cond->AsIntConstant()->IsOne()) {
3277 if (true_target != nullptr) {
3278 __ B(true_target);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003279 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003280 } else {
David Brazdil0debae72015-11-12 18:37:00 +00003281 DCHECK(cond->AsIntConstant()->IsZero());
3282 if (false_target != nullptr) {
3283 __ B(false_target);
3284 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003285 }
David Brazdil0debae72015-11-12 18:37:00 +00003286 return;
3287 }
3288
3289 // The following code generates these patterns:
3290 // (1) true_target == nullptr && false_target != nullptr
3291 // - opposite condition true => branch to false_target
3292 // (2) true_target != nullptr && false_target == nullptr
3293 // - condition true => branch to true_target
3294 // (3) true_target != nullptr && false_target != nullptr
3295 // - condition true => branch to true_target
3296 // - branch to false_target
3297 if (IsBooleanValueOrMaterializedCondition(cond)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003298 // The condition instruction has been materialized, compare the output to 0.
David Brazdil0debae72015-11-12 18:37:00 +00003299 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003300 DCHECK(cond_val.IsRegister());
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003301 if (true_target == nullptr) {
David Brazdil0debae72015-11-12 18:37:00 +00003302 __ Beqz(cond_val.AsRegister<Register>(), false_target);
3303 } else {
3304 __ Bnez(cond_val.AsRegister<Register>(), true_target);
3305 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003306 } else {
3307 // The condition instruction has not been materialized, use its inputs as
3308 // the comparison and its condition as the branch condition.
David Brazdil0debae72015-11-12 18:37:00 +00003309 HCondition* condition = cond->AsCondition();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003310 Primitive::Type type = condition->InputAt(0)->GetType();
3311 LocationSummary* locations = cond->GetLocations();
3312 IfCondition if_cond = condition->GetCondition();
3313 MipsLabel* branch_target = true_target;
David Brazdil0debae72015-11-12 18:37:00 +00003314
David Brazdil0debae72015-11-12 18:37:00 +00003315 if (true_target == nullptr) {
3316 if_cond = condition->GetOppositeCondition();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003317 branch_target = false_target;
David Brazdil0debae72015-11-12 18:37:00 +00003318 }
3319
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003320 switch (type) {
3321 default:
3322 GenerateIntCompareAndBranch(if_cond, locations, branch_target);
3323 break;
3324 case Primitive::kPrimLong:
3325 GenerateLongCompareAndBranch(if_cond, locations, branch_target);
3326 break;
3327 case Primitive::kPrimFloat:
3328 case Primitive::kPrimDouble:
3329 GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target);
3330 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003331 }
3332 }
David Brazdil0debae72015-11-12 18:37:00 +00003333
3334 // If neither branch falls through (case 3), the conditional branch to `true_target`
3335 // was already emitted (case 2) and we need to emit a jump to `false_target`.
3336 if (true_target != nullptr && false_target != nullptr) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003337 __ B(false_target);
3338 }
3339}
3340
3341void LocationsBuilderMIPS::VisitIf(HIf* if_instr) {
3342 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
David Brazdil0debae72015-11-12 18:37:00 +00003343 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003344 locations->SetInAt(0, Location::RequiresRegister());
3345 }
3346}
3347
3348void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00003349 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
3350 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
3351 MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
3352 nullptr : codegen_->GetLabelOf(true_successor);
3353 MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
3354 nullptr : codegen_->GetLabelOf(false_successor);
3355 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003356}
3357
3358void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) {
3359 LocationSummary* locations = new (GetGraph()->GetArena())
3360 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
David Brazdil0debae72015-11-12 18:37:00 +00003361 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003362 locations->SetInAt(0, Location::RequiresRegister());
3363 }
3364}
3365
3366void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08003367 SlowPathCodeMIPS* slow_path =
3368 deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00003369 GenerateTestAndBranch(deoptimize,
3370 /* condition_input_index */ 0,
3371 slow_path->GetEntryLabel(),
3372 /* false_target */ nullptr);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003373}
3374
David Brazdil74eb1b22015-12-14 11:44:01 +00003375void LocationsBuilderMIPS::VisitSelect(HSelect* select) {
3376 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select);
3377 if (Primitive::IsFloatingPointType(select->GetType())) {
3378 locations->SetInAt(0, Location::RequiresFpuRegister());
3379 locations->SetInAt(1, Location::RequiresFpuRegister());
3380 } else {
3381 locations->SetInAt(0, Location::RequiresRegister());
3382 locations->SetInAt(1, Location::RequiresRegister());
3383 }
3384 if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) {
3385 locations->SetInAt(2, Location::RequiresRegister());
3386 }
3387 locations->SetOut(Location::SameAsFirstInput());
3388}
3389
3390void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) {
3391 LocationSummary* locations = select->GetLocations();
3392 MipsLabel false_target;
3393 GenerateTestAndBranch(select,
3394 /* condition_input_index */ 2,
3395 /* true_target */ nullptr,
3396 &false_target);
3397 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
3398 __ Bind(&false_target);
3399}
3400
David Srbecky0cf44932015-12-09 14:09:59 +00003401void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) {
3402 new (GetGraph()->GetArena()) LocationSummary(info);
3403}
3404
David Srbeckyd28f4a02016-03-14 17:14:24 +00003405void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) {
3406 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00003407}
3408
3409void CodeGeneratorMIPS::GenerateNop() {
3410 __ Nop();
David Srbecky0cf44932015-12-09 14:09:59 +00003411}
3412
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003413void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3414 Primitive::Type field_type = field_info.GetFieldType();
3415 bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble);
3416 bool generate_volatile = field_info.IsVolatile() && is_wide;
3417 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3418 instruction, generate_volatile ? LocationSummary::kCall : LocationSummary::kNoCall);
3419
3420 locations->SetInAt(0, Location::RequiresRegister());
3421 if (generate_volatile) {
3422 InvokeRuntimeCallingConvention calling_convention;
3423 // need A0 to hold base + offset
3424 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3425 if (field_type == Primitive::kPrimLong) {
3426 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimLong));
3427 } else {
3428 locations->SetOut(Location::RequiresFpuRegister());
3429 // Need some temp core regs since FP results are returned in core registers
3430 Location reg = calling_convention.GetReturnLocation(Primitive::kPrimLong);
3431 locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>()));
3432 locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>()));
3433 }
3434 } else {
3435 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3436 locations->SetOut(Location::RequiresFpuRegister());
3437 } else {
3438 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3439 }
3440 }
3441}
3442
3443void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction,
3444 const FieldInfo& field_info,
3445 uint32_t dex_pc) {
3446 Primitive::Type type = field_info.GetFieldType();
3447 LocationSummary* locations = instruction->GetLocations();
3448 Register obj = locations->InAt(0).AsRegister<Register>();
3449 LoadOperandType load_type = kLoadUnsignedByte;
3450 bool is_volatile = field_info.IsVolatile();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003451 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003452
3453 switch (type) {
3454 case Primitive::kPrimBoolean:
3455 load_type = kLoadUnsignedByte;
3456 break;
3457 case Primitive::kPrimByte:
3458 load_type = kLoadSignedByte;
3459 break;
3460 case Primitive::kPrimShort:
3461 load_type = kLoadSignedHalfword;
3462 break;
3463 case Primitive::kPrimChar:
3464 load_type = kLoadUnsignedHalfword;
3465 break;
3466 case Primitive::kPrimInt:
3467 case Primitive::kPrimFloat:
3468 case Primitive::kPrimNot:
3469 load_type = kLoadWord;
3470 break;
3471 case Primitive::kPrimLong:
3472 case Primitive::kPrimDouble:
3473 load_type = kLoadDoubleword;
3474 break;
3475 case Primitive::kPrimVoid:
3476 LOG(FATAL) << "Unreachable type " << type;
3477 UNREACHABLE();
3478 }
3479
3480 if (is_volatile && load_type == kLoadDoubleword) {
3481 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003482 __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003483 // Do implicit Null check
3484 __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0);
3485 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3486 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pA64Load),
3487 instruction,
3488 dex_pc,
3489 nullptr,
3490 IsDirectEntrypoint(kQuickA64Load));
3491 CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>();
3492 if (type == Primitive::kPrimDouble) {
3493 // Need to move to FP regs since FP results are returned in core registers.
3494 __ Mtc1(locations->GetTemp(1).AsRegister<Register>(),
3495 locations->Out().AsFpuRegister<FRegister>());
Alexey Frunzebb9863a2016-01-11 15:51:16 -08003496 __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(),
3497 locations->Out().AsFpuRegister<FRegister>());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003498 }
3499 } else {
3500 if (!Primitive::IsFloatingPointType(type)) {
3501 Register dst;
3502 if (type == Primitive::kPrimLong) {
3503 DCHECK(locations->Out().IsRegisterPair());
3504 dst = locations->Out().AsRegisterPairLow<Register>();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003505 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
3506 if (obj == dst) {
3507 __ LoadFromOffset(kLoadWord, dst_high, obj, offset + kMipsWordSize);
3508 codegen_->MaybeRecordImplicitNullCheck(instruction);
3509 __ LoadFromOffset(kLoadWord, dst, obj, offset);
3510 } else {
3511 __ LoadFromOffset(kLoadWord, dst, obj, offset);
3512 codegen_->MaybeRecordImplicitNullCheck(instruction);
3513 __ LoadFromOffset(kLoadWord, dst_high, obj, offset + kMipsWordSize);
3514 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003515 } else {
3516 DCHECK(locations->Out().IsRegister());
3517 dst = locations->Out().AsRegister<Register>();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003518 __ LoadFromOffset(load_type, dst, obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003519 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003520 } else {
3521 DCHECK(locations->Out().IsFpuRegister());
3522 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
3523 if (type == Primitive::kPrimFloat) {
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003524 __ LoadSFromOffset(dst, obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003525 } else {
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003526 __ LoadDFromOffset(dst, obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003527 }
3528 }
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003529 // Longs are handled earlier.
3530 if (type != Primitive::kPrimLong) {
3531 codegen_->MaybeRecordImplicitNullCheck(instruction);
3532 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003533 }
3534
3535 if (is_volatile) {
3536 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3537 }
3538}
3539
3540void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3541 Primitive::Type field_type = field_info.GetFieldType();
3542 bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble);
3543 bool generate_volatile = field_info.IsVolatile() && is_wide;
3544 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3545 instruction, generate_volatile ? LocationSummary::kCall : LocationSummary::kNoCall);
3546
3547 locations->SetInAt(0, Location::RequiresRegister());
3548 if (generate_volatile) {
3549 InvokeRuntimeCallingConvention calling_convention;
3550 // need A0 to hold base + offset
3551 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3552 if (field_type == Primitive::kPrimLong) {
3553 locations->SetInAt(1, Location::RegisterPairLocation(
3554 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
3555 } else {
3556 locations->SetInAt(1, Location::RequiresFpuRegister());
3557 // Pass FP parameters in core registers.
3558 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
3559 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3)));
3560 }
3561 } else {
3562 if (Primitive::IsFloatingPointType(field_type)) {
3563 locations->SetInAt(1, Location::RequiresFpuRegister());
3564 } else {
3565 locations->SetInAt(1, Location::RequiresRegister());
3566 }
3567 }
3568}
3569
3570void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction,
3571 const FieldInfo& field_info,
3572 uint32_t dex_pc) {
3573 Primitive::Type type = field_info.GetFieldType();
3574 LocationSummary* locations = instruction->GetLocations();
3575 Register obj = locations->InAt(0).AsRegister<Register>();
3576 StoreOperandType store_type = kStoreByte;
3577 bool is_volatile = field_info.IsVolatile();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003578 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003579
3580 switch (type) {
3581 case Primitive::kPrimBoolean:
3582 case Primitive::kPrimByte:
3583 store_type = kStoreByte;
3584 break;
3585 case Primitive::kPrimShort:
3586 case Primitive::kPrimChar:
3587 store_type = kStoreHalfword;
3588 break;
3589 case Primitive::kPrimInt:
3590 case Primitive::kPrimFloat:
3591 case Primitive::kPrimNot:
3592 store_type = kStoreWord;
3593 break;
3594 case Primitive::kPrimLong:
3595 case Primitive::kPrimDouble:
3596 store_type = kStoreDoubleword;
3597 break;
3598 case Primitive::kPrimVoid:
3599 LOG(FATAL) << "Unreachable type " << type;
3600 UNREACHABLE();
3601 }
3602
3603 if (is_volatile) {
3604 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3605 }
3606
3607 if (is_volatile && store_type == kStoreDoubleword) {
3608 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003609 __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003610 // Do implicit Null check.
3611 __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0);
3612 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3613 if (type == Primitive::kPrimDouble) {
3614 // Pass FP parameters in core registers.
3615 __ Mfc1(locations->GetTemp(1).AsRegister<Register>(),
3616 locations->InAt(1).AsFpuRegister<FRegister>());
Alexey Frunzebb9863a2016-01-11 15:51:16 -08003617 __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(),
3618 locations->InAt(1).AsFpuRegister<FRegister>());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003619 }
3620 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pA64Store),
3621 instruction,
3622 dex_pc,
3623 nullptr,
3624 IsDirectEntrypoint(kQuickA64Store));
3625 CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>();
3626 } else {
3627 if (!Primitive::IsFloatingPointType(type)) {
3628 Register src;
3629 if (type == Primitive::kPrimLong) {
3630 DCHECK(locations->InAt(1).IsRegisterPair());
3631 src = locations->InAt(1).AsRegisterPairLow<Register>();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003632 Register src_high = locations->InAt(1).AsRegisterPairHigh<Register>();
3633 __ StoreToOffset(kStoreWord, src, obj, offset);
3634 codegen_->MaybeRecordImplicitNullCheck(instruction);
3635 __ StoreToOffset(kStoreWord, src_high, obj, offset + kMipsWordSize);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003636 } else {
3637 DCHECK(locations->InAt(1).IsRegister());
3638 src = locations->InAt(1).AsRegister<Register>();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003639 __ StoreToOffset(store_type, src, obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003640 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003641 } else {
3642 DCHECK(locations->InAt(1).IsFpuRegister());
3643 FRegister src = locations->InAt(1).AsFpuRegister<FRegister>();
3644 if (type == Primitive::kPrimFloat) {
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003645 __ StoreSToOffset(src, obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003646 } else {
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003647 __ StoreDToOffset(src, obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003648 }
3649 }
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003650 // Longs are handled earlier.
3651 if (type != Primitive::kPrimLong) {
3652 codegen_->MaybeRecordImplicitNullCheck(instruction);
3653 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003654 }
3655
3656 // TODO: memory barriers?
3657 if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) {
3658 DCHECK(locations->InAt(1).IsRegister());
3659 Register src = locations->InAt(1).AsRegister<Register>();
3660 codegen_->MarkGCCard(obj, src);
3661 }
3662
3663 if (is_volatile) {
3664 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3665 }
3666}
3667
3668void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3669 HandleFieldGet(instruction, instruction->GetFieldInfo());
3670}
3671
3672void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3673 HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
3674}
3675
3676void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3677 HandleFieldSet(instruction, instruction->GetFieldInfo());
3678}
3679
3680void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3681 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
3682}
3683
3684void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) {
3685 LocationSummary::CallKind call_kind =
3686 instruction->IsExactCheck() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
3687 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3688 locations->SetInAt(0, Location::RequiresRegister());
3689 locations->SetInAt(1, Location::RequiresRegister());
3690 // The output does overlap inputs.
3691 // Note that TypeCheckSlowPathMIPS uses this register too.
3692 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3693}
3694
3695void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) {
3696 LocationSummary* locations = instruction->GetLocations();
3697 Register obj = locations->InAt(0).AsRegister<Register>();
3698 Register cls = locations->InAt(1).AsRegister<Register>();
3699 Register out = locations->Out().AsRegister<Register>();
3700
3701 MipsLabel done;
3702
3703 // Return 0 if `obj` is null.
3704 // TODO: Avoid this check if we know `obj` is not null.
3705 __ Move(out, ZERO);
3706 __ Beqz(obj, &done);
3707
3708 // Compare the class of `obj` with `cls`.
3709 __ LoadFromOffset(kLoadWord, out, obj, mirror::Object::ClassOffset().Int32Value());
3710 if (instruction->IsExactCheck()) {
3711 // Classes must be equal for the instanceof to succeed.
3712 __ Xor(out, out, cls);
3713 __ Sltiu(out, out, 1);
3714 } else {
3715 // If the classes are not equal, we go into a slow path.
3716 DCHECK(locations->OnlyCallsOnSlowPath());
3717 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction);
3718 codegen_->AddSlowPath(slow_path);
3719 __ Bne(out, cls, slow_path->GetEntryLabel());
3720 __ LoadConst32(out, 1);
3721 __ Bind(slow_path->GetExitLabel());
3722 }
3723
3724 __ Bind(&done);
3725}
3726
3727void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) {
3728 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
3729 locations->SetOut(Location::ConstantLocation(constant));
3730}
3731
3732void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
3733 // Will be generated at use site.
3734}
3735
3736void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) {
3737 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
3738 locations->SetOut(Location::ConstantLocation(constant));
3739}
3740
3741void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
3742 // Will be generated at use site.
3743}
3744
3745void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) {
3746 InvokeDexCallingConventionVisitorMIPS calling_convention_visitor;
3747 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
3748}
3749
3750void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) {
3751 HandleInvoke(invoke);
3752 // The register T0 is required to be used for the hidden argument in
3753 // art_quick_imt_conflict_trampoline, so add the hidden argument.
3754 invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0));
3755}
3756
3757void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) {
3758 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
3759 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
3760 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
3761 invoke->GetImtIndex() % mirror::Class::kImtSize, kMipsPointerSize).Uint32Value();
3762 Location receiver = invoke->GetLocations()->InAt(0);
3763 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3764 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsWordSize);
3765
3766 // Set the hidden argument.
3767 __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
3768 invoke->GetDexMethodIndex());
3769
3770 // temp = object->GetClass();
3771 if (receiver.IsStackSlot()) {
3772 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
3773 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
3774 } else {
3775 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
3776 }
3777 codegen_->MaybeRecordImplicitNullCheck(invoke);
3778 // temp = temp->GetImtEntryAt(method_offset);
3779 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
3780 // T9 = temp->GetEntryPoint();
3781 __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value());
3782 // T9();
3783 __ Jalr(T9);
3784 __ Nop();
3785 DCHECK(!codegen_->IsLeafMethod());
3786 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
3787}
3788
3789void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Chris Larsen701566a2015-10-27 15:29:13 -07003790 IntrinsicLocationsBuilderMIPS intrinsic(codegen_);
3791 if (intrinsic.TryDispatch(invoke)) {
3792 return;
3793 }
3794
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003795 HandleInvoke(invoke);
3796}
3797
3798void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00003799 // Explicit clinit checks triggered by static invokes must have been pruned by
3800 // art::PrepareForRegisterAllocation.
3801 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003802
Chris Larsen701566a2015-10-27 15:29:13 -07003803 IntrinsicLocationsBuilderMIPS intrinsic(codegen_);
3804 if (intrinsic.TryDispatch(invoke)) {
3805 return;
3806 }
3807
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003808 HandleInvoke(invoke);
3809}
3810
Chris Larsen701566a2015-10-27 15:29:13 -07003811static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003812 if (invoke->GetLocations()->Intrinsified()) {
Chris Larsen701566a2015-10-27 15:29:13 -07003813 IntrinsicCodeGeneratorMIPS intrinsic(codegen);
3814 intrinsic.Dispatch(invoke);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003815 return true;
3816 }
3817 return false;
3818}
3819
Vladimir Markodc151b22015-10-15 18:02:30 +01003820HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch(
3821 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
3822 MethodReference target_method ATTRIBUTE_UNUSED) {
3823 switch (desired_dispatch_info.method_load_kind) {
3824 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
3825 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative:
3826 // TODO: Implement these types. For the moment, we fall back to kDexCacheViaMethod.
3827 return HInvokeStaticOrDirect::DispatchInfo {
3828 HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod,
3829 HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod,
3830 0u,
3831 0u
3832 };
3833 default:
3834 break;
3835 }
3836 switch (desired_dispatch_info.code_ptr_location) {
3837 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
3838 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
3839 // TODO: Implement these types. For the moment, we fall back to kCallArtMethod.
3840 return HInvokeStaticOrDirect::DispatchInfo {
3841 desired_dispatch_info.method_load_kind,
3842 HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod,
3843 desired_dispatch_info.method_load_data,
3844 0u
3845 };
3846 default:
3847 return desired_dispatch_info;
3848 }
3849}
3850
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003851void CodeGeneratorMIPS::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
3852 // All registers are assumed to be correctly set up per the calling convention.
3853
3854 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
3855 switch (invoke->GetMethodLoadKind()) {
3856 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
3857 // temp = thread->string_init_entrypoint
3858 __ LoadFromOffset(kLoadWord,
3859 temp.AsRegister<Register>(),
3860 TR,
3861 invoke->GetStringInitOffset());
3862 break;
3863 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00003864 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003865 break;
3866 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
3867 __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress());
3868 break;
3869 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003870 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative:
Vladimir Markodc151b22015-10-15 18:02:30 +01003871 // TODO: Implement these types.
3872 // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch().
3873 LOG(FATAL) << "Unsupported";
3874 UNREACHABLE();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003875 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
Vladimir Markoc53c0792015-11-19 15:48:33 +00003876 Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003877 Register reg = temp.AsRegister<Register>();
3878 Register method_reg;
3879 if (current_method.IsRegister()) {
3880 method_reg = current_method.AsRegister<Register>();
3881 } else {
3882 // TODO: use the appropriate DCHECK() here if possible.
3883 // DCHECK(invoke->GetLocations()->Intrinsified());
3884 DCHECK(!current_method.IsValid());
3885 method_reg = reg;
3886 __ Lw(reg, SP, kCurrentMethodStackOffset);
3887 }
3888
3889 // temp = temp->dex_cache_resolved_methods_;
3890 __ LoadFromOffset(kLoadWord,
3891 reg,
3892 method_reg,
3893 ArtMethod::DexCacheResolvedMethodsOffset(kMipsPointerSize).Int32Value());
3894 // temp = temp[index_in_cache]
3895 uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index;
3896 __ LoadFromOffset(kLoadWord,
3897 reg,
3898 reg,
3899 CodeGenerator::GetCachePointerOffset(index_in_cache));
3900 break;
3901 }
3902 }
3903
3904 switch (invoke->GetCodePtrLocation()) {
3905 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
3906 __ Jalr(&frame_entry_label_, T9);
3907 break;
3908 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
3909 // LR = invoke->GetDirectCodePtr();
3910 __ LoadConst32(T9, invoke->GetDirectCodePtr());
3911 // LR()
3912 __ Jalr(T9);
3913 __ Nop();
3914 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003915 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
Vladimir Markodc151b22015-10-15 18:02:30 +01003916 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
3917 // TODO: Implement these types.
3918 // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch().
3919 LOG(FATAL) << "Unsupported";
3920 UNREACHABLE();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003921 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
3922 // T9 = callee_method->entry_point_from_quick_compiled_code_;
Goran Jakovljevic1a878372015-10-26 14:28:52 +01003923 __ LoadFromOffset(kLoadWord,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003924 T9,
3925 callee_method.AsRegister<Register>(),
3926 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
3927 kMipsWordSize).Int32Value());
3928 // T9()
3929 __ Jalr(T9);
3930 __ Nop();
3931 break;
3932 }
3933 DCHECK(!IsLeafMethod());
3934}
3935
3936void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00003937 // Explicit clinit checks triggered by static invokes must have been pruned by
3938 // art::PrepareForRegisterAllocation.
3939 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003940
3941 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
3942 return;
3943 }
3944
3945 LocationSummary* locations = invoke->GetLocations();
3946 codegen_->GenerateStaticOrDirectCall(invoke,
3947 locations->HasTemps()
3948 ? locations->GetTemp(0)
3949 : Location::NoLocation());
3950 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
3951}
3952
Chris Larsen3acee732015-11-18 13:31:08 -08003953void CodeGeneratorMIPS::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003954 LocationSummary* locations = invoke->GetLocations();
3955 Location receiver = locations->InAt(0);
Chris Larsen3acee732015-11-18 13:31:08 -08003956 Register temp = temp_location.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003957 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
3958 invoke->GetVTableIndex(), kMipsPointerSize).SizeValue();
3959 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3960 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsWordSize);
3961
3962 // temp = object->GetClass();
Chris Larsen3acee732015-11-18 13:31:08 -08003963 DCHECK(receiver.IsRegister());
3964 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
3965 MaybeRecordImplicitNullCheck(invoke);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003966 // temp = temp->GetMethodAt(method_offset);
3967 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
3968 // T9 = temp->GetEntryPoint();
3969 __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value());
3970 // T9();
3971 __ Jalr(T9);
3972 __ Nop();
Chris Larsen3acee732015-11-18 13:31:08 -08003973}
3974
3975void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) {
3976 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
3977 return;
3978 }
3979
3980 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003981 DCHECK(!codegen_->IsLeafMethod());
3982 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
3983}
3984
3985void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) {
Pavle Batutae87a7182015-10-28 13:10:42 +01003986 InvokeRuntimeCallingConvention calling_convention;
3987 CodeGenerator::CreateLoadClassLocationSummary(
3988 cls,
3989 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
3990 Location::RegisterLocation(V0));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003991}
3992
3993void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) {
3994 LocationSummary* locations = cls->GetLocations();
Pavle Batutae87a7182015-10-28 13:10:42 +01003995 if (cls->NeedsAccessCheck()) {
3996 codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex());
3997 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess),
3998 cls,
3999 cls->GetDexPc(),
4000 nullptr,
4001 IsDirectEntrypoint(kQuickInitializeTypeAndVerifyAccess));
Roland Levillain888d0672015-11-23 18:53:50 +00004002 CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>();
Pavle Batutae87a7182015-10-28 13:10:42 +01004003 return;
4004 }
4005
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004006 Register out = locations->Out().AsRegister<Register>();
4007 Register current_method = locations->InAt(0).AsRegister<Register>();
4008 if (cls->IsReferrersClass()) {
4009 DCHECK(!cls->CanCallRuntime());
4010 DCHECK(!cls->MustGenerateClinitCheck());
4011 __ LoadFromOffset(kLoadWord, out, current_method,
4012 ArtMethod::DeclaringClassOffset().Int32Value());
4013 } else {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004014 __ LoadFromOffset(kLoadWord, out, current_method,
4015 ArtMethod::DexCacheResolvedTypesOffset(kMipsPointerSize).Int32Value());
4016 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray42e372e2015-11-24 15:48:56 +00004017
4018 if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) {
4019 DCHECK(cls->CanCallRuntime());
4020 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS(
4021 cls,
4022 cls,
4023 cls->GetDexPc(),
4024 cls->MustGenerateClinitCheck());
4025 codegen_->AddSlowPath(slow_path);
4026 if (!cls->IsInDexCache()) {
4027 __ Beqz(out, slow_path->GetEntryLabel());
4028 }
4029 if (cls->MustGenerateClinitCheck()) {
4030 GenerateClassInitializationCheck(slow_path, out);
4031 } else {
4032 __ Bind(slow_path->GetExitLabel());
4033 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004034 }
4035 }
4036}
4037
4038static int32_t GetExceptionTlsOffset() {
4039 return Thread::ExceptionOffset<kMipsWordSize>().Int32Value();
4040}
4041
4042void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) {
4043 LocationSummary* locations =
4044 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4045 locations->SetOut(Location::RequiresRegister());
4046}
4047
4048void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) {
4049 Register out = load->GetLocations()->Out().AsRegister<Register>();
4050 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
4051}
4052
4053void LocationsBuilderMIPS::VisitClearException(HClearException* clear) {
4054 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
4055}
4056
4057void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
4058 __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset());
4059}
4060
4061void LocationsBuilderMIPS::VisitLoadLocal(HLoadLocal* load) {
4062 load->SetLocations(nullptr);
4063}
4064
4065void InstructionCodeGeneratorMIPS::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) {
4066 // Nothing to do, this is driven by the code generator.
4067}
4068
4069void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) {
Roland Levillain698fa972015-12-16 17:06:47 +00004070 LocationSummary::CallKind call_kind = load->IsInDexCache()
4071 ? LocationSummary::kNoCall
4072 : LocationSummary::kCallOnSlowPath;
Nicolas Geoffray917d0162015-11-24 18:25:35 +00004073 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004074 locations->SetInAt(0, Location::RequiresRegister());
4075 locations->SetOut(Location::RequiresRegister());
4076}
4077
4078void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004079 LocationSummary* locations = load->GetLocations();
4080 Register out = locations->Out().AsRegister<Register>();
4081 Register current_method = locations->InAt(0).AsRegister<Register>();
4082 __ LoadFromOffset(kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
4083 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
4084 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
Nicolas Geoffray917d0162015-11-24 18:25:35 +00004085
4086 if (!load->IsInDexCache()) {
4087 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS(load);
4088 codegen_->AddSlowPath(slow_path);
4089 __ Beqz(out, slow_path->GetEntryLabel());
4090 __ Bind(slow_path->GetExitLabel());
4091 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004092}
4093
4094void LocationsBuilderMIPS::VisitLocal(HLocal* local) {
4095 local->SetLocations(nullptr);
4096}
4097
4098void InstructionCodeGeneratorMIPS::VisitLocal(HLocal* local) {
4099 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
4100}
4101
4102void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) {
4103 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
4104 locations->SetOut(Location::ConstantLocation(constant));
4105}
4106
4107void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
4108 // Will be generated at use site.
4109}
4110
4111void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) {
4112 LocationSummary* locations =
4113 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4114 InvokeRuntimeCallingConvention calling_convention;
4115 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4116}
4117
4118void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) {
4119 if (instruction->IsEnter()) {
4120 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLockObject),
4121 instruction,
4122 instruction->GetDexPc(),
4123 nullptr,
4124 IsDirectEntrypoint(kQuickLockObject));
4125 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
4126 } else {
4127 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pUnlockObject),
4128 instruction,
4129 instruction->GetDexPc(),
4130 nullptr,
4131 IsDirectEntrypoint(kQuickUnlockObject));
4132 }
4133 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
4134}
4135
4136void LocationsBuilderMIPS::VisitMul(HMul* mul) {
4137 LocationSummary* locations =
4138 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
4139 switch (mul->GetResultType()) {
4140 case Primitive::kPrimInt:
4141 case Primitive::kPrimLong:
4142 locations->SetInAt(0, Location::RequiresRegister());
4143 locations->SetInAt(1, Location::RequiresRegister());
4144 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4145 break;
4146
4147 case Primitive::kPrimFloat:
4148 case Primitive::kPrimDouble:
4149 locations->SetInAt(0, Location::RequiresFpuRegister());
4150 locations->SetInAt(1, Location::RequiresFpuRegister());
4151 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
4152 break;
4153
4154 default:
4155 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
4156 }
4157}
4158
4159void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) {
4160 Primitive::Type type = instruction->GetType();
4161 LocationSummary* locations = instruction->GetLocations();
4162 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
4163
4164 switch (type) {
4165 case Primitive::kPrimInt: {
4166 Register dst = locations->Out().AsRegister<Register>();
4167 Register lhs = locations->InAt(0).AsRegister<Register>();
4168 Register rhs = locations->InAt(1).AsRegister<Register>();
4169
4170 if (isR6) {
4171 __ MulR6(dst, lhs, rhs);
4172 } else {
4173 __ MulR2(dst, lhs, rhs);
4174 }
4175 break;
4176 }
4177 case Primitive::kPrimLong: {
4178 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
4179 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
4180 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4181 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
4182 Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>();
4183 Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>();
4184
4185 // Extra checks to protect caused by the existance of A1_A2.
4186 // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo:
4187 // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2).
4188 DCHECK_NE(dst_high, lhs_low);
4189 DCHECK_NE(dst_high, rhs_low);
4190
4191 // A_B * C_D
4192 // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ]
4193 // dst_lo: [ low(B*D) ]
4194 // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result.
4195
4196 if (isR6) {
4197 __ MulR6(TMP, lhs_high, rhs_low);
4198 __ MulR6(dst_high, lhs_low, rhs_high);
4199 __ Addu(dst_high, dst_high, TMP);
4200 __ MuhuR6(TMP, lhs_low, rhs_low);
4201 __ Addu(dst_high, dst_high, TMP);
4202 __ MulR6(dst_low, lhs_low, rhs_low);
4203 } else {
4204 __ MulR2(TMP, lhs_high, rhs_low);
4205 __ MulR2(dst_high, lhs_low, rhs_high);
4206 __ Addu(dst_high, dst_high, TMP);
4207 __ MultuR2(lhs_low, rhs_low);
4208 __ Mfhi(TMP);
4209 __ Addu(dst_high, dst_high, TMP);
4210 __ Mflo(dst_low);
4211 }
4212 break;
4213 }
4214 case Primitive::kPrimFloat:
4215 case Primitive::kPrimDouble: {
4216 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
4217 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
4218 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
4219 if (type == Primitive::kPrimFloat) {
4220 __ MulS(dst, lhs, rhs);
4221 } else {
4222 __ MulD(dst, lhs, rhs);
4223 }
4224 break;
4225 }
4226 default:
4227 LOG(FATAL) << "Unexpected mul type " << type;
4228 }
4229}
4230
4231void LocationsBuilderMIPS::VisitNeg(HNeg* neg) {
4232 LocationSummary* locations =
4233 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
4234 switch (neg->GetResultType()) {
4235 case Primitive::kPrimInt:
4236 case Primitive::kPrimLong:
4237 locations->SetInAt(0, Location::RequiresRegister());
4238 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4239 break;
4240
4241 case Primitive::kPrimFloat:
4242 case Primitive::kPrimDouble:
4243 locations->SetInAt(0, Location::RequiresFpuRegister());
4244 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
4245 break;
4246
4247 default:
4248 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
4249 }
4250}
4251
4252void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) {
4253 Primitive::Type type = instruction->GetType();
4254 LocationSummary* locations = instruction->GetLocations();
4255
4256 switch (type) {
4257 case Primitive::kPrimInt: {
4258 Register dst = locations->Out().AsRegister<Register>();
4259 Register src = locations->InAt(0).AsRegister<Register>();
4260 __ Subu(dst, ZERO, src);
4261 break;
4262 }
4263 case Primitive::kPrimLong: {
4264 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
4265 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
4266 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4267 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
4268 __ Subu(dst_low, ZERO, src_low);
4269 __ Sltu(TMP, ZERO, dst_low);
4270 __ Subu(dst_high, ZERO, src_high);
4271 __ Subu(dst_high, dst_high, TMP);
4272 break;
4273 }
4274 case Primitive::kPrimFloat:
4275 case Primitive::kPrimDouble: {
4276 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
4277 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
4278 if (type == Primitive::kPrimFloat) {
4279 __ NegS(dst, src);
4280 } else {
4281 __ NegD(dst, src);
4282 }
4283 break;
4284 }
4285 default:
4286 LOG(FATAL) << "Unexpected neg type " << type;
4287 }
4288}
4289
4290void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) {
4291 LocationSummary* locations =
4292 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4293 InvokeRuntimeCallingConvention calling_convention;
4294 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4295 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
4296 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
4297 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
4298}
4299
4300void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) {
4301 InvokeRuntimeCallingConvention calling_convention;
4302 Register current_method_register = calling_convention.GetRegisterAt(2);
4303 __ Lw(current_method_register, SP, kCurrentMethodStackOffset);
4304 // Move an uint16_t value to a register.
4305 __ LoadConst32(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
4306 codegen_->InvokeRuntime(
4307 GetThreadOffset<kMipsWordSize>(instruction->GetEntrypoint()).Int32Value(),
4308 instruction,
4309 instruction->GetDexPc(),
4310 nullptr,
4311 IsDirectEntrypoint(kQuickAllocArrayWithAccessCheck));
4312 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
4313 void*, uint32_t, int32_t, ArtMethod*>();
4314}
4315
4316void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) {
4317 LocationSummary* locations =
4318 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4319 InvokeRuntimeCallingConvention calling_convention;
David Brazdil6de19382016-01-08 17:37:10 +00004320 if (instruction->IsStringAlloc()) {
4321 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
4322 } else {
4323 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4324 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
4325 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004326 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
4327}
4328
4329void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) {
David Brazdil6de19382016-01-08 17:37:10 +00004330 if (instruction->IsStringAlloc()) {
4331 // String is allocated through StringFactory. Call NewEmptyString entry point.
4332 Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>();
4333 MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsWordSize);
4334 __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
4335 __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value());
4336 __ Jalr(T9);
4337 __ Nop();
4338 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
4339 } else {
4340 codegen_->InvokeRuntime(
4341 GetThreadOffset<kMipsWordSize>(instruction->GetEntrypoint()).Int32Value(),
4342 instruction,
4343 instruction->GetDexPc(),
4344 nullptr,
4345 IsDirectEntrypoint(kQuickAllocObjectWithAccessCheck));
4346 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
4347 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004348}
4349
4350void LocationsBuilderMIPS::VisitNot(HNot* instruction) {
4351 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
4352 locations->SetInAt(0, Location::RequiresRegister());
4353 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4354}
4355
4356void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) {
4357 Primitive::Type type = instruction->GetType();
4358 LocationSummary* locations = instruction->GetLocations();
4359
4360 switch (type) {
4361 case Primitive::kPrimInt: {
4362 Register dst = locations->Out().AsRegister<Register>();
4363 Register src = locations->InAt(0).AsRegister<Register>();
4364 __ Nor(dst, src, ZERO);
4365 break;
4366 }
4367
4368 case Primitive::kPrimLong: {
4369 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
4370 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
4371 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4372 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
4373 __ Nor(dst_high, src_high, ZERO);
4374 __ Nor(dst_low, src_low, ZERO);
4375 break;
4376 }
4377
4378 default:
4379 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
4380 }
4381}
4382
4383void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) {
4384 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
4385 locations->SetInAt(0, Location::RequiresRegister());
4386 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4387}
4388
4389void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) {
4390 LocationSummary* locations = instruction->GetLocations();
4391 __ Xori(locations->Out().AsRegister<Register>(),
4392 locations->InAt(0).AsRegister<Register>(),
4393 1);
4394}
4395
4396void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) {
4397 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
4398 ? LocationSummary::kCallOnSlowPath
4399 : LocationSummary::kNoCall;
4400 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
4401 locations->SetInAt(0, Location::RequiresRegister());
4402 if (instruction->HasUses()) {
4403 locations->SetOut(Location::SameAsFirstInput());
4404 }
4405}
4406
Calin Juravle2ae48182016-03-16 14:05:09 +00004407void CodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) {
4408 if (CanMoveNullCheckToUser(instruction)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004409 return;
4410 }
4411 Location obj = instruction->GetLocations()->InAt(0);
4412
4413 __ Lw(ZERO, obj.AsRegister<Register>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00004414 RecordPcInfo(instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004415}
4416
Calin Juravle2ae48182016-03-16 14:05:09 +00004417void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004418 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00004419 AddSlowPath(slow_path);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004420
4421 Location obj = instruction->GetLocations()->InAt(0);
4422
4423 __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
4424}
4425
4426void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00004427 codegen_->GenerateNullCheck(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004428}
4429
4430void LocationsBuilderMIPS::VisitOr(HOr* instruction) {
4431 HandleBinaryOp(instruction);
4432}
4433
4434void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) {
4435 HandleBinaryOp(instruction);
4436}
4437
4438void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
4439 LOG(FATAL) << "Unreachable";
4440}
4441
4442void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) {
4443 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
4444}
4445
4446void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) {
4447 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
4448 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
4449 if (location.IsStackSlot()) {
4450 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
4451 } else if (location.IsDoubleStackSlot()) {
4452 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
4453 }
4454 locations->SetOut(location);
4455}
4456
4457void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction
4458 ATTRIBUTE_UNUSED) {
4459 // Nothing to do, the parameter is already at its location.
4460}
4461
4462void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) {
4463 LocationSummary* locations =
4464 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4465 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
4466}
4467
4468void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction
4469 ATTRIBUTE_UNUSED) {
4470 // Nothing to do, the method is already at its location.
4471}
4472
4473void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) {
4474 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
4475 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
4476 locations->SetInAt(i, Location::Any());
4477 }
4478 locations->SetOut(Location::Any());
4479}
4480
4481void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
4482 LOG(FATAL) << "Unreachable";
4483}
4484
4485void LocationsBuilderMIPS::VisitRem(HRem* rem) {
4486 Primitive::Type type = rem->GetResultType();
4487 LocationSummary::CallKind call_kind =
4488 (type == Primitive::kPrimInt) ? LocationSummary::kNoCall : LocationSummary::kCall;
4489 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
4490
4491 switch (type) {
4492 case Primitive::kPrimInt:
4493 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze7e99e052015-11-24 19:28:01 -08004494 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004495 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4496 break;
4497
4498 case Primitive::kPrimLong: {
4499 InvokeRuntimeCallingConvention calling_convention;
4500 locations->SetInAt(0, Location::RegisterPairLocation(
4501 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
4502 locations->SetInAt(1, Location::RegisterPairLocation(
4503 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
4504 locations->SetOut(calling_convention.GetReturnLocation(type));
4505 break;
4506 }
4507
4508 case Primitive::kPrimFloat:
4509 case Primitive::kPrimDouble: {
4510 InvokeRuntimeCallingConvention calling_convention;
4511 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
4512 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
4513 locations->SetOut(calling_convention.GetReturnLocation(type));
4514 break;
4515 }
4516
4517 default:
4518 LOG(FATAL) << "Unexpected rem type " << type;
4519 }
4520}
4521
4522void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) {
4523 Primitive::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004524
4525 switch (type) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08004526 case Primitive::kPrimInt:
4527 GenerateDivRemIntegral(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004528 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004529 case Primitive::kPrimLong: {
4530 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod),
4531 instruction,
4532 instruction->GetDexPc(),
4533 nullptr,
4534 IsDirectEntrypoint(kQuickLmod));
4535 CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>();
4536 break;
4537 }
4538 case Primitive::kPrimFloat: {
4539 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf),
4540 instruction, instruction->GetDexPc(),
4541 nullptr,
4542 IsDirectEntrypoint(kQuickFmodf));
Roland Levillain888d0672015-11-23 18:53:50 +00004543 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004544 break;
4545 }
4546 case Primitive::kPrimDouble: {
4547 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod),
4548 instruction, instruction->GetDexPc(),
4549 nullptr,
4550 IsDirectEntrypoint(kQuickFmod));
Roland Levillain888d0672015-11-23 18:53:50 +00004551 CheckEntrypointTypes<kQuickFmod, double, double, double>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004552 break;
4553 }
4554 default:
4555 LOG(FATAL) << "Unexpected rem type " << type;
4556 }
4557}
4558
4559void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
4560 memory_barrier->SetLocations(nullptr);
4561}
4562
4563void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
4564 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
4565}
4566
4567void LocationsBuilderMIPS::VisitReturn(HReturn* ret) {
4568 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret);
4569 Primitive::Type return_type = ret->InputAt(0)->GetType();
4570 locations->SetInAt(0, MipsReturnLocation(return_type));
4571}
4572
4573void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
4574 codegen_->GenerateFrameExit();
4575}
4576
4577void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) {
4578 ret->SetLocations(nullptr);
4579}
4580
4581void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
4582 codegen_->GenerateFrameExit();
4583}
4584
Alexey Frunze92d90602015-12-18 18:16:36 -08004585void LocationsBuilderMIPS::VisitRor(HRor* ror) {
4586 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00004587}
4588
Alexey Frunze92d90602015-12-18 18:16:36 -08004589void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) {
4590 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00004591}
4592
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004593void LocationsBuilderMIPS::VisitShl(HShl* shl) {
4594 HandleShift(shl);
4595}
4596
4597void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) {
4598 HandleShift(shl);
4599}
4600
4601void LocationsBuilderMIPS::VisitShr(HShr* shr) {
4602 HandleShift(shr);
4603}
4604
4605void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) {
4606 HandleShift(shr);
4607}
4608
4609void LocationsBuilderMIPS::VisitStoreLocal(HStoreLocal* store) {
4610 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store);
4611 Primitive::Type field_type = store->InputAt(1)->GetType();
4612 switch (field_type) {
4613 case Primitive::kPrimNot:
4614 case Primitive::kPrimBoolean:
4615 case Primitive::kPrimByte:
4616 case Primitive::kPrimChar:
4617 case Primitive::kPrimShort:
4618 case Primitive::kPrimInt:
4619 case Primitive::kPrimFloat:
4620 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
4621 break;
4622
4623 case Primitive::kPrimLong:
4624 case Primitive::kPrimDouble:
4625 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
4626 break;
4627
4628 default:
4629 LOG(FATAL) << "Unimplemented local type " << field_type;
4630 }
4631}
4632
4633void InstructionCodeGeneratorMIPS::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) {
4634}
4635
4636void LocationsBuilderMIPS::VisitSub(HSub* instruction) {
4637 HandleBinaryOp(instruction);
4638}
4639
4640void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) {
4641 HandleBinaryOp(instruction);
4642}
4643
4644void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4645 HandleFieldGet(instruction, instruction->GetFieldInfo());
4646}
4647
4648void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4649 HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
4650}
4651
4652void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) {
4653 HandleFieldSet(instruction, instruction->GetFieldInfo());
4654}
4655
4656void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) {
4657 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
4658}
4659
4660void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet(
4661 HUnresolvedInstanceFieldGet* instruction) {
4662 FieldAccessCallingConventionMIPS calling_convention;
4663 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
4664 instruction->GetFieldType(),
4665 calling_convention);
4666}
4667
4668void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet(
4669 HUnresolvedInstanceFieldGet* instruction) {
4670 FieldAccessCallingConventionMIPS calling_convention;
4671 codegen_->GenerateUnresolvedFieldAccess(instruction,
4672 instruction->GetFieldType(),
4673 instruction->GetFieldIndex(),
4674 instruction->GetDexPc(),
4675 calling_convention);
4676}
4677
4678void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet(
4679 HUnresolvedInstanceFieldSet* instruction) {
4680 FieldAccessCallingConventionMIPS calling_convention;
4681 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
4682 instruction->GetFieldType(),
4683 calling_convention);
4684}
4685
4686void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet(
4687 HUnresolvedInstanceFieldSet* instruction) {
4688 FieldAccessCallingConventionMIPS calling_convention;
4689 codegen_->GenerateUnresolvedFieldAccess(instruction,
4690 instruction->GetFieldType(),
4691 instruction->GetFieldIndex(),
4692 instruction->GetDexPc(),
4693 calling_convention);
4694}
4695
4696void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet(
4697 HUnresolvedStaticFieldGet* instruction) {
4698 FieldAccessCallingConventionMIPS calling_convention;
4699 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
4700 instruction->GetFieldType(),
4701 calling_convention);
4702}
4703
4704void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet(
4705 HUnresolvedStaticFieldGet* instruction) {
4706 FieldAccessCallingConventionMIPS calling_convention;
4707 codegen_->GenerateUnresolvedFieldAccess(instruction,
4708 instruction->GetFieldType(),
4709 instruction->GetFieldIndex(),
4710 instruction->GetDexPc(),
4711 calling_convention);
4712}
4713
4714void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet(
4715 HUnresolvedStaticFieldSet* instruction) {
4716 FieldAccessCallingConventionMIPS calling_convention;
4717 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
4718 instruction->GetFieldType(),
4719 calling_convention);
4720}
4721
4722void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet(
4723 HUnresolvedStaticFieldSet* instruction) {
4724 FieldAccessCallingConventionMIPS calling_convention;
4725 codegen_->GenerateUnresolvedFieldAccess(instruction,
4726 instruction->GetFieldType(),
4727 instruction->GetFieldIndex(),
4728 instruction->GetDexPc(),
4729 calling_convention);
4730}
4731
4732void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) {
4733 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
4734}
4735
4736void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) {
4737 HBasicBlock* block = instruction->GetBlock();
4738 if (block->GetLoopInformation() != nullptr) {
4739 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
4740 // The back edge will generate the suspend check.
4741 return;
4742 }
4743 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
4744 // The goto will generate the suspend check.
4745 return;
4746 }
4747 GenerateSuspendCheck(instruction, nullptr);
4748}
4749
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004750void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) {
4751 LocationSummary* locations =
4752 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4753 InvokeRuntimeCallingConvention calling_convention;
4754 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4755}
4756
4757void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) {
4758 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException),
4759 instruction,
4760 instruction->GetDexPc(),
4761 nullptr,
4762 IsDirectEntrypoint(kQuickDeliverException));
4763 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
4764}
4765
4766void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) {
4767 Primitive::Type input_type = conversion->GetInputType();
4768 Primitive::Type result_type = conversion->GetResultType();
4769 DCHECK_NE(input_type, result_type);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004770 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004771
4772 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
4773 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
4774 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
4775 }
4776
4777 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004778 if (!isR6 &&
4779 ((Primitive::IsFloatingPointType(result_type) && input_type == Primitive::kPrimLong) ||
4780 (result_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(input_type)))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004781 call_kind = LocationSummary::kCall;
4782 }
4783
4784 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
4785
4786 if (call_kind == LocationSummary::kNoCall) {
4787 if (Primitive::IsFloatingPointType(input_type)) {
4788 locations->SetInAt(0, Location::RequiresFpuRegister());
4789 } else {
4790 locations->SetInAt(0, Location::RequiresRegister());
4791 }
4792
4793 if (Primitive::IsFloatingPointType(result_type)) {
4794 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
4795 } else {
4796 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4797 }
4798 } else {
4799 InvokeRuntimeCallingConvention calling_convention;
4800
4801 if (Primitive::IsFloatingPointType(input_type)) {
4802 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
4803 } else {
4804 DCHECK_EQ(input_type, Primitive::kPrimLong);
4805 locations->SetInAt(0, Location::RegisterPairLocation(
4806 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
4807 }
4808
4809 locations->SetOut(calling_convention.GetReturnLocation(result_type));
4810 }
4811}
4812
4813void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) {
4814 LocationSummary* locations = conversion->GetLocations();
4815 Primitive::Type result_type = conversion->GetResultType();
4816 Primitive::Type input_type = conversion->GetInputType();
4817 bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004818 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
4819 bool fpu_32bit = codegen_->GetInstructionSetFeatures().Is32BitFloatingPoint();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004820
4821 DCHECK_NE(input_type, result_type);
4822
4823 if (result_type == Primitive::kPrimLong && Primitive::IsIntegralType(input_type)) {
4824 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
4825 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
4826 Register src = locations->InAt(0).AsRegister<Register>();
4827
4828 __ Move(dst_low, src);
4829 __ Sra(dst_high, src, 31);
4830 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
4831 Register dst = locations->Out().AsRegister<Register>();
4832 Register src = (input_type == Primitive::kPrimLong)
4833 ? locations->InAt(0).AsRegisterPairLow<Register>()
4834 : locations->InAt(0).AsRegister<Register>();
4835
4836 switch (result_type) {
4837 case Primitive::kPrimChar:
4838 __ Andi(dst, src, 0xFFFF);
4839 break;
4840 case Primitive::kPrimByte:
4841 if (has_sign_extension) {
4842 __ Seb(dst, src);
4843 } else {
4844 __ Sll(dst, src, 24);
4845 __ Sra(dst, dst, 24);
4846 }
4847 break;
4848 case Primitive::kPrimShort:
4849 if (has_sign_extension) {
4850 __ Seh(dst, src);
4851 } else {
4852 __ Sll(dst, src, 16);
4853 __ Sra(dst, dst, 16);
4854 }
4855 break;
4856 case Primitive::kPrimInt:
4857 __ Move(dst, src);
4858 break;
4859
4860 default:
4861 LOG(FATAL) << "Unexpected type conversion from " << input_type
4862 << " to " << result_type;
4863 }
4864 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004865 if (input_type == Primitive::kPrimLong) {
4866 if (isR6) {
4867 // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary
4868 // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction.
4869 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
4870 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
4871 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
4872 __ Mtc1(src_low, FTMP);
4873 __ Mthc1(src_high, FTMP);
4874 if (result_type == Primitive::kPrimFloat) {
4875 __ Cvtsl(dst, FTMP);
4876 } else {
4877 __ Cvtdl(dst, FTMP);
4878 }
4879 } else {
4880 int32_t entry_offset = (result_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pL2f)
4881 : QUICK_ENTRY_POINT(pL2d);
4882 bool direct = (result_type == Primitive::kPrimFloat) ? IsDirectEntrypoint(kQuickL2f)
4883 : IsDirectEntrypoint(kQuickL2d);
4884 codegen_->InvokeRuntime(entry_offset,
4885 conversion,
4886 conversion->GetDexPc(),
4887 nullptr,
4888 direct);
4889 if (result_type == Primitive::kPrimFloat) {
4890 CheckEntrypointTypes<kQuickL2f, float, int64_t>();
4891 } else {
4892 CheckEntrypointTypes<kQuickL2d, double, int64_t>();
4893 }
4894 }
4895 } else {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004896 Register src = locations->InAt(0).AsRegister<Register>();
4897 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
4898 __ Mtc1(src, FTMP);
4899 if (result_type == Primitive::kPrimFloat) {
4900 __ Cvtsw(dst, FTMP);
4901 } else {
4902 __ Cvtdw(dst, FTMP);
4903 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004904 }
4905 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
4906 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004907 if (result_type == Primitive::kPrimLong) {
4908 if (isR6) {
4909 // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary
4910 // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction.
4911 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
4912 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
4913 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
4914 MipsLabel truncate;
4915 MipsLabel done;
4916
4917 // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive
4918 // value when the input is either a NaN or is outside of the range of the output type
4919 // after the truncation. IOW, the three special cases (NaN, too small, too big) produce
4920 // the same result.
4921 //
4922 // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum
4923 // value of the output type if the input is outside of the range after the truncation or
4924 // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct
4925 // results. This matches the desired float/double-to-int/long conversion exactly.
4926 //
4927 // So, NAN2008 affects handling of negative values and NaNs by the truncate instruction.
4928 //
4929 // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate
4930 // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6,
4931 // even though it must be NAN2008=1 on R6.
4932 //
4933 // The code takes care of the different behaviors by first comparing the input to the
4934 // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int).
4935 // If the input is greater than or equal to the minimum, it procedes to the truncate
4936 // instruction, which will handle such an input the same way irrespective of NAN2008.
4937 // Otherwise the input is compared to itself to determine whether it is a NaN or not
4938 // in order to return either zero or the minimum value.
4939 //
4940 // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the
4941 // truncate instruction for MIPS64R6.
4942 if (input_type == Primitive::kPrimFloat) {
4943 uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int64_t>::min());
4944 __ LoadConst32(TMP, min_val);
4945 __ Mtc1(TMP, FTMP);
4946 __ CmpLeS(FTMP, FTMP, src);
4947 } else {
4948 uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int64_t>::min());
4949 __ LoadConst32(TMP, High32Bits(min_val));
4950 __ Mtc1(ZERO, FTMP);
4951 __ Mthc1(TMP, FTMP);
4952 __ CmpLeD(FTMP, FTMP, src);
4953 }
4954
4955 __ Bc1nez(FTMP, &truncate);
4956
4957 if (input_type == Primitive::kPrimFloat) {
4958 __ CmpEqS(FTMP, src, src);
4959 } else {
4960 __ CmpEqD(FTMP, src, src);
4961 }
4962 __ Move(dst_low, ZERO);
4963 __ LoadConst32(dst_high, std::numeric_limits<int32_t>::min());
4964 __ Mfc1(TMP, FTMP);
4965 __ And(dst_high, dst_high, TMP);
4966
4967 __ B(&done);
4968
4969 __ Bind(&truncate);
4970
4971 if (input_type == Primitive::kPrimFloat) {
4972 __ TruncLS(FTMP, src);
4973 } else {
4974 __ TruncLD(FTMP, src);
4975 }
4976 __ Mfc1(dst_low, FTMP);
4977 __ Mfhc1(dst_high, FTMP);
4978
4979 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004980 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004981 int32_t entry_offset = (input_type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pF2l)
4982 : QUICK_ENTRY_POINT(pD2l);
4983 bool direct = (result_type == Primitive::kPrimFloat) ? IsDirectEntrypoint(kQuickF2l)
4984 : IsDirectEntrypoint(kQuickD2l);
4985 codegen_->InvokeRuntime(entry_offset, conversion, conversion->GetDexPc(), nullptr, direct);
4986 if (input_type == Primitive::kPrimFloat) {
4987 CheckEntrypointTypes<kQuickF2l, int64_t, float>();
4988 } else {
4989 CheckEntrypointTypes<kQuickD2l, int64_t, double>();
4990 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004991 }
4992 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08004993 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
4994 Register dst = locations->Out().AsRegister<Register>();
4995 MipsLabel truncate;
4996 MipsLabel done;
4997
4998 // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate
4999 // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6,
5000 // even though it must be NAN2008=1 on R6.
5001 //
5002 // For details see the large comment above for the truncation of float/double to long on R6.
5003 //
5004 // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the
5005 // truncate instruction for MIPS64R6.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005006 if (input_type == Primitive::kPrimFloat) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005007 uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min());
5008 __ LoadConst32(TMP, min_val);
5009 __ Mtc1(TMP, FTMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005010 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005011 uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min());
5012 __ LoadConst32(TMP, High32Bits(min_val));
5013 __ Mtc1(ZERO, FTMP);
5014 if (fpu_32bit) {
5015 __ Mtc1(TMP, static_cast<FRegister>(FTMP + 1));
5016 } else {
5017 __ Mthc1(TMP, FTMP);
5018 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005019 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005020
5021 if (isR6) {
5022 if (input_type == Primitive::kPrimFloat) {
5023 __ CmpLeS(FTMP, FTMP, src);
5024 } else {
5025 __ CmpLeD(FTMP, FTMP, src);
5026 }
5027 __ Bc1nez(FTMP, &truncate);
5028
5029 if (input_type == Primitive::kPrimFloat) {
5030 __ CmpEqS(FTMP, src, src);
5031 } else {
5032 __ CmpEqD(FTMP, src, src);
5033 }
5034 __ LoadConst32(dst, std::numeric_limits<int32_t>::min());
5035 __ Mfc1(TMP, FTMP);
5036 __ And(dst, dst, TMP);
5037 } else {
5038 if (input_type == Primitive::kPrimFloat) {
5039 __ ColeS(0, FTMP, src);
5040 } else {
5041 __ ColeD(0, FTMP, src);
5042 }
5043 __ Bc1t(0, &truncate);
5044
5045 if (input_type == Primitive::kPrimFloat) {
5046 __ CeqS(0, src, src);
5047 } else {
5048 __ CeqD(0, src, src);
5049 }
5050 __ LoadConst32(dst, std::numeric_limits<int32_t>::min());
5051 __ Movf(dst, ZERO, 0);
5052 }
5053
5054 __ B(&done);
5055
5056 __ Bind(&truncate);
5057
5058 if (input_type == Primitive::kPrimFloat) {
5059 __ TruncWS(FTMP, src);
5060 } else {
5061 __ TruncWD(FTMP, src);
5062 }
5063 __ Mfc1(dst, FTMP);
5064
5065 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005066 }
5067 } else if (Primitive::IsFloatingPointType(result_type) &&
5068 Primitive::IsFloatingPointType(input_type)) {
5069 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
5070 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
5071 if (result_type == Primitive::kPrimFloat) {
5072 __ Cvtsd(dst, src);
5073 } else {
5074 __ Cvtds(dst, src);
5075 }
5076 } else {
5077 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
5078 << " to " << result_type;
5079 }
5080}
5081
5082void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) {
5083 HandleShift(ushr);
5084}
5085
5086void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) {
5087 HandleShift(ushr);
5088}
5089
5090void LocationsBuilderMIPS::VisitXor(HXor* instruction) {
5091 HandleBinaryOp(instruction);
5092}
5093
5094void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) {
5095 HandleBinaryOp(instruction);
5096}
5097
5098void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
5099 // Nothing to do, this should be removed during prepare for register allocator.
5100 LOG(FATAL) << "Unreachable";
5101}
5102
5103void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
5104 // Nothing to do, this should be removed during prepare for register allocator.
5105 LOG(FATAL) << "Unreachable";
5106}
5107
5108void LocationsBuilderMIPS::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005109 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005110}
5111
5112void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005113 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005114}
5115
5116void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005117 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005118}
5119
5120void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005121 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005122}
5123
5124void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005125 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005126}
5127
5128void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005129 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005130}
5131
5132void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005133 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005134}
5135
5136void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005137 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005138}
5139
5140void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005141 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005142}
5143
5144void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005145 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005146}
5147
5148void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005149 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005150}
5151
5152void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005153 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005154}
5155
5156void LocationsBuilderMIPS::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005157 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005158}
5159
5160void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005161 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005162}
5163
5164void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005165 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005166}
5167
5168void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005169 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005170}
5171
5172void LocationsBuilderMIPS::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005173 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005174}
5175
5176void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005177 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005178}
5179
5180void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005181 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005182}
5183
5184void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005185 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005186}
5187
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005188void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
5189 LocationSummary* locations =
5190 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
5191 locations->SetInAt(0, Location::RequiresRegister());
5192}
5193
5194void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
5195 int32_t lower_bound = switch_instr->GetStartValue();
5196 int32_t num_entries = switch_instr->GetNumEntries();
5197 LocationSummary* locations = switch_instr->GetLocations();
5198 Register value_reg = locations->InAt(0).AsRegister<Register>();
5199 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
5200
5201 // Create a set of compare/jumps.
Vladimir Markof3e0ee22015-12-17 15:23:13 +00005202 Register temp_reg = TMP;
5203 __ Addiu32(temp_reg, value_reg, -lower_bound);
5204 // Jump to default if index is negative
5205 // Note: We don't check the case that index is positive while value < lower_bound, because in
5206 // this case, index >= num_entries must be true. So that we can save one branch instruction.
5207 __ Bltz(temp_reg, codegen_->GetLabelOf(default_block));
5208
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005209 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00005210 // Jump to successors[0] if value == lower_bound.
5211 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0]));
5212 int32_t last_index = 0;
5213 for (; num_entries - last_index > 2; last_index += 2) {
5214 __ Addiu(temp_reg, temp_reg, -2);
5215 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
5216 __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
5217 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
5218 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2]));
5219 }
5220 if (num_entries - last_index == 2) {
5221 // The last missing case_value.
5222 __ Addiu(temp_reg, temp_reg, -1);
5223 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005224 }
5225
Vladimir Markof3e0ee22015-12-17 15:23:13 +00005226 // And the default for any other value.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005227 if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) {
5228 __ B(codegen_->GetLabelOf(default_block));
5229 }
5230}
5231
5232void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
5233 // The trampoline uses the same calling convention as dex calling conventions,
5234 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
5235 // the method_idx.
5236 HandleInvoke(invoke);
5237}
5238
5239void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
5240 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
5241}
5242
Roland Levillain2aba7cd2016-02-03 12:27:20 +00005243void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) {
5244 LocationSummary* locations =
5245 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
5246 locations->SetInAt(0, Location::RequiresRegister());
5247 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00005248}
5249
Roland Levillain2aba7cd2016-02-03 12:27:20 +00005250void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) {
5251 LocationSummary* locations = instruction->GetLocations();
5252 uint32_t method_offset = 0;
Vladimir Markoa1de9182016-02-25 11:37:38 +00005253 if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) {
Roland Levillain2aba7cd2016-02-03 12:27:20 +00005254 method_offset = mirror::Class::EmbeddedVTableEntryOffset(
5255 instruction->GetIndex(), kMipsPointerSize).SizeValue();
5256 } else {
5257 method_offset = mirror::Class::EmbeddedImTableEntryOffset(
5258 instruction->GetIndex() % mirror::Class::kImtSize, kMipsPointerSize).Uint32Value();
5259 }
5260 __ LoadFromOffset(kLoadWord,
5261 locations->Out().AsRegister<Register>(),
5262 locations->InAt(0).AsRegister<Register>(),
5263 method_offset);
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00005264}
5265
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005266#undef __
5267#undef QUICK_ENTRY_POINT
5268
5269} // namespace mips
5270} // namespace art